123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using FairyGUI;
- using FL.Data;
- using FL.Data.Items;
- using System;
- using System.Collections.Generic;
- using XGame.Database;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class TemporaryEquipBagPanelCtrl : UIController<TemporaryEquipBagPanelVM>
- {
- private const int MaxRow = 6;// 最大行数
- private List<EquipAttr> _equipDataList; //装备背包的数据
- private Dictionary<EEquipType, long> _wearEquipPowerMap; // 身上部位穿戴的装备战力数据
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- EventSingle.Instance.AddListener(EventDefine.RefreshTemporaryEquip, RefreshTemporaryEquip);
- EventSingle.Instance.AddListener(EventDefine.OnChangeEquip, OnChangeEquip);
- ShowUI();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- EventSingle.Instance.RemoveListener(EventDefine.RefreshTemporaryEquip, RefreshTemporaryEquip);
- EventSingle.Instance.RemoveListener(EventDefine.OnChangeEquip, OnChangeEquip);
- _wearEquipPowerMap?.Clear();
- _wearEquipPowerMap = null;
- _equipDataList?.Clear();
- _equipDataList = null;
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.SellBtn.onClick.Add(OnClickSellBtn);
- }
- private void RemoveUIListenres()
- {
- VM.SellBtn.onClick.Remove(OnClickSellBtn);
- }
- /// <summary>
- /// 一键出售按钮
- /// </summary>
- /// <param name="context"></param>
- private void OnClickSellBtn(EventContext context)
- {
- Context.ClosePanel();
- DragonEggService.Instance.SendToSellAllBagEquips();
- }
- #endregion
- private void Init()
- {
- if (_equipDataList == null) _equipDataList = new List<EquipAttr>();
- else _equipDataList.Clear();
- if (_wearEquipPowerMap == null)
- {
- _wearEquipPowerMap = new Dictionary<EEquipType, long>();
- for (int i = 1; i < 7; i++)
- {
- _wearEquipPowerMap.Add((EEquipType)i, 0);
- }
- }
- EquipData.Instance.GetWearEquipPower(ref _wearEquipPowerMap);
- }
- private void ShowUI()
- {
- bool bEmpty = EquipData.Instance.IsEquipbagEmpty();
- VM.EmptyCtrl.selectedIndex = bEmpty ? 1 : 0;
- if (bEmpty)
- {
- VM.ListBG.height = 425;
- VM.UIGroup.height = 462;
- return;
- }
- Init();
- EquipData.Instance.GetBagEquipList(ref _equipDataList);
- OnSortEquipDataList();
- VM.EquipList.BindDatas(_equipDataList);
- int num = (int)Math.Ceiling(_equipDataList.Count / 5.0f);
- int addHeight = (Math.Min(num, MaxRow)-1) * 140 -32;
- VM.EquipList.height = 140 + addHeight;
- VM.ListBG.height = 425 + addHeight;
- VM.UIGroup.height = 462 + addHeight;
- }
- private void OnSortEquipDataList()
- {
- _equipDataList.Sort((a, b) =>
- {
- var aHighPower = GetCompareValue(a);
- var bHighPower = GetCompareValue(b);
- if (aHighPower == bHighPower)
- {
- if (a.FightingPower == b.FightingPower)
- {
- return a.Id.CompareTo(b.Id); // 升序
- }
- return b.FightingPower.CompareTo(a.FightingPower); //降序
- }
- else
- return bHighPower - aHighPower;
- });
- }
- /// <summary>
- /// 比身上穿戴的装备的战力高标识
- /// </summary>
- /// <param name="equipData"></param>
- /// <returns></returns>
- private int GetCompareValue(EquipAttr equipData)
- {
- int compareFlag = 0;
- if (equipData?.Table.Part > 0)
- {
- if (equipData.FightingPower > _wearEquipPowerMap[equipData.Table.Part])
- compareFlag = 1;
- }
- return compareFlag;
- }
- /// <summary>
- /// 更换装备
- /// </summary>
- /// <param name="type"></param>
- /// <param name="id"></param>
- private void OnChangeEquip(int eventId, object args)
- {
- if (args == null)
- {
- return;
- }
- var changeEquipPartList = args as List<EEquipType>;
- if (changeEquipPartList?.Count > 0)
- {
- foreach (var equipPart in changeEquipPartList)
- {
- _wearEquipPowerMap[equipPart] = EquipData.Instance.GetWearPartPower(equipPart);
- }
- }
- }
- /// <summary>
- /// 刷新临时装备背包
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void RefreshTemporaryEquip(int eventId, object args)
- {
- _equipDataList.Clear();
- EquipData.Instance.GetBagEquipList(ref _equipDataList);
- OnSortEquipDataList();
- VM.EquipList.BindDatas(_equipDataList);
- VM.EquipList.scrollPane.SetPercY(0,false);
- }
- }
- }
|