/// #pkgName FGUI包名 /// #panelName UIPanel名字 /// #UIName = $"{#pkgName}{#panelName}" UIKey名字 /// 该脚本由模板创建 /// created by cb 2024 using FairyGUI; using System; using XGame.Framework.UI; namespace FL.FGUI { public struct RenameParam { public int limitWordCount; // 限制修改的字数 public string title; // 改名标题 public string tipsDesc; // 提示文本 public Action renameCallback;//改名回调函数 } /// /// UI逻辑处理类 /// /// public partial class CommonRenamePanelCtrl : UIController { private bool _bChange;// 是否更改 private string _rename; Action _renameCallback; protected override void OnEnable(object intent) { AddUIListenres(); ShowUI((RenameParam)intent); } protected override void OnDisable() { RemoveUIListenres(); if (_renameCallback != null) { _renameCallback(_rename, _bChange); _renameCallback = null; } _rename = string.Empty; VM.Input.text = string.Empty; } #region UI事件 private void AddUIListenres() { VM.ConfirmBtn.onClick.Add(OnClickConfirmBtn); } private void RemoveUIListenres() { VM.ConfirmBtn.onClick.Remove(OnClickConfirmBtn); } private void OnClickConfirmBtn(EventContext context) { _rename = VM.Input.text; if (_rename.Length > 0) { _bChange = true; Context.ClosePanel(); } else { Context.ShowTips(StringDefine.commonRenameEmpty); } } #endregion private void ShowUI(RenameParam param) { _bChange = false; _rename = string.Empty; _renameCallback = param.renameCallback; if (!string.IsNullOrEmpty(param.title)) VM.PopWin.title = param.title; if (!string.IsNullOrEmpty(param.tipsDesc)) VM.TipsDescLabel.text = param.tipsDesc; // 设置最大字数限制 if (param.limitWordCount > 0) { VM.Input.maxLength = param.limitWordCount; VM.Input.promptText = string.Format(StringDefine.commonRenamePrompt, param.limitWordCount); } } } }