Skip to content

Commit

Permalink
Fix #1750: Scenario index is not updated when in-game language changes (
Browse files Browse the repository at this point in the history
#1751)

* Update scenario index when in-game language is changed

* ScenarioManager: name forceReload parameter; default to false
  • Loading branch information
AaronVanGeffen committed Jan 12, 2023
1 parent 51e0ac5 commit a26f820
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,6 +1,7 @@
22.12+ (???)
------------------------------------------------------------------------
- Feature: [#1745] Add cheat to instantly win any scenario/challenge.
- Fix: [#1750] Scenario index is not updated when in-game language changes.

22.12 (2022-12-22)
------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/EditorController.cpp
Expand Up @@ -262,7 +262,7 @@ namespace OpenLoco::EditorController
break;
}

ScenarioManager::loadIndex(1);
ScenarioManager::loadIndex(true);

// This ends with a premature tick termination
Game::returnToTitle();
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/OpenLoco.cpp
Expand Up @@ -284,7 +284,7 @@ namespace OpenLoco
Ui::ProgressBar::setProgress(40);
Ui::ProgressBar::end();
ObjectManager::loadIndex();
ScenarioManager::loadIndex(0);
ScenarioManager::loadIndex();
Ui::ProgressBar::begin(StringIds::loading);
Ui::ProgressBar::setProgress(60);
Gfx::loadG1();
Expand Down
13 changes: 3 additions & 10 deletions src/OpenLoco/src/ScenarioManager.cpp
Expand Up @@ -369,7 +369,7 @@ namespace OpenLoco::ScenarioManager
}

// 0x0044452F
void loadIndex(uint8_t al)
void loadIndex(const bool forceReload)
{
const auto oldFlags = getScreenFlags();
setAllScreenFlags(ScreenFlags::title | oldFlags);
Expand All @@ -380,18 +380,11 @@ namespace OpenLoco::ScenarioManager
}

const auto currentState = getCurrentScenarioFolderState();

if (!tryLoadIndex(currentState))
if (forceReload || !tryLoadIndex(currentState))
{
createIndex(currentState);
}
else
{
if (al != 0)
{
createIndex(currentState);
}
}

setAllScreenFlags(oldFlags);
}

Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/ScenarioManager.h
Expand Up @@ -51,7 +51,7 @@ namespace OpenLoco::ScenarioManager
bool hasScenarioInCategory(uint8_t category, ScenarioIndexEntry* scenario);
uint16_t getScenarioCountByCategory(uint8_t category);
ScenarioIndexEntry* getNthScenarioFromCategory(uint8_t category, uint8_t index);
void loadIndex(uint8_t al);
void loadIndex(const bool forceReload = false);
void saveNewScore(Scenario::ObjectiveProgress& progress, const CompanyId companyId);

// 0x00525F5E
Expand Down
4 changes: 4 additions & 0 deletions src/OpenLoco/src/Windows/Options.cpp
Expand Up @@ -16,6 +16,7 @@
#include "Objects/ObjectIndex.h"
#include "Objects/ObjectManager.h"
#include "S5/S5.h"
#include "ScenarioManager.h"
#include "SceneManager.h"
#include "Ui.h"
#include "Ui/Dropdown.h"
Expand Down Expand Up @@ -1508,6 +1509,9 @@ namespace OpenLoco::Ui::Windows::Options
// Reloading the objects will force objects to load the new language
ObjectManager::reloadAll();
Gfx::invalidateScreen();

// Rebuild the scenario index to use the new language.
ScenarioManager::loadIndex(true);
}

// 0x004C0C73
Expand Down

0 comments on commit a26f820

Please sign in to comment.