完成快速选中相关内容
This commit is contained in:
Binary file not shown.
@@ -34,6 +34,8 @@ namespace NBF.Fishing2
|
||||
}
|
||||
}
|
||||
|
||||
#region 获取物品列表
|
||||
|
||||
public List<ItemInfo> GetItemsByType(ItemType itemType)
|
||||
{
|
||||
return Items.Where(item => item.ItemType == itemType).ToList();
|
||||
@@ -62,6 +64,33 @@ namespace NBF.Fishing2
|
||||
return dic;
|
||||
}
|
||||
|
||||
public List<object> GetItemListData(params ItemType[] itemTypes)
|
||||
{
|
||||
var dic = GetItemsByType();
|
||||
|
||||
if (itemTypes == null || itemTypes.Length == 0)
|
||||
{
|
||||
itemTypes = new ItemType[] { ItemType.Rod, ItemType.Bobber, ItemType.Reel };
|
||||
}
|
||||
|
||||
List<object> items = new List<object>();
|
||||
|
||||
foreach (var (type, list) in dic)
|
||||
{
|
||||
if (!itemTypes.Contains(type)) continue;
|
||||
var typeItem = new ClassifyListTitleData()
|
||||
{
|
||||
Title = type.ToString()
|
||||
};
|
||||
items.Add(typeItem);
|
||||
items.AddRange(list);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public List<ItemInfo> GetBindItems(long itemId)
|
||||
{
|
||||
List<ItemInfo> ret = new List<ItemInfo>();
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace NBF
|
||||
UIConfig.verticalScrollBar = "ui://6hgkvlauoomej";
|
||||
UIConfig.defaultFont = "AlibabaPuHuiTi-3-Medium";
|
||||
App.UI.SetUILanguage<UILangeageConfig>();
|
||||
UIConfig.modalLayerColor = new Color(0, 0, 0, 0.9f);
|
||||
UIConfig.modalLayerColor = new Color(0, 0, 0, 0.99f);
|
||||
AddUIPackages();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace NBF
|
||||
private void OnInited()
|
||||
{
|
||||
onDragStart.Add(DragStart);
|
||||
// Oncl
|
||||
}
|
||||
|
||||
|
||||
|
||||
4
Assets/Scripts/UI/Bag/BagSelectPanel.Designer.cs
generated
4
Assets/Scripts/UI/Bag/BagSelectPanel.Designer.cs
generated
@@ -18,12 +18,12 @@ namespace NBF
|
||||
public GImage back;
|
||||
[AutoFind(Name = "box")]
|
||||
public GImage box;
|
||||
[AutoFind(Name = "List")]
|
||||
public GList List;
|
||||
[AutoFind(Name = "BtnCancel")]
|
||||
public BtnTitleInputControl BtnCancel;
|
||||
[AutoFind(Name = "BtnConfirm")]
|
||||
public BtnTitleInputControl BtnConfirm;
|
||||
[AutoFind(Name = "List")]
|
||||
public ClassifyList List;
|
||||
public override string[] GetDependPackages(){ return new string[] {"Common"}; }
|
||||
|
||||
public static void Show(object param = null){ App.UI.OpenUI<BagSelectPanel>(param); }
|
||||
|
||||
@@ -15,26 +15,46 @@ namespace NBF
|
||||
{
|
||||
//context.data
|
||||
private static Action<long> _selectCallBack;
|
||||
private static ItemType _itemType;
|
||||
private List<ItemInfo> _items;
|
||||
|
||||
public static void Show(ItemType itemType, Action<long> callBack)
|
||||
// private static ItemType _itemType;
|
||||
private static readonly List<ItemType> _itemTypes = new List<ItemType>();
|
||||
private long _selectedId;
|
||||
// private List<ItemInfo> _items;
|
||||
|
||||
// public static void Show(ItemType itemType, Action<long> callBack)
|
||||
// {
|
||||
// Show(new[] { itemType }, callBack);
|
||||
// }
|
||||
|
||||
public static void Show(Action<long> callBack, params ItemType[] itemTypes)
|
||||
{
|
||||
_itemType = itemType;
|
||||
_itemTypes.Clear();
|
||||
_itemTypes.AddRange(itemTypes);
|
||||
_selectCallBack = callBack;
|
||||
// List
|
||||
Show();
|
||||
}
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
IsModal = true;
|
||||
this.AutoAddClick(OnClick);
|
||||
List.OnDoubleClickItem += OnDoubleClickItem;
|
||||
List.OnClickItem += OnClickItem;
|
||||
}
|
||||
|
||||
protected override void OnShow()
|
||||
{
|
||||
_selectedId = 0;
|
||||
SetList();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
List.OnClickItem -= OnClickItem;
|
||||
List.OnDoubleClickItem -= OnDoubleClickItem;
|
||||
}
|
||||
|
||||
private void OnClick(GComponent btn)
|
||||
{
|
||||
if (btn == BtnCancel)
|
||||
@@ -43,12 +63,29 @@ namespace NBF
|
||||
}
|
||||
else if (btn == BtnConfirm)
|
||||
{
|
||||
var selectIndex = List.selectedIndex;
|
||||
if (selectIndex >= 0)
|
||||
if (_selectedId > 0)
|
||||
{
|
||||
var itemData = _items[selectIndex];
|
||||
_selectCallBack?.Invoke(itemData.Id);
|
||||
_selectCallBack?.Invoke(_selectedId);
|
||||
}
|
||||
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClickItem(object item)
|
||||
{
|
||||
if (item is BagItem bagItem)
|
||||
{
|
||||
_selectedId = bagItem.ItemInfo.Id;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDoubleClickItem(object item)
|
||||
{
|
||||
if (item is BagItem bagItem)
|
||||
{
|
||||
_selectedId = bagItem.ItemInfo.Id;
|
||||
_selectCallBack?.Invoke(bagItem.ItemInfo.Id);
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
@@ -57,24 +94,9 @@ namespace NBF
|
||||
{
|
||||
var role = App.Main.GetComponent<Role>();
|
||||
var roleBag = role.GetComponent<RoleBag>();
|
||||
|
||||
_items = roleBag.GetItemsByType(_itemType);
|
||||
|
||||
List.RemoveChildrenToPool();
|
||||
List.defaultItem = BagItem.URL;
|
||||
List.itemRenderer = OnRenderItem;
|
||||
List.selectionMode = ListSelectionMode.Single;
|
||||
|
||||
List.numItems = _items.Count;
|
||||
}
|
||||
|
||||
void OnRenderItem(int index, GObject obj)
|
||||
{
|
||||
var itemData = _items[index];
|
||||
if (obj is BagItem bagItem)
|
||||
{
|
||||
bagItem.SetData(itemData);
|
||||
}
|
||||
|
||||
List<object> items = roleBag.GetItemListData();
|
||||
List.SetListData(items);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,7 @@ namespace NBF
|
||||
private void OnRemove(EventContext context)
|
||||
{
|
||||
context.PreventDefault();
|
||||
context.StopPropagation();
|
||||
OnChangeSlot?.Invoke(Index, 0);
|
||||
}
|
||||
|
||||
|
||||
2
Assets/Scripts/UI/Bag/BagSlotPanel.Designer.cs
generated
2
Assets/Scripts/UI/Bag/BagSlotPanel.Designer.cs
generated
@@ -19,7 +19,7 @@ namespace NBF
|
||||
[AutoFind(Name = "SlotTitle")]
|
||||
public GComponent SlotTitle;
|
||||
[AutoFind(Name = "List")]
|
||||
public GList List;
|
||||
public ClassifyList List;
|
||||
[AutoFind(Name = "SlotList")]
|
||||
public GList SlotList;
|
||||
[AutoFind(Name = "SlotSeparator")]
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace NBF
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
SlotList.onClickItem.Add(OnClickSlotItem);
|
||||
}
|
||||
|
||||
protected override void OnShow()
|
||||
@@ -41,26 +42,31 @@ namespace NBF
|
||||
}
|
||||
}
|
||||
|
||||
List.RemoveChildrenToPool();
|
||||
List.itemRenderer = OnRenderItem;
|
||||
|
||||
List.numItems = _items.Count;
|
||||
}
|
||||
|
||||
void OnRenderItem(int index, GObject obj)
|
||||
{
|
||||
var itemData = _items[index];
|
||||
if (obj is BagItem bagItem)
|
||||
List<object> items = _roleBag.GetItemListData();
|
||||
List.SetListData(items);
|
||||
var children = List.List.GetChildren();
|
||||
foreach (var gObject in children)
|
||||
{
|
||||
bagItem.SetData(itemData);
|
||||
bagItem.draggable = true;
|
||||
gObject.draggable = true;
|
||||
}
|
||||
}
|
||||
|
||||
// void OnRenderItem(int index, GObject obj)
|
||||
// {
|
||||
// var itemData = _items[index];
|
||||
// if (obj is BagItem bagItem)
|
||||
// {
|
||||
// bagItem.SetData(itemData);
|
||||
// bagItem.draggable = true;
|
||||
// }
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
#region 快速选择列表
|
||||
|
||||
private int _lastSelectedItem;
|
||||
|
||||
private void SetSlotList()
|
||||
{
|
||||
SlotList.RemoveChildrenToPool();
|
||||
@@ -86,6 +92,21 @@ namespace NBF
|
||||
// SlotList.RefreshVirtualList();
|
||||
}
|
||||
|
||||
private void OnClickSlotItem(EventContext context)
|
||||
{
|
||||
if (context.data is BagSlotItem bagSlotItem)
|
||||
{
|
||||
_lastSelectedItem = bagSlotItem.Index;
|
||||
BagSelectPanel.Show(SelectCallback, ItemType.Rod, ItemType.Bobber, ItemType.Reel);
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectCallback(long selectId)
|
||||
{
|
||||
if (selectId < 1) return;
|
||||
_roleBag.SetSlot(_lastSelectedItem, selectId).OnCompleted(OnChangeSlotItemDone);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private bool CanShow(ItemInfo itemInfo)
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace NBF
|
||||
{
|
||||
if (context.data is not BagGearItem item) return;
|
||||
_lastSelectedItem = item;
|
||||
BagSelectPanel.Show(item.BindData.Type, SelectCallback);
|
||||
BagSelectPanel.Show(SelectCallback, item.BindData.Type);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace NBF
|
||||
private readonly List<object> _listData = new List<object>();
|
||||
|
||||
public event Action<object> OnClickItem;
|
||||
public event Action<object> OnDoubleClickItem;
|
||||
|
||||
private int _columnsCount;
|
||||
|
||||
@@ -98,6 +99,10 @@ namespace NBF
|
||||
void OnClickListItem(EventContext context)
|
||||
{
|
||||
OnClickItem?.Invoke(context.data);
|
||||
if (context.inputEvent.isDoubleClick)
|
||||
{
|
||||
OnDoubleClickItem?.Invoke(context.data);
|
||||
}
|
||||
}
|
||||
|
||||
void OnRenderItem(int index, GObject obj)
|
||||
|
||||
Reference in New Issue
Block a user