CreateRoleView.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using FairyGUI;
  2. using UI.CreateRole;
  3. using System;
  4. using System.Text.RegularExpressions;
  5. using ET;
  6. namespace GFGGame
  7. {
  8. public class CreateRoleView : BaseWindow
  9. {
  10. private UI_CreateRoleUI _ui;
  11. public override void Dispose()
  12. {
  13. base.Dispose();
  14. }
  15. protected override void OnInit()
  16. {
  17. base.OnInit();
  18. packageName = UI_CreateRoleUI.PACKAGE_NAME;
  19. _ui = UI_CreateRoleUI.Create();
  20. this.viewCom = _ui.target;
  21. this.viewCom.Center();
  22. this.clickBlankToClose = false;
  23. this.modal = true;
  24. _ui.m_btnSure.onClick.Add(OnClickBtnSure);
  25. _ui.m_btnDice.onClick.Add(() =>
  26. {
  27. RandomRoleName();
  28. });
  29. }
  30. protected override void OnShown()
  31. {
  32. base.OnShown();
  33. RandomRoleName();
  34. LogServerHelperHttp.SendNodeLog((int)LogNode.ShowCreateRole);
  35. }
  36. protected override void OnHide()
  37. {
  38. base.OnHide();
  39. }
  40. private void OnClickBtnSure()
  41. {
  42. string roleName = _ui.m_inputName.text;
  43. if (string.IsNullOrEmpty(roleName))
  44. {
  45. PromptController.Instance.ShowFloatTextPrompt("角色名不能为空");
  46. return;
  47. }
  48. if (roleName.Length > GFGGame.GlobalConst.MaxNameLen)
  49. {
  50. PromptController.Instance.ShowFloatTextPrompt("角色名最多七个字");
  51. return;
  52. }
  53. if (!Regex.IsMatch(roleName, @"^[\u4e00-\u9fa5_0-9]+$"))//角色起名仅允许汉字、数字、底划线
  54. {
  55. PromptController.Instance.ShowFloatTextPrompt("角色名仅允许汉字、数字、下划线");
  56. return;
  57. }
  58. LoginController.ReqCreateRole(roleName).Coroutine();
  59. }
  60. private async void RandomRoleName()
  61. {
  62. string name = await LoginHelper.ReqRandomRoleName();
  63. _ui.m_inputName.text = name;
  64. }
  65. }
  66. }