convert gamepausemenu

This commit is contained in:
yugecin 2017-01-19 19:43:47 +01:00
parent a3df6e12d6
commit 2d0e2143d1
4 changed files with 94 additions and 94 deletions

View File

@ -90,7 +90,7 @@ public class Opsu extends StateBasedGame {
//addState(new ButtonMenu(STATE_BUTTONMENU)); //addState(new ButtonMenu(STATE_BUTTONMENU));
//addState(new SongMenu(STATE_SONGMENU)); //addState(new SongMenu(STATE_SONGMENU));
//addState(new Game(STATE_GAME)); //addState(new Game(STATE_GAME));
addState(new GamePauseMenu(STATE_GAMEPAUSEMENU)); //addState(new GamePauseMenu(STATE_GAMEPAUSEMENU));
//addState(new GameRanking(STATE_GAMERANKING)); //addState(new GameRanking(STATE_GAMERANKING));
//addState(new OptionsMenu(STATE_OPTIONSMENU)); //addState(new OptionsMenu(STATE_OPTIONSMENU));
//addState(new DownloadsMenu(STATE_DOWNLOADSMENU)); //addState(new DownloadsMenu(STATE_DOWNLOADSMENU));

View File

@ -66,6 +66,8 @@ import yugecin.opsudance.*;
import yugecin.opsudance.core.DisplayContainer; import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.inject.InstanceContainer; import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.core.state.ComplexOpsuState; import yugecin.opsudance.core.state.ComplexOpsuState;
import yugecin.opsudance.core.state.transitions.FadeInTransitionState;
import yugecin.opsudance.core.state.transitions.FadeOutTransitionState;
import yugecin.opsudance.events.BubbleNotificationEvent; import yugecin.opsudance.events.BubbleNotificationEvent;
import yugecin.opsudance.objects.curves.FakeCombinedCurve; import yugecin.opsudance.objects.curves.FakeCombinedCurve;
import yugecin.opsudance.sbv2.MoveStoryboard; import yugecin.opsudance.sbv2.MoveStoryboard;
@ -802,7 +804,7 @@ public class Game extends ComplexOpsuState {
// focus lost: go back to pause screen // focus lost: go back to pause screen
else if (!Display.isActive()) { else if (!Display.isActive()) {
// TODO d displayContainer.switchState(GamePauseMenu.class); displayContainer.switchStateNow(GamePauseMenu.class);
pausePulse = 0f; pausePulse = 0f;
} }
@ -1034,7 +1036,7 @@ public class Game extends ComplexOpsuState {
if (MusicController.isPlaying() || isLeadIn()) { if (MusicController.isPlaying() || isLeadIn()) {
pauseTime = trackPosition; pauseTime = trackPosition;
} }
// TODO d displayContainer.switchState(GamePauseMenu.class); displayContainer.switchStateNow(GamePauseMenu.class);
} }
// drain health // drain health
@ -1061,7 +1063,7 @@ public class Game extends ComplexOpsuState {
rotations = new IdentityHashMap<>(); rotations = new IdentityHashMap<>();
SoundController.playSound(SoundEffect.FAIL); SoundController.playSound(SoundEffect.FAIL);
// TODO d displayContainer.switchState(GamePauseMenu.class, FadeOutTransitionState.class, MUSIC_FADEOUT_TIME - LOSE_FADEOUT_TIME, FadeInTransitionState.class, 300); displayContainer.switchState(GamePauseMenu.class, FadeOutTransitionState.class, MUSIC_FADEOUT_TIME - LOSE_FADEOUT_TIME, FadeInTransitionState.class, 300);
} }
} }
} }
@ -1143,7 +1145,7 @@ public class Game extends ComplexOpsuState {
if (MusicController.isPlaying() || isLeadIn()) { if (MusicController.isPlaying() || isLeadIn()) {
pauseTime = trackPosition; pauseTime = trackPosition;
} }
// TODO d displayContainer.switchStateNow(GamePauseMenu.class); displayContainer.switchStateNow(GamePauseMenu.class);
break; break;
case Input.KEY_SPACE: case Input.KEY_SPACE:
// skip intro // skip intro
@ -1296,7 +1298,7 @@ public class Game extends ComplexOpsuState {
if (MusicController.isPlaying() || isLeadIn()) { if (MusicController.isPlaying() || isLeadIn()) {
pauseTime = trackPosition; pauseTime = trackPosition;
} }
// TODO d displayContainer.switchStateNow(GamePauseMenu.class); displayContainer.switchStateNow(GamePauseMenu.class);
return true; return true;
} }
@ -1973,7 +1975,7 @@ public class Game extends ComplexOpsuState {
skipButton.setHoverExpand(1.1f, MenuButton.Expand.UP_LEFT); skipButton.setHoverExpand(1.1f, MenuButton.Expand.UP_LEFT);
// load other images... // load other images...
// TODO d instanceContainer.provide(GamePauseMenu.class).loadImages(); instanceContainer.provide(GamePauseMenu.class).loadImages();
data.loadImages(); data.loadImages();
} }

