From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../Scripts/XMainClient/Utility/XUITabControl.cs | 287 +++++++++++++++++++++ 1 file changed, 287 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/Utility/XUITabControl.cs (limited to 'Client/Assets/Scripts/XMainClient/Utility/XUITabControl.cs') diff --git a/Client/Assets/Scripts/XMainClient/Utility/XUITabControl.cs b/Client/Assets/Scripts/XMainClient/Utility/XUITabControl.cs new file mode 100644 index 00000000..95e0d6a4 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/Utility/XUITabControl.cs @@ -0,0 +1,287 @@ +using System; +using System.Collections.Generic; +using UILib; +using UnityEngine; +using XUtliPoolLib; + +namespace XMainClient.Utility +{ + internal class XUITabControl + { + private XUIPool tab_pool = new XUIPool(XSingleton.singleton.m_uiTool); + + protected float m_DisableAlpha; + + private Dictionary m_TabFrames = new Dictionary(); + + public delegate void UITabControlCallback(ulong id); + + public IXUICheckBox GetByCheckBoxId(ulong id) + { + List list = ListPool.Get(); + this.tab_pool.GetActiveList(list); + IXUICheckBox ixuicheckBox = null; + for (int i = 0; i < list.Count; i++) + { + IXUICheckBox ixuicheckBox2 = list[i].transform.Find("Bg").GetComponent("XUICheckBox") as IXUICheckBox; + bool flag = ixuicheckBox2.ID == id; + if (flag) + { + ixuicheckBox = ixuicheckBox2; + break; + } + } + ListPool.Release(list); + bool flag2 = ixuicheckBox == null; + if (flag2) + { + XSingleton.singleton.AddErrorLog("Have not this CheckBox of id.", null, null, null, null, null); + } + return ixuicheckBox; + } + + public void SetTabTpl(Transform tpl) + { + this.tab_pool.SetupPool(tpl.parent.gameObject, tpl.gameObject, 5u, false); + } + + public static XSysDefine GetTargetSys(XSysDefine sys, out List subSys) + { + XSysDefine parentSys = XSingleton.singleton.GetParentSys(sys); + subSys = XSingleton.singleton.GetChildSys(parentSys); + XSysDefine xsysDefine = sys; + bool flag = sys == parentSys; + if (flag) + { + for (int i = 0; i < subSys.Count; i++) + { + bool flag2 = !XSingleton.singleton.IsSystemOpened(subSys[i], XSingleton.singleton.XPlayerData); + if (!flag2) + { + bool flag3 = xsysDefine == parentSys; + if (flag3) + { + xsysDefine = subSys[i]; + } + bool sysRedPointState = XSingleton.singleton.GetSysRedPointState(subSys[i]); + if (sysRedPointState) + { + xsysDefine = subSys[i]; + break; + } + } + } + } + return xsysDefine; + } + + public IXUICheckBox[] SetupTabs(XSysDefine sys, XUITabControl.UITabControlCallback func, bool bHorizontal = false, float fDisable = 1f) + { + this.tab_pool.ReturnAll(false); + this.m_TabFrames.Clear(); + XPlayerAttributes xplayerData = XSingleton.singleton.XPlayerData; + XSysDefine parentSys = XSingleton.singleton.GetParentSys(sys); + List childSys = XSingleton.singleton.GetChildSys(parentSys); + Vector3 localPosition = this.tab_pool._tpl.transform.localPosition; + float num = (float)this.tab_pool.TplWidth; + float num2 = (float)this.tab_pool.TplHeight; + IXUICheckBox[] array = new IXUICheckBox[childSys.Count]; + IXUICheckBox ixuicheckBox = null; + XSysDefine xsysDefine = sys; + bool flag = sys == parentSys; + if (flag) + { + for (int i = 0; i < childSys.Count; i++) + { + bool flag2 = !XSingleton.singleton.IsSystemOpened(childSys[i], xplayerData); + if (!flag2) + { + bool flag3 = xsysDefine == parentSys; + if (flag3) + { + xsysDefine = childSys[i]; + } + bool sysRedPointState = XSingleton.singleton.GetSysRedPointState(childSys[i]); + if (sysRedPointState) + { + xsysDefine = childSys[i]; + break; + } + } + } + } + int j = 0; + int num3 = 0; + while (j < childSys.Count) + { + bool flag4 = !XSingleton.singleton.IsSystemOpened(childSys[j], xplayerData); + if (!flag4) + { + GameObject gameObject = this.tab_pool.FetchGameObject(false); + gameObject.name = childSys[j].ToString(); + if (bHorizontal) + { + gameObject.transform.localPosition = localPosition + new Vector3(num * (float)num3, 0f, 0f); + } + else + { + gameObject.transform.localPosition = localPosition + new Vector3(0f, -num2 * (float)num3, 0f); + } + num3++; + IXUICheckBox ixuicheckBox2 = gameObject.transform.Find("Bg").GetComponent("XUICheckBox") as IXUICheckBox; + ixuicheckBox2.ID = (ulong)((long)XFastEnumIntEqualityComparer.ToInt(childSys[j])); + ixuicheckBox2.ForceSetFlag(false); + ixuicheckBox2.RegisterOnCheckEventHandler(new CheckBoxOnCheckEventHandler(this.OnTabControlStateChange)); + array[j] = ixuicheckBox2; + this.m_TabFrames.Add((int)ixuicheckBox2.ID, func); + Transform transform = gameObject.transform.Find("Bg/TextLabel"); + bool flag5 = transform != null; + if (flag5) + { + IXUILabel ixuilabel = transform.GetComponent("XUILabel") as IXUILabel; + IXUILabel ixuilabel2 = gameObject.transform.Find("Bg/SelectedTextLabel").GetComponent("XUILabel") as IXUILabel; + string @string = XStringDefineProxy.GetString(childSys[j].ToString()); + ixuilabel.SetText(@string); + ixuilabel2.SetText(@string); + } + else + { + IXUISprite ixuisprite = gameObject.transform.Find("Bg/Text").GetComponent("XUISprite") as IXUISprite; + IXUISprite ixuisprite2 = gameObject.transform.Find("Bg/SelectedText").GetComponent("XUISprite") as IXUISprite; + string string2 = XStringDefineProxy.GetString(childSys[j].ToString()); + ixuisprite.SetSprite(string2 + "0"); + ixuisprite2.SetSprite(string2 + "1"); + ixuisprite.MakePixelPerfect(); + ixuisprite2.MakePixelPerfect(); + } + bool flag6 = childSys[j] == xsysDefine; + if (flag6) + { + ixuicheckBox = ixuicheckBox2; + } + } + j++; + } + bool flag7 = ixuicheckBox != null; + if (flag7) + { + ixuicheckBox.bChecked = true; + } + this.m_DisableAlpha = fDisable; + return array; + } + + public IXUICheckBox[] SetupTabs(List ids, List prefix, XUITabControl.UITabControlCallback func, bool bHorizontal = false, float fDisable = 1f, int select = -1, bool bFromStringTable = true) + { + this.tab_pool.ReturnAll(false); + this.m_TabFrames.Clear(); + Vector3 localPosition = this.tab_pool._tpl.transform.localPosition; + float num = (float)this.tab_pool.TplWidth; + float num2 = (float)this.tab_pool.TplHeight; + IXUICheckBox[] array = new IXUICheckBox[ids.Count]; + IXUICheckBox ixuicheckBox = null; + bool flag = select == -1; + if (flag) + { + select = 0; + } + else + { + select = ids.IndexOf(select); + } + bool flag2 = select == -1; + if (flag2) + { + select = 0; + } + for (int i = 0; i < ids.Count; i++) + { + GameObject gameObject = this.tab_pool.FetchGameObject(false); + gameObject.name = ids[i].ToString(); + if (bHorizontal) + { + gameObject.transform.localPosition = localPosition + new Vector3(num * (float)i, 0f, 0f); + } + else + { + gameObject.transform.localPosition = localPosition + new Vector3(0f, -num2 * (float)i, 0f); + } + IXUICheckBox ixuicheckBox2 = gameObject.transform.Find("Bg").GetComponent("XUICheckBox") as IXUICheckBox; + ixuicheckBox2.ID = (ulong)((long)ids[i]); + ixuicheckBox2.ForceSetFlag(false); + ixuicheckBox2.RegisterOnCheckEventHandler(new CheckBoxOnCheckEventHandler(this.OnTabControlStateChange)); + array[i] = ixuicheckBox2; + this.m_TabFrames.Add((int)ixuicheckBox2.ID, func); + Transform transform = gameObject.transform.Find("Bg/TextLabel"); + bool flag3 = transform != null; + if (flag3) + { + IXUILabel ixuilabel = transform.GetComponent("XUILabel") as IXUILabel; + IXUILabel ixuilabel2 = gameObject.transform.Find("Bg/SelectedTextLabel").GetComponent("XUILabel") as IXUILabel; + string text = bFromStringTable ? XStringDefineProxy.GetString(prefix[i]) : prefix[i]; + ixuilabel.SetText(text); + ixuilabel2.SetText(text); + } + else + { + IXUISprite ixuisprite = gameObject.transform.Find("Bg/Text").GetComponent("XUISprite") as IXUISprite; + IXUISprite ixuisprite2 = gameObject.transform.Find("Bg/SelectedText").GetComponent("XUISprite") as IXUISprite; + ixuisprite.SetSprite(prefix[i] + "0"); + ixuisprite2.SetSprite(prefix[i] + "1"); + ixuisprite.MakePixelPerfect(); + ixuisprite2.MakePixelPerfect(); + } + bool flag4 = i == select; + if (flag4) + { + ixuicheckBox = ixuicheckBox2; + } + } + bool flag5 = ixuicheckBox != null; + if (flag5) + { + ixuicheckBox.bChecked = true; + } + this.m_DisableAlpha = fDisable; + return array; + } + + public void RegistrerNewTab(ulong id, XUITabControl.UITabControlCallback func) + { + List list = ListPool.Get(); + this.tab_pool.GetActiveList(list); + for (int i = 0; i < list.Count; i++) + { + IXUICheckBox ixuicheckBox = list[i].transform.Find("Bg").GetComponent("XUICheckBox") as IXUICheckBox; + bool flag = ixuicheckBox.ID == id; + if (flag) + { + ixuicheckBox.RegisterOnCheckEventHandler(new CheckBoxOnCheckEventHandler(this.OnTabControlStateChange)); + this.m_TabFrames.Add((int)id, func); + } + } + ListPool.Release(list); + } + + public bool OnTabControlStateChange(IXUICheckBox chkBox) + { + bool bChecked = chkBox.bChecked; + if (bChecked) + { + int key = (int)chkBox.ID; + XUITabControl.UITabControlCallback uitabControlCallback = this.m_TabFrames[key]; + bool flag = uitabControlCallback != null; + if (flag) + { + uitabControlCallback(chkBox.ID); + } + chkBox.SetAlpha(1f); + } + else + { + chkBox.SetAlpha(this.m_DisableAlpha); + } + return true; + } + } +} -- cgit v1.1-26-g67d0