added setup option to save setup without "save and exit" menu entry
authorHolger Schemel <holger.schemel@virtion.de>
Tue, 12 Nov 2024 19:52:02 +0000 (20:52 +0100)
committerHolger Schemel <holger.schemel@virtion.de>
Tue, 12 Nov 2024 19:52:05 +0000 (20:52 +0100)
src/events.c
src/files.c
src/files.h
src/libgame/system.h
src/screens.c
src/tools.c

index 3603e32c09b7489e83aacbef0e07d6454dd67cfc..b25bce3e87bc34884728c64ec0bac1bf55944af0 100644 (file)
@@ -666,6 +666,9 @@ void HandleWindowEvent(WindowEvent *event)
        UpdateMousePosition();
 
        SetWindowTitle();
+
+        // required if executed from outside setup menu
+        SaveSetupIfNeeded();
       }
     }
 #if defined(PLATFORM_ANDROID)
index 9496b89ef804ff87df059bf89f7ebd9fd64a6e31..43f8f5c082b3c4371acc1021b119fcd37b88c3b2 100644 (file)
@@ -11015,6 +11015,10 @@ static struct TokenInfo global_setup_tokens[] =
     TYPE_SWITCH,
     &setup.show_undo_redo_buttons,             "show_undo_redo_buttons"
   },
+  {
+    TYPE_SWITCH,
+    &setup.show_menu_to_save_setup,            "show_menu_to_save_setup"
+  },
   {
     TYPE_STRING,
     &setup.scores_in_highscore_list,           "scores_in_highscore_list"
@@ -11867,6 +11871,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->small_game_graphics = FALSE;
   si->show_load_save_buttons = FALSE;
   si->show_undo_redo_buttons = FALSE;
+  si->show_menu_to_save_setup = FALSE;
   si->scores_in_highscore_list = getStringCopy(STR_SCORES_TYPE_DEFAULT);
 
   si->graphics_set = getStringCopy(GFX_CLASSIC_SUBDIR);
@@ -12776,6 +12781,13 @@ void SaveSetup(void)
   SaveSetup_EditorCascade();
 }
 
+void SaveSetupIfNeeded(void)
+{
+  // save changed setup value if "save and exit" menu disabled
+  if (!setup.show_menu_to_save_setup)
+    SaveSetup();
+}
+
 static void SaveSetup_WriteGameControllerMappings(SetupFileHash *mappings_hash,
                                                  char *filename)
 {
index c122716b60fb8dc672db78903bad35f43f8961a0..cf379db6264ebf1a61291e18bbf3672a3ab55342 100644 (file)
@@ -94,6 +94,7 @@ void SaveSetup_EditorCascade(void);
 
 void LoadSetup(void);
 void SaveSetup(void);
+void SaveSetupIfNeeded(void);
 
 void SaveSetup_AddGameControllerMapping(char *);
 
index 16a00b6c0a73a2f1533bdd32d81b2873bbcc634e..84d401cef7d39f2eb54204205b41e9a928b68631 100644 (file)
@@ -1546,6 +1546,7 @@ struct SetupInfo
   boolean small_game_graphics;
   boolean show_load_save_buttons;
   boolean show_undo_redo_buttons;
+  boolean show_menu_to_save_setup;
   char *scores_in_highscore_list;
 
   char *graphics_set;
index 27ef88a69d650095a5c8548801d2da4636035072..a26d2d11859e56c132691dc7e9e3e6a3fbba26ef 100644 (file)
@@ -356,6 +356,7 @@ static void AdjustScoreInfoButtons_PlayTape(int, int, boolean);
 
 static boolean OfferUploadTapes(void);
 static void execOfferUploadTapes(void);
+static void execSaveAndExitSetup(void);
 
 static void DrawHallOfFame_setScoreEntries(void);
 static void HandleHallOfFame_SelectLevel(int, int);
@@ -5731,6 +5732,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
            execSetupTouch();
          else
            execSetupArtwork();
+
+          SaveSetupIfNeeded();
        }
        else
        {
@@ -8339,6 +8342,7 @@ static struct TokenInfo setup_info_game[] =
   { TYPE_STRING,       &snapshot_mode_text,            ""                              },
   { TYPE_SWITCH,       &setup.show_load_save_buttons,  "Show Load/Save Buttons:"       },
   { TYPE_SWITCH,       &setup.show_undo_redo_buttons,  "Show Undo/Redo Buttons:"       },
+  { TYPE_SWITCH,       &setup.show_menu_to_save_setup, "Show Menu to Save Setup:"      },
   { TYPE_EMPTY,                NULL,                           ""                              },
   { TYPE_LEAVE_MENU,   execSetupMain,                  "Back"                          },
 
@@ -8987,6 +8991,8 @@ static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
   // update old setup options from new setup options
   if (si->value == &setup.allow_skipping_levels)
     UpdateHandicapAndSkipLevels();
+
+  SaveSetupIfNeeded();
 }
 
 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)
@@ -9055,6 +9061,11 @@ static void DrawSetupScreen_Generic(void)
   {
     setup_info = setup_info_main;
     title_string = STR_SETUP_MAIN;
+
+    if (!setup.show_menu_to_save_setup)
+      setHideSetupEntry(execSaveAndExitSetup);
+    else
+      removeHideSetupEntry(execSaveAndExitSetup);
   }
   else if (setup_mode == SETUP_MODE_GAME)
   {
index a6d5aa47c0a2918c55a4f3bafd328e5722d07969..8416aae1c1c7588df7d01d6775fedcbae9f7a4fd 100644 (file)
@@ -14,6 +14,7 @@
 #include "libgame/libgame.h"
 
 #include "tools.h"
+#include "files.h"
 #include "init.h"
 #include "game.h"
 #include "events.h"
@@ -11886,6 +11887,9 @@ void ToggleFullscreenIfNeeded(void)
 
   // set setup value according to successfully changed fullscreen mode
   setup.fullscreen = video.fullscreen_enabled;
+
+  // required if executed from outside setup menu
+  SaveSetupIfNeeded();
 }
 
 void ChangeWindowScalingIfNeeded(void)
@@ -11899,6 +11903,9 @@ void ChangeWindowScalingIfNeeded(void)
 
   // set setup value according to successfully changed window scaling
   setup.window_scaling_percent = video.window_scaling_percent;
+
+  // required if executed from outside setup menu
+  SaveSetupIfNeeded();
 }
 
 void ChangeVsyncModeIfNeeded(void)