moar zoom, fixed fort mode, other glitches
authorkoda
Sat, 26 Jun 2010 04:36:04 +0200
changeset 3551 d4de36b3801a
parent 3550 149416b948fc
child 3556 4bdc59101ce5
moar zoom, fixed fort mode, other glitches but best of all, touch works fo' real
hedgewars/CCHandlers.inc
hedgewars/PascalExports.pas
hedgewars/uLand.pas
hedgewars/uWorld.pas
project_files/HedgewarsMobile/Classes/CGPointUtils.h
project_files/HedgewarsMobile/Classes/CommodityFunctions.m
project_files/HedgewarsMobile/Classes/GameSetup.m
project_files/HedgewarsMobile/Classes/OverlayViewController.h
project_files/HedgewarsMobile/Classes/OverlayViewController.m
project_files/HedgewarsMobile/Classes/PascalImports.h
project_files/HedgewarsMobile/Classes/TeamConfigViewController.h
project_files/HedgewarsMobile/Classes/TeamConfigViewController.m
project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj
--- a/hedgewars/CCHandlers.inc	Thu Jun 24 01:08:57 2010 +0200
+++ b/hedgewars/CCHandlers.inc	Sat Jun 26 04:36:04 2010 +0200
@@ -815,7 +815,11 @@
 procedure chZoomOut(var s: shortstring);
 begin
     s:= s; // avoid compiler hint
+{$IFDEF IPHONEOS}
+    if ZoomValue > 0.5 then
+{$ELSE}
     if ZoomValue > 1.0 then
+{$ENDIF}
         ZoomValue:= ZoomValue - 0.20;
 end;
 
--- a/hedgewars/PascalExports.pas	Thu Jun 24 01:08:57 2010 +0200
+++ b/hedgewars/PascalExports.pas	Sat Jun 26 04:36:04 2010 +0200
@@ -13,7 +13,7 @@
 unit PascalExports;
 
 interface
-uses uKeys, GLunit, uWorld, hwengine;
+uses uKeys, GLunit, uWorld, uMisc, uConsole, hwengine;
 
 {$INCLUDE "config.inc"}
 
@@ -152,6 +152,17 @@
         cOffsetY:= 120;
     end;
 end;
+
+procedure HW_setCursor(x,y: LongInt); cdecl; export;
+begin
+    CursorPoint.X:= x;
+    CursorPoint.Y:= y;
+end;
+
+function HW_isAmmoOpen:boolean; cdecl; export;
+begin
+    exit(bShowAmmoMenu);
+end;
 {$ENDIF}
 
 end.
--- a/hedgewars/uLand.pas	Thu Jun 24 01:08:57 2010 +0200
+++ b/hedgewars/uLand.pas	Sat Jun 26 04:36:04 2010 +0200
@@ -1220,6 +1220,10 @@
 
     LoadThemeConfig;
     isMap:= false;
+    
+    if ((GameFlags and gfForts) <> 0) or (Pathz[ptMapCurrent] <> '') then
+        FillChar(Land,SizeOf(TCollisionArray),0);
+        
     if (GameFlags and gfForts) = 0 then
         if Pathz[ptMapCurrent] <> '' then
             LoadMap
--- a/hedgewars/uWorld.pas	Thu Jun 24 01:08:57 2010 +0200
+++ b/hedgewars/uWorld.pas	Sat Jun 26 04:36:04 2010 +0200
@@ -1007,12 +1007,14 @@
 const PrevSentPointTime: LongWord = 0;
 var EdgesDist,  wdy: LongInt;
 begin
+{$IFNDEF IPHONEOS}
 if (not (CurrentTeam^.ExtDriven and isCursorVisible and not bShowAmmoMenu)) and cHasFocus then
-    begin
+begin
     SDL_GetMouseState(@CursorPoint.X, @CursorPoint.Y);
     CursorPoint.X:= CursorPoint.X - (cScreenWidth shr 1);
     CursorPoint.Y:= cScreenHeight - CursorPoint.Y;
-    end;
+end;
+{$ENDIF}
 
 if (not PlacingHogs) and (FollowGear <> nil) and (not isCursorVisible) and (not fastUntilLag) then
     if abs(CursorPoint.X - prevPoint.X) + abs(CursorPoint.Y - prevpoint.Y) > 4 then
