Jelajahi Sumber

界面管理优化

huangxiaoyue 1 tahun lalu
induk
melakukan
478ccc066e

+ 1 - 1
GameClient/Assets/Game/HotUpdate/Views/DressUp/DressUpFightView.cs

@@ -692,7 +692,7 @@ namespace GFGGame
             else
                 ViewManager.Show<StoryFightSingleView>(null, true);
 
-            ViewManager.DeleteViewStackCountDown(1);
+            ViewManager.DeleteViewStackCountDown(null,1);
         }
         private void OnClickBtnRecommend()
         {

+ 1 - 1
GameClient/Assets/Game/HotUpdate/Views/League/LeagueTeaPartyShowView.cs

@@ -116,7 +116,7 @@ namespace GFGGame
 
         private static void OnCompletePriorStoryDialog(bool isSkip, object param)
         {
-            ViewManager.DeleteViewStackCountDown(2);
+            ViewManager.DeleteViewStackCountDown(null, 2);
             ViewManager.Show<LeagueTeaPartyOverView>();
         }
 

+ 54 - 22
GameClient/Assets/Game/HotUpdate/Views/ViewManager.cs

@@ -27,7 +27,7 @@ namespace GFGGame
         private static GComponent _alertLayer;
         private static GComponent _debugLayer;
         private static GComponent _floatLayer;
-        private static bool _nowHideOthers = false;
+        private static bool _nowHideOthers = false;     //正在关闭所有界面的循环中
 
         private static Dictionary<string, List<object[]>> _goBackDatas = new Dictionary<string, List<object[]>>();
        
@@ -170,17 +170,36 @@ namespace GFGGame
                 viewStructure.viewData = viewData;
                 viewStructure.iUIView = obj;
                 _viewStack.Add(viewStructure);
-                if (_viewStack.Count > 1 && !hideOthers)
+                if (_viewStack.Count > 1 && !hideOthers) {
                     _viewStack[_viewStack.Count - 2].iUIView.Hide();
+                }
             }
 
             return true;
         }
 
-        //删除队列中的倒数几个
-        public static void DeleteViewStackCountDown(int count)
+        //
+        /// <summary>
+        /// 界面可返回栈里的跳转
+        /// </summary>
+        /// <param name="viewName">跳转到界面缓存栈里的某个界面,使用这个参数时写在打开下一个界面后</param>
+        /// <param name="count">删除队列中的倒数几个,较灵活应对更多种情况,可自由控制</param>
+        public static void DeleteViewStackCountDown(string viewName, int count = 0)
         {
+            if (viewName != null && viewName != "")
+            {
+                for (int i = _viewStack.Count - 2; i > 0; i--)
+                {
+                    ViewStructure viewStructure = _viewStack[i];
+                    if (viewStructure.name == viewName)
+                        break;
+                    _viewStack.RemoveAt(i);
+                }
+                return;
+            }
             for (int i = 0; i < count; i++) {
+                if (_viewStack.Count <= 1)
+                    break;
                 _viewStack.RemoveAt(_viewStack.Count-1);
             }
         }
@@ -212,9 +231,13 @@ namespace GFGGame
 
         public static void HideWin(string viewName)
         {
-            if (_viewStack.Count > 1 && !_nowHideOthers) {
-                ViewStructure viewStructure = _viewStack[_viewStack.Count - 1];
+            if (_nowHideOthers)
+                return;
+            
+            if (_viewStack.Count >= 1)
+            {
                 bool hasShowingView = false;
+                bool needShowNextView = false;
                 foreach (var info in _viewDic.Keys)
                 {
                     IUIView objIsShowing = _viewDic[info];
@@ -224,26 +247,35 @@ namespace GFGGame
                         break;
                     }
                 }
-                if (!hasShowingView || (viewStructure.iUIView.isReturnView && viewStructure.name == viewName))
+                ViewStructure viewStructure = _viewStack[_viewStack.Count - 1];
+                if (_viewStack.Count == 1)
                 {
-                    //关闭自己,在队列里去除
-                    if(viewStructure.iUIView.isReturnView && viewStructure.name == viewName)
-                        _viewStack.RemoveAt(_viewStack.Count - 1);
+                    //没有界面显示了,栈被清除剩1个的时候,做保底
+                    if (!hasShowingView)
+                        needShowNextView = true;
+                }
+                else { 
+                    if (!hasShowingView || (viewStructure.iUIView.isReturnView && viewStructure.name == viewName))
+                    {
+                        //关闭自己,在队列里去除
+                        if (viewStructure.iUIView.isReturnView && viewStructure.name == viewName)
+                            _viewStack.RemoveAt(_viewStack.Count - 1);
+
+                        if (_viewStack.Count >= 1)
+                            needShowNextView = true;
+                    }
+                }
 
-                    if (_viewStack.Count >= 1)
+                if (needShowNextView) { 
+                    viewStructure = _viewStack[_viewStack.Count - 1];
+                    ViewManager.Show($"GFGGame.{viewStructure.name}", viewStructure.viewData);
+                    foreach (var objName in _viewDic.Keys)
                     {
-                        viewStructure = _viewStack[_viewStack.Count - 1];
-                        ViewManager.Show($"GFGGame.{viewStructure.name}", viewStructure.viewData);
-                        foreach (var objName in _viewDic.Keys)
+                        if (objName != viewStructure.name)
                         {
-                            if (objName != viewStructure.name)
-                            {
-                                IUIView view = (IUIView)_viewDic[objName];
-                                if (view.isShowing)
-                                {
-                                    view.Show();
-                                }
-                            }
+                            IUIView view = (IUIView)_viewDic[objName];
+                            if (view.isShowing)
+                                view.Show();
                         }
                     }
                 }