From 444074a931c9a8c67e8c64e1d23b30b9515686e3 Mon Sep 17 00:00:00 2001 From: Dav999-v Date: Sun, 22 Nov 2020 03:10:26 +0100 Subject: [PATCH] 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. --- desktop_version/src/Game.cpp | 29 +++++++++++--- desktop_version/src/Game.h | 8 +++- desktop_version/src/Input.cpp | 69 +++++++++++++++++++++------------- desktop_version/src/Render.cpp | 3 ++ 4 files changed, 76 insertions(+), 33 deletions(-) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 86668dd3..b2fd2d2c 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -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. diff --git a/desktop_version/src/Game.h b/desktop_version/src/Game.h index 7b1efb7c..da6c0c45 100644 --- a/desktop_version/src/Game.h +++ b/desktop_version/src/Game.h @@ -32,6 +32,7 @@ namespace Menu quickloadlevel, youwannaquit, errornostart, + errorsavingsettings, graphicoptions, ed_settings, ed_desc, @@ -132,7 +133,8 @@ public: void loadstats(ScreenSettings* screen_settings); - void savestats(const bool stats_only = false); + bool savestats(const bool stats_only = false); + void savestats_menu(); void deletestats(); @@ -142,7 +144,7 @@ public: void loadsettings(ScreenSettings* screen_settings); - void savesettings(); + bool savesettings(); void deletesettings(); @@ -260,6 +262,8 @@ public: int creditposx, creditposy, creditposdelay; int oldcreditposx; + bool silence_settings_error; + //Sine Wave Ninja Minigame bool swnmode; diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 290d735d..ba2ee1f5 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -385,16 +385,17 @@ void menuactionpress() case 0: music.playef(11); graphics.screenbuffer->toggleFullScreen(); - game.savestats(); // Recreate menu to update "resize to nearest" game.createmenu(game.currentmenuname, true); game.currentmenuoption = 0; + + game.savestats_menu(); break; case 1: music.playef(11); graphics.screenbuffer->toggleStretchMode(); - game.savestats(); + game.savestats_menu(); break; case 2: // resize to nearest multiple @@ -402,7 +403,7 @@ void menuactionpress() { music.playef(11); graphics.screenbuffer->ResizeToNearestMultiple(); - game.savestats(); + game.savestats_menu(); } else { @@ -412,19 +413,19 @@ void menuactionpress() case 3: music.playef(11); graphics.screenbuffer->toggleLinearFilter(); - game.savestats(); + game.savestats_menu(); break; case 4: //change smoothing music.playef(11); graphics.screenbuffer->badSignalEffect= !graphics.screenbuffer->badSignalEffect; - game.savestats(); + game.savestats_menu(); break; case 5: //toggle 30+ fps music.playef(11); game.over30mode = !game.over30mode; - game.savestats(); + game.savestats_menu(); break; case 6: //toggle vsync @@ -432,7 +433,7 @@ void menuactionpress() #ifndef __HAIKU__ // FIXME: Remove after SDL VSync bug is fixed! -flibit graphics.screenbuffer->vsync = !graphics.screenbuffer->vsync; graphics.screenbuffer->resetRendererWorkaround(); - game.savestats(); + game.savestats_menu(); #endif break; default: @@ -476,10 +477,10 @@ void menuactionpress() break; default: map.invincibility = !map.invincibility; - game.savestats(); music.playef(11); game.returnmenu(); map.nexttowercolour(); + game.savestats_menu(); break; } break; @@ -489,35 +490,35 @@ void menuactionpress() case 0: //back game.slowdown = 30; - game.savestats(); music.playef(11); game.returnmenu(); game.currentmenuoption = 4; map.nexttowercolour(); + game.savestats_menu(); break; case 1: game.slowdown = 24; - game.savestats(); music.playef(11); game.returnmenu(); game.currentmenuoption = 4; map.nexttowercolour(); + game.savestats_menu(); break; case 2: game.slowdown = 18; - game.savestats(); music.playef(11); game.returnmenu(); game.currentmenuoption = 4; map.nexttowercolour(); + game.savestats_menu(); break; case 3: game.slowdown = 12; - game.savestats(); music.playef(11); game.returnmenu(); game.currentmenuoption = 4; map.nexttowercolour(); + game.savestats_menu(); break; } break; @@ -535,26 +536,31 @@ void menuactionpress() SDL_ShowCursor(SDL_ENABLE); graphics.showmousecursor = true; } + game.savestats_menu(); break; case 1: // toggle unfocus pause game.disablepause = !game.disablepause; + game.savestats_menu(); music.playef(11); break; case 2: // toggle fake load screen game.skipfakeload = !game.skipfakeload; + game.savestats_menu(); music.playef(11); break; case 3: // toggle translucent roomname BG graphics.translucentroomname = !graphics.translucentroomname; + game.savestats_menu(); music.playef(11); break; case 4: // Glitchrunner mode music.playef(11); game.glitchrunnermode = !game.glitchrunnermode; + game.savestats_menu(); break; case 5: //back @@ -570,7 +576,7 @@ void menuactionpress() case 0: //disable animated backgrounds game.colourblindmode = !game.colourblindmode; - game.savestats(); + game.savestats_menu(); graphics.towerbg.tdrawback = true; graphics.titlebg.tdrawback = true; music.playef(11); @@ -578,7 +584,7 @@ void menuactionpress() case 1: //disable screeneffects game.noflashingmode = !game.noflashingmode; - game.savestats(); + game.savestats_menu(); if (!game.noflashingmode) { music.playef(18); @@ -591,7 +597,7 @@ void menuactionpress() case 2: //disable text outline graphics.notextoutline = !graphics.notextoutline; - game.savestats(); + game.savestats_menu(); music.playef(11); break; case 3: @@ -606,6 +612,7 @@ void menuactionpress() else { map.invincibility = !map.invincibility; + game.savestats_menu(); } music.playef(11); } @@ -775,49 +782,49 @@ void menuactionpress() game.unlock[9] = true; game.unlocknotify[9] = true; music.playef(11); - game.savestats(); game.createmenu(Menu::unlockmenutrials, true); game.currentmenuoption = 0; + game.savestats_menu(); break; case 1: //unlock 2 game.unlock[10] = true; game.unlocknotify[10] = true; music.playef(11); - game.savestats(); game.createmenu(Menu::unlockmenutrials, true); game.currentmenuoption = 1; + game.savestats_menu(); break; case 2: //unlock 3 game.unlock[11] = true; game.unlocknotify[11] = true; music.playef(11); - game.savestats(); game.createmenu(Menu::unlockmenutrials, true); game.currentmenuoption = 2; + game.savestats_menu(); break; case 3: //unlock 4 game.unlock[12] = true; game.unlocknotify[12] = true; music.playef(11); - game.savestats(); game.createmenu(Menu::unlockmenutrials, true); game.currentmenuoption = 3; + game.savestats_menu(); break; case 4: //unlock 5 game.unlock[13] = true; game.unlocknotify[13] = true; music.playef(11); - game.savestats(); game.createmenu(Menu::unlockmenutrials, true); game.currentmenuoption = 4; + game.savestats_menu(); break; case 5: //unlock 6 game.unlock[14] = true; game.unlocknotify[14] = true; music.playef(11); - game.savestats(); game.createmenu(Menu::unlockmenutrials, true); game.currentmenuoption = 5; + game.savestats_menu(); break; case 6: //back //back @@ -843,44 +850,44 @@ void menuactionpress() game.unlocknotify[16] = true; game.unlock[6] = true; game.unlock[7] = true; - game.savestats(); game.createmenu(Menu::unlockmenu, true); game.currentmenuoption = 1; + game.savestats_menu(); break; case 2: //unlock no death mode music.playef(11); game.unlock[17] = true; game.unlocknotify[17] = true; - game.savestats(); game.createmenu(Menu::unlockmenu, true); game.currentmenuoption = 2; + game.savestats_menu(); break; case 3: //unlock flip mode music.playef(11); game.unlock[18] = true; game.unlocknotify[18] = true; - game.savestats(); game.createmenu(Menu::unlockmenu, true); game.currentmenuoption = 3; + game.savestats_menu(); break; case 4: //unlock jukebox music.playef(11); game.stat_trinkets = 20; - game.savestats(); game.createmenu(Menu::unlockmenu, true); game.currentmenuoption = 4; + game.savestats_menu(); break; case 5: //unlock secret lab music.playef(11); game.unlock[8] = true; game.unlocknotify[8] = true; - game.savestats(); game.createmenu(Menu::unlockmenu, true); game.currentmenuoption = 5; + game.savestats_menu(); break; default: //back @@ -1244,6 +1251,7 @@ void menuactionpress() { key.sensitivity = 0; } + game.savestats_menu(); break; case 5: @@ -1585,6 +1593,15 @@ void menuactionpress() game.returnmenu(); map.nexttowercolour(); break; + case Menu::errorsavingsettings: + if (game.currentmenuoption == 1) + { + game.silence_settings_error = true; + } + music.playef(11); + game.returnmenu(); + map.nexttowercolour(); + break; default: break; } diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 1ab6158b..bfb970f7 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -1157,6 +1157,9 @@ void menurender() } break; } + case Menu::errorsavingsettings: + graphics.Print( -1, 95, "ERROR: Could not save settings file!", tr, tg, tb, true); + break; default: break; }