123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
-
- /// #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
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PartnerDetailsPanelCtrl : UIController<PartnerDetailsPanelVM>
- {
- private long _partnerId;
- private int _state; /// 1:已获取未上阵 2:已上阵
- private int _curIndex;
- private List<long> _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();
- }
- /// <summary>
- /// 下阵按钮事件
- /// </summary>
- /// <param name="context"></param>
- 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);
- }
- }
- }
- /// <summary>
- /// 星星数
- /// </summary>
- /// <param name="starLv"></param>
- 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}");
- }
- /// <summary>
- /// 升级消耗
- /// </summary>
- /// <param name="starLv"></param>
- 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]);
- }
- }
- }
- /// <summary>
- /// 升星相关UI
- /// </summary>
- /// <param name="starLv"></param>
- /// <param name="partnerTableId"></param>
- private void ShowStarRatingUI(int starLv, int partnerTableId)
- {
- ShowPartnerStarUI(starLv);
- partnerStarUpTable partnerStarInfo = partnerStarUpTableRepo.Get(partnerTableId * 1000 + starLv);
- ShowStarRatingCostUI(starLv, partnerStarInfo);
- ShowStarOwnAttr(partnerStarInfo?.StarOwnAttr);
- }
- /// <summary>
- /// 拥有的星级效果属性描述
- /// </summary>
- 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}%";
- }
- /// <summary>
- /// 升星消耗
- /// </summary>
- /// <param name="starLv"></param>
- 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<long>();
- 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();
- }
- /// <summary>
- /// 上一个|下一个按钮显隐
- /// </summary>
- private void ShowBtnState()
- {
- VM.PreviousBtn.visible = _curIndex > 0;
- VM.NextBtn.visible = _curIndex < _partnerIdList.Count - 1;
- // 2_已上阵的圣器
- VM.ShowBtnCtrl.selectedIndex = _state == 2 ? 1 : 0;
- }
- /// <summary>
- /// 圣器升级基础属性
- /// </summary>
- /// <param name="partnerTableId"></param>
- /// <param name="level"></param>
- 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]);
- }
- }
- }
- /// <summary>
- /// 攻速描述
- /// </summary>
- /// <param name="atkSpeedVal"></param>
- 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);
- }
- /// <summary>
- /// 攻击伤害
- /// </summary>
- /// <param name="attrType"></param>
- /// <param name="attackVal"></param>
- 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);
- }
- /// <summary>
- /// 加载圣器的spine
- /// </summary>
- /// <param name="spineName"></param>
- private void LoadPartnerSpine(string spineName)
- {
- VM.PartnerSpine.LoadSpine(spineName, "idle", true);
- }
- private void ShowBuff(int[] starSkillIds, int risingStarLv)
- {
- var dataList = new List<List<int>>();
- 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<int>()
- {
- starSkillIds[i],
- starSkillIds[i + 1],
- risingStarLv
- };
- dataList.Add(data);
- }
- index++;
- }
- }
- VM.StarBuffItemList.BindDatas(dataList);
- }
- /// <summary>
- /// 基础技能描述
- /// </summary>
- /// <param name="skillId"></param>
- private void ShowSkillBaseInfo(int skillId)
- {
- var skillInfo = SkillTableRepo.Get(skillId);
- VM.SkillInfoLabel.text = skillInfo == null ? "" : skillInfo.Desc;
- }
- /// <summary>
- /// 圣兵升级监听事件
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void UpgradePartnerLevel(int eventId, object args)
- {
- }
- /// <summary>
- /// 圣兵升星监听事件
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void UpgradePartnerStar(int eventId, object args)
- {
- }
- }
- }
|