using System; using UILib; using UnityEngine; using XUpdater; using XUtliPoolLib; namespace XMainClient.UI.UICommon { //c 界面逻辑控制器基类 public abstract class DlgBase : IXUIDlg, IDlgHandlerMgr where TDlgClass : IXUIDlg, new() where TUIBehaviour : DlgBehaviourBase { public static TDlgClass singleton { get { bool flag = DlgBase.s_instance == null; if (flag) { object obj = DlgBase.s_objLock; lock (obj) { bool flag2 = DlgBase.s_instance == null; if (flag2) { DlgBase.s_instance = Activator.CreateInstance(); } } } return DlgBase.s_instance; } } public IXUIBehaviour uiBehaviourInterface { get { return this.m_uiBehaviour; } } public TUIBehaviour uiBehaviour { get { return this.m_uiBehaviour; } } public virtual string fileName { get { return ""; } } public string luaFileName { get { bool flag = this.fileName.Length > 1 && this.fileName.Contains("/"); string result; if (flag) { result = this.fileName.Substring(this.fileName.LastIndexOf('/') + 1); } else { result = this.fileName; } return result; } } public virtual int layer { get { return 2; } } public virtual int group { get { return 0; } } public virtual bool exclusive { get { return false; } } public virtual bool autoload { get { return false; } } public virtual bool isHideChat { get { return true; } } public virtual bool hideMainMenu { get { return false; } } public virtual bool pushstack { get { return false; } } public virtual bool isMainUI { get { return false; } } public virtual bool isHideTutorial { get { return false; } } public virtual int sysid { get { return 0; } } public virtual bool fullscreenui { get { return false; } } public bool Prepared { get { return null != this.m_uiBehaviour; } } public virtual bool isPopup { get { return false; } } public virtual bool needOnTop { get { return false; } } public DlgHandlerMgr HandlerMgr { get { return this.m_DlgHandlerMgr; } } private LoadUIFinishedEventHandler _loadUICb = null; protected int m_dummPool = -1; private IXNGUICallback panelCB = null; protected TUIBehaviour m_uiBehaviour = default(TUIBehaviour); private static TDlgClass s_instance = default(TDlgClass); private static object s_objLock = new object(); private bool m_bVisible = false; protected bool m_bLoaded = false; private float m_fDepthZ = 0f; private bool m_bBindedReverse = false; private Transform m_DlgController = null; private bool m_bCacheVisible = false; private DlgBase.OnAnimationOver m_animationOver; private IXUIDlg m_RelatedDlg; private DlgHandlerMgr m_DlgHandlerMgr = new DlgHandlerMgr(); public delegate void OnAnimationOver(); public DlgBase() { this._loadUICb = new LoadUIFinishedEventHandler(this.OnLoadUIFinishedEventHandler); } public virtual void OnUpdate() { this.HandlerMgr.OnUpdate(); } public virtual void OnPostUpdate() { } public void SetVisiblePure(bool bVisible) { bool flag = !this.m_bLoaded && this.autoload; if (flag) { this.Load(); } else { bool flag2 = !this.m_bLoaded && !this.autoload; if (flag2) { return; } } this.uiBehaviour.SetVisible(bVisible); this.m_bVisible = bVisible; this.OnSetVisiblePure(bVisible); bool flag3 = this.m_RelatedDlg != null; if (flag3) { this.m_RelatedDlg.SetRelatedVisible(this.m_bVisible); } } public virtual void SetVisible(bool bIsVisible, bool bEnableAuto = true) { bool bLoaded = this.m_bLoaded; if (!bLoaded) { bool flag = this.autoload && bEnableAuto; if (!flag) { return; } this.Load(); } bool flag2 = bIsVisible && !this._CanShow(); if (!flag2) { bool prepared = this.Prepared; if (prepared) { bool flag3 = this.m_bVisible != bIsVisible; if (flag3) { this.uiBehaviour.SetVisible(bIsVisible); this.m_bVisible = bIsVisible; if (bIsVisible) { XSingleton.singleton.OnDlgShow(DlgBase.s_instance); ILuaEngine xluaEngine = XSingleton.singleton.XLuaEngine; bool flag4 = !xluaEngine.hotfixMgr.TryFixRefresh(HotfixMode.BEFORE, this.luaFileName, this.uiBehaviour.gameObject); if (flag4) { this.OnShow(); xluaEngine.hotfixMgr.TryFixRefresh(HotfixMode.AFTER, this.luaFileName, this.uiBehaviour.gameObject); } bool flag5 = this.fullscreenui && XSingleton.singleton.GameCamera != null && XSingleton.singleton.GameCamera.UnityCamera != null; if (flag5) { XSingleton.singleton.GameCamera.UnityCamera.enabled = false; } } else { this.OnHide(); XSingleton.singleton.OnDlgHide(DlgBase.s_instance); ILuaEngine xluaEngine2 = XSingleton.singleton.XLuaEngine; xluaEngine2.hotfixMgr.TryFixRefresh(HotfixMode.HIDE, this.luaFileName, this.uiBehaviour.gameObject); bool flag6 = XSingleton.singleton.GetFullScreenUICount() == 0 && XSingleton.singleton.GameCamera != null && XSingleton.singleton.GameCamera.UnityCamera != null; if (flag6) { XSingleton.singleton.GameCamera.UnityCamera.enabled = true; } } bool flag7 = this.m_RelatedDlg != null; if (flag7) { this.m_RelatedDlg.SetVisible(this.m_bVisible, true); } } } } } public virtual void SetVisibleWithAnimation(bool bVisible, DlgBase.OnAnimationOver AnimationOverDelegate) { bool flag = !this.m_bLoaded; if (flag) { this.Load(); } bool flag2 = bVisible && !this._CanShow(); if (!flag2) { int fullScreenUICount = XSingleton.singleton.GetFullScreenUICount(); bool flag3 = (bVisible && fullScreenUICount > 0) || (!bVisible && ((this.fullscreenui && fullScreenUICount > 1) || (!this.fullscreenui && fullScreenUICount > 0))); if (flag3) { this.SetVisible(bVisible, true); bool flag4 = AnimationOverDelegate != null; if (flag4) { AnimationOverDelegate(); } } else { this.SetVisible(bVisible, true); this.m_bCacheVisible = bVisible; this.m_animationOver = AnimationOverDelegate; bool flag5 = AnimationOverDelegate != null; if (flag5) { AnimationOverDelegate(); } } } } protected void OnShowAnimationFinish(IXUITweenTool tween) { bool fullscreenui = this.fullscreenui; if (fullscreenui) { XSingleton.singleton.GameCamera.UnityCamera.enabled = false; } } protected void OnCloseAnimationFinish(IXUITweenTool tween) { this.SetVisible(false, true); bool flag = this.m_animationOver != null; if (flag) { this.m_animationOver(); } } protected virtual void OnShow() { } protected virtual void OnHide() { } protected virtual void OnLoad() { } protected virtual void OnUnload() { this.UnRegisterEvent(); } public bool IsVisible() { bool bLoaded = this.m_bLoaded; return bLoaded && this.uiBehaviour.IsVisible(); } public void SetDepthZ(int nDepthZ) { this.m_fDepthZ = (float)(nDepthZ * 10); bool prepared = this.Prepared; if (prepared) { Vector3 localPosition = this.uiBehaviour.transform.localPosition; localPosition.z = this.m_fDepthZ; this.uiBehaviour.transform.localPosition = localPosition; } } public virtual void Reset() { } public virtual void StackRefresh() { bool flag = this.HandlerMgr != null; if (flag) { this.HandlerMgr.StackRefresh(); } } public virtual void LeaveStackTop() { bool flag = this.HandlerMgr != null; if (flag) { this.HandlerMgr.LeaveStackTop(); } } protected virtual void OnSetVisiblePure(bool bShow) { } protected virtual void Init() { } private void InnerInit() { this.m_uiBehaviour.Init(); Vector3 localPosition = this.uiBehaviour.transform.localPosition; localPosition.z = this.m_fDepthZ; this.uiBehaviour.transform.localPosition = localPosition; this.m_DlgController = this.uiBehaviour.transform.Find("DlgController"); } public void Load() { bool flag = !this.m_bLoaded; if (flag) { this.m_bLoaded = true; XSingleton.singleton.LoadUI(this.fileName, this._loadUICb); XSingleton.singleton.AddDlg(DlgBase.s_instance); this.OnLoad(); } } public bool IsLoaded() { return this.m_bLoaded; } public void UnLoad(bool bTransfer = false) { bool bLoaded = this.m_bLoaded; if (bLoaded) { if (bTransfer) { this.SetVisible(false, false); } else { ILuaEngine xluaEngine = XSingleton.singleton.XLuaEngine; xluaEngine.hotfixMgr.TryFixRefresh(HotfixMode.UNLOAD, this.luaFileName, this.uiBehaviour.gameObject); this.OnUnload(); this.HandlerMgr.Unload(); XSingleton.singleton.RemoveDlg(DlgBase.s_instance); XSingleton.singleton.UnSafeDestroy(this.uiBehaviour.gameObject, false, true); this.m_uiBehaviour = default(TUIBehaviour); this.m_uiBehaviour = default(TUIBehaviour); this.m_bLoaded = false; bool flag = !XSingleton.singleton.switchScene; if (flag) { bool flag2 = XSingleton.singleton.unloadUICount >= 10; if (flag2) { Resources.UnloadUnusedAssets(); XSingleton.singleton.unloadUICount = 0; } else { XSingleton.singleton.unloadUICount++; } } } } } public void SetAlpha(float a) { IXUIPanel ixuipanel = this.uiBehaviour.gameObject.GetComponent("XUIPanel") as IXUIPanel; bool flag = ixuipanel != null; if (flag) { ixuipanel.SetAlpha(a); } } public float GetAlpha() { IXUIPanel ixuipanel = this.uiBehaviour.gameObject.GetComponent("XUIPanel") as IXUIPanel; bool flag = ixuipanel != null; float result; if (flag) { result = ixuipanel.GetAlpha(); } else { result = 1f; } return result; } public void RegCallBack() { this.panelCB = (this.uiBehaviour.gameObject.GetComponent("NGUIAssetCallBack") as IXNGUICallback); bool flag = this.panelCB != null; if (flag) { this.panelCB.RegisterClickEventHandler(new IXNGUIClickEventHandler(this.OnXNGUIClick)); } } public virtual void OnXNGUIClick(GameObject obj, string path) { XSingleton.singleton.AddLog(obj.name, " ", path, null, null, null, XDebugColor.XDebug_None); } protected GameObject SetXUILable(string name, string content) { bool flag = this.uiBehaviour.transform == null; GameObject result; if (flag) { result = null; } else { bool flag2 = string.IsNullOrEmpty(content); if (flag2) { content = string.Empty; } IXUILabel ixuilabel = this.uiBehaviour.transform.Find(name).GetComponent("XUILabel") as IXUILabel; bool flag3 = ixuilabel == null; if (flag3) { XSingleton.singleton.AddErrorLog("SetXUILable ", name, " ", content, null, null); result = null; } else { ixuilabel.SetText(content); result = ixuilabel.gameObject; } } return result; } private void OnLoadUIFinishedEventHandler(string location) { Debug.Log("加载界面prfab: " + location); //c 加载prefab GameObject gameObject = XSingleton.singleton.CreateFromPrefab("UI/" + location, true, false) as GameObject; bool flag = null != gameObject; if (flag) { gameObject.transform.parent = XSingleton.singleton.UIRoot; gameObject.transform.localPosition = new Vector3(0f, 0f, 0f); gameObject.transform.localScale = new Vector3(1f, 1f, 1f); this.m_uiBehaviour = gameObject.AddComponent(); //c 这里给界面挂上对应的脚本 this.m_uiBehaviour.uiDlgInterface = this; bool flag2 = !this.m_bBindedReverse; if (flag2) { this.Init(); this.InnerInit(); this.RegisterEvent(); this.RegCallBack(); this.uiBehaviour.SetVisible(false); this.m_bVisible = false; } } } public bool BindReverse(IXUIBehaviour iXUIBehaviour) { TUIBehaviour tuibehaviour = iXUIBehaviour as TUIBehaviour; bool flag = null == tuibehaviour; bool result; if (flag) { result = false; } else { this.m_bLoaded = true; this.m_uiBehaviour = tuibehaviour; this.m_uiBehaviour.uiDlgInterface = this; this.RegisterEvent(); this.InnerInit(); this.Init(); this.m_bBindedReverse = true; result = true; } return result; } public virtual void RegisterEvent() { } protected virtual void UnRegisterEvent() { } public virtual void SetRelatedDlg(IXUIDlg dlg) { this.m_RelatedDlg = dlg; } protected virtual void OnRelatedShow() { } protected virtual void OnRelatedHide() { } public void SetRelatedVisible(bool bVisible) { bool bLoaded = this.m_bLoaded; if (bLoaded) { this.SetVisiblePure(bVisible); if (bVisible) { this.OnRelatedShow(); } else { this.OnRelatedHide(); } } } private bool _CanShow() { bool flag = this.isPopup && XSingleton.singleton.InTutorial; bool result; if (flag) { this.OnPopupBlocked(); result = false; } else { result = true; } return result; } protected virtual void OnPopupBlocked() { } public virtual int[] GetTitanBarItems() { return null; } protected void Alloc3DAvatarPool(string user) { bool flag = this.m_dummPool < 0; if (flag) { this.m_dummPool = XSingleton.singleton.AllocDummyPool(user, 1); } } protected void Return3DAvatarPool() { XSingleton.singleton.ReturnDummyPool(this.m_dummPool); this.m_dummPool = -1; } public static Transform FindChildRecursively(string childName) { TDlgClass singleton = DlgBase.singleton; TUIBehaviour tuibehaviour = singleton.uiBehaviourInterface as TUIBehaviour; bool flag = !tuibehaviour.IsVisible(); Transform result; if (flag) { result = null; } else { Transform transform = XSingleton.singleton.FindChildRecursively(tuibehaviour.transform, childName); result = transform; } return result; } public static Vector3 GetChildWorldPos(string childName) { TDlgClass singleton = DlgBase.singleton; TUIBehaviour tuibehaviour = singleton.uiBehaviourInterface as TUIBehaviour; bool flag = !tuibehaviour.IsVisible(); Vector3 result; if (flag) { result = Vector3.zero; } else { Transform transform = XSingleton.singleton.FindChildRecursively(tuibehaviour.transform, childName); bool flag2 = transform != null; if (flag2) { result = transform.position; } else { result = Vector3.zero; } } return result; } } }