2014-06-30 04:17:04 +02:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
2015-01-16 18:05:44 +01:00
|
|
|
* Copyright (C) 2014, 2015 Jeffrey Han
|
2014-06-30 04:17:04 +02:00
|
|
|
*
|
|
|
|
* opsu! is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* opsu! is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with opsu!. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package itdelatrisu.opsu.states;
|
|
|
|
|
2014-07-04 22:41:52 +02:00
|
|
|
import itdelatrisu.opsu.GameImage;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.Opsu;
|
2015-01-21 05:56:10 +01:00
|
|
|
import itdelatrisu.opsu.Options;
|
2014-07-02 01:32:03 +02:00
|
|
|
import itdelatrisu.opsu.Utils;
|
2015-01-08 01:29:51 +01:00
|
|
|
import itdelatrisu.opsu.audio.MusicController;
|
|
|
|
import itdelatrisu.opsu.audio.SoundController;
|
|
|
|
import itdelatrisu.opsu.audio.SoundEffect;
|
2015-05-29 07:55:57 +02:00
|
|
|
import itdelatrisu.opsu.ui.MenuButton;
|
|
|
|
import itdelatrisu.opsu.ui.UI;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2014-07-18 05:58:37 +02:00
|
|
|
import org.lwjgl.input.Keyboard;
|
2014-06-30 04:17:04 +02:00
|
|
|
import org.newdawn.slick.Color;
|
|
|
|
import org.newdawn.slick.GameContainer;
|
|
|
|
import org.newdawn.slick.Graphics;
|
|
|
|
import org.newdawn.slick.Input;
|
|
|
|
import org.newdawn.slick.SlickException;
|
|
|
|
import org.newdawn.slick.state.BasicGameState;
|
|
|
|
import org.newdawn.slick.state.StateBasedGame;
|
|
|
|
import org.newdawn.slick.state.transition.FadeInTransition;
|
|
|
|
import org.newdawn.slick.state.transition.FadeOutTransition;
|
|
|
|
|
|
|
|
/**
|
2014-07-04 22:41:52 +02:00
|
|
|
* "Game Pause/Fail" state.
|
2014-06-30 04:17:04 +02:00
|
|
|
* <ul>
|
|
|
|
* <li>[Continue] - unpause game (return to game state)
|
|
|
|
* <li>[Retry] - restart game (return to game state)
|
|
|
|
* <li>[Back] - return to song menu state
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
public class GamePauseMenu extends BasicGameState {
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Music fade-out time, in milliseconds. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private static final int FADEOUT_TIME = 1000;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Track position when the pause menu was loaded (for FADEOUT_TIME). */
|
2014-06-30 04:17:04 +02:00
|
|
|
private long pauseStartTime;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** "Continue", "Retry", and "Back" buttons. */
|
2014-12-30 06:00:58 +01:00
|
|
|
private MenuButton continueButton, retryButton, backButton;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// game-related variables
|
2014-07-04 22:41:52 +02:00
|
|
|
private GameContainer container;
|
2014-07-18 05:58:37 +02:00
|
|
|
private StateBasedGame game;
|
|
|
|
private Input input;
|
2014-06-30 04:17:04 +02:00
|
|
|
private int state;
|
2015-01-15 05:57:50 +01:00
|
|
|
private Game gameState;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
public GamePauseMenu(int state) {
|
|
|
|
this.state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void init(GameContainer container, StateBasedGame game)
|
|
|
|
throws SlickException {
|
2014-07-04 22:41:52 +02:00
|
|
|
this.container = container;
|
2014-06-30 04:17:04 +02:00
|
|
|
this.game = game;
|
2015-01-15 05:57:50 +01:00
|
|
|
this.input = container.getInput();
|
|
|
|
this.gameState = (Game) game.getState(Opsu.STATE_GAME);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render(GameContainer container, StateBasedGame game, Graphics g)
|
|
|
|
throws SlickException {
|
2015-01-16 00:16:46 +01:00
|
|
|
// get background image
|
|
|
|
GameImage bg = (gameState.getRestart() == Game.Restart.LOSE) ?
|
|
|
|
GameImage.FAIL_BACKGROUND : GameImage.PAUSE_OVERLAY;
|
|
|
|
|
|
|
|
// don't draw default background if button skinned and background unskinned
|
|
|
|
boolean buttonsSkinned =
|
|
|
|
GameImage.PAUSE_CONTINUE.hasSkinImage() ||
|
|
|
|
GameImage.PAUSE_RETRY.hasSkinImage() ||
|
|
|
|
GameImage.PAUSE_BACK.hasSkinImage();
|
|
|
|
if (!buttonsSkinned || bg.hasSkinImage())
|
|
|
|
bg.getImage().draw();
|
2014-06-30 04:17:04 +02:00
|
|
|
else
|
2015-01-16 00:16:46 +01:00
|
|
|
g.setBackground(Color.black);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// draw buttons
|
2015-01-15 06:56:30 +01:00
|
|
|
if (gameState.getRestart() != Game.Restart.LOSE)
|
2014-06-30 04:17:04 +02:00
|
|
|
continueButton.draw();
|
|
|
|
retryButton.draw();
|
|
|
|
backButton.draw();
|
2014-07-02 01:32:03 +02:00
|
|
|
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.draw(g);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(GameContainer container, StateBasedGame game, int delta)
|
|
|
|
throws SlickException {
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.update(delta);
|
2014-12-24 05:41:37 +01:00
|
|
|
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
|
|
|
continueButton.hoverUpdate(delta, mouseX, mouseY);
|
|
|
|
retryButton.hoverUpdate(delta, mouseX, mouseY);
|
|
|
|
backButton.hoverUpdate(delta, mouseX, mouseY);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getID() { return state; }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyPressed(int key, char c) {
|
2014-07-18 05:58:37 +02:00
|
|
|
// game keys
|
|
|
|
if (!Keyboard.isRepeatEvent()) {
|
|
|
|
if (key == Options.getGameKeyLeft())
|
|
|
|
mousePressed(Input.MOUSE_LEFT_BUTTON, input.getMouseX(), input.getMouseY());
|
|
|
|
else if (key == Options.getGameKeyRight())
|
|
|
|
mousePressed(Input.MOUSE_RIGHT_BUTTON, input.getMouseX(), input.getMouseY());
|
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
switch (key) {
|
|
|
|
case Input.KEY_ESCAPE:
|
|
|
|
// 'esc' will normally unpause, but will return to song menu if health is zero
|
2015-01-15 06:56:30 +01:00
|
|
|
if (gameState.getRestart() == Game.Restart.LOSE) {
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUBACK);
|
2015-01-23 22:06:57 +01:00
|
|
|
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad();
|
2015-05-17 03:25:19 +02:00
|
|
|
MusicController.playAt(MusicController.getBeatmap().previewTime, true);
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.resetCursor();
|
2014-06-30 04:17:04 +02:00
|
|
|
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
2014-12-30 05:35:31 +01:00
|
|
|
} else {
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUBACK);
|
2015-01-15 06:56:30 +01:00
|
|
|
gameState.setRestart(Game.Restart.FALSE);
|
2014-12-30 05:35:31 +01:00
|
|
|
game.enterState(Opsu.STATE_GAME);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Input.KEY_R:
|
|
|
|
// restart
|
|
|
|
if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
|
2015-01-15 06:56:30 +01:00
|
|
|
gameState.setRestart(Game.Restart.MANUAL);
|
2014-12-30 05:35:31 +01:00
|
|
|
game.enterState(Opsu.STATE_GAME);
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
2015-03-05 20:40:57 +01:00
|
|
|
case Input.KEY_F7:
|
|
|
|
Options.setNextFPS(container);
|
|
|
|
break;
|
|
|
|
case Input.KEY_F10:
|
|
|
|
Options.toggleMouseDisabled();
|
|
|
|
break;
|
2014-06-30 04:17:04 +02:00
|
|
|
case Input.KEY_F12:
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.takeScreenShot();
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mousePressed(int button, int x, int y) {
|
2014-07-18 05:58:37 +02:00
|
|
|
if (button == Input.MOUSE_MIDDLE_BUTTON)
|
2014-06-30 04:17:04 +02:00
|
|
|
return;
|
|
|
|
|
2015-01-15 06:56:30 +01:00
|
|
|
boolean loseState = (gameState.getRestart() == Game.Restart.LOSE);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// if music faded out (i.e. health is zero), don't process any actions before FADEOUT_TIME
|
|
|
|
if (loseState && System.currentTimeMillis() - pauseStartTime < FADEOUT_TIME)
|
|
|
|
return;
|
|
|
|
|
2014-12-30 05:35:31 +01:00
|
|
|
if (continueButton.contains(x, y) && !loseState) {
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUBACK);
|
2015-01-15 06:56:30 +01:00
|
|
|
gameState.setRestart(Game.Restart.FALSE);
|
2014-12-30 05:35:31 +01:00
|
|
|
game.enterState(Opsu.STATE_GAME);
|
|
|
|
} else if (retryButton.contains(x, y)) {
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
2015-01-15 06:56:30 +01:00
|
|
|
gameState.setRestart(Game.Restart.MANUAL);
|
2014-12-30 05:35:31 +01:00
|
|
|
game.enterState(Opsu.STATE_GAME);
|
2014-06-30 04:17:04 +02:00
|
|
|
} else if (backButton.contains(x, y)) {
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUBACK);
|
2015-01-23 22:06:57 +01:00
|
|
|
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad();
|
|
|
|
if (loseState)
|
2015-05-17 03:25:19 +02:00
|
|
|
MusicController.playAt(MusicController.getBeatmap().previewTime, true);
|
2015-01-23 22:06:57 +01:00
|
|
|
else
|
|
|
|
MusicController.resume();
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.resetCursor();
|
2014-06-30 04:17:04 +02:00
|
|
|
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 01:40:50 +01:00
|
|
|
@Override
|
|
|
|
public void mouseWheelMoved(int newValue) {
|
|
|
|
if (Options.isMouseWheelDisabled() || Options.isMouseDisabled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
UI.changeVolume((newValue < 0) ? -1 : 1);
|
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
@Override
|
|
|
|
public void enter(GameContainer container, StateBasedGame game)
|
|
|
|
throws SlickException {
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.enter();
|
2014-06-30 04:17:04 +02:00
|
|
|
pauseStartTime = System.currentTimeMillis();
|
2015-01-15 06:56:30 +01:00
|
|
|
if (gameState.getRestart() == Game.Restart.LOSE) {
|
2014-06-30 04:17:04 +02:00
|
|
|
MusicController.fadeOut(FADEOUT_TIME);
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.FAIL);
|
2014-07-01 07:14:03 +02:00
|
|
|
} else
|
2014-06-30 04:17:04 +02:00
|
|
|
MusicController.pause();
|
2015-02-02 06:15:16 +01:00
|
|
|
continueButton.resetHover();
|
|
|
|
retryButton.resetHover();
|
|
|
|
backButton.resetHover();
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-07-04 22:41:52 +02:00
|
|
|
* Loads all game pause/fail menu images.
|
|
|
|
*/
|
|
|
|
public void loadImages() {
|
|
|
|
int width = container.getWidth();
|
|
|
|
int height = container.getHeight();
|
|
|
|
|
|
|
|
// initialize buttons
|
2014-12-30 06:00:58 +01:00
|
|
|
continueButton = new MenuButton(GameImage.PAUSE_CONTINUE.getImage(), width / 2f, height * 0.25f);
|
|
|
|
retryButton = new MenuButton(GameImage.PAUSE_RETRY.getImage(), width / 2f, height * 0.5f);
|
|
|
|
backButton = new MenuButton(GameImage.PAUSE_BACK.getImage(), width / 2f, height * 0.75f);
|
2015-02-02 06:15:16 +01:00
|
|
|
continueButton.setHoverExpand();
|
|
|
|
retryButton.setHoverExpand();
|
|
|
|
backButton.setHoverExpand();
|
2014-07-04 22:41:52 +02:00
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|