diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListBase.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListBase.cs
index 730baa73..07f71276 100644
--- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListBase.cs
+++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListBase.cs
@@ -9,10 +9,10 @@ namespace GameLogic
///
/// UI列表Item
///
- ///
- public interface IListDataItem
+ ///
+ public interface IListDataItem
{
- void SetItemData(DataT d);
+ void SetItemData(TData d);
}
///
@@ -180,8 +180,7 @@ namespace GameLogic
///
public void SetDatas(List dataList, int n = -1)
{
- AdjustItemNum(Mathf.Max(0, n >= 0 ? n : (dataList == null ? 0 : (dataList.Count - dataStartOffset))),
- dataList);
+ AdjustItemNum(Mathf.Max(0, n >= 0 ? n : (dataList == null ? 0 : (dataList.Count - dataStartOffset))), dataList);
}
///
@@ -215,8 +214,7 @@ namespace GameLogic
return;
}
- var listDataItem = item as IListDataItem;
- if (listDataItem != null)
+ if (item is IListDataItem listDataItem)
{
listDataItem.SetItemData(GetData(i));
}
@@ -271,8 +269,7 @@ namespace GameLogic
var preIndex = selectIndex;
m_selectIndex = i;
- var item = GetItem(preIndex) as IListSelectItem;
- if (item != null)
+ if (GetItem(preIndex) is IListSelectItem item)
{
item.SetSelected(false);
}
@@ -282,12 +279,19 @@ namespace GameLogic
{
item.SetSelected(true);
}
-
+ UpdateSnapTargetItem();
if (triggerEvt && funcOnSelectChange != null)
{
funcOnSelectChange.Invoke();
}
}
+
+ ///
+ /// 刷新Snap
+ ///
+ protected virtual void UpdateSnapTargetItem()
+ {
+ }
///
/// 获取当前选中的数据
@@ -312,12 +316,17 @@ namespace GameLogic
///
/// 获取item
///
- ///
+ ///
///
- public virtual ItemT GetItem(int index)
+ public virtual ItemT GetItem(int i)
{
return null;
}
+
+ ///
+ /// 点击选择
+ ///
+ public bool SelectByClick = true;
///
/// item被点击
@@ -331,7 +340,10 @@ namespace GameLogic
funcOnItemClick.Invoke(i);
}
- selectIndex = i;
+ if (SelectByClick)
+ {
+ selectIndex = i;
+ }
}
}
}
\ No newline at end of file
diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListWidget.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListWidget.cs
new file mode 100644
index 00000000..90ccbdc1
--- /dev/null
+++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListWidget.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using TEngine;
+
+namespace GameLogic
+{
+ ///
+ /// 普通UI列表。
+ ///
+ public class UIListWidget : UIListBase where TItem : UIWidget, new()
+ {
+ ///
+ /// item列表。
+ ///
+ protected List m_items = new List();
+
+ ///
+ /// item列表。
+ ///
+ public List items => m_items;
+
+ ///
+ /// 设置显示数据。
+ ///
+ ///
+ ///
+ ///
+ protected override void AdjustItemNum(int n, List datas = null, Action funcItem = null)
+ {
+ base.AdjustItemNum(n, datas, funcItem);
+ AdjustIconNum(m_items, n, gameObject.transform, itemBase);
+ UpdateList(funcItem);
+ }
+
+ ///
+ /// 刷新列表。
+ ///
+ ///
+ protected void UpdateList(Action funcItem = null)
+ {
+ for (var i = 0; i < m_items.Count; i++)
+ {
+ UpdateListItem(m_items[i], i, funcItem);
+ }
+ }
+
+ ///
+ /// 获取item
+ ///
+ ///
+ ///
+ public override TItem GetItem(int i)
+ {
+ return i >= 0 && i < m_items.Count ? m_items[i] : null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListWidget.cs.meta b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListWidget.cs.meta
new file mode 100644
index 00000000..6346b930
--- /dev/null
+++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListWidget.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 96f732d895e94fbc99c904d66ca844ca
+timeCreated: 1701844130
\ No newline at end of file
diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopGridWidget.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopGridWidget.cs
index 955f1d89..14183fd0 100644
--- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopGridWidget.cs
+++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopGridWidget.cs
@@ -66,6 +66,7 @@ namespace GameLogic
LoopRectView.SetListItemCount(n);
LoopRectView.RefreshAllShownItem();
m_tpFuncItem = null;
+ UpdateAllItemSelect();
}
///
@@ -145,14 +146,23 @@ namespace GameLogic
return widget;
}
- ///
- /// 获取item
- ///
- ///
- ///
+ ///
+ /// 获取item
+ ///
+ ///
+ ///
public override TItem GetItem(int index)
{
- return index >= 0 && index < m_itemCache.Count ? m_itemCache.GetValueByIndex(index) : null;
+ for (var i = 0; i < m_itemCache.Count; i++)
+ {
+
+ var item = m_itemCache.GetValueByIndex(i);
+ if (item.GetItemIndex() == index)
+ {
+ return item;
+ }
+ }
+ return null;
}
///
@@ -178,5 +188,21 @@ namespace GameLogic
{
return m_itemCache.GetValueByIndex(index);
}
+
+ ///
+ /// 刷新所有item选中状态
+ ///
+ ///
+ public void UpdateAllItemSelect()
+ {
+ var index = selectIndex;
+ for (var i = 0; i < m_itemCache.Count; i++)
+ {
+ if (m_itemCache.GetValueByIndex(i) is IListSelectItem item)
+ {
+ item.SetSelected(item.GetItemIndex() == index);
+ }
+ }
+ }
}
}
diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopListWidget.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopListWidget.cs
index ed815eb9..e09f151f 100644
--- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopListWidget.cs
+++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopListWidget.cs
@@ -65,8 +65,9 @@ namespace GameLogic
base.AdjustItemNum(n, datas, funcItem);
m_tpFuncItem = funcItem;
LoopRectView.SetListItemCount(n);
- // LoopRectView.RefreshAllShownItem();
+ LoopRectView.RefreshAllShownItem();
m_tpFuncItem = null;
+ UpdateAllItemSelect();
}
///
@@ -151,7 +152,16 @@ namespace GameLogic
///
public override TItem GetItem(int index)
{
- return index >= 0 && index < m_itemCache.Count ? m_itemCache.GetValueByIndex(index) : null;
+ for (var i = 0; i < m_itemCache.Count; i++)
+ {
+
+ var item = m_itemCache.GetValueByIndex(i);
+ if (item.GetItemIndex() == index)
+ {
+ return item;
+ }
+ }
+ return null;
}
///
@@ -186,5 +196,30 @@ namespace GameLogic
{
return m_itemCache.GetValueByIndex(index);
}
+
+ ///
+ /// 刷新所有item选中状态
+ ///
+ ///
+ public void UpdateAllItemSelect()
+ {
+ var index = selectIndex;
+ for (var i = 0; i < m_itemCache.Count; i++)
+ {
+ if (m_itemCache.GetValueByIndex(i) is IListSelectItem item)
+ {
+ item.SetSelected(item.GetItemIndex() == index);
+ }
+ }
+ }
+
+ protected override void UpdateSnapTargetItem()
+ {
+ base.UpdateSnapTargetItem();
+ if (LoopRectView != null && LoopRectView.ItemSnapEnable)
+ {
+ LoopRectView.SetSnapTargetItemIndex(selectIndex);
+ }
+ }
}
}