/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using System.Collections.Generic; using XGame.Framework.FGUI; using XGame.Framework.UI; namespace FL.FGUI { /// /// UI逻辑处理类 /// /// public partial class CommonToastPanelCtrl : UIController { private const int TIPS_LIMIT = 5; private HashSet _showingTips; private Stack _unusedTips; protected override void OnEnable(object intent) { AddListenres(); } protected override void OnDisable() { VM.KillTweens(); RemoveListenres(); ClearTips(); } private void AddListenres() { Context.AddListener(EventDefine.ShowTips, OnShowTips); } private void RemoveListenres() { Context.RemoveListener(EventDefine.ShowTips, OnShowTips); } #region Tips private void OnShowTips(int eventId, object args) { var tips = (string)args; if (_unusedTips != null && _unusedTips.Count > 0) { var tipsItemView = _unusedTips.Pop(); tipsItemView.Enable(null); ShowTips(tipsItemView, tips); return; } var async = Context.Asset.LoadFguiNested(UINestedKeys.CommonTipsItem, VM.ItemRoot); async.On(_ => { var result = async.Result as CommonTipsItemView; if (result == null) { return; } ShowTips(result, tips); }); } private void ShowTips(CommonTipsItemView tipsItemView, string tips) { if (_showingTips == null) { _showingTips = new HashSet(); } _showingTips.Add(tipsItemView); tipsItemView.Ctrl.ShowTips(tips, () => { tipsItemView.Disable(); _showingTips.Remove(tipsItemView); if (_unusedTips == null) _unusedTips = new Stack(); _unusedTips.Push(tipsItemView); }); } private void ClearTips() { if (_showingTips != null) { foreach (var item in _showingTips) { Context.Asset.Recycle(item); } _showingTips.Clear(); } if (_unusedTips != null) { while (_unusedTips.Count > 0) { var item = _unusedTips.Pop(); Context.Asset.Recycle(item); } } } #endregion } }