1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- /// #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<string, bool> renameCallback;//改名回调函数
- }
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class CommonRenamePanelCtrl : UIController<CommonRenamePanelVM>
- {
- private bool _bChange;// 是否更改
- private string _rename;
- Action<string, bool> _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);
- }
- }
- }
- }
|