NotificationCodeEnterWrong.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using UnityEngine;
  2. using System.Collections;
  3. public class NotificationCodeEnterWrong : MonoBehaviour {
  4. ScreenBase screen;
  5. UILabel label;
  6. public CapchaCheck Check;
  7. public ScreenBase ScreenMessageBase;
  8. private UILabel messageCodeCap;
  9. void Awake()
  10. {
  11. messageCodeCap = ScreenMessageBase.GetComponent<MessageCodeCap>().LabelMessage;
  12. screen = GetComponent<ScreenBase>();
  13. screen.Hide();
  14. NotificationCenter.AddListener(OnShowEnterWrong, NotificationType.ShowEnterWrong);
  15. }
  16. void OnDestroy()
  17. {
  18. NotificationCenter.RemoveListener(OnShowEnterWrong, NotificationType.ShowEnterWrong);
  19. }
  20. public void OnShowEnterWrong(Notification note)
  21. {
  22. LoginManager.Instance.CurScreenCodeEnter = screen;
  23. screen.Show();
  24. }
  25. public UIInput Captcha;
  26. public UIInput CodeEnter;
  27. void OnEnable()
  28. {
  29. CodeEnter.text = "Fyll i kod...";
  30. Captcha.text = "";
  31. StartCoroutine(AlphaActive());
  32. }
  33. public UIButton Ok;
  34. public UIButton Close;
  35. private PlayerFrontColliderScriptCS hPlayerFrontColliderScriptCS;
  36. private PlayerSidesColliderScriptCS hPlayerSidesColliderScriptCS;
  37. private bool DoneCaptcha;
  38. private bool DoneCode;
  39. void Start()
  40. {
  41. Ok.onClick.Add(new EventDelegate(ClickOk));
  42. hPlayerSidesColliderScriptCS = (PlayerSidesColliderScriptCS)GameObject.Find("PlayerSidesCollider").GetComponent(typeof(PlayerSidesColliderScriptCS));
  43. hPlayerFrontColliderScriptCS = (PlayerFrontColliderScriptCS)GameObject.Find("PlayerFrontCollider").GetComponent(typeof(PlayerFrontColliderScriptCS));
  44. StartCoroutine(AlphaActive());
  45. }
  46. private IEnumerator AlphaActive()
  47. {
  48. yield return new WaitForSeconds(0.5f);
  49. GetComponent<UIPanel>().alpha = 1;
  50. //Check.GetComponent<UIPanel>().alpha = 1;
  51. }
  52. public CheckBoxConditionsHandler CheckBoxConditionsHandler;
  53. private void ClickOk()
  54. {
  55. NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  56. if (!ConnectivityPollManager.HasInternet)
  57. {
  58. screen.Hide();
  59. LoginManager.Instance.WrongConnectMessages.Show();
  60. NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  61. return;
  62. }
  63. if (Check.Check(Captcha.value))
  64. {
  65. Debug.LogWarning("capcha ok");
  66. }
  67. else
  68. {
  69. Debug.LogWarning("capcha fail");
  70. }
  71. if (CodeColaCaptchaManager.Instance.CheckingCode(CodeEnter.text.ToUpper()) && CodeColaCaptchaManager.Instance.CheckingCaptcha(Captcha.text) && Check.Check(Captcha.value))
  72. {
  73. if (ConnectivityPollManager.HasInternet) //register code
  74. {
  75. RegisterCodeMIX.Instance.Activate(CodeEnter.text,(state, s) =>
  76. {
  77. switch (state)
  78. {
  79. case RegisterCodeMIX.ActivateStates.OtherError:
  80. // screen.Hide();
  81. // NotificationCenter.Post(NotificationType.ShowEnterWrong);
  82. messageCodeCap.text = "Okänt fel";
  83. ScreenMessageBase.Show();
  84. CodeEnter.text = "Fyll i kod...";
  85. Captcha.text = "";
  86. //todo: handle error
  87. break;
  88. case RegisterCodeMIX.ActivateStates.RequestOrNetworkError:
  89. NotificationCenter.Post(NotificationType.ShowInternetWrong);
  90. screen.Hide();
  91. //todo: handle error
  92. break;
  93. case RegisterCodeMIX.ActivateStates.CouponAlreadyReedemed:
  94. messageCodeCap.text = "Ogiltig kod";
  95. ScreenMessageBase.Show();
  96. CodeEnter.text = "Fyll i kod...";
  97. Captcha.text = "";
  98. //todo: handle error
  99. break;
  100. case RegisterCodeMIX.ActivateStates.BadInput:
  101. messageCodeCap.text = "Ogiltig kod";
  102. ScreenMessageBase.Show();
  103. CodeEnter.text = "Fyll i kod...";
  104. Captcha.text = "";
  105. // screen.Hide();
  106. // NotificationCenter.Post(NotificationType.ShowEnterWrong);
  107. //todo: handle error
  108. break;
  109. case RegisterCodeMIX.ActivateStates.Done:
  110. Debug.Log(RegisterCodeMIX.ActivateStates.Done);
  111. OnDone();
  112. //todo: EVERYTHING GOES WELL
  113. break;
  114. }
  115. Debug.Log(state);
  116. NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  117. });
  118. }
  119. else
  120. {
  121. screen.Hide();
  122. NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  123. }
  124. }
  125. else
  126. {
  127. NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  128. }
  129. }
  130. void OnDone()
  131. {
  132. LifeManager.BottleCap();
  133. UIEnergy.Instance.Restore();
  134. PlayerController.Instance.Alive();
  135. InGameScriptCS.Instance.InvokeResurrection();
  136. InGameScriptCS.Instance.EnergyAdd(100);
  137. hPlayerSidesColliderScriptCS.InvokeResurrection();
  138. hPlayerFrontColliderScriptCS.InvokeResurrection();
  139. ControllerScriptCS.Instance.bControlsEnabled = true;
  140. InGameScriptCS.Instance.Resurected = false;
  141. screen.Hide();
  142. }
  143. }