/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using FairyGUI; using FL.Data; using FL.Data.Items; using FL.Network; using System.Collections.Generic; using System.Linq; using XGame.Database; using XGame.Framework; using XGame.Framework.Time; using XGame.Framework.UI; namespace FL.FGUI { public class ObtainItemsParam { public List dropItems; public bool bShowBtn; } /// /// UI逻辑处理类 /// /// public partial class ItemGetItemPanelCtrl : UIController { private ITimer _delayTimer; // 延迟展示高战力装备 private List _waitEquipIdList; // 穿戴|替换等待服务器消息返回的装备id列表 private List _dropItems; protected override void OnEnable(object intent) { AddUIListenres(); AddEventLisenter(); ShowUI(intent as ObtainItemsParam); } protected override void OnDisable() { RemoveUIListenres(); RemoveEventLisenter(); ClearTimer(); if (_waitEquipIdList != null ) _waitEquipIdList.Clear(); if (_dropItems != null ) _dropItems.Clear(); EquipData.Instance.ClearTemporaryEquipList(); } private void ClearTimer() { _delayTimer?.Cancel(); _delayTimer = null; } #region UI事件 private void AddUIListenres() { VM.OpenBagBtn.onClick.Add(OnClickOpenBagBtn); } private void RemoveUIListenres() { VM.OpenBagBtn.onClick.Remove(OnClickOpenBagBtn); } /// /// 一键处理 /// /// private void OnClickOpenBagBtn(EventContext context) { SendToSellTemporaryEquip(); } #endregion private void AddEventLisenter() { EventSingle.Instance.AddListener(EventDefine.WearEquipSucess, WearEquipSucess); EventSingle.Instance.AddListener(EventDefine.RemoveTemporaryEquip, RemoveTemporaryEquip); EventSingle.Instance.AddListener(EventDefine.RefreshTemporaryEquip, RefreshTemporaryEquip); FrameworkEvent.Instance.AddListener(XGame.Framework.EventDefine.UI_CLOSED, OnUIClosed); } private void RemoveEventLisenter() { EventSingle.Instance.RemoveListener(EventDefine.WearEquipSucess, WearEquipSucess); EventSingle.Instance.RemoveListener(EventDefine.RemoveTemporaryEquip, RemoveTemporaryEquip); EventSingle.Instance.RemoveListener(EventDefine.RefreshTemporaryEquip, RefreshTemporaryEquip); FrameworkEvent.Instance.RemoveListener(XGame.Framework.EventDefine.UI_CLOSED, OnUIClosed); } private void OnClosePanel() { Context.ClosePanel(); } private void ShowUI(ObtainItemsParam ObtainData) { ShowBtn(false); if (_dropItems == null) { _dropItems = new List(); } if (ObtainData?.dropItems != null) { _dropItems.AddRange(ObtainData.dropItems); } ShowDropUI(); if(ObtainData != null && ObtainData.bShowBtn) { ShowEquipUI(); } } private void ShowDropUI() { //XGame.Log.Info($"道具的数量:{_dropItems.Count}"); bool bLess = _dropItems.Count < 6; // 单行 VM.ItemList.visible = !bLess; VM.LessItemList.visible = bLess; if (bLess) { VM.LessItemList.BindDatas(_dropItems); } else { VM.ItemList.BindDatas(_dropItems); } VM.EmptyComCtrl.selectedIndex = bLess ? 0 : (_dropItems.Count > 15 ? 2 : 1); VM.ItemList.scrollPane.bouncebackEffect = _dropItems.Count > 15 ? true : false; } private void ShowBtn(bool bShow) { VM.OpenBagBtn.visible = bShow; } private void ShowEquipUI() { List equipItemList = _dropItems.FindAll(item => item.count == 0); var highEquipMap = new Dictionary(); foreach (var item in equipItemList) { var equipItem = EquipData.Instance.GetTemporaryEquipItem(item.id); if (equipItem != null && IsHighEquip(equipItem)) { if (highEquipMap.ContainsKey(equipItem.EquipType)) { if (highEquipMap[equipItem.EquipType].FightingPower < equipItem.FightingPower) { highEquipMap[equipItem.EquipType] = equipItem; } } else { highEquipMap.Add(equipItem.EquipType, equipItem); } } } if (highEquipMap.Count > 0) { DelayToShowHighEquip(highEquipMap); } else ShowBtn(true); } /// /// 等待掉落道具显示后再冒泡展示高战力装备替换界面 /// /// private void DelayToShowHighEquip(Dictionary highEquipMap) { ClearTimer(); _delayTimer = Context.Time.AddDelayTimer(1000, () => { ShowHighEquipUI(highEquipMap); }); } /// /// 是否高战力装备 /// /// /// private bool IsHighEquip(EquipItem equipItem) { EquipItem wearEquip = EquipData.Instance.GetWearEquipData(equipItem.Table.Part); if (wearEquip == null) return true; return equipItem.FightingPower > wearEquip.FightingPower; } private void ShowHighEquipUI(Dictionary highEquipMap) { if (highEquipMap?.Count == 0) { ShowBtn(true); return; } if (_waitEquipIdList?.Count > 0) _waitEquipIdList.Clear(); else _waitEquipIdList = new List(); foreach (var item in highEquipMap) { _waitEquipIdList.Add(item.Value.Id); } highEquipMap.Clear(); ShowEquipEquipPanel(); } /// /// 显示装备穿戴|替换界面 /// private void ShowEquipEquipPanel() { if (_waitEquipIdList.Count > 0) { EquipData.Instance.BubblingEquipUid = _waitEquipIdList[0]; Context.UI.OpenAsync(UIKeys.EquipEquipPanel, EquipData.Instance.GetTemporaryEquipItem(_waitEquipIdList[0])); } else { ShowDropUI(); ShowBtn(true); } } /// /// 成功穿戴|替换装备 /// /// /// private void WearEquipSucess(int eventId, object args) { var changEquipIdList = args as HashSet; if (changEquipIdList != null) { foreach (var item in changEquipIdList) { _waitEquipIdList.Remove(item); } } } /// /// 穿戴移除只会发生在身上装备栏空 /// /// /// private void RemoveTemporaryEquip(int eventId, object args) { int[] removeIds = args as int[]; if (removeIds.Length > 0) { foreach(var id in removeIds) { _waitEquipIdList.Remove(id); _dropItems = _dropItems.FindAll(item =>(item.count > 0 || item.id != id)); } } } /// /// 成功穿戴|替换装备消息流程结束 /// /// /// private void RefreshTemporaryEquip(int eventId, object args) { ShowEquipEquipPanel(); } /// /// 监听装备穿戴|替换界面关闭事件 /// /// /// private void OnUIClosed(int eventId, object args) { var uiKey = args as UIKey; if (uiKey != null && uiKey == UIKeys.EquipEquipPanel) { if (EquipData.Instance.BubblingEquipUid > 0) { _waitEquipIdList.Remove(EquipData.Instance.BubblingEquipUid); EquipData.Instance.BubblingEquipUid = 0; ShowEquipEquipPanel(); } } } /// /// 一键出售,拥有高战力装备的二次确认框按钮监听事件 /// /// /// private void ConfirmationToSell() { HashSet sellIds = new HashSet(); foreach (var item in _dropItems) { if (item.count == 0) { sellIds.Add(item.id); } } DragonEggService.Instance.SellEquip(sellIds.ToArray()); sellIds.Clear(); OnClosePanel(); } /// /// 一键出售临时装备 /// private void SendToSellTemporaryEquip() { if (IsHighFighingPower()) { //XGame.Log.Warn($"当前要出售的装备{_newEquip.FightingPower}战力高于身上穿戴的{_wearEquip.FightingPower}"); ConfirmationBoxParam dialogParam = new ConfirmationBoxParam() { cnt = StringDefine.sellHightPowerEquip, //tipsKey = EDayTipsKey.SellEquip, onCancelCallback = OnClosePanel, onPromiseCallback = ConfirmationToSell }; Context.UI.OpenAsync(UIKeys.CommonConfirmationBox, dialogParam); return; } ConfirmationToSell(); OnClosePanel(); } /// /// 是否有高战力装备未处理 /// /// private bool IsHighFighingPower() { for (int i = 0; i < _dropItems.Count; i++) { if (_dropItems[i]?.count == 0) { EquipItem equipData = EquipData.Instance.GetBagEquipItem(_dropItems[i].id); if (equipData != null) { EquipItem wearEquip = EquipData.Instance.GetWearEquipData(equipData.EquipType); if ( wearEquip == null || equipData.FightingPower > wearEquip.FightingPower) { return true; } } } } return false; } } }