LoginInputView.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. }
  30. protected override void OnShown()
  31. {
  32. base.OnShown();
  33. string account = PlayerPrefs.GetString(GameConst.ACCOUNT_LAST_LOGIN_KEY);
  34. if (account != null)
  35. {
  36. _ui.m_inputAccount.text = account;
  37. }
  38. }
  39. protected override void OnHide()
  40. {
  41. base.OnHide();
  42. }
  43. protected override void AddEventListener()
  44. {
  45. base.AddEventListener();
  46. EventAgent.AddEventListener(ConstMessage.LOGIN_FAIL, OnLoginFail);
  47. }
  48. protected override void RemoveEventListener()
  49. {
  50. base.RemoveEventListener();
  51. EventAgent.RemoveEventListener(ConstMessage.LOGIN_FAIL, OnLoginFail);
  52. }
  53. private void OnClickBtnSure()
  54. {
  55. var account = _ui.m_inputAccount.text;
  56. var password = _ui.m_inputPassword.text;
  57. if (string.IsNullOrEmpty(account))
  58. {
  59. PromptController.Instance.ShowFloatTextPrompt("请输入账号");
  60. return;
  61. }
  62. if (!string.IsNullOrEmpty(password))
  63. {
  64. LoginController.Login(account, password).Coroutine();
  65. }
  66. else if (LauncherConfig.netType == LauncherConfig.EnumNetType.LOCAL)
  67. {
  68. LoginController.LoginTest(account).Coroutine();
  69. }
  70. else
  71. {
  72. PromptController.Instance.ShowFloatTextPrompt("请输入密码");
  73. }
  74. }
  75. private void OnClickBtnCancel()
  76. {
  77. this.Hide();
  78. }
  79. //private void OnClickBtnTourist()
  80. //{
  81. // if (GameGlobal.isOfflineVisitor)
  82. // {
  83. // LoginProxy.LoginAsVisitor();
  84. // }
  85. // else
  86. // {
  87. // Alert.Show("游客账号无法保证您的账号安全,且受到充值和时长限制,无法体验全部游戏内容。强烈建议您注册账号登录游戏。")
  88. // .SetLeftButton(true, "进入游戏", (object data) =>
  89. // {
  90. // LoginProxy.LoginAsVisitor();
  91. // })
  92. // .SetRightButton(true, "前往注册", (object data) =>
  93. // {
  94. // ViewManager.Show<RegisterView>();
  95. // })
  96. // .SetClickBlankToClose(true);
  97. // }
  98. //}
  99. private void OnClickBtnRegister()
  100. {
  101. ViewManager.Show<RegisterView>();
  102. }
  103. private void OnLoginFail(EventContext context)
  104. {
  105. string account = (string)context.data;
  106. _ui.m_inputAccount.text = account;
  107. }
  108. }
  109. }