123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- /// #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
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PartnerEpiMainPanelCtrl : UIController<PartnerEpiMainPanelVM>
- {
- 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();
- }
- /// <summary>
- /// 铭文上阵打开事件
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- 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<int>();
- 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<int, int>();
- 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("%");
- }
- }
- }
|