using FairyGUI; using UI.CreateRole; using System; using System.Text.RegularExpressions; namespace GFGGame { public class CreateRoleView : BaseWindow { private UI_CreateRoleUI _ui; public override void Dispose() { base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_CreateRoleUI.PACKAGE_NAME; _ui = UI_CreateRoleUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.clickBlankToClose = false; this.modal = true; _ui.m_btnSure.onClick.Add(OnClickBtnSure); _ui.m_btnDice.onClick.Add(() => { RandomRoleName(); }); } protected override void OnShown() { base.OnShown(); RandomRoleName(); LogServerHelperHttp.SendNodeLog((int)LogNode.ShowCreateRole); } protected override void OnHide() { base.OnHide(); } private void OnClickBtnSure() { string roleName = _ui.m_inputName.text; if (string.IsNullOrEmpty(roleName)) { PromptController.Instance.ShowFloatTextPrompt("角色名不能为空"); return; } if (roleName.Length > GFGGame.GlobalConst.MaxNameLen) { PromptController.Instance.ShowFloatTextPrompt("角色名最多七个字"); return; } if (!Regex.IsMatch(roleName, @"^[\u4e00-\u9fa5_0-9]+$"))//角色起名仅允许汉字、数字、底划线 { PromptController.Instance.ShowFloatTextPrompt("角色名仅允许汉字、数字、下划线"); return; } LoginController.ReqCreateRole(roleName).Coroutine(); } private void RandomRoleName() { _ui.m_inputName.text = RoleDataManager.RandomRoleName(); } } }