快捷键重构
This commit is contained in:
@@ -11,18 +11,65 @@ namespace NBF
|
||||
public partial class ClassifyList : GComponent
|
||||
{
|
||||
private readonly List<object> _listData = new List<object>();
|
||||
|
||||
|
||||
public event Action<object> OnClickItem;
|
||||
|
||||
|
||||
private int _columnsCount;
|
||||
|
||||
private void OnInited()
|
||||
{
|
||||
List.itemProvider = GetListItemResource;
|
||||
List.itemRenderer = OnRenderItem;
|
||||
List.onClickItem.Add(OnClickListItem);
|
||||
InputManager.OnUICanceled += OnUICanceled;
|
||||
}
|
||||
|
||||
public void SetListData(List<object> listData,ListSelectionMode selectionMode = ListSelectionMode.Single)
|
||||
public override void Dispose()
|
||||
{
|
||||
InputManager.OnUICanceled -= OnUICanceled;
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
private void OnUICanceled(string action)
|
||||
{
|
||||
if (action == InputDef.UI.Right)
|
||||
{
|
||||
SetListSelected(List.selectedIndex + 1);
|
||||
}
|
||||
else if (action == InputDef.UI.Left)
|
||||
{
|
||||
SetListSelected(List.selectedIndex - 1);
|
||||
}
|
||||
else if (action == InputDef.UI.Up)
|
||||
{
|
||||
SetListSelected(List.selectedIndex - _columnsCount);
|
||||
}
|
||||
else if (action == InputDef.UI.Down)
|
||||
{
|
||||
if (List.selectedIndex < 0)
|
||||
{
|
||||
SetListSelected(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetListSelected(List.selectedIndex + _columnsCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetListSelected(int selectedIndex)
|
||||
{
|
||||
if (selectedIndex >= 0 && selectedIndex < _listData.Count)
|
||||
{
|
||||
List.selectedIndex = selectedIndex;
|
||||
List.ScrollToView(List.selectedIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetListData(List<object> listData, ListSelectionMode selectionMode = ListSelectionMode.Single)
|
||||
{
|
||||
List.selectedIndex = -1;
|
||||
List.defaultItem = GetListDefaultItemResource(listData);
|
||||
List.itemRenderer = OnRenderItem;
|
||||
List.onClickItem.Add(OnClickListItem);
|
||||
List.SetVirtual();
|
||||
_listData.Clear();
|
||||
foreach (var obj in listData)
|
||||
{
|
||||
@@ -32,13 +79,14 @@ namespace NBF
|
||||
List.selectionMode = selectionMode;
|
||||
List.numItems = _listData.Count;
|
||||
List.ScrollToView(0);
|
||||
_columnsCount = 5;
|
||||
}
|
||||
|
||||
void OnClickListItem(EventContext context)
|
||||
{
|
||||
OnClickItem?.Invoke(context.data);
|
||||
}
|
||||
|
||||
|
||||
void OnRenderItem(int index, GObject obj)
|
||||
{
|
||||
if (obj is ListItemBase item)
|
||||
@@ -48,20 +96,15 @@ namespace NBF
|
||||
}
|
||||
|
||||
//根据索引的不同,返回不同的资源URL
|
||||
string GetListItemResource(int index)
|
||||
string GetListDefaultItemResource(List<object> listData)
|
||||
{
|
||||
var itemData = _listData[index];
|
||||
|
||||
if (itemData is ShopGearData shopItem)
|
||||
var itemData = listData.Find(t => t != null);
|
||||
|
||||
if (itemData is ShopGearData)
|
||||
{
|
||||
return ShopGearItem.URL;
|
||||
}
|
||||
|
||||
if (itemData is ListClassifyData item)
|
||||
{
|
||||
return ListTitleItem.URL;
|
||||
}
|
||||
|
||||
return List.defaultItem;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user