View File

@ -19,9 +19,7 @@
package itdelatrisu.opsu.states; package itdelatrisu.opsu.states;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Opsu;
import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.audio.MusicController; import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.audio.SoundController; import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect; import itdelatrisu.opsu.audio.SoundEffect;
@ -31,14 +29,11 @@ import itdelatrisu.opsu.ui.animations.AnimationEquation;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException; import yugecin.opsudance.core.DisplayContainer;
import org.newdawn.slick.state.BasicGameState; import yugecin.opsudance.core.inject.InstanceContainer;
import org.newdawn.slick.state.StateBasedGame; import yugecin.opsudance.core.state.BaseOpsuState;
import org.newdawn.slick.state.transition.FadeInTransition;
import org.newdawn.slick.state.transition.EasedFadeOutTransition;
/** /**
* "Game Pause/Fail" state. * "Game Pause/Fail" state.
@ -46,33 +41,22 @@ import org.newdawn.slick.state.transition.EasedFadeOutTransition;
* Players are able to continue the game (if applicable), retry the beatmap, * Players are able to continue the game (if applicable), retry the beatmap,
* or return to the song menu from this state. * or return to the song menu from this state.
*/ */
public class GamePauseMenu extends BasicGameState { public class GamePauseMenu extends BaseOpsuState {
/** "Continue", "Retry", and "Back" buttons. */
private final InstanceContainer instanceContainer;
private MenuButton continueButton, retryButton, backButton; private MenuButton continueButton, retryButton, backButton;
// game-related variables private final Game gameState;
private GameContainer container;
private StateBasedGame game;
private Input input;
private final int state;
private Game gameState;
public GamePauseMenu(int state) { public GamePauseMenu(DisplayContainer displayContainer, InstanceContainer instanceContainer, Game gameState) {
this.state = state; super(displayContainer);
this.instanceContainer = instanceContainer;
this.gameState = gameState;
} }
@Override @Override
public void init(GameContainer container, StateBasedGame game) public void render(Graphics g) {
throws SlickException {
this.container = container;
this.game = game;
this.input = container.getInput();
this.gameState = (Game) game.getState(Opsu.STATE_GAME);
}
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g)
throws SlickException {
// get background image // get background image
GameImage bg = (gameState.getRestart() == Game.Restart.LOSE) ? GameImage bg = (gameState.getRestart() == Game.Restart.LOSE) ?
GameImage.FAIL_BACKGROUND : GameImage.PAUSE_OVERLAY; GameImage.FAIL_BACKGROUND : GameImage.PAUSE_OVERLAY;
@ -97,81 +81,78 @@ public class GamePauseMenu extends BasicGameState {
} }
@Override @Override
public void update(GameContainer container, StateBasedGame game, int delta) public void preRenderUpdate() {
throws SlickException { int delta = displayContainer.renderDelta;
UI.update(delta); UI.update(delta);
int mouseX = input.getMouseX(), mouseY = input.getMouseY(); continueButton.hoverUpdate(delta, displayContainer.mouseX, displayContainer.mouseY);
continueButton.hoverUpdate(delta, mouseX, mouseY); retryButton.hoverUpdate(delta, displayContainer.mouseX, displayContainer.mouseY);
retryButton.hoverUpdate(delta, mouseX, mouseY); backButton.hoverUpdate(delta, displayContainer.mouseX, displayContainer.mouseY);
backButton.hoverUpdate(delta, mouseX, mouseY);
} }
@Override @Override
public int getID() { return state; } public boolean keyPressed(int key, char c) {
if (super.keyPressed(key, c)) {
@Override return true;
public void keyPressed(int key, char c) {
// 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());
} }
switch (key) { // game keys
case Input.KEY_ESCAPE: if (!Keyboard.isRepeatEvent()) {
if (key == Options.getGameKeyLeft()) {
mousePressed(Input.MOUSE_LEFT_BUTTON, displayContainer.mouseX, displayContainer.mouseY);
} else if (key == Options.getGameKeyRight()) {
mousePressed(Input.MOUSE_RIGHT_BUTTON, displayContainer.mouseX, displayContainer.mouseY);
}
}
if (key == Input.KEY_ESCAPE) {
// 'esc' will normally unpause, but will return to song menu if health is zero // 'esc' will normally unpause, but will return to song menu if health is zero
if (gameState.getRestart() == Game.Restart.LOSE) { if (gameState.getRestart() == Game.Restart.LOSE) {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad(); instanceContainer.provide(SongMenu.class).resetGameDataOnLoad();
MusicController.playAt(MusicController.getBeatmap().previewTime, true); MusicController.playAt(MusicController.getBeatmap().previewTime, true);
if (UI.getCursor().isBeatmapSkinned()) if (UI.getCursor().isBeatmapSkinned()) {
UI.getCursor().reset(); UI.getCursor().reset();
game.enterState(Opsu.STATE_SONGMENU, new EasedFadeOutTransition(), new FadeInTransition()); }
displayContainer.switchState(SongMenu.class);
} else { } else {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
gameState.setRestart(Game.Restart.FALSE); gameState.setRestart(Game.Restart.FALSE);
game.enterState(Opsu.STATE_GAME); displayContainer.switchState(Game.class);
} }
break; return true;
case Input.KEY_R:
// restart
if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
gameState.setRestart(Game.Restart.MANUAL);
game.enterState(Opsu.STATE_GAME);
}
break;
case Input.KEY_F7:
// TODO d
//Options.setNextFPS(container);
break;
case Input.KEY_F10:
Options.toggleMouseDisabled();
break;
case Input.KEY_F12:
Utils.takeScreenShot();
break;
} }
if (key == Input.KEY_R && (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL))) {
gameState.setRestart(Game.Restart.MANUAL);
displayContainer.switchState(Game.class);
return true;
}
return false;
} }
@Override @Override
public void mousePressed(int button, int x, int y) { public boolean mousePressed(int button, int x, int y) {
if (button == Input.MOUSE_MIDDLE_BUTTON) if (super.mousePressed(button, x, y)) {
return; return true;
}
if (button == Input.MOUSE_MIDDLE_BUTTON) {
return true;
}
boolean loseState = (gameState.getRestart() == Game.Restart.LOSE); boolean loseState = (gameState.getRestart() == Game.Restart.LOSE);
if (continueButton.contains(x, y) && !loseState) { if (continueButton.contains(x, y) && !loseState) {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
gameState.setRestart(Game.Restart.FALSE); gameState.setRestart(Game.Restart.FALSE);
game.enterState(Opsu.STATE_GAME); displayContainer.switchState(Game.class);
} else if (retryButton.contains(x, y)) { } else if (retryButton.contains(x, y)) {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
gameState.setRestart(Game.Restart.MANUAL); gameState.setRestart(Game.Restart.MANUAL);
game.enterState(Opsu.STATE_GAME); displayContainer.switchState(Game.class);
} else if (backButton.contains(x, y)) { } else if (backButton.contains(x, y)) {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad(); instanceContainer.provide(SongMenu.class).resetGameDataOnLoad();
if (loseState) if (loseState)
MusicController.playAt(MusicController.getBeatmap().previewTime, true); MusicController.playAt(MusicController.getBeatmap().previewTime, true);
else else
@ -179,21 +160,30 @@ public class GamePauseMenu extends BasicGameState {
if (UI.getCursor().isBeatmapSkinned()) if (UI.getCursor().isBeatmapSkinned())
UI.getCursor().reset(); UI.getCursor().reset();
MusicController.setPitch(1.0f); MusicController.setPitch(1.0f);
game.enterState(Opsu.STATE_SONGMENU, new EasedFadeOutTransition(), new FadeInTransition()); displayContainer.switchState(SongMenu.class);
} }
return true;
} }
@Override @Override
public void mouseWheelMoved(int newValue) { public boolean mouseWheelMoved(int newValue) {
if (Options.isMouseWheelDisabled()) if (super.mouseWheelMoved(newValue)) {
return; return true;
}
if (Options.isMouseWheelDisabled()) {
return true;
}
UI.changeVolume((newValue < 0) ? -1 : 1); UI.changeVolume((newValue < 0) ? -1 : 1);
return true;
} }
@Override @Override
public void enter(GameContainer container, StateBasedGame game) public void enter() {
throws SlickException { super.enter();
UI.enter(); UI.enter();
MusicController.pause(); MusicController.pause();
continueButton.resetHover(); continueButton.resetHover();
@ -201,17 +191,23 @@ public class GamePauseMenu extends BasicGameState {
backButton.resetHover(); backButton.resetHover();
} }
@Override
public boolean onCloseRequest() {
SongMenu songmenu = instanceContainer.provide(SongMenu.class);
songmenu.resetTrackOnLoad();
songmenu.resetGameDataOnLoad();
displayContainer.switchState(SongMenu.class);
return false;
}
/** /**
* Loads all game pause/fail menu images. * Loads all game pause/fail menu images.
*/ */
public void loadImages() { public void loadImages() {
int width = container.getWidth();
int height = container.getHeight();
// initialize buttons // initialize buttons
continueButton = new MenuButton(GameImage.PAUSE_CONTINUE.getImage(), width / 2f, height * 0.25f); continueButton = new MenuButton(GameImage.PAUSE_CONTINUE.getImage(), displayContainer.width / 2f, displayContainer.height * 0.25f);
retryButton = new MenuButton(GameImage.PAUSE_RETRY.getImage(), width / 2f, height * 0.5f); retryButton = new MenuButton(GameImage.PAUSE_RETRY.getImage(), displayContainer.width / 2f, displayContainer.height * 0.5f);
backButton = new MenuButton(GameImage.PAUSE_BACK.getImage(), width / 2f, height * 0.75f); backButton = new MenuButton(GameImage.PAUSE_BACK.getImage(), displayContainer.width / 2f, displayContainer.height * 0.75f);
final int buttonAnimationDuration = 300; final int buttonAnimationDuration = 300;
continueButton.setHoverAnimationDuration(buttonAnimationDuration); continueButton.setHoverAnimationDuration(buttonAnimationDuration);
retryButton.setHoverAnimationDuration(buttonAnimationDuration); retryButton.setHoverAnimationDuration(buttonAnimationDuration);
@ -224,4 +220,5 @@ public class GamePauseMenu extends BasicGameState {
retryButton.setHoverExpand(); retryButton.setHoverExpand();
backButton.setHoverExpand(); backButton.setHoverExpand();
} }
} }

View File

@ -59,6 +59,7 @@ public class OpsuDanceInjector extends Injector {
bind(DownloadsMenu.class).asEagerSingleton(); bind(DownloadsMenu.class).asEagerSingleton();
bind(GameRanking.class).asEagerSingleton(); bind(GameRanking.class).asEagerSingleton();
bind(Game.class).asEagerSingleton(); bind(Game.class).asEagerSingleton();
bind(GamePauseMenu.class).asEagerSingleton();
} }
} }