--- a/project_files/HedgewarsMobile/Classes/CGPointUtils.h	Thu Jun 24 01:08:57 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/CGPointUtils.h	Sat Jun 26 04:36:04 2010 +0200
@@ -9,9 +9,12 @@
 
 #import <CoreGraphics/CoreGraphics.h>
 
-#define degreesToRadian(x) (M_PI * x / 180.0)
+#define degreesToRadian(x)  (M_PI * x / 180.0)
 #define radiansToDegrees(x) (180.0 * x / M_PI)
 
+#define HWX(x) (int)(x-screen.size.height/2)
+#define HWY(x) (int)(screen.size.width-x)
+
 CGFloat distanceBetweenPoints (CGPoint first, CGPoint second);
 CGFloat angleBetweenPoints(CGPoint first, CGPoint second);
 CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint lin2End);
--- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Thu Jun 24 01:08:57 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.m	Sat Jun 26 04:36:04 2010 +0200
@@ -113,11 +113,8 @@
 }
 
 BOOL rotationManager (UIInterfaceOrientation interfaceOrientation) {
-    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
-        return YES;
-    else
-        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight) ||
-               (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);  
+    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight) ||
+           (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);  
 }
 
 NSInteger randomPort () {
--- a/project_files/HedgewarsMobile/Classes/GameSetup.m	Thu Jun 24 01:08:57 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameSetup.m	Sat Jun 26 04:36:04 2010 +0200
@@ -306,7 +306,7 @@
                 break;
             case '?':
                 // without this sleep sometimes frontend replies before engine has processed any flag (resulting in an error)
-                [NSThread sleepForTimeInterval:0.4];
+                [NSThread sleepForTimeInterval:0.6];
                 DLog(@"Ping? Pong!");
                 [self sendToEngine:@"!"];
                 break;
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.h	Thu Jun 24 01:08:57 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.h	Sat Jun 26 04:36:04 2010 +0200
@@ -22,7 +22,6 @@
     UITextField *writeChatTextField;
     
     CGFloat initialDistanceForPinching;
-    CGPoint gestureStartPoint;
     UIActivityIndicatorView *spinningWheel;
 }
 
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Thu Jun 24 01:08:57 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Sat Jun 26 04:36:04 2010 +0200
@@ -57,6 +57,7 @@
             [self chatDisappear];
             HW_setLandscape(YES);
             break;
+        /*
         case UIDeviceOrientationPortrait:
             if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
                 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(270));
@@ -73,6 +74,7 @@
                 HW_setLandscape(NO);
             }
             break;
+        */
         default:
             break;
     }
