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/UICommon/UIManager.cs | 586 +++++++++++++++++++++ 1 file changed, 586 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/UI/UICommon/UIManager.cs (limited to 'Client/Assets/Scripts/XMainClient/UI/UICommon/UIManager.cs') diff --git a/Client/Assets/Scripts/XMainClient/UI/UICommon/UIManager.cs b/Client/Assets/Scripts/XMainClient/UI/UICommon/UIManager.cs new file mode 100644 index 00000000..0daba0f9 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/UI/UICommon/UIManager.cs @@ -0,0 +1,586 @@ +using System; +using System.Collections.Generic; +using System.Text; +using UILib; +using UnityEngine; +using XUpdater; +using XUtliPoolLib; + +namespace XMainClient.UI.UICommon +{ + internal class UIManager : XSingleton + { + public Transform UIRoot + { + get + { + return this.m_uiRoot; + } + set + { + this.m_uiRoot = value; + } + } + + private Dictionary m_dicDlgs = new Dictionary(); + + private Dictionary> m_dicUILayer = new Dictionary>(); + + private List m_iterDlgs = new List(); + + private Transform m_uiRoot = null; + + private Dictionary m_GroupDlg = new Dictionary(); + + private List m_ShowedDlg = new List(); + + private int m_TutorialClashUICount = 0; + + private List m_ToBeUnloadDlg = new List(); + + private XLFU m_LFU = new XLFU(5); + + private List m_CachedExculsiveUI = new List(); + + private Stack m_ShowUIStack = new Stack(); + + private List m_StoreUIList = new List(); + + private List m_AvatarStack = new List(); + + public int unloadUICount = 0; + + public void OnEnterScene() + { + this.m_LFU.Clear(); + this.m_ShowedDlg.Clear(); + this.m_TutorialClashUICount = 0; + this.m_CachedExculsiveUI.Clear(); + this.m_ShowUIStack.Clear(); + this.m_ToBeUnloadDlg.Clear(); + this.m_StoreUIList.Clear(); + this.unloadUICount = 0; + } + + public void OnLeaveScene(bool transfer) + { + for (int i = this.m_iterDlgs.Count - 1; i >= 0; i--) + { + bool flag = i < this.m_iterDlgs.Count && this.m_iterDlgs[i] != null; + if (flag) + { + this.m_iterDlgs[i].UnLoad(transfer); + } + } + this.m_AvatarStack.Clear(); + this.unloadUICount = 0; + } + + public override bool Init() + { + RuntimePlatform platform = Application.platform; + int @int; + if ((int)platform != 8) + { + if ((int)platform != 11) + { + @int = XSingleton.singleton.GetInt("UIUnloadLFUSizeDefault"); + } + else + { + @int = XSingleton.singleton.GetInt("UIUnloadLFUSizeAndroid"); + } + } + else + { + @int = XSingleton.singleton.GetInt("UIUnloadLFUSizeIPhone"); + } + this.m_LFU = new XLFU(@int); + return true; + } + + public override void Uninit() + { + } + + public void LoadUI(string strUIFile, LoadUIFinishedEventHandler eventHandler) + { + bool flag = eventHandler != null; + if (flag) + { + eventHandler(strUIFile); + } + } + + public void Update(float fDeltaT) + { + int i = 0; + while (i < this.m_iterDlgs.Count) + { + IXUIDlg ixuidlg = this.m_iterDlgs[i]; + bool flag = ixuidlg != null; + if (flag) + { + bool flag2 = ixuidlg.uiBehaviourInterface == null || ixuidlg.uiBehaviourInterface.gameObject == null; + if (flag2) + { + XSingleton.singleton.AddErrorLog("UI missing: ", ixuidlg.fileName, null, null, null, null); + } + else + { + bool activeInHierarchy = ixuidlg.uiBehaviourInterface.gameObject.activeInHierarchy; + if (activeInHierarchy) + { + ixuidlg.OnUpdate(); + } + } + } + IL_78: + i++; + continue; + goto IL_78; + } + } + + public void PostUpdate(float fDeltaT) + { + for (int i = 0; i < this.m_iterDlgs.Count; i++) + { + bool flag = this.m_iterDlgs[i] != null; + if (flag) + { + this.m_iterDlgs[i].OnPostUpdate(); + } + } + bool flag2 = this.m_ToBeUnloadDlg.Count > 0; + if (flag2) + { + for (int j = 0; j < this.m_ToBeUnloadDlg.Count; j++) + { + this.m_ToBeUnloadDlg[j].UnLoad(false); + } + this.m_ToBeUnloadDlg.Clear(); + } + } + + public bool IsUIShowed() + { + bool flag = this.m_ShowUIStack.Count > 0; + bool result; + if (flag) + { + result = true; + } + else + { + bool flag2 = DlgBase.singleton.IsLoaded() && DlgBase.singleton.IsVisible(); + if (flag2) + { + result = true; + } + else + { + bool flag3 = DlgBase.singleton.IsVisible(); + if (flag3) + { + result = true; + } + else + { + bool flag4 = XSingleton.singleton.XLuaEngine.luaUIManager.IsUIShowed(); + result = flag4; + } + } + } + return result; + } + + public bool IsHideTutorial() + { + return this.m_TutorialClashUICount != 0; + } + + public int GetUIStackCount() + { + return this.m_ShowUIStack.Count; + } + + public int GetFullScreenUICount() + { + int num = 0; + foreach (IXUIDlg ixuidlg in this.m_ShowUIStack) + { + bool fullscreenui = ixuidlg.fullscreenui; + if (fullscreenui) + { + num++; + } + } + return num; + } + + public void RemoveDlg(IXUIDlg dlg) + { + List list = null; + bool flag = this.m_dicUILayer.TryGetValue(dlg.layer, out list); + if (flag) + { + list.Remove(dlg); + } + bool flag2 = this.m_dicDlgs.ContainsKey(dlg.fileName); + if (flag2) + { + this.m_dicDlgs.Remove(dlg.fileName); + this.m_iterDlgs.Remove(dlg); + } + bool flag3 = this.m_GroupDlg.ContainsKey(dlg.group); + if (flag3) + { + this.m_GroupDlg.Remove(dlg.group); + } + bool flag4 = this.m_ShowedDlg.Contains(dlg); + if (flag4) + { + bool isHideTutorial = dlg.isHideTutorial; + if (isHideTutorial) + { + this.ChangeTutorialClashUI(false); + } + this.m_ShowedDlg.Remove(dlg); + } + this.m_LFU.Remove(dlg); + this.m_AvatarStack.Remove(dlg); + } + + public bool AddDlg(IXUIDlg dlg) + { + bool flag = this.m_dicDlgs.ContainsKey(dlg.fileName); + bool result; + if (flag) + { + XSingleton.singleton.AddLog("true == m_dicDlgs.ContainsKey(dlg.fileName): ", dlg.fileName, null, null, null, null, XDebugColor.XDebug_None); + result = false; + } + else + { + this.m_dicDlgs.Add(dlg.fileName, dlg); + this.m_iterDlgs.Add(dlg); + List list = null; + bool flag2 = this.m_dicUILayer.TryGetValue(dlg.layer, out list); + if (flag2) + { + list.Add(dlg); + } + else + { + list = new List(); + list.Add(dlg); + this.m_dicUILayer.Add(dlg.layer, list); + } + result = true; + } + return result; + } + + protected void CacheExclusiveUI() + { + this.m_CachedExculsiveUI.Clear(); + for (int i = 0; i < this.m_ShowedDlg.Count; i++) + { + this.m_CachedExculsiveUI.Add(this.m_ShowedDlg[i]); + } + } + + public void CloseAllUI() + { + this.ClearUIinStack(); + List list = new List(); + for (int i = 0; i < this.m_ShowedDlg.Count; i++) + { + bool flag = !this.m_ShowedDlg[i].isMainUI; + if (flag) + { + list.Add(this.m_ShowedDlg[i]); + } + } + for (int j = 0; j < list.Count; j++) + { + list[j].SetVisible(false, true); + } + } + + public void OnDlgShow(IXUIDlg dlg) + { + bool exclusive = dlg.exclusive; + if (exclusive) + { + this.CloseAllUI(); + this.CacheExclusiveUI(); + for (int i = 0; i < this.m_CachedExculsiveUI.Count; i++) + { + this.m_CachedExculsiveUI[i].uiBehaviourInterface.uiDlgInterface.SetVisiblePure(false); + } + this.ChangeTutorialClashUI(true); + } + else + { + bool flag = !this.m_ShowedDlg.Contains(dlg); + if (flag) + { + this.m_ShowedDlg.Add(dlg); + bool isHideTutorial = dlg.isHideTutorial; + if (isHideTutorial) + { + this.ChangeTutorialClashUI(true); + } + } + bool flag2 = !dlg.needOnTop; + if (flag2) + { + this.m_AvatarStack.Remove(dlg); + this.m_AvatarStack.Add(dlg); + } + else + { + Vector3 localPosition = dlg.uiBehaviourInterface.gameObject.transform.localPosition; + localPosition.z = 0f; + dlg.uiBehaviourInterface.gameObject.transform.localPosition = localPosition; + } + float num = 0f; + for (int j = this.m_AvatarStack.Count - 1; j >= 0; j--) + { + IXUIDlg ixuidlg = this.m_AvatarStack[j]; + Vector3 localPosition2 = ixuidlg.uiBehaviourInterface.gameObject.transform.localPosition; + localPosition2.z = num; + ixuidlg.uiBehaviourInterface.gameObject.transform.localPosition = localPosition2; + num += 800f; + } + } + bool pushstack = dlg.pushstack; + if (pushstack) + { + IXUIDlg ixuidlg2 = this.m_LFU.Add(dlg); + bool flag3 = ixuidlg2 != null; + if (flag3) + { + this.m_ToBeUnloadDlg.Add(ixuidlg2); + XSingleton.singleton.AddGreenLog("Auto Unload UI: ", ixuidlg2.fileName, " while opening ", dlg.fileName, null, null); + } + XSingleton.singleton.Cancel(); + } + bool hideMainMenu = dlg.hideMainMenu; + if (hideMainMenu) + { + this.UIBlurEffect(true); + } + bool pushstack2 = dlg.pushstack; + if (pushstack2) + { + XMainInterfaceDocument specificDocument = XDocuments.GetSpecificDocument(XMainInterfaceDocument.uuID); + bool flag4 = this.m_ShowUIStack.Count > 0; + if (flag4) + { + IXUIDlg ixuidlg3 = this.m_ShowUIStack.Peek(); + ixuidlg3.LeaveStackTop(); + ixuidlg3.uiBehaviourInterface.uiDlgInterface.SetVisiblePure(false); + Stack stack = new Stack(); + IXUIDlg ixuidlg4 = this.m_ShowUIStack.Pop(); + while (ixuidlg4 != dlg && this.m_ShowUIStack.Count > 0) + { + stack.Push(ixuidlg4); + ixuidlg4 = this.m_ShowUIStack.Pop(); + } + bool flag5 = ixuidlg4 != dlg; + if (flag5) + { + this.m_ShowUIStack.Push(ixuidlg4); + } + while (stack.Count > 0) + { + this.m_ShowUIStack.Push(stack.Pop()); + } + } + this.m_ShowUIStack.Push(dlg); + specificDocument.OnTopUIRefreshed(dlg); + } + DlgBase.singleton.TryCloseChat(dlg); + } + + public void UIBlurEffect(bool bOn) + { + bool flag = DlgBase.singleton.IsLoaded(); + if (flag) + { + DlgBase.singleton.FakeShowSelf(!bOn); + } + } + + public void OnDlgHide(IXUIDlg dlg) + { + bool exclusive = dlg.exclusive; + if (exclusive) + { + for (int i = 0; i < this.m_CachedExculsiveUI.Count; i++) + { + this.m_CachedExculsiveUI[i].uiBehaviourInterface.uiDlgInterface.SetVisiblePure(true); + } + this.ChangeTutorialClashUI(false); + } + else + { + this.m_ShowedDlg.Remove(dlg); + bool isHideTutorial = dlg.isHideTutorial; + if (isHideTutorial) + { + this.ChangeTutorialClashUI(false); + } + this.m_AvatarStack.Remove(dlg); + } + bool pushstack = dlg.pushstack; + if (pushstack) + { + this.m_LFU.MarkCanPop(dlg, true); + } + bool hideMainMenu = dlg.hideMainMenu; + if (hideMainMenu) + { + this.UIBlurEffect(false); + } + bool flag = dlg.pushstack && this.m_ShowUIStack.Count > 0; + if (flag) + { + IXUIDlg ixuidlg = this.m_ShowUIStack.Peek(); + bool flag2 = ixuidlg != dlg; + if (flag2) + { + XSingleton.singleton.AddLog("Not hide top of ui stack!:", dlg.fileName, null, null, null, null, XDebugColor.XDebug_None); + Stack stack = new Stack(); + for (IXUIDlg ixuidlg2 = this.m_ShowUIStack.Pop(); ixuidlg2 != dlg; ixuidlg2 = this.m_ShowUIStack.Pop()) + { + stack.Push(ixuidlg2); + bool flag3 = this.m_ShowUIStack.Count == 0; + if (flag3) + { + StringBuilder sharedStringBuilder = XSingleton.singleton.GetSharedStringBuilder(); + sharedStringBuilder.Length = 0; + sharedStringBuilder.Append("Hide UI not in stack!!!! : ").Append(dlg.fileName); + sharedStringBuilder.Append("; UIs in stack: "); + foreach (IXUIDlg ixuidlg3 in stack) + { + sharedStringBuilder.Append(ixuidlg3.fileName).Append(" "); + } + XSingleton.singleton.AddErrorLog(sharedStringBuilder.ToString(), null, null, null, null, null); + break; + } + } + while (stack.Count > 0) + { + this.m_ShowUIStack.Push(stack.Pop()); + } + bool flag4 = this.m_ShowUIStack.Count > 0; + if (flag4) + { + IXUIDlg ixuidlg4 = this.m_ShowUIStack.Peek(); + bool hideMainMenu2 = ixuidlg4.hideMainMenu; + if (hideMainMenu2) + { + this.UIBlurEffect(true); + } + } + } + else + { + this.m_ShowUIStack.Pop(); + XMainInterfaceDocument specificDocument = XDocuments.GetSpecificDocument(XMainInterfaceDocument.uuID); + bool flag5 = this.m_ShowUIStack.Count > 0; + if (flag5) + { + IXUIDlg ixuidlg5 = this.m_ShowUIStack.Peek(); + ixuidlg5.uiBehaviourInterface.uiDlgInterface.SetVisiblePure(true); + ixuidlg5.StackRefresh(); + specificDocument.OnTopUIRefreshed(ixuidlg5); + bool hideMainMenu3 = ixuidlg5.hideMainMenu; + if (hideMainMenu3) + { + this.UIBlurEffect(true); + } + } + else + { + specificDocument.OnTopUIRefreshed(null); + } + } + } + } + + public List GetShowedUI() + { + return this.m_ShowedDlg; + } + + public void ClearUIinStack() + { + while (this.m_ShowUIStack.Count > 0) + { + IXUIDlg ixuidlg = this.m_ShowUIStack.Peek(); + bool flag = ixuidlg != null; + if (flag) + { + ixuidlg.SetVisiblePure(true); + ixuidlg.SetVisible(false, true); + } + } + this.UIBlurEffect(false); + } + + public void HideAllUIWithOutCall() + { + for (int i = 0; i < this.m_ShowedDlg.Count; i++) + { + bool flag = this.m_ShowedDlg[i] == DlgBase.singleton || this.m_ShowedDlg[i] == DlgBase.singleton || this.m_ShowedDlg[i] == DlgBase.singleton; + if (!flag) + { + bool flag2 = this.m_ShowedDlg[i].IsVisible(); + if (flag2) + { + this.m_StoreUIList.Add(this.m_ShowedDlg[i]); + this.m_ShowedDlg[i].SetVisiblePure(false); + } + } + } + } + + public void RestoreAllUIWithOutCall() + { + for (int i = 0; i < this.m_StoreUIList.Count; i++) + { + bool flag = this.m_StoreUIList[i] != null; + if (flag) + { + this.m_StoreUIList[i].SetVisiblePure(true); + } + } + this.m_StoreUIList.Clear(); + } + + private void ChangeTutorialClashUI(bool isAdd) + { + if (isAdd) + { + this.m_TutorialClashUICount++; + XSingleton.singleton.AddGreenLog("TutorialClashUICount++:" + this.m_TutorialClashUICount, null, null, null, null, null); + } + else + { + this.m_TutorialClashUICount--; + XSingleton.singleton.AddGreenLog("TutorialClashUICount--:" + this.m_TutorialClashUICount, null, null, null, null, null); + bool flag = this.m_TutorialClashUICount < 0; + if (flag) + { + this.m_TutorialClashUICount = 0; + XSingleton.singleton.AddErrorLog("TutorialClashUICount Error", null, null, null, null, null); + } + } + } + } +} -- cgit v1.1-26-g67d0