Add button to set bounciness in touch interface
authorWuzzy <Wuzzy2@mail.ru>
Thu, 10 Jan 2019 17:54:58 +0100
changeset 14559 1dab5d92aca7
parent 14558 ce40351e0690
child 14560 c36d67d6366d
Add button to set bounciness in touch interface
hedgewars/uTouch.pas
hedgewars/uTypes.pas
hedgewars/uVariables.pas
hedgewars/uWorld.pas
project_files/Android-build/SDL-android-project/assets/Data/Graphics/Buttons/bouncebutton.png
--- a/hedgewars/uTouch.pas	Thu Jan 10 03:14:02 2019 +0100
+++ b/hedgewars/uTouch.pas	Thu Jan 10 17:54:58 2019 +0100
@@ -22,7 +22,7 @@
 
 interface
 
-uses SysUtils, uUtils, uConsole, uVariables, SDLh, uFloat, uConsts, uCommands, GLUnit, uTypes, uCaptions, uAmmos, uWorld;
+uses SysUtils, uUtils, uConsole, uVariables, SDLh, uFloat, uConsts, uCommands, GLUnit, uTypes, uCaptions, uWorld, uGearsHedgehog;
 
 
 procedure initModule;
@@ -89,7 +89,7 @@
 procedure onTouchDown(x, y: Single; pointerId: TSDL_FingerId);
 var
     finger: PTouch_Data;
-    xr, yr: LongWord;
+    xr, yr, tmp: LongWord;
 begin
 xr:= round(x * cScreenWidth);
 yr:= round(y * cScreenHeight);
@@ -159,10 +159,35 @@
     if(CurrentHedgehog <> nil) then
         begin
         if Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_Timerable <> 0 then
-            ParseTeamCommand('/timer ' + inttostr((GetCurAmmoEntry(CurrentHedgeHog^)^.Timer div 1000) mod 5 + 1));
+            begin
+            tmp:= HHGetTimerMsg(CurrentHedgehog^.Gear);
+            if tmp <> MSGPARAM_INVALID then
+                ParseTeamCommand('/timer ' + inttostr(tmp mod 5 + 1));
+            end;
         end;
     exit;
     end;
+
+if isOnWidget(utilityWidget2, finger^) then
+    begin
+    finger^.pressedWidget:= @utilityWidget2;
+    moveCursor:= false;
+    if(CurrentHedgehog <> nil) then
+        begin
+        if Ammoz[CurrentHedgehog^.CurAmmoType].Ammo.Propz and ammoprop_SetBounce <> 0 then
+            begin
+            tmp := HHGetBouncinessMsg(CurrentHedgehog^.Gear);
+            if tmp <> MSGPARAM_INVALID then
+                begin
+                ParseTeamCommand('+precise');
+                ParseTeamCommand('timer ' + inttostr(tmp mod 5 + 1));
+                bounceButtonPressed:= true;
+                end;
+            end;
+        end;
+    exit;
+    end;
+
 dec(buttonsDown);//no buttonsDown, undo the inc() above
 if buttonsDown = 0 then
     begin
@@ -496,6 +521,12 @@
             aimingDown:= false;
             end;
         end;
+
+if bounceButtonPressed then
+    begin
+    ParseTeamCommand('-precise');
+    bounceButtonPressed:= false;
+    end;
 end;
 
 function findFinger(id: TSDL_FingerId): PTouch_Data;
@@ -627,6 +658,7 @@
 begin
     buttonsDown:= 0;
     pointerCount:= 0;
+    bounceButtonPressed:= false;
 
     setLength(fingers, 4);
     for index := 0 to (Length(fingers)-1) do
--- a/hedgewars/uTypes.pas	Thu Jan 10 03:14:02 2019 +0100
+++ b/hedgewars/uTypes.pas	Thu Jan 10 17:54:58 2019 +0100
@@ -61,7 +61,7 @@
 {$IFDEF USE_TOUCH_INTERFACE}
             sprFireButton, sprArrowUp, sprArrowDown, sprArrowLeft, sprArrowRight,
             sprJumpWidget, sprAMWidget, sprPauseButton, sprTimerButton, sprTargetButton,
-            sprSwitchButton,
+            sprSwitchButton, sprBounceButton,
 {$ENDIF}
             sprFlake, sprHandRope, sprHandBazooka, sprHandShotgun,
             sprHandDEagle, sprHandAirAttack, sprHandBaseball, sprPHammer,
