/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using FairyGUI; using FL.Data; using XGame.Database; using XGame.Framework.UI; namespace FL.FGUI { public struct TreasureChestIncome { public int dropId; // 当前等级掉落id public int nextLvDropId; // 下一级的掉落id } /// /// UI逻辑处理类 /// /// public partial class TreasureChestIncomeListItemCtrl : UIController { protected override void OnEnable(object intent) { AddUIListenres(); } protected override void OnDisable() { RemoveUIListenres(); } #region UI事件 private void AddUIListenres() { VM.InfoBtn.onClick.Add(OnClickInfoBtn); } private void RemoveUIListenres() { VM.InfoBtn.onClick.Remove(OnClickInfoBtn); } private void OnClickInfoBtn(EventContext context) { EventSingle.Instance.Notify(EventDefine.ShowEquipQualityProbability); } #endregion public void OnRefresh(int index, TreasureChestIncome dropData) { VM.HideLineCtrl.selectedIndex = index < 4 ? 0 : 1; bool bEquip = index == 2; VM.EquipCtrl.selectedIndex = bEquip ? 1 : 0; // 第3个宝箱产出装备 bool bMaxLv = dropData.nextLvDropId == 0; VM.MaxLvCtrl.selectedIndex = bMaxLv ? 1 : 0; var curDropInfo = DropTableRepo.Get(dropData.dropId); if (curDropInfo?.Group[0] > 0) { VM.ItemIcon1.icon = GetItemIcon(curDropInfo.Group[0]); VM.CurLvNumLabel.text = curDropInfo?.Group[1].ToString(); } if (!bMaxLv) { var nextDropInfo = DropTableRepo.Get(dropData.nextLvDropId); if (nextDropInfo?.Group[0] > 0) { VM.ItemIcon2.icon = GetItemIcon(nextDropInfo.Group[0]); VM.NextLvNumLabel.text = nextDropInfo?.Group[1].ToString(); } } ShowTreasureBoxIcon(index); if (bEquip) { ShowMaxEquipQuality(bMaxLv); } } private string GetItemIcon(int itemId) { var itemInfo = ItemTableRepo.Get(itemId); return itemInfo?.Icon; } /// /// 当前宝箱等级可以产出的最高装备品质描述 /// private void ShowMaxEquipQuality(bool bMaxLv) { var curTreasure = treasureTableRepo.Get(DragonEggData.Instance.Level); if (curTreasure != null) { int maxQuality = 1; for (int i = 0; i < curTreasure.EquipmentProbability.Length; i += 2) { if (curTreasure.EquipmentProbability[i + 1] > 0 && curTreasure.EquipmentProbability[i] > maxQuality) { maxQuality = curTreasure.EquipmentProbability[i]; } } EQualityLevel quality = (EQualityLevel)maxQuality; string nextQualityStr = bMaxLv ? string.Empty : GetNextLvEquipQuality(DragonEggData.Instance.Level + 1, maxQuality); VM.ProduceLabel.text = string.Format(StringDefine.maxEquipQuality, ColorDefine.GetQualityColor(quality), StringDefine.equipQualityNameList[maxQuality - 1], nextQualityStr); } } /// /// 判断升级后是否会开启新的品质装备 /// /// /// /// private string GetNextLvEquipQuality(int level, int curQuality) { int maxQuality = curQuality; var treasureInfo = treasureTableRepo.Get(DragonEggData.Instance.Level); if (treasureInfo != null) { for (int i = 0; i < treasureInfo.EquipmentProbability.Length; i += 2) { if (treasureInfo.EquipmentProbability[i + 1] > 0 && treasureInfo.EquipmentProbability[i] > maxQuality) { maxQuality = treasureInfo.EquipmentProbability[i]; } } } if (maxQuality > curQuality) { return string.Format(StringDefine.nextLvEquipQuality, ColorDefine.GetQualityColor((EQualityLevel)maxQuality), StringDefine.equipQualityNameList[maxQuality - 1]); } return string.Empty; } /// /// (品质)宝箱的icon /// /// private void ShowTreasureBoxIcon(int index) { VM.DragonIcon.icon = AddressableDefine.DragonIcon(index + 1); } } }