123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- /// #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<KindItem> dropItems;
- public bool bShowBtn;
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class ItemGetItemPanelCtrl : UIController<ItemGetItemPanelVM>
- {
- private ITimer _delayTimer; // 延迟展示高战力装备
- private List<long> _waitEquipIdList; // 穿戴|替换等待服务器消息返回的装备id列表
- private List<KindItem> _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);
- }
- /// <summary>
- /// 一键处理
- /// </summary>
- /// <param name="context"></param>
- 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<KindItem>();
- }
- 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<KindItem> equipItemList = _dropItems.FindAll(item => item.count == 0);
- var highEquipMap = new Dictionary<EEquipType, EquipItem>();
- 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);
- }
- /// <summary>
- /// 等待掉落道具显示后再冒泡展示高战力装备替换界面
- /// </summary>
- /// <param name="highEquipMap"></param>
- private void DelayToShowHighEquip(Dictionary<EEquipType, EquipItem> highEquipMap)
- {
- ClearTimer();
- _delayTimer = Context.Time.AddDelayTimer(1000, () =>
- {
- ShowHighEquipUI(highEquipMap);
- });
- }
- /// <summary>
- /// 是否高战力装备
- /// </summary>
- /// <param name="equipItem"></param>
- /// <returns></returns>
- 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<EEquipType, EquipItem> highEquipMap)
- {
- if (highEquipMap?.Count == 0)
- {
- ShowBtn(true);
- return;
- }
- if (_waitEquipIdList?.Count > 0)
- _waitEquipIdList.Clear();
- else
- _waitEquipIdList = new List<long>();
- foreach (var item in highEquipMap)
- {
- _waitEquipIdList.Add(item.Value.Id);
- }
- highEquipMap.Clear();
- ShowEquipEquipPanel();
- }
- /// <summary>
- /// 显示装备穿戴|替换界面
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 成功穿戴|替换装备
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void WearEquipSucess(int eventId, object args)
- {
- var changEquipIdList = args as HashSet<long>;
- if (changEquipIdList != null)
- {
- foreach (var item in changEquipIdList)
- {
- _waitEquipIdList.Remove(item);
- }
- }
- }
- /// <summary>
- /// 穿戴移除只会发生在身上装备栏空
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- 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));
- }
- }
- }
- /// <summary>
- /// 成功穿戴|替换装备消息流程结束
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void RefreshTemporaryEquip(int eventId, object args)
- {
- ShowEquipEquipPanel();
- }
- /// <summary>
- /// 监听装备穿戴|替换界面关闭事件
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- 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();
- }
- }
- }
- /// <summary>
- /// 一键出售,拥有高战力装备的二次确认框按钮监听事件
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void ConfirmationToSell()
- {
- HashSet<int> sellIds = new HashSet<int>();
- foreach (var item in _dropItems)
- {
- if (item.count == 0)
- {
- sellIds.Add(item.id);
- }
- }
- DragonEggService.Instance.SellEquip(sellIds.ToArray());
- sellIds.Clear();
- OnClosePanel();
- }
- /// <summary>
- /// 一键出售临时装备
- /// </summary>
- 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();
- }
- /// <summary>
- /// 是否有高战力装备未处理
- /// </summary>
- /// <returns></returns>
- 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;
- }
- }
- }
|