Ammo menu: Show number instead F1, etc. if slot keys differ from default or in Touch interface
authorWuzzy <Wuzzy2@mail.ru>
Mon, 10 Dec 2018 21:04:37 +0100
changeset 14432 71359339a493
parent 14431 e72ffa27492d
child 14433 70fe783d0548
Ammo menu: Show number instead F1, etc. if slot keys differ from default or in Touch interface
ChangeLog.txt
hedgewars/uInputHandler.pas
hedgewars/uWorld.pas
--- a/ChangeLog.txt	Mon Dec 10 19:20:36 2018 +0100
+++ b/ChangeLog.txt	Mon Dec 10 21:04:37 2018 +0100
@@ -9,6 +9,7 @@
  * King Mode: Kill resurrected minions if king is not alive
  * Fix poison damage not working in first round
  * Hide most HUD elements in cinematic mode
+ * Don't show "F1", "F2", etc. in ammo menu if these aren't the actual slot keys
 
 Lua API:
  + New call: SetTurnTimePaused(isPaused): Call with true to pause turn time, false to unpause
--- a/hedgewars/uInputHandler.pas	Mon Dec 10 19:20:36 2018 +0100
+++ b/hedgewars/uInputHandler.pas	Mon Dec 10 21:04:37 2018 +0100
@@ -38,6 +38,10 @@
 procedure ProcessKey(event: TSDL_KeyboardEvent); inline;
 procedure ProcessKey(code: LongInt; KeyDown: boolean);
 
+{$IFDEF USE_AM_NUMCOLUMN}
+function CheckDefaultSlotKeys: boolean;
+{$ENDIF}
+
 procedure ResetKbd;
 procedure ResetMouseWheel;
 procedure FreezeEnterKey;
@@ -488,6 +492,32 @@
 end;
 
 
+{$IFDEF USE_AM_NUMCOLUMN}
+function CheckDefaultSlotKeys: boolean;
+{$IFDEF USE_TOUCH_INTERFACE}
+begin
+    CheckDefaultSlotKeys:= false;
+{$ELSE}
+var i, code: LongInt;
+begin
+    WriteLnToConsole('Check');
+    for i:=1 to cMaxSlotIndex do
+        begin
+        code:= KeyNameToCode('f'+IntToStr(i));
+        WriteLnToConsole('f'+IntToStr(i));
+        WriteLnToConsole(CurrentBinds.binds[CurrentBinds.indices[code]]);
+        if CurrentBinds.binds[CurrentBinds.indices[code]] <> 'slot '+char(i+48) then
+            begin
+            WriteLnToConsole('false');
+            CheckDefaultSlotKeys:= false;
+            exit;
+            end;
+        end;
+    WriteLnToConsole('true');
+    CheckDefaultSlotKeys:= true;
+{$ENDIF}
+end;
+{$ENDIF}
 
 {$IFNDEF MOBILE}
 procedure SetBinds(var binds: TBinds);
--- a/hedgewars/uWorld.pas	Mon Dec 10 19:20:36 2018 +0100
+++ b/hedgewars/uWorld.pas	Mon Dec 10 21:04:37 2018 +0100
@@ -63,6 +63,7 @@
     , uCommands
     , uTeams
     , uDebug
+    , uInputHandler
 {$IFDEF USE_VIDEO_RECORDING}
     , uVideoRec
 {$ENDIF}
@@ -415,7 +416,10 @@
     STurns: LongInt;
     amSurface: PSDL_Surface;
     AMRect: TSDL_Rect;
-{$IFDEF USE_AM_NUMCOLUMN}tmpsurf: PSDL_Surface;{$ENDIF}
+{$IFDEF USE_AM_NUMCOLUMN}
+    tmpsurf: PSDL_Surface;
+    usesDefaultSlotKeys: boolean;
+{$ENDIF}
 begin
     if cOnlyStats then exit(nil);
 
@@ -451,6 +455,9 @@
 
     x:= AMRect.x;
     y:= AMRect.y;
+{$IFDEF USE_AM_NUMCOLUMN}
+    usesDefaultSlotKeys:= CheckDefaultSlotKeys;
+{$ENDIF USE_AM_NUMCOLUMN}
     for i:= 0 to cMaxSlotIndex do
         if (i <> cHiddenSlotIndex) and (Ammo^[i, 0].Count > 0) then
             begin
@@ -460,7 +467,13 @@
             x:= AMRect.x;
 {$ENDIF}
 {$IFDEF USE_AM_NUMCOLUMN}
-            tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar('F' + IntToStr(i+1)), cWhiteColorChannels);
+            // Ammo slot number column
+            if usesDefaultSlotKeys then
+                // F1, F2, F3, F4, ...
+                tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar('F'+IntToStr(i+1)), cWhiteColorChannels)
+            else
+                // 1, 2, 3, 4, ...
+                tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i+1)), cWhiteColorChannels);
             copyToXY(tmpsurf, amSurface,
                      x + AMSlotPadding + (AMSlotSize shr 1) - (tmpsurf^.w shr 1),
                      y + AMSlotPadding + (AMSlotSize shr 1) - (tmpsurf^.h shr 1));