Exemplo n.º 1
0
        /// <summary>
        /// 打开面板
        /// </summary>
        public void OpenPanel(string uiname)
        {
            BasePanel panel = GetPanel(uiname);

            if (null == panel)
            {
                return;
            }

            if (m_OnDisplayPanelDic.ContainsKey(panel.Level))
            {
                if (m_OnDisplayPanelDic[panel.Level].Contains(panel))
                {
                    ClosePanel(uiname);
                    return;
                }
            }
            else
            {
                m_OnDisplayPanelDic.Add(panel.Level, new List <BasePanel>());
            }

            m_OnDisplayPanelDic[panel.Level].Add(panel);
            if (m_OnDisplayPanelDic.ContainsKey(panel.Level - 1)) // 可以改为 if(panel.level > 0)
            {
                m_OnDisplayPanelDic[panel.Level - 1].End().OnPause();
            }

            panel.OnOpen();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 把某个页面入栈,  把某个页面显示在界面上
        /// </summary>
        public void PushPanel(string uiname)
        {
            if (m_PanelStack == null)
            {
                m_PanelStack = new Stack <BasePanel>();
            }

            BasePanel nextPanel    = GetPanel(uiname); // 计划打开的页面
            BasePanel currentPanel = null;             // 最近一次关闭的界面

            // 判断一下栈里面是否有页面
            if (m_PanelStack.Count > 0)
            {
                BasePanel topPanel = m_PanelStack.Peek(); // 获取栈顶页面

                // 如果即将打开的页面是栈顶页面,即关闭栈顶页面
                if (topPanel == nextPanel)
                {
                    PopPanel();
                    return;
                }
                // 当栈内有面板时,进行判断
                while (m_PanelStack.Count > 0)
                {
                    if (topPanel.Level < nextPanel.Level)
                    {
                        break;
                    }
                    // 如果栈顶页面的层级不小于要打开的页面层级,关闭它并保存
                    currentPanel = PopPanel();
                    if (m_PanelStack.Count > 0)
                    {
                        topPanel = m_PanelStack.Peek();
                    }
                }
            }
            // 如果最后关闭的界面和要打开的是同一个,就不打开了
            if (currentPanel != nextPanel)
            {
                nextPanel.OnOpen();
                m_PanelStack.Push(nextPanel); // 将打开的面板入栈
            }
        }