/// #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 { /// /// UI逻辑处理类 /// /// public partial class PartnerMwStrengthPanelCtrl : UIController { 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 _mwList = new List(); 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(); 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(); } } }