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 <itdelatrisu@gmail.com>
This commit is contained in:
parent
2592faec44
commit
b0649541eb
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user