/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using FairyGUI; using FL.Data; using System.Collections.Generic; using System.Linq; using XGame.Database; using XGame.Framework.UI; namespace FL.FGUI { /// /// UI逻辑处理类 /// /// public partial class PartnerDetailsPanelCtrl : UIController { private long _partnerId; private int _state; /// 1:已获取未上阵 2:已上阵 private int _curIndex; private List _partnerIdList; // 拥有的全部伙伴(圣兵)id列表 protected override void OnEnable(object intent) { AddUIListenres(); AddEventListener(); InitUI(intent as PartnerListItemData); ShowUI(); } protected override void OnDisable() { RemoveUIListenres(); RemoveEventListener(); } private void OnClosePanel() { Context.ClosePanel(); } #region UI事件 private void AddUIListenres() { VM.PreviousBtn.onClick.Add(OnClickPreviousBtn); VM.NextBtn.onClick.Add(OnClickNextBtn); VM.ChangeBtn.onClick.Add(OnClickChangeBtn); VM.UpgradeBtn.onClick.Add(OnClickUpgradeBtn); VM.GoIntoBattleBtn.onClick.Add(OnClickGoIntoBattleBtn); VM.TakeDownBtn.onClick.Add(OnclickTakeDownBtn); VM.RisingStarBtn.onClick.Add(OnClickRisingStarBtn); VM.BackBtn.onClick.Add(OnClickBackBtn); } private void RemoveUIListenres() { VM.PreviousBtn.onClick.Remove(OnClickPreviousBtn); VM.NextBtn.onClick.Remove(OnClickNextBtn); VM.ChangeBtn.onClick.Remove(OnClickChangeBtn); VM.UpgradeBtn.onClick.Remove(OnClickUpgradeBtn); VM.GoIntoBattleBtn.onClick.Remove(OnClickGoIntoBattleBtn); VM.TakeDownBtn.onClick.Remove(OnclickTakeDownBtn); VM.RisingStarBtn.onClick.Remove(OnClickRisingStarBtn); VM.BackBtn.onClick.Remove(OnClickBackBtn); } private void OnClickPreviousBtn(EventContext context) { OnSelectPartner(_curIndex-1); } private void OnClickNextBtn(EventContext context) { OnSelectPartner(_curIndex+1); } private void OnClickChangeBtn(EventContext context) { EventSingle.Instance.Notify(EventDefine.ShowTips, "打开铭文替换界面"); } private void OnClickUpgradeBtn(EventContext context) { EventSingle.Instance.Notify(EventDefine.ShowTips, "升级按钮事件"); } private void OnClickGoIntoBattleBtn(EventContext context) { EventSingle.Instance.Notify(EventDefine.ShowTips, "上阵按钮事件"); //if (PartnersData.Instance.IsReachedLimit) //{ // //Context.UI.OpenAsync(UIKeys.PartnerReplacePartnerPanel, new PartnerParam() // //{ // // partnerId = _partnerId, // // lineupPlanIndex = PartnersData.Instance.usePlanIndex // //}); // EventSingle.Instance.Notify(EventDefine.WaitForDownPartner,true); //} //else //{ // PartnersService.Instance.RequestPartnerUp(_partnerId); //} EventSingle.Instance.Notify(EventDefine.WaitForDownPartner, true); OnClosePanel(); } /// /// 下阵按钮事件 /// /// private void OnclickTakeDownBtn(EventContext context) { //PartnersData.Instance.GoneUpMap.ContainsKey(_partnerId) //PartnersService.Instance.RequestPartnerDown(_partnerId); OnClosePanel(); } private void OnClickRisingStarBtn(EventContext context) { EventSingle.Instance.Notify(EventDefine.ShowTips, "升星按钮事件"); } private void OnClickBackBtn(EventContext context) { OnClosePanel(); } #endregion private void AddEventListener() { EventSingle.Instance.AddListener(EventDefine.UpgradePartnerLevel, UpgradePartnerLevel); EventSingle.Instance.AddListener(EventDefine.UpgradePartnerStar, UpgradePartnerStar); } private void RemoveEventListener() { EventSingle.Instance.RemoveListener(EventDefine.UpgradePartnerLevel, UpgradePartnerLevel); EventSingle.Instance.RemoveListener(EventDefine.UpgradePartnerStar, UpgradePartnerStar); } private void InitUI(PartnerListItemData data) { if (data != null) { _partnerId = data.tableId; //_state = data.state; } } private void ShowUI() { InitPartnerIdList(); _curIndex = _partnerIdList.IndexOf(_partnerId); XGame.Log.Info($"_partnerId:{_partnerId}所处的索引:{_curIndex}"); ShowPartnerUI(); ShowBtnState(); } private void ShowPartnerUI() { if (PartnersData.Instance.PartnersMap.TryGetValue(_partnerId, out var partnerData)) { var partnerInfo = PartnerTableRepo.Get(partnerData.TableId); if (partnerInfo != null) { EQualityLevel qualityLv = (EQualityLevel)partnerInfo.Quality; VM.PartnerIcon.icon = partnerInfo.Icon; //LoadPartnerSpine(partnerInfo?.Model); VM.QualityIcon.icon = AddressableDefine.ItemFrame(qualityLv); VM.SacredVesselsIcon.icon = partnerInfo.Icon; VM.AttrTypeIcon.icon = AddressableDefine.PartnerElementType((int)partnerInfo.Element); VM.NameLabel.text = partnerInfo.Name; VM.TypeLabel.text = StringDefine.partnerTypeList[partnerInfo.Type - 1]; ShowUpgradeUI(partnerData.TableId, partnerData.Level); ShowStarRatingUI(partnerData.RisingStarLv, partnerData.TableId); ShowBuff(partnerInfo.Skill, partnerData.RisingStarLv); } } } /// /// 星星数 /// /// private void ShowPartnerStarUI(int starLv) { int starNum = starLv == 0 ? 0 : starLv % PartnersData.MaxStarNum; if (starLv > 0 && starNum == 0)starNum = PartnersData.MaxStarNum; int starStep = PartnersData.Instance.GetStarStep(starLv); int[] array = Enumerable.Repeat(starStep, starNum).ToArray(); VM.StarRatingList.BindDatas(array); //XGame.Log.Info($"星级starLv:{starLv}对应的星阶starStep:{starStep}"); } /// /// 升级消耗 /// /// private void ShowUpgradeCostUI(partnerLvUpTable partnerInfo) { if (partnerInfo == null) return; bool bMaxLv = partnerLvUpTableRepo.Get(partnerInfo.Id + 1) == null; VM.MaxLvCtrl.selectedIndex = bMaxLv ? 1 : 0; if (!bMaxLv) { if (partnerInfo?.LevelUpCost?.Length > 0) { VM.UpgradeCostItem.Ctrl.ShowCostUI(partnerInfo.LevelUpCost[0], partnerInfo.LevelUpCost[1]); } } } /// /// 升星相关UI /// /// /// private void ShowStarRatingUI(int starLv, int partnerTableId) { ShowPartnerStarUI(starLv); partnerStarUpTable partnerStarInfo = partnerStarUpTableRepo.Get(partnerTableId * 1000 + starLv); ShowStarRatingCostUI(starLv, partnerStarInfo); ShowStarOwnAttr(partnerStarInfo?.StarOwnAttr); } /// /// 拥有的星级效果属性描述 /// private void ShowStarOwnAttr(int[] attrsArray) { string desc = string.Empty; if (attrsArray?.Length > 0) { for (int i = 0; i < attrsArray.Length; i+=2) { GetAttributeDesc(attrsArray[i], attrsArray[i + 1], ref desc); if (i+1 < attrsArray.Length-1) { desc += ","; } } } VM.SkillEffectLabel.text = string.Format(StringDefine.partnerStarAttribute, desc); } private void GetAttributeDesc(int attrType, int attrValue,ref string desc) { var attributeInfo = AttrDescTableRepo.Get(attrType); string valStr = attrValue > 0 ? TableUtils.ToRealDouble(attrValue).ToString("F2") : "0"; desc += $"{attributeInfo?.ShowName}{valStr}%"; } /// /// 升星消耗 /// /// private void ShowStarRatingCostUI(int starLv, partnerStarUpTable partnerStarInfo) { bool bMaxStar = starLv >= PartnersData.MaxStarNum * PartnersData.MaxStarStep; VM.MaxStarCtrl.selectedIndex = bMaxStar ? 1 : 0; if (!bMaxStar && partnerStarInfo?.StarUpCost > 0) { long num = ItemData.Instance.GetItemNum(partnerStarInfo.PetId); VM.StarCostBar.max = partnerStarInfo.StarUpCost; VM.StarCostBar.value = num; } } private void InitPartnerIdList() { if (_partnerIdList == null) _partnerIdList = new List(); else _partnerIdList.Clear(); var partnersMap = PartnersData.Instance.PartnersMap; if (partnersMap != null) { foreach (var key in partnersMap.Keys) { _partnerIdList.Add(key); } } } private void OnSelectPartner(int selectIndex) { if (selectIndex < 0 || selectIndex >= _partnerIdList?.Count) return; _curIndex = selectIndex; _partnerId = _partnerIdList[selectIndex]; _state = PartnersData.Instance.GoneUpMap.ContainsKey(_partnerId) ? 2 : 1; ShowPartnerUI(); ShowBtnState(); } /// /// 上一个|下一个按钮显隐 /// private void ShowBtnState() { VM.PreviousBtn.visible = _curIndex > 0; VM.NextBtn.visible = _curIndex < _partnerIdList.Count - 1; // 2_已上阵的圣器 VM.ShowBtnCtrl.selectedIndex = _state == 2 ? 1 : 0; } /// /// 圣器升级基础属性 /// /// /// private void ShowUpgradeUI(int partnerTableId, int level) { VM.LvLabel.text = $"LV.{level}"; partnerLvUpTable partnerLvInfo = partnerLvUpTableRepo.Get(partnerTableId * 1000 + level); ShowUpgradeCostUI(partnerLvInfo); if (partnerLvInfo?.LvAttr?.Length > 0) { ShowAttack(partnerLvInfo.LvAttr[0], partnerLvInfo.LvAttr[1]); if (partnerLvInfo.LvAttr.Length > 3) { ShowAtkSpeed(partnerLvInfo.LvAttr[2], partnerLvInfo.LvAttr[3]); } } } /// /// 攻速描述 /// /// private void ShowAtkSpeed(int attrType, long atkSpeedVal) { //var attributeInfo = AttrDescTableRepo.Get(attrType); string desc = atkSpeedVal > 0 ? TableUtils.ToRealDouble(atkSpeedVal).ToString("F1") : "0"; //VM.AtkSpeedLabel.text = $"{attributeInfo?.ShowName}:{desc}"; VM.AtkSpeedLabel.text = string.Format(StringDefine.partnerAtkSpeed, desc); } /// /// 攻击伤害 /// /// /// private void ShowAttack(int attrType,long attackVal) { //var attributeInfo = AttrDescTableRepo.Get(attrType); string desc = attackVal > 0 ? TableUtils.ToRealDouble(attackVal).ToString("F1") : "0"; //VM.AtkLabel.text = $"{attributeInfo?.ShowName}:{desc}"; VM.AtkLabel.text = string.Format(StringDefine.partnerAttack, desc); } /// /// 加载圣器的spine /// /// private void LoadPartnerSpine(string spineName) { VM.PartnerSpine.LoadSpine(spineName, "idle", true); } private void ShowBuff(int[] starSkillIds, int risingStarLv) { var dataList = new List>(); if (starSkillIds?.Length > 0) { int index = 0; for (int i = 0; i < starSkillIds.Length; i += 2) { // 0星激活的技能效果 if (starSkillIds[i + 1] == 0) { ShowSkillBaseInfo(starSkillIds[i]); } else { var data = new List() { starSkillIds[i], starSkillIds[i + 1], risingStarLv }; dataList.Add(data); } index++; } } VM.StarBuffItemList.BindDatas(dataList); } /// /// 基础技能描述 /// /// private void ShowSkillBaseInfo(int skillId) { var skillInfo = SkillTableRepo.Get(skillId); VM.SkillInfoLabel.text = skillInfo == null ? "" : skillInfo.Desc; } /// /// 圣兵升级监听事件 /// /// /// private void UpgradePartnerLevel(int eventId, object args) { } /// /// 圣兵升星监听事件 /// /// /// private void UpgradePartnerStar(int eventId, object args) { } } }