PopLoginBase.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using ShadowKit;
  6. using Engine.Http;
  7. using System.Text.RegularExpressions;
  8. public class PopLoginBase : PopBase
  9. {
  10. protected override void Start() {
  11. }
  12. public override void Show(object data)
  13. {
  14. base.Show(data);
  15. AccountText = GameDataSetting.Instance.DefaultUserAccount;
  16. PasswordText = GameDataSetting.Instance.DefaultUserPassword;
  17. }
  18. protected virtual string AccountText { get; set; }
  19. protected virtual string PasswordText { get; set; }
  20. protected virtual string CodeText { get; set; }
  21. protected void LoginClick()
  22. {
  23. if(isLoading)
  24. {
  25. return;
  26. }
  27. isLoading = true;
  28. GameDataSetting.Instance.DefaultUserAccount = AccountText;
  29. GameDataSetting.Instance.DefaultUserPassword = PasswordText;
  30. string pattern = @"\s";
  31. AccountText = Regex.Replace(AccountText, pattern, "");
  32. PasswordText = Regex.Replace(PasswordText, pattern, "");
  33. HttpStaticMessage.SendHttpLogin(AccountText, PasswordText, CodeText, HttpDataBackOK);
  34. HideKeyBoard();
  35. }
  36. protected void VisitorLogin()
  37. {
  38. Hide();
  39. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_POP_BY_TYPE, new ShowPopData(PopType.DeviceLogin, null));
  40. //SendVistorLogin();
  41. }
  42. protected virtual void Update()
  43. {
  44. if(Input.GetKeyDown(KeyCode.A))
  45. {
  46. SendVistorLogin();
  47. }
  48. }
  49. protected void SendVistorLogin()
  50. {
  51. /*
  52. if (!GameCenterManager.Instance.NetIsAble)
  53. {
  54. MessageCenter.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "网络断开");
  55. return;
  56. }
  57. */
  58. if (isLoading)
  59. {
  60. return;
  61. }
  62. isLoading = true;
  63. if (CheckNameSafe())
  64. {
  65. HttpStaticMessage.HttpVisitorLogin(AccountText, HttpDataBackOK);
  66. HideKeyBoard();
  67. }
  68. else
  69. {
  70. isLoading = false;
  71. }
  72. }
  73. protected void RegisterClick()
  74. {
  75. }
  76. protected virtual void HideKeyBoard()
  77. {
  78. }
  79. private bool CheckNameSafe()
  80. {
  81. if (AccountText.Length == 0)
  82. {
  83. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "游客ID不能为空");
  84. return false;
  85. }
  86. if (AccountText.Length > GameEnum.VISTOR_NAME_MAX_LENGHT)
  87. {
  88. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_MSG_POP, "游客ID字符超过" + GameEnum.VISTOR_NAME_MAX_LENGHT);
  89. return false;
  90. }
  91. return true;
  92. }
  93. private bool isLoading;
  94. private void HttpDataBackOK(HttpResponse backHttpResponse)
  95. {
  96. isLoading = false;
  97. //必须是执行成功
  98. if (backHttpResponse.isSuccess)
  99. {
  100. this.Hide();
  101. if (backHttpResponse.Code == MsgConst.HTTP_MSG_AUTO_LOGIN)
  102. {
  103. GamePlayerData.Instance.user_name = AccountText;
  104. }
  105. MessageCenterController.Instance.Broadcast(GameEnum.MESSAGE_SHOW_POP_BY_TYPE, new ShowPopData(PopType.ServerList, null));
  106. }
  107. }
  108. }