/// #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 { /// /// UI逻辑处理类 /// /// public partial class PartnerSbStrengthPanelCtrl : 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.LevelUpBtn.VM.PanelEvent.Add(OnClickLevelUp); VM.DownBtn.onClick.Add(OnClickDownBtn); EventSingle.Instance.AddListener(EventDefine.PartnerUpLevel, OnUpLevel); EventSingle.Instance.AddListener(EventDefine.PartnerUpStar, OnUpStar); } 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); EventSingle.Instance.RemoveListener(EventDefine.PartnerUpLevel, OnUpLevel); EventSingle.Instance.RemoveListener(EventDefine.PartnerUpStar, OnUpStar); } private void OnClickDownBtn(EventContext eventContext) { PartnersService.Instance.RequestPartnerDownNew(_curSelectId); Context.ClosePanel(); } private void OnUpStar(int eventId, object args) { ShowInfo(); } private void OnUpLevel(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, ) } #endregion private bool _init = false; private List _sbList = new List(); 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(); 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(); } } }