touch overlay reworked, improvements to zoom and confirmation
authorkoda
Sun, 11 Jul 2010 18:39:01 +0200
changeset 3638 33ee433749ba
parent 3637 0db298524c3d
child 3639 b5cdbcc89b61
touch overlay reworked, improvements to zoom and confirmation
hedgewars/CCHandlers.inc
hedgewars/PascalExports.pas
hedgewars/uConsts.pas
hedgewars/uWorld.pas
project_files/HedgewarsMobile/Classes/OverlayViewController.h
project_files/HedgewarsMobile/Classes/OverlayViewController.m
project_files/HedgewarsMobile/Resources/OverlayViewController.xib
--- a/hedgewars/CCHandlers.inc	Sun Jul 11 03:23:26 2010 +0200
+++ b/hedgewars/CCHandlers.inc	Sun Jul 11 18:39:01 2010 +0200
@@ -510,10 +510,6 @@
         Message:= Message or gm_Weapon;
         MsgParam:= byte(s[1]);
     end;
-    
-{$IFDEF IPHONEOS}
-    savedAmmoType:= TAmmoType(s[1]);
-{$ENDIF}
 end;
 
 procedure chTaunt(var s: shortstring);
@@ -616,8 +612,8 @@
 
 procedure chPut(var s: shortstring);
 begin
-s:= s; // avoid compiler hint
-doPut(0, 0, false)
+    s:= s; // avoid compiler hint
+    doPut(0, 0, false);
 end;
 
 procedure chCapture(var s: shortstring);
@@ -804,23 +800,15 @@
 procedure chZoomIn(var s: shortstring);
 begin
     s:= s; // avoid compiler hint
-{$IFDEF IPHONEOS}
-    if ZoomValue < 4.0 then
-{$ELSE}
-    if ZoomValue < 3.0 then
-{$ENDIF}
-        ZoomValue:= ZoomValue + 0.20;
+    if ZoomValue < cMinZoomLevel then
+        ZoomValue:= ZoomValue + cZoomDelta;
 end;
 
 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;
+    if ZoomValue > cMaxZoomLevel then
+        ZoomValue:= ZoomValue - cZoomDelta;
 end;
 
 procedure chZoomReset(var s: shortstring);
--- a/hedgewars/PascalExports.pas	Sun Jul 11 03:23:26 2010 +0200
+++ b/hedgewars/PascalExports.pas	Sun Jul 11 18:39:01 2010 +0200
@@ -197,14 +197,7 @@
 
 function HW_isWeaponRequiringClick: boolean; cdecl; export;
 begin
-    exit( (savedAmmoType = amTeleport) or
-          (savedAmmoType = amBee) or
-          (savedAmmoType = amAirAttack) or
-          (savedAmmoType = amMineStrike) or
-          (savedAmmoType = amGirder) or
-          (savedAmmoType = amNapalm) or
-          (savedAmmoType = amPiano)
-        )
+    exit( (CurrentHedgehog^.Gear^.State and gstHHChooseTarget) <> 0 )
 end;
 
 //amSwitch
--- a/hedgewars/uConsts.pas	Sun Jul 11 03:23:26 2010 +0200
+++ b/hedgewars/uConsts.pas	Sun Jul 11 18:39:01 2010 +0200
@@ -297,11 +297,16 @@
 
 {$IFDEF IPHONEOS}
     cMaxCaptions = 3;
-    cDefaultZoomLevel = 1.5;
-    savedAmmoType : TAmmoType = amNothing;
+    cDefaultZoomLevel = 2.0;
+    cMaxZoomLevel = 0.5;
+    cMinZoomLevel = 3.5;
+    cZoomDelta = 0.20;
 {$ELSE}
     cMaxCaptions = 4;
     cDefaultZoomLevel = 2.0;
+    cMaxZoomLevel = 1.0;
+    cMinZoomLevel = 3.0;
+    cZoomDelta = 0.25;
 {$ENDIF}
 
     cSendEmptyPacketTime = 1000;
--- a/hedgewars/uWorld.pas	Sun Jul 11 03:23:26 2010 +0200
+++ b/hedgewars/uWorld.pas	Sun Jul 11 18:39:01 2010 +0200
@@ -48,6 +48,7 @@
 procedure ShowMission(caption, subcaption, text: ansistring; icon, time : LongInt);
 procedure HideMission;
 procedure ShakeCamera(amount: LongWord);
