From b0649541ebe4ac77cd327a09fb9d3c78c89f34d2 Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Tue, 30 Dec 2014 00:41:32 -0500 Subject: [PATCH] Better emulation of main menu behavior. - Pressing 'Esc' will now always enter the MainMenuExit state. - Returning from MainMenuExit state does not reset button states: these must be manually reset by calling the reset() method. Signed-off-by: Jeffrey Han --- src/itdelatrisu/opsu/states/GameRanking.java | 1 + src/itdelatrisu/opsu/states/MainMenu.java | 52 ++++++++++++++------ src/itdelatrisu/opsu/states/SongMenu.java | 2 + 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/itdelatrisu/opsu/states/GameRanking.java b/src/itdelatrisu/opsu/states/GameRanking.java index 991b1c48..94566651 100644 --- a/src/itdelatrisu/opsu/states/GameRanking.java +++ b/src/itdelatrisu/opsu/states/GameRanking.java @@ -176,6 +176,7 @@ public class GameRanking extends BasicGameState { game.enterState(Opsu.STATE_GAME, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } else if (exitButton.contains(x, y)) { SoundController.playSound(SoundController.SOUND_MENUBACK); + ((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset(); game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } else if (Utils.getBackButton().contains(x, y)) { MusicController.pause(); diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index 028bfeba..bcfdd524 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -156,6 +156,8 @@ public class MainMenu extends BasicGameState { musicNext.setHoverScale(1.5f); musicPrevious.setHoverScale(1.5f); + reset(); + // menu background try { backgroundImage = new Image("menu-background.jpg").getScaledCopy(width, height); @@ -294,16 +296,22 @@ public class MainMenu extends BasicGameState { @Override public void enter(GameContainer container, StateBasedGame game) throws SlickException { - logoClicked = false; - logoTimer = 0; - logo.setX(container.getWidth() / 2); - logo.setScale(1f); - playButton.setScale(1f); - exitButton.setScale(1f); - musicPlay.setScale(1f); - musicPause.setScale(1f); - musicNext.setScale(1f); - musicPrevious.setScale(1f); + // reset button hover states if mouse is not currently hovering over the button + int mouseX = input.getMouseX(), mouseY = input.getMouseY(); + if (!logo.contains(mouseX, mouseY)) + logo.setScale(1f); + if (!playButton.contains(mouseX, mouseY)) + playButton.setScale(1f); + if (!exitButton.contains(mouseX, mouseY)) + exitButton.setScale(1f); + if (!musicPlay.contains(mouseX, mouseY)) + musicPlay.setScale(1f); + if (!musicPause.contains(mouseX, mouseY)) + musicPause.setScale(1f); + if (!musicNext.contains(mouseX, mouseY)) + musicNext.setScale(1f); + if (!musicPrevious.contains(mouseX, mouseY)) + musicPrevious.setScale(1f); } @Override @@ -368,11 +376,6 @@ public class MainMenu extends BasicGameState { public void keyPressed(int key, char c) { switch (key) { case Input.KEY_ESCAPE: - if (logoClicked) - logoTimer = MOVE_DELAY; - else - game.enterState(Opsu.STATE_MAINMENUEXIT); - break; case Input.KEY_Q: game.enterState(Opsu.STATE_MAINMENUEXIT); break; @@ -392,6 +395,23 @@ public class MainMenu extends BasicGameState { Utils.takeScreenShot(); break; } - + } + + /** + * Resets the button states. + */ + public void reset() { + // reset logo + logo.setX(container.getWidth() / 2); + logoClicked = false; + logoTimer = 0; + + logo.setScale(1f); + playButton.setScale(1f); + exitButton.setScale(1f); + musicPlay.setScale(1f); + musicPause.setScale(1f); + musicNext.setScale(1f); + musicPrevious.setScale(1f); } } diff --git a/src/itdelatrisu/opsu/states/SongMenu.java b/src/itdelatrisu/opsu/states/SongMenu.java index e397866c..26cf0cd0 100644 --- a/src/itdelatrisu/opsu/states/SongMenu.java +++ b/src/itdelatrisu/opsu/states/SongMenu.java @@ -352,6 +352,7 @@ public class SongMenu extends BasicGameState { // back if (Utils.getBackButton().contains(x, y)) { SoundController.playSound(SoundController.SOUND_MENUBACK); + ((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset(); game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); return; } @@ -424,6 +425,7 @@ public class SongMenu extends BasicGameState { searchTimer = SEARCH_DELAY; } else { SoundController.playSound(SoundController.SOUND_MENUBACK); + ((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset(); game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); } break;