|
@@ -1,15 +1,20 @@
|
|
|
using FL.FGUI;
|
|
|
-using XGame.Framework.Asyncs;
|
|
|
-using XGame.Framework.FGUI;
|
|
|
-using XGame.Framework.Loadable;
|
|
|
+using System.Collections.Generic;
|
|
|
+using XGame.Framework;
|
|
|
using XGame.Framework.Nodes;
|
|
|
+using XGame.Framework.UI;
|
|
|
|
|
|
namespace FL.Nodes.GameMain
|
|
|
{
|
|
|
- public class UIComponent : NodeComponent, ILoadAsyncHandle
|
|
|
+ public class UIComponent : NodeComponent
|
|
|
{
|
|
|
+ private Dictionary<UILayer, HashSet<UIKey>> _openKeysMap = new();
|
|
|
+
|
|
|
public override void OnEnable(object intent)
|
|
|
{
|
|
|
+ FrameworkEvent.Instance.AddListener(XGame.Framework.EventDefine.UI_OPENED, OnUIOpened);
|
|
|
+ FrameworkEvent.Instance.AddListener(XGame.Framework.EventDefine.UI_CLOSED, OnUIClosed);
|
|
|
+
|
|
|
Context.UI.OpenAsync(UIKeys.MainHomePanel, "打开MainHomePanel");
|
|
|
Context.UI.OpenAsync(UIKeys.MainHomeBottomPanel);
|
|
|
|
|
@@ -20,20 +25,79 @@ namespace FL.Nodes.GameMain
|
|
|
}
|
|
|
public override void OnDisable()
|
|
|
{
|
|
|
+ // 先移除监听事件
|
|
|
+ FrameworkEvent.Instance.RemoveListener(XGame.Framework.EventDefine.UI_OPENED, OnUIOpened);
|
|
|
+ FrameworkEvent.Instance.RemoveListener(XGame.Framework.EventDefine.UI_CLOSED, OnUIClosed);
|
|
|
+
|
|
|
Context.UI.Close(UIKeys.MainHomePanel);
|
|
|
Context.UI.Close(UIKeys.MainHomeBottomPanel);
|
|
|
Context.UI.Close(UIKeys.CommonToastPanel);
|
|
|
|
|
|
Context.Tree.Remove(NodeKeys.Partners);
|
|
|
Context.Tree.Remove(NodeKeys.DragonEgg);
|
|
|
+
|
|
|
+ _openKeysMap.Clear();
|
|
|
}
|
|
|
|
|
|
- void ILoadAsyncHandle.OnLoadAsync(IAsyncGroup group)
|
|
|
+ #region UILayer管理
|
|
|
+ private void OnUIOpened(int eventId, object args)
|
|
|
+ {
|
|
|
+ var uikey = args as UIKey;
|
|
|
+ if (uikey == UIKeys.MainHomeBottomPanel)
|
|
|
+ return; // 主界面底部菜单固定显示,忽略
|
|
|
+ var layer = UIKeys.GetLayer(uikey);
|
|
|
+ if (IsFiltered(layer))
|
|
|
+ return;
|
|
|
+ if (!_openKeysMap.TryGetValue(layer, out var openKeys))
|
|
|
+ {
|
|
|
+ openKeys = new HashSet<UIKey>();
|
|
|
+ _openKeysMap[layer] = openKeys;
|
|
|
+ }
|
|
|
+ openKeys.Add(uikey);
|
|
|
+
|
|
|
+ // 打开Normal的UI,关闭所有Middle和High
|
|
|
+ // 打开Middle的UI,关闭所有High
|
|
|
+ if (layer is UILayer.Normal or UILayer.Middle)
|
|
|
+ {
|
|
|
+ CloseUIByLayer(UILayer.High);
|
|
|
+ }
|
|
|
+ if (layer is UILayer.Normal)
|
|
|
+ {
|
|
|
+ CloseUIByLayer(UILayer.Middle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void OnUIClosed(int eventId, object args)
|
|
|
+ {
|
|
|
+ var uikey = args as UIKey;
|
|
|
+ var layer = UIKeys.GetLayer(uikey);
|
|
|
+ if (_openKeysMap.TryGetValue(layer, out var openKeys))
|
|
|
+ {
|
|
|
+ openKeys.Remove(uikey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 关闭指定Layer的所有UI
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="layer"></param>
|
|
|
+ private void CloseUIByLayer(UILayer layer)
|
|
|
{
|
|
|
- Context.UI.Preload(UINestedKeys.CommonItemBase).Join(group);
|
|
|
+ if (_openKeysMap.TryGetValue(layer, out var openKeys) && openKeys.Count > 0)
|
|
|
+ {
|
|
|
+ var list = ListPool.Acquire<UIKey>();
|
|
|
+ list.AddRange(openKeys);
|
|
|
+ foreach (var item in list)
|
|
|
+ {
|
|
|
+ Context.UI.Close(item);
|
|
|
+ }
|
|
|
+ ListPool.Recycle(list);
|
|
|
+ }
|
|
|
}
|
|
|
- void ILoadAsyncHandle.OnUnloadAsync(IAsyncGroup group)
|
|
|
+ private bool IsFiltered(UILayer layer)
|
|
|
{
|
|
|
+ return layer is UILayer.MapUI or UILayer.Toast or UILayer.Guide or UILayer.Effect;
|
|
|
}
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|