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 Game(STATE_GAME));
addState(new GamePauseMenu(STATE_GAMEPAUSEMENU));
addState(new GameRanking(STATE_GAMERANKING));
//addState(new GameRanking(STATE_GAMERANKING));
//addState(new OptionsMenu(STATE_OPTIONSMENU));
//addState(new DownloadsMenu(STATE_DOWNLOADSMENU));
}

View File

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