--- a/hedgewars/uVariables.pas	Thu Jan 10 03:14:02 2019 +0100
+++ b/hedgewars/uVariables.pas	Thu Jan 10 17:54:58 2019 +0100
@@ -283,10 +283,12 @@
 //Buttons
 {$IFDEF USE_TOUCH_INTERFACE}
     buttonScale: GLFloat;
+    bounceButtonPressed: boolean;
 
     arrowUp, arrowDown, arrowLeft, arrowRight : TOnScreenWidget;
     firebutton, jumpWidget, AMWidget          : TOnScreenWidget;
     pauseButton, utilityWidget                : TOnScreenWidget;
+    utilityWidget2                            : TOnScreenWidget;
 {$ENDIF}
 
 
@@ -487,6 +489,8 @@
             Width: 128; Height: 128; imageWidth: 0; imageHeight: 0; saveSurf: false; critical: true; checkSum: false; priority: tpHigh; getDimensions: false; getImageDimensions: true), // sprTargetButton
             (FileName: 'switchbutton'; Path: ptButtons; AltPath: ptNone; Texture: nil; Surface: nil;
             Width: 128; Height: 128; imageWidth: 0; imageHeight: 0; saveSurf: false; critical: true; checkSum: false; priority: tpHigh; getDimensions: false; getImageDimensions: true), // sprSwitchButton
+            (FileName: 'bouncebutton'; Path: ptButtons; AltPath: ptNone; Texture: nil; Surface: nil;
+            Width: 128; Height: 128; imageWidth: 0; imageHeight: 0; saveSurf: false; critical: true; checkSum: false; priority: tpHigh; getDimensions: false; getImageDimensions: true), // sprBounceButton
 {$ENDIF}
             (FileName:      'Flake'; Path:ptCurrTheme; AltPath: ptNone; Texture: nil; Surface: nil;
             Width:  64; Height: 64; imageWidth: 0; imageHeight: 0; saveSurf: false; critical: true; checkSum: false; priority: tpHighest; getDimensions: false; getImageDimensions: true),// sprFlake
--- a/hedgewars/uWorld.pas	Thu Jan 10 03:14:02 2019 +0100
+++ b/hedgewars/uWorld.pas	Thu Jan 10 17:54:58 2019 +0100
@@ -396,6 +396,28 @@
         source.y:= frame.y;
         end;
     end;
+
+with utilityWidget2 do
+    begin
+    show:= false;
+    sprite:= sprBounceButton;
+    frame.w:= Round(spritesData[sprite].Texture^.w * buttonScale);
+    frame.h:= Round(spritesData[sprite].Texture^.h * buttonScale);
+    frame.x:= utilityWidget.frame.x + Round(frame.w * 1.25);
+    frame.y:= arrowLeft.frame.y - Round(frame.h * 1.25);
+    active.x:= frame.x;
+    active.y:= frame.y;
+    active.w:= frame.w;
+    active.h:= frame.h;
+    with moveAnim do
+        begin
+        target.x:= frame.x;
+        target.y:= frame.y;
+        source.x:= frame.x;
+        source.y:= frame.y;
+        end;
+    end;
+
 {$ENDIF}
 end;
 
@@ -1621,6 +1643,7 @@
 DrawScreenWidget(@jumpWidget);
 DrawScreenWidget(@AMWidget);
 DrawScreenWidget(@utilityWidget);
+DrawScreenWidget(@utilityWidget2);
 DrawScreenWidget(@pauseButton);
 {$ENDIF}
 
@@ -2130,6 +2153,14 @@
         end
     else if utilityWidget.show then
         animateWidget(@utilityWidget, true, false);
+
+    if ((Ammoz[ammoType].Ammo.Propz and ammoprop_SetBounce) <> 0) then
+        begin
+        utilityWidget2.sprite:= sprBounceButton;
+        animateWidget(@utilityWidget2, true, true);
+        end
+    else if utilityWidget2.show then
+        animateWidget(@utilityWidget2, true, false);
 {$ELSE}
 ammoType:= ammoType; // avoid hint
 {$ENDIF}
Binary file project_files/Android-build/SDL-android-project/assets/Data/Graphics/Buttons/bouncebutton.png has changed