LoginInputView.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using UI.Login;
  2. using FairyGUI;
  3. using UnityEngine;
  4. namespace GFGGame
  5. {
  6. public class LoginInputView : BaseWindow
  7. {
  8. private UI_LoginInputUI _ui;
  9. public override void Dispose()
  10. {
  11. if (_ui != null)
  12. {
  13. _ui.Dispose();
  14. _ui = null;
  15. }
  16. base.Dispose();
  17. }
  18. protected override void OnInit()
  19. {
  20. base.OnInit();
  21. packageName = UI_LoginInputUI.PACKAGE_NAME;
  22. _ui = UI_LoginInputUI.Create();
  23. this.viewCom = _ui.target;
  24. this.viewCom.Center();
  25. this.modal = true;
  26. _ui.m_btnSure.onClick.Add(OnClickBtnSure);
  27. _ui.m_btnCancel.onClick.Add(OnClickBtnCancel);
  28. _ui.m_btnRegister.onClick.Add(OnClickBtnRegister);
  29. _ui.m_inputAccount.restrict = "[0-9A-Za-z_]";
  30. if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  31. {
  32. _ui.m_inputPassword.promptText = "[color=#B8A492]当前支持免密登录[/color]";
  33. }
  34. }
  35. protected override void OnShown()
  36. {
  37. base.OnShown();
  38. string account = PlayerPrefs.GetString(GameConst.ACCOUNT_LAST_LOGIN_KEY);
  39. if (account != null)
  40. {
  41. _ui.m_inputAccount.text = account;
  42. }
  43. }
  44. protected override void OnHide()
  45. {
  46. base.OnHide();
  47. }
  48. protected override void AddEventListener()
  49. {
  50. base.AddEventListener();
  51. EventAgent.AddEventListener(ConstMessage.LOGIN_FAIL, OnLoginFail);
  52. }
  53. protected override void RemoveEventListener()
  54. {
  55. base.RemoveEventListener();
  56. EventAgent.RemoveEventListener(ConstMessage.LOGIN_FAIL, OnLoginFail);
  57. }
  58. private void OnClickBtnSure()
  59. {
  60. var account = _ui.m_inputAccount.text;
  61. var password = _ui.m_inputPassword.text;
  62. if (string.IsNullOrEmpty(account))
  63. {
  64. PromptController.Instance.ShowFloatTextPrompt("请输入账号");
  65. return;
  66. }
  67. if (!string.IsNullOrEmpty(password))
  68. {
  69. LoginController.Login(account, password).Coroutine();
  70. }
  71. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  72. {
  73. LoginController.LoginTest(account).Coroutine();
  74. }
  75. else
  76. {
  77. PromptController.Instance.ShowFloatTextPrompt("请输入密码");
  78. }
  79. }
  80. private void OnClickBtnCancel()
  81. {
  82. this.Hide();
  83. }
  84. //private void OnClickBtnTourist()
  85. //{
  86. // if (GameGlobal.isOfflineVisitor)
  87. // {
  88. // LoginProxy.LoginAsVisitor();
  89. // }
  90. // else
  91. // {
  92. // Alert.Show("游客账号无法保证您的账号安全,且受到充值和时长限制,无法体验全部游戏内容。强烈建议您注册账号登录游戏。")
  93. // .SetLeftButton(true, "进入游戏", (object data) =>
  94. // {
  95. // LoginProxy.LoginAsVisitor();
  96. // })
  97. // .SetRightButton(true, "前往注册", (object data) =>
  98. // {
  99. // ViewManager.Show<RegisterView>();
  100. // })
  101. // .SetClickBlankToClose(true);
  102. // }
  103. //}
  104. private void OnClickBtnRegister()
  105. {
  106. ViewManager.Show<RegisterView>();
  107. }
  108. private void OnLoginFail(EventContext context)
  109. {
  110. string account = (string)context.data;
  111. _ui.m_inputAccount.text = account;
  112. }
  113. }
  114. }