NotificationCodeEnterNoConnect.cs 5.0 KB

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