|
@@ -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
|
|
|
}
|
|
|
}
|