123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using System.Collections.Generic;
- using FairyGUI;
- using FL.Data;
- using FL.Data.Items;
- using XGame.Database;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PartnerMwStrengthPanelCtrl : UIController<PartnerMwStrengthPanelVM>
- {
- 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.DownBtn.onClick.Add(OnClickDownBtn);
- Context.AddListener(EventDefine.EpigraphUpStar, 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.DownBtn.onClick.Remove(OnClickDownBtn);
- Context.RemoveListener(EventDefine.EpigraphUpStar, OnUpInfo);
- Context.RemoveListener(EventDefine.PartnerBinding, OnEpiChange);
- }
- private void OnClickDownBtn(EventContext eventContext)
- {
- var mwData = EpigraphData.Instance.GetEpigraphAttrByTableId(_curSelectId);
- EpigraphService.Instance.RequestEpiInset(mwData.PartnerId, 0);
- Context.ClosePanel();
- }
- public void OnEpiChange(int eventId, object args)
- {
- ShowUI();
- }
- private void OnUpInfo(int eventId, object args)
- {
- ShowInfo();
- }
- private void OnClickStarUp(EventContext context)
- {
- var attr = EpigraphData.Instance.GetEpigraphAttrByTableId(_curSelectId);
- var star = attr?.StarLv ?? 1;
- var starUpTable = epigraphUpTableRepo.GetEpiragphUp(_curSelectId, star);
- XGame.Framework.Assert.IsNotNull(
- starUpTable,
- $"铭文升星表不存在,id:{_curSelectId},starlv:{star}"
- );
- if (ItemService.Instance.IsEnough(starUpTable.PetId, starUpTable.LevelUpCost, true))
- {
- EpigraphService.Instance.RequestEpiStarUp(_curSelectId);
- }
- }
- private void OnClickUpBtn(EventContext context)
- {
- if (PartnersData.Instance.UpSbPosMap.Count <= 0)
- {
- Context.ShowTips(EStringDefine.PartnerNoUp);
- return;
- }
- EpigraphService.Instance.OpenUpMode(_curSelectId);
- Context.UI.Close(UIKeys.PartnerSbBagPanel);
- Context.ClosePanel();
- }
- private void OnClickLeftBtn(EventContext context)
- {
- OnSelectPartnerOffset(-1);
- }
- private void OnClickRightBtn(EventContext context)
- {
- OnSelectPartnerOffset(1);
- }
- #endregion
- private bool _init = false;
- private List<int> _mwList = new List<int>();
- private int _curSelectId;
- private void InitView()
- {
- if (_init)
- return;
- _init = true;
- var tableList = EpigraphTableRepo.GetAll();
- foreach (var item in tableList)
- {
- _mwList.Add(item.Id);
- }
- }
- private void ShowUI()
- {
- ShowInfo();
- ShowSb();
- }
- private void ShowInfo()
- {
- var table = EpigraphTableRepo.Get(_curSelectId);
- XGame.Framework.Assert.IsNotNull(table, $"铭文表不存在,id:{_curSelectId}");
- VM.NameLabel.text = table.Name;
- VM.MwBase.Ctrl.SetEpiIcon(_curSelectId);
- var mwData = EpigraphData.Instance.GetEpigraphAttrByTableId(table.Id);
- var star = mwData?.StarLv ?? 1;
- if (mwData == null)
- {
- VM.StarUpBtn.Disable();
- VM.Have.selectedIndex = 1;
- }
- else
- {
- if (epigraphUpTableRepo.GetEpiragphUp(_curSelectId, star + 1) == null)
- {
- VM.StarUpBtn.Disable();
- }
- else
- {
- VM.StarUpBtn.Enable(null);
- }
- VM.Have.selectedIndex = 0;
- var sbId = mwData?.PartnerId ?? 0;
- VM.IsUp.selectedIndex = sbId <= 0 ? 0 : 1;
- }
- ShowStar(star);
- VM.DetailNested.Ctrl.ShowUI(_curSelectId);
- if (mwData != null)
- {
- ShowUpBtn(mwData.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 ShowSb()
- {
- var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_curSelectId);
- if (info == null)
- {
- VM.SbSetItem.Disable();
- }
- else
- {
- if (info.PartnerId > 0)
- {
- var data = ItemBase.Create(info.PartnerId);
- VM.SbSetItem.Enable(null);
- VM.SbSetItem.VM.ItemBase.Ctrl.ShowUI(data);
- }
- else
- {
- VM.SbSetItem.VM.ItemBase.Ctrl.ShowEmptyUI();
- }
- }
- }
- private void ShowUpBtn(int sbId)
- {
- VM.StarUpBtn.Ctrl.SetData(sbId);
- }
- private void OnSelectPartnerOffset(int offset)
- {
- var index = _mwList.IndexOf(_curSelectId);
- index += offset;
- if (index < 0)
- {
- index += _mwList.Count;
- }
- else if (index >= _mwList.Count)
- {
- index -= _mwList.Count;
- }
- _curSelectId = _mwList[index];
- ShowUI();
- }
- }
- }
|