CommonRenamePanelCtrl.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. public struct RenameParam
  12. {
  13. public int limitWordCount; // 限制修改的字数
  14. public string title; // 改名标题
  15. public string tipsDesc; // 提示文本
  16. public Action<string, bool> renameCallback;//改名回调函数
  17. }
  18. /// <summary>
  19. /// UI逻辑处理类
  20. /// </summary>
  21. /// <typeparam name=""></typeparam>
  22. public partial class CommonRenamePanelCtrl : UIController<CommonRenamePanelVM>
  23. {
  24. private bool _bChange;// 是否更改
  25. private string _rename;
  26. Action<string, bool> _renameCallback;
  27. protected override void OnEnable(object intent)
  28. {
  29. AddUIListenres();
  30. ShowUI((RenameParam)intent);
  31. }
  32. protected override void OnDisable()
  33. {
  34. RemoveUIListenres();
  35. if (_renameCallback != null)
  36. {
  37. _renameCallback(_rename, _bChange);
  38. _renameCallback = null;
  39. }
  40. _rename = string.Empty;
  41. VM.Input.text = string.Empty;
  42. }
  43. #region UI事件
  44. private void AddUIListenres()
  45. {
  46. VM.ConfirmBtn.onClick.Add(OnClickConfirmBtn);
  47. }
  48. private void RemoveUIListenres()
  49. {
  50. VM.ConfirmBtn.onClick.Remove(OnClickConfirmBtn);
  51. }
  52. private void OnClickConfirmBtn(EventContext context)
  53. {
  54. _rename = VM.Input.text;
  55. if (_rename.Length > 0)
  56. {
  57. _bChange = true;
  58. Context.ClosePanel();
  59. }
  60. else
  61. {
  62. Context.ShowTips(StringDefine.commonRenameEmpty);
  63. }
  64. }
  65. #endregion
  66. private void ShowUI(RenameParam param)
  67. {
  68. _bChange = false;
  69. _rename = string.Empty;
  70. _renameCallback = param.renameCallback;
  71. if (!string.IsNullOrEmpty(param.title)) VM.PopWin.title = param.title;
  72. if (!string.IsNullOrEmpty(param.tipsDesc)) VM.TipsDescLabel.text = param.tipsDesc;
  73. // 设置最大字数限制
  74. if (param.limitWordCount > 0)
  75. {
  76. VM.Input.maxLength = param.limitWordCount;
  77. VM.Input.promptText = string.Format(StringDefine.commonRenamePrompt, param.limitWordCount);
  78. }
  79. }
  80. }
  81. }