From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/UI/FashionComboBox.cs | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/UI/FashionComboBox.cs (limited to 'Client/Assets/Scripts/XMainClient/UI/FashionComboBox.cs') diff --git a/Client/Assets/Scripts/XMainClient/UI/FashionComboBox.cs b/Client/Assets/Scripts/XMainClient/UI/FashionComboBox.cs new file mode 100644 index 00000000..ed0ab8d1 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/UI/FashionComboBox.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using UILib; +using UnityEngine; +using XUtliPoolLib; + +namespace XMainClient.UI +{ + internal class FashionComboBox + { + private ComboboxClickEventHandler _handler; + + private IXUISprite selector = null; + + private Transform droplist = null; + + private IXUISprite close = null; + + private IXUILabel selecttext = null; + + private XUIPool itempool = new XUIPool(XSingleton.singleton.m_uiTool); + + private int itemPerRow = 0; + + private int itemcount = 0; + + private Dictionary value2string = new Dictionary(); + + public FashionComboBox(GameObject go, ComboboxClickEventHandler handler, int PerRow = 2) + { + this._handler = handler; + this.itemPerRow = PerRow; + this.selector = (go.transform.Find("Difficulty").GetComponent("XUISprite") as IXUISprite); + this.close = (go.transform.Find("Difficulty/DropList/Close").GetComponent("XUISprite") as IXUISprite); + this.selecttext = (go.transform.Find("Difficulty/SelectedText").GetComponent("XUILabel") as IXUILabel); + this.droplist = go.transform.Find("Difficulty/DropList"); + Transform transform = go.transform.Find("Difficulty/DropList/ItemTpl"); + this.itempool.SetupPool(this.droplist.gameObject, transform.gameObject, 6u, false); + this.droplist.gameObject.SetActive(false); + this.selector.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnSelectorClick)); + this.close.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnCloseClick)); + } + + private void OnSelectorClick(IXUISprite sp) + { + this.droplist.gameObject.SetActive(true); + } + + private void OnCloseClick(IXUISprite sp) + { + this.droplist.gameObject.SetActive(false); + } + + public void AddItem(string text, int value) + { + GameObject gameObject = this.itempool.FetchGameObject(false); + int num = this.itemcount % this.itemPerRow; + int num2 = this.itemcount / this.itemPerRow; + gameObject.transform.localPosition = this.itempool.TplPos + new Vector3((float)(num * this.itempool.TplWidth), (float)(-(float)num2 * this.itempool.TplHeight)); + IXUISprite ixuisprite = gameObject.GetComponent("XUISprite") as IXUISprite; + ixuisprite.ID = (ulong)((long)value); + ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnItemClick)); + IXUILabel ixuilabel = gameObject.transform.Find("ItemText").GetComponent("XUILabel") as IXUILabel; + ixuilabel.SetText(text); + this.value2string.Add(value, text); + this.itemcount++; + } + + private void OnItemClick(IXUISprite sp) + { + this.selecttext.SetText(this.value2string[(int)sp.ID]); + this.droplist.gameObject.SetActive(false); + this._handler((int)sp.ID); + } + + public void SetSelect(int value) + { + string text; + bool flag = this.value2string.TryGetValue(value, out text); + if (flag) + { + this.selecttext.SetText(text); + this.droplist.gameObject.SetActive(false); + this._handler(value); + } + } + } +} -- cgit v1.1-26-g67d0