PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/Assets/Scripts/GUI/GameOverAdvancedGui.cs

https://gitlab.com/deliriumgameworks/lab
C# | 289 lines | 248 code | 41 blank | 0 comment | 15 complexity | 18fcf9ed74fc7b388baa2bf1d14dbf79 MD5 | raw file
  1. #pragma warning disable 0168 // variable declared but not used.
  2. using UnityEngine;
  3. using System.Collections;
  4. public class GameOverAdvancedGui: MonoBehaviour {
  5. private const int INSERT_VERSION = 1;
  6. private const int HIGHSCORE_VERSION = 2;
  7. const string TwitterShare = "http://twitter.com/intent/tweet";
  8. const string FacebookID = "648150285304327";
  9. const string FacebookShare = "http://www.facebook.com/dialog/feed";
  10. private float buttonWidth = 0f;
  11. private float buttonHeight = 0f;
  12. private float rateWidth = 0f;
  13. private float rateHeight = 0f;
  14. private float ScoreButtonWidth = 0f;
  15. private float ScoreButtonHeight = 0f;
  16. private float ShareButtonWidth = 0f;
  17. private float ShareButtonHeight = 0f;
  18. private float goLabelWidth = 0f;
  19. private float goLabelHeight = 0f;
  20. private float backGroundWidth = 0f;
  21. private float backGroundHeight = 0f;
  22. private float labelWidth = 0f;
  23. private float labelHeight = 0f;
  24. public GUISkin gameOverSkin;
  25. public GUISkin labelSkin;
  26. public GUISkin labelSkinOverlay;
  27. private HighScoreboard highScoreboard;
  28. float score = 0;
  29. WWW up_query;
  30. bool up_handled;
  31. public Texture2D MainMenu;
  32. public Texture2D Retry;
  33. public Texture2D RateUs;
  34. public Texture2D HighScoreBG;
  35. public Texture2D DonutMasters;
  36. public Texture2D Twitter;
  37. public Texture2D Facebook;
  38. public Texture2D GameOverLabel;
  39. public Texture2D GlobalButtonOn;
  40. public Texture2D LocalButtonOn;
  41. public Texture2D GlobalButtonOff;
  42. public Texture2D LocalButtonOff;
  43. private Texture2D GlobalButtonToggle;
  44. private Texture2D LocalButtonToggle;
  45. void flexibleSpaces(int num) {
  46. for (int i = 0; i < num; ++i) {
  47. GUILayout.FlexibleSpace();
  48. }
  49. }
  50. void Start ()
  51. {
  52. highScoreboard = HighScores.getInstance().localScores;
  53. GlobalButtonToggle = GlobalButtonOff;
  54. LocalButtonToggle = LocalButtonOn;
  55. buttonWidth = Screen.width * .2f;
  56. buttonHeight = Screen.height * .1f;
  57. rateWidth = Screen.width * .2f;
  58. rateHeight = Screen.height * .1f;
  59. ScoreButtonWidth = Screen.width * 0.15f;
  60. ScoreButtonHeight = Screen.height * 0.15f;
  61. ShareButtonWidth = Screen.width * 0.06f;
  62. ShareButtonHeight = Screen.height * 0.1f;
  63. goLabelWidth = Screen.width * 0.25f;
  64. goLabelHeight = Screen.height * 0.15f;
  65. labelWidth = Screen.width * 0.5f;
  66. labelHeight = 94;
  67. backGroundWidth = Screen.width * 0.4f;
  68. backGroundHeight = Screen.height * 0.5f;
  69. up_handled = false;
  70. score = Mathf.Round(GameVars.getInstance().getScore());
  71. HighScoreEntry highScoreEntry = new HighScoreEntry();
  72. highScoreEntry.playerName = GameVars.getInstance().getPlayerName();
  73. highScoreEntry.playerUuid = GameVars.getInstance().getPlayerUuid();
  74. highScoreEntry.scoreUuid = System.Guid.NewGuid();
  75. highScoreEntry.score = (int) score;
  76. highScoreEntry.scoreVersion = HIGHSCORE_VERSION;
  77. highScoreEntry.appVersion = GameVars.VERSION_NUMBER;
  78. HighScores.getInstance().localScores.addHighScoreEntry(highScoreEntry);
  79. if (GameVars.getInstance().getGlobalHighScoresSelected()) {
  80. highScoreboard = HighScores.getInstance().globalScores;
  81. GlobalButtonToggle = GlobalButtonOn;
  82. LocalButtonToggle = LocalButtonOff;
  83. } else {
  84. highScoreboard = HighScores.getInstance().localScores;
  85. GlobalButtonToggle = GlobalButtonOff;
  86. LocalButtonToggle = LocalButtonOn;
  87. }
  88. if (GameVars.getInstance().getValidUsername()) {
  89. string up_query_str =
  90. "https://www.copsvsorcs.com/insert_high_score.php" +
  91. "?id=" + WWW.EscapeURL(GameVars.getInstance().getPlayerName()) +
  92. "&score=" + WWW.EscapeURL(score.ToString()) +
  93. "&playerUuid=" + WWW.EscapeURL(highScoreEntry.playerUuid.ToString()) +
  94. "&scoreVersion=" + WWW.EscapeURL(highScoreEntry.scoreVersion.ToString()) +
  95. "&scoreUuid=" + WWW.EscapeURL(highScoreEntry.scoreUuid.ToString()) +
  96. "&version=" + WWW.EscapeURL(INSERT_VERSION.ToString());
  97. #if UNITY_EDITOR
  98. Debug.LogDebug(up_query_str);
  99. #endif
  100. up_query = new WWW(up_query_str);
  101. }
  102. GameObject.Find ("HeroCop(Clone)").transform.position = new Vector3 (-6f, -3.4f, 0f);
  103. GameVars.getInstance().setUserHasStarted(false);
  104. }
  105. void OnGUI()
  106. {
  107. if (!up_handled && up_query != null && up_query.isDone)
  108. {
  109. up_handled = true;
  110. HighScores.getInstance().LoadGlobalScoresResponseString(up_query.text);
  111. }
  112. GUI.skin = gameOverSkin;
  113. GUI.skin.label.fontSize = (int) (Screen.height*0.038f);
  114. GUILayoutOption[] buttonOptions = {GUILayout.Width(buttonWidth), GUILayout.Height(buttonHeight)};
  115. GUILayoutOption[] rateOptions = {GUILayout.Width(rateWidth), GUILayout.Height(rateHeight)};
  116. GUILayoutOption[] BackgroundOptions = {GUILayout.Width(backGroundWidth), GUILayout.Height(backGroundHeight)};
  117. GUILayoutOption[] LabelOptions = {GUILayout.Width(labelWidth), GUILayout.Height(labelHeight)};
  118. GUILayoutOption[] goLabelOptions = {GUILayout.Width(goLabelWidth), GUILayout.Height(goLabelHeight)};
  119. GUILayoutOption[] scoreButtonOptions = {GUILayout.Width(ScoreButtonWidth), GUILayout.Height(ScoreButtonHeight)};
  120. GUILayoutOption[] shareButtonOptions = {GUILayout.Width(ShareButtonWidth), GUILayout.Height(ShareButtonHeight)};
  121. GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
  122. GUILayout.BeginVertical ();
  123. flexibleSpaces (1);//vert distance from top of screen to buttons and gameoverlabel
  124. GUILayout.BeginHorizontal ();
  125. flexibleSpaces (1);//space from left side to retry button
  126. if (GUILayout.Button(Retry, buttonOptions))
  127. {
  128. GameVars.getInstance().setOrcKills(0);
  129. GameVars.getInstance().setDistance(0);
  130. GameVars.getInstance().setOrcHits(0);
  131. GameVars.getInstance().setComboMultiplier(0);
  132. GameVars.getInstance().setComboOrcKills(0);
  133. GameVars.getInstance().setMScore(0);
  134. SceneManager.LoadLevel(SceneManager.Scene.ENDLESS_RUN);
  135. }
  136. flexibleSpaces (1);//spacefrom retry button to game over label
  137. GUILayout.Box (GameOverLabel, goLabelOptions);
  138. flexibleSpaces (1);//space from gameover label to main menu button
  139. if (GUILayout.Button(MainMenu, buttonOptions))
  140. {
  141. GameVars.getInstance().setOrcKills(0);
  142. GameVars.getInstance().setDistance(0);
  143. GameVars.getInstance().setOrcHits(0);
  144. GameVars.getInstance().setComboMultiplier(0);
  145. GameVars.getInstance().setComboOrcKills(0);
  146. GameVars.getInstance().setMScore(0);
  147. SceneManager.LoadLevel(SceneManager.Scene.MAIN_MENU);
  148. }
  149. flexibleSpaces (1);//space from main menu to right edge
  150. GUILayout.EndHorizontal ();
  151. flexibleSpaces (1);//vert distance from gameover to score text prompt
  152. GUILayout.BeginHorizontal ();
  153. flexibleSpaces (1);
  154. GUI.skin = labelSkin;
  155. GUI.skin.label.fontSize = (int) (Screen.height*0.04f);
  156. GUILayout.Label("Your score this round was $" + score + "!", LabelOptions);
  157. GUI.skin = gameOverSkin;
  158. flexibleSpaces (1);
  159. GUILayout.EndHorizontal ();
  160. flexibleSpaces (20);//vert distance between score prompt bottom of screen
  161. GUILayout.BeginArea (new Rect (0, 0, Screen.width, Screen.height));
  162. GUILayout.BeginVertical ();
  163. flexibleSpaces (7);
  164. GUILayout.BeginHorizontal ();
  165. flexibleSpaces (1);
  166. GUILayout.Label (highScoreboard.getNames(), BackgroundOptions);
  167. flexibleSpaces (1);
  168. GUILayout.EndHorizontal ();
  169. flexibleSpaces (3);
  170. GUILayout.EndVertical ();
  171. GUILayout.EndArea ();
  172. GUILayout.BeginArea (new Rect (0, 0, Screen.width, Screen.height));
  173. GUILayout.BeginVertical ();
  174. flexibleSpaces (7);
  175. GUILayout.BeginHorizontal ();
  176. flexibleSpaces (1);
  177. GUI.skin = labelSkinOverlay;
  178. GUI.skin.label.fontSize = (int) (Screen.height*0.038f);
  179. GUILayout.Label (highScoreboard.getScores(), BackgroundOptions);
  180. GUI.skin = gameOverSkin;
  181. flexibleSpaces (1);
  182. GUILayout.EndHorizontal ();
  183. flexibleSpaces (3);
  184. GUILayout.EndVertical ();
  185. GUILayout.EndArea ();
  186. GUILayout.BeginArea (new Rect (0, 0, Screen.width, Screen.height));
  187. GUILayout.BeginVertical ();
  188. flexibleSpaces (2);
  189. GUILayout.BeginHorizontal ();
  190. flexibleSpaces (1);
  191. if (GUILayout.Button (GlobalButtonToggle, scoreButtonOptions)) {
  192. GlobalButtonToggle = GlobalButtonOn;
  193. LocalButtonToggle = LocalButtonOff;
  194. GameVars.getInstance().setGlobalHighScoresSelected(true);
  195. highScoreboard = HighScores.getInstance().globalScores;
  196. }
  197. GUILayout.Box (DonutMasters, goLabelOptions);
  198. if (GUILayout.Button (LocalButtonToggle, scoreButtonOptions)) {
  199. GlobalButtonToggle = GlobalButtonOff;
  200. LocalButtonToggle = LocalButtonOn;
  201. GameVars.getInstance().setGlobalHighScoresSelected(false);
  202. highScoreboard = HighScores.getInstance().localScores;
  203. }
  204. flexibleSpaces (1);
  205. GUILayout.EndHorizontal ();
  206. flexibleSpaces (3);
  207. GUILayout.EndVertical ();
  208. GUILayout.EndArea ();
  209. GUILayout.BeginArea (new Rect (0, 0, Screen.width, Screen.height));
  210. GUILayout.BeginVertical ();
  211. flexibleSpaces (20);
  212. GUILayout.BeginHorizontal ();
  213. flexibleSpaces (4);
  214. if (GUILayout.Button (Twitter, GUIStyle.none, shareButtonOptions)) {
  215. Application.OpenURL(TwitterShare + "?text=" + WWW.EscapeURL("@Delirium_GW, I scored " + score + " on #CopsVsOrcs!")
  216. + "&url=" + WWW.EscapeURL("https://www.facebook.com/deliriumgameworks?fref=ts")
  217. + "&related=" + WWW.EscapeURL("https://www.twitter.com/Delirium_GW")
  218. + "&lang=" + WWW.EscapeURL("en"));
  219. }
  220. if (GUILayout.Button (Facebook, GUIStyle.none, shareButtonOptions)) {
  221. Application.OpenURL(FacebookShare +
  222. "?app_id=" + FacebookID +
  223. "&link=" + WWW.EscapeURL("https://www.facebook.com/deliriumgameworks?fref=ts")+
  224. "&picture=" + WWW.EscapeURL("https://pbs.twimg.com/profile_images/602945529169883136/j21GJ7G4.jpg")+
  225. "&name=" + WWW.EscapeURL("Cops vs Orcs!!!") +
  226. "&caption=" + WWW.EscapeURL("Check out my new HighScore on CopsVsOrcs") +
  227. "&description=" + WWW.EscapeURL("@deliriumgameworks, My new Cops vs Orcs score is " + score) +
  228. "&redirect_uri=" + WWW.EscapeURL("https://www.deliriumgameworks.com/"));
  229. }
  230. GUI.skin = gameOverSkin;
  231. flexibleSpaces (2);
  232. GUILayout.EndHorizontal ();
  233. flexibleSpaces (1);
  234. GUILayout.EndVertical ();
  235. GUILayout.EndArea ();
  236. flexibleSpaces (1);
  237. if (GUILayout.Button (RateUs, rateOptions)) {
  238. #if UNITY_ANDROID
  239. Application.OpenURL("market://details?id=com.deliriumgw.copsvsorcs");
  240. #elif UNITY_IPHONE
  241. Application.OpenURL("itms-apps://itunes.apple.com/app/id1004888424");
  242. #endif
  243. }
  244. flexibleSpaces (1);
  245. GUILayout.EndVertical ();
  246. GUILayout.EndArea ();
  247. }
  248. }