123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- using UnityEngine;
- using System.Collections;
- using System;
- public class NotificationCodeEnter : MonoBehaviour
- {
- public ScreenBase WrongCode;
- ScreenBase screen;
- UILabel label;
- public GameObject GoInvite;
- public GameObject GoShowAd;
- public CapchaCheck Check;
- private NGUIMenuScript hNGUIMenuScript;
- void Awake()
- {
- //PlayerPrefs.DeleteAll();
- screen = GetComponent<ScreenBase>();
- screen.Hide();
- NotificationCenter.AddListener(OnShowEnterCode, NotificationType.ShowEnterCode);
- }
- void OnDestroy()
- {
- NotificationCenter.RemoveListener(OnShowEnterCode, NotificationType.ShowEnterCode);
- }
- public void OnShowEnterCode(Notification note)
- {
- var addLifeStep = PlayerPrefs.GetInt("AddLifeStep", 0);
- addLifeStep = 2;
- if (addLifeStep == 0)
- {
- GoInvite.SetActive(true);
- GoShowAd.SetActive(false);
- NGUIMenuScript.Instance.toggleHUDGroupState(true, true);
- }
- else if (addLifeStep == 1)
- {
- GoInvite.SetActive(false);
- GoShowAd.SetActive(true);
- NGUIMenuScript.Instance.toggleHUDGroupState(true, true);
- }
- else if (addLifeStep == 2)
- {
- GoInvite.SetActive(false);
- GoShowAd.SetActive(false);
- NGUIMenuScript.Instance.toggleHUDGroupState(false, false);
- ClickClose();
- return;
- }
-
- LoginManager.Instance.CurScreenCodeEnter = screen;
- screen.Show();
- }
- public UIInput emailFriend;
- public UIInput CodeEnter;
- public UIButton Ok;
- public UIButton SendInvite;
- public UIButton ShowAd;
- public UIButton Close;
- public UIInput InputMail;
- // Use this for initialization
- void Start()
- {
- Ok.onClick.Add(new EventDelegate(ClickOk));
- Close.onClick.Add(new EventDelegate(ClickClose));
- SendInvite.onClick.Add(new EventDelegate(ClickSendInvite));
- ShowAd.onClick.Add(new EventDelegate(ClickShowAd));
- hPlayerSidesColliderScriptCS = (PlayerSidesColliderScriptCS)GameObject.Find("PlayerSidesCollider").GetComponent(typeof(PlayerSidesColliderScriptCS));
- hPlayerFrontColliderScriptCS = (PlayerFrontColliderScriptCS)GameObject.Find("PlayerFrontCollider").GetComponent(typeof(PlayerFrontColliderScriptCS));
- hNGUIMenuScript = (NGUIMenuScript)GameObject.Find("UI Root (2D)").GetComponent(typeof(NGUIMenuScript));
- StartCoroutine(AlphaActive());
- StartCoroutine(TestAd());
- }
- bool CheckingMail(string mail)
- {
- RegexUtilities util = new RegexUtilities();
- return util.IsValidEmail(mail);
- }
- public enum StateGameOver
- {
- InviteFriends,
- ShowAd,
- None
- }
-
- public StateGameOver CurStateGameOver;
- public void ClickSendInvite()
- {
- Debug.Log("ClickSendInvite");
- if (!ConnectivityPollManager.HasInternet)
- {
- screen.Hide();
- LoginManager.Instance.WrongConnectMessages.Show();
- NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
- return;
- }
- if (ConnectivityPollManager.HasInternet) //register code
- {
- if (CheckingMail(emailFriend.value))
- {
- Debug.LogWarning(emailFriend.value);
- ServerGiftManager.Instance.SendInviteMailToserv(emailFriend.value, state =>
- {
- Debug.LogWarning("!!! " +emailFriend.value);
- string s2 = state.ToString().Trim('\"');
- switch (s2.ToString())
- {
-
- case "ok":
-
- LifeManager.AddlifeInviteFriends();
- if (LifeManager.Lifes > 0)
- {
- PlayerPrefs.SetInt("AddLifeStep", 1);
- OnDone();
- screen.Hide();
- Debug.Log(">0");
- }
- else
- {
- ClickClose();
- Debug.Log("0");
- }
- Debug.Log("ok");
- break;
- case "already":
- UIMessage.LabelMessage.text = "This email adress is old";
- UIMessage.GetComponent<ScreenBase>().Show();
- break;
- //case "already":
- // UIMessage.LabelMessage.text = "This email adress is old";
- // UIMessage.GetComponent<ScreenBase>().Show();
- // break;
- }
- Debug.LogWarning(state);
- });
- }
- else
- {
- UIMessage.LabelMessage.text = "Not correct email adress";
- UIMessage.GetComponent<ScreenBase>().Show();
- }
- }
-
- }
- private void ClickShowAd()
- {
-
- AdManager.Instance.PlayVideoAd();
- }
- private IEnumerator TestAd()
- {
- yield return new WaitForSeconds(10);
- //Check.GetComponent<UIPanel>().alpha = 1;
- }
- private IEnumerator AlphaActive()
- {
- yield return new WaitForSeconds(0.5f);
- GetComponent<UIPanel>().alpha = 1;
- //Check.GetComponent<UIPanel>().alpha = 1;
- }
- private void ClickClose()
- {
- NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.GameOver);
-
- NGUIMenuScript.Instance.CurStatePopup = NGUIMenuScript.StatesMenuForPopup.GameOver;
- screen.Hide();
- var distance = (int)ControllerScriptCS.Instance.getCurrentMileage();
- var gifts = PowerupsMainControllerCS.Instance.getCurrencyUnits();
- var score = (int)(ControllerScriptCS.Instance.getCurrentMileage() + (PowerupsMainControllerCS.Instance.getCurrencyUnits() * 3) + TooltipLastterController.Instance.PontWords);
- //FlurryLogger.Instance.GameFinish(distance, gifts, score);
- if (KHD.FlurryAnalyticsTest.Instance)
- {
- KHD.FlurryAnalyticsTest.Instance.GameFinish(distance, gifts, score);
- }
-
- }
-
- public void EnterDoneCaptcha()
- {
- Debug.Log("EnterDoneCaptcha");
- transform.position = new Vector3(transform.position.x, 0, transform.position.z);
- }
- public void EnterCaptcha()
- {
- transform.position = new Vector3(transform.position.x, 77, transform.position.z);
- }
- void OnEnable()
- {
- var day = DateTime.Now;
- var saveDate = PlayerPrefs.GetInt("OldDate", 0);
- if (saveDate == 0)
- {
- saveDate = DateTime.Now.Day;
- PlayerPrefs.SetInt("OldDate", saveDate);
- }
- else
- {
- if (saveDate != day.Day)
- {
- PlayerPrefs.SetInt("AddLifeStep", 0);
- PlayerPrefs.SetInt("OldDate", day.Day);
- }
- }
- PlayerPrefs.Save();
- CodeEnter.text = "Fyll i kod...";
- emailFriend.text = "";
- StartCoroutine(AlphaActive());
- }
- private bool DoneCaptcha;
- private bool DoneCode;
- public PlayerSidesColliderScriptCS hPlayerSidesColliderScriptCS { get; private set; }
- public PlayerFrontColliderScriptCS hPlayerFrontColliderScriptCS { get; private set; }
- public CheckBoxConditionsHandler CheckBoxConditionsHandler;
- public MessageCodeCap UIMessage;
- private void ClickOk()
- {
- NGUIMenuScript.Instance.ShowMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
- if (!ConnectivityPollManager.HasInternet)
- {
- screen.Hide();
- LoginManager.Instance.WrongConnectMessages.Show();
- NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
- return;
- }
- if (Check.Check(emailFriend.value))
- {
- Debug.LogWarning("capcha ok");
- }
- else
- {
- Debug.LogWarning("capcha fail");
- }
- if (Check.Check(emailFriend.value))
- {
- if (ConnectivityPollManager.HasInternet) //register code
- {
-
- RegisterCodeMIX.Instance.Activate(CodeEnter.text, (state, s) =>
- {
- Debug.Log(state + CodeEnter.text);
- switch (state)
- {
- case RegisterCodeMIX.ActivateStates.OtherError:
- screen.Hide();
- NotificationCenter.Post(NotificationType.ShowEnterWrong);
- NGUIMenuScript.Instance.WrongCodeCap = true;
- //todo: handle error
- break;
- case RegisterCodeMIX.ActivateStates.RequestOrNetworkError:
- screen.Hide();
- NotificationCenter.Post(NotificationType.ShowInternetWrong);
- NGUIMenuScript.Instance.WrongCodeCap = true;
- //todo: handle error
- break;
- case RegisterCodeMIX.ActivateStates.CouponAlreadyReedemed:
- screen.Hide();
- NotificationCenter.Post(NotificationType.ShowEnterWrong);
- NGUIMenuScript.Instance.WrongCodeCap = true;
- //todo: handle error
- break;
- case RegisterCodeMIX.ActivateStates.BadInput:
- screen.Hide();
- NotificationCenter.Post(NotificationType.ShowEnterWrong);
- NGUIMenuScript.Instance.WrongCodeCap = true;
- //todo: handle error
- break;
- case RegisterCodeMIX.ActivateStates.Done:
- Debug.Log(RegisterCodeMIX.ActivateStates.Done);
- //LoginManager.Instance.CountEnterCode++;
- OnDone();
- //todo: EVERYTHING GOES WELL
- break;
- }
- Debug.Log(state);
- NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
- });
- }
- else
- {
- NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
- screen.Hide();
- }
- }
- else
- {
- NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
- }
- }
- void OnDone()
- {
- UIEnergy.Instance.Restore();
- PlayerController.Instance.Alive();
- InGameScriptCS.Instance.InvokeResurrection();
- InGameScriptCS.Instance.EnergyAdd(100);
- hPlayerSidesColliderScriptCS.InvokeResurrection();
- hPlayerFrontColliderScriptCS.InvokeResurrection();
- ControllerScriptCS.Instance.bControlsEnabled = true;
- InGameScriptCS.Instance.Resurected = false;
-
- screen.Hide();
- Text_PauseCounter.Show();
- }
- }
|