fixed bugs with showing correct game buttons for various cases
authorHolger Schemel <info@artsoft.org>
Fri, 21 Feb 2025 21:42:28 +0000 (22:42 +0100)
committerHolger Schemel <info@artsoft.org>
Fri, 21 Feb 2025 17:43:11 +0000 (18:43 +0100)
This change should fix problems (like multiple mapped or wrong buttons
at the same screen position) with various combinations of game button
positions (if defined in custom artwork set) and setup options to show
load/save buttons and/or undo/redo buttons (which might happen because
stop/save/undo buttons and play/load/redo/restart buttons are defined
to be at the same screen position by default).

src/game.c

index 42178c7ede6d5260b14c7492bda96f20f965694f..94d114bd2d03621d409dbadfd4007095f223d354 100644 (file)
@@ -17577,31 +17577,66 @@ static void UnmapGameButtonsAtSamePosition(int id)
       UnmapGadget(game_gadget[i]);
 }
 
+static void UnmapGameButtonsAtSamePositionIfMapped(int id)
+{
+  if (isMappedGadget(game_gadget[id]))
+    UnmapGameButtonsAtSamePosition(id);
+}
+
+static void UnmapGameButtonsAtSamePositionIfMapped_LoadSaveGroup(void)
+{
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_SAVE);
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_PAUSE2);
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_LOAD);
+}
+
+static void UnmapGameButtonsAtSamePositionIfMapped_UndoRedoGroup(void)
+{
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_UNDO);
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_PAUSE2);
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_REDO);
+}
+
+static void UnmapGameButtonsAtSamePositionIfMapped_StopPlayGroup(void)
+{
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_STOP);
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_PAUSE);
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_PLAY);
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_RESTART);
+
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_PANEL_STOP);
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_PANEL_PAUSE);
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_PANEL_PLAY);
+  UnmapGameButtonsAtSamePositionIfMapped(GAME_CTRL_ID_PANEL_RESTART);
+}
+
 static void UnmapGameButtonsAtSamePosition_All(void)
 {
+  // make sure that only one button is mapped for multiple buttons at the same position
+
   if (setup.show_load_save_buttons)
   {
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_SAVE);
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_PAUSE2);
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_LOAD);
+    UnmapGameButtonsAtSamePositionIfMapped_LoadSaveGroup();
+
+    // if above buttons have redefined position, do the same for the remaining buttons
+    if (setup.show_undo_redo_buttons)
+      UnmapGameButtonsAtSamePositionIfMapped_UndoRedoGroup();
+    else
+      UnmapGameButtonsAtSamePositionIfMapped_StopPlayGroup();
   }
   else if (setup.show_undo_redo_buttons)
   {
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_UNDO);
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_PAUSE2);
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_REDO);
+    UnmapGameButtonsAtSamePositionIfMapped_UndoRedoGroup();
+
+    // if above buttons have redefined position, do the same for the remaining buttons
+    if (setup.show_load_save_buttons)
+      UnmapGameButtonsAtSamePositionIfMapped_LoadSaveGroup();
+    else
+      UnmapGameButtonsAtSamePositionIfMapped_StopPlayGroup();
   }
   else
   {
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_STOP);
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_PAUSE);
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_PLAY);
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_RESTART);
-
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_PANEL_STOP);
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_PANEL_PAUSE);
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_PANEL_PLAY);
-    UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_PANEL_RESTART);
+    UnmapGameButtonsAtSamePositionIfMapped_StopPlayGroup();
   }
 }