From 9891d34abb571660f96a35dadb129e5d6f97c476 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Fri, 21 Feb 2025 22:42:28 +0100 Subject: [PATCH] fixed bugs with showing correct game buttons for various cases 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 | 65 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/src/game.c b/src/game.c index 42178c7e..94d114bd 100644 --- a/src/game.c +++ b/src/game.c @@ -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(); } } -- 2.34.1