convert gameranking

This commit is contained in:
yugecin 2017-01-19 16:16:30 +01:00
parent e7eec14341
commit 4b2f29df98
2 changed files with 75 additions and 90 deletions

View File

@ -91,7 +91,7 @@ public class Opsu extends StateBasedGame {
//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

@ -21,9 +21,6 @@ package itdelatrisu.opsu.states;
import itdelatrisu.opsu.GameData; import itdelatrisu.opsu.GameData;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.GameMod; import itdelatrisu.opsu.GameMod;
import itdelatrisu.opsu.Opsu;
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;
@ -35,17 +32,13 @@ import itdelatrisu.opsu.ui.UI;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import org.lwjgl.opengl.Display;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import org.newdawn.slick.Input; 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.EasedFadeOutTransition;
import org.newdawn.slick.util.Log; import org.newdawn.slick.util.Log;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.core.state.BaseOpsuState;
/** /**
* "Game Ranking" (score card) state. * "Game Ranking" (score card) state.
@ -54,7 +47,10 @@ import org.newdawn.slick.util.Log;
* or watch a replay of the game from this state. * or watch a replay of the game from this state.
* </ul> * </ul>
*/ */
public class GameRanking extends BasicGameState { public class GameRanking extends BaseOpsuState {
private final InstanceContainer instanceContainer;
/** Associated GameData object. */ /** Associated GameData object. */
private GameData data; private GameData data;
@ -64,48 +60,34 @@ public class GameRanking extends BasicGameState {
/** Button coordinates. */ /** Button coordinates. */
private float retryY, replayY; private float retryY, replayY;
// game-related variables public GameRanking(DisplayContainer displayContainer, InstanceContainer instanceContainer) {
private GameContainer container; super(displayContainer);
private StateBasedGame game; this.instanceContainer = instanceContainer;
private final int state;
private Input input;
public GameRanking(int state) {
this.state = state;
} }
@Override @Override
public void init(GameContainer container, StateBasedGame game) public void revalidate() {
throws SlickException { super.revalidate();
this.container = container;
this.game = game;
this.input = container.getInput();
int width = container.getWidth();
int height = container.getHeight();
// buttons // buttons
Image retry = GameImage.PAUSE_RETRY.getImage(); Image retry = GameImage.PAUSE_RETRY.getImage();
Image replay = GameImage.PAUSE_REPLAY.getImage(); Image replay = GameImage.PAUSE_REPLAY.getImage();
replayY = (height * 0.985f) - replay.getHeight() / 2f; replayY = (displayContainer.height * 0.985f) - replay.getHeight() / 2f;
retryY = replayY - (replay.getHeight() / 2f) - (retry.getHeight() / 1.975f); retryY = replayY - (replay.getHeight() / 2f) - (retry.getHeight() / 1.975f);
retryButton = new MenuButton(retry, width - (retry.getWidth() / 2f), retryY); retryButton = new MenuButton(retry, displayContainer.width - (retry.getWidth() / 2f), retryY);
replayButton = new MenuButton(replay, width - (replay.getWidth() / 2f), replayY); replayButton = new MenuButton(replay, displayContainer.width - (replay.getWidth() / 2f), replayY);
retryButton.setHoverFade(); retryButton.setHoverFade();
replayButton.setHoverFade(); replayButton.setHoverFade();
} }
@Override @Override
public void render(GameContainer container, StateBasedGame game, Graphics g) public void render(Graphics g) {
throws SlickException {
int width = container.getWidth();
int height = container.getHeight();
Beatmap beatmap = MusicController.getBeatmap(); Beatmap beatmap = MusicController.getBeatmap();
// background // background
if (!beatmap.drawBackground(width, height, 0.7f, true)) if (!beatmap.drawBackground(displayContainer.width, displayContainer.height, 0.7f, true)) {
GameImage.PLAYFIELD.getImage().draw(0, 0); GameImage.PLAYFIELD.getImage().draw(0, 0);
}
// ranking screen elements // ranking screen elements
data.drawRankingElements(g, beatmap); data.drawRankingElements(g, beatmap);
@ -117,63 +99,62 @@ public class GameRanking extends BasicGameState {
UI.getBackButton().draw(); UI.getBackButton().draw();
UI.draw(g); UI.draw(g);
super.render(g);
} }
@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(); replayButton.hoverUpdate(delta, displayContainer.mouseX, displayContainer.mouseY);
replayButton.hoverUpdate(delta, mouseX, mouseY); if (data.isGameplay()) {
if (data.isGameplay()) retryButton.hoverUpdate(delta, displayContainer.mouseX, displayContainer.mouseY);
retryButton.hoverUpdate(delta, mouseX, mouseY); } else {
else
MusicController.loopTrackIfEnded(true); MusicController.loopTrackIfEnded(true);
UI.getBackButton().hoverUpdate(delta, mouseX, mouseY); }
UI.getBackButton().hoverUpdate(delta, displayContainer.mouseX, displayContainer.mouseY);
} }
@Override @Override
public int getID() { return state; } public boolean mouseWheelMoved(int newValue) {
if (displayContainer.input.isKeyDown(Input.KEY_LALT) || displayContainer.input.isKeyDown(Input.KEY_RALT)) {
@Override
public void mouseWheelMoved(int newValue) {
if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT))
UI.changeVolume((newValue < 0) ? -1 : 1); UI.changeVolume((newValue < 0) ? -1 : 1);
} }
return true;
}
@Override @Override
public void keyPressed(int key, char c) { public boolean keyPressed(int key, char c) {
switch (key) { if (super.keyPressed(key, c)) {
case Input.KEY_ESCAPE: return true;
}
if (key == Input.KEY_ESCAPE) {
returnToSongMenu(); returnToSongMenu();
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;
} }
return true;
} }
@Override @Override
public void mousePressed(int button, int x, int y) { public boolean mousePressed(int button, int x, int y) {
if (super.mousePressed(button, x, y)) {
return true;
}
// check mouse button // check mouse button
if (button == Input.MOUSE_MIDDLE_BUTTON) if (button == Input.MOUSE_MIDDLE_BUTTON) {
return; return false;
}
// back to menu // back to menu
if (UI.getBackButton().contains(x, y)) { if (UI.getBackButton().contains(x, y)) {
returnToSongMenu(); returnToSongMenu();
return; return true;
} }
// replay // replay
Game gameState = (Game) game.getState(Opsu.STATE_GAME); Game gameState = instanceContainer.provide(Game.class);
boolean returnToGame = false; boolean returnToGame = false;
boolean replayButtonPressed = replayButton.contains(x, y); boolean replayButtonPressed = replayButton.contains(x, y);
if (replayButtonPressed && !(data.isGameplay() && GameMod.AUTO.isActive())) { if (replayButtonPressed && !(data.isGameplay() && GameMod.AUTO.isActive())) {
@ -207,16 +188,16 @@ public class GameRanking extends BasicGameState {
Beatmap beatmap = MusicController.getBeatmap(); Beatmap beatmap = MusicController.getBeatmap();
gameState.loadBeatmap(beatmap); gameState.loadBeatmap(beatmap);
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
game.enterState(Opsu.STATE_GAME, new EasedFadeOutTransition(), new FadeInTransition()); // TODO d displayContainer.switchState(Game.class);
return;
} }
return true;
} }
@Override @Override
public void enter(GameContainer container, StateBasedGame game) public void enter() {
throws SlickException { super.enter();
UI.enter(); UI.enter();
Display.setTitle(game.getTitle());
if (!data.isGameplay()) { if (!data.isGameplay()) {
if (!MusicController.isTrackDimmed()) if (!MusicController.isTrackDimmed())
MusicController.toggleTrackDimmed(0.5f); MusicController.toggleTrackDimmed(0.5f);
@ -230,12 +211,14 @@ public class GameRanking extends BasicGameState {
} }
@Override @Override
public void leave(GameContainer container, StateBasedGame game) public void leave() {
throws SlickException { super.leave();
this.data = null; this.data = null;
if (MusicController.isTrackDimmed()) if (MusicController.isTrackDimmed()) {
MusicController.toggleTrackDimmed(1f); MusicController.toggleTrackDimmed(1f);
} }
}
/** /**
* Returns to the song menu. * Returns to the song menu.
@ -243,13 +226,15 @@ public class GameRanking extends BasicGameState {
private void returnToSongMenu() { private void returnToSongMenu() {
SoundController.muteSoundComponent(); SoundController.muteSoundComponent();
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
SongMenu songMenu = (SongMenu) game.getState(Opsu.STATE_SONGMENU); SongMenu songMenu = instanceContainer.provide(SongMenu.class);
if (data.isGameplay()) if (data.isGameplay()) {
songMenu.resetTrackOnLoad(); songMenu.resetTrackOnLoad();
}
songMenu.resetGameDataOnLoad(); songMenu.resetGameDataOnLoad();
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);
} }
/** /**