123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- using UnityEngine;
- using System.Collections;
- using System;
- public class EnterMailTelephoneButtonHundler : MonoBehaviour
- {
- public UIInput Telephone;
- public UIInput MailAdress;
- public UILabel ErrorMail;
- public CheckBoxConditionsHandler CheckBoxConditionsHandler;
- public ScreenBase ScreenError;
- public UILabel MessasageError;
- public UIButton Ok;
- private string PhoneCodeCountryDenmark = "45";
- private string PhoneCodeCountryUkraine = "38";
- private string PhoneCodeCountryIceland = "354";
-
- // Use this for initialization
- void Start () {
- //PlayerPrefs.SetInt("GetCoupon", 0);
- Ok.onClick.Add(new EventDelegate(ClickOk));
- if (Telephone != null)
- {
- if (Telephone.GetComponent<UIButton>())
- {
- Telephone.GetComponent<UIButton>().onClick.Add(new EventDelegate(CheckMail));
- }
- }
-
-
- if (MailAdress != null )
- {
- if (MailAdress.GetComponent<UIButton>())
- {
- MailAdress.GetComponent<UIButton>().onClick.Add(new EventDelegate(CheckTelephone));
- }
-
- }
-
- }
- private void CheckTelephone()
- {
- if (Telephone.text == "Telefonnummer..." || Telephone.text == "")
- return;
- Debug.Log("CheckTelephone");
- if (!ChekingTelephone(Telephone.text))
- {
- Telephone.text = "Telefonnummer...";
- MessasageError.text = "Ogiltigt telefonnummer";
- ScreenError.Show();
- }
-
- }
- private void CheckMail()
- {
- if (MailAdress.text == "Mailadress..." || MailAdress.text == "")
- return;
- if (!CheckingMail(MailAdress.text))
- {
- MailAdress.text = "Mailadress...";
- MessasageError.text = "Ogiltig e-post";
- ScreenError.Show();
- }
- }
- void OnEnable()
- {
- Telephone.text = "Telefonnummer...";
- if (TelephoneEnter)
- {
- //Telephone.text = "Telefonnummer...";
- }
- else
- {
- //Telephone.text = "Telefonnummer...";
- //MailAdress.text = "Mailadress...";
- ErrorMail.gameObject.SetActive(false);
- }
- }
- private bool DoneMail;
- private bool DonePhone;
- public bool TelephoneEnter;
- public bool NoConnect;
- private void ClickOk()
- {
-
- if (NoConnect)
- {
-
- }
- else
- {
- if (TelephoneEnter)
- {
- if (ChekingTelephone(Telephone.text))
- {
-
- // Debug.Log("Telephone success");
- }
- else
- {
-
- if (transform.name == "CouponPopupWrongNumber")
- {
-
- }
- else
- {
- if (NGUIMenuScript.Instance.CurStatePopup == NGUIMenuScript.StatesMenuForPopup.StartMenu)
- {
- LoginManager.Instance.StartNoNumberCompetitions = true;
- }
- LoginManager.Instance.WrongNumberPhone.Show();
- NGUIMenuScript.Instance.CurState = NGUIMenuScript.StatePopupGetCouponeGameOver.WrongNumber;
- if (Ok.transform.parent.name == "CouponPopup")
- {
-
- GetComponent<ScreenBase>().Hide();
- }
- else
- {
- LoginManager.Instance.WrongMessages.GetComponent<MessageCodeCap>().LabelMessage.text = "Ogiltigt telefonnummer";
- LoginManager.Instance.WrongMessages.Show();
- }
- }
- return;
- }
- if (CheckBoxConditionsHandler.Check)
- {
- }
- if (ChekingTelephone(Telephone.text) && CheckBoxConditionsHandler.Check)
- {
- switch (LoginManager.Instance.CurStateCountryCodePhone)
- {
- case LoginManager.StateCountryTelephoneCode.Danmark:
-
- Telephone.text = PhoneCodeCountryDenmark + Telephone.text;
- break;
- case LoginManager.StateCountryTelephoneCode.Ukraine:
-
- Telephone.text = PhoneCodeCountryUkraine + Telephone.text;
- break;
- case LoginManager.StateCountryTelephoneCode.Iceland:
- Telephone.text = PhoneCodeCountryIceland + Telephone.text;
- break;
- }
- onDonePhone();
- Debug.LogWarning("Phone " + Telephone.text);
- PlayerPrefs.SetString("NumberPhone", Telephone.text);
- PlayerPrefs.Save();
- //ServerGiftManager.Instance.RegisterPhone(Telephone.text, states => onDonePhone());
- GetComponent<ScreenBase>().Hide();
- if (PlayerPrefs.GetInt("LevelDone", 0) == 1)
- {
- LoginManager.Instance.PopupLifeEndMessages.Show();
- PlayerPrefs.SetInt("LevelDone", 2);
- }
-
-
- }
- }
- else
- {
- if (CheckingMail(MailAdress.text))
- {
- RegistrationManager.Instance.Mail = MailAdress.text;
- }
- else
- {
- MailAdress.text = "Mailadress...";
- MessasageError.text = "Ogiltig e-post";
- ScreenError.Show();
- return;
- }
- if (ChekingTelephone(Telephone.text))
- {
- RegistrationManager.Instance.Number = Telephone.text;
- // Debug.Log("Telephone success");
- }
- else
- {
- if (NGUIMenuScript.Instance.CurStatePopup == NGUIMenuScript.StatesMenuForPopup.StartMenu)
- {
- LoginManager.Instance.StartNoNumberCompetitions = true;
- }
- //LoginManager.Instance.WrongNumberPhone.Show();
- NGUIMenuScript.Instance.CurState = NGUIMenuScript.StatePopupGetCouponeGameOver.WrongNumber;
- GetComponent<ScreenBase>().Hide();
- Telephone.text = "Telefonnummer...";
- MessasageError.text = "Ogiltigt telefonnummer";
- ScreenError.Show();
- }
- if (CheckBoxConditionsHandler.Check)
- {
- Debug.Log("Check success");
- }
- if (CheckingMail(MailAdress.text) && ChekingTelephone(Telephone.text) && CheckBoxConditionsHandler.Check)
- {
- //ServerGiftManager.Instance.FullRegistration(RegistrationManager.Instance.CurName, Telephone.text, MailAdress.text, states => onDonePhone());
- if (NGUIMenuScript.Instance.CurStatePopup == NGUIMenuScript.StatesMenuForPopup.StartMenu)
- {
- GetComponent<ScreenBase>().Hide();
- }
- else
- {
- LoginManager.Instance.LoginOpen = false;
- var top = GameObject.Find("fbTOP100").GetComponent<fbtop>();
- var distance = PlayerControllerLevels.Instance.AllDistance;
- var gifts = PlayerControllerLevels.Instance.AllGifts;
- top.AddScore(distance, gifts,TooltipLastterController.Instance.PontWords);
- NGUIMenuScript.Instance.CurStatePopup = NGUIMenuScript.StatesMenuForPopup.Popup;
- //NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
- //NGUIMenuScript.Instance.StartCoroutine(NGUIMenuScript.Instance.LoadingIndicatorOff());
- NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.LeaderBoardNew);
- NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.GameOver);
- }
- }
- }
- }
- }
- private void onDonePhone()
- {
- if (TelephoneEnter)
- {
- ServerGiftManager.Instance.ConsumeToken();
- ServerGiftManager.Instance.SendCoupon(Telephone.text,(done, message, errorCode) =>
- {
- if (done)
- {
- //GetComponent<ButtonWithTwoStates>().DeactivateButton();
- //NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.SendCoupone);
- foreach (var b in LoginManager.Instance.ButtonsCoupon)
- {
- if (b.gameObject.activeSelf)
- {
- b.DeactivateButton();
- }
- }
- PlayerPrefs.SetInt("CloseEnterNumber", 0);
- PlayerPrefs.SetInt("GetCoupon", 0);
- PlayerPrefs.SetInt("giftNum", 0);
- LoginManager.Instance.ScreenSendSmsMessages.Show();
- if (NGUIMenuScript.Instance.CurStatePopup == NGUIMenuScript.StatesMenuForPopup.GameOver)
- {
-
- }
- else if (NGUIMenuScript.Instance.CurStatePopup == NGUIMenuScript.StatesMenuForPopup.Menu)
- {
-
- }
- else
- {
- LoginManager.Instance.OnClickOkLevelDone();
- }
- Debug.LogWarning("SendCoupon");
-
- switch (InGameScriptCS.Instance.Level)
- {
- case 1:
- KHD.FlurryAnalyticsTest.Instance.SendPhone();
- break;
- case 2:
- KHD.FlurryAnalyticsTest.Instance.SendPhone();
- break;
- case 3:
- KHD.FlurryAnalyticsTest.Instance.SendPhone();
- break;
- case 0:
- switch (ServerGiftManager.Instance.LevelServer)
- {
- case 1:
- KHD.FlurryAnalyticsTest.Instance.SendPhone();
- break;
- case 2:
- KHD.FlurryAnalyticsTest.Instance.SendPhone();
- break;
- case 3:
- KHD.FlurryAnalyticsTest.Instance.SendPhone();
- break;
- }
- break;
- }
- //TODO coupon sent
- }
- else
- {
- switch (message)
- {
- case "coupon is activated already":
- PlayerPrefs.SetInt("GetCoupon", 0);
- LoginManager.Instance.OnClickOkLevelDone();
- Debug.Log("coupon is activated already");
- break;
- }
- Debug.Log(errorCode);
- switch (errorCode)
- {
- case 56:
- Debug.LogError("//TODO handle error: deviceID is not registered");
- //TODO handle error: deviceID is not registered
- break;
- case 57:
- Debug.LogError("//TODO handle error: no deviceID");
- //TODO handle error: no deviceID
- break;
- case 58:
- Debug.LogError("//TODO handle error: phone number does not provided");
- //TODO handle error: phone number does not provided
- break;
- case 59:
- Debug.LogError("//TODO handle error: no deviceID");
- //TODO handle error: request error
- break;
- }
- }
- });
- Debug.Log("onDonePhone");
- PlayerPrefs.SetInt("Phone", 1);
- DonePhone = true;
- }
- else
- {
- Debug.Log("onDonePhone");
- PlayerPrefs.SetInt("Phone", 1);
- DonePhone = true;
- }
- }
- private void onDoneMail()
- {
- Debug.Log("onDonePhone");
- PlayerPrefs.SetInt("Mail", 1);
- DoneMail = true;
- }
- private bool CheckingMail(string mail)
- {
- RegexUtilities util = new RegexUtilities();
- return util.IsValidEmail(mail);
- }
- private bool ChekingTelephone(string telephone)
- {
- RegexUtilities util = new RegexUtilities();
- return util.IsValidPhone(telephone);
- }
- }
|