123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503 |
- using System;
- using UnityEngine;
- using System.Collections;
- using Debug = UnityEngine.Debug;
- public class NGUIMenuScript : MonoBehaviour {
- public static NGUIMenuScript Instance { get; private set; }
- public bool GameOverURL;
- public enum NGUIMenus
- {
- MainMenu = 0,
- PauseMenu = 1,
- GameOverMenu = 2,
- InstructionsMenu = 3,
- SettingsMenu = 4,
- MissionsMenu = 5,
- AchievementsMenu = 6,
- ShopHome = 7,
- ShopCostumes = 8,
- ShopIAPs = 9,
- ShopPowerups = 10,
- ShopUtilities = 11,
- LeaderBoard = 12,
- RaceStart = 13,
- RaceEnd = 14,
- CreastmasTree = 15,
- SendSms = 16,
- EnterCode = 17,
- Congratulations = 18,
- Ad = 19,
- LoginFacebook = 20,
- LoadingIndicator = 21,
- //CommonDialog = 22
- About = 22,
- MovementInfo = 23,
- LiderboardInfo = 24,
- EnterCodeInfo = 25,
- FBShare = 26,
- FBInviteFriends = 27,
- Registration = 28,
- Error = 29,
- /// <summary>
- /// new UI
- /// </summary>
- Banner = 30,
- MainMenuNew = 31,
- Menu = 32,
- TermsConditionsWin = 33,
- AboutPage= 34,
- HowToPlayPage = 35,
- CompaingPage = 36,
- CreastmasPage = 37,
- LeaderBoardNew = 38,
- Settings= 39,
- GameOver = 40,
- CodeEnterWrongNoConnect = 41,
- CompetitionPage = 42,
- TermsConditionsCompetitionsPage = 43,
- CodeEnterWrong = 44,
- CodeEnter = 45,
- TermsConditionsCoke = 46,
- TermsConditionsCode = 47,
- ChangeLevel = 48,
- ChangeAge =49,
- StartPage = 50
- //SendCoupone = 48
- }
- public enum StatesMenuForPopup
- {
- GameOver,
- LostLife,
- None,
- Popup,
- Tavling,
- Liderboard,
- Menu,
- StartMenu,
- Bunner,
- ChangeLevel,
- AboutPage
- }
- public StatesMenuForPopup CurStatePopup = StatesMenuForPopup.None;
-
- private GameObject[] goNGUIMenus;//all the NGUI menu game objects
- private GameObject goHUDGroup;//HUDGroup game object
- private UILabel uilAchievementsText;//achievement text located on the achievement menu
- private UILabel uilMissionPauseMenuText;//list of missions on the pause menu
- private UILabel uilMissionMissionMenuText;//list of missions on the missions menu
- private ControllerScriptCS hControllerScriptCS;
- private int iMenuCount;//total number of menus
- private NGUIMenus CurrentMenu;//currently active menu
-
- //variables needed for the resume game counter
- private UILabel uilPauseCounter;//countdown timer
- private int iResumeGameState = 0;
- private float iResumeGameStartTime;//when the resume button was pressed
-
- //scripts references
- private InGameScriptCS hInGameScriptCS;
- private NGUIHUDScript hNGUIHUDScript;
- public bool GetCoupon;
- public bool WrongCodeCap;
- public UILabel LabelVideoTimer;
- public FullScreenUITexture FullScreenUITexture;
- public enum StatePopupGetCouponeGameOver
- {
- EnterNumber,
- WrongNumber,
- EnterNumberNoConnet
- }
- public StatePopupGetCouponeGameOver CurState;
- public IEnumerator LoadingIndicatorOff()
- {
- yield return new WaitForSeconds(1);
- //NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
- }
- public AchivmentController.Level CurLevel;
- void Start ()
- {
- //PlayerPrefs.DeleteAll();
- //PlayerPrefs.Save();
- Instance = this;
-
- NGUIMenuScript.Instance.CurStatePopup = NGUIMenuScript.StatesMenuForPopup.StartMenu;
- if (Candle)
- {
- Candle.SetActive(false);
- }
- //scirpt references
- hControllerScriptCS = (ControllerScriptCS)GameObject.Find("Player").GetComponent(typeof(ControllerScriptCS));
- hInGameScriptCS = (InGameScriptCS)GameObject.Find("Player").GetComponent(typeof(InGameScriptCS));
- hNGUIHUDScript = (NGUIHUDScript)this.transform.Find("Camera/Anchor_center/HUDGroup").GetComponent(typeof(NGUIHUDScript));
-
- //get the total number of menus used
- iMenuCount = System.Enum.GetValues(typeof(NGUIMenus)).Length;
- //Debug.Log(iMenuCount);
- goHUDGroup = GameObject.Find("Camera/Anchor_center/HUDGroup");//gameobject of the HUD Group
-
- //get the gameobjects of all menus used for later access
- goNGUIMenus = new GameObject[iMenuCount];
- goNGUIMenus[(int)NGUIMenus.MainMenu] = GameObject.Find("Camera/Anchor_center/MainMenu");
- goNGUIMenus[(int)NGUIMenus.PauseMenu] = GameObject.Find("Camera/Anchor_center/PauseMenu");
- goNGUIMenus[(int)NGUIMenus.GameOver] = GameObject.Find("Camera/Anchor_center/GameOver");
- goNGUIMenus[(int)NGUIMenus.InstructionsMenu] = GameObject.Find("Camera/Anchor_center/InstructionsMenu");
- goNGUIMenus[(int)NGUIMenus.SettingsMenu] = GameObject.Find("Camera/Anchor_center/SettingsMenu");
- goNGUIMenus[(int)NGUIMenus.MissionsMenu] = GameObject.Find("Camera/Anchor_center/MissionsMenu");
- goNGUIMenus[(int)NGUIMenus.AchievementsMenu] = GameObject.Find("Camera/Anchor_center/AchievementsMenu");
- goNGUIMenus[(int)NGUIMenus.ShopHome] = GameObject.Find("Camera/Anchor_center/Shop/ShopHome");
- goNGUIMenus[(int)NGUIMenus.ShopCostumes] = GameObject.Find("Camera/Anchor_center/Shop/ShopCostumes");
- goNGUIMenus[(int)NGUIMenus.ShopIAPs] = GameObject.Find("Camera/Anchor_center/Shop/ShopIAPs");
- goNGUIMenus[(int)NGUIMenus.ShopPowerups] = GameObject.Find("Camera/Anchor_center/Shop/ShopPowerups");
- goNGUIMenus[(int)NGUIMenus.ShopUtilities] = GameObject.Find("Camera/Anchor_center/Shop/ShopUtilities");
- goNGUIMenus[(int)NGUIMenus.LeaderBoard] = GameObject.Find("Camera/Anchor_center/LeaderBoard");
- goNGUIMenus[(int)NGUIMenus.RaceStart] = GameObject.Find("Camera/Anchor_center/RaceStart");
- goNGUIMenus[(int)NGUIMenus.RaceEnd] = GameObject.Find("Camera/Anchor_center/RaceEnd");
- goNGUIMenus[(int)NGUIMenus.CreastmasTree] = GameObject.Find("Camera/Anchor_center/CristmasTreeScreen");
- goNGUIMenus[(int)NGUIMenus.SendSms] = GameObject.Find("Camera/Anchor_center/SMSMenu");
- goNGUIMenus[(int)NGUIMenus.EnterCode] = GameObject.Find("Camera/Anchor_center/EnterCode");
- goNGUIMenus[(int)NGUIMenus.Congratulations] = GameObject.Find("Camera/Anchor_center/Congratilations");
- goNGUIMenus[(int)NGUIMenus.Ad] = GameObject.Find("Camera/Anchor_center/AD");
- goNGUIMenus[(int)NGUIMenus.LoginFacebook] = GameObject.Find("Camera/Anchor_center/LoginFacebook");
- goNGUIMenus[(int)NGUIMenus.About] = GameObject.Find("Camera/Anchor_center/About");
- goNGUIMenus[(int)NGUIMenus.MovementInfo] = GameObject.Find("Camera/Anchor_center/Movement");
- goNGUIMenus[(int)NGUIMenus.LiderboardInfo] = GameObject.Find("Camera/Anchor_center/LiderboardInfo");
- goNGUIMenus[(int)NGUIMenus.EnterCodeInfo] = GameObject.Find("Camera/Anchor_center/TreeCodeEnter");
- goNGUIMenus[(int)NGUIMenus.FBShare] = GameObject.Find("Camera/Anchor_center/FBDialogShare");
- goNGUIMenus[(int)NGUIMenus.FBInviteFriends] = GameObject.Find("Camera/Anchor_center/FBInviteFriends");
- goNGUIMenus[(int)NGUIMenus.Registration] = GameObject.Find("Camera/Anchor_center/Registration");
- goNGUIMenus[(int)NGUIMenus.Error] = GameObject.Find("Camera/Anchor_center/Error");
- goNGUIMenus[(int)NGUIMenus.Banner] = GameObject.Find("Camera/Anchor_center/Banner");
- goNGUIMenus[(int)NGUIMenus.ChangeLevel] = GameObject.Find("Camera/Anchor_center/ChangeLevel");
-
- goNGUIMenus[(int)NGUIMenus.Menu] = GameObject.Find("Camera/Anchor_center/Menu");
- goNGUIMenus[(int)NGUIMenus.StartPage] = GameObject.Find("Camera/Anchor_center/StartPage");
- goNGUIMenus[(int)NGUIMenus.MainMenuNew] = GameObject.Find("Camera/Anchor_center/MainMenuNew");
- goNGUIMenus[(int)NGUIMenus.TermsConditionsWin] = GameObject.Find("Camera/Anchor_center/TermsConditionsWin");
- goNGUIMenus[(int) NGUIMenus.AboutPage] = GameObject.Find("Camera/Anchor_center/AboutPage");
- goNGUIMenus[(int)NGUIMenus.HowToPlayPage] = GameObject.Find("Camera/Anchor_center/HowToPlayPage");
- goNGUIMenus[(int)NGUIMenus.CompaingPage] = GameObject.Find("Camera/Anchor_center/CompaingPage");
- goNGUIMenus[(int)NGUIMenus.CreastmasPage] = GameObject.Find("Camera/Anchor_center/CreastmasPage");
- goNGUIMenus[(int)NGUIMenus.LeaderBoardNew] = GameObject.Find("Camera/Anchor_center/LeaderBoardNew");
- goNGUIMenus[(int)NGUIMenus.Settings] = GameObject.Find("Camera/Anchor_center/Settings");
- goNGUIMenus[(int)NGUIMenus.GameOver] = GameObject.Find("Camera/Anchor_center/GameOver");
- goNGUIMenus[(int)NGUIMenus.CodeEnterWrongNoConnect] = GameObject.Find("Camera/Anchor_center/CodeEnterWrongNoConnect");
- goNGUIMenus[(int)NGUIMenus.CompetitionPage] = GameObject.Find("Camera/Anchor_center/CompetitionPage");
- goNGUIMenus[(int)NGUIMenus.TermsConditionsCompetitionsPage] = GameObject.Find("Camera/Anchor_center/TermsConditionsCompetitionsPage");
- goNGUIMenus[(int)NGUIMenus.CodeEnterWrong] = GameObject.Find("Camera/Anchor_center/CodeEnterWrong");
- goNGUIMenus[(int)NGUIMenus.TermsConditionsCoke] = GameObject.Find("Camera/Anchor_center/TermsConditionsCoke");
- goNGUIMenus[(int)NGUIMenus.ChangeAge] = GameObject.Find("Camera/Anchor_center/ChangeAge");
- goNGUIMenus[(int)NGUIMenus.TermsConditionsCode] = GameObject.Find("Camera/Anchor_center/TermsConditionsCode");
- goNGUIMenus[(int)NGUIMenus.LoadingIndicator] = GameObject.Find("Camera/Anchor_center/LoadingIndicator");
- //goNGUIMenus[(int)NGUIMenus.SendCoupone] = GameObject.Find("Camera/Anchor_center/CongratulationsCoupone");
- //Debug.Log(goNGUIMenus.Length);
- for (int i = 0; i < iMenuCount; i++) //disable all menu groups when game starts
- {
- if (goNGUIMenus[i]!=null)
- {
- //Debug.Log(goNGUIMenus[i].name);
- NGUITools.SetActive(goNGUIMenus[i], false);
- }
-
- }
- //uilAchievementsText = (UILabel)goNGUIMenus[(int)NGUIMenus.AchievementsMenu].transform.
- //Find("Text_Achievements").GetComponent(typeof(UILabel));
- uilPauseCounter = (UILabel)this.transform.Find("Camera/Anchor_center/Text_PauseCounter").GetComponent(typeof(UILabel));
- NGUITools.SetActive(uilPauseCounter.gameObject, false);
-
- uilMissionPauseMenuText = (UILabel)goNGUIMenus[(int)NGUIMenus.PauseMenu].transform.Find("Text_Missions").GetComponent(typeof(UILabel));
- //uilMissionMissionMenuText = (UILabel)goNGUIMenus[(int)NGUIMenus.MissionsMenu].transform.Find("Text_Missions").GetComponent(typeof(UILabel));
- if(PlayerPrefs.GetInt("FirstEnterPage") > 0)
- {
- ShowMenu(NGUIMenus.MainMenuNew);//display main menu when game starts
- }
- else
- {
- ShowMenu(NGUIMenus.StartPage);
- }
- StartCoroutine(UpdateFullScreen());
- toggleHUDGroupState(false);
- }//end of Start function
- private IEnumerator UpdateFullScreen()
- {
- yield return new WaitForSeconds(0.2f);
- FullScreenUITexture.Start();
- }
- /*
- * FUNCTION: Return the reference of the NGUIHUDScript.cs script.
- * This is used if the NGUI HUDGroup is disabled when its needed.
- * CALLED BY: MissionsControllerCS.Start()
- * */
- public NGUIHUDScript getNGUIHUDScriptReference()
- {
- return hNGUIHUDScript;
- }
- public void LoadinHide()
- {
- StartCoroutine(LoadinHideCoroutine());
- }
- public IEnumerator LoadinHideCoroutine()
- {
- yield return new WaitForSeconds(1);
- //NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
- }
- void FixedUpdate()
- {
- //Debug.Log("!!!!!!!!!!!!!!!!!!!!! + iResumeGameState " + iResumeGameState);
- //display countdown timer on Resume
- /*if (iResumeGameState == 0)
- ;
- else*/ if (iResumeGameState == 1)//display the counter
- {
- NGUITools.SetActive(uilPauseCounter.gameObject, true);
- iResumeGameStartTime = (int)Time.time;
- iResumeGameState = 2;
- }
- else if (iResumeGameState == 2)//count down
- {
- //Debug.Log("!!!______________");
- if (!_silentTimer)
- {
- uilPauseCounter.text = Mathf.Round(4 - (Time.time - iResumeGameStartTime)).ToString();
- }
- //else
- //{
- // uilPauseCounter.text = "";
- //}
-
- if ( (Time.time - iResumeGameStartTime) >= 3)//resume the game when time expires
- {
- hControllerScriptCS.launchGame();
- uilPauseCounter.text = string.Empty;
- NGUITools.SetActive(uilPauseCounter.gameObject, false);
-
- hInGameScriptCS.processClicksPauseMenu(MenuScriptCS.PauseMenuEvents.Resume);
- iResumeGameStartTime = 0;
- iResumeGameState = 0;
- }
- }
- }//end of fixed update
-
- /*
- * FUNCTION: Trigger the Fixed Update code to start resume game counter
- * after which the InGameScript is signaled to resume gameplay
- * CALLED BY: ExitButtonHandler.OnClick()
- * */
- private bool _silentTimer;
- public void startResumeGameCounter(bool silent = false)
- {
- _silentTimer = silent;
- iResumeGameState = 1;//start the countdown timer
- if(goNGUIMenus[(int)NGUIMenus.PauseMenu].activeSelf)
- {
- CloseMenu(NGUIMenus.PauseMenu);
- }
-
- //Debug.Log("iResumeGameState " + iResumeGameState );
- }
-
- /*
- * FUNCTION: Display the list of achievemnts on the achievements menu.
- * CALLED BY: GlobalAchievemntControllerCS.updateMenuDescription()
- * */
- public void updateAchievementsMenuDescription(string description)
- {
- //uilAchievementsText.text = description;
- }
-
- /*
- * FUNCTION: Display description of the currently active
- * missions on Pause Menu.
- * CALLED BY: MissionsControllerCS.updateMenuDescriptions()
- */
- public void updatePauseMenuMissions(string description)
- {
- uilMissionPauseMenuText.text = description;
- }
-
- /*
- * FUNCTION: Display the currently active mission on the Mission Menu.
- * CALLED BY: MissionsControllerCS.updateMenuDescriptions()
- */
- public void updateMissionsMenuMissions(string description)
- {
- //uilMissionMissionMenuText.text = description;
- }
-
- /*
- * FUNCTION: Updates the value of the currency on the header. This
- * header item is located at all shop menus.
- * */
- public void updateCurrencyOnHeader(NGUIMenus menu)
- {
- //( (UILabel)goNGUIMenus[(int)menu].transform.Find("Text_Currency").GetComponent(typeof(UILabel)) ).text = hInGameScriptCS.getCurrencyCount().ToString();
- ((UILabel)goNGUIMenus[(int)menu].transform.Find("Text_Currency").GetComponent(typeof(UILabel))).text = Finances.Coins.ToString();
- }
-
- /*
- * FUNCTION: Enable the menu to show.
- */
- public void ShowMenu(NGUIMenus menu)
- {
- CurrentMenu = menu;//set the currently active menu
- NGUITools.SetActive(goNGUIMenus[(int)menu], true);//enable the menu
- NGUITools.SetActive(goHUDGroup, false);//disable the HUD components
- //Debug.Log("UIThanks.Instance.OnShow();");
- //update the currency on the shop home menu header
- if (menu == NGUIMenus.ShopHome || menu == NGUIMenus.ShopCostumes
- || menu == NGUIMenus.ShopIAPs || menu == NGUIMenus.ShopPowerups
- || menu == NGUIMenus.ShopUtilities)
- updateCurrencyOnHeader(menu);
- if (menu == NGUIMenus.GameOver)
- {
- if (hNGUIHUDScript.Score > Finances.BestScore)
- {
- //hNGUIHUDScript.BestScore.SetActive(true);
- //Finances.BestScore = hNGUIHUDScript.Score;
-
- }
-
- UIThanks.Instance.OnShow();
- }
- else
- {
- //hNGUIHUDScript.BestScore.SetActive(false);
- }
- if (menu == NGUIMenus.LeaderBoardNew)
- {
- var lb = goNGUIMenus[(int) menu].GetComponent<UILeaderBoard>();
- lb.OnShow();
- }
- if (menu == NGUIMenus.RaceStart)
- {
- var sr = goNGUIMenus[(int)menu].GetComponent<UIRaceStart>();
- sr.OnShow();
- }
- switch (menu)
- {
- case NGUIMenus.MainMenu:
-
- break;
- case NGUIMenus.PauseMenu:
- iResumeGameState = 0;
- break;
- case NGUIMenus.GameOver:
-
- break;
- case NGUIMenus.InstructionsMenu:
- break;
- case NGUIMenus.SettingsMenu:
- break;
- case NGUIMenus.MissionsMenu:
- break;
- case NGUIMenus.AchievementsMenu:
- break;
- case NGUIMenus.ShopHome:
-
- break;
- case NGUIMenus.ShopCostumes:
- break;
- case NGUIMenus.ShopIAPs:
- break;
- case NGUIMenus.ShopPowerups:
- break;
- case NGUIMenus.ShopUtilities:
- break;
- }
- }
-
- /*
- * FUNCTION: Disable the menu to close
- */
- public void CloseMenu(NGUIMenus menu)
- {
- NGUITools.SetActive(goNGUIMenus[(int)menu], false);//disable the menu
- }
-
- /*
- * FUNCTION: Enable/ disable the current script.
- * ADDITIONA INFO: The NGUIMenuScript.js is disabled during gameplay to improve
- * performance.
- */
- public void NGUIMenuScriptEnabled(bool state)
- {
- this.enabled = state;
- }
-
- /*
- * FUNCTION: Dispaly or hide HUD depeding upon the state the game is in;
- * HUD is not displayed when menus are active.
- */
- public void toggleHUDGroupState(bool state,bool resurection = false)
- {
- if (goHUDGroup == null)
- {
- goHUDGroup = GameObject.Find("Camera/Anchor_center/HUDGroup");//gameobject of the HUD Group
- }
- NGUITools.SetActive(goHUDGroup, state);
- hNGUIHUDScript.toggleHUDGroupState(state);
- if (state && !resurection)
- {
- //Analitics.Game();
- }
- }
-
- /*
- * FUNCTION: Get the currently active menu.
- * RETURNS: The current menu enum object.
- * */
- public NGUIMenus getCurrentMenu()
- {
- return CurrentMenu;
- }
- public GameObject Candle;
- public string TestID;
- public bool CloseEnterNumber;
- public void ShowCandle()
- {
- Candle.SetActive(true);
- StartCoroutine(RemoveCandle());
- }
- private IEnumerator RemoveCandle()
- {
- yield return new WaitForSeconds(3);
- Candle.SetActive(false);
- }
-
- }
|