123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- /// #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 PartnerEpiDetailInfoCtrl : UIController<PartnerEpiDetailInfoVM>
- {
- protected override void OnEnable(object intent)
- {
- _mwId = (int)intent;
- AddUIListenres();
- UpView();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.UpBtn.onClick.Add(OnClickUpBtn);
- VM.DownBtn.onClick.Add(OnClickDownBtn);
- VM.GotoBtn.onClick.Add(OnClickGotoBtn);
- VM.RankUpBtn.onClick.Add(OnClickRankUpBtn);
- EventSingle.Instance.AddListener(EventDefine.EpigraphUpStar, OnEpiUpdate);
- EventSingle.Instance.AddListener(EventDefine.PartnerBinding, UpdateUpDownBtn);
- EventSingle.Instance.AddListener(EventDefine.UpdataItemData, OnItemUpdate);
- }
- private void RemoveUIListenres()
- {
- VM.UpBtn.onClick.Remove(OnClickUpBtn);
- VM.DownBtn.onClick.Remove(OnClickDownBtn);
- VM.GotoBtn.onClick.Remove(OnClickGotoBtn);
- VM.RankUpBtn.onClick.Remove(OnClickRankUpBtn);
- EventSingle.Instance.RemoveListener(EventDefine.EpigraphUpStar, OnEpiUpdate);
- EventSingle.Instance.RemoveListener(EventDefine.PartnerBinding, UpdateUpDownBtn);
- EventSingle.Instance.RemoveListener(EventDefine.UpdataItemData, OnItemUpdate);
- }
- private void OnItemUpdate(int eventId, object args)
- {
- UpProgressInfo();
- }
- private void OnEpiUpdate(int eventId, object args)
- {
- UpProgressInfo();
- UpSkillList();
- }
- private void OnClickDownBtn(EventContext eventContext)
- {
- var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
- if (info == null)
- {
- Log.Error($"铭文数据不存在tableId:{_mwId}");
- return;
- }
- EpigraphService.Instance.RequestEpiInset(info.PartnerId, 0);
- Context.ClosePanel();
- }
- private void OnClickUpBtn(EventContext context)
- {
- if (!EpigraphData.Instance.TryGetEpigraphAttrByTableId(_mwId, out var attr))
- {
- Context.ShowTips(StringDefine.EpigraphEmptyTips);
- return;
- }
- if (attr.PartnerId > 0)
- {
- Context.ShowTips(StringDefine.EpigraphAlreadyUpTips);
- return;
- }
- EpigraphService.Instance.OpenUpMode(_mwId);
- Context.ClosePanel();
- }
- private void OnClickGotoBtn(EventContext context) { }
- private void OnClickRankUpBtn(EventContext context)
- {
- var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
- if (info == null)
- {
- Log.Error($"铭文数据不存在tableId:{_mwId}");
- return;
- }
- var table = epigraphUpTableRepo.GetEpiragphUp(_mwId, info.StarLv);
- if (table == null)
- {
- Log.Error($"铭文升星表不存在id:{_mwId}, starLv{info.StarLv}");
- return;
- }
- if (table.LevelUpCost > ItemData.Instance.GetItemNum(_mwId))
- {
- Context.ShowTips(StringDefine.epigraphUpUnenough);
- return;
- }
- EpigraphService.Instance.RequestEpiStarUp(_mwId);
- }
- #endregion
- #region 属性
- private int _mwId;
- #endregion
- #region 页面
- private void UpView()
- {
- UpDescInfo();
- UpProgressInfo();
- UpSkillList();
- }
- private void UpdateUpDownBtn(int eventId, object args)
- {
- var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
- VM.Up.selectedIndex = info?.PartnerId > 0 ? 1 : 0;
- }
- private void UpDescInfo()
- {
- var table = EpigraphTableRepo.Get(_mwId);
- if (table == null)
- {
- Log.Error($"铭文表不存在id:{_mwId}");
- }
- VM.EpiLabel.Ctrl.SetEpiIcon(_mwId, true);
- var initSkillId = table.Skill[0];
- var skillTable = SkillTableRepo.Get(initSkillId);
- if (skillTable == null)
- {
- Log.Error($"技能表不能存在,技能ID:{initSkillId}");
- return;
- }
- VM.DescLabel.text = skillTable.Desc;
- VM.NameLabel.text = table.Name;
- var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
- if (info != null)
- {
- VM.Up.selectedIndex = info.PartnerId > 0 ? 1 : 0;
- int nextLv = info.StarLv + 1;
- var nextUpTable = epigraphUpTableRepo.GetEpiragphUp(_mwId, nextLv);
- VM.HaveState.selectedIndex = nextUpTable != null ? 1 : 2;
- }
- else
- {
- VM.HaveState.selectedIndex = 0;
- }
- if (table.Element > 0)
- {
- VM.AttrIcon.visible = true;
- VM.AttrIcon.url = AddressableDefine.PartnerElementType(((int)table.Element));
- }
- else
- {
- VM.AttrIcon.visible = false;
- }
- VM.HaveAtrr.selectedIndex = table.Own_attr.Length > 0 ? 0 : 1;
- if (table.Own_attr.Length > 0)
- {
- string str = "";
- for (int i = 0; i < table.Own_attr.Length; i += 2)
- {
- var attrTable = AttrDescTableRepo.Get(table.Own_attr[i]);
- if (attrTable == null)
- continue;
- var attrValue = table.Own_attr[i + 1];
- var val =
- attrValue > 0 ? TableUtils.ToRealDouble(attrValue).ToString("F2") : "0";
- if (i > 0)
- str += ",";
- str += $"{attrTable.ShowName}{val}%";
- }
- VM.AttrLabel.SetVar("attr", str).FlushVars();
- }
- }
- private void UpProgressInfo()
- {
- var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
- var curlv = info != null ? info.StarLv : 0;
- var table = epigraphUpTableRepo.GetEpiragphUp(_mwId, curlv);
- if (table == null)
- {
- Log.Error($"铭文升星表不存在id:{_mwId}, starLv:{curlv}");
- return;
- }
- VM.ChipPbar.max = table.LevelUpCost;
- VM.ChipPbar.value = ItemData.Instance.GetItemNum(table.PetId);
- }
- private void UpSkillList()
- {
- var list = new List<EpigraphSkillLimit>();
- var epiTable = EpigraphTableRepo.Get(_mwId);
- if (epiTable == null)
- {
- Log.Error($"铭文表不存在id:{_mwId}");
- return;
- }
- for (var i = 2; i < epiTable.Skill.Length; i = i + 2)
- {
- var skill = epiTable.Skill[i];
- var limit = epiTable.Skill[i + 1];
- var skillLimit = new EpigraphSkillLimit()
- {
- epiId = _mwId,
- limitLv = limit,
- skillId = skill,
- };
- list.Add(skillLimit);
- }
- VM.EffectList.BindDatas(list);
- }
- #endregion
- }
- }
|