Skip to content

Commit

Permalink
Fix bug when changing languages without reloading game (old language …
Browse files Browse the repository at this point in the history
…would stick around).

This should hopefully put an end to mods not correctly falling back to English when no translation is available. As long as you support en-US everything should be fine.
  • Loading branch information
SupSuper committed Nov 22, 2018
1 parent f0be2ee commit efa947e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Engine/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,10 +557,10 @@ bool Game::isQuitting() const
}

/**
* Loads the most appropriate language
* Loads the most appropriate languages
* given current system and game options.
*/
void Game::defaultLanguage()
void Game::loadLanguages()
{
const std::string defaultLang = "en-US";
std::string currentLang = defaultLang;
Expand Down
8 changes: 4 additions & 4 deletions src/Engine/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Game
int _timeUntilNextFrame;
static const double VOLUME_GRADIENT;

/// Loads a new language for the game.
void loadLanguage(const std::string &filename);
public:
/// Creates a new game and initializes SDL.
Game(const std::string &title);
Expand Down Expand Up @@ -82,8 +84,6 @@ class Game
void popState();
/// Gets the currently loaded language.
Language *getLanguage() const;
/// Loads a new language for the game.
void loadLanguage(const std::string &filename);
/// Gets the currently loaded saved game.
SavedGame *getSavedGame() const;
/// Sets a new saved game for the game.
Expand All @@ -98,8 +98,8 @@ class Game
bool isState(State *state) const;
/// Returns whether the game is shutting down.
bool isQuitting() const;
/// Sets up the default language.
void defaultLanguage();
/// Loads the default and current language.
void loadLanguages();
/// Sets up the audio.
void initAudio();
};
Expand Down
2 changes: 1 addition & 1 deletion src/Menu/OptionsBaseState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void OptionsBaseState::btnOkClick(Action *)
{
Options::mapResources();
}
_game->loadLanguage(Options::language);
_game->loadLanguages();
SDL_WM_GrabInput(Options::captureMouse);
_game->getScreen()->resetDisplay();
_game->setVolume(Options::soundVolume, Options::musicVolume, Options::uiVolume);
Expand Down
2 changes: 1 addition & 1 deletion src/Menu/OptionsDefaultsState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void OptionsDefaultsState::btnYesClick(Action *action)
{
std::vector< std::pair<std::string, bool> > prevMods(Options::mods);
Options::resetDefault();
_game->defaultLanguage();
_game->loadLanguages();

if (_origin == OPT_MENU && prevMods != Options::mods)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Menu/StartState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ int StartState::load(void *game_ptr)
game->loadMods();
Log(LOG_INFO) << "Data loaded successfully.";
Log(LOG_INFO) << "Loading language...";
game->defaultLanguage();
game->loadLanguages();
Log(LOG_INFO) << "Language loaded successfully.";
loading = LOADING_SUCCESSFUL;
}
Expand Down

0 comments on commit efa947e

Please sign in to comment.