CreateRoleView.cs 2.0 KB

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