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();
if (state[SDLC_KEYSTATE_LALT] != 0 || state[SDLC_KEYSTATE_RALT] != 0) {
sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen());
SaveOptions();
if (gfnFullscreen != nullptr)
gfnFullscreen();
return;

1
Source/DiabloUI/selstart.cpp

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

2
Source/DiabloUI/settingsmenu.cpp

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

18
Source/diablo.cpp

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

1
Source/gamemenu.cpp

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

3
Source/gmenu.cpp

@ -14,6 +14,7 @@
#include "engine/load_cel.hpp"
#include "engine/render/cel_render.hpp"
#include "engine/render/text_render.hpp"
#include "options.h"
#include "stores.h"
#include "utils/language.h"
#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)
sgpCurrItem = sgCurrentMenuIdx > 0 ? &sgpCurrentMenu[sgCurrentMenuIdx - 1] : nullptr;
GmenuUpDown(true);
if (sgpCurrentMenu == nullptr)
SaveOptions();
}
void gmenu_draw(const Surface &out)

6
Source/options.cpp

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

1
Source/options.h

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

Loading…
Cancel
Save