Add error messages for failed writes to disk of settings

Changing settings would most of the time attempt to save unlock.vvv and
now also settings.vvv, but there would be no feedback whether the files
have been saved successfully or not. Now, if saving fails when changing
settings in the menu, a warning message will be shown. The setting will
still be applied of course, but the user will be informed it couldn't
be saved. This message can be silenced until the game is restarted,
because I can imagine this could get very annoying when someone already
knows their settings aren't writeable.

Also, some options didn't even save settings in the first place. These
are turning off invincibility, and by coincidence precisely all the
options in the advanced options menu. I made sure these options now do
so.
This commit is contained in:
Dav999-v
2020-11-22 03:10:26 +01:00
committed by Ethan Lee
parent d910c5118d
commit 444074a931
4 changed files with 76 additions and 33 deletions

View File

@@ -210,6 +210,8 @@ void Game::init(void)
playcustomlevel=0;
createmenu(Menu::mainmenu);
silence_settings_error = false;
deathcounts = 0;
gameoverdelay = 0;
frames = 0;
@@ -4734,7 +4736,7 @@ void Game::deserializesettings(tinyxml2::XMLElement* dataNode, ScreenSettings* s
}
}
void Game::savestats(const bool stats_only /*= true*/)
bool Game::savestats(const bool stats_only /*= true*/)
{
tinyxml2::XMLDocument doc;
bool already_exists = FILESYSTEM_loadTiXml2Document("saves/unlock.vvv", doc);
@@ -4810,11 +4812,23 @@ void Game::savestats(const bool stats_only /*= true*/)
serializesettings(dataNode);
FILESYSTEM_saveTiXml2Document("saves/unlock.vvv", doc);
bool success = FILESYSTEM_saveTiXml2Document("saves/unlock.vvv", doc);
if (!stats_only)
{
savesettings();
success = success && savesettings();
}
return success;
}
void Game::savestats_menu()
{
// Call Game::savestats(), but upon failure, go to the save error screen
if (!savestats() && !silence_settings_error)
{
createmenu(Menu::errorsavingsettings);
map.nexttowercolour();
}
}
@@ -4973,7 +4987,7 @@ void Game::loadsettings(ScreenSettings* screen_settings)
deserializesettings(dataNode, screen_settings);
}
void Game::savesettings()
bool Game::savesettings()
{
tinyxml2::XMLDocument doc;
bool already_exists = FILESYSTEM_loadTiXml2Document("saves/settings.vvv", doc);
@@ -4992,7 +5006,7 @@ void Game::savesettings()
serializesettings(dataNode);
FILESYSTEM_saveTiXml2Document("saves/settings.vvv", doc);
return FILESYSTEM_saveTiXml2Document("saves/settings.vvv", doc);
}
void Game::customstart()
@@ -6822,6 +6836,11 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ )
option("return to play menu");
menuyoff = 70;
break;
case Menu::errorsavingsettings:
option("ok");
option("silence");
menuyoff = 10;
break;
}
// Automatically center the menu. We must check the width of the menu with the initial horizontal spacing.