列表选择器修改
This commit is contained in:
@@ -21,10 +21,13 @@ namespace NBF
|
||||
|
||||
private int _columnsCount;
|
||||
|
||||
public ListSelector _selector;
|
||||
|
||||
private void OnInited()
|
||||
{
|
||||
Game.Input.OnUICanceled += OnUICanceled;
|
||||
List.onClickItem.Add(OnClickListItem);
|
||||
_selector = new ListSelector(List, typeof(ListTitleItem));
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
@@ -37,49 +40,43 @@ namespace NBF
|
||||
{
|
||||
if (action == InputDef.UI.Right)
|
||||
{
|
||||
SetListSelected(List.selectedIndex + 1);
|
||||
_selector.Right();
|
||||
}
|
||||
else if (action == InputDef.UI.Left)
|
||||
{
|
||||
SetListSelected(List.selectedIndex - 1);
|
||||
_selector.Left();
|
||||
}
|
||||
else if (action == InputDef.UI.Up)
|
||||
{
|
||||
SetListSelected(List.selectedIndex - _columnsCount);
|
||||
_selector.Up();
|
||||
}
|
||||
else if (action == InputDef.UI.Down)
|
||||
{
|
||||
if (List.selectedIndex < 0)
|
||||
{
|
||||
SetListSelected(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetListSelected(List.selectedIndex + _columnsCount);
|
||||
}
|
||||
_selector.Down();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetListSelected(int selectedIndex)
|
||||
{
|
||||
if (selectedIndex >= 0 && selectedIndex < _listData.Count)
|
||||
{
|
||||
var count = List.numChildren;
|
||||
List.selectedIndex = selectedIndex;
|
||||
List.ScrollToView(selectedIndex);
|
||||
}
|
||||
}
|
||||
// private void SetListSelected(int selectedIndex)
|
||||
// {
|
||||
// if (selectedIndex >= 0 && selectedIndex < _listData.Count)
|
||||
// {
|
||||
// var count = List.numChildren;
|
||||
// List.selectedIndex = selectedIndex;
|
||||
// List.ScrollToView(selectedIndex);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void SetListData(List<object> listData,
|
||||
ListSelectionMode selectionMode = ListSelectionMode.Single)
|
||||
{
|
||||
List.selectedIndex = -1;
|
||||
_listData.Clear();
|
||||
|
||||
|
||||
foreach (var obj in listData)
|
||||
{
|
||||
_listData.Add(obj);
|
||||
}
|
||||
|
||||
List.RemoveChildrenToPool();
|
||||
List.defaultItem = ListTitleItem.URL;
|
||||
List.itemProvider = GetListItemResource;
|
||||
@@ -92,10 +89,11 @@ namespace NBF
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e);
|
||||
Log.Error(e);
|
||||
}
|
||||
|
||||
|
||||
_columnsCount = 6;
|
||||
_selector.Refresh();
|
||||
}
|
||||
|
||||
void OnClickListItem(EventContext context)
|
||||
@@ -136,6 +134,7 @@ namespace NBF
|
||||
{
|
||||
return BagItem.URL;
|
||||
}
|
||||
|
||||
if (itemData is ClassifyListTitleData titleData)
|
||||
{
|
||||
return ListTitleItem.URL;
|
||||
|
||||
Reference in New Issue
Block a user