CreateRoleView.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. if (_ui != null)
  14. {
  15. _ui.Dispose();
  16. _ui = null;
  17. }
  18. base.Dispose();
  19. }
  20. protected override void OnInit()
  21. {
  22. base.OnInit();
  23. packageName = UI_CreateRoleUI.PACKAGE_NAME;
  24. _ui = UI_CreateRoleUI.Create();
  25. this.viewCom = _ui.target;
  26. // this.viewCom.Center();
  27. this.isfullScreen = true;
  28. this.clickBlankToClose = false;
  29. this.modal = true;
  30. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("bg_yaoqinghan");
  31. _ui.m_btnSure.onClick.Add(OnClickBtnSure);
  32. _ui.m_btnDice.onClick.Add(() =>
  33. {
  34. RandomRoleName().Coroutine();
  35. });
  36. }
  37. protected override void OnShown()
  38. {
  39. base.OnShown();
  40. RandomRoleName().Coroutine();
  41. LogServerHelper.SendNodeLog((int)LogNode.ShowCreateRole);
  42. }
  43. protected override void OnHide()
  44. {
  45. base.OnHide();
  46. }
  47. private async void OnClickBtnSure()
  48. {
  49. string roleName = _ui.m_inputName.text;
  50. if (string.IsNullOrEmpty(roleName))
  51. {
  52. PromptController.Instance.ShowFloatTextPrompt("角色名不能为空");
  53. return;
  54. }
  55. if (roleName.Length > GFGGame.GlobalConst.MaxNameLen)
  56. {
  57. PromptController.Instance.ShowFloatTextPrompt("角色名最多七个字");
  58. return;
  59. }
  60. if (!Regex.IsMatch(roleName, @"^[\u4e00-\u9fa5_0-9]+$"))//角色起名仅允许汉字、数字、底划线
  61. {
  62. PromptController.Instance.ShowFloatTextPrompt("角色名仅允许汉字、数字、下划线");
  63. return;
  64. }
  65. bool result = await RoleInfoSProxy.ReqModifyRoleName(roleName);
  66. if (result)
  67. {
  68. StorageSProxy.ReqSetClientValue(ConstStorageId.CHANGE_NAME, 1).Coroutine();
  69. this.Hide();
  70. }
  71. }
  72. private async ETTask RandomRoleName()
  73. {
  74. string name = await LoginController.ReqRandomRoleName();
  75. if(_ui != null && _ui.m_inputName != null)
  76. {
  77. _ui.m_inputName.text = name;
  78. }
  79. }
  80. }
  81. }