From a233edac83741676fb4631ee4756e5ca6ce1a281 Mon Sep 17 00:00:00 2001 From: Nathan Date: Fri, 21 Apr 2023 13:23:14 -0600 Subject: [PATCH] Some various fixes (#153) * Fix calibration menu breaking the game when entered * Fix pause menu MissingReferenceException * Resume instead of exiting when pressing back in the pause menu * Clean up PauseMenu * Fix index out of range exception in DifficultyView --- Assets/Script/GameManager.cs | 1 - Assets/Script/UI/DifficultyView.cs | 10 +++-- Assets/Script/UI/MainMenu.cs | 4 -- Assets/Script/UI/PauseMenu.cs | 53 ++++++++++++++--------- ProjectSettings/EditorBuildSettings.asset | 3 -- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/Assets/Script/GameManager.cs b/Assets/Script/GameManager.cs index 43f7c7fd1..b2c8f813f 100644 --- a/Assets/Script/GameManager.cs +++ b/Assets/Script/GameManager.cs @@ -11,7 +11,6 @@ public enum SceneIndex { PERSISTANT, MENU, PLAY, - SERVER_HOST, CALIBRATION } diff --git a/Assets/Script/UI/DifficultyView.cs b/Assets/Script/UI/DifficultyView.cs index 67cc389c6..7a34069e7 100644 --- a/Assets/Script/UI/DifficultyView.cs +++ b/Assets/Script/UI/DifficultyView.cs @@ -17,11 +17,15 @@ public void SetInfo(string instrument, int difficulty) { var icon = Addressables.LoadAssetAsync($"FontSprites[{instrument}]").WaitForCompletion(); instrumentIcon.sprite = icon; + // Acceptable difficulty range is -1 to 6 + if (difficulty < -1) { + difficulty = 0; // Clamp values below -1 to 0 since this is a specifically-set value + } else if (difficulty > 6) { + difficulty = 6; + } + // Set ring sprite int index = difficulty + 1; - if (difficulty == -2) { - index = 1; - } ringSprite.sprite = ringSprites[index]; // Set instrument opacity diff --git a/Assets/Script/UI/MainMenu.cs b/Assets/Script/UI/MainMenu.cs index 2e5695e31..531e0f73e 100644 --- a/Assets/Script/UI/MainMenu.cs +++ b/Assets/Script/UI/MainMenu.cs @@ -233,10 +233,6 @@ public void ShowCalibrationScene() { } } - public void ShowHostServerScene() { - GameManager.Instance.LoadScene(SceneIndex.SERVER_HOST); - } - public void AbortSongLoad() { SettingsManager.DeleteSettingsFile(); diff --git a/Assets/Script/UI/PauseMenu.cs b/Assets/Script/UI/PauseMenu.cs index 70b7bcfd5..87a374cef 100644 --- a/Assets/Script/UI/PauseMenu.cs +++ b/Assets/Script/UI/PauseMenu.cs @@ -5,6 +5,12 @@ namespace YARG.UI { public class PauseMenu : MonoBehaviour { + private enum ButtonIndex { + RESUME = 0, + SETTINGS, + QUIT + } + [SerializeField] private GenericOption[] options; @@ -53,14 +59,11 @@ private void OnGenericNavigation(NavigationType navigationType, bool firstPresse return; } - if (navigationType == NavigationType.UP) { - MoveOption(-1); - } else if (navigationType == NavigationType.DOWN) { - MoveOption(1); - } else if (navigationType == NavigationType.PRIMARY) { - Next(); - } else if (navigationType == NavigationType.SECONDARY) { - MainMenu.Instance.ShowSongSelect(); + switch (navigationType) { + case NavigationType.UP: MoveOption(-1); break; + case NavigationType.DOWN: MoveOption(1); break; + case NavigationType.PRIMARY: SelectCurrentOption(); break; + case NavigationType.SECONDARY: OnResumeSelected(); break; } } @@ -97,34 +100,30 @@ private void HoverOption(GenericOption option) { } private void ClickOption(GenericOption option) { - Next(); + SelectCurrentOption(); } - public void Next() { - if (selected == 0) { - // Resume - Play.Instance.Paused = false; - } else if (selected == 1) { - // Settings - settingsContainer.SetActive(!settingsContainer.activeSelf); - } else if (selected == 2) { - // Quit - Play.Instance.Exit(); + public void SelectCurrentOption() { + switch ((ButtonIndex)selected) { + case ButtonIndex.RESUME: OnResumeSelected(); break; + case ButtonIndex.SETTINGS: OnSettingsSelected(); break; + case ButtonIndex.QUIT: OnQuitSelected(); break; + default: Debug.LogError($"Unhandled option index {selected}!"); break; } } private void UpdateText() { // Add to options - optionCount = 3; string[] ops = { "Resume", "Settings", "Quit", null }; + optionCount = ops.Length - 1; // Set text and sprites - for (int i = 0; i < 4; i++) { + for (int i = 0; i < ops.Length; i++) { options[i].SetText(ops[i]); options[i].SetSelected(false); } @@ -133,5 +132,17 @@ private void UpdateText() { selected = 0; options[0].SetSelected(true); } + + private void OnResumeSelected() { + Play.Instance.Paused = false; + } + + private void OnSettingsSelected() { + settingsContainer.SetActive(!settingsContainer.activeSelf); + } + + private void OnQuitSelected() { + Play.Instance.Exit(); + } } } \ No newline at end of file diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index d2ac852af..4875c2d0c 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -14,9 +14,6 @@ EditorBuildSettings: - enabled: 1 path: Assets/Scenes/PlayScene.unity guid: 99c9720ab356a0642a771bea13969a05 - - enabled: 0 - path: Assets/Scenes/ServerHostScene.unity - guid: e834445e547f55b4c9fb2d58be1ff16c - enabled: 1 path: Assets/Scenes/CalibrationScene.unity guid: 40fdd5787dc39f540b9024e7dfa32f0f