Skip to content

Commit

Permalink
Some various fixes (#153)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
TheNathannator authored Apr 21, 2023
1 parent 03ea5b1 commit a233eda
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
1 change: 0 additions & 1 deletion Assets/Script/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public enum SceneIndex {
PERSISTANT,
MENU,
PLAY,
SERVER_HOST,
CALIBRATION
}

Expand Down
10 changes: 7 additions & 3 deletions Assets/Script/UI/DifficultyView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ public void SetInfo(string instrument, int difficulty) {
var icon = Addressables.LoadAssetAsync<Sprite>($"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
Expand Down
4 changes: 0 additions & 4 deletions Assets/Script/UI/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@ public void ShowCalibrationScene() {
}
}

public void ShowHostServerScene() {
GameManager.Instance.LoadScene(SceneIndex.SERVER_HOST);
}

public void AbortSongLoad() {
SettingsManager.DeleteSettingsFile();

Expand Down
53 changes: 32 additions & 21 deletions Assets/Script/UI/PauseMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

namespace YARG.UI {
public class PauseMenu : MonoBehaviour {
private enum ButtonIndex {
RESUME = 0,
SETTINGS,
QUIT
}

[SerializeField]
private GenericOption[] options;

Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}
}
}
3 changes: 0 additions & 3 deletions ProjectSettings/EditorBuildSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a233eda

Please sign in to comment.