NotificationCodeEnter.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. public class NotificationCodeEnter : MonoBehaviour
  5. {
  6. public ScreenBase WrongCode;
  7. ScreenBase screen;
  8. UILabel label;
  9. public GameObject GoInvite;
  10. public GameObject GoShowAd;
  11. public CapchaCheck Check;
  12. private NGUIMenuScript hNGUIMenuScript;
  13. void Awake()
  14. {
  15. //PlayerPrefs.DeleteAll();
  16. screen = GetComponent<ScreenBase>();
  17. screen.Hide();
  18. NotificationCenter.AddListener(OnShowEnterCode, NotificationType.ShowEnterCode);
  19. }
  20. void OnDestroy()
  21. {
  22. NotificationCenter.RemoveListener(OnShowEnterCode, NotificationType.ShowEnterCode);
  23. }
  24. public void OnShowEnterCode(Notification note)
  25. {
  26. var addLifeStep = PlayerPrefs.GetInt("AddLifeStep", 0);
  27. addLifeStep = 2;
  28. if (addLifeStep == 0)
  29. {
  30. GoInvite.SetActive(true);
  31. GoShowAd.SetActive(false);
  32. NGUIMenuScript.Instance.toggleHUDGroupState(true, true);
  33. }
  34. else if (addLifeStep == 1)
  35. {
  36. GoInvite.SetActive(false);
  37. GoShowAd.SetActive(true);
  38. NGUIMenuScript.Instance.toggleHUDGroupState(true, true);
  39. }
  40. else if (addLifeStep == 2)
  41. {
  42. GoInvite.SetActive(false);
  43. GoShowAd.SetActive(false);
  44. NGUIMenuScript.Instance.toggleHUDGroupState(false, false);
  45. ClickClose();
  46. return;
  47. }
  48. LoginManager.Instance.CurScreenCodeEnter = screen;
  49. screen.Show();
  50. }
  51. public UIInput emailFriend;
  52. public UIInput CodeEnter;
  53. public UIButton Ok;
  54. public UIButton SendInvite;
  55. public UIButton ShowAd;
  56. public UIButton Close;
  57. public UIInput InputMail;
  58. // Use this for initialization
  59. void Start()
  60. {
  61. Ok.onClick.Add(new EventDelegate(ClickOk));
  62. Close.onClick.Add(new EventDelegate(ClickClose));
  63. SendInvite.onClick.Add(new EventDelegate(ClickSendInvite));
  64. ShowAd.onClick.Add(new EventDelegate(ClickShowAd));
  65. hPlayerSidesColliderScriptCS = (PlayerSidesColliderScriptCS)GameObject.Find("PlayerSidesCollider").GetComponent(typeof(PlayerSidesColliderScriptCS));
  66. hPlayerFrontColliderScriptCS = (PlayerFrontColliderScriptCS)GameObject.Find("PlayerFrontCollider").GetComponent(typeof(PlayerFrontColliderScriptCS));
  67. hNGUIMenuScript = (NGUIMenuScript)GameObject.Find("UI Root (2D)").GetComponent(typeof(NGUIMenuScript));
  68. StartCoroutine(AlphaActive());
  69. StartCoroutine(TestAd());
  70. }
  71. bool CheckingMail(string mail)
  72. {
  73. RegexUtilities util = new RegexUtilities();
  74. return util.IsValidEmail(mail);
  75. }
  76. public enum StateGameOver
  77. {
  78. InviteFriends,
  79. ShowAd,
  80. None
  81. }
  82. public StateGameOver CurStateGameOver;
  83. public void ClickSendInvite()
  84. {
  85. Debug.Log("ClickSendInvite");
  86. if (!ConnectivityPollManager.HasInternet)
  87. {
  88. screen.Hide();
  89. LoginManager.Instance.WrongConnectMessages.Show();
  90. NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  91. return;
  92. }
  93. if (ConnectivityPollManager.HasInternet) //register code
  94. {
  95. if (CheckingMail(emailFriend.value))
  96. {
  97. Debug.LogWarning(emailFriend.value);
  98. ServerGiftManager.Instance.SendInviteMailToserv(emailFriend.value, state =>
  99. {
  100. Debug.LogWarning("!!! " +emailFriend.value);
  101. string s2 = state.ToString().Trim('\"');
  102. switch (s2.ToString())
  103. {
  104. case "ok":
  105. LifeManager.AddlifeInviteFriends();
  106. if (LifeManager.Lifes > 0)
  107. {
  108. PlayerPrefs.SetInt("AddLifeStep", 1);
  109. OnDone();
  110. screen.Hide();
  111. Debug.Log(">0");
  112. }
  113. else
  114. {
  115. ClickClose();
  116. Debug.Log("0");
  117. }
  118. Debug.Log("ok");
  119. break;
  120. case "already":
  121. UIMessage.LabelMessage.text = "This email adress is old";
  122. UIMessage.GetComponent<ScreenBase>().Show();
  123. break;
  124. //case "already":
  125. // UIMessage.LabelMessage.text = "This email adress is old";
  126. // UIMessage.GetComponent<ScreenBase>().Show();
  127. // break;
  128. }
  129. Debug.LogWarning(state);
  130. });
  131. }
  132. else
  133. {
  134. UIMessage.LabelMessage.text = "Not correct email adress";
  135. UIMessage.GetComponent<ScreenBase>().Show();
  136. }
  137. }
  138. }
  139. private void ClickShowAd()
  140. {
  141. AdManager.Instance.PlayVideoAd();
  142. }
  143. private IEnumerator TestAd()
  144. {
  145. yield return new WaitForSeconds(10);
  146. //Check.GetComponent<UIPanel>().alpha = 1;
  147. }
  148. private IEnumerator AlphaActive()
  149. {
  150. yield return new WaitForSeconds(0.5f);
  151. GetComponent<UIPanel>().alpha = 1;
  152. //Check.GetComponent<UIPanel>().alpha = 1;
  153. }
  154. private void ClickClose()
  155. {
  156. NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.GameOver);
  157. NGUIMenuScript.Instance.CurStatePopup = NGUIMenuScript.StatesMenuForPopup.GameOver;
  158. screen.Hide();
  159. var distance = (int)ControllerScriptCS.Instance.getCurrentMileage();
  160. var gifts = PowerupsMainControllerCS.Instance.getCurrencyUnits();
  161. var score = (int)(ControllerScriptCS.Instance.getCurrentMileage() + (PowerupsMainControllerCS.Instance.getCurrencyUnits() * 3) + TooltipLastterController.Instance.PontWords);
  162. //FlurryLogger.Instance.GameFinish(distance, gifts, score);
  163. if (KHD.FlurryAnalyticsTest.Instance)
  164. {
  165. KHD.FlurryAnalyticsTest.Instance.GameFinish(distance, gifts, score);
  166. }
  167. }
  168. public void EnterDoneCaptcha()
  169. {
  170. Debug.Log("EnterDoneCaptcha");
  171. transform.position = new Vector3(transform.position.x, 0, transform.position.z);
  172. }
  173. public void EnterCaptcha()
  174. {
  175. transform.position = new Vector3(transform.position.x, 77, transform.position.z);
  176. }
  177. void OnEnable()
  178. {
  179. var day = DateTime.Now;
  180. var saveDate = PlayerPrefs.GetInt("OldDate", 0);
  181. if (saveDate == 0)
  182. {
  183. saveDate = DateTime.Now.Day;
  184. PlayerPrefs.SetInt("OldDate", saveDate);
  185. }
  186. else
  187. {
  188. if (saveDate != day.Day)
  189. {
  190. PlayerPrefs.SetInt("AddLifeStep", 0);
  191. PlayerPrefs.SetInt("OldDate", day.Day);
  192. }
  193. }
  194. PlayerPrefs.Save();
  195. CodeEnter.text = "Fyll i kod...";
  196. emailFriend.text = "";
  197. StartCoroutine(AlphaActive());
  198. }
  199. private bool DoneCaptcha;
  200. private bool DoneCode;
  201. public PlayerSidesColliderScriptCS hPlayerSidesColliderScriptCS { get; private set; }
  202. public PlayerFrontColliderScriptCS hPlayerFrontColliderScriptCS { get; private set; }
  203. public CheckBoxConditionsHandler CheckBoxConditionsHandler;
  204. public MessageCodeCap UIMessage;
  205. private void ClickOk()
  206. {
  207. NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  208. if (!ConnectivityPollManager.HasInternet)
  209. {
  210. screen.Hide();
  211. LoginManager.Instance.WrongConnectMessages.Show();
  212. NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  213. return;
  214. }
  215. if (Check.Check(emailFriend.value))
  216. {
  217. Debug.LogWarning("capcha ok");
  218. }
  219. else
  220. {
  221. Debug.LogWarning("capcha fail");
  222. }
  223. if (Check.Check(emailFriend.value))
  224. {
  225. if (ConnectivityPollManager.HasInternet) //register code
  226. {
  227. RegisterCodeMIX.Instance.Activate(CodeEnter.text, (state, s) =>
  228. {
  229. Debug.Log(state + CodeEnter.text);
  230. switch (state)
  231. {
  232. case RegisterCodeMIX.ActivateStates.OtherError:
  233. screen.Hide();
  234. NotificationCenter.Post(NotificationType.ShowEnterWrong);
  235. NGUIMenuScript.Instance.WrongCodeCap = true;
  236. //todo: handle error
  237. break;
  238. case RegisterCodeMIX.ActivateStates.RequestOrNetworkError:
  239. screen.Hide();
  240. NotificationCenter.Post(NotificationType.ShowInternetWrong);
  241. NGUIMenuScript.Instance.WrongCodeCap = true;
  242. //todo: handle error
  243. break;
  244. case RegisterCodeMIX.ActivateStates.CouponAlreadyReedemed:
  245. screen.Hide();
  246. NotificationCenter.Post(NotificationType.ShowEnterWrong);
  247. NGUIMenuScript.Instance.WrongCodeCap = true;
  248. //todo: handle error
  249. break;
  250. case RegisterCodeMIX.ActivateStates.BadInput:
  251. screen.Hide();
  252. NotificationCenter.Post(NotificationType.ShowEnterWrong);
  253. NGUIMenuScript.Instance.WrongCodeCap = true;
  254. //todo: handle error
  255. break;
  256. case RegisterCodeMIX.ActivateStates.Done:
  257. Debug.Log(RegisterCodeMIX.ActivateStates.Done);
  258. //LoginManager.Instance.CountEnterCode++;
  259. OnDone();
  260. //todo: EVERYTHING GOES WELL
  261. break;
  262. }
  263. Debug.Log(state);
  264. NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  265. });
  266. }
  267. else
  268. {
  269. NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  270. screen.Hide();
  271. }
  272. }
  273. else
  274. {
  275. NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  276. }
  277. }
  278. void OnDone()
  279. {
  280. UIEnergy.Instance.Restore();
  281. PlayerController.Instance.Alive();
  282. InGameScriptCS.Instance.InvokeResurrection();
  283. InGameScriptCS.Instance.EnergyAdd(100);
  284. hPlayerSidesColliderScriptCS.InvokeResurrection();
  285. hPlayerFrontColliderScriptCS.InvokeResurrection();
  286. ControllerScriptCS.Instance.bControlsEnabled = true;
  287. InGameScriptCS.Instance.Resurected = false;
  288. screen.Hide();
  289. Text_PauseCounter.Show();
  290. }
  291. }