/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
using FairyGUI;
using FL.Data;
using XGame;
using XGame.Database;
using XGame.Framework.UI;
namespace FL.FGUI
{
public interface IPartnerReplacePanelCtrl
{
int PlanId { get; }
int SlotId { get; }
int CurSelectId { get; }
}
public class PartnerReplacePartnerListItemCtrlParam
{
public int PartnerId;
public IPartnerReplacePanelCtrl Ctrl;
}
///
/// UI逻辑处理类
///
///
public partial class PartnerReplacePartnerListItemCtrl
: UIController
{
private int _partnerId; // 圣兵的uid
private int _planId; //方案id
private int _slotId;
private int _curSelectedId;
protected override void OnEnable(object intent)
{
AddUIListenres();
}
protected override void OnDisable()
{
RemoveUIListenres();
}
#region UI事件
private void AddUIListenres()
{
VM.PanelEvent.Add(OnClickClickBtn);
}
private void RemoveUIListenres()
{
VM.PanelEvent.Remove(OnClickClickBtn);
}
private void OnClickClickBtn(EventContext context)
{
EventSingle.Instance.Notify(EventDefine.PartnerSelectReplace, _partnerId);
}
#endregion
public void OnRefresh(int index, PartnerReplacePartnerListItemCtrlParam param)
{
_partnerId = param.PartnerId;
_planId = param.Ctrl.PlanId;
_slotId = param.Ctrl.SlotId;
_curSelectedId = param.Ctrl.CurSelectId;
var info = PartnersData.Instance.GetPartnerAttrByTableId(param.PartnerId);
if (info == null)
{
Log.Error($"圣兵数据不存在id:{param.PartnerId}");
return;
}
ShowSelectState();
var plan = PartnersData.Instance.GetPlanById(param.Ctrl.PlanId);
if (plan == null)
{
Log.Error($"方案信息不存在,方案id:{param.Ctrl.PlanId}");
return;
}
var isUp = false;
foreach (var slot in plan.Slots)
{
if (slot.SbId == _partnerId)
{
isUp = true;
break;
}
}
VM.StateCtrl.selectedIndex = isUp ? 1 : 0;
var parterInfo = PartnerTableRepo.Get(param.PartnerId);
VM.NameLabel.text = parterInfo?.Name ?? "";
VM.PartnerItem.Ctrl.ShowUI(_partnerId);
}
public void ShowSelectState()
{
VM.Selected.selectedIndex = _curSelectedId == _partnerId ? 1 : 0;
}
}
}