summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/I2.Loc/LocalizeDropdown.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-19 16:05:58 +0800
committerchai <215380520@qq.com>2024-05-19 16:05:58 +0800
commit8e13e7e2874adc8982e16d1d2ed2e28d7480b45f (patch)
tree63ef85c460288891f5a593d69afeca16cba050b3 /Thronefall_1_57/Decompile/I2.Loc/LocalizeDropdown.cs
parentc5f145786f4c6d2fe4bea831dfc16e52228920a5 (diff)
+1.57
Diffstat (limited to 'Thronefall_1_57/Decompile/I2.Loc/LocalizeDropdown.cs')
-rw-r--r--Thronefall_1_57/Decompile/I2.Loc/LocalizeDropdown.cs100
1 files changed, 100 insertions, 0 deletions
diff --git a/Thronefall_1_57/Decompile/I2.Loc/LocalizeDropdown.cs b/Thronefall_1_57/Decompile/I2.Loc/LocalizeDropdown.cs
new file mode 100644
index 0000000..57fd328
--- /dev/null
+++ b/Thronefall_1_57/Decompile/I2.Loc/LocalizeDropdown.cs
@@ -0,0 +1,100 @@
+using System.Collections.Generic;
+using TMPro;
+using UnityEngine;
+using UnityEngine.UI;
+
+namespace I2.Loc;
+
+[AddComponentMenu("I2/Localization/Localize Dropdown")]
+public class LocalizeDropdown : MonoBehaviour
+{
+ public List<string> _Terms = new List<string>();
+
+ public void Start()
+ {
+ LocalizationManager.OnLocalizeEvent += OnLocalize;
+ OnLocalize();
+ }
+
+ public void OnDestroy()
+ {
+ LocalizationManager.OnLocalizeEvent -= OnLocalize;
+ }
+
+ private void OnEnable()
+ {
+ if (_Terms.Count == 0)
+ {
+ FillValues();
+ }
+ OnLocalize();
+ }
+
+ public void OnLocalize()
+ {
+ if (base.enabled && !(base.gameObject == null) && base.gameObject.activeInHierarchy && !string.IsNullOrEmpty(LocalizationManager.CurrentLanguage))
+ {
+ UpdateLocalization();
+ }
+ }
+
+ private void FillValues()
+ {
+ Dropdown component = GetComponent<Dropdown>();
+ if (component == null && I2Utils.IsPlaying())
+ {
+ FillValuesTMPro();
+ return;
+ }
+ foreach (Dropdown.OptionData option in component.options)
+ {
+ _Terms.Add(option.text);
+ }
+ }
+
+ public void UpdateLocalization()
+ {
+ Dropdown component = GetComponent<Dropdown>();
+ if (component == null)
+ {
+ UpdateLocalizationTMPro();
+ return;
+ }
+ component.options.Clear();
+ foreach (string term in _Terms)
+ {
+ string text = TextTranslator.Translate(term);
+ component.options.Add(new Dropdown.OptionData(text));
+ }
+ component.RefreshShownValue();
+ }
+
+ public void UpdateLocalizationTMPro()
+ {
+ TMP_Dropdown component = GetComponent<TMP_Dropdown>();
+ if (component == null)
+ {
+ return;
+ }
+ component.options.Clear();
+ foreach (string term in _Terms)
+ {
+ string text = TextTranslator.Translate(term);
+ component.options.Add(new TMP_Dropdown.OptionData(text));
+ }
+ component.RefreshShownValue();
+ }
+
+ private void FillValuesTMPro()
+ {
+ TMP_Dropdown component = GetComponent<TMP_Dropdown>();
+ if (component == null)
+ {
+ return;
+ }
+ foreach (TMP_Dropdown.OptionData option in component.options)
+ {
+ _Terms.Add(option.text);
+ }
+ }
+}