123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- /// #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 PartnerMainPanelCtrl : UIController<PartnerMainPanelVM>
- {
- #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);
- }
- }
- /// <summary>
- /// 圣兵上阵打开事件
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- 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<int>();
- 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<int>();
- 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<int, int>();
- 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("%");
- }
- }
- }
|