/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
using FairyGUI;
using System;
using XGame.Database;
using XGame.Framework.UI;
namespace FL.FGUI
{
///
/// UI逻辑处理类
///
///
public partial class PlayerPassiveSkillListItemCtrl : UIController
{
private int _index;
private int _passiveSkillId;
private Action _callback;//点击被动技能图标的回调函数
protected override void OnEnable(object intent)
{
AddUIListenres();
}
protected override void OnDisable()
{
RemoveUIListenres();
_callback = null;
_passiveSkillId = 0;
}
#region UI事件
private void AddUIListenres()
{
VM.PassiveSkillBtn.onClick.Add(OnClickBtn);
}
private void RemoveUIListenres()
{
VM.PassiveSkillBtn.onClick.Remove(OnClickBtn);
}
private void OnClickBtn(EventContext context)
{
if (_callback != null)
{
_callback(_passiveSkillId,_index);
}
}
#endregion
public void OnRefresh(int index, JobSkillParam skillParam)
{
_index = index;
//使用默认值来判断结构体是否被初始化
bool bEmpty = skillParam.Equals(default(JobSkillParam));
VM.Ctrl.selectedIndex = bEmpty ? 0 : 1;
if (bEmpty)
{
_callback = null;
_passiveSkillId = 0;
return;
}
_passiveSkillId = skillParam.skillId;
_callback = skillParam.onclickSkillIcon;
var skillInfo = SkillTableRepo.Get(skillParam.skillId);
if (skillInfo != null)
{
VM.PassiveSkillBtn.icon = skillInfo.Icon;
}
}
}
}