浏览代码

fix:底部菜单支持normal层ui关闭操作

chenbin 1 周之前
父节点
当前提交
54de00484c

二进制
Assets/Res/Addressable/FGUI/Main/Main_fui.bytes


+ 62 - 13
Assets/Scripts/Business/Runtime/FGUI/Main/HomeBottomPanel/MainHomeBottomPanelCtrl.cs

@@ -5,6 +5,8 @@
 /// created by cb 2024
 
 using FairyGUI;
+using System.Collections.Generic;
+using XGame;
 using XGame.Framework;
 using XGame.Framework.UI;
 
@@ -17,6 +19,10 @@ namespace FL.FGUI
     public partial class MainHomeBottomPanelCtrl : UIController<MainHomeBottomPanelVM>
     {
         private UIKey _tempKey;
+        /// <summary>
+        /// 已开启的Normal层UI队列
+        /// </summary>
+        private List<UIKey> _normalUIs = new();
         protected override void OnEnable(object intent)
         {
             AddUIListenres();
@@ -32,22 +38,26 @@ namespace FL.FGUI
             FrameworkEvent.Instance.RemoveListener(XGame.Framework.EventDefine.UI_OPENED, OnUIOpened);
             FrameworkEvent.Instance.RemoveListener(XGame.Framework.EventDefine.UI_CLOSED, OnUIClosed);
             _tempKey = null;
+            _normalUIs.Clear();
         }
         #region UI事件
         private void AddUIListenres()
         {
             VM.ClosePanelBtn.onClick.Add(OnClickClosePanelBtn);
-
-
         }
         private void RemoveUIListenres()
         {
             VM.ClosePanelBtn.onClick.Remove(OnClickClosePanelBtn);
-
-
         }
         private void OnClickClosePanelBtn(EventContext context)
         {
+            if (_normalUIs.Count > 0)
+            {
+                var uikey = _normalUIs[0];
+                _normalUIs.RemoveAt(0);
+                Context.UI.Close(uikey);
+                return;
+            }
             VM.BtnCtrl.selectedIndex = 0;
         }
 
@@ -89,7 +99,12 @@ namespace FL.FGUI
         }
         private void OnBtnCtrlChanged(EventContext context)
         {
-            XGame.Log.Debug($"OnBtnCtrlChanged. previousIndex:{VM.BtnCtrl.previousIndex} selectedIndex:{VM.BtnCtrl.selectedIndex}");
+            Log.Debug($"OnBtnCtrlChanged. previousIndex:{VM.BtnCtrl.previousIndex} selectedIndex:{VM.BtnCtrl.selectedIndex}");
+            if (VM.BtnCtrl.selectedIndex == 7)
+            { // 7为单独显示返回按钮
+                return;
+            }
+            CloseAllNormalUI();
             var lastUIKey = IndexToKey(VM.BtnCtrl.previousIndex);
             if (lastUIKey != null)
             {
@@ -116,24 +131,42 @@ namespace FL.FGUI
         }
         private void OnUIOpened(int eventId, object args)
         {
-            var uiKey = args as UIKey;
-            XGame.Log.Debug($"收到UI开启事件 UIKey:{uiKey} selectedIndex:{VM.BtnCtrl.selectedIndex}");
-            if (uiKey == _tempKey) return; // 避免重复监听
-            var index = KeyToIndex(uiKey);
+            var uikey = args as UIKey;
+            Log.Debug($"收到UI开启事件 UIKey:{uikey} selectedIndex:{VM.BtnCtrl.selectedIndex}");
+            if (uikey == _tempKey) return; // 避免重复监听
+            var index = KeyToIndex(uikey);
             if (index != -1)
             { // 是控制器关联的UI
                 if (index != VM.BtnCtrl.selectedIndex)
                 { // 控制器索引不一致
                     VM.BtnCtrl.selectedIndex = index;
                 }
+                return;
             }
+            if (_normalUIs.Contains(uikey))
+            {
+                Log.Error($"重复记录UI开启事件. UIKey:{uikey}");
+                return;
+            }
+            var layer = UIKeys.GetLayer(uikey);
+            if (layer != UILayer.Normal)
+                return;
+            if (VM.BtnCtrl.selectedIndex == 0)
+            {// 7为单独显示返回按钮
+                VM.BtnCtrl.selectedIndex = 7;
+            }
+            _normalUIs.Insert(0, uikey);
         }
         private void OnUIClosed(int eventId, object args)
         {
-            var uiKey = args as UIKey;
-            XGame.Log.Debug($"收到UI关闭事件 UIKey:{uiKey} selectedIndex:{VM.BtnCtrl.selectedIndex}");
-            if (uiKey == _tempKey) return; // 避免重复监听
-            var index = KeyToIndex(uiKey);
+            var uikey = args as UIKey;
+            Log.Debug($"收到UI关闭事件 UIKey:{uikey} selectedIndex:{VM.BtnCtrl.selectedIndex}");
+            if (uikey == _tempKey) return; // 避免重复监听
+            if (UIKeys.GetLayer(uikey) == UILayer.Normal)
+            {
+                _normalUIs.Remove(uikey);
+            }
+            var index = KeyToIndex(uikey);
             if (index != -1)
             { // 是控制器关联的UI
                 if (index == VM.BtnCtrl.selectedIndex)
@@ -142,6 +175,22 @@ namespace FL.FGUI
                 }
             }
         }
