123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- /// #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 PartnerReplacePartnerPanelCtrlParam
- {
- public int PlanId;
- public int SlotId;
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class PartnerReplacePartnerPanelCtrl
- : UIController<PartnerReplacePartnerPanelVM>,
- IPartnerReplacePanelCtrl
- {
- private int _planId;
- private int _slotId;
- private int _curSelectId;
- public int PlanId => _planId;
- public int SlotId => _slotId;
- public int CurSelectId => _curSelectId;
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- AddEventListener();
- ShowUI(intent as PartnerReplacePartnerPanelCtrlParam);
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- RemoveEventListener();
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.UpBtn.onClick.Add(OnClickUpPartner);
- }
- private void RemoveUIListenres()
- {
- VM.UpBtn.onClick.Remove(OnClickUpPartner);
- }
- private void OnClickUpPartner(EventContext context)
- {
- if (_curSelectId <= 0)
- {
- Log.Error("当前选择圣兵id为0");
- return;
- }
- var plan = PartnersData.Instance.GetPlanById(_planId);
- if (plan == null)
- {
- Log.Error($"方案信息不存在id: {_planId}");
- return;
- }
- foreach (var slot in plan.Slots)
- {
- if (slot.SbId == CurSelectId)
- {
- Context.ShowTips(StringDefine.PartnerAlreadyUpTips);
- return;
- }
- }
- Context.ClosePanel();
- if (_planId == PartnersData.Instance.UsePlanId)
- {
- PartnersService.Instance.RequestPartnerUp(_slotId, _curSelectId);
- }
- else
- {
- PartnersService.Instance.RequestUpdatePlanSb(_planId, _slotId, _curSelectId);
- }
- }
- #endregion
- private void AddEventListener()
- {
- EventSingle.Instance.AddListener(
- EventDefine.PartnerSelectReplace,
- SelectReplacePartner
- );
- EventSingle.Instance.AddListener(EventDefine.PartnerBinding, OnInfoUpdate);
- EventSingle.Instance.AddListener(EventDefine.PartnerUp, OnInfoUpdate);
- EventSingle.Instance.AddListener(EventDefine.PartnerDown, OnInfoUpdate);
- EventSingle.Instance.AddListener(EventDefine.PartnerUpdatePlan, OnInfoUpdate);
- }
- private void RemoveEventListener()
- {
- EventSingle.Instance.RemoveListener(
- EventDefine.PartnerSelectReplace,
- SelectReplacePartner
- );
- EventSingle.Instance.RemoveListener(EventDefine.PartnerBinding, OnInfoUpdate);
- EventSingle.Instance.RemoveListener(EventDefine.PartnerUp, OnInfoUpdate);
- EventSingle.Instance.RemoveListener(EventDefine.PartnerDown, OnInfoUpdate);
- EventSingle.Instance.RemoveListener(EventDefine.PartnerUpdatePlan, OnInfoUpdate);
- }
- private void OnInfoUpdate(int eventId, object args)
- {
- UpdateList();
- }
- private void SelectReplacePartner(int eventId, object args)
- {
- var id = (int)args;
- if (id == _curSelectId)
- {
- Context.UI.OpenAsync(
- UIKeys.PartnerDetailsPanel,
- new PartnerDetailsPanelParam()
- {
- PlanId = _planId,
- SlotId = _slotId,
- PartnerId = _curSelectId,
- }
- );
- Context.ClosePanel();
- return;
- }
- _curSelectId = id;
- UpdateList();
- }
- private void ShowUI(PartnerReplacePartnerPanelCtrlParam param)
- {
- _slotId = param.SlotId;
- _planId = param.PlanId;
- var slot = PartnersData.Instance.GetPlanSlot(_planId, _slotId);
- var list = PartnersData.Instance.PartnerList;
- if (list.Count <= 0)
- {
- Log.Error($"圣兵库内不存在圣兵");
- return;
- }
- var sbId = slot?.SbId ?? 0;
- _curSelectId = sbId > 0 ? sbId : list[0].TableId;
- UpdateList();
- }
- private void UpdateList()
- {
- var list = PartnersData.Instance.PartnerList;
- var datas = new List<PartnerReplacePartnerListItemCtrlParam>();
- foreach (var partner in list)
- {
- datas.Add(
- new PartnerReplacePartnerListItemCtrlParam()
- {
- PartnerId = partner.TableId,
- Ctrl = this,
- }
- );
- }
- VM.PartnerList.BindDatas(datas);
- }
- }
- }
|