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;
|
|
|
|
|
2015-01-27 09:19:39 +01:00
|
|
|
import itdelatrisu.opsu.GameData;
|
2015-01-28 09:47:24 +01:00
|
|
|
import itdelatrisu.opsu.GameImage;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.Opsu;
|
2015-03-05 20:40:57 +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-17 03:25:19 +02:00
|
|
|
import itdelatrisu.opsu.beatmap.Beatmap;
|
2015-03-11 20:53:19 +01:00
|
|
|
import itdelatrisu.opsu.replay.Replay;
|
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
|
|
|
|
2015-03-12 06:18:50 +01:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
import org.lwjgl.opengl.Display;
|
|
|
|
import org.newdawn.slick.Color;
|
|
|
|
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.FadeOutTransition;
|
2015-03-12 06:18:50 +01:00
|
|
|
import org.newdawn.slick.util.Log;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* "Game Ranking" (score card) state.
|
|
|
|
* <ul>
|
|
|
|
* <li>[Retry] - restart game (return to game state)
|
2015-03-11 20:53:19 +01:00
|
|
|
* <li>[Replay] - watch replay (return to game state)
|
2014-06-30 04:17:04 +02:00
|
|
|
* <li>[Back] - return to song menu state
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
public class GameRanking extends BasicGameState {
|
2015-01-27 09:19:39 +01:00
|
|
|
/** Associated GameData object. */
|
|
|
|
private GameData data;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-03-11 20:53:19 +01:00
|
|
|
/** "Retry" and "Replay" buttons. */
|
|
|
|
private MenuButton retryButton, replayButton;
|
|
|
|
|
|
|
|
/** Button coordinates. */
|
|
|
|
private float retryY, replayY;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// game-related variables
|
2015-03-05 20:40:57 +01:00
|
|
|
private GameContainer container;
|
2014-06-30 04:17:04 +02:00
|
|
|
private StateBasedGame game;
|
|
|
|
private int state;
|
2014-12-24 05:41:37 +01:00
|
|
|
private Input input;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
public GameRanking(int state) {
|
|
|
|
this.state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void init(GameContainer container, StateBasedGame game)
|
|
|
|
throws SlickException {
|
2015-03-05 20:40:57 +01:00
|
|
|
this.container = container;
|
2014-06-30 04:17:04 +02:00
|
|
|
this.game = game;
|
2014-12-24 05:41:37 +01:00
|
|
|
this.input = container.getInput();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
int width = container.getWidth();
|
|
|
|
int height = container.getHeight();
|
|
|
|
|
|
|
|
// buttons
|
2015-03-11 20:53:19 +01:00
|
|
|
Image retry = GameImage.PAUSE_RETRY.getImage();
|
|
|
|
Image replay = GameImage.PAUSE_REPLAY.getImage();
|
|
|
|
replayY = (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.setHoverFade();
|
|
|
|
replayButton.setHoverFade();
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render(GameContainer container, StateBasedGame game, Graphics g)
|
|
|
|
throws SlickException {
|
|
|
|
int width = container.getWidth();
|
|
|
|
int height = container.getHeight();
|
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
Beatmap beatmap = MusicController.getBeatmap();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// background
|
2015-05-17 03:25:19 +02:00
|
|
|
if (!beatmap.drawBG(width, height, 0.7f, true))
|
2015-03-06 06:25:48 +01:00
|
|
|
GameImage.PLAYFIELD.getImage().draw(0,0);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// ranking screen elements
|
2015-05-17 03:25:19 +02:00
|
|
|
data.drawRankingElements(g, beatmap);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// buttons
|
2015-03-11 20:53:19 +01:00
|
|
|
replayButton.draw();
|
|
|
|
if (data.isGameplay())
|
2015-01-28 09:47:24 +01:00
|
|
|
retryButton.draw();
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.getBackButton().draw();
|
2014-06-30 04:17:04 +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();
|
2015-03-11 20:53:19 +01:00
|
|
|
replayButton.hoverUpdate(delta, mouseX, mouseY);
|
|
|
|
if (data.isGameplay())
|
2015-02-19 06:33:32 +01:00
|
|
|
retryButton.hoverUpdate(delta, mouseX, mouseY);
|
2015-03-11 20:53:19 +01:00
|
|
|
else
|
2015-03-08 01:04:45 +01:00
|
|
|
MusicController.loopTrackIfEnded(true);
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.getBackButton().hoverUpdate(delta, mouseX, mouseY);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getID() { return state; }
|
|
|
|
|
2015-03-27 01:45:33 +01:00
|
|
|
@Override
|
|
|
|
public void mouseWheelMoved(int newValue) {
|
|
|
|
if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT))
|
|
|
|
UI.changeVolume((newValue < 0) ? -1 : 1);
|
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
@Override
|
|
|
|
public void keyPressed(int key, char c) {
|
|
|
|
switch (key) {
|
|
|
|
case Input.KEY_ESCAPE:
|
2015-01-28 09:47:24 +01:00
|
|
|
returnToSongMenu();
|
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) {
|
2015-01-16 21:44:13 +01:00
|
|
|
// check mouse button
|
2015-02-13 09:45:38 +01:00
|
|
|
if (button == Input.MOUSE_MIDDLE_BUTTON)
|
2014-06-30 04:17:04 +02:00
|
|
|
return;
|
|
|
|
|
2015-03-11 20:53:19 +01:00
|
|
|
// back to menu
|
2015-03-05 19:27:45 +01:00
|
|
|
if (UI.getBackButton().contains(x, y)) {
|
2015-01-28 09:47:24 +01:00
|
|
|
returnToSongMenu();
|
|
|
|
return;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-03-11 20:53:19 +01:00
|
|
|
|
|
|
|
// replay
|
2015-03-12 01:52:51 +01:00
|
|
|
Game gameState = (Game) game.getState(Opsu.STATE_GAME);
|
2015-03-11 20:53:19 +01:00
|
|
|
boolean returnToGame = false;
|
|
|
|
if (replayButton.contains(x, y)) {
|
2015-03-16 04:05:27 +01:00
|
|
|
Replay r = data.getReplay(null, null);
|
2015-03-11 20:53:19 +01:00
|
|
|
if (r != null) {
|
2015-03-12 06:18:50 +01:00
|
|
|
try {
|
|
|
|
r.load();
|
|
|
|
gameState.setReplay(r);
|
|
|
|
gameState.setRestart((data.isGameplay()) ? Game.Restart.REPLAY : Game.Restart.NEW);
|
|
|
|
returnToGame = true;
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
UI.sendBarNotification("Replay file not found.");
|
|
|
|
} catch (IOException e) {
|
|
|
|
Log.error("Failed to load replay data.", e);
|
|
|
|
UI.sendBarNotification("Failed to load replay data. See log for details.");
|
|
|
|
}
|
2015-03-12 01:52:51 +01:00
|
|
|
} else
|
|
|
|
UI.sendBarNotification("Replay file not found.");
|
2015-03-11 20:53:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// retry
|
|
|
|
else if (data.isGameplay() && retryButton.contains(x, y)) {
|
2015-03-12 01:52:51 +01:00
|
|
|
gameState.setReplay(null);
|
|
|
|
gameState.setRestart(Game.Restart.MANUAL);
|
2015-03-11 20:53:19 +01:00
|
|
|
returnToGame = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (returnToGame) {
|
2015-05-17 03:25:19 +02:00
|
|
|
Beatmap beatmap = MusicController.getBeatmap();
|
|
|
|
gameState.loadBeatmap(beatmap);
|
2015-03-11 20:53:19 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
|
|
|
game.enterState(Opsu.STATE_GAME, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
Display.setTitle(game.getTitle());
|
2015-01-29 02:57:43 +01:00
|
|
|
if (!data.isGameplay()) {
|
|
|
|
if (!MusicController.isTrackDimmed())
|
|
|
|
MusicController.toggleTrackDimmed(0.5f);
|
2015-03-11 20:53:19 +01:00
|
|
|
replayButton.setY(retryY);
|
2015-02-19 06:33:32 +01:00
|
|
|
} else {
|
2015-01-29 01:23:02 +01:00
|
|
|
SoundController.playSound(SoundEffect.APPLAUSE);
|
2015-02-19 06:33:32 +01:00
|
|
|
retryButton.resetHover();
|
2015-03-11 20:53:19 +01:00
|
|
|
replayButton.setY(replayY);
|
2015-02-19 06:33:32 +01:00
|
|
|
}
|
2015-03-11 20:53:19 +01:00
|
|
|
replayButton.resetHover();
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-01-15 05:57:50 +01:00
|
|
|
|
2015-01-28 09:47:24 +01:00
|
|
|
@Override
|
|
|
|
public void leave(GameContainer container, StateBasedGame game)
|
|
|
|
throws SlickException {
|
|
|
|
this.data = null;
|
2015-03-12 01:52:51 +01:00
|
|
|
if (MusicController.isTrackDimmed())
|
|
|
|
MusicController.toggleTrackDimmed(1f);
|
2015-01-28 09:47:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns to the song menu.
|
|
|
|
*/
|
|
|
|
private void returnToSongMenu() {
|
|
|
|
SoundController.playSound(SoundEffect.MENUBACK);
|
|
|
|
if (data.isGameplay()) {
|
|
|
|
SongMenu songMenu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
|
|
|
|
songMenu.resetGameDataOnLoad();
|
|
|
|
songMenu.resetTrackOnLoad();
|
|
|
|
}
|
2015-05-29 10:48:03 +02:00
|
|
|
if (UI.getCursor().isSkinned())
|
|
|
|
UI.getCursor().reset();
|
2015-01-28 09:47:24 +01:00
|
|
|
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
|
|
|
}
|
|
|
|
|
2015-01-15 05:57:50 +01:00
|
|
|
/**
|
2015-01-27 09:19:39 +01:00
|
|
|
* Sets the associated GameData object.
|
|
|
|
* @param data the GameData
|
2015-01-15 05:57:50 +01:00
|
|
|
*/
|
2015-01-29 02:57:43 +01:00
|
|
|
public void setGameData(GameData data) { this.data = data; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current GameData object (usually null unless state active).
|
|
|
|
*/
|
|
|
|
public GameData getGameData() { return data; }
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|