Skip to content

Commit

Permalink
Language can now be switched without requiring a game restart
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorPhilipp committed May 24, 2017
1 parent 548055d commit 69825dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ User manual: http://www.viathinksoft.de/tmpe
1.9.5, 05/24/2017
- Updated for game version 1.7.1-f1
- Updated Polish, Korean and Italian translation
- Language can now be switched without requiring a game restart
- Bugfix: Routing calculation does not work as expected for one-way roads with tram tracks (thanks to @bigblade66, @Battelman2 and @AS_ for reporting and providing extensive information)
- Bugfix: Copying timed traffic lights lead to inconsistent internal states which causes timed traffic lights to be omitted during the save process (thanks to @jakeroot and @t1a2l for reporting this issue)
- Bugfix: In certain situations unnecessary vehicle-seperate traffic lights are being created
Expand Down
14 changes: 13 additions & 1 deletion TLM/TLM/State/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using ColossalFramework.Globalization;
using TrafficManager.Manager;
using CSUtil.Commons;
using System.Reflection;

namespace TrafficManager.State {

Expand Down Expand Up @@ -183,7 +184,7 @@ public static void makeSettings(UIHelperBase helper) {
}
}

languageDropdown = generalGroup.AddDropdown(Translation.GetString("Language") + " (" + Translation.GetString("requires_game_restart") + "):", languageLabels, languageIndex, onLanguageChanged) as UIDropDown;
languageDropdown = generalGroup.AddDropdown(Translation.GetString("Language") + ":", languageLabels, languageIndex, onLanguageChanged) as UIDropDown;
lockButtonToggle = generalGroup.AddCheckbox(Translation.GetString("Lock_main_menu_button_position"), GlobalConfig.Instance.MainMenuButtonPosLocked, onLockButtonChanged) as UICheckBox;
lockMenuToggle = generalGroup.AddCheckbox(Translation.GetString("Lock_main_menu_position"), GlobalConfig.Instance.MainMenuPosLocked, onLockMenuChanged) as UICheckBox;

Expand Down Expand Up @@ -444,17 +445,28 @@ private static void onConnectedLanesOverlayChanged(bool newValue) {
}

private static void onLanguageChanged(int newLanguageIndex) {
bool localeChanged = false;

if (newLanguageIndex <= 0) {
GlobalConfig.Instance.LanguageCode = null;
GlobalConfig.WriteConfig();
MenuRebuildRequired = true;
localeChanged = true;
} else if (newLanguageIndex - 1 < Translation.AVAILABLE_LANGUAGE_CODES.Count) {
GlobalConfig.Instance.LanguageCode = Translation.AVAILABLE_LANGUAGE_CODES[newLanguageIndex - 1];
GlobalConfig.WriteConfig();
MenuRebuildRequired = true;
localeChanged = true;
} else {
Log.Warning($"Options.onLanguageChanged: Invalid language index: {newLanguageIndex}");
}

if (localeChanged) {
MethodInfo onChangedHandler = typeof(OptionsMainPanel).GetMethod("OnLocaleChanged", BindingFlags.Instance | BindingFlags.NonPublic);
if (onChangedHandler != null) {
onChangedHandler.Invoke(UIView.library.Get<OptionsMainPanel>("OptionsPanel"), new object[0] { });
}
}
}

private static void onLockButtonChanged(bool newValue) {
Expand Down

0 comments on commit 69825dc

Please sign in to comment.