123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using UI.RoleInfo;
- using System.Text.RegularExpressions;
- namespace GFGGame
- {
- public class ChangeNameView : BaseWindow
- {
- private UI_ChangeNameUI _ui;
- public override void Dispose()
- {
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_ChangeNameUI.PACKAGE_NAME;
- _ui = UI_ChangeNameUI.Create();
- this.viewCom = _ui.target;
- this.viewCom.Center();
- this.modal = true;
- _ui.m_btnSure.onClick.Add(OnClickBtnSureAsync);
- }
- protected override void OnShown()
- {
- base.OnShown();
- this._ui.m_inputName.text = "";
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- private void OnClickBtnSureAsync()
- {
- 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;
- }
- string costName = ItemUtil.GetItemName(GlobalCfgArray.globalCfg.changeNameCostArr[0]);
- int count = GlobalCfgArray.globalCfg.changeNameCostArr[1];
- AlertUI.Show(string.Format("是否花费{0}个{1}改名1次?", count, costName))
- .SetLeftButton(true).SetRightButton(true, "确定", async (object data) =>
- {
- bool result = await RoleInfoSProxy.ReqModifyRoleName(roleName);
- if (result)
- {
- this.Hide();
- }
- });
- }
- }
- }
|