+        /// <summary>
+        /// 关闭所有的Normal层UI
+        /// </summary>
+        private void CloseAllNormalUI()
+        {
+            if (_normalUIs.Count == 0)
+                return;
+            for(var i = _normalUIs.Count - 1; i >= 0; i--)
+            {
+                var uikey = _normalUIs[i];
+                _normalUIs.RemoveAt(i);
+                _tempKey = uikey;
+                Context.UI.Close(uikey);
+            }
+            _tempKey = null;
+        }
         #endregion
     }
 }

+ 3 - 2
fl-fgui-project/assets/Main/HomeBottomPanel.xml

@@ -1,12 +1,13 @@
 <?xml version="1.0" encoding="utf-8"?>
 <component size="756,1344" opaque="false" designImage="ui://rbw1tv9tpiud9d" designImageLayer="1">
-  <controller name="btnCtrl" alias="底部通用按钮" pages="0,,3,,5,,1,,6,,4,,2," selected="1">
+  <controller name="btnCtrl" alias="底部通用按钮" pages="0,,3,,5,,1,,6,,4,,2,,7," selected="0">
     <remark page="1" value="角色"/>
     <remark page="2" value="圣兵"/>
     <remark page="3" value="铭文"/>
     <remark page="4" value="玩法"/>
     <remark page="5" value="家园"/>
     <remark page="6" value="宝藏"/>
+    <remark page="7" value="返回"/>
   </controller>
   <displayList>
     <image id="n269_pa7c" name="n269" src="piudaj" fileName="Image1/Functionbar.png" xy="378,1274" pivot="0.5,0.5" anchor="true" group="n275_pa7c"/>
@@ -35,7 +36,7 @@
       <property target="UnlockTxt" propertyId="0" value="主线3&#xA;解锁"/>
     </component>
     <component id="n276_pa7c" name="ClosePanelBtn" src="pa7cbp" fileName="Components1/ClosePanelBtn.xml" xy="377,1251" pivot="0.5,0.5" anchor="true" group="n275_pa7c">
-      <gearDisplay controller="btnCtrl" pages="3,5,1,6,4,2"/>
+      <gearDisplay controller="btnCtrl" pages="3,5,1,6,4,2,7"/>
     </component>
     <group id="n275_pa7c" name="n275" xy="0,1201" size="756,143" advanced="true">
       <relation target="" sidePair="bottom-bottom"/>