123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- /// #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
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class TreasureChestIncomeListItemCtrl : UIController<TreasureChestIncomeListItemVM>
- {
- 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;
- }
- /// <summary>
- /// 当前宝箱等级可以产出的最高装备品质描述
- /// </summary>
- 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);
- }
- }
- /// <summary>
- /// 判断升级后是否会开启新的品质装备
- /// </summary>
- /// <param name="level"></param>
- /// <param name="curQuality"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// (品质)宝箱的icon
- /// </summary>
- /// <param name="index"></param>
- private void ShowTreasureBoxIcon(int index)
- {
- VM.DragonIcon.icon = AddressableDefine.DragonIcon(index + 1);
- }
- }
- }
|