From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/XBagWindow.cs | 167 ++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XBagWindow.cs (limited to 'Client/Assets/Scripts/XMainClient/XBagWindow.cs') diff --git a/Client/Assets/Scripts/XMainClient/XBagWindow.cs b/Client/Assets/Scripts/XMainClient/XBagWindow.cs new file mode 100644 index 00000000..78a260ff --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XBagWindow.cs @@ -0,0 +1,167 @@ +using System; +using System.Collections.Generic; +using UILib; +using UnityEngine; +using XUtliPoolLib; + +namespace XMainClient +{ + internal class XBagWindow + { + public int COL_COUNT = 6; + + public int ROW_COUNT = 4; + + public GameObject PanelObject; + + private IXUIWrapContent m_WrapContent; + + private IXUIScrollView m_ScrollView; + + private XUIPool m_ItemPool = new XUIPool(XSingleton.singleton.m_uiTool); + + public List m_XItemIDList = new List(); + + public List m_XItemList; + + private ItemUpdateHandler itemUpdateHandler = null; + + private GetItemHandler getItemHandler = null; + + public XBagWindow(GameObject PanelGo, ItemUpdateHandler updateHandler, GetItemHandler getHandler) + { + this.PanelObject = PanelGo; + this.itemUpdateHandler = updateHandler; + this.getItemHandler = getHandler; + } + + public void Init() + { + Transform transform = this.PanelObject.transform.Find("Panel/WrapContent/ItemTpl"); + this.m_ScrollView = (this.PanelObject.transform.Find("Panel").GetComponent("XUIScrollView") as IXUIScrollView); + this.m_WrapContent = (this.PanelObject.transform.Find("Panel/WrapContent").GetComponent("XUIWrapContent") as IXUIWrapContent); + this.m_WrapContent.RegisterItemUpdateEventHandler(new WrapItemUpdateEventHandler(this.WrapContentItemUpdated)); + this.COL_COUNT = this.m_WrapContent.widthDimension; + this.ROW_COUNT = this.m_WrapContent.heightDimensionMax; + } + + private void WrapContentItemUpdated(Transform t, int index) + { + this.itemUpdateHandler(t, index); + } + + public void ChangeData(ItemUpdateHandler updateHandler, GetItemHandler getHandler) + { + this.itemUpdateHandler = updateHandler; + this.getItemHandler = getHandler; + } + + public void OnShow() + { + this.UpdateBag(); + this.m_ScrollView.ResetPosition(); + } + + public void OnHide() + { + this.m_ItemPool.ReturnAll(true); + this.m_XItemIDList.Clear(); + } + + protected void _RefreshBag() + { + int num = Math.Max(this.m_XItemList.Count, this.COL_COUNT * this.ROW_COUNT); + this.m_WrapContent.SetContentCount(num, false); + } + + public void UpdateBag() + { + this.GetItemData(this.getItemHandler()); + this.m_XItemIDList.Clear(); + for (int i = 0; i < this.m_XItemList.Count; i++) + { + bool flag = this.m_XItemList[i] != null; + if (flag) + { + this.m_XItemIDList.Add(this.m_XItemList[i].uid); + } + else + { + this.m_XItemIDList.Add(0UL); + } + } + this._RefreshBag(); + } + + private void GetItemData(List lst) + { + bool flag = this.m_XItemList != null; + if (flag) + { + this.m_XItemList.Clear(); + } + else + { + this.m_XItemList = new List(); + } + for (int i = 0; i < lst.Count; i++) + { + this.m_XItemList.Add(lst[i]); + } + } + + public void RefreshWindow() + { + this.m_WrapContent.RefreshAllVisibleContents(); + } + + public void UpdateItem(XItem item) + { + for (int i = 0; i < this.m_XItemList.Count; i++) + { + bool flag = this.m_XItemIDList[i] == item.uid; + if (flag) + { + this.m_XItemList[i] = item; + break; + } + } + this.RefreshWindow(); + } + + public void ReplaceItem(XItem from, XItem to) + { + for (int i = 0; i < this.m_XItemList.Count; i++) + { + bool flag = this.m_XItemIDList[i] == from.uid; + if (flag) + { + this.m_XItemList[i] = to; + this.m_XItemIDList[i] = to.uid; + break; + } + } + this.RefreshWindow(); + } + + public void ResetPosition() + { + this.m_ScrollView.ResetPosition(); + } + + public Transform FindChildByName(string name) + { + bool flag = this.m_WrapContent != null; + Transform result; + if (flag) + { + result = this.m_WrapContent.gameObject.transform.Find(name); + } + else + { + result = null; + } + return result; + } + } +} -- cgit v1.1-26-g67d0