2014-07-06 03:00:52 +02:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
2015-01-16 18:05:44 +01:00
|
|
|
* Copyright (C) 2014, 2015 Jeffrey Han
|
2014-07-06 03:00:52 +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-08 05:45:21 +01:00
|
|
|
import itdelatrisu.opsu.GameImage;
|
2014-07-06 03:00:52 +02:00
|
|
|
import itdelatrisu.opsu.Opsu;
|
2015-01-21 05:56:10 +01:00
|
|
|
import itdelatrisu.opsu.Options;
|
2014-07-06 03:00:52 +02:00
|
|
|
import itdelatrisu.opsu.OsuParser;
|
2014-07-06 07:58:44 +02:00
|
|
|
import itdelatrisu.opsu.OszUnpacker;
|
2014-07-06 03:00:52 +02:00
|
|
|
import itdelatrisu.opsu.Utils;
|
2015-01-08 01:29:51 +01:00
|
|
|
import itdelatrisu.opsu.audio.MusicController;
|
|
|
|
import itdelatrisu.opsu.audio.SoundController;
|
2015-05-17 03:25:19 +02:00
|
|
|
import itdelatrisu.opsu.beatmap.BeatmapSetList;
|
2015-05-29 07:55:57 +02:00
|
|
|
import itdelatrisu.opsu.ui.UI;
|
2014-07-06 03:00:52 +02:00
|
|
|
|
2014-07-06 07:58:44 +02:00
|
|
|
import java.io.File;
|
|
|
|
|
2014-07-06 03:00:52 +02:00
|
|
|
import org.newdawn.slick.Color;
|
|
|
|
import org.newdawn.slick.GameContainer;
|
|
|
|
import org.newdawn.slick.Graphics;
|
|
|
|
import org.newdawn.slick.Image;
|
2014-07-06 08:27:53 +02:00
|
|
|
import org.newdawn.slick.Input;
|
2014-07-06 03:00:52 +02:00
|
|
|
import org.newdawn.slick.SlickException;
|
|
|
|
import org.newdawn.slick.state.BasicGameState;
|
|
|
|
import org.newdawn.slick.state.StateBasedGame;
|
|
|
|
|
2014-07-06 07:58:44 +02:00
|
|
|
/**
|
|
|
|
* "Splash Screen" state.
|
|
|
|
* <p>
|
|
|
|
* Loads game resources and enters "Main Menu" state.
|
|
|
|
*/
|
2014-07-06 03:00:52 +02:00
|
|
|
public class Splash extends BasicGameState {
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Whether or not loading has completed. */
|
2014-07-06 03:00:52 +02:00
|
|
|
private boolean finished = false;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Loading thread. */
|
2015-01-18 21:26:00 +01:00
|
|
|
private Thread thread;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Number of times the 'Esc' key has been pressed. */
|
2015-01-18 21:26:00 +01:00
|
|
|
private int escapeCount = 0;
|
|
|
|
|
2014-07-06 03:00:52 +02:00
|
|
|
// game-related variables
|
|
|
|
private int state;
|
2014-07-06 08:27:53 +02:00
|
|
|
private GameContainer container;
|
2014-07-06 07:58:44 +02:00
|
|
|
private boolean init = false;
|
2014-07-06 03:00:52 +02:00
|
|
|
|
|
|
|
public Splash(int state) {
|
|
|
|
this.state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void init(GameContainer container, StateBasedGame game)
|
|
|
|
throws SlickException {
|
2014-07-06 08:27:53 +02:00
|
|
|
this.container = container;
|
|
|
|
|
2014-07-06 03:00:52 +02:00
|
|
|
// load Utils class first (needed in other 'init' methods)
|
|
|
|
Utils.init(container, game);
|
2015-01-08 05:45:21 +01:00
|
|
|
|
|
|
|
GameImage.MENU_LOGO.getImage().setAlpha(0f);
|
2014-07-06 03:00:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render(GameContainer container, StateBasedGame game, Graphics g)
|
|
|
|
throws SlickException {
|
|
|
|
g.setBackground(Color.black);
|
2015-01-08 05:45:21 +01:00
|
|
|
GameImage.MENU_LOGO.getImage().drawCentered(container.getWidth() / 2, container.getHeight() / 2);
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.drawLoadingProgress(g);
|
2014-07-06 03:00:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void update(GameContainer container, StateBasedGame game, int delta)
|
|
|
|
throws SlickException {
|
2014-07-06 07:58:44 +02:00
|
|
|
if (!init) {
|
|
|
|
init = true;
|
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
if (BeatmapSetList.get() != null) {
|
2015-01-21 01:24:59 +01:00
|
|
|
// resources already loaded (from application restart)
|
|
|
|
finished = true;
|
|
|
|
} else {
|
|
|
|
// load resources in a new thread
|
|
|
|
thread = new Thread() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-01-21 01:01:18 +01:00
|
|
|
File beatmapDir = Options.getBeatmapDir();
|
|
|
|
|
|
|
|
// unpack all OSZ archives
|
|
|
|
OszUnpacker.unpackAllFiles(Options.getOSZDir(), beatmapDir);
|
2015-01-21 01:24:59 +01:00
|
|
|
|
2015-01-21 01:01:18 +01:00
|
|
|
// parse song directory
|
2015-02-01 08:10:17 +01:00
|
|
|
OsuParser.parseAllFiles(beatmapDir);
|
2015-01-21 01:01:18 +01:00
|
|
|
|
|
|
|
// load sounds
|
|
|
|
SoundController.init();
|
2014-07-06 07:58:44 +02:00
|
|
|
|
2015-01-21 01:24:59 +01:00
|
|
|
finished = true;
|
2015-01-21 07:38:02 +01:00
|
|
|
thread = null;
|
2015-01-21 01:24:59 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
thread.start();
|
|
|
|
}
|
2014-07-06 07:58:44 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 03:00:52 +02:00
|
|
|
// fade in logo
|
2015-01-08 05:45:21 +01:00
|
|
|
Image logo = GameImage.MENU_LOGO.getImage();
|
2014-07-06 03:00:52 +02:00
|
|
|
float alpha = logo.getAlpha();
|
|
|
|
if (alpha < 1f)
|
2015-01-08 05:45:21 +01:00
|
|
|
logo.setAlpha(alpha + (delta / 500f));
|
2014-07-06 03:00:52 +02:00
|
|
|
|
|
|
|
// change states when loading complete
|
2014-08-25 05:48:52 +02:00
|
|
|
if (finished && alpha >= 1f) {
|
|
|
|
// initialize song list
|
2015-05-17 03:25:19 +02:00
|
|
|
if (BeatmapSetList.get().size() > 0) {
|
|
|
|
BeatmapSetList.get().init();
|
2015-02-15 07:40:01 +01:00
|
|
|
if (Options.isThemeSongEnabled())
|
2015-02-02 06:15:16 +01:00
|
|
|
MusicController.playThemeSong();
|
|
|
|
else
|
2015-05-17 03:25:19 +02:00
|
|
|
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).setFocus(BeatmapSetList.get().getRandomNode(), -1, true, true);
|
2015-01-21 07:38:02 +01:00
|
|
|
}
|
2014-08-25 05:48:52 +02:00
|
|
|
|
2014-12-21 00:17:04 +01:00
|
|
|
// play the theme song
|
2015-02-02 06:15:16 +01:00
|
|
|
else
|
2014-12-21 00:17:04 +01:00
|
|
|
MusicController.playThemeSong();
|
|
|
|
|
2014-07-06 03:00:52 +02:00
|
|
|
game.enterState(Opsu.STATE_MAINMENU);
|
2014-08-25 05:48:52 +02:00
|
|
|
}
|
2014-07-06 03:00:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getID() { return state; }
|
2014-07-06 08:27:53 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyPressed(int key, char c) {
|
2015-01-27 21:20:03 +01:00
|
|
|
if (key == Input.KEY_ESCAPE) {
|
|
|
|
// close program
|
|
|
|
if (++escapeCount >= 3)
|
|
|
|
container.exit();
|
2015-01-30 02:36:23 +01:00
|
|
|
|
2015-05-17 03:25:19 +02:00
|
|
|
// stop parsing beatmaps by sending interrupt to OsuParser
|
2015-01-27 21:20:03 +01:00
|
|
|
else if (thread != null)
|
|
|
|
thread.interrupt();
|
|
|
|
}
|
2014-07-06 08:27:53 +02:00
|
|
|
}
|
2014-07-06 03:00:52 +02:00
|
|
|
}
|