123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- /// #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;// 最大行数
- 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);
- }
- /// <summary>
- /// 一键出售按钮
- /// </summary>
- /// <param name="context"></param>
- 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<EquipItem>();
- 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<EquipItem> 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;
- }
- /// <summary>
- /// 刷新临时装备背包
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void RefreshTemporaryEquip(int eventId, object args)
- {
- var equipDataList = new List<EquipItem>();
- EquipData.Instance.GetBagEquipList(ref equipDataList);
- OnSortEquipDataList(ref equipDataList);
- VM.EquipList.BindDatas(equipDataList);
- }
- }
- }
|