Browse Source

Save settings before leaving the settings menu

pull/3987/head
staphen 4 years ago committed by Anders Jenbo
parent
commit
df830f6495
  1. 1
      Source/DiabloUI/diabloui.cpp
  2. 1
      Source/DiabloUI/selstart.cpp
  3. 2
      Source/DiabloUI/settingsmenu.cpp
  4. 18
      Source/diablo.cpp
  5. 1
      Source/gamemenu.cpp
  6. 3
      Source/gmenu.cpp
  7. 6
      Source/options.cpp
  8. 1
      Source/options.h

1
Source/DiabloUI/diabloui.cpp

@ -436,6 +436,7 @@ void UiHandleEvents(SDL_Event *event)
const Uint8 *state = SDLC_GetKeyState(); const Uint8 *state = SDLC_GetKeyState();
if (state[SDLC_KEYSTATE_LALT] != 0 || state[SDLC_KEYSTATE_RALT] != 0) { if (state[SDLC_KEYSTATE_LALT] != 0 || state[SDLC_KEYSTATE_RALT] != 0) {
sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen()); sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen());
SaveOptions();
if (gfnFullscreen != nullptr) if (gfnFullscreen != nullptr)
gfnFullscreen(); gfnFullscreen();
return; return;

1
Source/DiabloUI/selstart.cpp

@ -19,6 +19,7 @@ void ItemSelected(int value)
{ {
auto option = static_cast<StartUpGameMode>(vecDialogItems[value]->m_value); auto option = static_cast<StartUpGameMode>(vecDialogItems[value]->m_value);
sgOptions.StartUp.gameMode.SetValue(option); sgOptions.StartUp.gameMode.SetValue(option);
SaveOptions();
endMenu = true; endMenu = true;
} }

2
Source/DiabloUI/settingsmenu.cpp

@ -354,6 +354,8 @@ void UiSettingsMenu()
CleanUpSettingsUI(); CleanUpSettingsUI();
} while (!backToMain); } while (!backToMain);
SaveOptions();
} }
} // namespace devilution } // namespace devilution

18
Source/diablo.cpp

