From e2106400b51b2d62b2beff2bdb775065b7ef5b11 Mon Sep 17 00:00:00 2001 From: Xevion Date: Wed, 20 May 2020 17:09:08 -0500 Subject: [PATCH] makeshift system for moving UI elements back and forth using tweening, implemented about/title tweens and button behaviour for title screen --- Boids/Assets/Scripts/UIController.cs | 103 +++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 14 deletions(-) diff --git a/Boids/Assets/Scripts/UIController.cs b/Boids/Assets/Scripts/UIController.cs index 51b21dd..0fd07e7 100644 --- a/Boids/Assets/Scripts/UIController.cs +++ b/Boids/Assets/Scripts/UIController.cs @@ -1,12 +1,19 @@ -using UnityEngine; +using System; +using UnityEngine; using UnityEngine.UI; public class UIController : MonoBehaviour { + public Canvas canvas; + public BoidController boidController; + + // Main Title Screen Elements public Button startButton; public Button settingsButton; - + public Button aboutButton; public Text titleText; - public BoidController boidController; + + public RectTransform aboutPanel; + public Button aboutCloseButton; // Element Groups private GameObject[] _titleElements; @@ -14,6 +21,13 @@ public class UIController : MonoBehaviour { private GameObject[] _aboutElements; private GameObject[] _adjustmentElements; + // Element Group + private bool _titleActive = true; + private bool _aboutActive = false; + private bool _settingsActive = false; + private bool _playActive = false; + private bool _adjustmentsActive = false; + private UIStance _currentUI; private enum UIStance { @@ -24,9 +38,15 @@ public class UIController : MonoBehaviour { } private void Start() { + // Basic variable setup + _currentUI = UIStance.Title; + // Add event functions startButton.onClick.AddListener(OnStartButton); - settingsButton.onClick.AddListener(OnSettingsButton); + aboutButton.onClick.AddListener(OnAboutButton); + aboutCloseButton.onClick.AddListener(OnAboutClose); + + // settingsButton.onClick.AddListener(OnSettingsButton); // Organize all UI Game Objects _titleElements = new GameObject[] @@ -39,20 +59,75 @@ public class UIController : MonoBehaviour { // Handle Start Button Clicking private void OnStartButton() { - // Move the Title Text up - startButton.interactable = settingsButton.interactable = false; - foreach (GameObject element in _titleElements) { - LeanTween - .move(element, element.transform.position + new Vector3(0, 500, 0), 1.2f) - .setEase(LeanTweenType.easeInCubic); + switch (_currentUI) { + case UIStance.Title: { + Debug.Log("Switching to Play Screen"); + MoveTitleElements(true); + break; + } + // Shouldn't be processed + case UIStance.Play: + case UIStance.Settings: + case UIStance.About: + Debug.LogWarning($"User clicked Start Button out of Title Screen ({_currentUI})"); + break; } } - private void SwitchScreen(UIStance next) { - + // Move Title Elements In/Out + private void MoveTitleElements(bool away) { + foreach (GameObject element in _titleElements) { + LeanTween + .move(element, element.transform.position + new Vector3(0, 500 * (away ? 1 : -1), 0), 1f) + .setEase(LeanTweenType.easeInCubic); + } + + LeanTween + .move(aboutButton.gameObject, aboutButton.transform.position + new Vector3(100 * (away ? 1 : -1), 0, 0), + 0.75f) + .setEase(LeanTweenType.easeInCubic); } - // Handle Settings Button Clicking - private void OnSettingsButton() { + // Move About Elements In/Out + private void MoveAboutElements(bool away) { + LeanTween + .move(aboutPanel.gameObject, aboutPanel.transform.position + new Vector3(760 * (away ? 1 : -1), 0, 0), 1.2f) + .setEase(LeanTweenType.easeInCubic); + } + + // Handle switching to the About Screen + private void OnAboutButton() { + if (_currentUI == UIStance.Title) { + Debug.Log($"Screen Transition: {_currentUI} -> {UIStance.About}"); + MoveAboutElements(false); + MoveTitleElements(true); + _currentUI = UIStance.About; + } + } + + // Handle returning to the Title Screen, closing the About Screen + private void OnAboutClose() { + if (_currentUI == UIStance.About) { + Debug.Log($"Screen Transition: {_currentUI} -> {UIStance.Title}"); + MoveAboutElements(true); + MoveTitleElements(false); + _currentUI = UIStance.Title; + } + } + + private void SwitchToTitle() { + _currentUI = UIStance.Title; + } + + private void SwitchToAbout() { + _currentUI = UIStance.About; + } + + private void SwitchToSettings() { + _currentUI = UIStance.Settings; + } + + private void SwitchToPlay() { + _currentUI = UIStance.Play; } } \ No newline at end of file