@@ -242,7 +244,6 @@
 // on iphone instead just use the tableViewController directly (and implement manually all animations)
 -(IBAction) showPopover{
     isPopoverVisible = YES;
-    CGRect anchorForPopover;
 
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
         if (popupMenu == nil) 
@@ -252,13 +253,8 @@
             [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES];
             [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
         }
-        
-        if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]))
-            anchorForPopover = CGRectMake(960, 0, 220, 32);
-        else
-            anchorForPopover = CGRectMake(736, 0, 220, 32);
-        
-        [popoverController presentPopoverFromRect:anchorForPopover
+
+        [popoverController presentPopoverFromRect:CGRectMake(1000, 0, 220, 32)
                                            inView:self.view
                          permittedArrowDirections:UIPopoverArrowDirectionUp
                                          animated:YES];
@@ -303,11 +299,8 @@
 
 // this function is called by pascal FinishProgress and removes the spinning wheel when loading is done
 void spinningWheelDone (void) {
-    [UIView beginAnimations:@"hiding spinning wheel" context:NULL];
-    [UIView setAnimationDuration:0.7];
-    singleton.alpha = 0;
-    [UIView commitAnimations];
-    [singleton performSelector:@selector(stopAnimating) withObject:nil afterDelay:0.7];
+    [singleton stopAnimating];
+    singleton = nil;
     canDim = YES;
 }
 
@@ -316,6 +309,8 @@
 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     NSArray *twoTouches;
     UITouch *touch = [touches anyObject];
+    CGRect screen = [[UIScreen mainScreen] bounds];
+    CGPoint currentPosition = [touch locationInView:self.view];
     
     if (isPopoverVisible) {
         [self dismissPopover];
@@ -324,33 +319,19 @@
         [self.writeChatTextField resignFirstResponder];
         [dimTimer setFireDate:HIDING_TIME_DEFAULT];
     }
-    
-    gestureStartPoint = [touch locationInView:self.view];
-        
+            
     switch ([touches count]) {
-        /*case 1:
-            initialDistanceForPinching = 0;
-            switch ([touch tapCount]) {
-                case 1:
-                    NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y );
-                    //SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
-                    //            (int)gestureStartPoint.y, width - (int)gestureStartPoint.x);
-                    //HW_click();
-                    break;
-                case 2:
-                    HW_ammoMenu();
-                    break;
-                default:
-                    break;
-            }
-            break;*/
+        case 1:
+            DLog(@"X:%d Y:%d", HWX(currentPosition.x), HWY(currentPosition.y));
+            HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
+            break;
         case 2:
-            if (2 == [touch tapCount]) {
-                HW_zoomReset();
+            if (2 == [touch tapCount] && currentPosition.y < screen.size.width - 100) {
+                HW_ammoMenu();
+                //HW_zoomReset();
             }
             
             // pinching
-            gestureStartPoint = CGPointMake(0, 0);
             twoTouches = [touches allObjects];
             UITouch *first = [twoTouches objectAtIndex:0];
             UITouch *second = [twoTouches objectAtIndex:1];
@@ -363,9 +344,9 @@
 }
 
 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
-    gestureStartPoint = CGPointMake(0, 0);
     initialDistanceForPinching = 0;
     //HW_allKeysUp();
+    HW_click();
 }
 
 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
@@ -374,48 +355,20 @@
 }
 
 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
-    CGFloat minimumGestureLength;
-    int logCoeff;
-    
-    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
-        minimumGestureLength = 5.0f;
-        logCoeff = 19;
-    } else {
-        minimumGestureLength = 3.0f;
-        logCoeff = 3;
-    }
+    CGRect screen = [[UIScreen mainScreen] bounds];
     
     NSArray *twoTouches;
     CGPoint currentPosition;
     UITouch *touch = [touches anyObject];
 
     switch ([touches count]) {
-        /*case 1:
-            currentPosition = [touch locationInView:self.view];
-            // panning
-            CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
-            CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
-            
-            // the two ifs are not mutually exclusive
-            if (deltaX >= minimumGestureLength) {
-                DLog(@"deltaX: %f deltaY: %f", deltaX, deltaY);
-                if (currentPosition.x > gestureStartPoint.x) {
-                    HW_cursorLeft(logCoeff*log(deltaX));
-                } else {
-                    HW_cursorRight(logCoeff*log(deltaX));
-                }
-
-            } 
-            if (deltaY >= minimumGestureLength) {
-                DLog(@"deltaX: %f deltaY: %f", deltaX, deltaY);
-                if (currentPosition.y < gestureStartPoint.y) {
-                    HW_cursorDown(logCoeff*log(deltaY));
-                } else {
-                    HW_cursorUp(logCoeff*log(deltaY));
-                }            
+        case 1:
+            if (HW_isAmmoOpen()) {
+                currentPosition = [touch locationInView:self.view];
+                DLog(@"X:%d Y:%d", HWX(currentPosition.x), HWY(currentPosition.y));
+                HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
             }
-
-            break;*/
+            break;
         case 2:
             twoTouches = [touches allObjects];
             UITouch *first = [twoTouches objectAtIndex:0];
--- a/project_files/HedgewarsMobile/Classes/PascalImports.h	Thu Jun 24 01:08:57 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/PascalImports.h	Sat Jun 26 04:36:04 2010 +0200
@@ -52,6 +52,8 @@
     void HW_terminate(BOOL);
     
     void HW_setLandscape(BOOL);
+    void HW_setCursor(int x, int y);
+    BOOL HW_isAmmoOpen(void);
 #ifdef __cplusplus
 }
 #endif
