多语言设置界面逻辑

This commit is contained in:
bob
2025-06-12 16:18:55 +08:00
parent 15eaa0e666
commit 07e7715be8
20 changed files with 212 additions and 111 deletions

View File

@@ -17,6 +17,8 @@ namespace NBF
private readonly List<TabListData> tabList = new List<TabListData>();
private string _currentTab = "";
private List<int> _canSelectIndex = new List<int>();
private int _nowSelectIndex = -1;
protected override void OnInit()
{
@@ -60,7 +62,7 @@ namespace NBF
private void ResetSettingList()
{
// TextTitle.text = Lan.Get(_currentGroup);
_nowSelectIndex = -1;
List.RemoveChildrenToPool();
if (string.IsNullOrEmpty(_currentTab)) return;
var options = Settings.Instance.GetOptionsByTab(_currentTab);
@@ -76,6 +78,7 @@ namespace NBF
list.Add(option);
}
_canSelectIndex.Clear();
var url = UIPackage.GetItemURL(UIPackName, "SettingSubTitleItem");
foreach (var key in groupOptions.Keys)
{
@@ -90,6 +93,8 @@ namespace NBF
if (List.AddItemFromPool() is SettingItem item)
{
item.SetData(option);
var index = List.GetChildIndex(item);
_canSelectIndex.Add(index);
}
}
}
@@ -138,18 +143,11 @@ namespace NBF
}
else if (action == InputDef.UI.Up)
{
SetListSelected(List.selectedIndex - 1);
ChangeListSelected();
}
else if (action == InputDef.UI.Down)
{
if (List.selectedIndex < 0)
{
SetListSelected(0);
}
else
{
SetListSelected(List.selectedIndex + 1);
}
ChangeListSelected(false);
}
else if (action == InputDef.UI.Back)
{
@@ -161,6 +159,24 @@ namespace NBF
}
}
private void ChangeListSelected(bool up = true)
{
if (!up)
{
_nowSelectIndex++;
}
else
{
_nowSelectIndex--;
}
if (_nowSelectIndex < 0) _nowSelectIndex = 0;
else if (_nowSelectIndex >= _canSelectIndex.Count) _nowSelectIndex = _canSelectIndex.Count - 1;
var targetIndex = _canSelectIndex[_nowSelectIndex];
SetListSelected(targetIndex);
}
private void SetListSelected(int selectedIndex)
{
if (selectedIndex >= 0 && selectedIndex < List.numItems)