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));
|
game.enterState(Opsu.STATE_GAME, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||||
} else if (exitButton.contains(x, y)) {
|
} else if (exitButton.contains(x, y)) {
|
||||||
SoundController.playSound(SoundController.SOUND_MENUBACK);
|
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));
|
game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||||
} else if (Utils.getBackButton().contains(x, y)) {
|
} else if (Utils.getBackButton().contains(x, y)) {
|
||||||
MusicController.pause();
|
MusicController.pause();
|
||||||
|
|
|
@ -156,6 +156,8 @@ public class MainMenu extends BasicGameState {
|
||||||
musicNext.setHoverScale(1.5f);
|
musicNext.setHoverScale(1.5f);
|
||||||
musicPrevious.setHoverScale(1.5f);
|
musicPrevious.setHoverScale(1.5f);
|
||||||
|
|
||||||
|
reset();
|
||||||
|
|
||||||
// menu background
|
// menu background
|
||||||
try {
|
try {
|
||||||
backgroundImage = new Image("menu-background.jpg").getScaledCopy(width, height);
|
backgroundImage = new Image("menu-background.jpg").getScaledCopy(width, height);
|
||||||
|
@ -294,15 +296,21 @@ public class MainMenu extends BasicGameState {
|
||||||
@Override
|
@Override
|
||||||
public void enter(GameContainer container, StateBasedGame game)
|
public void enter(GameContainer container, StateBasedGame game)
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
logoClicked = false;
|
// reset button hover states if mouse is not currently hovering over the button
|
||||||
logoTimer = 0;
|
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
||||||
logo.setX(container.getWidth() / 2);
|
if (!logo.contains(mouseX, mouseY))
|
||||||
logo.setScale(1f);
|
logo.setScale(1f);
|
||||||
|
if (!playButton.contains(mouseX, mouseY))
|
||||||
playButton.setScale(1f);
|
playButton.setScale(1f);
|
||||||
|
if (!exitButton.contains(mouseX, mouseY))
|
||||||
exitButton.setScale(1f);
|
exitButton.setScale(1f);
|
||||||
|
if (!musicPlay.contains(mouseX, mouseY))
|
||||||
musicPlay.setScale(1f);
|
musicPlay.setScale(1f);
|
||||||
|
if (!musicPause.contains(mouseX, mouseY))
|
||||||
musicPause.setScale(1f);
|
musicPause.setScale(1f);
|
||||||
|
if (!musicNext.contains(mouseX, mouseY))
|
||||||
musicNext.setScale(1f);
|
musicNext.setScale(1f);
|
||||||
|
if (!musicPrevious.contains(mouseX, mouseY))
|
||||||
musicPrevious.setScale(1f);
|
musicPrevious.setScale(1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,11 +376,6 @@ public class MainMenu extends BasicGameState {
|
||||||
public void keyPressed(int key, char c) {
|
public void keyPressed(int key, char c) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case Input.KEY_ESCAPE:
|
case Input.KEY_ESCAPE:
|
||||||
if (logoClicked)
|
|
||||||
logoTimer = MOVE_DELAY;
|
|
||||||
else
|
|
||||||
game.enterState(Opsu.STATE_MAINMENUEXIT);
|
|
||||||
break;
|
|
||||||
case Input.KEY_Q:
|
case Input.KEY_Q:
|
||||||
game.enterState(Opsu.STATE_MAINMENUEXIT);
|
game.enterState(Opsu.STATE_MAINMENUEXIT);
|
||||||
break;
|
break;
|
||||||
|
@ -392,6 +395,23 @@ public class MainMenu extends BasicGameState {
|
||||||
Utils.takeScreenShot();
|
Utils.takeScreenShot();
|
||||||
break;
|
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
|
// back
|
||||||
if (Utils.getBackButton().contains(x, y)) {
|
if (Utils.getBackButton().contains(x, y)) {
|
||||||
SoundController.playSound(SoundController.SOUND_MENUBACK);
|
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));
|
game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -424,6 +425,7 @@ public class SongMenu extends BasicGameState {
|
||||||
searchTimer = SEARCH_DELAY;
|
searchTimer = SEARCH_DELAY;
|
||||||
} else {
|
} else {
|
||||||
SoundController.playSound(SoundController.SOUND_MENUBACK);
|
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));
|
game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user