--- a/project_files/HedgewarsMobile/Classes/TeamConfigViewController.h	Thu Jun 24 01:08:57 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/TeamConfigViewController.h	Sat Jun 26 04:36:04 2010 +0200
@@ -12,6 +12,7 @@
 @interface TeamConfigViewController : UITableViewController {
     NSMutableArray *listOfTeams;
     NSMutableArray *listOfSelectedTeams;
+    BOOL isFirstLoad;
 }
 
 @property (nonatomic, retain) NSMutableArray *listOfTeams;
--- a/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m	Thu Jun 24 01:08:57 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/TeamConfigViewController.m	Sat Jun 26 04:36:04 2010 +0200
@@ -25,30 +25,34 @@
     
     CGSize screenSize = [[UIScreen mainScreen] bounds].size;
     self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44);
+    isFirstLoad = YES;
 }
 
 -(void) viewWillAppear:(BOOL)animated {
     [super viewWillAppear:animated];
 
-    // integer representation of various color (defined in SquareButtonView)
-    NSUInteger colors[6] = { 4421353, 4100897, 10632635, 16749353, 14483456, 7566195 };
-    NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL];
-    NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]];
-    for (int i = 0; i < [contentsOfDir count]; i++) {
-        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
-                                                                  [contentsOfDir objectAtIndex:i],@"team",
-                                                                  [NSNumber numberWithInt:4],@"number",
-                                                                  [NSNumber numberWithInt:colors[i%6]],@"color",nil];
-        [array addObject:dict];
-        [dict release];
+    // avoid overwriting selected teams when returning on this view
+    if (isFirstLoad) {
+        // integer representation of various color (defined in SquareButtonView)
+        NSUInteger colors[6] = { 4421353, 4100897, 10632635, 16749353, 14483456, 7566195 };
+        NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL];
+        NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]];
+        for (int i = 0; i < [contentsOfDir count]; i++) {
+            NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
+                                         [contentsOfDir objectAtIndex:i],@"team",
+                                         [NSNumber numberWithInt:4],@"number",
+                                         [NSNumber numberWithInt:colors[i%6]],@"color",nil];
+            [array addObject:dict];
+            [dict release];
+        }
+        self.listOfTeams = array;
+        [array release];
+        
+        NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil];
+        self.listOfSelectedTeams = emptyArray;
+        [emptyArray release];
+        isFirstLoad = NO;
     }
-    self.listOfTeams = array;
-    [array release];
-    
-    NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil];
-    self.listOfSelectedTeams = emptyArray;
-    [emptyArray release];
-
     [self.tableView reloadData];
 }
 
--- a/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Thu Jun 24 01:08:57 2010 +0200
+++ b/project_files/HedgewarsMobile/Hedgewars.xcodeproj/project.pbxproj	Sat Jun 26 04:36:04 2010 +0200
@@ -1187,7 +1187,7 @@
 		6137064B117B1CB3004EE44A /* Distribution */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)";
+				ARCHS = "$(ARCHS_STANDARD_32_BIT)";
 				CODE_SIGN_ENTITLEMENTS = "Entitlements-Distribution.plist";
 				CODE_SIGN_IDENTITY = "iPhone Distribution";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
@@ -1298,7 +1298,7 @@
 		6164429D11B5CDE500B9A6F3 /* Valgrind */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)";
+				ARCHS = "$(ARCHS_STANDARD_32_BIT)";
 				CODE_SIGN_IDENTITY = "iPhone Developer: Vittorio Giovara (DC2BRETXAC)";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Vittorio Giovara (DC2BRETXAC)";
 				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
@@ -1501,7 +1501,7 @@
 		C01FCF4F08A954540054247B /* Debug */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)";
+				ARCHS = "$(ARCHS_STANDARD_32_BIT)";
 				CODE_SIGN_IDENTITY = "iPhone Developer: Vittorio Giovara (DC2BRETXAC)";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Vittorio Giovara (DC2BRETXAC)";
 				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
@@ -1541,7 +1541,7 @@
 		C01FCF5008A954540054247B /* Release */ = {
 			isa = XCBuildConfiguration;
 			buildSettings = {
-				ARCHS = "$(ARCHS_UNIVERSAL_IPHONE_OS)";
+				ARCHS = "$(ARCHS_STANDARD_32_BIT)";
 				CODE_SIGN_IDENTITY = "iPhone Developer";
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				FPC_COMMON_OPTIONS = "-dIPHONEOS -Cs2000000 -vwi -B  -Sgix";