more updates on touch input/control
authorkoda
Sat, 24 Oct 2009 13:50:31 +0000
changeset 2579 e5e4ebf528b5
parent 2578 ec8e69b23097
child 2580 aeccc8f51d3f
more updates on touch input/control
hedgewars/CCHandlers.inc
hedgewars/SDLh.pas
hedgewars/hwengine.pas
hedgewars/uGame.pas
hedgewars/uKeys.pas
hedgewars/uTeams.pas
hedgewars/uWorld.pas
--- a/hedgewars/CCHandlers.inc	Fri Oct 23 11:12:01 2009 +0000
+++ b/hedgewars/CCHandlers.inc	Sat Oct 24 13:50:31 2009 +0000
@@ -724,12 +724,22 @@
 
 procedure chZoomIn(var s: shortstring);
 begin
-if ZoomValue < 3.0 then ZoomValue:= ZoomValue + 0.25;
+{$IFDEF IPHONEOS}
+if ZoomValue < 3.5 then
+{$ELSE}
+if ZoomValue < 3.0 then
+{$ENDIF}
+        ZoomValue:= ZoomValue + 0.25;
 end;
 
 procedure chZoomOut(var s: shortstring);
 begin
-if ZoomValue > 1.0 then ZoomValue:= ZoomValue - 0.25;
+{$IFDEF IPHONEOS}
+if ZoomValue > 0.5 then
+{$ELSE}
+if ZoomValue > 1.0 then
+{$ENDIF}
+        ZoomValue:= ZoomValue - 0.25;
 end;
 
 procedure chZoomReset(var s: shortstring);
--- a/hedgewars/SDLh.pas	Fri Oct 23 11:12:01 2009 +0000
+++ b/hedgewars/SDLh.pas	Sat Oct 24 13:50:31 2009 +0000
@@ -402,7 +402,7 @@
 function  SDL_GetMouseState(index: LongInt; x, y: PLongInt): Byte; cdecl; external SDLLibName;
 function  SDL_SelectMouse(index: LongInt): LongInt; cdecl; external SDLLibName;
 function  SDL_GetRelativeMouseState(index: LongInt; x, y: PLongInt): Byte; cdecl; external SDLLibName;
-function  SDL_GetNumMice : LongInt; cdecl; external SDLLibName;
+function  SDL_GetNumMice: LongInt; cdecl; external SDLLibName;
 {$ELSE}
 function  SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName;
 function  SDL_GetMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
--- a/hedgewars/hwengine.pas	Fri Oct 23 11:12:01 2009 +0000
+++ b/hedgewars/hwengine.pas	Sat Oct 24 13:50:31 2009 +0000
@@ -164,10 +164,12 @@
     CurrTime: Longword;
     event: TSDL_Event;
 {$IFDEF IPHONEOS}
-    mouseState: byte;
+type TDirection = (nodir, left, right);
+var mouseState: byte;
     x, y: LongInt;
     oldy: LongInt = 240;
-oldJoy: LongInt =0;
+    oldJoy: LongInt =0;
+    dir: TDirection = nodir;
 {$ENDIF}
 begin
 PrevTime:= SDL_GetTicks;
@@ -187,7 +189,10 @@
         {*MoveCamera is in uWord.pas -- conflicts with other commands*}
         {*Keys are in uKeys.pas*}
                 SDL_MOUSEBUTTONDOWN: begin
+                                AddFileLog('*********************************************       touch down');
+
                         mouseState:= SDL_GetMouseState(0, @x, @y);
+
                         if x <= 50 then 
                         begin
 {$IFDEF DEBUGFILE}
@@ -215,26 +220,37 @@
                         if (y > 430) and (x > 50) and (x <= 135) then
                         begin
 {$IFDEF DEBUGFILE}
