ChangeNameView.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using UI.RoleInfo;
  2. using System.Text.RegularExpressions;
  3. namespace GFGGame
  4. {
  5. public class ChangeNameView : BaseWindow
  6. {
  7. private UI_ChangeNameUI _ui;
  8. public override void Dispose()
  9. {
  10. if (_ui != null)
  11. {
  12. _ui.Dispose();
  13. _ui = null;
  14. }
  15. base.Dispose();
  16. }
  17. protected override void OnInit()
  18. {
  19. base.OnInit();
  20. packageName = UI_ChangeNameUI.PACKAGE_NAME;
  21. _ui = UI_ChangeNameUI.Create();
  22. this.viewCom = _ui.target;
  23. this.viewCom.Center();
  24. this.modal = true;
  25. _ui.m_btnSure.onClick.Add(OnClickBtnSureAsync);
  26. }
  27. protected override void OnShown()
  28. {
  29. base.OnShown();
  30. this._ui.m_inputName.text = "";
  31. }
  32. protected override void OnHide()
  33. {
  34. base.OnHide();
  35. }
  36. private void OnClickBtnSureAsync()
  37. {
  38. string roleName = _ui.m_inputName.text;
  39. if (string.IsNullOrEmpty(roleName))
  40. {
  41. PromptController.Instance.ShowFloatTextPrompt("角色名不能为空");
  42. return;
  43. }
  44. if (roleName.Length > GFGGame.GlobalConst.MaxNameLen)
  45. {
  46. PromptController.Instance.ShowFloatTextPrompt("角色名最多七个字");
  47. return;
  48. }
  49. if (!Regex.IsMatch(roleName, @"^[\u4e00-\u9fa5_0-9]+$"))//角色起名仅允许汉字、数字、底划线
  50. {
  51. PromptController.Instance.ShowFloatTextPrompt("角色名仅允许汉字、数字、下划线");
  52. return;
  53. }
  54. string costName = ItemUtil.GetItemName(GlobalCfgArray.globalCfg.changeNameCostArr[0]);
  55. int count = GlobalCfgArray.globalCfg.changeNameCostArr[1];
  56. AlertUI.Show(string.Format("是否花费{0}个{1}改名1次?", count, costName))
  57. .SetLeftButton(true).SetRightButton(true, "确定", async (object data) =>
  58. {
  59. bool result = await RoleInfoSProxy.ReqModifyRoleName(roleName);
  60. if (result)
  61. {
  62. this.Hide();
  63. }
  64. });
  65. }
  66. }
  67. }