NGUIMenuScript.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using Debug = UnityEngine.Debug;
  5. public class NGUIMenuScript : MonoBehaviour {
  6. public static NGUIMenuScript Instance { get; private set; }
  7. public bool GameOverURL;
  8. public enum NGUIMenus
  9. {
  10. MainMenu = 0,
  11. PauseMenu = 1,
  12. GameOverMenu = 2,
  13. InstructionsMenu = 3,
  14. SettingsMenu = 4,
  15. MissionsMenu = 5,
  16. AchievementsMenu = 6,
  17. ShopHome = 7,
  18. ShopCostumes = 8,
  19. ShopIAPs = 9,
  20. ShopPowerups = 10,
  21. ShopUtilities = 11,
  22. LeaderBoard = 12,
  23. RaceStart = 13,
  24. RaceEnd = 14,
  25. CreastmasTree = 15,
  26. SendSms = 16,
  27. EnterCode = 17,
  28. Congratulations = 18,
  29. Ad = 19,
  30. LoginFacebook = 20,
  31. LoadingIndicator = 21,
  32. //CommonDialog = 22
  33. About = 22,
  34. MovementInfo = 23,
  35. LiderboardInfo = 24,
  36. EnterCodeInfo = 25,
  37. FBShare = 26,
  38. FBInviteFriends = 27,
  39. Registration = 28,
  40. Error = 29,
  41. /// <summary>
  42. /// new UI
  43. /// </summary>
  44. Banner = 30,
  45. MainMenuNew = 31,
  46. Menu = 32,
  47. TermsConditionsWin = 33,
  48. AboutPage= 34,
  49. HowToPlayPage = 35,
  50. CompaingPage = 36,
  51. CreastmasPage = 37,
  52. LeaderBoardNew = 38,
  53. Settings= 39,
  54. GameOver = 40,
  55. CodeEnterWrongNoConnect = 41,
  56. CompetitionPage = 42,
  57. TermsConditionsCompetitionsPage = 43,
  58. CodeEnterWrong = 44,
  59. CodeEnter = 45,
  60. TermsConditionsCoke = 46,
  61. TermsConditionsCode = 47,
  62. ChangeLevel = 48,
  63. ChangeAge =49,
  64. StartPage = 50
  65. //SendCoupone = 48
  66. }
  67. public enum StatesMenuForPopup
  68. {
  69. GameOver,
  70. LostLife,
  71. None,
  72. Popup,
  73. Tavling,
  74. Liderboard,
  75. Menu,
  76. StartMenu,
  77. Bunner,
  78. ChangeLevel,
  79. AboutPage
  80. }
  81. public StatesMenuForPopup CurStatePopup = StatesMenuForPopup.None;
  82. private GameObject[] goNGUIMenus;//all the NGUI menu game objects
  83. private GameObject goHUDGroup;//HUDGroup game object
  84. private UILabel uilAchievementsText;//achievement text located on the achievement menu
  85. private UILabel uilMissionPauseMenuText;//list of missions on the pause menu
  86. private UILabel uilMissionMissionMenuText;//list of missions on the missions menu
  87. private ControllerScriptCS hControllerScriptCS;
  88. private int iMenuCount;//total number of menus
  89. private NGUIMenus CurrentMenu;//currently active menu
  90. //variables needed for the resume game counter
  91. private UILabel uilPauseCounter;//countdown timer
  92. private int iResumeGameState = 0;
  93. private float iResumeGameStartTime;//when the resume button was pressed
  94. //scripts references
  95. private InGameScriptCS hInGameScriptCS;
  96. private NGUIHUDScript hNGUIHUDScript;
  97. public bool GetCoupon;
  98. public bool WrongCodeCap;
  99. public UILabel LabelVideoTimer;
  100. public FullScreenUITexture FullScreenUITexture;
  101. public enum StatePopupGetCouponeGameOver
  102. {
  103. EnterNumber,
  104. WrongNumber,
  105. EnterNumberNoConnet
  106. }
  107. public StatePopupGetCouponeGameOver CurState;
  108. public IEnumerator LoadingIndicatorOff()
  109. {
  110. yield return new WaitForSeconds(1);
  111. //NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  112. }
  113. public AchivmentController.Level CurLevel;
  114. void Start ()
  115. {
  116. //PlayerPrefs.DeleteAll();
  117. //PlayerPrefs.Save();
  118. Instance = this;
  119. NGUIMenuScript.Instance.CurStatePopup = NGUIMenuScript.StatesMenuForPopup.StartMenu;
  120. if (Candle)
  121. {
  122. Candle.SetActive(false);
  123. }
  124. //scirpt references
  125. hControllerScriptCS = (ControllerScriptCS)GameObject.Find("Player").GetComponent(typeof(ControllerScriptCS));
  126. hInGameScriptCS = (InGameScriptCS)GameObject.Find("Player").GetComponent(typeof(InGameScriptCS));
  127. hNGUIHUDScript = (NGUIHUDScript)this.transform.Find("Camera/Anchor_center/HUDGroup").GetComponent(typeof(NGUIHUDScript));
  128. //get the total number of menus used
  129. iMenuCount = System.Enum.GetValues(typeof(NGUIMenus)).Length;
  130. //Debug.Log(iMenuCount);
  131. goHUDGroup = GameObject.Find("Camera/Anchor_center/HUDGroup");//gameobject of the HUD Group
  132. //get the gameobjects of all menus used for later access
  133. goNGUIMenus = new GameObject[iMenuCount];
  134. goNGUIMenus[(int)NGUIMenus.MainMenu] = GameObject.Find("Camera/Anchor_center/MainMenu");
  135. goNGUIMenus[(int)NGUIMenus.PauseMenu] = GameObject.Find("Camera/Anchor_center/PauseMenu");
  136. goNGUIMenus[(int)NGUIMenus.GameOver] = GameObject.Find("Camera/Anchor_center/GameOver");
  137. goNGUIMenus[(int)NGUIMenus.InstructionsMenu] = GameObject.Find("Camera/Anchor_center/InstructionsMenu");
  138. goNGUIMenus[(int)NGUIMenus.SettingsMenu] = GameObject.Find("Camera/Anchor_center/SettingsMenu");
  139. goNGUIMenus[(int)NGUIMenus.MissionsMenu] = GameObject.Find("Camera/Anchor_center/MissionsMenu");
  140. goNGUIMenus[(int)NGUIMenus.AchievementsMenu] = GameObject.Find("Camera/Anchor_center/AchievementsMenu");
  141. goNGUIMenus[(int)NGUIMenus.ShopHome] = GameObject.Find("Camera/Anchor_center/Shop/ShopHome");
  142. goNGUIMenus[(int)NGUIMenus.ShopCostumes] = GameObject.Find("Camera/Anchor_center/Shop/ShopCostumes");
  143. goNGUIMenus[(int)NGUIMenus.ShopIAPs] = GameObject.Find("Camera/Anchor_center/Shop/ShopIAPs");
  144. goNGUIMenus[(int)NGUIMenus.ShopPowerups] = GameObject.Find("Camera/Anchor_center/Shop/ShopPowerups");
  145. goNGUIMenus[(int)NGUIMenus.ShopUtilities] = GameObject.Find("Camera/Anchor_center/Shop/ShopUtilities");
  146. goNGUIMenus[(int)NGUIMenus.LeaderBoard] = GameObject.Find("Camera/Anchor_center/LeaderBoard");
  147. goNGUIMenus[(int)NGUIMenus.RaceStart] = GameObject.Find("Camera/Anchor_center/RaceStart");
  148. goNGUIMenus[(int)NGUIMenus.RaceEnd] = GameObject.Find("Camera/Anchor_center/RaceEnd");
  149. goNGUIMenus[(int)NGUIMenus.CreastmasTree] = GameObject.Find("Camera/Anchor_center/CristmasTreeScreen");
  150. goNGUIMenus[(int)NGUIMenus.SendSms] = GameObject.Find("Camera/Anchor_center/SMSMenu");
  151. goNGUIMenus[(int)NGUIMenus.EnterCode] = GameObject.Find("Camera/Anchor_center/EnterCode");
  152. goNGUIMenus[(int)NGUIMenus.Congratulations] = GameObject.Find("Camera/Anchor_center/Congratilations");
  153. goNGUIMenus[(int)NGUIMenus.Ad] = GameObject.Find("Camera/Anchor_center/AD");
  154. goNGUIMenus[(int)NGUIMenus.LoginFacebook] = GameObject.Find("Camera/Anchor_center/LoginFacebook");
  155. goNGUIMenus[(int)NGUIMenus.About] = GameObject.Find("Camera/Anchor_center/About");
  156. goNGUIMenus[(int)NGUIMenus.MovementInfo] = GameObject.Find("Camera/Anchor_center/Movement");
  157. goNGUIMenus[(int)NGUIMenus.LiderboardInfo] = GameObject.Find("Camera/Anchor_center/LiderboardInfo");
  158. goNGUIMenus[(int)NGUIMenus.EnterCodeInfo] = GameObject.Find("Camera/Anchor_center/TreeCodeEnter");
  159. goNGUIMenus[(int)NGUIMenus.FBShare] = GameObject.Find("Camera/Anchor_center/FBDialogShare");
  160. goNGUIMenus[(int)NGUIMenus.FBInviteFriends] = GameObject.Find("Camera/Anchor_center/FBInviteFriends");
  161. goNGUIMenus[(int)NGUIMenus.Registration] = GameObject.Find("Camera/Anchor_center/Registration");
  162. goNGUIMenus[(int)NGUIMenus.Error] = GameObject.Find("Camera/Anchor_center/Error");
  163. goNGUIMenus[(int)NGUIMenus.Banner] = GameObject.Find("Camera/Anchor_center/Banner");
  164. goNGUIMenus[(int)NGUIMenus.ChangeLevel] = GameObject.Find("Camera/Anchor_center/ChangeLevel");
  165. goNGUIMenus[(int)NGUIMenus.Menu] = GameObject.Find("Camera/Anchor_center/Menu");
  166. goNGUIMenus[(int)NGUIMenus.StartPage] = GameObject.Find("Camera/Anchor_center/StartPage");
  167. goNGUIMenus[(int)NGUIMenus.MainMenuNew] = GameObject.Find("Camera/Anchor_center/MainMenuNew");
  168. goNGUIMenus[(int)NGUIMenus.TermsConditionsWin] = GameObject.Find("Camera/Anchor_center/TermsConditionsWin");
  169. goNGUIMenus[(int) NGUIMenus.AboutPage] = GameObject.Find("Camera/Anchor_center/AboutPage");
  170. goNGUIMenus[(int)NGUIMenus.HowToPlayPage] = GameObject.Find("Camera/Anchor_center/HowToPlayPage");
  171. goNGUIMenus[(int)NGUIMenus.CompaingPage] = GameObject.Find("Camera/Anchor_center/CompaingPage");
  172. goNGUIMenus[(int)NGUIMenus.CreastmasPage] = GameObject.Find("Camera/Anchor_center/CreastmasPage");
  173. goNGUIMenus[(int)NGUIMenus.LeaderBoardNew] = GameObject.Find("Camera/Anchor_center/LeaderBoardNew");
  174. goNGUIMenus[(int)NGUIMenus.Settings] = GameObject.Find("Camera/Anchor_center/Settings");
  175. goNGUIMenus[(int)NGUIMenus.GameOver] = GameObject.Find("Camera/Anchor_center/GameOver");
  176. goNGUIMenus[(int)NGUIMenus.CodeEnterWrongNoConnect] = GameObject.Find("Camera/Anchor_center/CodeEnterWrongNoConnect");
  177. goNGUIMenus[(int)NGUIMenus.CompetitionPage] = GameObject.Find("Camera/Anchor_center/CompetitionPage");
  178. goNGUIMenus[(int)NGUIMenus.TermsConditionsCompetitionsPage] = GameObject.Find("Camera/Anchor_center/TermsConditionsCompetitionsPage");
  179. goNGUIMenus[(int)NGUIMenus.CodeEnterWrong] = GameObject.Find("Camera/Anchor_center/CodeEnterWrong");
  180. goNGUIMenus[(int)NGUIMenus.TermsConditionsCoke] = GameObject.Find("Camera/Anchor_center/TermsConditionsCoke");
  181. goNGUIMenus[(int)NGUIMenus.ChangeAge] = GameObject.Find("Camera/Anchor_center/ChangeAge");
  182. goNGUIMenus[(int)NGUIMenus.TermsConditionsCode] = GameObject.Find("Camera/Anchor_center/TermsConditionsCode");
  183. goNGUIMenus[(int)NGUIMenus.LoadingIndicator] = GameObject.Find("Camera/Anchor_center/LoadingIndicator");
  184. //goNGUIMenus[(int)NGUIMenus.SendCoupone] = GameObject.Find("Camera/Anchor_center/CongratulationsCoupone");
  185. //Debug.Log(goNGUIMenus.Length);
  186. for (int i = 0; i < iMenuCount; i++) //disable all menu groups when game starts
  187. {
  188. if (goNGUIMenus[i]!=null)
  189. {
  190. //Debug.Log(goNGUIMenus[i].name);
  191. NGUITools.SetActive(goNGUIMenus[i], false);
  192. }
  193. }
  194. //uilAchievementsText = (UILabel)goNGUIMenus[(int)NGUIMenus.AchievementsMenu].transform.
  195. //Find("Text_Achievements").GetComponent(typeof(UILabel));
  196. uilPauseCounter = (UILabel)this.transform.Find("Camera/Anchor_center/Text_PauseCounter").GetComponent(typeof(UILabel));
  197. NGUITools.SetActive(uilPauseCounter.gameObject, false);
  198. uilMissionPauseMenuText = (UILabel)goNGUIMenus[(int)NGUIMenus.PauseMenu].transform.Find("Text_Missions").GetComponent(typeof(UILabel));
  199. //uilMissionMissionMenuText = (UILabel)goNGUIMenus[(int)NGUIMenus.MissionsMenu].transform.Find("Text_Missions").GetComponent(typeof(UILabel));
  200. if(PlayerPrefs.GetInt("FirstEnterPage") > 0)
  201. {
  202. ShowMenu(NGUIMenus.MainMenuNew);//display main menu when game starts
  203. }
  204. else
  205. {
  206. ShowMenu(NGUIMenus.StartPage);
  207. }
  208. StartCoroutine(UpdateFullScreen());
  209. toggleHUDGroupState(false);
  210. }//end of Start function
  211. private IEnumerator UpdateFullScreen()
  212. {
  213. yield return new WaitForSeconds(0.2f);
  214. FullScreenUITexture.Start();
  215. }
  216. /*
  217. * FUNCTION: Return the reference of the NGUIHUDScript.cs script.
  218. * This is used if the NGUI HUDGroup is disabled when its needed.
  219. * CALLED BY: MissionsControllerCS.Start()
  220. * */
  221. public NGUIHUDScript getNGUIHUDScriptReference()
  222. {
  223. return hNGUIHUDScript;
  224. }
  225. public void LoadinHide()
  226. {
  227. StartCoroutine(LoadinHideCoroutine());
  228. }
  229. public IEnumerator LoadinHideCoroutine()
  230. {
  231. yield return new WaitForSeconds(1);
  232. //NGUIMenuScript.Instance.CloseMenu(NGUIMenuScript.NGUIMenus.LoadingIndicator);
  233. }
  234. void FixedUpdate()
  235. {
  236. //Debug.Log("!!!!!!!!!!!!!!!!!!!!! + iResumeGameState " + iResumeGameState);
  237. //display countdown timer on Resume
  238. /*if (iResumeGameState == 0)
  239. ;
  240. else*/ if (iResumeGameState == 1)//display the counter
  241. {
  242. NGUITools.SetActive(uilPauseCounter.gameObject, true);
  243. iResumeGameStartTime = (int)Time.time;
  244. iResumeGameState = 2;
  245. }
  246. else if (iResumeGameState == 2)//count down
  247. {
  248. //Debug.Log("!!!______________");
  249. if (!_silentTimer)
  250. {
  251. uilPauseCounter.text = Mathf.Round(4 - (Time.time - iResumeGameStartTime)).ToString();
  252. }
  253. //else
  254. //{
  255. // uilPauseCounter.text = "";
  256. //}
  257. if ( (Time.time - iResumeGameStartTime) >= 3)//resume the game when time expires
  258. {
  259. hControllerScriptCS.launchGame();
  260. uilPauseCounter.text = string.Empty;
  261. NGUITools.SetActive(uilPauseCounter.gameObject, false);
  262. hInGameScriptCS.processClicksPauseMenu(MenuScriptCS.PauseMenuEvents.Resume);
  263. iResumeGameStartTime = 0;
  264. iResumeGameState = 0;
  265. }
  266. }
  267. }//end of fixed update
  268. /*
  269. * FUNCTION: Trigger the Fixed Update code to start resume game counter
  270. * after which the InGameScript is signaled to resume gameplay
  271. * CALLED BY: ExitButtonHandler.OnClick()
  272. * */
  273. private bool _silentTimer;
  274. public void startResumeGameCounter(bool silent = false)
  275. {
  276. _silentTimer = silent;
  277. iResumeGameState = 1;//start the countdown timer
  278. if(goNGUIMenus[(int)NGUIMenus.PauseMenu].activeSelf)
  279. {
  280. CloseMenu(NGUIMenus.PauseMenu);
  281. }
  282. //Debug.Log("iResumeGameState " + iResumeGameState );
  283. }
  284. /*
  285. * FUNCTION: Display the list of achievemnts on the achievements menu.
  286. * CALLED BY: GlobalAchievemntControllerCS.updateMenuDescription()
  287. * */
  288. public void updateAchievementsMenuDescription(string description)
  289. {
  290. //uilAchievementsText.text = description;
  291. }
  292. /*
  293. * FUNCTION: Display description of the currently active
  294. * missions on Pause Menu.
  295. * CALLED BY: MissionsControllerCS.updateMenuDescriptions()
  296. */
  297. public void updatePauseMenuMissions(string description)
  298. {
  299. uilMissionPauseMenuText.text = description;
  300. }
  301. /*
  302. * FUNCTION: Display the currently active mission on the Mission Menu.
  303. * CALLED BY: MissionsControllerCS.updateMenuDescriptions()
  304. */
  305. public void updateMissionsMenuMissions(string description)
  306. {
  307. //uilMissionMissionMenuText.text = description;
  308. }
  309. /*
  310. * FUNCTION: Updates the value of the currency on the header. This
  311. * header item is located at all shop menus.
  312. * */
  313. public void updateCurrencyOnHeader(NGUIMenus menu)
  314. {
  315. //( (UILabel)goNGUIMenus[(int)menu].transform.Find("Text_Currency").GetComponent(typeof(UILabel)) ).text = hInGameScriptCS.getCurrencyCount().ToString();
  316. ((UILabel)goNGUIMenus[(int)menu].transform.Find("Text_Currency").GetComponent(typeof(UILabel))).text = Finances.Coins.ToString();
  317. }
  318. /*
  319. * FUNCTION: Enable the menu to show.
  320. */
  321. public void ShowMenu(NGUIMenus menu)
  322. {
  323. CurrentMenu = menu;//set the currently active menu
  324. NGUITools.SetActive(goNGUIMenus[(int)menu], true);//enable the menu
  325. NGUITools.SetActive(goHUDGroup, false);//disable the HUD components
  326. //Debug.Log("UIThanks.Instance.OnShow();");
  327. //update the currency on the shop home menu header
  328. if (menu == NGUIMenus.ShopHome || menu == NGUIMenus.ShopCostumes
  329. || menu == NGUIMenus.ShopIAPs || menu == NGUIMenus.ShopPowerups
  330. || menu == NGUIMenus.ShopUtilities)
  331. updateCurrencyOnHeader(menu);
  332. if (menu == NGUIMenus.GameOver)
  333. {
  334. if (hNGUIHUDScript.Score > Finances.BestScore)
  335. {
  336. //hNGUIHUDScript.BestScore.SetActive(true);
  337. //Finances.BestScore = hNGUIHUDScript.Score;
  338. }
  339. UIThanks.Instance.OnShow();
  340. }
  341. else
  342. {
  343. //hNGUIHUDScript.BestScore.SetActive(false);
  344. }
  345. if (menu == NGUIMenus.LeaderBoardNew)
  346. {
  347. var lb = goNGUIMenus[(int) menu].GetComponent<UILeaderBoard>();
  348. lb.OnShow();
  349. }
  350. if (menu == NGUIMenus.RaceStart)
  351. {
  352. var sr = goNGUIMenus[(int)menu].GetComponent<UIRaceStart>();
  353. sr.OnShow();
  354. }
  355. switch (menu)
  356. {
  357. case NGUIMenus.MainMenu:
  358. break;
  359. case NGUIMenus.PauseMenu:
  360. iResumeGameState = 0;
  361. break;
  362. case NGUIMenus.GameOver:
  363. break;
  364. case NGUIMenus.InstructionsMenu:
  365. break;
  366. case NGUIMenus.SettingsMenu:
  367. break;
  368. case NGUIMenus.MissionsMenu:
  369. break;
  370. case NGUIMenus.AchievementsMenu:
  371. break;
  372. case NGUIMenus.ShopHome:
  373. break;
  374. case NGUIMenus.ShopCostumes:
  375. break;
  376. case NGUIMenus.ShopIAPs:
  377. break;
  378. case NGUIMenus.ShopPowerups:
  379. break;
  380. case NGUIMenus.ShopUtilities:
  381. break;
  382. }
  383. }
  384. /*
  385. * FUNCTION: Disable the menu to close
  386. */
  387. public void CloseMenu(NGUIMenus menu)
  388. {
  389. NGUITools.SetActive(goNGUIMenus[(int)menu], false);//disable the menu
  390. }
  391. /*
  392. * FUNCTION: Enable/ disable the current script.
  393. * ADDITIONA INFO: The NGUIMenuScript.js is disabled during gameplay to improve
  394. * performance.
  395. */
  396. public void NGUIMenuScriptEnabled(bool state)
  397. {
  398. this.enabled = state;
  399. }
  400. /*
  401. * FUNCTION: Dispaly or hide HUD depeding upon the state the game is in;
  402. * HUD is not displayed when menus are active.
  403. */
  404. public void toggleHUDGroupState(bool state,bool resurection = false)
  405. {
  406. if (goHUDGroup == null)
  407. {
  408. goHUDGroup = GameObject.Find("Camera/Anchor_center/HUDGroup");//gameobject of the HUD Group
  409. }
  410. NGUITools.SetActive(goHUDGroup, state);
  411. hNGUIHUDScript.toggleHUDGroupState(state);
  412. if (state && !resurection)
  413. {
  414. //Analitics.Game();
  415. }
  416. }
  417. /*
  418. * FUNCTION: Get the currently active menu.
  419. * RETURNS: The current menu enum object.
  420. * */
  421. public NGUIMenus getCurrentMenu()
  422. {
  423. return CurrentMenu;
  424. }
  425. public GameObject Candle;
  426. public string TestID;
  427. public bool CloseEnterNumber;
  428. public void ShowCandle()
  429. {
  430. Candle.SetActive(true);
  431. StartCoroutine(RemoveCandle());
  432. }
  433. private IEnumerator RemoveCandle()
  434. {
  435. yield return new WaitForSeconds(3);
  436. Candle.SetActive(false);
  437. }
  438. }