/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
using FairyGUI;
using FL.Data;
using XGame;
using XGame.Framework.UI;
namespace FL.FGUI
{
///
/// UI逻辑处理类
///
///
public partial class PartnerPartnerUpListItemCtrl : UIController
{
protected override void OnEnable(object intent)
{
AddUIListenres();
}
protected override void OnDisable()
{
RemoveUIListenres();
}
#region UI事件
private void AddUIListenres()
{
VM.PartnerItem.VM.PartnerBase.VM.PanelEvent.Add(OnClickClickBtn);
VM.DownBtn.onClick.Add(OnClickDownBtn);
VM.PartnerItem.VM.EpiSetBase.VM.PanelEvent.Add(OnClickEpiSet);
}
private void RemoveUIListenres()
{
VM.PartnerItem.VM.PartnerBase.VM.PanelEvent.Remove(OnClickClickBtn);
VM.DownBtn.onClick.Remove(OnClickDownBtn);
VM.PartnerItem.VM.EpiSetBase.VM.PanelEvent.Remove(OnClickEpiSet);
}
private void OnClickEpiSet(EventContext eventContext)
{
if (PartnersData.Instance.UpModeSelect > 0)
{
EventSingle.Instance.Notify(EventDefine.PartnerUpModeSelect, _slotId);
}
else
{
var partnerInfo = PartnersData.Instance.GetPartnerAttrByTableId(_sbId);
if (partnerInfo == null)
{
Log.Error($"圣兵数据不存在,id:{_sbId}");
return;
}
Context.UI.OpenAsync(
UIKeys.PartnerEpiChangePanel,
new PartnerEpiChangePanelCtrlParam()
{
PlanId = PartnersData.Instance.UsePlanId,
SlotId = -1,
SbId = _sbId,
}
);
}
}
private void OnClickClickBtn(EventContext context)
{
if (PartnersData.Instance.UpModeSelect > 0)
{
EventSingle.Instance.Notify(EventDefine.PartnerUpModeSelect, _slotId);
}
else if (_sbId > 0)
{
Context.UI.OpenAsync(
UIKeys.PartnerDetailsPanel,
new PartnerDetailsPanelParam()
{
PlanId = PartnersData.Instance.UsePlanId,
SlotId = -1,
PartnerId = _sbId,
}
);
}
else
{
Context.UI.OpenAsync(
UIKeys.PartnerReplacePartnerPanel,
new PartnerReplacePartnerPanelCtrlParam()
{
PlanId = PartnersData.Instance.UsePlanId,
SlotId = _slotId,
}
);
}
}
private void OnClickDownBtn(EventContext context)
{
var slotData = PartnersData.Instance.CurUsePlan.GetSlot(_slotId);
if (slotData.SbId <= 0)
{
Context.ShowTips(StringDefine.PartnerCurSlotNoSbTips);
return;
}
PartnersService.Instance.RequestPartnerDown(slotData.SbId);
}
#endregion
#region 属性
private int _slotId;
private int _sbId;
#endregion
public void OnRefresh(int index, int slotId)
{
_slotId = slotId;
var slotData = PartnersData.Instance.CurUsePlan.GetSlot(slotId);
_sbId = slotData?.SbId ?? 0;
VM.IsUp.selectedIndex = _sbId > 0 ? 0 : 1;
VM.PartnerItem.Ctrl.ShowUI(_sbId);
}
}
}