summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/UI/FashionComboBox.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XMainClient/UI/FashionComboBox.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/UI/FashionComboBox.cs')
-rw-r--r--Client/Assets/Scripts/XMainClient/UI/FashionComboBox.cs88
1 files changed, 88 insertions, 0 deletions
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<XGameUI>.singleton.m_uiTool);
+
+ private int itemPerRow = 0;
+
+ private int itemcount = 0;
+
+ private Dictionary<int, string> value2string = new Dictionary<int, string>();
+
+ 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);
+ }
+ }
+ }
+}