123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using System.Collections.Generic;
- using FairyGUI;
- using FL.Data;
- using XGame.Database;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PartnerSbStrengthPanelCtrl : UIController<PartnerSbStrengthPanelVM>
- {
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- InitView();
- _curSelectId = (int)intent;
- ShowUI();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.UpBtn.onClick.Add(OnClickUpBtn);
- VM.LeftBtn.onClick.Add(OnClickLeftBtn);
- VM.RightBtn.onClick.Add(OnClickRightBtn);
- VM.MwSet.VM.PanelEvent.Add(OnClickMwSet);
- VM.StarUpBtn.VM.PanelEvent.Add(OnClickStarUp);
- VM.LevelUpBtn.VM.PanelEvent.Add(OnClickLevelUp);
- VM.DownBtn.onClick.Add(OnClickDownBtn);
- Context.AddListener(EventDefine.PartnerUpLevel, OnUpInfo);
- Context.AddListener(EventDefine.PartnerUpStar, OnUpInfo);
- Context.AddListener(EventDefine.PartnerBinding, OnEpiChange);
- }
- private void RemoveUIListenres()
- {
- VM.UpBtn.onClick.Remove(OnClickUpBtn);
- VM.LeftBtn.onClick.Remove(OnClickLeftBtn);
- VM.RightBtn.onClick.Remove(OnClickRightBtn);
- VM.MwSet.VM.PanelEvent.Remove(OnClickMwSet);
- VM.StarUpBtn.VM.PanelEvent.Remove(OnClickStarUp);
- VM.LevelUpBtn.VM.PanelEvent.Remove(OnClickLevelUp);
- VM.DownBtn.onClick.Remove(OnClickDownBtn);
- Context.RemoveListener(EventDefine.PartnerUpLevel, OnUpInfo);
- Context.RemoveListener(EventDefine.PartnerUpStar, OnUpInfo);
- Context.RemoveListener(EventDefine.PartnerBinding, OnEpiChange);
- }
- private void OnClickDownBtn(EventContext eventContext)
- {
- PartnersService.Instance.RequestPartnerDownNew(_curSelectId);
- Context.ClosePanel();
- }
- public void OnEpiChange(int eventId, object args)
- {
- ShowEpi();
- }
- private void OnUpInfo(int eventId, object args)
- {
- ShowInfo();
- }
- private void OnClickLevelUp()
- {
- var attr = PartnersData.Instance.GetPartnerAttrByTableId(_curSelectId);
- var level = attr?.Level ?? 1;
- var upLevelTable = partnerLvUpTableRepo.GetPartnerLvUpTable(_curSelectId, level);
- XGame.Framework.Assert.IsNotNull(
- upLevelTable,
- $"圣兵升级表不存在,id:{_curSelectId},level:{level}"
- );
- if (
- ItemService.Instance.IsEnough(
- upLevelTable.LevelUpCost[0],
- upLevelTable.LevelUpCost[1],
- true
- )
- )
- {
- PartnersService.Instance.RequestLvUp(_curSelectId);
- }
- }
- private void OnClickStarUp(EventContext context)
- {
- var attr = PartnersData.Instance.GetPartnerAttrByTableId(_curSelectId);
- var star = attr?.RisingStarLv ?? 1;
- var starUpTable = partnerStarUpTableRepo.GetPartnerStarTable(_curSelectId, star);
- XGame.Framework.Assert.IsNotNull(
- starUpTable,
- $"圣兵升星表不存在,id:{_curSelectId},starlv:{star}"
- );
- if (ItemService.Instance.IsEnough(starUpTable.PetId, starUpTable.StarUpCost, true))
- {
- PartnersService.Instance.RequestStarUp(_curSelectId);
- }
- }
- private void OnClickUpBtn(EventContext context)
- {
- PartnersService.Instance.OpenUpPartnerMode(_curSelectId);
- Context.UI.Close(UIKeys.PartnerSbBagPanel);
- Context.ClosePanel();
- }
- private void OnClickLeftBtn(EventContext context)
- {
- OnSelectPartnerOffset(-1);
- }
- private void OnClickRightBtn(EventContext context)
- {
- OnSelectPartnerOffset(1);
- }
- private void OnClickMwSet(EventContext context)
- {
- Context.UI.OpenAsync(
- UIKeys.PartnerEpiChangePanel,
- new PartnerEpiChangePanelCtrlParam() { SbId = _curSelectId }
- );
- }
- #endregion
- private bool _init = false;
- private List<int> _sbList = new List<int>();
- private int _curSelectId;
- private void InitView()
- {
- if (_init)
- return;
- _init = true;
- var tableList = PartnerTableRepo.GetAll();
- foreach (var item in tableList)
- {
- _sbList.Add(item.Id);
- }
- }
- private void ShowUI()
- {
- ShowInfo();
- ShowEpi();
- }
- private void ShowInfo()
- {
- var table = PartnerTableRepo.Get(_curSelectId);
- XGame.Framework.Assert.IsNotNull(table, $"圣兵表不存在,id:{_curSelectId}");
- VM.NameLabel.text = table.Name;
- VM.PictureLoader.url = AddressableDefine.PartnerPicture(table.Id);
- var attr = PartnersData.Instance.GetPartnerAttrByTableId(table.Id);
- var level = attr == null ? 1 : attr.Level;
- var star = attr == null ? 1 : attr.RisingStarLv;
- if (attr == null)
- {
- VM.StarUpBtn.Disable();
- VM.LevelUpBtn.Disable();
- VM.Have.selectedIndex = 1;
- }
- else
- {
- if (partnerStarUpTableRepo.GetPartnerStarTable(_curSelectId, star + 1) == null)
- {
- VM.StarUpBtn.Disable();
- }
- else
- {
- VM.StarUpBtn.Enable(null);
- }
- if (partnerLvUpTableRepo.GetPartnerLvUpTable(_curSelectId, level + 1) == null)
- {
- VM.LevelUpBtn.Disable();
- }
- else
- {
- VM.LevelUpBtn.Enable(null);
- }
- VM.Have.selectedIndex = 0;
- var pos = PartnersData.Instance.UpSbPosMap.GetValueOrDefault(_curSelectId, -1);
- VM.IsUp.selectedIndex = pos < 0 ? 0 : 1;
- }
- ShowStar(star);
- VM.LvLabel.text = $"Lv {level}";
- VM.DetailNested.Ctrl.ShowUI(_curSelectId);
- if (attr != null)
- {
- ShowUpBtn(attr.TableId);
- }
- }
- private void ShowStar(int starLv)
- {
- var curNum = PartnersService.Instance.GetStarLv(starLv);
- var curStep = PartnersService.Instance.GetStarStep(starLv);
- var list = new List<int>();
- for (int i = 0; i < curNum; i++)
- {
- list.Add(curStep);
- }
- VM.StarList.BindDatas(list);
- }
- private void ShowEpi()
- {
- var info = PartnersData.Instance.GetPartnerAttrByTableId(_curSelectId);
- if (info == null)
- {
- VM.MwSet.Disable();
- }
- else
- {
- VM.MwSet.Enable(null);
- VM.MwSet.Ctrl.SetData(info.EpigraphId, _curSelectId, true);
- }
- }
- private void ShowUpBtn(int sbId)
- {
- VM.StarUpBtn.Ctrl.SetData(sbId);
- VM.LevelUpBtn.Ctrl.ShowUI(sbId);
- }
- private void OnSelectPartnerOffset(int offset)
- {
- var index = _sbList.IndexOf(_curSelectId);
- index += offset;
- if (index < 0)
- {
- index += _sbList.Count;
- }
- else if (index >= _sbList.Count)
- {
- index -= _sbList.Count;
- }
- _curSelectId = _sbList[index];
- ShowUI();
- }
- }
- }
|