123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using System.Collections.Generic;
- using FairyGUI;
- using FL.Data;
- using XGame;
- using XGame.Database;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PartnerPartnerBaseItemCtrl : UIController<PartnerPartnerBaseItemVM>
- {
- private List<GLoader> _starIconList;
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- ClearStar();
- }
- #region UI事件
- private void AddUIListenres() { }
- private void RemoveUIListenres() { }
- #endregion
- public void ShowUI(int id, bool showOther)
- {
- if (id <= 0)
- {
- VM.PartnerImg.visible = false;
- VM.QualityImg.icon = AddressableDefine.PartnerEmptyDi();
- VM.ShowOther.selectedIndex = 1;
- VM.LevelTxt.visible = false;
- return;
- }
- var table = PartnerTableRepo.Get(id);
- if (table == null)
- {
- Log.Error($"圣兵表不存在id:{id}");
- return;
- }
- VM.PartnerImg.visible = true;
- VM.QualityImg.icon = AddressableDefine.PartnerQualityFrame((int)table.Quality);
- VM.PartnerImg.icon = table.Icon;
- var partnerData = PartnersData.Instance.GetPartnerAttrByTableId(id);
- var level = partnerData?.Level ?? 0;
- bool bShowLevel = level > 0;
- VM.LevelTxt.visible = bShowLevel;
- if (bShowLevel)
- {
- VM.LevelTxt.text = $"LV.{level}";
- }
- VM.ShowOther.selectedIndex = showOther ? 0 : 1;
- if (showOther)
- {
- var starLv = partnerData?.RisingStarLv == null ? 0 : partnerData.RisingStarLv;
- ShowStarUI(starLv);
- var starTable = partnerStarUpTableRepo.GetPartnerStarTable(id, starLv);
- if (starTable == null)
- {
- VM.SpPbar.visible = false;
- }
- else
- {
- VM.SpPbar.GetChild("icon").asLoader.url = AddressableDefine.PartnerSpProgressDi((int)table.Quality);
- VM.SpPbar.max = starTable.StarUpCost;
- VM.SpPbar.value = ItemData.Instance.GetItemNum(starTable.PetId);
- VM.SpPbar.visible = true;
- }
- }
- }
- private void ShowStarUI(int starLv)
- {
- InitStarList();
- int starNum = starLv == 0 ? 0 : starLv % PartnersData.MaxStarNum;
- if (starLv > 0 && starNum == 0)
- starNum = PartnersData.MaxStarNum;
- VM.StarRating.GetController("StarNumCtrl").selectedIndex = starNum;
- ShowStarIcon(starNum, starLv);
- }
- private void ClearStar()
- {
- if (_starIconList != null)
- {
- _starIconList.Clear();
- _starIconList = null;
- }
- }
- private void InitStarList()
- {
- if (_starIconList == null)
- {
- _starIconList = new List<GLoader>()
- {
- VM.StarRating.GetChild("Star1").asLoader,
- VM.StarRating.GetChild("Star2").asLoader,
- VM.StarRating.GetChild("Star3").asLoader,
- VM.StarRating.GetChild("Star4").asLoader,
- VM.StarRating.GetChild("Star5").asLoader,
- };
- }
- foreach (var item in _starIconList)
- {
- item.visible = false;
- }
- }
- private void ShowStarIcon(int count, int starLv)
- {
- if (count > 0)
- {
- int starStep = PartnersData.Instance.GetStarStep(starLv);
- for (int i = 0; i < count; i++)
- {
- if (_starIconList[i] != null)
- {
- _starIconList[i].visible = true;
- _starIconList[i].icon = AddressableDefine.PartnerStarIconName(starStep);
- }
- }
- }
- }
- }
- }
|