using FairyGUI; using UI.CreateRole; using System; using System.Text.RegularExpressions; using ET; namespace GFGGame { public class CreateRoleView : BaseWindow { private UI_CreateRoleUI _ui; public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } 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.isfullScreen = true; this.clickBlankToClose = false; this.modal = true; _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("bg_yaoqinghan"); _ui.m_btnSure.onClick.Add(OnClickBtnSure); _ui.m_btnDice.onClick.Add(() => { RandomRoleName(); }); } protected override void OnShown() { base.OnShown(); RandomRoleName(); LogServerHelper.SendNodeLog((int)LogNode.ShowCreateRole); } protected override void OnHide() { base.OnHide(); } private async 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; } bool result = await RoleInfoSProxy.ReqModifyRoleName(roleName); if (result) { StorageSProxy.ReqSetClientValue(ConstStorageId.CHANGE_NAME, 1).Coroutine(); this.Hide(); } } private async void RandomRoleName() { string name = await LoginController.ReqRandomRoleName(); _ui.m_inputName.text = name; } } }