ChangeNameView.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using FairyGUI;
  2. using UI.Main;
  3. using System;
  4. using System.Text.RegularExpressions;
  5. using ET;
  6. using System.Threading.Tasks;
  7. namespace GFGGame
  8. {
  9. public class ChangeNameView : BaseWindow
  10. {
  11. private UI_ChangeNameUI _ui;
  12. public override void Dispose()
  13. {
  14. if (_ui != null)
  15. {
  16. _ui.Dispose();
  17. _ui = null;
  18. }
  19. base.Dispose();
  20. }
  21. protected override void OnInit()
  22. {
  23. base.OnInit();
  24. packageName = UI_ChangeNameUI.PACKAGE_NAME;
  25. _ui = UI_ChangeNameUI.Create();
  26. this.viewCom = _ui.target;
  27. this.viewCom.Center();
  28. this.modal = true;
  29. _ui.m_btnSure.onClick.Add(OnClickBtnSureAsync);
  30. }
  31. protected override void OnShown()
  32. {
  33. base.OnShown();
  34. this._ui.m_inputName.text = "";
  35. }
  36. protected override void OnHide()
  37. {
  38. base.OnHide();
  39. }
  40. private void OnClickBtnSureAsync()
  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. string costName = ItemUtil.GetItemName(GlobalCfgArray.globalCfg.changeNameCostArr[0]);
  59. int count = GlobalCfgArray.globalCfg.changeNameCostArr[1];
  60. AlertUI.Show( string .Format("是否花费{0}个{1}改名1次?",count,costName))
  61. .SetLeftButton(true).SetRightButton(true, "确定", async (object data) =>
  62. {
  63. bool result = await RoleInfoSProxy.ReqModifyRoleName(roleName);
  64. if (result)
  65. {
  66. this.Hide();
  67. }
  68. });
  69. }
  70. }
  71. }