GmToolFieldNameListItemCtrl.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using System;
  8. using XGame.Framework.UI;
  9. namespace FL.FGUI
  10. {
  11. /// <summary>
  12. /// UI逻辑处理类
  13. /// </summary>
  14. /// <typeparam name=""></typeparam>
  15. public partial class GmToolFieldNameListItemCtrl : UIController<GmToolFieldNameListItemVM>
  16. {
  17. private Action<GmFieldParam> _changeValueCallback; // 回调函数
  18. protected override void OnEnable(object intent)
  19. {
  20. AddUIListenres();
  21. }
  22. protected override void OnDisable()
  23. {
  24. RemoveUIListenres();
  25. if (_changeValueCallback != null) _changeValueCallback = null;
  26. }
  27. #region UI事件
  28. private void AddUIListenres()
  29. {
  30. VM.FieldValueInput.onFocusOut.Add(OnFocusOut);
  31. }
  32. private void RemoveUIListenres()
  33. {
  34. VM.FieldValueInput.onFocusOut.Remove(OnFocusOut);
  35. }
  36. #endregion
  37. public void OnRefresh(int index, GmToolFieldData data)
  38. {
  39. VM.FieldNameLabel.text = data.filedName;
  40. VM.FieldValueInput.text = string.Empty;
  41. _changeValueCallback = data.changeValueCallback;
  42. }
  43. /// <summary>
  44. /// 失去焦点事件
  45. /// </summary>
  46. /// <param name="context"></param>
  47. private void OnFocusOut(EventContext context)
  48. {
  49. //XGame.Log.Info($"失去焦点事件,此时输入框的内容:{VM.FieldValueInput.text}");
  50. AlterValue();
  51. }
  52. /// <summary>
  53. /// 修改字段值
  54. /// </summary>
  55. private void AlterValue()
  56. {
  57. if (_changeValueCallback != null)
  58. {
  59. _changeValueCallback(new GmFieldParam()
  60. {
  61. fieldName = VM.FieldNameLabel.text,
  62. fieldValue = VM.FieldValueInput.text
  63. });
  64. }
  65. }
  66. }
  67. }