EnterMailTelephoneButtonHundler.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. public class EnterMailTelephoneButtonHundler : MonoBehaviour
  5. {
  6. public UIInput Telephone;
  7. public UIInput MailAdress;
  8. public UILabel ErrorMail;
  9. public CheckBoxConditionsHandler CheckBoxConditionsHandler;
  10. public ScreenBase ScreenError;
  11. public UILabel MessasageError;
  12. public UIButton Ok;
  13. private string PhoneCodeCountryDenmark = "45";
  14. private string PhoneCodeCountryUkraine = "38";
  15. private string PhoneCodeCountryIceland = "354";
  16. // Use this for initialization
  17. void Start () {
  18. //PlayerPrefs.SetInt("GetCoupon", 0);
  19. Ok.onClick.Add(new EventDelegate(ClickOk));
  20. if (Telephone != null)
  21. {
  22. if (Telephone.GetComponent<UIButton>())
  23. {
  24. Telephone.GetComponent<UIButton>().onClick.Add(new EventDelegate(CheckMail));
  25. }
  26. }
  27. if (MailAdress != null )
  28. {
  29. if (MailAdress.GetComponent<UIButton>())
  30. {
  31. MailAdress.GetComponent<UIButton>().onClick.Add(new EventDelegate(CheckTelephone));
  32. }
  33. }
  34. }
  35. private void CheckTelephone()
  36. {
  37. if (Telephone.text == "Telefonnummer..." || Telephone.text == "")
  38. return;
  39. Debug.Log("CheckTelephone");
  40. if (!ChekingTelephone(Telephone.text))
  41. {
  42. Telephone.text = "Telefonnummer...";
  43. MessasageError.text = "Ogiltigt telefonnummer";
  44. ScreenError.Show();
  45. }
  46. }
  47. private void CheckMail()
  48. {
  49. if (MailAdress.text == "Mailadress..." || MailAdress.text == "")
  50. return;
  51. if (!CheckingMail(MailAdress.text))
  52. {
  53. MailAdress.text = "Mailadress...";
  54. MessasageError.text = "Ogiltig e-post";
  55. ScreenError.Show();
  56. }
  57. }
  58. void OnEnable()
  59. {
  60. Telephone.text = "Telefonnummer...";
  61. if (TelephoneEnter)
  62. {
  63. //Telephone.text = "Telefonnummer...";
  64. }
  65. else
  66. {
  67. //Telephone.text = "Telefonnummer...";
  68. //MailAdress.text = "Mailadress...";
  69. ErrorMail.gameObject.SetActive(false);
  70. }
  71. }
  72. private bool DoneMail;
  73. private bool DonePhone;
  74. public bool TelephoneEnter;
  75. public bool NoConnect;
  76. private void ClickOk()
  77. {
  78. if (NoConnect)
  79. {
  80. }
  81. else
  82. {
  83. if (TelephoneEnter)
  84. {
  85. if (ChekingTelephone(Telephone.text))
  86. {
  87. // Debug.Log("Telephone success");
  88. }
  89. else
  90. {
  91. if (transform.name == "CouponPopupWrongNumber")
  92. {
  93. }
  94. else
  95. {
  96. if (NGUIMenuScript.Instance.CurStatePopup == NGUIMenuScript.StatesMenuForPopup.StartMenu)
  97. {
  98. LoginManager.Instance.StartNoNumberCompetitions = true;
  99. }
  100. LoginManager.Instance.WrongNumberPhone.Show();
  101. NGUIMenuScript.Instance.CurState = NGUIMenuScript.StatePopupGetCouponeGameOver.WrongNumber;
  102. if (Ok.transform.parent.name == "CouponPopup")
  103. {
  104. GetComponent<ScreenBase>().Hide();
  105. }
  106. else
  107. {
  108. LoginManager.Instance.WrongMessages.GetComponent<MessageCodeCap>().LabelMessage.text = "Ogiltigt telefonnummer";
  109. LoginManager.Instance.WrongMessages.Show();
  110. }
  111. }
  112. return;
  113. }
  114. if (CheckBoxConditionsHandler.Check)
  115. {
  116. }
  117. if (ChekingTelephone(Telephone.text) && CheckBoxConditionsHandler.Check)
  118. {
  119. switch (LoginManager.Instance.CurStateCountryCodePhone)
  120. {
  121. case LoginManager.StateCountryTelephoneCode.Danmark:
  122. Telephone.text = PhoneCodeCountryDenmark + Telephone.text;
  123. break;
  124. case LoginManager.StateCountryTelephoneCode.Ukraine:
  125. Telephone.text = PhoneCodeCountryUkraine + Telephone.text;
  126. break;
  127. case LoginManager.StateCountryTelephoneCode.Iceland:
  128. Telephone.text = PhoneCodeCountryIceland + Telephone.text;
  129. break;
  130. }
  131. onDonePhone();
  132. Debug.LogWarning("Phone " + Telephone.text);
  133. PlayerPrefs.SetString("NumberPhone", Telephone.text);
  134. PlayerPrefs.Save();
  135. //ServerGiftManager.Instance.RegisterPhone(Telephone.text, states => onDonePhone());
  136. GetComponent<ScreenBase>().Hide();
  137. if (PlayerPrefs.GetInt("LevelDone", 0) == 1)
  138. {
  139. LoginManager.Instance.PopupLifeEndMessages.Show();
  140. PlayerPrefs.SetInt("LevelDone", 2);
  141. }
  142. }
  143. }
  144. else
  145. {
  146. if (CheckingMail(MailAdress.text))
  147. {
  148. RegistrationManager.Instance.Mail = MailAdress.text;
  149. }
  150. else
  151. {
  152. MailAdress.text = "Mailadress...";
  153. MessasageError.text = "Ogiltig e-post";
  154. ScreenError.Show();
  155. return;
  156. }
  157. if (ChekingTelephone(Telephone.text))
  158. {
  159. RegistrationManager.Instance.Number = Telephone.text;
  160. // Debug.Log("Telephone success");
  161. }
  162. else
  163. {
  164. if (NGUIMenuScript.Instance.CurStatePopup == NGUIMenuScript.StatesMenuForPopup.StartMenu)
  165. {
  166. LoginManager.Instance.StartNoNumberCompetitions = true;
  167. }
  168. //LoginManager.Instance.WrongNumberPhone.Show();
  169. NGUIMenuScript.Instance.CurState = NGUIMenuScript.StatePopupGetCouponeGameOver.WrongNumber;
  170. GetComponent<ScreenBase>().Hide();
  171. Telephone.text = "Telefonnummer...";
  172. MessasageError.text = "Ogiltigt telefonnummer";
  173. ScreenError.Show();
  174. }
  175. if (CheckBoxConditionsHandler.Check)
  176. {
  177. Debug.Log("Check success");
  178. }
  179. if (CheckingMail(MailAdress.text) && ChekingTelephone(Telephone.text) && CheckBoxConditionsHandler.Check)
  180. {
  181. //ServerGiftManager.Instance.FullRegistration(RegistrationManager.Instance.CurName, Telephone.text, MailAdress.text, states => onDonePhone());
  182. if (NGUIMenuScript.Instance.CurStatePopup == NGUIMenuScript.StatesMenuForPopup.StartMenu)
  183. {
  184. GetComponent<ScreenBase>().Hide();
  185. }
  186. else
  187. {
  188. LoginManager.Instance.LoginOpen = false;
  189. var top = GameObject.Find("fbTOP100").GetComponent<fbtop>();
  190. var distance = PlayerControllerLevels.Instance.AllDistance;
  191. var gifts = PlayerControllerLevels.Instance.AllGifts;
  192. top.AddScore(distance, gifts,TooltipLastterController.Instance.PontWords);
  193. NGUIMenuScript.Instance.CurStatePopup = NGUIMenuScript.StatesMenuForPopup.Popup;
  194. //NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  195. //NGUIMenuScript.Instance.StartCoroutine(NGUIMenuScript.Instance.LoadingIndicatorOff());
  196. NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.LeaderBoardNew);
  197. NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.GameOver);
  198. }
  199. }
  200. }
  201. }
  202. }
  203. private void onDonePhone()
  204. {
  205. if (TelephoneEnter)
  206. {
  207. ServerGiftManager.Instance.ConsumeToken();
  208. ServerGiftManager.Instance.SendCoupon(Telephone.text,(done, message, errorCode) =>
  209. {
  210. if (done)
  211. {
  212. //GetComponent<ButtonWithTwoStates>().DeactivateButton();
  213. //NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.SendCoupone);
  214. foreach (var b in LoginManager.Instance.ButtonsCoupon)
  215. {
  216. if (b.gameObject.activeSelf)
  217. {
  218. b.DeactivateButton();
  219. }
  220. }
  221. PlayerPrefs.SetInt("CloseEnterNumber", 0);
  222. PlayerPrefs.SetInt("GetCoupon", 0);
  223. PlayerPrefs.SetInt("giftNum", 0);
  224. LoginManager.Instance.ScreenSendSmsMessages.Show();
  225. if (NGUIMenuScript.Instance.CurStatePopup == NGUIMenuScript.StatesMenuForPopup.GameOver)
  226. {
  227. }
  228. else if (NGUIMenuScript.Instance.CurStatePopup == NGUIMenuScript.StatesMenuForPopup.Menu)
  229. {
  230. }
  231. else
  232. {
  233. LoginManager.Instance.OnClickOkLevelDone();
  234. }
  235. Debug.LogWarning("SendCoupon");
  236. switch (InGameScriptCS.Instance.Level)
  237. {
  238. case 1:
  239. KHD.FlurryAnalyticsTest.Instance.SendPhone();
  240. break;
  241. case 2:
  242. KHD.FlurryAnalyticsTest.Instance.SendPhone();
  243. break;
  244. case 3:
  245. KHD.FlurryAnalyticsTest.Instance.SendPhone();
  246. break;
  247. case 0:
  248. switch (ServerGiftManager.Instance.LevelServer)
  249. {
  250. case 1:
  251. KHD.FlurryAnalyticsTest.Instance.SendPhone();
  252. break;
  253. case 2:
  254. KHD.FlurryAnalyticsTest.Instance.SendPhone();
  255. break;
  256. case 3:
  257. KHD.FlurryAnalyticsTest.Instance.SendPhone();
  258. break;
  259. }
  260. break;
  261. }
  262. //TODO coupon sent
  263. }
  264. else
  265. {
  266. switch (message)
  267. {
  268. case "coupon is activated already":
  269. PlayerPrefs.SetInt("GetCoupon", 0);
  270. LoginManager.Instance.OnClickOkLevelDone();
  271. Debug.Log("coupon is activated already");
  272. break;
  273. }
  274. Debug.Log(errorCode);
  275. switch (errorCode)
  276. {
  277. case 56:
  278. Debug.LogError("//TODO handle error: deviceID is not registered");
  279. //TODO handle error: deviceID is not registered
  280. break;
  281. case 57:
  282. Debug.LogError("//TODO handle error: no deviceID");
  283. //TODO handle error: no deviceID
  284. break;
  285. case 58:
  286. Debug.LogError("//TODO handle error: phone number does not provided");
  287. //TODO handle error: phone number does not provided
  288. break;
  289. case 59:
  290. Debug.LogError("//TODO handle error: no deviceID");
  291. //TODO handle error: request error
  292. break;
  293. }
  294. }
  295. });
  296. Debug.Log("onDonePhone");
  297. PlayerPrefs.SetInt("Phone", 1);
  298. DonePhone = true;
  299. }
  300. else
  301. {
  302. Debug.Log("onDonePhone");
  303. PlayerPrefs.SetInt("Phone", 1);
  304. DonePhone = true;
  305. }
  306. }
  307. private void onDoneMail()
  308. {
  309. Debug.Log("onDonePhone");
  310. PlayerPrefs.SetInt("Mail", 1);
  311. DoneMail = true;
  312. }
  313. private bool CheckingMail(string mail)
  314. {
  315. RegexUtilities util = new RegexUtilities();
  316. return util.IsValidEmail(mail);
  317. }
  318. private bool ChekingTelephone(string telephone)
  319. {
  320. RegexUtilities util = new RegexUtilities();
  321. return util.IsValidPhone(telephone);
  322. }
  323. }