From 24ef59c65e98565dde88854eefc062b098a9a8fd Mon Sep 17 00:00:00 2001 From: Misa Date: Thu, 18 May 2023 19:58:23 -0700 Subject: [PATCH] Prevent other cases of losing unsaved levels by returning to menu 2.3 already made it so that if you ran the `rollcredits` command during in-editor playtesting, you wouldn't be returned to the title screen while losing unsaved level changes. But there are plenty of other ways to go back to the title screen from in-editor playtesting too. Namely, gamestate 1015 (the gamestate after completing a level) and 82 (time trial complete). So just add the appropriate checks to those gamestates, and add a catch-all check in Game::quittomenu(). Additionally, Game::updatecustomlevelstats() should not update custom level stats during in-editor playtesting (otherwise it would still happen even if the game didn't bring you back to the title screen). Editor notes will also be shown if the game prevents you from going to the title screen. Also, just to make things clear, I also added a level note for when the level is completed during in-editor playtesting. This is just to make it clear in cases where it might not be obvious that the game returned you to the editor for this reason. E.g. you have a terminal that calls gamestate(1013) in a level with 0 custom crewmates, but when you activate it, it looks like the terminal didn't work for some reason and just brought you back to the editor. But that's just only because you literally just completed the level. --- desktop_version/lang/ca/strings.xml | 3 +++ desktop_version/lang/de/strings.xml | 3 +++ desktop_version/lang/en/strings.xml | 3 +++ desktop_version/lang/eo/strings.xml | 3 +++ desktop_version/lang/es/strings.xml | 3 +++ desktop_version/lang/fr/strings.xml | 3 +++ desktop_version/lang/it/strings.xml | 3 +++ desktop_version/lang/nl/strings.xml | 3 +++ desktop_version/lang/pt_BR/strings.xml | 3 +++ desktop_version/lang/pt_PT/strings.xml | 3 +++ desktop_version/lang/ru/strings.xml | 3 +++ desktop_version/lang/tr/strings.xml | 3 +++ desktop_version/src/Game.cpp | 35 ++++++++++++++++++++++++++ 13 files changed, 71 insertions(+) diff --git a/desktop_version/lang/ca/strings.xml b/desktop_version/lang/ca/strings.xml index 0bc289cc..441dfbd9 100644 --- a/desktop_version/lang/ca/strings.xml +++ b/desktop_version/lang/ca/strings.xml @@ -648,7 +648,10 @@ + + + diff --git a/desktop_version/lang/de/strings.xml b/desktop_version/lang/de/strings.xml index a51355a9..06ae62aa 100644 --- a/desktop_version/lang/de/strings.xml +++ b/desktop_version/lang/de/strings.xml @@ -648,7 +648,10 @@ + + + diff --git a/desktop_version/lang/en/strings.xml b/desktop_version/lang/en/strings.xml index 43ca393d..1be77f6c 100644 --- a/desktop_version/lang/en/strings.xml +++ b/desktop_version/lang/en/strings.xml @@ -648,7 +648,10 @@ + + + diff --git a/desktop_version/lang/eo/strings.xml b/desktop_version/lang/eo/strings.xml index d49c5211..352e30f9 100644 --- a/desktop_version/lang/eo/strings.xml +++ b/desktop_version/lang/eo/strings.xml @@ -648,7 +648,10 @@ + + + diff --git a/desktop_version/lang/es/strings.xml b/desktop_version/lang/es/strings.xml index d576cc5c..00f6168a 100644 --- a/desktop_version/lang/es/strings.xml +++ b/desktop_version/lang/es/strings.xml @@ -648,7 +648,10 @@ + + + diff --git a/desktop_version/lang/fr/strings.xml b/desktop_version/lang/fr/strings.xml index 98142709..96f4d6f0 100644 --- a/desktop_version/lang/fr/strings.xml +++ b/desktop_version/lang/fr/strings.xml @@ -648,7 +648,10 @@ + + + diff --git a/desktop_version/lang/it/strings.xml b/desktop_version/lang/it/strings.xml index 5786d877..eb768a10 100644 --- a/desktop_version/lang/it/strings.xml +++ b/desktop_version/lang/it/strings.xml @@ -648,7 +648,10 @@ + + + diff --git a/desktop_version/lang/nl/strings.xml b/desktop_version/lang/nl/strings.xml index 575cd9d9..18bfbcc2 100644 --- a/desktop_version/lang/nl/strings.xml +++ b/desktop_version/lang/nl/strings.xml @@ -648,7 +648,10 @@ + + + diff --git a/desktop_version/lang/pt_BR/strings.xml b/desktop_version/lang/pt_BR/strings.xml index ea7a8ebb..393ce8fe 100644 --- a/desktop_version/lang/pt_BR/strings.xml +++ b/desktop_version/lang/pt_BR/strings.xml @@ -648,7 +648,10 @@ + + + diff --git a/desktop_version/lang/pt_PT/strings.xml b/desktop_version/lang/pt_PT/strings.xml index 497f9e93..eb570743 100644 --- a/desktop_version/lang/pt_PT/strings.xml +++ b/desktop_version/lang/pt_PT/strings.xml @@ -648,7 +648,10 @@ + + + diff --git a/desktop_version/lang/ru/strings.xml b/desktop_version/lang/ru/strings.xml index 4cefc76a..cdb79350 100644 --- a/desktop_version/lang/ru/strings.xml +++ b/desktop_version/lang/ru/strings.xml @@ -648,7 +648,10 @@ + + + diff --git a/desktop_version/lang/tr/strings.xml b/desktop_version/lang/tr/strings.xml index 38389b73..c0ba1de6 100644 --- a/desktop_version/lang/tr/strings.xml +++ b/desktop_version/lang/tr/strings.xml @@ -648,7 +648,10 @@ + + + diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index 2d6c7dfa..9c42a635 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -442,6 +442,12 @@ void Game::clearcustomlevelstats(void) void Game::updatecustomlevelstats(std::string clevel, int cscore) { + if (!map.custommodeforreal) + { + /* We are playtesting, don't update level stats */ + return; + } + if (clevel.find("levels/") != std::string::npos) { clevel = clevel.substr(7); @@ -1573,6 +1579,14 @@ void Game::updatestate(void) case 82: //Time Trial Complete! obj.removetrigger(82); +#if !defined(NO_CUSTOM_LEVELS) && !defined(NO_EDITOR) + if (map.custommode && !map.custommodeforreal) + { + returntoeditor(); + ed.show_note(loc::gettext("Time trial completed")); + break; + } +#endif if (translator_exploring) { translator_exploring_allowtele = true; @@ -2151,6 +2165,7 @@ void Game::updatestate(void) else { returntoeditor(); + ed.show_note(loc::gettext("Level completed")); } #endif } @@ -7150,8 +7165,28 @@ static void hardreset(void) script.hardreset(); } +#if !defined(NO_CUSTOM_LEVELS) && !defined(NO_EDITOR) +static void returntoeditor_callback(void) +{ + extern Game game; + game.returntoeditor(); + ed.show_note(loc::gettext("Level quits to menu")); +} +#endif + void Game::quittomenu(void) { +#if !defined(NO_CUSTOM_LEVELS) && !defined(NO_EDITOR) + if (map.custommode && !map.custommodeforreal) + { + /* We are playtesting! Go back to the editor + * instead of losing unsaved changes. */ + /* This needs to be deferred, otherwise some state would persist. */ + DEFER_CALLBACK(returntoeditor_callback); + return; + } +#endif + gamestate = TITLEMODE; graphics.fademode = FADE_START_FADEIN; FILESYSTEM_unmountAssets();