123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- /// #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
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class CommonToastPanelCtrl : UIController<CommonToastPanelVM>
- {
- private const int TIPS_LIMIT = 5;
- private HashSet<CommonTipsItemView> _showingTips;
- private Stack<CommonTipsItemView> _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<CommonTipsItemView>();
- }
- _showingTips.Add(tipsItemView);
- tipsItemView.Ctrl.ShowTips(tips, () =>
- {
- tipsItemView.Disable();
- _showingTips.Remove(tipsItemView);
- if (_unusedTips == null)
- _unusedTips = new Stack<CommonTipsItemView>();
- _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
- }
- }
|