Skip to content

Commit

Permalink
Move CurrentLanguageKey into MulliganUserPreferences
Browse files Browse the repository at this point in the history
By storing the key outside of MulliganUserPreferences it was not
properly cleaned up when resetting preferences. This also makes sure
all preferences obey the same pattern.
  • Loading branch information
edwardrowe committed May 12, 2020
1 parent f5616b4 commit 1d6753b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public static void DrawPreferences(MulliganUserPreferences preferences, Language
var newLanguage = DrawLanguageDropdown(LocalizationManager.Instance.CurrentLanguage);
if (newLanguage != LocalizationManager.Instance.CurrentLanguage)
{
preferences.CurrentLanguageKey = newLanguage.Key;
LocalizationManager.Instance.ChangeLanguage(newLanguage.Key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public class LocalizationManager
{
private static LocalizationManager _Instance;

private const string LanguagePrefKey = "RedBlueGames.MulliganRenamer.Locale";

private const string LanguageFoldername = "MulliganLanguages";

public event System.Action LanguageChanged;
Expand Down Expand Up @@ -111,7 +109,8 @@ public static List<Language> LoadAllLanguages()
public void Initialize()
{
this.CacheAllLanguages();
this.ChangeLanguage(EditorPrefs.GetString(LanguagePrefKey, "en"));
var preferences = MulliganUserPreferences.LoadOrCreatePreferences();
this.ChangeLanguage(preferences.CurrentLanguageKey);
}
/// <summary>
/// Change the current Locale so that Translations are of the new, specified languages
Expand All @@ -122,7 +121,6 @@ public void ChangeLanguage(string languageKey)
var language = this.allLanguages.FirstOrDefault(x => x.Key == languageKey);
if (language != null)
{
EditorPrefs.SetString(LanguagePrefKey, languageKey);
this.currentLanguage = language;

if (this.LanguageChanged != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public class MulliganUserPreferences : ISerializationCallbackReceiver
[SerializeField]
private bool hasInitializedColors;

[SerializeField]
private string currentLanguageKey;

/// <summary>
/// Gets or Sets the previously used Sequence of Rename Operations
/// </summary>
Expand Down Expand Up @@ -232,6 +235,19 @@ public Color DeletionBackgroundColor
}
}

public string CurrentLanguageKey
{
get
{
return this.currentLanguageKey;
}

set
{
this.currentLanguageKey = value;
}
}

/// <summary>
/// Create a new Instance of MulliganUserPreferences
/// </summary>
Expand Down Expand Up @@ -401,6 +417,7 @@ private void ResetAllValuesToDefault()

this.savedPresets = new List<RenameSequencePreset>();

this.currentLanguageKey = "en";
}

private void UpgradePreferences()
Expand All @@ -410,6 +427,9 @@ private void UpgradePreferences()
this.ResetColorsToDefault();
this.hasInitializedColors = true;
}

// We moved this value into MulliganUserPrefs so delete it if it exists
EditorPrefs.DeleteKey("RedBlueGames.MulliganRenamer.Locale");
}
}
}

0 comments on commit 1d6753b

Please sign in to comment.