2014-06-30 04:17:04 +02:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
|
|
|
* Copyright (C) 2014 Jeffrey Han
|
|
|
|
*
|
|
|
|
* 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-08 05:45:21 +01:00
|
|
|
import itdelatrisu.opsu.GameImage;
|
2014-07-16 22:01:36 +02:00
|
|
|
import itdelatrisu.opsu.GameMod;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.GameScore;
|
2015-01-08 01:29:51 +01:00
|
|
|
import itdelatrisu.opsu.MenuButton;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.Opsu;
|
|
|
|
import itdelatrisu.opsu.OsuFile;
|
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;
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "Game Ranking" (score card) state.
|
|
|
|
* <ul>
|
|
|
|
* <li>[Retry] - restart game (return to game state)
|
|
|
|
* <li>[Exit] - return to main menu state
|
|
|
|
* <li>[Back] - return to song menu state
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
public class GameRanking extends BasicGameState {
|
|
|
|
/**
|
|
|
|
* Associated GameScore object.
|
|
|
|
*/
|
2014-07-09 19:36:42 +02:00
|
|
|
private GameScore score;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* "Retry" and "Exit" buttons.
|
|
|
|
*/
|
2014-12-30 06:00:58 +01:00
|
|
|
private MenuButton retryButton, exitButton;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// game-related variables
|
|
|
|
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 {
|
|
|
|
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-01-08 05:45:21 +01:00
|
|
|
Image retry = GameImage.RANKING_RETRY.getImage();
|
|
|
|
Image exit = GameImage.RANKING_EXIT.getImage();
|
2014-12-30 06:00:58 +01:00
|
|
|
retryButton = new MenuButton(retry,
|
2014-06-30 04:17:04 +02:00
|
|
|
width - (retry.getWidth() / 2f),
|
|
|
|
(height * 0.97f) - (exit.getHeight() * 1.5f)
|
|
|
|
);
|
2014-12-30 06:00:58 +01:00
|
|
|
exitButton = new MenuButton(exit,
|
2014-06-30 04:17:04 +02:00
|
|
|
width - (exit.getWidth() / 2f),
|
|
|
|
(height * 0.97f) - (exit.getHeight() / 2f)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render(GameContainer container, StateBasedGame game, Graphics g)
|
|
|
|
throws SlickException {
|
|
|
|
int width = container.getWidth();
|
|
|
|
int height = container.getHeight();
|
|
|
|
|
2014-07-02 09:02:11 +02:00
|
|
|
OsuFile osu = MusicController.getOsuFile();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// background
|
|
|
|
if (!osu.drawBG(width, height, 0.7f))
|
2014-07-02 01:32:03 +02:00
|
|
|
g.setBackground(Utils.COLOR_BLACK_ALPHA);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// ranking screen elements
|
|
|
|
score.drawRankingElements(g, width, height);
|
|
|
|
|
|
|
|
// game mods
|
2014-07-16 22:01:36 +02:00
|
|
|
for (GameMod mod : GameMod.valuesReversed()) {
|
|
|
|
if (mod.isActive()) {
|
|
|
|
Image modImage = mod.getImage();
|
2014-06-30 04:17:04 +02:00
|
|
|
modImage.draw(
|
2014-07-16 22:01:36 +02:00
|
|
|
(width * 0.75f) + ((mod.getID() - (GameMod.size() / 2)) * modImage.getWidth() / 3f),
|
2014-06-30 04:17:04 +02:00
|
|
|
height / 2f
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// header text
|
|
|
|
g.setColor(Color.white);
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.FONT_LARGE.drawString(10, 0,
|
2014-08-25 05:48:52 +02:00
|
|
|
String.format("%s - %s [%s]", osu.getArtist(), osu.getTitle(), osu.version));
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.FONT_MEDIUM.drawString(10, Utils.FONT_LARGE.getLineHeight() - 6,
|
2014-06-30 04:17:04 +02:00
|
|
|
String.format("Beatmap by %s", osu.creator));
|
|
|
|
|
|
|
|
// buttons
|
|
|
|
retryButton.draw();
|
|
|
|
exitButton.draw();
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.getBackButton().draw();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.drawFPS();
|
|
|
|
Utils.drawCursor();
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(GameContainer container, StateBasedGame game, int delta)
|
|
|
|
throws SlickException {
|
2014-07-07 05:13:33 +02:00
|
|
|
Utils.updateCursor(delta);
|
2014-12-24 05:41:37 +01:00
|
|
|
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
|
|
|
Utils.getBackButton().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) {
|
|
|
|
switch (key) {
|
|
|
|
case Input.KEY_ESCAPE:
|
2014-07-01 07:14:03 +02:00
|
|
|
MusicController.pause();
|
2014-07-02 09:02:11 +02:00
|
|
|
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUBACK);
|
2014-06-30 04:17:04 +02:00
|
|
|
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
|
|
|
break;
|
|
|
|
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) {
|
|
|
|
// check mouse button
|
|
|
|
if (button != Input.MOUSE_LEFT_BUTTON)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (retryButton.contains(x, y)) {
|
2014-07-02 09:02:11 +02:00
|
|
|
OsuFile osu = MusicController.getOsuFile();
|
2014-06-30 04:17:04 +02:00
|
|
|
Display.setTitle(String.format("%s - %s", game.getTitle(), osu.toString()));
|
2015-01-15 06:56:30 +01:00
|
|
|
((Game) game.getState(Opsu.STATE_GAME)).setRestart(Game.Restart.MANUAL);
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
2014-06-30 04:17:04 +02:00
|
|
|
game.enterState(Opsu.STATE_GAME, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
2014-07-01 07:14:03 +02:00
|
|
|
} else if (exitButton.contains(x, y)) {
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUBACK);
|
2014-12-30 06:41:32 +01:00
|
|
|
((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset();
|
2015-01-15 22:47:55 +01:00
|
|
|
((Game) game.getState(Opsu.STATE_GAME)).resetGameData();
|
2014-06-30 04:17:04 +02:00
|
|
|
game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
2014-07-02 01:32:03 +02:00
|
|
|
} else if (Utils.getBackButton().contains(x, y)) {
|
2014-07-01 07:14:03 +02:00
|
|
|
MusicController.pause();
|
2014-07-02 09:02:11 +02:00
|
|
|
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUBACK);
|
2015-01-15 22:47:55 +01:00
|
|
|
((Game) game.getState(Opsu.STATE_GAME)).resetGameData();
|
2014-06-30 04:17:04 +02:00
|
|
|
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void enter(GameContainer container, StateBasedGame game)
|
|
|
|
throws SlickException {
|
|
|
|
Display.setTitle(game.getTitle());
|
2014-12-24 05:41:37 +01:00
|
|
|
Utils.getBackButton().setScale(1f);
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.APPLAUSE);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-01-15 05:57:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the associated GameScore object.
|
|
|
|
* @param score the GameScore
|
|
|
|
*/
|
|
|
|
public void setGameScore(GameScore score) {
|
|
|
|
this.score = score;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|