123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using System.Collections.Generic;
- using System.Linq;
- using FairyGUI;
- using FL.Data;
- using XGame;
- using XGame.Database;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- public class PartnerDetailsPanelParam
- {
- public int PlanId;
- /// <summary>
- /// 槽位id,-1为非更换界面打开的详情
- /// </summary>
- public int SlotId;
- public int PartnerId;
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PartnerDetailsPanelCtrl : UIController<PartnerDetailsPanelVM>
- {
- private int _partnerId;
- private int _slotId;
- private int _planId;
- private bool _initView = false;
- private List<int> _partnerIds = new List<int>();
- protected override void OnEnable(object intent)
- {
- var param = intent as PartnerDetailsPanelParam;
- _partnerId = param.PartnerId;
- _planId = param.PlanId;
- _slotId = param.SlotId;
- AddUIListenres();
- AddEventListener();
- InitPartnerIdList();
- ShowUI();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- RemoveEventListener();
- }
- #region 事件
- private void AddUIListenres()
- {
- VM.PreviousBtn.onClick.Add(OnClickPreviousBtn);
- VM.NextBtn.onClick.Add(OnClickNextBtn);
- VM.ChangeBtn.onClick.Add(OnClickChangeBtn);
- VM.UpLvBtn.onClick.Add(OnClickUpLvBtn);
- VM.UpBtn.onClick.Add(OnClickUpBtn);
- VM.DownBtn.onClick.Add(OnClickDownBtn);
- VM.UpStarBtn.onClick.Add(OnClickUpStarBtn);
- VM.BackBtn.onClick.Add(OnClickBackBtn);
- VM.EpiItem.VM.PanelEvent.Add(OnClickEpiSet);
- }
- private void RemoveUIListenres()
- {
- VM.PreviousBtn.onClick.Remove(OnClickPreviousBtn);
- VM.NextBtn.onClick.Remove(OnClickNextBtn);
- VM.ChangeBtn.onClick.Remove(OnClickChangeBtn);
- VM.UpLvBtn.onClick.Remove(OnClickUpLvBtn);
- VM.UpBtn.onClick.Remove(OnClickUpBtn);
- VM.DownBtn.onClick.Remove(OnClickDownBtn);
- VM.UpStarBtn.onClick.Remove(OnClickUpStarBtn);
- VM.BackBtn.onClick.Remove(OnClickBackBtn);
- VM.EpiItem.VM.PanelEvent.Remove(OnClickEpiSet);
- }
- private void AddEventListener()
- {
- EventSingle.Instance.AddListener(EventDefine.PartnerUpLevel, OnUpdateLv);
- EventSingle.Instance.AddListener(EventDefine.PartnerUpStar, OnUpdateStar);
- EventSingle.Instance.AddListener(EventDefine.UpdataItemData, OnItemUpdate);
- EventSingle.Instance.AddListener(EventDefine.PartnerUp, OnUpDownPartner);
- EventSingle.Instance.AddListener(EventDefine.PartnerDown, OnUpDownPartner);
- EventSingle.Instance.AddListener(EventDefine.PartnerBinding, OnBinding);
- }
- private void RemoveEventListener()
- {
- EventSingle.Instance.RemoveListener(EventDefine.PartnerUpLevel, OnUpdateLv);
- EventSingle.Instance.RemoveListener(EventDefine.PartnerUpStar, OnUpdateStar);
- EventSingle.Instance.RemoveListener(EventDefine.UpdataItemData, OnItemUpdate);
- EventSingle.Instance.RemoveListener(EventDefine.PartnerUp, OnUpDownPartner);
- EventSingle.Instance.RemoveListener(EventDefine.PartnerDown, OnUpDownPartner);
- EventSingle.Instance.RemoveListener(EventDefine.PartnerBinding, OnBinding);
- }
- private void OnBinding(int eventId, object args)
- {
- ShowEpi();
- }
- private void OnUpdateStar(int eventId, object args)
- {
- ShowStarUI();
- }
- private void OnItemUpdate(int eventId, object args)
- {
- var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
- var starLv = info?.RisingStarLv ?? 1;
- ShowStarRatingCostUI(starLv);
- }
- private void OnClickPreviousBtn(EventContext context)
- {
- OnSelectPartnerOffset(1);
- }
- private void OnClickNextBtn(EventContext context)
- {
- OnSelectPartnerOffset(-1);
- }
- private void OnClickEpiSet(EventContext context)
- {
- var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
- if (info == null)
- {
- Context.ShowTips(StringDefine.PartnerEmptyTips);
- return;
- }
- Context.UI.OpenAsync(
- UIKeys.PartnerEpiChangePanel,
- new PartnerEpiChangePanelCtrlParam()
- {
- PlanId = PartnersData.Instance.UsePlanId,
- SlotId = -1,
- SbId = _partnerId,
- }
- );
- }
- private void OnClickChangeBtn(EventContext context)
- {
- var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
- if (info == null)
- {
- Context.ShowTips(StringDefine.PartnerEmptyTips);
- return;
- }
- Context.UI.OpenAsync(
- UIKeys.PartnerEpiChangePanel,
- new PartnerEpiChangePanelCtrlParam()
- {
- PlanId = PartnersData.Instance.UsePlanId,
- SlotId = -1,
- SbId = _partnerId,
- }
- );
- }
- private void OnClickUpLvBtn(EventContext context)
- {
- var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
- if (info == null)
- {
- Context.ShowTips(StringDefine.PartnerEmptyTips);
- return;
- }
- var lvTable = partnerLvUpTableRepo.GetPartnerLvUpTable(_partnerId, info.Level);
- if (lvTable == null)
- {
- Context.ShowTips(StringDefine.PartnerUpLvEmptyTips);
- return;
- }
- if (
- !ItemService.Instance.IsEnough(lvTable.LevelUpCost[0], lvTable.LevelUpCost[1], true)
- )
- return;
- PartnersService.Instance.RequestLvUp(_partnerId);
- }
- private void OnClickUpBtn(EventContext context)
- {
- if (!PartnersData.Instance.TryGetPartnerAttrByTableId(_partnerId, out var info))
- {
- Context.ShowTips(StringDefine.PartnerEmptyTips);
- return;
- }
- if (PartnersData.Instance.UsePlanId == _planId)
- {
- if (info.Status > 0)
- {
- Context.ShowTips(StringDefine.PartnerAlreadyUpTips);
- return;
- }
- if (_slotId < 0)
- {
- PartnersService.Instance.OpenPartnerMode(_partnerId);
- }
- else
- {
- PartnersService.Instance.RequestPartnerUp(_slotId, _partnerId);
- }
- }
- else
- {
- PartnersService.Instance.RequestUpdatePlanSb(_planId, _slotId, _partnerId);
- }
- Context.ClosePanel();
- }
- /// <summary>
- /// 下阵按钮事件
- /// </summary>
- /// <param name="context"></param>
- private void OnClickDownBtn(EventContext context)
- {
- if (!PartnersData.Instance.TryGetPartnerAttrByTableId(_partnerId, out var info))
- {
- Context.ShowTips(StringDefine.PartnerEmptyTips);
- return;
- }
- if (_planId == PartnersData.Instance.UsePlanId)
- {
- PartnersService.Instance.RequestPartnerDown(_partnerId);
- }
- else
- {
- if (!PartnersData.Instance.TryGetPlan(_planId, out var plan))
- {
- Context.ShowTips(StringDefine.PartnerPlanEmptyTips);
- return;
- }
- if (!plan.TryGetUpPos(_partnerId, out var upPos))
- {
- Context.ShowTips(StringDefine.PartnerAlreadyUpTips);
- return;
- }
- PartnersService.Instance.RequestUpdatePlanSb(_planId, upPos, 0);
- }
- Context.ClosePanel();
- }
- private void OnClickUpStarBtn(EventContext context)
- {
- var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
- if (info == null)
- {
- Context.ShowTips(StringDefine.PartnerEmptyTips);
- return;
- }
- var starTable = partnerStarUpTableRepo.GetPartnerStarTable(
- _partnerId,
- info.RisingStarLv
- );
- if (starTable == null)
- {
- Context.ShowTips(StringDefine.PartnerUpStarEmptyTips);
- return;
- }
- if (!ItemService.Instance.IsEnough(starTable.PetId, starTable.StarUpCost, true))
- return;
- PartnersService.Instance.RequestStarUp(_partnerId);
- }
- private void OnClickBackBtn(EventContext context)
- {
- Context.ClosePanel();
- }
- private void OnUpDownPartner(int eventId, object args)
- {
- ShowUpDownBtn();
- }
- /// <summary>
- /// 圣兵升级监听事件
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void OnUpdateLv(int eventId, object args)
- {
- ShowLevelUI();
- }
- #endregion
- #region 界面
- private void ShowUI()
- {
- ShowPartnerUI();
- ShowEpi();
- ShowSwitchState();
- }
- private void ShowEpi()
- {
- var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
- if (info == null)
- {
- VM.EpiItem.Disable();
- }
- else
- {
- VM.EpiItem.Enable(null);
- VM.EpiItem.Ctrl.SetData(info.EpigraphId, _partnerId, true);
- }
- }
- private void ShowPartnerUI()
- {
- var table = PartnerTableRepo.Get(_partnerId);
- if (table == null)
- {
- Log.Error($"圣兵tableId {_partnerId} 不存在");
- return;
- }
- VM.PartnerIcon.icon = table.Icon;
- //LoadPartnerSpine(partnerInfo?.Model);
- VM.QualityIcon.icon = AddressableDefine.ItemFrame(table.Quality);
- VM.SacredVesselsIcon.icon = table.SkillIcon;
- VM.AttrTypeIcon.icon = AddressableDefine.PartnerElementType((int)table.Element);
- VM.NameLabel.text = table.Name;
- VM.TypeLabel.text = StringDefine.partnerTypeList[table.Type - 1];
- ShowUpDownBtn();
- var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
- VM.Have.selectedIndex = info != null ? 1 : 0;
- ShowLevelUI();
- ShowStarUI();
- }
- private void ShowUpDownBtn()
- {
- if (!PartnersData.Instance.TryGetPlan(_planId, out var plan))
- {
- Log.Error($"圣兵信息不存在,id:{_planId}");
- return;
- }
- VM.ShowBtnCtrl.selectedIndex = plan.TryGetUpPos(_partnerId, out var upPos) ? 1 : 0;
- }
- private void ShowStarUI()
- {
- var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
- var starLv = info?.RisingStarLv ?? 1;
- ShowPartnerStarUI(starLv);
- ShowStarRatingCostUI(starLv);
- ShowStarOwnAttr(starLv);
- ShowBuff(starLv);
- }
- /// <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 = PartnersService.Instance.GetStarStep(starLv);
- int[] array = Enumerable.Repeat(starStep, starNum).ToArray();
- VM.StarRatingList.BindDatas(array);
- }
- /// <summary>
- /// 拥有的星级效果属性描述
- /// </summary>
- private void ShowStarOwnAttr(int starLv)
- {
- partnerStarUpTable starTable = partnerStarUpTableRepo.GetPartnerStarTable(
- _partnerId,
- starLv
- );
- if (starTable == null)
- {
- Log.Error($"圣兵升星表tableId:{_partnerId}, starLv:{starLv} 不存在");
- return;
- }
- var attrsArray = starTable.StarOwnAttr;
- if (attrsArray?.Length > 0)
- {
- string desc = string.Empty;
- 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);
- VM.SkillEffectLabel.visible = true;
- }
- else
- {
- VM.SkillEffectLabel.visible = false;
- }
- }
- 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 starTable = partnerStarUpTableRepo.GetPartnerStarTable(
- _partnerId,
- starLv
- );
- if (starTable == null)
- {
- Log.Error($"圣兵升星表tableId:{_partnerId}, starLv:{starLv} 不存在");
- return;
- }
- bool isMaxStar =
- partnerStarUpTableRepo.GetPartnerStarTable(_partnerId, starLv + 1) == null;
- VM.MaxStarCtrl.selectedIndex = isMaxStar ? 1 : 0;
- if (!isMaxStar && starTable?.StarUpCost > 0)
- {
- long num = ItemData.Instance.GetItemNum(starTable.PetId);
- VM.StarCostBar.max = starTable.StarUpCost;
- VM.StarCostBar.value = num;
- }
- }
- private void InitPartnerIdList()
- {
- if (_initView)
- return;
- var attrs = PartnerTableRepo.GetAll();
- foreach (var attr in attrs)
- {
- _partnerIds.Add(attr.Id);
- }
- _initView = true;
- }
- private void OnSelectPartnerOffset(int offset)
- {
- var index = _partnerIds.IndexOf(_partnerId);
- index += offset;
- if (index < 0)
- {
- index += _partnerIds.Count;
- }
- else if (index >= _partnerIds.Count)
- {
- index -= _partnerIds.Count;
- }
- _partnerId = _partnerIds[index];
- ShowUI();
- }
- /// <summary>
- /// 上一个|下一个按钮显隐
- /// </summary>
- private void ShowSwitchState()
- {
- VM.CanSwitch.selectedIndex = (_partnerIds.Count > 0 && _slotId < 0) ? 1 : 0;
- }
- /// <summary>
- /// 圣器升级基础属性
- /// </summary>
- /// <param name="partnerTableId"></param>
- /// <param name="level"></param>
- private void ShowLevelUI()
- {
- var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
- var lv = info?.Level ?? 1;
- var lvTable = partnerLvUpTableRepo.GetPartnerLvUpTable(_partnerId, lv);
- if (lvTable == null)
- {
- Log.Error($"圣兵等级提升表不存在sbId{_partnerId}, lv:{lv}");
- return;
- }
- bool bMaxLv = partnerLvUpTableRepo.GetPartnerLvUpTable(_partnerId, lv + 1) == null;
- if (info == null)
- {
- VM.UpgradeCostItem.Disable();
- }
- else if (bMaxLv)
- {
- VM.UpgradeCostItem.Disable();
- }
- else
- {
- VM.UpgradeCostItem.Enable(null);
- }
- VM.LvLabel.text = $"LV.{lv}";
- if (lvTable.LvAttr.Length > 0)
- {
- VM.MaxLvCtrl.selectedIndex = bMaxLv ? 1 : 0;
- if (!bMaxLv)
- {
- if (lvTable?.LevelUpCost?.Length > 0)
- {
- VM.UpgradeCostItem.Ctrl.ShowCostUI(
- lvTable.LevelUpCost[0],
- lvTable.LevelUpCost[1]
- );
- }
- }
- var atkVal = lvTable.LvAttr[1];
- //var attributeInfo = AttrDescTableRepo.Get(attrType);
- string desc = atkVal > 0 ? TableUtils.ToRealDouble(atkVal).ToString("F1") : "0";
- //VM.AtkLabel.text = $"{attributeInfo?.ShowName}:{desc}";
- VM.AtkLabel.text = string.Format(StringDefine.partnerAttack, desc);
- if (lvTable.LvAttr.Length > 3)
- {
- //var attributeInfo = AttrDescTableRepo.Get(attrType);
- var atkSpeed = lvTable.LvAttr[3];
- string descSpeed =
- atkSpeed > 0 ? TableUtils.ToRealDouble(atkSpeed).ToString("F1") : "0";
- //VM.AtkSpeedLabel.text = $"{attributeInfo?.ShowName}:{desc}";
- VM.AtkSpeedLabel.text = string.Format(StringDefine.partnerAtkSpeed, descSpeed);
- }
- }
- }
- /// <summary>
- /// 加载圣器的spine
- /// </summary>
- /// <param name="spineName"></param>
- private void LoadPartnerSpine(string spineName)
- {
- VM.PartnerSpine.LoadSpine(spineName, "idle", true);
- }
- private void ShowBuff(int starLv)
- {
- var table = PartnerTableRepo.Get(_partnerId);
- if (table == null)
- {
- Log.Error($"圣兵tableId {_partnerId} 不存在");
- return;
- }
- var starSkillIds = table?.Skill;
- 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], starLv };
- 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;
- }
- #endregion
- }
- }
|