fix: 科目编辑面板实时翻译 - 订阅LanguageChanged事件, SetSubName使用Get(), 下拉框地形名同步翻译

This commit is contained in:
ayuan9957 2026-07-23 10:56:17 +08:00
parent 02088b6f17
commit 53de0cb412

View File

@ -16,6 +16,8 @@ public class SubjectEditorBase : BasePanel
public InputField input_TaskIntr;
public InputField input_FileIntr;
private string subNameKey;
public SubjectEditorBase(string panelName) : base(new UIType(panelName))
{
}
@ -41,6 +43,24 @@ public class SubjectEditorBase : BasePanel
dropdown_Terrain.onValueChanged.AddListener(TerrainChange);
button_Save?.onClick.AddListener(SaveFile);
button_finish?.onClick.AddListener(FinishEditor);
LocalizationManager.LanguageChanged += OnLanguageChanged;
}
private void OnLanguageChanged()
{
if (subName != null && !string.IsNullOrEmpty(subNameKey))
subName.text = LocalizationManager.Get(subNameKey);
// Refresh dropdown options with localized terrain names
if (dropdown_Terrain != null)
{
string[] terrainNames = DBManager.Instance.GetABNames(ABType.);
for (int i = 0; i < terrainNames.Length && i < dropdown_Terrain.options.Count; i++)
{
dropdown_Terrain.options[i].text = LocalizationManager.Get(terrainNames[i]);
}
dropdown_Terrain.RefreshShownValue();
}
}
@ -61,7 +81,8 @@ public class SubjectEditorBase : BasePanel
public void SetSubName(string subNameStr)
{
subName.text = subNameStr;
subNameKey = subNameStr;
subName.text = LocalizationManager.Get(subNameStr);
}
async void TerrainChange(int terrainIndex)
@ -78,6 +99,7 @@ public class SubjectEditorBase : BasePanel
public override void OnDestroy(bool isDestroy = false)
{
base.OnDestroy(isDestroy);
LocalizationManager.LanguageChanged -= OnLanguageChanged;
input_TaskIntr.text = "";
input_FileIntr.text = "";
}