+procedure MoveCamera;
 
 implementation
 uses    uStore, uMisc, uTeams, uIO, uKeys, uLocale, uSound, uAmmos, uVisualGears, uChat, uLandTexture, uLand, GLunit;
@@ -390,8 +391,6 @@
 if AMxShift = 0 then DrawSprite(sprArrow, CursorPoint.X, cScreenHeight - CursorPoint.Y, (RealTicks shr 6) mod 8)
 end;
 
-procedure MoveCamera; forward;
-
 procedure DrawWater(Alpha: byte; OffsetY: LongInt);
 var VertexBuffer: array [0..3] of TVertex2f;
     r: TSDL_Rect;
@@ -1012,8 +1011,8 @@
 end;
 
 procedure MoveCamera;
-const PrevSentPointTime: LongWord = 0;
 var EdgesDist,  wdy: LongInt;
+    PrevSentPointTime: LongWord = 0;
 begin
 {$IFNDEF IPHONEOS}
 if (not (CurrentTeam^.ExtDriven and isCursorVisible and not bShowAmmoMenu)) and cHasFocus then
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.h	Sun Jul 11 03:23:26 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.h	Sun Jul 11 18:39:01 2010 +0200
@@ -8,6 +8,9 @@
 
 #import <UIKit/UIKit.h>
 