@ -437,10 +437,12 @@ void PressKey(int vkey)
} }
sgOptions.Keymapper.KeyPressed(vkey); sgOptions.Keymapper.KeyPressed(vkey);
if (vkey == DVL_VK_RETURN) { if (vkey == DVL_VK_RETURN) {
if (GetAsyncKeyState(DVL_VK_MENU)) if (GetAsyncKeyState(DVL_VK_MENU)) {
sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen()); sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen());
else SaveOptions();
} else {
control_type_message(); control_type_message();
}
} }
if (vkey != DVL_VK_ESCAPE) { if (vkey != DVL_VK_ESCAPE) {
return; return;
@ -461,14 +463,17 @@ void PressKey(int vkey)
sgOptions.Keymapper.KeyPressed(vkey); sgOptions.Keymapper.KeyPressed(vkey);
if (PauseMode == 2) { if (PauseMode == 2) {
if (vkey == DVL_VK_RETURN && GetAsyncKeyState(DVL_VK_MENU)) if (vkey == DVL_VK_RETURN && GetAsyncKeyState(DVL_VK_MENU)) {
sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen()); sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen());
SaveOptions();
}
return; return;
} }
if (vkey == DVL_VK_RETURN) { if (vkey == DVL_VK_RETURN) {
if (GetAsyncKeyState(DVL_VK_MENU)) { if (GetAsyncKeyState(DVL_VK_MENU)) {
sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen()); sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen());
SaveOptions();
} else if (stextflag != STORE_NONE) { } else if (stextflag != STORE_NONE) {
StoreEnter(); StoreEnter();
} else if (QuestLogIsOpen) { } else if (QuestLogIsOpen) {
@ -995,8 +1000,10 @@ void DiabloSplash()
play_movie("gendata\\Hellfire.smk", true); play_movie("gendata\\Hellfire.smk", true);
else else
play_movie("gendata\\diablo1.smk", true); play_movie("gendata\\diablo1.smk", true);
if (*intro == StartUpIntro::Once) if (*intro == StartUpIntro::Once) {
intro.SetValue(StartUpIntro::Off); intro.SetValue(StartUpIntro::Off);
SaveOptions();
}
} }
if (IsAnyOf(*sgOptions.StartUp.splash, StartUpSplash::TitleDialog, StartUpSplash::LogoAndTitleDialog)) if (IsAnyOf(*sgOptions.StartUp.splash, StartUpSplash::TitleDialog, StartUpSplash::LogoAndTitleDialog))
@ -1007,8 +1014,6 @@ void DiabloDeinit()
{ {
FreeItemGFX(); FreeItemGFX();
if (sbWasOptionsLoaded && !demo::IsRunning())
SaveOptions();
if (was_snd_init) if (was_snd_init)
effects_cleanup_sfx(); effects_cleanup_sfx();
snd_deinit(); snd_deinit();
@ -1726,6 +1731,7 @@ int DiabloMain(int argc, char **argv)
// Finally load game data // Finally load game data
LoadGameArchives(); LoadGameArchives();
SaveOptions();
DiabloInit(); DiabloInit();
#ifdef __UWP__ #ifdef __UWP__

1
Source/gamemenu.cpp

@ -341,6 +341,7 @@ void gamemenu_save_game(bool /*bActivate*/)
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
if (CornerStone.activated) { if (CornerStone.activated) {
CornerstoneSave(); CornerstoneSave();
SaveOptions();
} }
interface_msg_pump(); interface_msg_pump();
SetWindowProc(saveProc); SetWindowProc(saveProc);

3
Source/gmenu.cpp

@ -14,6 +14,7 @@
#include "engine/load_cel.hpp" #include "engine/load_cel.hpp"
#include "engine/render/cel_render.hpp" #include "engine/render/cel_render.hpp"
#include "engine/render/text_render.hpp" #include "engine/render/text_render.hpp"
#include "options.h"
#include "stores.h" #include "stores.h"
#include "utils/language.h" #include "utils/language.h"
#include "utils/stdcompat/optional.hpp" #include "utils/stdcompat/optional.hpp"
@ -216,6 +217,8 @@ void gmenu_set_items(TMenuItem *pItem, void (*gmFunc)())
// BUGFIX: OOB access when sgCurrentMenuIdx is 0; should be set to NULL instead. (fixed) // BUGFIX: OOB access when sgCurrentMenuIdx is 0; should be set to NULL instead. (fixed)
sgpCurrItem = sgCurrentMenuIdx > 0 ? &sgpCurrentMenu[sgCurrentMenuIdx - 1] : nullptr; sgpCurrItem = sgCurrentMenuIdx > 0 ? &sgpCurrentMenu[sgCurrentMenuIdx - 1] : nullptr;
GmenuUpDown(true); GmenuUpDown(true);
if (sgpCurrentMenu == nullptr)
SaveOptions();
} }
void gmenu_draw(const Surface &out) void gmenu_draw(const Surface &out)

6
Source/options.cpp

@ -302,7 +302,6 @@ void OptionAudioChanged()
/** Game options */ /** Game options */
Options sgOptions; Options sgOptions;
bool sbWasOptionsLoaded = false;
#if SDL_VERSION_ATLEAST(2, 0, 0) #if SDL_VERSION_ATLEAST(2, 0, 0)
bool HardwareCursorSupported() bool HardwareCursorSupported()
@ -354,12 +353,13 @@ void LoadOptions()
if (demo::IsRunning()) if (demo::IsRunning())
demo::OverrideOptions(); demo::OverrideOptions();
sbWasOptionsLoaded = true;
} }
void SaveOptions() void SaveOptions()
{ {
if (demo::IsRunning())
return;
for (OptionCategoryBase *pCategory : sgOptions.GetCategories()) { for (OptionCategoryBase *pCategory : sgOptions.GetCategories()) {
for (OptionEntryBase *pEntry : pCategory->GetEntries()) { for (OptionEntryBase *pEntry : pCategory->GetEntries()) {
pEntry->SaveToIni(pCategory->GetKey()); pEntry->SaveToIni(pCategory->GetKey());

1
Source/options.h

@ -605,7 +605,6 @@ struct Options {
}; };
extern DVL_API_FOR_TEST Options sgOptions; extern DVL_API_FOR_TEST Options sgOptions;
extern bool sbWasOptionsLoaded;
bool HardwareCursorSupported(); bool HardwareCursorSupported();

Loading…
Cancel
Save