123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using System.Collections.Generic;
- using FairyGUI;
- using FL.Data;
- using XGame;
- using XGame.Framework.UI;
- namespace FL.FGUI
- {
- public class PartnerEpiChangePanelCtrlParam
- {
- public int SbId;
- /// <summary>
- /// 方案id
- /// </summary>
- public int PlanId;
- /// <summary>
- /// 方案内槽位,如果有planId则必填
- /// </summary>
- public int SlotId;
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PartnerEpiChangePanelCtrl : UIController<PartnerEpiChangePanelVM>
- {
- protected override void OnEnable(object intent)
- {
- var param = intent as PartnerEpiChangePanelCtrlParam;
- _sbId = param.SbId;
- _planId = param.PlanId;
- _slotId = param.SlotId;
- AddUIListenres();
- InitView();
- UpView();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- }
- #region UI事件
- private void AddUIListenres()
- {
- EventSingle.Instance.AddListener(EventDefine.PartnerBinding, OnUpdateList);
- EventSingle.Instance.AddListener(EventDefine.EpigraphChangeSelect, OnClickItem);
- VM.UpBtn.onClick.Add(OnClickUpBtn);
- }
- private void RemoveUIListenres()
- {
- EventSingle.Instance.RemoveListener(EventDefine.PartnerBinding, OnUpdateList);
- EventSingle.Instance.RemoveListener(EventDefine.EpigraphChangeSelect, OnClickItem);
- VM.UpBtn.onClick.Remove(OnClickUpBtn);
- }
- private void OnUpdateList(int eventId, object args)
- {
- RefreshList();
- }
- private void OnClickItem(int eventId, object args)
- {
- var id = (int)args;
- if (id == _curSelectId && PartnersData.Instance.UsePlanId == _planId)
- {
- Context.UI.OpenAsync(UIKeys.PartnerEpiDetailInfo, _curSelectId);
- Context.ClosePanel();
- return;
- }
- _curSelectId = id;
- RefreshList();
- }
- private void OnClickUpBtn(EventContext eventContext)
- {
- var id = _curSelectId;
- if (_planId == PartnersData.Instance.UsePlanId)
- {
- if (!PartnersData.Instance.TryGetPartnerAttrByTableId(_sbId, out var info))
- {
- Context.ShowTips(StringDefine.PartnerEmptyTips);
- return;
- }
- if (id == info.EpigraphId)
- return;
- EpigraphService.Instance.RequestEpiInset(_sbId, id);
- Context.ClosePanel();
- }
- else if (_planId >= 0 && _slotId >= 0 && _sbId > 0)
- {
- var plan = PartnersData.Instance.GetPlanById(_planId);
- foreach (var slot in plan.PlanValues)
- {
- if (slot.MwId == id)
- {
- Context.ShowTips(StringDefine.EpigraphAlreadyUpTips);
- return;
- }
- }
- PartnersService.Instance.RequestUpdatePlanMw(_planId, _slotId, _sbId, id);
- Context.ClosePanel();
- }
- }
- #endregion
- #region 属性
- private bool _isInit = false;
- /// <summary>
- /// 圣兵id
- /// </summary>
- private int _sbId;
- private int _planId;
- private int _slotId;
- private List<EpiChangeListData> _list;
- private int _curSelectId;
- #endregion
- #region 页面
- private void InitView()
- {
- if (_isInit)
- return;
- _isInit = true;
- VM.List.ListType = EGListType.Virtual;
- }
- private void UpView()
- {
- var epiList = EpigraphData.Instance.EpiList;
- var list = new List<EpiChangeListData>();
- foreach (var epi in epiList)
- {
- list.Add(new EpiChangeListData(_planId, _sbId, epi.TableId));
- }
- _list = list;
- var slot = PartnersData.Instance.GetPlanSlot(_planId, _slotId);
- if (_planId == PartnersData.Instance.UsePlanId)
- {
- if (!PartnersData.Instance.TryGetPartnerAttrByTableId(_sbId, out var attr))
- {
- Log.Error($"圣兵数据不存在,id:{_sbId}");
- return;
- }
- if (attr.EpigraphId > 0)
- {
- _curSelectId = attr.EpigraphId;
- }
- else
- {
- _curSelectId = epiList[0].TableId;
- }
- }
- else
- {
- if (slot == null || slot.MwId == 0)
- {
- _curSelectId = epiList[0].TableId;
- }
- else
- {
- _curSelectId = slot.MwId;
- }
- }
- VM.List.BindDatas(list);
- }
- private void RefreshList()
- {
- var epiList = EpigraphData.Instance.EpiList;
- var list = new List<EpiChangeListData>();
- foreach (var epi in epiList)
- {
- list.Add(new EpiChangeListData(_planId, _sbId, epi.TableId));
- }
- _list = list;
- VM.List.BindDatas(list);
- }
- #endregion
- }
- }
|