+#define CONFIRMATION_TAG 5959
+#define removeConfirmationInput() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]
+
 @class PopoverMenuViewController;
 
 @interface OverlayViewController : UIViewController {
--- a/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Sun Jul 11 03:23:26 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/OverlayViewController.m	Sun Jul 11 18:39:01 2010 +0200
@@ -257,9 +257,11 @@
             HW_tab();
             break;
         case 10:
+            removeConfirmationInput();
             [self showPopover];
             break;
         case 11:
+            removeConfirmationInput();
             HW_ammoMenu();
             break;
         default:
@@ -337,10 +339,8 @@
 #pragma mark -
 #pragma mark Custom touch event handling
 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
-    NSArray *twoTouches;
-    UITouch *touch = [touches anyObject];
-    CGRect screen = [[UIScreen mainScreen] bounds];
-    CGPoint currentPosition = [touch locationInView:self.view];
+    NSSet *allTouches = [event allTouches];
+    UITouch *touch, *first, *second;
     
     if (isPopoverVisible) {
         [self dismissPopover];
@@ -351,87 +351,98 @@
         [dimTimer setFireDate:HIDING_TIME_DEFAULT];
     }
     */
-
-    if (currentPosition.y < screen.size.width - 130 || (currentPosition.x > 130 && currentPosition.x < screen.size.height - 130)) {
-        switch ([touches count]) {
-            case 1:
-                //DLog(@"X:%d Y:%d", HWX(currentPosition.x), HWY(currentPosition.y));
-                // this is a single touch/tap
-                isSingleClick = YES;
-                // save were the click event will take place
-                pointWhereToClick = currentPosition;
-                
-                [[self.view viewWithTag:5599] removeFromSuperview];
-                if (2 == [touch tapCount])
-                    HW_zoomReset();
-                break;
-            case 2:                
-                // pinching
-                twoTouches = [touches allObjects];
-                UITouch *first = [twoTouches objectAtIndex:0];
-                UITouch *second = [twoTouches objectAtIndex:1];
-                initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
-                break;
-            default:
-                break;
-        }
+    
+    switch ([allTouches count]) {
+        case 1:
+            touch = [[allTouches allObjects] objectAtIndex:0];
+            CGPoint currentPosition = [touch locationInView:self.view];
+            
+            //DLog(@"X:%d Y:%d", HWX(currentPosition.x), HWY(currentPosition.y));
+            // this is a single touch/tap
+            isSingleClick = YES;
+            // save were the click event will take place
+            pointWhereToClick = currentPosition;
+            
+            removeConfirmationInput();
+            if (2 == [touch tapCount])
+                HW_zoomReset();
+            break;
+        case 2:                
+            // pinching
+            first = [[allTouches allObjects] objectAtIndex:0];
+            second = [[allTouches allObjects] objectAtIndex:1];
+            initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
+            break;
+        default:
+            break;
     }
 }
 
+    //if (currentPosition.y < screen.size.width - 130 || (currentPosition.x > 130 && currentPosition.x < screen.size.height - 130)) {
+
 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
     CGRect screen = [[UIScreen mainScreen] bounds];
-    //HW_allKeysUp();
-    if (HW_isAmmoOpen()) {
-        // if we're in the menu we just click in the point
-        HW_setCursor(HWX(pointWhereToClick.x), HWY(pointWhereToClick.y));
-        HW_click();
-    } else 
-        if (isSingleClick) {
-            // if they tapped in the screen we trick the system so that camera doesn't move
-            HW_saveCursor(FALSE);
-            HW_setCursor(HWX(pointWhereToClick.x), HWY(pointWhereToClick.y));
-            HW_click();
-            HW_saveCursor(TRUE);
-            
-            // and remove the label (if any)
-            [[self.view viewWithTag:5599] removeFromSuperview];
-        } else {
-            // if weapon requires a further click, ask for tapping again
-            if (HW_isWeaponRequiringClick()) {
-                CGPoint currentPosition = [[touches anyObject] locationInView:self.view];
-                UILabel *tapAgain = [[UILabel alloc] initWithFrame:CGRectMake(currentPosition.x-100, currentPosition.y + 10, 200, 25)];
-                tapAgain.text = NSLocalizedString(@"Tap again to confirm",@"from the overlay");
-                tapAgain.backgroundColor = [UIColor clearColor];
-                tapAgain.tag = 5599;
-                tapAgain.textColor = [UIColor blueColor];
-                tapAgain.textAlignment = UITextAlignmentCenter;
-                tapAgain.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
-                [self.view addSubview:tapAgain];
-                [tapAgain release];
-            }
-        }
-
+    NSSet *allTouches = [event allTouches];
+    UITouch *touch;
+    
+    switch ([allTouches count]) {
+        case 1:
+            if (HW_isAmmoOpen()) {
+                // if we're in the menu we just click in the point
+                HW_setCursor(HWX(pointWhereToClick.x), HWY(pointWhereToClick.y));
+                HW_click();
+            } else 
+                if (isSingleClick) {
+                    // if they tapped in the screen we trick the system so that camera doesn't move
+                    HW_saveCursor(FALSE);
+                    HW_setCursor(HWX(pointWhereToClick.x), HWY(pointWhereToClick.y));
+                    HW_click();
+                    HW_saveCursor(TRUE);
+                    
+                    // and remove the label (if any)
+                    removeConfirmationInput();
+                } else {
+                    // if weapon requires a further click, ask for tapping again
+                    if (HW_isWeaponRequiringClick()) {
+                        touch = [[allTouches allObjects] objectAtIndex:0];
+                        CGPoint currentPosition = [touch locationInView:self.view];
+                        UILabel *tapAgain = [[UILabel alloc] initWithFrame:CGRectMake(currentPosition.x-100, currentPosition.y + 10, 200, 25)];
+                        tapAgain.text = NSLocalizedString(@"Tap again to confirm",@"from the overlay");
+                        tapAgain.backgroundColor = [UIColor clearColor];
+                        tapAgain.tag = CONFIRMATION_TAG;
+                        tapAgain.textColor = [UIColor blueColor];
+                        tapAgain.textAlignment = UITextAlignmentCenter;
+                        tapAgain.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
+                        [self.view addSubview:tapAgain];
+                        [tapAgain release];
+                    }
+                }
+            break;
+        case 2:
+            HW_allKeysUp();
+            break;
+    }
+    
     pointWhereToClick = CGPointZero;
     initialDistanceForPinching = 0;
     isSingleClick = NO;
 }
 
 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
-    // this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances
     [self touchesEnded:touches withEvent:event];
 }
 
 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
     CGRect screen = [[UIScreen mainScreen] bounds];
+    NSSet *allTouches = [event allTouches];
     
-    NSArray *twoTouches;
-    CGPoint currentPosition;
-    UITouch *touch = [touches anyObject];
+    UITouch *touch, *first, *second;
 
