/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using System.Collections.Generic; using System.Text; using FairyGUI; using FL.Data; using XGame; using XGame.Database; using XGame.Framework.UI; using XGame.Framework.Utils; namespace FL.FGUI { /// /// UI逻辑处理类 /// /// public partial class PartnerMainPanelCtrl : UIController { #region 属性 private bool _showPlanSwitch = false; private bool _initView = false; private Controller _switchBtnCtrl; #endregion protected override void OnEnable(object intent) { AddUIListenres(); AddEventListenres(); InitView(); UpView(); } protected override void OnDisable() { RemoveUIListenres(); RemoveEventListenres(); ClearView(); } #region UI事件 private void AddUIListenres() { VM.OneKeyUpBtn.onClick.Add(OnClickOneKeyUpBtn); VM.OneKeyStrongBtn.onClick.Add(OnClickOneKeyStrongBtn); VM.ChangeBtn.onClick.Add(OnClickChangeBtn); VM.MaskBtn.onClick.Add(OnClickMaskBtn); } private void RemoveUIListenres() { VM.OneKeyUpBtn.onClick.Remove(OnClickOneKeyUpBtn); VM.OneKeyStrongBtn.onClick.Remove(OnClickOneKeyStrongBtn); VM.ChangeBtn.onClick.Remove(OnClickChangeBtn); VM.MaskBtn.onClick.Remove(OnClickMaskBtn); } private void OnClickOneKeyUpBtn(EventContext context) { PartnersService.Instance.RequestPartnerOneKeyUp(); } private void OnClickOneKeyStrongBtn(EventContext context) { var list = PartnersData.Instance.PartnerList; var isFind = false; foreach (var partner in list) { var starLvTable = partnerStarUpTableRepo.GetPartnerStarTable( partner.TableId, partner.RisingStarLv ); if (starLvTable == null) { Log.Error( $"圣兵升星表不存在,id:{partner.TableId},starLv:{partner.RisingStarLv}" ); continue; } if (starLvTable.StarUpCost <= ItemData.Instance.GetItemNum(starLvTable.PetId)) { isFind = true; break; } } if (isFind) PartnersService.Instance.RequestPartnerOneKeyLvUp(); else { Context.ShowTips(StringDefine.PartnerCantStarUpAll); } } private void OnClickChangeBtn(EventContext context) { _showPlanSwitch = !_showPlanSwitch; if (PartnersData.Instance.UpModeSelect > 0) { PartnersService.Instance.FinishUpPartnerMode(); } ShowPlanNested(); RefreshAllPartners(); } #endregion #region 事件监听 private void AddEventListenres() { EventSingle.Instance.AddListener(EventDefine.PartnerUp, OnUpdateAll); EventSingle.Instance.AddListener(EventDefine.PartnerDown, OnUpdateAll); EventSingle.Instance.AddListener(EventDefine.PartnerBinding, OnUpdateAll); EventSingle.Instance.AddListener(EventDefine.PartnerPlanChange, OnPlanChange); EventSingle.Instance.AddListener(EventDefine.PartnerStrongAll, OnUpdateAll); EventSingle.Instance.AddListener(EventDefine.PartnerUpLevel, OnUpdateAll); EventSingle.Instance.AddListener(EventDefine.PartnerUpStar, OnUpdateAll); EventSingle.Instance.AddListener(EventDefine.PartnerWearAll, OnUpdateAll); EventSingle.Instance.AddListener(EventDefine.EpigraphWearAll, OnUpdateAll); EventSingle.Instance.AddListener(EventDefine.PartnerFinishUpMode, OnFinishUpMode); EventSingle.Instance.AddListener(EventDefine.PartnerOpenUpMode, OnOpenUpMode); EventSingle.Instance.AddListener( EventDefine.PartnerUpModeSelect, OnPartnerUpModeSelect ); EventSingle.Instance.AddListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode); EventSingle.Instance.AddListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode); EventSingle.Instance.AddListener(EventDefine.EpigraphUpModeSelect, OnEpiUpSelect); } private void RemoveEventListenres() { EventSingle.Instance.RemoveListener(EventDefine.PartnerUp, OnUpdateAll); EventSingle.Instance.RemoveListener(EventDefine.PartnerDown, OnUpdateAll); EventSingle.Instance.RemoveListener(EventDefine.PartnerBinding, OnUpdateAll); EventSingle.Instance.RemoveListener(EventDefine.PartnerPlanChange, OnPlanChange); EventSingle.Instance.RemoveListener(EventDefine.PartnerStrongAll, OnUpdateAll); EventSingle.Instance.RemoveListener(EventDefine.PartnerUpLevel, OnUpdateAll); EventSingle.Instance.RemoveListener(EventDefine.PartnerUpStar, OnUpdateAll); EventSingle.Instance.RemoveListener(EventDefine.PartnerWearAll, OnUpdateAll); EventSingle.Instance.RemoveListener(EventDefine.EpigraphWearAll, OnUpdateAll); EventSingle.Instance.RemoveListener(EventDefine.PartnerFinishUpMode, OnFinishUpMode); EventSingle.Instance.RemoveListener(EventDefine.PartnerOpenUpMode, OnOpenUpMode); EventSingle.Instance.RemoveListener( EventDefine.PartnerUpModeSelect, OnPartnerUpModeSelect ); EventSingle.Instance.RemoveListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode); EventSingle.Instance.RemoveListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode); EventSingle.Instance.RemoveListener(EventDefine.EpigraphUpModeSelect, OnEpiUpSelect); } private void OnUpdateAll(int eventId, object args) { RefreshGoneUpPartners(); RefreshAllPartners(); } private void OnPlanChange(int eventId, object args) { ShowPlanName(); RefreshGoneUpPartners(); RefreshAllPartners(); } private void OnClickMaskBtn(EventContext eventContext) { PartnersService.Instance.FinishUpPartnerMode(); } private void OnPartnerUpModeSelect(int eventId, object args) { if (args is not int pos) return; if (PartnersData.Instance.UpModeSelect > 0) { PartnersService.Instance.RequestPartnerUp(pos, PartnersData.Instance.UpModeSelect); } } private void OnEpiUpSelect(int eventId, object args) { var sbId = (int)args; if (EpigraphData.Instance.UpModeSelect > 0) { EpigraphService.Instance.RequestEpiInset(sbId, EpigraphData.Instance.UpModeSelect); } } /// /// 圣兵上阵打开事件 /// /// /// private void OnOpenUpMode(int eventId, object args) { if (_showPlanSwitch) { _showPlanSwitch = false; ShowPlanNested(); RefreshAllPartners(); } ShowUpMode(); } private void OnFinishUpMode(int eventId, object args) { ShowUpMode(); } #endregion #region 页面 private void InitView() { if (_initView) return; VM.UpList.ListType = EGListType.None; VM.ParentAllList.ListType = EGListType.Virtual; _switchBtnCtrl = VM.ChangeBtn.GetController("arr"); } private void ClearView() { PartnersService.Instance.FinishUpPartnerMode(); EpigraphService.Instance.FinishUpMode(); _showPlanSwitch = false; VM.PlanNested.Disable(); } private void UpView() { ShowPlanName(); RefreshGoneUpPartners(); RefreshAllPartners(); ShowPlanNested(); ShowUpMode(); } private void RefreshGoneUpPartners() { var plan = PartnersData.Instance.CurUsePlan; var list = new List(); for (int i = 0; i < PartnersData.GoneUpLimit; i++) { list.Add(i); } VM.UpList.BindDatas(list); } private void ShowPlanName() { var plan = PartnersData.Instance.CurUsePlan; VM.PlanLabel.text = plan.Name; } private void RefreshAllPartners() { if (VM.SwitchPlan.selectedIndex == 1) return; var table = PartnerTableRepo.GetAll(); var list = new List(); foreach (var partner in table) { list.Add(partner.Id); } list.Sort( (a, b) => { return a - b; } ); //已上阵的排最前,已拥有其次,未解锁排最后, //已拥有的的等级高的排前面, //未解锁的根据id排序 list.Sort( (a, b) => { PartnersData.Instance.TryGetPartnerAttrByTableId(a, out var aAttr); PartnersData.Instance.TryGetPartnerAttrByTableId(b, out var bAttr); if (aAttr != null && bAttr != null) { if (aAttr.Status != bAttr.Status) { return bAttr.Status - aAttr.Status; } else if (bAttr.Level != aAttr.Level) { return bAttr.Level - aAttr.Level; } } else if (aAttr == null && bAttr != null) { return 1; } else if (aAttr != null && bAttr == null) { return -1; } return b - a; } ); VM.ParentAllList.BindDatas(list); ShowOwnerAttr(); } private void ShowUpMode() { if (PartnersData.Instance.UpModeSelect > 0) { VM.UpPartner.selectedIndex = 1; } else if (EpigraphData.Instance.UpModeSelect > 0) { VM.UpPartner.selectedIndex = 1; } else { VM.UpPartner.selectedIndex = 0; } } #endregion private void ShowPlanNested() { VM.SwitchPlan.selectedIndex = _showPlanSwitch ? 1 : 0; _switchBtnCtrl.selectedIndex = _showPlanSwitch ? 1 : 0; if (_showPlanSwitch) { VM.PlanNested.Enable(null); VM.PlanNested.Ctrl.ShowUI(); } else { VM.PlanNested.Disable(); } } public void ShowOwnerAttr() { var list = PartnersData.Instance.PartnerList; var map = new Dictionary(); foreach (var partner in list) { partnerStarUpTable starTable = partnerStarUpTableRepo.GetPartnerStarTable( partner.TableId, partner.RisingStarLv ); if (starTable == null) { Log.Error( $"圣兵升星表不存在id:{partner.TableId}, starLv:{partner.RisingStarLv}" ); continue; } var attrsArray = starTable.StarOwnAttr; if (attrsArray?.Length > 0) { for (int i = 0; i < attrsArray.Length; i += 2) { if (map.TryGetValue(attrsArray[i], out var attr)) { map.Remove(attrsArray[i]); map.Add(attrsArray[i], attr + attrsArray[i + 1]); } else { map.Add(attrsArray[i], attrsArray[i + 1]); } } } } if (map.Count > 0) { var desc = StringBuilderUtils.Acquire(); int index = 0; foreach (var pair in map) { if (index > 0) { desc.Append(","); index++; } GetAttributeDesc(pair.Key, pair.Value, ref desc); } VM.AttrLabel.text = desc.ToString(); VM.HaveLabel.visible = true; VM.AttrLabel.visible = true; } else { VM.HaveLabel.visible = false; VM.AttrLabel.visible = false; } } private void GetAttributeDesc(int attrType, int attrValue, ref StringBuilder desc) { var attributeInfo = AttrDescTableRepo.Get(attrType); string valStr = attrValue > 0 ? TableUtils.ToRealDouble(attrValue).ToString("F2") : "0"; desc.Append(attributeInfo?.ShowName); desc.Append(valStr); desc.Append("%"); } } }