using System; using System.Collections.Generic; using AlicizaX.Runtime; namespace AlicizaX.UI.Runtime { internal sealed partial class UIManager { private readonly Dictionary mWindowDisposeTimerIds = new Dictionary(); private readonly Dictionary m_CacheWindow = new Dictionary(); private bool InCache(Type type) { return m_CacheWindow.ContainsKey(type); } private void CacheWindow(PanelInfo info) { if (info == null) { Log.Error("{0} panelinfo not exist!", info.UIClsType.FullName); return; } if (info.UIBasePanel == null) { Log.Error("{0} PanelObject not exist!", info.UIClsType.FullName); return; } info.SetPanelState(EPanelState.Cache); m_CacheWindow.Add(info.UIClsType, info); SetPanelLayer(info, UILayer.Cache); if (info.DelayedClose > 0) { RemoveTimerDispose(info.UIClsType); int hideTimerId =_timerManager.AddTimer(OnTimerDiposeWindow, info.DelayedClose, false, true, info); mWindowDisposeTimerIds.Add(info.UIClsType, hideTimerId); } } private void OnTimerDiposeWindow(object[] args) { PanelInfo info = args[0] as PanelInfo; info.UIBasePanel.InternalDestroy(); m_CacheWindow.Remove(info.UIClsType); info.Reset(null); info.SetPanelState(EPanelState.None); } private void RemoveTimerDispose(Type type) { if (mWindowDisposeTimerIds.TryGetValue(type, out int tiemrId)) { _timerManager.RemoveTimer(tiemrId); mWindowDisposeTimerIds.Remove(type); } } private void RemoveFromCache(PanelInfo info) { m_CacheWindow.Remove(info.UIClsType); if (mWindowDisposeTimerIds.TryGetValue(info.UIClsType, out int tiemrId)) { _timerManager.RemoveTimer(tiemrId); mWindowDisposeTimerIds.Remove(info.UIClsType); } } } }