-    switch ([touches count]) {
+    switch ([allTouches count]) {
         case 1:
+            touch = [[allTouches allObjects] objectAtIndex:0];
+            CGPoint currentPosition = [touch locationInView:self.view];
             isSingleClick = NO;
-            currentPosition = [touch locationInView:self.view];
             if (HW_isAmmoOpen()) {
                 // saves the point on which to select the ammo
                 pointWhereToClick = currentPosition;
@@ -443,9 +454,8 @@
             }
             break;
         case 2:
-            twoTouches = [touches allObjects];
-            UITouch *first = [twoTouches objectAtIndex:0];
-            UITouch *second = [twoTouches objectAtIndex:1];
+            first = [[allTouches allObjects] objectAtIndex:0];
+            second = [[allTouches allObjects] objectAtIndex:1];
             CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
             const int pinchDelta = 40;
             
--- a/project_files/HedgewarsMobile/Resources/OverlayViewController.xib	Sun Jul 11 03:23:26 2010 +0200
+++ b/project_files/HedgewarsMobile/Resources/OverlayViewController.xib	Sun Jul 11 18:39:01 2010 +0200
@@ -42,6 +42,40 @@
 				<int key="NSvFlags">274</int>
 				<object class="NSMutableArray" key="NSSubviews">
 					<bool key="EncodedWithXMLCoder">YES</bool>
+					<object class="IBUIView" id="442546943">
+						<reference key="NSNextResponder" ref="191373211"/>
+						<int key="NSvFlags">268</int>
+						<string key="NSFrame">{{0, 175}, {164, 145}}</string>
+						<reference key="NSSuperview" ref="191373211"/>
+						<object class="NSColor" key="IBUIBackgroundColor">
+							<int key="NSColorSpace">3</int>
+							<bytes key="NSWhite">MQA</bytes>
+							<object class="NSColorSpace" key="NSCustomColorSpace" id="692152543">
+								<int key="NSID">2</int>
+							</object>
+						</object>
+						<bool key="IBUIOpaque">NO</bool>
+						<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
+						<float key="IBUIAlpha">0.0</float>
+						<bool key="IBUIUserInteractionEnabled">NO</bool>
+						<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+					</object>
+					<object class="IBUIView" id="358748789">
+						<reference key="NSNextResponder" ref="191373211"/>
+						<int key="NSvFlags">265</int>
+						<string key="NSFrame">{{337, 193}, {143, 127}}</string>
+						<reference key="NSSuperview" ref="191373211"/>
+						<object class="NSColor" key="IBUIBackgroundColor">
+							<int key="NSColorSpace">3</int>
+							<bytes key="NSWhite">MQA</bytes>
+							<reference key="NSCustomColorSpace" ref="692152543"/>
+						</object>
+						<bool key="IBUIOpaque">NO</bool>
+						<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
+						<float key="IBUIAlpha">0.0</float>
+						<bool key="IBUIUserInteractionEnabled">NO</bool>
+						<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+					</object>
 					<object class="IBUIButton" id="584263820">
 						<reference key="NSNextResponder" ref="191373211"/>
 						<int key="NSvFlags">268</int>
@@ -596,6 +630,8 @@
 							<reference ref="132251648"/>
 							<reference ref="752933969"/>
 							<reference ref="50885250"/>
+							<reference ref="442546943"/>
+							<reference ref="358748789"/>
 						</object>
 						<reference key="parent" ref="0"/>
 					</object>
@@ -662,6 +698,18 @@
 						<reference key="object" ref="50885250"/>
 						<reference key="parent" ref="191373211"/>
 					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">71</int>
+						<reference key="object" ref="442546943"/>
+						<reference key="parent" ref="191373211"/>
+						<string key="objectName">safezoneleft</string>
+					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">72</int>
+						<reference key="object" ref="358748789"/>
+						<reference key="parent" ref="191373211"/>
+						<string key="objectName">safezoneright</string>
+					</object>
 				</object>
 			</object>
 			<object class="NSMutableDictionary" key="flattenedProperties">
@@ -681,6 +729,8 @@
 					<string>53.IBPluginDependency</string>
 					<string>58.IBPluginDependency</string>
 					<string>67.IBPluginDependency</string>
+					<string>71.IBPluginDependency</string>
+					<string>72.IBPluginDependency</string>
 				</object>
 				<object class="NSMutableArray" key="dict.values">
 					<bool key="EncodedWithXMLCoder">YES</bool>
@@ -697,6 +747,8 @@
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+					<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 				</object>
 			</object>
 			<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -715,7 +767,7 @@
 				</object>
 			</object>
 			<nil key="sourceID"/>
-			<int key="maxID">69</int>
+			<int key="maxID">72</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">