/// #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 { /// /// UI逻辑处理类 /// /// public partial class TemporaryEquipBagPanelCtrl : UIController { private const int MaxRow = 6;// 最大行数 protected override void OnEnable(object intent) { AddUIListenres(); EventSingle.Instance.AddListener(EventDefine.RefreshTemporaryEquip, RefreshTemporaryEquip); ShowUI(); } protected override void OnDisable() { RemoveUIListenres(); EventSingle.Instance.RemoveListener(EventDefine.RefreshTemporaryEquip, RefreshTemporaryEquip); } #region UI事件 private void AddUIListenres() { VM.SellBtn.onClick.Add(OnClickSellBtn); } private void RemoveUIListenres() { VM.SellBtn.onClick.Remove(OnClickSellBtn); } /// /// 一键出售按钮 /// /// private void OnClickSellBtn(EventContext context) { Context.ClosePanel(); DragonEggService.Instance.SendToSellAllBagEquips(); } #endregion private void ShowUI() { bool bEmpty = EquipData.Instance.IsEquipbagEmpty(); VM.EmptyCtrl.selectedIndex = bEmpty ? 1 : 0; if (bEmpty) { return; } var equipDataList = new List(); EquipData.Instance.GetBagEquipList(ref equipDataList); OnSortEquipDataList(ref equipDataList); 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(ref List equipDataList) { 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.CompareTo(aHighPower); }); } private int GetCompareValue(EquipItem equipData) { int compareFlag = 0; if (equipData?.Table?.Part > 0) { long compareFightingPower = equipData?.FightingPower ?? 0; var equipItem = EquipData.Instance.GetWearEquipData(equipData.Table.Part); long wearFightingPower = equipItem?.FightingPower ?? 0; if (compareFightingPower > wearFightingPower) compareFlag = 1; } return compareFlag; } /// /// 刷新临时装备背包 /// /// /// private void RefreshTemporaryEquip(int eventId, object args) { var equipDataList = new List(); EquipData.Instance.GetBagEquipList(ref equipDataList); OnSortEquipDataList(ref equipDataList); VM.EquipList.BindDatas(equipDataList); } } }