/// #pkgName FGUI包名
/// #panelName UIPanel名字
/// #UIName = $"{#pkgName}{#panelName}" UIKey名字
/// 该脚本由模板创建
/// created by cb 2024
using FairyGUI;
using System;
using XGame.Framework.UI;
namespace FL.FGUI
{
///
/// UI逻辑处理类
///
///
public partial class GmToolFieldNameListItemCtrl : UIController
{
private Action _changeValueCallback; // 回调函数
protected override void OnEnable(object intent)
{
AddUIListenres();
}
protected override void OnDisable()
{
RemoveUIListenres();
if (_changeValueCallback != null) _changeValueCallback = null;
}
#region UI事件
private void AddUIListenres()
{
VM.FieldValueInput.onFocusOut.Add(OnFocusOut);
}
private void RemoveUIListenres()
{
VM.FieldValueInput.onFocusOut.Remove(OnFocusOut);
}
#endregion
public void OnRefresh(int index, GmToolFieldData data)
{
VM.FieldNameLabel.text = data.filedName;
VM.FieldValueInput.text = string.Empty;
_changeValueCallback = data.changeValueCallback;
}
///
/// 失去焦点事件
///
///
private void OnFocusOut(EventContext context)
{
//XGame.Log.Info($"失去焦点事件,此时输入框的内容:{VM.FieldValueInput.text}");
AlterValue();
}
///
/// 修改字段值
///
private void AlterValue()
{
if (_changeValueCallback != null)
{
_changeValueCallback(new GmFieldParam()
{
fieldName = VM.FieldNameLabel.text,
fieldValue = VM.FieldValueInput.text
});
}
}
}
}