-                                AddFileLog('Space -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
+                                AddFileLog('Enter -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
 {$ENDIF}
-                                ParseCommand('ljump', true);
+                       uKeys.enterKey:=true;
                         end;
                         if (y > 430) and (x > 185) and (x <= 270) then
                         begin
 {$IFDEF DEBUGFILE}
                                 AddFileLog('Backspace -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
 {$ENDIF}
-                                ParseCommand('hjump', true);
+                       uKeys.backspaceKey:=true;
+
                         end;
                         if (y <= 50) and (x > 50) and (x <= 270) then
                         begin
 {$IFDEF DEBUGFILE}
-                                AddFileLog('Backspace -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
+                                AddFileLog('Space DOWN -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
 {$ENDIF}
-                                //ParseCommand('hjump', true);
+                        uKeys.spaceKey:= true;
+                        uKeys.isAttacking:= true;
+                        end
+                        else
+                        begin
+                                AddFileLog('Space UP -- x: ' + inttostr(x) + ' y: ' + inttostr(y));
+                                uKeys.isAttacking:= false;
                         end;
                 end;
                 SDL_MOUSEBUTTONUP: begin
+                                AddFileLog('*********************************************       touch up');
+
+                        if bShowAmmoMenu = true then ParseCommand('/put', true);
+
                         mouseState:= SDL_GetMouseState(0, @x, @y);
                         {* open ammo menu *}
                         if (y > 430) and (x > 270) then
@@ -260,10 +276,23 @@
                         begin
                                 if (modulo(event.jaxis.value) > (oldJoy + 400)) or (modulo(event.jaxis.value) < (oldJoy - 400)) then
                                 begin
-                                        if event.jaxis.value > 1500 then ParseCommand('+right', true) else
-                                        if event.jaxis.value <= -1500 then ParseCommand('+left', true) else
-                                        if (event.jaxis.value > 0) and (event.jaxis.value <= 1500) then ParseCommand('-right', true) else
-                                        if (event.jaxis.value <= 0) and (event.jaxis.value > -1500) then ParseCommand('-left', true); 
+                                        if event.jaxis.value > 1500 then
+                                        begin
+                                                if dir <> right then ParseCommand('-left', true);
+                                                ParseCommand('+right', true);
+                                                dir:= right;
+                                        end
+                                        else
+                                                if event.jaxis.value <= -1500 then
+                                                begin 
+                                                        if dir <> left then ParseCommand('-right', true);
+                                                        ParseCommand('+left', true);
+                                                        dir:= left;
+                                                end
+                                                else
+                                                        if (event.jaxis.value > 0) and (event.jaxis.value <= 1500) then ParseCommand('-right', true)
+                                                else
+                                                                if (event.jaxis.value <= 0) and (event.jaxis.value > -1500) then ParseCommand('-left', true); 
 {$IFDEF DEBUGFILE}
                                         AddFileLog('Joystick value: ' + inttostr(event.jaxis.value) + ' oldJoy: ' + inttostr(oldJoy));
 {$ENDIF}
--- a/hedgewars/uGame.pas	Fri Oct 23 11:12:01 2009 +0000
+++ b/hedgewars/uGame.pas	Sat Oct 24 13:50:31 2009 +0000
@@ -64,7 +64,9 @@
                         end;
                gmtSave: begin
                         RestoreTeamsFromSave;
+{$IFNDEF IPHONEOS}
                         SetBinds(CurrentTeam^.Binds);
+{$ENDIF}
                         //CurrentHedgehog^.Gear^.Message:= 0; <- produces bugs with further save restoring and demos
                         isSoundEnabled:= isSEBackup;
                         GameType:= gmtLocal
--- a/hedgewars/uKeys.pas	Fri Oct 23 11:12:01 2009 +0000
+++ b/hedgewars/uKeys.pas	Sat Oct 24 13:50:31 2009 +0000
@@ -52,8 +52,11 @@
 rightKey: boolean = false;
 leftKey: boolean = false;
 
+backspaceKey: boolean = false;
 spaceKey: boolean = false;
 enterKey: boolean = false;
+isAttacking:boolean = false;
+
 {$ENDIF}
 	ControllerNumControllers: Integer;
     ControllerEnabled: Integer;
@@ -105,8 +108,10 @@
 k    := SDL_GetMouseState(nil, nil);
 {$ENDIF}
 
+{$IFNDEF IPHONEOS}
 for i:= 6 to pred(j) do // first 6 will be overwritten
 	tkbdn[i]:= pkbd^[i];
+{$ENDIF}
 
 // mouse buttons
 {$IFDEF DARWIN}
@@ -131,24 +136,25 @@
 middleClick:= false;
 rightClick:= false;
 
-{*
 //sdl1.3 for these keys is messed up
-tkbdn[273]:= ord(upKey);
-tkbdn[274]:= ord(downKey);
-tkbdn[275]:= ord(rightKey);
-tkbdn[276]:= ord(leftKey);
+//tkbdn[MYCONST]:= ord(upKey);
+//tkbdn[MYCONST + 1]:= ord(downKey);
+//tkbdn[MYCONST + 2]:= ord(rightKey);
+//tkbdn[MYCONST + 3]:= ord(leftKey);
 
+tkbdn[ 8]:= ord(backspaceKey);
+tkbdn[13]:= ord(enterKey);
 tkbdn[32]:= ord(spaceKey);
-tkbdn[13]:= ord(enterKey);
 
 upKey:= false;
 downKey:= false;
 rightKey:= false;
 leftKey:= false;
 
-spaceKey:= false;
+if isAttacking = false then spaceKey:= false;
 enterKey:= false;
-*}
+backspaceKey:= false;
+
 {$ENDIF}
 
 // Controller(s)
@@ -195,7 +201,7 @@
 end;
 
 procedure ResetKbd;
-var i, j, k, t: LongInt;
+var i, j, k, t,tmp: LongInt;
     pkbd: PByteArray;
 begin
 
@@ -208,8 +214,10 @@
 {$ENDIF}
 TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + inttostr(j) + ')', true);
 
+{$IFNDEF IPHONEOS}
 for i:= 1 to pred(j) do
 	tkbdn[i]:= pkbd^[i];
+{$ENDIF}
 
 // mouse buttons
 {$IFDEF DARWIN}
@@ -234,23 +242,24 @@
 middleClick:= false;
 rightClick:= false;
 
-{*
-tkbdn[273]:= ord(upKey);
-tkbdn[274]:= ord(downKey);
-tkbdn[275]:= ord(rightKey);
-tkbdn[276]:= ord(leftKey);
+//sdl1.3 for these keys is messed up
+//tkbdn[MYCONST]:= ord(upKey);
+//tkbdn[MYCONST + 1]:= ord(downKey);
+//tkbdn[MYCONST + 2]:= ord(rightKey);
+//tkbdn[MYCONST + 3]:= ord(leftKey);
 
+tkbdn[ 8]:= ord(backspaceKey);
+tkbdn[13]:= ord(enterKey);
 tkbdn[32]:= ord(spaceKey);
-tkbdn[13]:= ord(enterKey);
 
 upKey:= false;
 downKey:= false;
 rightKey:= false;
 leftKey:= false;
 
-spaceKey:= false;
+if isAttacking = false then spaceKey:= false;
 enterKey:= false;
-*}
+backspaceKey:= false;
 {$ENDIF}
 
 // Controller(s)
@@ -334,6 +343,14 @@
 		inc(k, 1);
 		end;
 	end;
+{$IFDEF IPHONEOS}
+
+DefaultBinds[  3]:= 'ammomenu';
+DefaultBinds[  8]:= 'hjump';
+DefaultBinds[ 13]:= 'ljump';
+DefaultBinds[ 32]:= '+attack';
+
+{$ENDIF}
 	
 DefaultBinds[ 27]:= 'quit';
 DefaultBinds[ 96]:= 'history';
--- a/hedgewars/uTeams.pas	Fri Oct 23 11:12:01 2009 +0000
+++ b/hedgewars/uTeams.pas	Sat Oct 24 13:50:31 2009 +0000
@@ -233,7 +233,9 @@
 {$IFDEF DEBUGFILE}AddFileLog('Wind = '+FloatToStr(cWindSpeed));{$ENDIF}
 ApplyAmmoChanges(CurrentHedgehog^);
 
+{$IFNDEF IPHONEOS}
 if not CurrentTeam^.ExtDriven then SetBinds(CurrentTeam^.Binds);
+{$ENDIF}
 
 bShowFinger:= true;
 
--- a/hedgewars/uWorld.pas	Fri Oct 23 11:12:01 2009 +0000
+++ b/hedgewars/uWorld.pas	Sat Oct 24 13:50:31 2009 +0000
@@ -96,8 +96,8 @@
    begin
    if AMxShift = 0 then
       begin
-      CursorPoint.X:= cScreenWidth div 2;
-      CursorPoint.Y:= cScreenHeight div 2;
+      CursorPoint.X:= cScreenWidth shr 1;
+      CursorPoint.Y:= cScreenHeight shr 1;
       prevPoint:= CursorPoint;
       SDL_WarpMouse(CursorPoint.X  + cScreenWidth div 2, cScreenHeight - CursorPoint.Y)
       end;
@@ -114,7 +114,7 @@
 	begin
 	if Ammo = nil then exit;
 	SlotsNum:= 0;
-	x:= cScreenWidth div 2 - 210 + AMxShift;
+	x:= (cScreenWidth shr 1) - 210 + AMxShift;
 	y:= cScreenHeight - 40;
 	dec(y);
 	DrawSprite(sprAMBorders, x, y, 0);
@@ -345,7 +345,7 @@
 {$IFDEF IPHONEOS}
 {* see the code in MainLoop *}
 SDL_GetMouseState(0, @x, @y);
-if (x > 100) and (x < 220) and (y > 200) and (y < 280) then
+if ((x > 100) and (x <= 220) and (y > 200) and (y <= 280)) and bShowAmmoMenu <> false then
 {$ENDIF}
 if not isPaused then MoveCamera;
 
@@ -359,8 +359,8 @@
     end;
 
 // Waves
-DrawWaves( 1,  0, - (cWaveHeight * 2));
-DrawWaves(-1, 100, - (cWaveHeight + cWaveHeight div 2));
+DrawWaves( 1,  0, - (cWaveHeight shl 1));
+DrawWaves(-1, 100, - (cWaveHeight + (cWaveHeight shr 1)));
 
 
 DrawLand(WorldDx, WorldDy);