/// #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 PartnerEpiMainPanelCtrl : UIController { private bool _initialized = false; private bool _showPlanSwitch = false; private Controller _switchBtnCtrl; protected override void OnEnable(object intent) { AddUIListenres(); AddEventListenres(); InitList(); UpView(); } protected override void OnDisable() { RemoveUIListenres(); RemoveEventListenres(); ClearView(); } #region UI事件 private void AddUIListenres() { VM.OneUpBtn.onClick.Add(OnClickOneUpBtn); VM.OneStrongBtn.onClick.Add(OnClickOneStrongBtn); VM.ChangeBtn.onClick.Add(OnClickChangeBtn); VM.MaskBtn.onClick.Add(OnClickMaskBtn); } private void RemoveUIListenres() { VM.OneUpBtn.onClick.Remove(OnClickOneUpBtn); VM.OneStrongBtn.onClick.Remove(OnClickOneStrongBtn); VM.ChangeBtn.onClick.Remove(OnClickChangeBtn); VM.MaskBtn.onClick.Remove(OnClickMaskBtn); } private void OnClickChangeBtn(EventContext context) { _showPlanSwitch = !_showPlanSwitch; if (EpigraphData.Instance.UpModeSelect > 0) { EpigraphService.Instance.FinishUpMode(); } ShowPlanNested(); RefreshBagEpigraph(); } private void OnClickMaskBtn(EventContext context) { EpigraphService.Instance.FinishUpMode(); } #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.EpigraphStrongAll, OnUpdateAll); 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.EpigraphStrongAll, OnUpdateAll); EventSingle.Instance.RemoveListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode); EventSingle.Instance.RemoveListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode); EventSingle.Instance.RemoveListener(EventDefine.EpigraphUpModeSelect, OnEpiUpSelect); } #endregion private void OnClickOneUpBtn(EventContext context) { EpigraphService.Instance.RequestEpiWearAll(); } private void OnClickOneStrongBtn(EventContext context) { var list = EpigraphData.Instance.EpiList; var canUp = false; foreach (var epigraph in list) { var lvTable = epigraphUpTableRepo.GetEpiragphUp(epigraph.TableId, epigraph.StarLv); if (lvTable == null) { Log.Error($"铭文升星表不存在id:{epigraph.TableId},starLv:{epigraph.StarLv}"); } if (ItemService.Instance.IsEnough(epigraph.TableId, lvTable.LevelUpCost, false)) { canUp = true; break; } } if (canUp) { EpigraphService.Instance.RequestEpiStrongAll(); } else { Context.ShowTips(StringDefine.EpigraphCantStarUpAll); } } #endregion #region 事件 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 OnReName(int eventId, object args) { UpdatePlanName(); } private void OnUpdateAll(int eventId, object args) { RefreshBagEpigraph(); RefreshGoneUpPartners(); } private void OnPlanChange(int eventId, object args) { UpdatePlanName(); RefreshBagEpigraph(); RefreshGoneUpPartners(); } private void OnEpiUpdate(int eventId, object args) { RefreshBagEpigraph(); RefreshGoneUpPartners(); } /// /// 铭文上阵打开事件 /// /// /// private void OnOpenUpMode(int eventId, object args) { if (_showPlanSwitch) { ShowPlanNested(); RefreshBagEpigraph(); } ShowUpMode(); } private void OnFinishUpMode(int eventId, object args) { ShowUpMode(); } #endregion private void InitList() { if (_initialized) return; VM.UpList.ListType = EGListType.None; VM.BagList.ListType = EGListType.Virtual; _switchBtnCtrl = VM.ChangeBtn.GetController("arr"); _initialized = true; } private void UpView() { RefreshBagEpigraph(); RefreshGoneUpPartners(); UpdatePlanName(); 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 UpdatePlanName() { var plan = PartnersData.Instance.CurUsePlan; VM.PlanLabel.text = plan.Name; } private void RefreshBagEpigraph() { if (VM.State.selectedIndex == 1) return; var list = EpigraphTableRepo.GetAll(); VM.BagList.BindDatas(list); ShowOwnerAttr(); } private void ShowPlanNested() { VM.State.selectedIndex = _showPlanSwitch ? 1 : 0; _switchBtnCtrl.selectedIndex = _showPlanSwitch ? 1 : 0; if (_showPlanSwitch) { VM.PlanNested.Enable(null); VM.PlanNested.Ctrl.ShowUI(); } else { VM.PlanNested.Disable(); } } private void ShowUpMode() { if (PartnersData.Instance.UpModeSelect > 0) { VM.SelectMode.selectedIndex = 1; } else if (EpigraphData.Instance.UpModeSelect > 0) { VM.SelectMode.selectedIndex = 1; } else { VM.SelectMode.selectedIndex = 0; } } private void ClearView() { EpigraphService.Instance.FinishUpMode(); PartnersService.Instance.FinishUpPartnerMode(); _showPlanSwitch = false; VM.PlanNested.Disable(); } public void ShowOwnerAttr() { var list = EpigraphData.Instance.EpiList; var map = new Dictionary(); foreach (var epigraph in list) { var starTable = epigraphUpTableRepo.GetEpiragphUp( epigraph.TableId, epigraph.StarLv ); if (starTable == null) { Log.Error($"铭文升星表不存在id:{epigraph.TableId},starLv:{epigraph.StarLv}"); continue; } var attrsArray = starTable.LvOwnAttr; 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("%"); } } }