aboutsummaryrefslogtreecommitdiff
path: root/td/Assets/Scripts/mainGUI.cs
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2017-10-08 22:43:20 +0200
committerJakob Stendahl <jakob.stendahl@outlook.com>2017-10-08 22:43:20 +0200
commit112a91b7084a5365291c712fabcb8ceeb4c644ce (patch)
tree54edd59c73ae7a5e435ff1c338c4384be73397cc /td/Assets/Scripts/mainGUI.cs
parent2338b4e43c35dd1990db69da5751bb28a9c4122c (diff)
downloadTD-112a91b7084a5365291c712fabcb8ceeb4c644ce.tar.gz
TD-112a91b7084a5365291c712fabcb8ceeb4c644ce.zip
Added game over screen
Diffstat (limited to 'td/Assets/Scripts/mainGUI.cs')
-rw-r--r--td/Assets/Scripts/mainGUI.cs111
1 files changed, 81 insertions, 30 deletions
diff --git a/td/Assets/Scripts/mainGUI.cs b/td/Assets/Scripts/mainGUI.cs
index 1c18a17..35d3948 100644
--- a/td/Assets/Scripts/mainGUI.cs
+++ b/td/Assets/Scripts/mainGUI.cs
@@ -1,33 +1,37 @@
using System;
-using System.Collections;
-using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class MainGui : MonoBehaviour {
-
- GameObject _pnlMenu;
- GameObject _pnlSidebar;
- GameObject _pnlSettings;
- RectTransform _pnlSidebarTransform;
- Button _btnToggleSidebar;
- Button _btnPauseGame;
- Button _btnResumeGame;
- Button _btnExitGame;
- Button _btnSettings;
- Button _btnSettingsDiscard;
- Button _btnSettingsSave;
-
- bool _sidebarExpanded;
- float[] _sidebarStates = new float[2] {0f, -202.4f}; // The x position of the sidebar expanded or collapsed
-
- bool _menuActive;
-
- void Awake() {
+ private GameObject _pnlMenu;
+ private GameObject _pnlSidebar;
+ private GameObject _pnlSettings;
+ private GameObject _pnlGameOver;
+ private RectTransform _pnlSidebarTransform;
+ private Button _btnToggleSidebar;
+ private Button _btnPauseGame;
+ private Button _btnResumeGame;
+ private Button _btnExitGame;
+ private Button _btnSettings;
+ private Button _btnSettingsDiscard;
+ private Button _btnSettingsSave;
+ private Button _btnGoRetry;
+ private Button _btnGoMenu;
+ private Text _txtGoScore;
+ private Text _txtGoHighScore;
+ private Text _txtGoNewHighScore;
+
+ private bool _sidebarExpanded;
+ private readonly float[] _sidebarStates = new float[2] {0f, -202.4f}; // The x position of the sidebar expanded or collapsed
+
+ private bool _menuActive;
+
+ private void Awake() {
/* Panels */
_pnlMenu = transform.Find ("menu").gameObject;
_pnlSidebar = transform.Find ("sidebarWrapper").gameObject;
_pnlSettings = transform.Find ("settings").gameObject;
+ _pnlGameOver = transform.Find("GameOver").gameObject;
_pnlSidebarTransform = _pnlSidebar.GetComponent <RectTransform> ();
/* Buttons */
@@ -38,6 +42,8 @@ public class MainGui : MonoBehaviour {
_btnSettings = _pnlMenu.transform.Find ("settings").gameObject.GetComponent <Button> ();
_btnSettingsDiscard = _pnlSettings.transform.Find ("discardChanges").gameObject.GetComponent <Button> ();
_btnSettingsSave = _pnlSettings.transform.Find ("saveChanges").gameObject.GetComponent <Button> ();
+ _btnGoMenu = _pnlGameOver.transform.Find ("menu").gameObject.GetComponent <Button> ();
+ _btnGoRetry = _pnlGameOver.transform.Find ("restart").gameObject.GetComponent <Button> ();
if (_btnToggleSidebar != null) { _btnToggleSidebar.onClick.AddListener (toggleSidebarHandler); }
if (_btnPauseGame != null) { _btnPauseGame.onClick.AddListener (pauseGameHandler); }
if (_btnResumeGame != null) { _btnResumeGame.onClick.AddListener (btnResumeGameHandler); }
@@ -45,20 +51,28 @@ public class MainGui : MonoBehaviour {
if (_btnSettings != null) { _btnSettings.onClick.AddListener (btnSettingsHandler); }
if (_btnSettingsDiscard != null) { _btnSettingsDiscard.onClick.AddListener (btnSettingsDiscardHandler); }
if (_btnSettingsSave != null) { _btnSettingsSave.onClick.AddListener (btnSettingsSaveHandler); }
+ if (_btnGoMenu != null) { _btnGoMenu.onClick.AddListener (btnGoMenuHandler); }
+ if (_btnGoRetry != null) { _btnGoRetry.onClick.AddListener (btnGoRetryHandler); }
+
+ /* Text */
+ _txtGoScore = _pnlGameOver.transform.Find("score").gameObject.GetComponent<Text>();
+ _txtGoHighScore = _pnlGameOver.transform.Find("highScore").gameObject.GetComponent<Text>();
+ _txtGoNewHighScore = _pnlGameOver.transform.Find("newHighscore").gameObject.GetComponent<Text>();
/* Set up initial states */
UpdateSidebarPosandBtn ();
_pnlMenu.SetActive (false);
_pnlSettings.SetActive (false);
+ _pnlGameOver.SetActive(false);
}
- void toggleSidebarHandler() {
+ private void toggleSidebarHandler() {
/* handler for btnToggleSidebar */
_sidebarExpanded = !_sidebarExpanded;
UpdateSidebarPosandBtn ();
}
- void pauseGameHandler() {
+ private void pauseGameHandler() {
/* handler for btnPauseGame */
_menuActive = true;
_pnlMenu.SetActive (_menuActive);
@@ -67,7 +81,7 @@ public class MainGui : MonoBehaviour {
_btnPauseGame.interactable = false;
}
- void btnResumeGameHandler() {
+ private void btnResumeGameHandler() {
/* handler for btnResumeGame */
_menuActive = false;
_pnlMenu.SetActive (_menuActive);
@@ -76,12 +90,12 @@ public class MainGui : MonoBehaviour {
_btnPauseGame.interactable = true;
}
- void btnExitGameHandler() {
+ private void btnExitGameHandler() {
/* handler for btnExitGame */
Application.Quit ();
}
- void btnSettingsHandler() {
+ private void btnSettingsHandler() {
/* handler for btnSettings */
_pnlMenu.SetActive (false);
_pnlSettings.SetActive (true);
@@ -91,7 +105,7 @@ public class MainGui : MonoBehaviour {
}
}
- void btnSettingsSaveHandler() {
+ private void btnSettingsSaveHandler() {
/* handler for btnSaveSettings */
_pnlMenu.SetActive (true);
_pnlSettings.SetActive (false);
@@ -99,13 +113,13 @@ public class MainGui : MonoBehaviour {
PlayerPrefs.SetInt ("developerMode", Convert.ToInt32(_pnlSettings.transform.Find ("developerEnabled").gameObject.GetComponent <Toggle>().isOn));
}
- void btnSettingsDiscardHandler() {
+ private void btnSettingsDiscardHandler() {
/* handler for btnSettingsDiscard */
_pnlMenu.SetActive (true);
_pnlSettings.SetActive (false);
}
- void UpdateSidebarPosandBtn() {
+ private void UpdateSidebarPosandBtn() {
/* update state of sidebar based on the expanded var */
if (_sidebarExpanded) {
_pnlSidebarTransform.localPosition = new Vector3 (_sidebarStates [1], 0f, 0f);
@@ -116,7 +130,15 @@ public class MainGui : MonoBehaviour {
}
}
- bool IntToBool(int input) {
+ private void btnGoMenuHandler() {
+ /* Handler for btnGoMenu */
+ }
+
+ private void btnGoRetryHandler() {
+ /* Handler for btnGoRetry */
+ }
+
+ private bool IntToBool(int input) {
/* Converts int to boolean */
if (input >= 1) {
return true;
@@ -125,4 +147,33 @@ public class MainGui : MonoBehaviour {
}
}
+ public void GameOverScreen(int score) {
+ /* Show game over screen */
+ bool newHighscore = false;
+ int highScore = 0;
+
+ if (PlayerPrefs.HasKey("highscore")) {
+ highScore = PlayerPrefs.GetInt("highscore");
+ if (score > highScore) {
+ newHighscore = true;
+ }
+ }
+
+ if (_sidebarExpanded) { toggleSidebarHandler(); }
+
+ /* Pause game */
+ Time.timeScale = 0.0F;
+ /* Activate panel */
+ _pnlGameOver.SetActive(true);
+ /* Set text, score */
+ _txtGoScore.text = "Score: " + score.ToString();
+ /* set text, highscore */
+ _txtGoHighScore.text = "Highscore: " + highScore.ToString();
+ /* set newHicgscore */
+ _txtGoNewHighScore.gameObject.SetActive(newHighscore);
+ /* Disable other onScreenButtons */
+ _btnToggleSidebar.interactable = false;
+ _btnPauseGame.interactable = false;
+ }
+
}