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-29 01:23:02 +01:00
|
|
|
import itdelatrisu.opsu.GameData;
|
|
|
|
import itdelatrisu.opsu.GameData.Grade;
|
2015-01-08 05:45:21 +01:00
|
|
|
import itdelatrisu.opsu.GameImage;
|
2015-01-16 08:00:42 +01:00
|
|
|
import itdelatrisu.opsu.GameMod;
|
2014-12-30 06:00:58 +01:00
|
|
|
import itdelatrisu.opsu.MenuButton;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.Opsu;
|
2015-01-21 07:38:02 +01:00
|
|
|
import itdelatrisu.opsu.Options;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.OsuFile;
|
2015-01-11 20:17:33 +01:00
|
|
|
import itdelatrisu.opsu.OsuGroupList;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.OsuGroupNode;
|
|
|
|
import itdelatrisu.opsu.OsuParser;
|
2015-01-21 07:38:02 +01:00
|
|
|
import itdelatrisu.opsu.OszUnpacker;
|
2015-01-30 02:36:23 +01:00
|
|
|
import itdelatrisu.opsu.ScoreData;
|
2014-07-19 02:33:41 +02:00
|
|
|
import itdelatrisu.opsu.SongSort;
|
2015-03-05 19:27:45 +01:00
|
|
|
import itdelatrisu.opsu.UI;
|
2014-07-02 01:32:03 +02:00
|
|
|
import itdelatrisu.opsu.Utils;
|
2015-01-08 01:29:51 +01:00
|
|
|
import itdelatrisu.opsu.audio.HitSound;
|
2015-03-01 06:03:06 +01:00
|
|
|
import itdelatrisu.opsu.audio.MultiClip;
|
2015-01-08 01:29:51 +01:00
|
|
|
import itdelatrisu.opsu.audio.MusicController;
|
|
|
|
import itdelatrisu.opsu.audio.SoundController;
|
|
|
|
import itdelatrisu.opsu.audio.SoundEffect;
|
2015-03-05 03:03:06 +01:00
|
|
|
import itdelatrisu.opsu.db.OsuDB;
|
|
|
|
import itdelatrisu.opsu.db.ScoreDB;
|
2015-02-13 08:43:34 +01:00
|
|
|
import itdelatrisu.opsu.states.ButtonMenu.MenuState;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-21 07:38:02 +01:00
|
|
|
import java.io.File;
|
2015-01-28 09:47:24 +01:00
|
|
|
import java.util.Map;
|
2015-01-16 21:44:13 +01:00
|
|
|
import java.util.Stack;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
import org.lwjgl.opengl.Display;
|
2014-07-18 03:16:15 +02:00
|
|
|
import org.newdawn.slick.Animation;
|
2014-06-30 04:17:04 +02:00
|
|
|
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;
|
2014-07-18 03:16:15 +02:00
|
|
|
import org.newdawn.slick.SpriteSheet;
|
2014-06-30 04:17:04 +02:00
|
|
|
import org.newdawn.slick.gui.TextField;
|
|
|
|
import org.newdawn.slick.state.BasicGameState;
|
|
|
|
import org.newdawn.slick.state.StateBasedGame;
|
|
|
|
import org.newdawn.slick.state.transition.EmptyTransition;
|
|
|
|
import org.newdawn.slick.state.transition.FadeInTransition;
|
|
|
|
import org.newdawn.slick.state.transition.FadeOutTransition;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "Song Selection" state.
|
|
|
|
* <ul>
|
|
|
|
* <li>[Song] - start game (move to game state)
|
|
|
|
* <li>[Back] - return to main menu
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
public class SongMenu extends BasicGameState {
|
2015-01-29 01:23:02 +01:00
|
|
|
/** The max number of song buttons to be shown on each screen. */
|
2015-02-18 04:54:20 +01:00
|
|
|
public static final int MAX_SONG_BUTTONS = 6;
|
2015-01-29 01:23:02 +01:00
|
|
|
|
|
|
|
/** The max number of score buttons to be shown at a time. */
|
|
|
|
public static final int MAX_SCORE_BUTTONS = 7;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Delay time, in milliseconds, between each search. */
|
2014-07-17 18:49:12 +02:00
|
|
|
private static final int SEARCH_DELAY = 500;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-02-13 08:43:34 +01:00
|
|
|
/** Delay time, in milliseconds, before moving to the beatmap menu after a right click. */
|
|
|
|
private static final int BEATMAP_MENU_DELAY = 600;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Maximum x offset of song buttons for mouse hover, in pixels. */
|
2015-01-08 22:28:49 +01:00
|
|
|
private static final float MAX_HOVER_OFFSET = 30f;
|
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
/** Time, in milliseconds, for the search bar to fade in or out. */
|
|
|
|
private static final int SEARCH_TRANSITION_TIME = 250;
|
|
|
|
|
|
|
|
/** Line width of the header/footer divider. */
|
|
|
|
private static final int DIVIDER_LINE_WIDTH = 4;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Song node class representing an OsuGroupNode and file index. */
|
2015-01-16 07:40:34 +01:00
|
|
|
private static class SongNode {
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Song node. */
|
2015-01-16 07:40:34 +01:00
|
|
|
private OsuGroupNode node;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** File index. */
|
2015-01-16 07:40:34 +01:00
|
|
|
private int index;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* @param node the OsuGroupNode
|
|
|
|
* @param index the file index
|
|
|
|
*/
|
|
|
|
public SongNode(OsuGroupNode node, int index) {
|
|
|
|
this.node = node;
|
|
|
|
this.index = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the associated OsuGroupNode.
|
|
|
|
*/
|
|
|
|
public OsuGroupNode getNode() { return node; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the associated file index.
|
|
|
|
*/
|
|
|
|
public int getIndex() { return index; }
|
|
|
|
}
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Current start node (topmost menu entry). */
|
2014-06-30 04:17:04 +02:00
|
|
|
private OsuGroupNode startNode;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Current focused (selected) node. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private OsuGroupNode focusNode;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The base node of the previous focus node. */
|
2015-01-16 07:40:34 +01:00
|
|
|
private SongNode oldFocusNode = null;
|
2014-07-09 01:03:43 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Stack of previous "random" (F2) focus nodes. */
|
2015-01-16 07:40:34 +01:00
|
|
|
private Stack<SongNode> randomStack = new Stack<SongNode>();
|
2014-07-09 01:03:43 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Current focus node's song information. */
|
2015-01-08 18:03:39 +01:00
|
|
|
private String[] songInfo;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Button coordinate values. */
|
2015-02-15 06:25:07 +01:00
|
|
|
private float buttonX, buttonY, buttonOffset, buttonWidth, buttonHeight;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Current x offset of song buttons for mouse hover, in pixels. */
|
2015-01-08 22:28:49 +01:00
|
|
|
private float hoverOffset = 0f;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Current index of hovered song button. */
|
2015-01-08 22:28:49 +01:00
|
|
|
private int hoverIndex = -1;
|
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
/** The selection buttons. */
|
|
|
|
private MenuButton selectModsButton, selectRandomButton, selectMapOptionsButton, selectOptionsButton;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The search textfield. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private TextField search;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delay timer, in milliseconds, before running another search.
|
|
|
|
* This is overridden by character entry (reset) and 'esc' (immediate search).
|
|
|
|
*/
|
2015-02-16 03:38:54 +01:00
|
|
|
private int searchTimer = 0;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Information text to display based on the search query. */
|
2015-02-16 03:38:54 +01:00
|
|
|
private String searchResultString = null;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Loader animation. */
|
2014-07-18 03:16:15 +02:00
|
|
|
private Animation loader;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Whether or not to reset game data upon entering the state. */
|
2015-01-16 06:36:05 +01:00
|
|
|
private boolean resetGame = false;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Whether or not to reset music track upon entering the state. */
|
2015-01-16 21:44:13 +01:00
|
|
|
private boolean resetTrack = false;
|
|
|
|
|
2015-02-13 08:43:34 +01:00
|
|
|
/** If non-null, determines the action to perform upon entering the state. */
|
|
|
|
private MenuState stateAction;
|
|
|
|
|
|
|
|
/** If non-null, the node that stateAction acts upon. */
|
|
|
|
private OsuGroupNode stateActionNode;
|
|
|
|
|
2015-02-13 09:45:38 +01:00
|
|
|
/** If non-null, the score data that stateAction acts upon. */
|
|
|
|
private ScoreData stateActionScore;
|
|
|
|
|
2015-02-13 08:43:34 +01:00
|
|
|
/** Timer before moving to the beatmap menu with the current focus node. */
|
|
|
|
private int beatmapMenuTimer = -1;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Beatmap reloading thread. */
|
2015-01-21 07:38:02 +01:00
|
|
|
private Thread reloadThread;
|
|
|
|
|
2015-01-28 09:47:24 +01:00
|
|
|
/** Current map of scores (Version, ScoreData[]). */
|
|
|
|
private Map<String, ScoreData[]> scoreMap;
|
|
|
|
|
2015-01-29 01:23:02 +01:00
|
|
|
/** Scores for the current focus node. */
|
|
|
|
private ScoreData[] focusScores;
|
|
|
|
|
|
|
|
/** Current start score (topmost score entry). */
|
|
|
|
private int startScore = 0;
|
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
/** Header and footer end and start y coordinates, respectively. */
|
|
|
|
private float headerY, footerY;
|
|
|
|
|
|
|
|
/** Time, in milliseconds, for fading the search bar. */
|
|
|
|
private int searchTransitionTimer = SEARCH_TRANSITION_TIME;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// game-related variables
|
|
|
|
private GameContainer container;
|
|
|
|
private StateBasedGame game;
|
|
|
|
private Input input;
|
|
|
|
private int state;
|
|
|
|
|
|
|
|
public SongMenu(int state) {
|
|
|
|
this.state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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();
|
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
// header/footer coordinates
|
|
|
|
headerY = height * 0.0075f + GameImage.MENU_MUSICNOTE.getImage().getHeight() +
|
|
|
|
Utils.FONT_BOLD.getLineHeight() + Utils.FONT_DEFAULT.getLineHeight() +
|
|
|
|
Utils.FONT_SMALL.getLineHeight();
|
|
|
|
footerY = height - GameImage.SELECTION_MODS.getImage().getHeight();
|
|
|
|
|
|
|
|
// initialize sorts
|
|
|
|
for (SongSort sort : SongSort.values())
|
|
|
|
sort.init(width, headerY - SongMenu.DIVIDER_LINE_WIDTH / 2);
|
|
|
|
|
|
|
|
// initialize score data buttons
|
|
|
|
ScoreData.init(width, headerY + height * 0.01f);
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// song button background & graphics context
|
2015-01-08 05:45:21 +01:00
|
|
|
Image menuBackground = GameImage.MENU_BUTTON_BG.getImage();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// song button coordinates
|
|
|
|
buttonX = width * 0.6f;
|
2015-02-16 03:38:54 +01:00
|
|
|
buttonY = headerY;
|
2014-06-30 04:17:04 +02:00
|
|
|
buttonWidth = menuBackground.getWidth();
|
|
|
|
buttonHeight = menuBackground.getHeight();
|
2015-02-16 03:38:54 +01:00
|
|
|
buttonOffset = (footerY - headerY - DIVIDER_LINE_WIDTH) / MAX_SONG_BUTTONS;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// search
|
2015-02-16 03:38:54 +01:00
|
|
|
int textFieldX = (int) (width * 0.7125f + Utils.FONT_BOLD.getWidth("Search: "));
|
|
|
|
int textFieldY = (int) (headerY + Utils.FONT_BOLD.getLineHeight() / 2);
|
2014-06-30 04:17:04 +02:00
|
|
|
search = new TextField(
|
2015-02-16 03:38:54 +01:00
|
|
|
container, Utils.FONT_BOLD, textFieldX, textFieldY,
|
|
|
|
(int) (width * 0.99f) - textFieldX, Utils.FONT_BOLD.getLineHeight()
|
2014-06-30 04:17:04 +02:00
|
|
|
);
|
|
|
|
search.setBackgroundColor(Color.transparent);
|
|
|
|
search.setBorderColor(Color.transparent);
|
|
|
|
search.setTextColor(Color.white);
|
|
|
|
search.setConsumeEvents(false);
|
|
|
|
search.setMaxLength(60);
|
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
// selection buttons
|
2015-02-19 06:33:32 +01:00
|
|
|
Image selectionMods = GameImage.SELECTION_MODS.getImage();
|
|
|
|
float selectX = width * 0.183f + selectionMods.getWidth() / 2f;
|
|
|
|
float selectY = height - selectionMods.getHeight() / 2f;
|
|
|
|
float selectOffset = selectionMods.getWidth() * 1.05f;
|
2015-02-16 03:38:54 +01:00
|
|
|
selectModsButton = new MenuButton(GameImage.SELECTION_MODS_OVERLAY.getImage(),
|
|
|
|
selectX, selectY);
|
|
|
|
selectRandomButton = new MenuButton(GameImage.SELECTION_RANDOM_OVERLAY.getImage(),
|
|
|
|
selectX + selectOffset, selectY);
|
|
|
|
selectMapOptionsButton = new MenuButton(GameImage.SELECTION_OPTIONS_OVERLAY.getImage(),
|
|
|
|
selectX + selectOffset * 2f, selectY);
|
|
|
|
selectOptionsButton = new MenuButton(GameImage.SELECTION_OTHER_OPTIONS_OVERLAY.getImage(),
|
|
|
|
selectX + selectOffset * 3f, selectY);
|
|
|
|
selectModsButton.setHoverFade(0f);
|
|
|
|
selectRandomButton.setHoverFade(0f);
|
|
|
|
selectMapOptionsButton.setHoverFade(0f);
|
|
|
|
selectOptionsButton.setHoverFade(0f);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2014-07-18 03:16:15 +02:00
|
|
|
// loader
|
2015-01-08 05:45:21 +01:00
|
|
|
int loaderDim = GameImage.MENU_MUSICNOTE.getImage().getWidth();
|
|
|
|
SpriteSheet spr = new SpriteSheet(GameImage.MENU_LOADER.getImage(), loaderDim, loaderDim);
|
2014-07-18 03:16:15 +02:00
|
|
|
loader = new Animation(spr, 50);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render(GameContainer container, StateBasedGame game, Graphics g)
|
|
|
|
throws SlickException {
|
|
|
|
g.setBackground(Color.black);
|
|
|
|
|
|
|
|
int width = container.getWidth();
|
|
|
|
int height = container.getHeight();
|
2015-01-11 05:14:22 +01:00
|
|
|
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// background
|
2015-02-11 08:56:02 +01:00
|
|
|
if (focusNode != null) {
|
|
|
|
OsuFile focusNodeOsu = focusNode.osuFiles.get(focusNode.osuFileIndex);
|
|
|
|
if (!focusNodeOsu.drawBG(width, height, 1.0f, true))
|
|
|
|
GameImage.PLAYFIELD.getImage().draw();
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-02-20 05:45:48 +01:00
|
|
|
// song buttons
|
|
|
|
OsuGroupNode node = startNode;
|
|
|
|
int songButtonIndex = 0;
|
|
|
|
if (node != null && node.prev != null) {
|
|
|
|
node = node.prev;
|
|
|
|
songButtonIndex = -1;
|
|
|
|
}
|
|
|
|
g.setClip(0, (int) (headerY + DIVIDER_LINE_WIDTH / 2), width, (int) (footerY - headerY));
|
|
|
|
for (int i = songButtonIndex; i <= MAX_SONG_BUTTONS && node != null; i++, node = node.next) {
|
|
|
|
// draw the node
|
|
|
|
float offset = (i == hoverIndex) ? hoverOffset : 0f;
|
|
|
|
ScoreData[] scores = getScoreDataForNode(node, false);
|
|
|
|
node.draw(buttonX - offset, buttonY + (i*buttonOffset) + DIVIDER_LINE_WIDTH / 2,
|
|
|
|
(scores == null) ? Grade.NULL : scores[0].getGrade(), (node == focusNode));
|
|
|
|
|
|
|
|
// load glyphs
|
|
|
|
Utils.loadGlyphs(node.osuFiles.get(0));
|
|
|
|
}
|
|
|
|
g.clearClip();
|
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
// top/bottom bars
|
2015-02-20 05:45:48 +01:00
|
|
|
g.setColor(Utils.COLOR_BLACK_ALPHA);
|
2015-02-16 03:38:54 +01:00
|
|
|
g.fillRect(0, 0, width, headerY);
|
|
|
|
g.fillRect(0, footerY, width, height - footerY);
|
2014-07-02 01:32:03 +02:00
|
|
|
g.setColor(Utils.COLOR_BLUE_DIVIDER);
|
2015-02-16 03:38:54 +01:00
|
|
|
g.setLineWidth(DIVIDER_LINE_WIDTH);
|
|
|
|
g.drawLine(0, headerY, width, headerY);
|
2015-02-20 05:45:48 +01:00
|
|
|
g.drawLine(0, footerY, width, footerY);
|
2014-06-30 04:17:04 +02:00
|
|
|
g.resetLineWidth();
|
|
|
|
|
|
|
|
// header
|
|
|
|
if (focusNode != null) {
|
2015-01-16 20:46:45 +01:00
|
|
|
float marginX = width * 0.005f, marginY = height * 0.005f;
|
2015-01-08 05:45:21 +01:00
|
|
|
Image musicNote = GameImage.MENU_MUSICNOTE.getImage();
|
2014-07-18 03:16:15 +02:00
|
|
|
if (MusicController.isTrackLoading())
|
2015-01-16 20:46:45 +01:00
|
|
|
loader.draw(marginX, marginY);
|
2014-07-18 03:16:15 +02:00
|
|
|
else
|
2015-01-16 20:46:45 +01:00
|
|
|
musicNote.draw(marginX, marginY);
|
2014-07-18 03:16:15 +02:00
|
|
|
int iconWidth = musicNote.getWidth();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-08 18:03:39 +01:00
|
|
|
if (songInfo == null)
|
|
|
|
songInfo = focusNode.getInfo();
|
2015-01-16 20:46:45 +01:00
|
|
|
marginX += 5;
|
2015-02-19 01:35:26 +01:00
|
|
|
float headerTextY = marginY;
|
|
|
|
Utils.FONT_LARGE.drawString(marginX + iconWidth * 1.05f, headerTextY, songInfo[0], Color.white);
|
|
|
|
headerTextY += Utils.FONT_LARGE.getLineHeight() - 8;
|
|
|
|
Utils.FONT_DEFAULT.drawString(marginX + iconWidth * 1.05f, headerTextY, songInfo[1], Color.white);
|
|
|
|
headerTextY += Utils.FONT_DEFAULT.getLineHeight() - 2;
|
2015-02-16 03:38:54 +01:00
|
|
|
Utils.FONT_BOLD.drawString(marginX, headerTextY, songInfo[2], Color.white);
|
2015-02-19 01:35:26 +01:00
|
|
|
headerTextY += Utils.FONT_BOLD.getLineHeight() - 4;
|
2015-02-16 03:38:54 +01:00
|
|
|
Utils.FONT_DEFAULT.drawString(marginX, headerTextY, songInfo[3], Color.white);
|
|
|
|
headerTextY += Utils.FONT_DEFAULT.getLineHeight() - 4;
|
|
|
|
Utils.FONT_SMALL.drawString(marginX, headerTextY, songInfo[4], Color.white);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
2015-01-29 01:23:02 +01:00
|
|
|
// score buttons
|
|
|
|
if (focusScores != null) {
|
|
|
|
for (int i = 0; i < MAX_SCORE_BUTTONS; i++) {
|
|
|
|
int rank = startScore + i;
|
|
|
|
if (rank >= focusScores.length)
|
|
|
|
break;
|
|
|
|
long prevScore = (rank + 1 < focusScores.length) ?
|
|
|
|
focusScores[rank + 1].score : -1;
|
|
|
|
focusScores[rank].draw(g, i, rank, prevScore, ScoreData.buttonContains(mouseX, mouseY, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
// scroll bar
|
|
|
|
if (focusScores.length > MAX_SCORE_BUTTONS && ScoreData.areaContains(mouseX, mouseY))
|
|
|
|
ScoreData.drawScrollbar(g, startScore, focusScores.length);
|
|
|
|
}
|
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
// selection buttons
|
2015-02-16 23:53:24 +01:00
|
|
|
GameImage.SELECTION_MODS.getImage().drawCentered(selectModsButton.getX(), selectModsButton.getY());
|
|
|
|
selectModsButton.draw();
|
2015-02-16 03:38:54 +01:00
|
|
|
GameImage.SELECTION_RANDOM.getImage().drawCentered(selectRandomButton.getX(), selectRandomButton.getY());
|
|
|
|
selectRandomButton.draw();
|
|
|
|
GameImage.SELECTION_OPTIONS.getImage().drawCentered(selectMapOptionsButton.getX(), selectMapOptionsButton.getY());
|
|
|
|
selectMapOptionsButton.draw();
|
|
|
|
GameImage.SELECTION_OTHER_OPTIONS.getImage().drawCentered(selectOptionsButton.getX(), selectOptionsButton.getY());
|
|
|
|
selectOptionsButton.draw();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// sorting tabs
|
2015-01-11 04:49:23 +01:00
|
|
|
SongSort currentSort = SongSort.getSort();
|
2015-01-11 05:14:22 +01:00
|
|
|
SongSort hoverSort = null;
|
|
|
|
for (SongSort sort : SongSort.values()) {
|
|
|
|
if (sort.contains(mouseX, mouseY)) {
|
|
|
|
hoverSort = sort;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-11 04:49:23 +01:00
|
|
|
for (SongSort sort : SongSort.VALUES_REVERSED) {
|
|
|
|
if (sort != currentSort)
|
2015-01-11 05:14:22 +01:00
|
|
|
sort.draw(false, sort == hoverSort);
|
2015-01-11 04:49:23 +01:00
|
|
|
}
|
2015-01-11 05:14:22 +01:00
|
|
|
currentSort.draw(true, false);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// search
|
2015-02-16 03:38:54 +01:00
|
|
|
boolean searchEmpty = search.getText().isEmpty();
|
|
|
|
int searchX = search.getX(), searchY = search.getY();
|
|
|
|
float searchBaseX = width * 0.7f;
|
|
|
|
float searchTextX = width * 0.7125f;
|
|
|
|
float searchRectHeight = Utils.FONT_BOLD.getLineHeight() * 2;
|
|
|
|
float searchExtraHeight = Utils.FONT_DEFAULT.getLineHeight() * 0.7f;
|
|
|
|
float searchProgress = (searchTransitionTimer < SEARCH_TRANSITION_TIME) ?
|
|
|
|
((float) searchTransitionTimer / SEARCH_TRANSITION_TIME) : 1f;
|
|
|
|
float oldAlpha = Utils.COLOR_BLACK_ALPHA.a;
|
|
|
|
if (searchEmpty) {
|
|
|
|
searchRectHeight += (1f - searchProgress) * searchExtraHeight;
|
|
|
|
Utils.COLOR_BLACK_ALPHA.a = 0.5f - searchProgress * 0.3f;
|
|
|
|
} else {
|
|
|
|
searchRectHeight += searchProgress * searchExtraHeight;
|
|
|
|
Utils.COLOR_BLACK_ALPHA.a = 0.2f + searchProgress * 0.3f;
|
|
|
|
}
|
|
|
|
g.setColor(Utils.COLOR_BLACK_ALPHA);
|
|
|
|
g.fillRect(searchBaseX, headerY + DIVIDER_LINE_WIDTH / 2, width - searchBaseX, searchRectHeight);
|
|
|
|
Utils.COLOR_BLACK_ALPHA.a = oldAlpha;
|
|
|
|
Utils.FONT_BOLD.drawString(searchTextX, searchY, "Search:", Utils.COLOR_GREEN_SEARCH);
|
|
|
|
if (searchEmpty)
|
|
|
|
Utils.FONT_BOLD.drawString(searchX, searchY, "Type to search!", Color.white);
|
|
|
|
else {
|
|
|
|
g.setColor(Color.white);
|
|
|
|
// TODO: why is this needed to correctly position the TextField?
|
|
|
|
search.setLocation(searchX - 3, searchY - 1);
|
|
|
|
search.render(container, g);
|
|
|
|
search.setLocation(searchX, searchY);
|
|
|
|
Utils.FONT_DEFAULT.drawString(searchTextX, searchY + Utils.FONT_BOLD.getLineHeight(),
|
|
|
|
(searchResultString == null) ? "Searching..." : searchResultString, Color.white);
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// scroll bar
|
|
|
|
if (focusNode != null) {
|
2015-02-15 06:25:07 +01:00
|
|
|
int focusNodes = focusNode.osuFiles.size();
|
|
|
|
int totalNodes = OsuGroupList.get().size() + focusNodes - 1;
|
|
|
|
if (totalNodes > MAX_SONG_BUTTONS) {
|
|
|
|
int startIndex = startNode.index;
|
|
|
|
if (startNode.index > focusNode.index)
|
|
|
|
startIndex += focusNodes;
|
|
|
|
else if (startNode.index == focusNode.index)
|
|
|
|
startIndex += startNode.osuFileIndex;
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.drawScrollbar(g, startIndex, totalNodes, MAX_SONG_BUTTONS,
|
2015-02-16 03:38:54 +01:00
|
|
|
width, headerY + DIVIDER_LINE_WIDTH / 2, 0, buttonOffset - DIVIDER_LINE_WIDTH * 1.5f, buttonOffset,
|
2015-02-15 06:25:07 +01:00
|
|
|
Utils.COLOR_BLACK_ALPHA, Color.white, true);
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
2015-01-21 07:38:02 +01:00
|
|
|
// reloading beatmaps
|
|
|
|
if (reloadThread != null) {
|
|
|
|
// darken the screen
|
|
|
|
g.setColor(Utils.COLOR_BLACK_ALPHA);
|
|
|
|
g.fillRect(0, 0, width, height);
|
|
|
|
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.drawLoadingProgress(g);
|
2015-01-21 07:38:02 +01:00
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// back button
|
2015-01-21 07:38:02 +01:00
|
|
|
else
|
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-05 19:27:45 +01:00
|
|
|
UI.getBackButton().hoverUpdate(delta, mouseX, mouseY);
|
2015-02-16 03:38:54 +01:00
|
|
|
selectModsButton.hoverUpdate(delta, mouseX, mouseY);
|
|
|
|
selectRandomButton.hoverUpdate(delta, mouseX, mouseY);
|
|
|
|
selectMapOptionsButton.hoverUpdate(delta, mouseX, mouseY);
|
|
|
|
selectOptionsButton.hoverUpdate(delta, mouseX, mouseY);
|
2014-07-07 05:13:33 +02:00
|
|
|
|
2015-02-13 08:43:34 +01:00
|
|
|
// beatmap menu timer
|
|
|
|
if (beatmapMenuTimer > -1) {
|
|
|
|
beatmapMenuTimer += delta;
|
|
|
|
if (beatmapMenuTimer >= BEATMAP_MENU_DELAY) {
|
|
|
|
beatmapMenuTimer = -1;
|
|
|
|
if (focusNode != null) {
|
|
|
|
((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.BEATMAP, focusNode);
|
|
|
|
game.enterState(Opsu.STATE_BUTTONMENU);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// search
|
2014-07-09 01:03:43 +02:00
|
|
|
search.setFocus(true);
|
2014-06-30 04:17:04 +02:00
|
|
|
searchTimer += delta;
|
2015-02-13 08:43:34 +01:00
|
|
|
if (searchTimer >= SEARCH_DELAY && reloadThread == null && beatmapMenuTimer == -1) {
|
2014-06-30 04:17:04 +02:00
|
|
|
searchTimer = 0;
|
|
|
|
|
|
|
|
// store the start/focus nodes
|
2015-01-16 07:40:34 +01:00
|
|
|
if (focusNode != null)
|
|
|
|
oldFocusNode = new SongNode(OsuGroupList.get().getBaseNode(focusNode.index), focusNode.osuFileIndex);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-11 20:17:33 +01:00
|
|
|
if (OsuGroupList.get().search(search.getText())) {
|
2015-01-16 07:40:34 +01:00
|
|
|
// reset song stack
|
|
|
|
randomStack = new Stack<SongNode>();
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// empty search
|
|
|
|
if (search.getText().isEmpty())
|
2015-02-16 03:38:54 +01:00
|
|
|
searchResultString = null;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// search produced new list: re-initialize it
|
|
|
|
startNode = focusNode = null;
|
2015-02-12 08:27:33 +01:00
|
|
|
scoreMap = null;
|
|
|
|
focusScores = null;
|
2015-01-11 20:17:33 +01:00
|
|
|
if (OsuGroupList.get().size() > 0) {
|
|
|
|
OsuGroupList.get().init();
|
2014-06-30 04:17:04 +02:00
|
|
|
if (search.getText().isEmpty()) { // cleared search
|
|
|
|
// use previous start/focus if possible
|
|
|
|
if (oldFocusNode != null)
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(oldFocusNode.getNode(), oldFocusNode.getIndex(), true, true);
|
2014-06-30 04:17:04 +02:00
|
|
|
else
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(OsuGroupList.get().getRandomNode(), -1, true, true);
|
2014-06-30 04:17:04 +02:00
|
|
|
} else {
|
2015-01-11 20:17:33 +01:00
|
|
|
int size = OsuGroupList.get().size();
|
2014-07-17 18:49:12 +02:00
|
|
|
searchResultString = String.format("%d match%s found!",
|
|
|
|
size, (size == 1) ? "" : "es");
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(OsuGroupList.get().getRandomNode(), -1, true, true);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2014-07-09 01:03:43 +02:00
|
|
|
oldFocusNode = null;
|
2014-06-30 04:17:04 +02:00
|
|
|
} else if (!search.getText().isEmpty())
|
|
|
|
searchResultString = "No matches found. Hit 'esc' to reset.";
|
|
|
|
}
|
|
|
|
}
|
2015-02-16 03:38:54 +01:00
|
|
|
if (searchTransitionTimer < SEARCH_TRANSITION_TIME) {
|
|
|
|
searchTransitionTimer += delta;
|
|
|
|
if (searchTransitionTimer > SEARCH_TRANSITION_TIME)
|
|
|
|
searchTransitionTimer = SEARCH_TRANSITION_TIME;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// slide buttons
|
|
|
|
int height = container.getHeight();
|
2015-02-16 03:38:54 +01:00
|
|
|
if (buttonY > headerY) {
|
2014-06-30 04:17:04 +02:00
|
|
|
buttonY -= height * delta / 20000f;
|
2015-02-16 03:38:54 +01:00
|
|
|
if (buttonY < headerY)
|
|
|
|
buttonY = headerY;
|
|
|
|
} else if (buttonY < headerY) {
|
2014-06-30 04:17:04 +02:00
|
|
|
buttonY += height * delta / 20000f;
|
2015-02-16 03:38:54 +01:00
|
|
|
if (buttonY > headerY)
|
|
|
|
buttonY = headerY;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-01-08 22:28:49 +01:00
|
|
|
|
|
|
|
// mouse hover
|
|
|
|
boolean isHover = false;
|
2015-02-16 03:38:54 +01:00
|
|
|
if (mouseY > headerY && mouseY < footerY) {
|
|
|
|
OsuGroupNode node = startNode;
|
|
|
|
for (int i = 0; i < MAX_SONG_BUTTONS && node != null; i++, node = node.next) {
|
|
|
|
float cx = (node.index == OsuGroupList.get().getExpandedIndex()) ? buttonX * 0.9f : buttonX;
|
|
|
|
if ((mouseX > cx && mouseX < cx + buttonWidth) &&
|
|
|
|
(mouseY > buttonY + (i * buttonOffset) && mouseY < buttonY + (i * buttonOffset) + buttonHeight)) {
|
|
|
|
if (i == hoverIndex) {
|
|
|
|
if (hoverOffset < MAX_HOVER_OFFSET) {
|
|
|
|
hoverOffset += delta / 3f;
|
|
|
|
if (hoverOffset > MAX_HOVER_OFFSET)
|
|
|
|
hoverOffset = MAX_HOVER_OFFSET;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hoverIndex = i;
|
|
|
|
hoverOffset = 0f;
|
2015-01-08 22:28:49 +01:00
|
|
|
}
|
2015-02-16 03:38:54 +01:00
|
|
|
isHover = true;
|
|
|
|
break;
|
2015-01-08 22:28:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isHover) {
|
|
|
|
hoverOffset = 0f;
|
|
|
|
hoverIndex = -1;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getID() { return state; }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mousePressed(int button, int x, int y) {
|
2015-01-16 21:44:13 +01:00
|
|
|
// check mouse button
|
2015-02-13 08:43:34 +01:00
|
|
|
if (button == Input.MOUSE_MIDDLE_BUTTON)
|
2014-06-30 04:17:04 +02:00
|
|
|
return;
|
|
|
|
|
2015-02-13 08:43:34 +01:00
|
|
|
// block input
|
|
|
|
if (reloadThread != null || beatmapMenuTimer > -1)
|
2015-01-21 07:38:02 +01:00
|
|
|
return;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// back
|
2015-03-05 19:27:45 +01:00
|
|
|
if (UI.getBackButton().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();
|
2014-06-30 04:17:04 +02:00
|
|
|
game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
// selection buttons
|
|
|
|
if (selectModsButton.contains(x, y)) {
|
|
|
|
this.keyPressed(Input.KEY_F1, '\0');
|
|
|
|
return;
|
|
|
|
} else if (selectRandomButton.contains(x, y)) {
|
|
|
|
this.keyPressed(Input.KEY_F2, '\0');
|
|
|
|
return;
|
|
|
|
} else if (selectMapOptionsButton.contains(x, y)) {
|
|
|
|
this.keyPressed(Input.KEY_F3, '\0');
|
|
|
|
return;
|
|
|
|
} else if (selectOptionsButton.contains(x, y)) {
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
2015-01-21 07:38:02 +01:00
|
|
|
game.enterState(Opsu.STATE_OPTIONSMENU, new EmptyTransition(), new FadeInTransition(Color.black));
|
2014-06-30 04:17:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (focusNode == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// sorting buttons
|
2014-07-19 02:33:41 +02:00
|
|
|
for (SongSort sort : SongSort.values()) {
|
|
|
|
if (sort.contains(x, y)) {
|
|
|
|
if (sort != SongSort.getSort()) {
|
|
|
|
SongSort.setSort(sort);
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUCLICK);
|
2015-01-11 20:17:33 +01:00
|
|
|
OsuGroupNode oldFocusBase = OsuGroupList.get().getBaseNode(focusNode.index);
|
2014-07-03 00:24:19 +02:00
|
|
|
int oldFocusFileIndex = focusNode.osuFileIndex;
|
|
|
|
focusNode = null;
|
2015-01-11 20:17:33 +01:00
|
|
|
OsuGroupList.get().init();
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(oldFocusBase, oldFocusFileIndex, true, true);
|
2014-07-03 00:24:19 +02:00
|
|
|
}
|
|
|
|
return;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-11 01:13:53 +02:00
|
|
|
// song buttons
|
2015-02-16 03:38:54 +01:00
|
|
|
if (y > headerY && y < footerY) {
|
|
|
|
int expandedIndex = OsuGroupList.get().getExpandedIndex();
|
|
|
|
OsuGroupNode node = startNode;
|
|
|
|
for (int i = 0; i < MAX_SONG_BUTTONS && node != null; i++, node = node.next) {
|
|
|
|
// is button at this index clicked?
|
|
|
|
float cx = (node.index == expandedIndex) ? buttonX * 0.9f : buttonX;
|
|
|
|
if ((x > cx && x < cx + buttonWidth) &&
|
|
|
|
(y > buttonY + (i * buttonOffset) && y < buttonY + (i * buttonOffset) + buttonHeight)) {
|
|
|
|
float oldHoverOffset = hoverOffset;
|
|
|
|
int oldHoverIndex = hoverIndex;
|
2015-02-19 01:35:26 +01:00
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
// clicked node is already expanded
|
|
|
|
if (node.index == expandedIndex) {
|
|
|
|
if (node.osuFileIndex == focusNode.osuFileIndex) {
|
|
|
|
// if already focused, load the beatmap
|
|
|
|
if (button != Input.MOUSE_RIGHT_BUTTON)
|
|
|
|
startGame();
|
|
|
|
else
|
|
|
|
SoundController.playSound(SoundEffect.MENUCLICK);
|
|
|
|
} else {
|
|
|
|
// focus the node
|
2015-02-13 08:43:34 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUCLICK);
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(node, 0, false, true);
|
2015-02-16 03:38:54 +01:00
|
|
|
}
|
|
|
|
}
|
2015-02-19 01:35:26 +01:00
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
// clicked node is a new group
|
|
|
|
else {
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUCLICK);
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(node, -1, false, true);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-02-19 01:35:26 +01:00
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
// restore hover data
|
|
|
|
hoverOffset = oldHoverOffset;
|
|
|
|
hoverIndex = oldHoverIndex;
|
2015-02-19 01:35:26 +01:00
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
// open beatmap menu
|
|
|
|
if (button == Input.MOUSE_RIGHT_BUTTON)
|
|
|
|
beatmapMenuTimer = (node.index == expandedIndex) ? BEATMAP_MENU_DELAY * 4 / 5 : 0;
|
2015-02-19 01:35:26 +01:00
|
|
|
|
2015-02-16 03:38:54 +01:00
|
|
|
return;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-01-29 01:23:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// score buttons
|
|
|
|
if (focusScores != null && ScoreData.areaContains(x, y)) {
|
|
|
|
for (int i = 0; i < MAX_SCORE_BUTTONS; i++) {
|
|
|
|
int rank = startScore + i;
|
|
|
|
if (rank >= focusScores.length)
|
|
|
|
break;
|
|
|
|
if (ScoreData.buttonContains(x, y, i)) {
|
2015-02-13 09:45:38 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
|
|
|
if (button != Input.MOUSE_RIGHT_BUTTON) {
|
|
|
|
// view score
|
|
|
|
GameData data = new GameData(focusScores[rank], container.getWidth(), container.getHeight());
|
|
|
|
((GameRanking) game.getState(Opsu.STATE_GAMERANKING)).setGameData(data);
|
|
|
|
game.enterState(Opsu.STATE_GAMERANKING, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
|
|
|
} else {
|
|
|
|
// score management
|
|
|
|
((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.SCORE, focusScores[rank]);
|
|
|
|
game.enterState(Opsu.STATE_BUTTONMENU);
|
|
|
|
}
|
2015-01-29 01:23:02 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyPressed(int key, char c) {
|
2015-02-13 08:43:34 +01:00
|
|
|
// block input
|
|
|
|
if ((reloadThread != null && !(key == Input.KEY_ESCAPE || key == Input.KEY_F12)) || beatmapMenuTimer > -1)
|
2015-01-21 07:38:02 +01:00
|
|
|
return;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
switch (key) {
|
|
|
|
case Input.KEY_ESCAPE:
|
2015-01-21 07:38:02 +01:00
|
|
|
if (reloadThread != null) {
|
|
|
|
// beatmap reloading: stop parsing OsuFiles by sending interrupt to OsuParser
|
2015-02-02 06:15:16 +01:00
|
|
|
reloadThread.interrupt();
|
2015-01-21 07:38:02 +01:00
|
|
|
} else if (!search.getText().isEmpty()) {
|
|
|
|
// clear search text
|
2014-06-30 04:17:04 +02:00
|
|
|
search.setText("");
|
|
|
|
searchTimer = SEARCH_DELAY;
|
2015-02-16 03:38:54 +01:00
|
|
|
searchTransitionTimer = 0;
|
2014-07-01 07:14:03 +02:00
|
|
|
} else {
|
2015-01-21 07:38:02 +01:00
|
|
|
// return to main menu
|
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();
|
2014-06-30 04:17:04 +02:00
|
|
|
game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
2014-07-01 07:14:03 +02:00
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
case Input.KEY_F1:
|
2015-01-21 07:38:02 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
2015-02-16 23:53:24 +01:00
|
|
|
((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.MODS);
|
|
|
|
game.enterState(Opsu.STATE_BUTTONMENU);
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
case Input.KEY_F2:
|
2015-01-16 07:40:34 +01:00
|
|
|
if (focusNode == null)
|
|
|
|
break;
|
2015-02-16 03:38:54 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
2015-01-16 07:40:34 +01:00
|
|
|
if (input.isKeyDown(Input.KEY_RSHIFT) || input.isKeyDown(Input.KEY_LSHIFT)) {
|
|
|
|
// shift key: previous random track
|
|
|
|
SongNode prev;
|
|
|
|
if (randomStack.isEmpty() || (prev = randomStack.pop()) == null)
|
|
|
|
break;
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(prev.getNode(), prev.getIndex(), true, true);
|
2015-01-16 07:40:34 +01:00
|
|
|
} else {
|
|
|
|
// random track, add previous to stack
|
|
|
|
randomStack.push(new SongNode(OsuGroupList.get().getBaseNode(focusNode.index), focusNode.osuFileIndex));
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(OsuGroupList.get().getRandomNode(), -1, true, true);
|
2015-01-16 07:40:34 +01:00
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
2015-02-13 08:43:34 +01:00
|
|
|
case Input.KEY_F3:
|
|
|
|
if (focusNode == null)
|
|
|
|
break;
|
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
|
|
|
((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.BEATMAP, focusNode);
|
|
|
|
game.enterState(Opsu.STATE_BUTTONMENU);
|
|
|
|
break;
|
2015-01-21 07:38:02 +01:00
|
|
|
case Input.KEY_F5:
|
2015-02-13 08:43:34 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
|
|
|
((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.RELOAD);
|
|
|
|
game.enterState(Opsu.STATE_BUTTONMENU);
|
2015-01-21 07:38:02 +01:00
|
|
|
break;
|
2015-03-06 07:29:50 +01:00
|
|
|
case Input.KEY_DELETE:
|
|
|
|
if (focusNode == null)
|
|
|
|
break;
|
|
|
|
if (input.isKeyDown(Input.KEY_RSHIFT) || input.isKeyDown(Input.KEY_LSHIFT)) {
|
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
|
|
|
MenuState ms = (focusNode.osuFileIndex == -1 || focusNode.osuFiles.size() == 1) ?
|
|
|
|
MenuState.BEATMAP_DELETE_CONFIRM : MenuState.BEATMAP_DELETE_SELECT;
|
|
|
|
((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(ms, focusNode);
|
|
|
|
game.enterState(Opsu.STATE_BUTTONMENU);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
case Input.KEY_ENTER:
|
2015-01-16 08:00:42 +01:00
|
|
|
if (focusNode == null)
|
|
|
|
break;
|
|
|
|
if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
|
|
|
|
// turn on "auto" mod
|
|
|
|
if (!GameMod.AUTO.isActive())
|
|
|
|
GameMod.AUTO.toggle(true);
|
|
|
|
}
|
|
|
|
startGame();
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
case Input.KEY_DOWN:
|
|
|
|
changeIndex(1);
|
|
|
|
break;
|
|
|
|
case Input.KEY_UP:
|
|
|
|
changeIndex(-1);
|
|
|
|
break;
|
|
|
|
case Input.KEY_RIGHT:
|
|
|
|
if (focusNode == null)
|
|
|
|
break;
|
|
|
|
OsuGroupNode next = focusNode.next;
|
|
|
|
if (next != null) {
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUCLICK);
|
2015-01-14 05:00:09 +01:00
|
|
|
OsuGroupNode oldStartNode = startNode;
|
|
|
|
float oldHoverOffset = hoverOffset;
|
|
|
|
int oldHoverIndex = hoverIndex;
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(next, 0, false, true);
|
2015-01-14 05:00:09 +01:00
|
|
|
if (startNode == oldStartNode) {
|
|
|
|
hoverOffset = oldHoverOffset;
|
|
|
|
hoverIndex = oldHoverIndex;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Input.KEY_LEFT:
|
|
|
|
if (focusNode == null)
|
|
|
|
break;
|
|
|
|
OsuGroupNode prev = focusNode.prev;
|
|
|
|
if (prev != null) {
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUCLICK);
|
2015-01-14 05:00:09 +01:00
|
|
|
OsuGroupNode oldStartNode = startNode;
|
|
|
|
float oldHoverOffset = hoverOffset;
|
|
|
|
int oldHoverIndex = hoverIndex;
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(prev, (prev.index == focusNode.index) ? 0 : prev.osuFiles.size() - 1, false, true);
|
2015-01-14 05:00:09 +01:00
|
|
|
if (startNode == oldStartNode) {
|
|
|
|
hoverOffset = oldHoverOffset;
|
|
|
|
hoverIndex = oldHoverIndex;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Input.KEY_NEXT:
|
2015-01-29 01:23:02 +01:00
|
|
|
changeIndex(MAX_SONG_BUTTONS);
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
case Input.KEY_PRIOR:
|
2015-01-29 01:23:02 +01:00
|
|
|
changeIndex(-MAX_SONG_BUTTONS);
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// wait for user to finish typing
|
2015-02-16 03:38:54 +01:00
|
|
|
// TODO: accept all characters (current conditions are from TextField class)
|
|
|
|
if ((c > 31 && c < 127) || key == Input.KEY_BACK) {
|
2014-06-30 04:17:04 +02:00
|
|
|
searchTimer = 0;
|
2015-02-16 03:38:54 +01:00
|
|
|
int textLength = search.getText().length();
|
|
|
|
if (key == Input.KEY_BACK) {
|
|
|
|
if (textLength == 0)
|
|
|
|
searchTransitionTimer = 0;
|
|
|
|
} else if (textLength == 1)
|
|
|
|
searchTransitionTimer = 0;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
|
2015-02-13 08:43:34 +01:00
|
|
|
// block input
|
|
|
|
if (reloadThread != null || beatmapMenuTimer > -1)
|
2015-01-21 07:38:02 +01:00
|
|
|
return;
|
|
|
|
|
2015-01-29 01:23:02 +01:00
|
|
|
int diff = newy - oldy;
|
|
|
|
if (diff == 0)
|
|
|
|
return;
|
|
|
|
int shift = (diff < 0) ? 1 : -1;
|
|
|
|
|
|
|
|
// check mouse button (right click scrolls faster on songs)
|
2014-06-30 04:17:04 +02:00
|
|
|
int multiplier;
|
|
|
|
if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON))
|
|
|
|
multiplier = 4;
|
|
|
|
else if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON))
|
|
|
|
multiplier = 1;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
2015-01-29 01:23:02 +01:00
|
|
|
// score buttons
|
|
|
|
if (focusScores != null && focusScores.length >= MAX_SCORE_BUTTONS && ScoreData.areaContains(oldx, oldy)) {
|
|
|
|
int newStartScore = startScore + shift;
|
|
|
|
if (newStartScore >= 0 && newStartScore + MAX_SCORE_BUTTONS <= focusScores.length)
|
|
|
|
startScore = newStartScore;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-01-29 01:23:02 +01:00
|
|
|
|
|
|
|
// song buttons
|
|
|
|
else
|
|
|
|
changeIndex(shift * multiplier);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseWheelMoved(int newValue) {
|
2015-02-13 08:43:34 +01:00
|
|
|
// block input
|
|
|
|
if (reloadThread != null || beatmapMenuTimer > -1)
|
2015-01-21 07:38:02 +01:00
|
|
|
return;
|
|
|
|
|
2015-01-29 01:23:02 +01:00
|
|
|
int shift = (newValue < 0) ? 1 : -1;
|
|
|
|
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
|
|
|
|
|
|
|
// score buttons
|
|
|
|
if (focusScores != null && focusScores.length >= MAX_SCORE_BUTTONS && ScoreData.areaContains(mouseX, mouseY)) {
|
|
|
|
int newStartScore = startScore + shift;
|
|
|
|
if (newStartScore >= 0 && newStartScore + MAX_SCORE_BUTTONS <= focusScores.length)
|
|
|
|
startScore = newStartScore;
|
|
|
|
}
|
|
|
|
|
|
|
|
// song buttons
|
|
|
|
else
|
|
|
|
changeIndex(shift);
|
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-02-16 03:38:54 +01:00
|
|
|
selectModsButton.resetHover();
|
|
|
|
selectRandomButton.resetHover();
|
|
|
|
selectMapOptionsButton.resetHover();
|
|
|
|
selectOptionsButton.resetHover();
|
2015-01-08 22:28:49 +01:00
|
|
|
hoverOffset = 0f;
|
|
|
|
hoverIndex = -1;
|
2015-01-29 01:23:02 +01:00
|
|
|
startScore = 0;
|
2015-02-13 08:43:34 +01:00
|
|
|
beatmapMenuTimer = -1;
|
2015-02-16 03:38:54 +01:00
|
|
|
searchTransitionTimer = SEARCH_TRANSITION_TIME;
|
2015-02-13 08:43:34 +01:00
|
|
|
|
|
|
|
// reset song stack
|
|
|
|
randomStack = new Stack<SongNode>();
|
2014-12-21 00:17:04 +01:00
|
|
|
|
2015-02-02 06:15:16 +01:00
|
|
|
// set focus node if not set (e.g. theme song playing)
|
|
|
|
if (focusNode == null && OsuGroupList.get().size() > 0)
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(OsuGroupList.get().getRandomNode(), -1, true, true);
|
2015-01-15 05:10:19 +01:00
|
|
|
|
2015-01-21 01:01:18 +01:00
|
|
|
// reset music track
|
|
|
|
else if (resetTrack) {
|
|
|
|
MusicController.pause();
|
|
|
|
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
|
|
|
resetTrack = false;
|
|
|
|
}
|
|
|
|
|
2015-01-15 06:56:30 +01:00
|
|
|
// unpause track
|
|
|
|
else if (MusicController.isPaused())
|
|
|
|
MusicController.resume();
|
|
|
|
|
2015-01-29 02:57:43 +01:00
|
|
|
// undim track
|
|
|
|
if (MusicController.isTrackDimmed())
|
|
|
|
MusicController.toggleTrackDimmed(1f);
|
|
|
|
|
2015-01-16 06:36:05 +01:00
|
|
|
// reset game data
|
|
|
|
if (resetGame) {
|
|
|
|
((Game) game.getState(Opsu.STATE_GAME)).resetGameData();
|
2015-01-28 09:47:24 +01:00
|
|
|
|
2015-03-01 06:03:06 +01:00
|
|
|
// destroy extra Clips
|
|
|
|
MultiClip.destroyExtraClips();
|
|
|
|
|
2015-01-25 04:23:49 +01:00
|
|
|
// destroy skin images, if any
|
|
|
|
for (GameImage img : GameImage.values()) {
|
|
|
|
if (img.isSkinnable())
|
|
|
|
img.destroySkinImage();
|
|
|
|
}
|
2015-01-28 09:47:24 +01:00
|
|
|
|
|
|
|
// reload scores
|
2015-01-29 01:23:02 +01:00
|
|
|
if (focusNode != null) {
|
2015-01-29 06:56:30 +01:00
|
|
|
scoreMap = ScoreDB.getMapSetScores(focusNode.osuFiles.get(focusNode.osuFileIndex));
|
2015-01-29 09:05:09 +01:00
|
|
|
focusScores = getScoreDataForNode(focusNode, true);
|
2015-01-29 01:23:02 +01:00
|
|
|
}
|
2015-01-28 09:47:24 +01:00
|
|
|
|
2015-01-16 06:36:05 +01:00
|
|
|
resetGame = false;
|
|
|
|
}
|
2015-02-13 08:43:34 +01:00
|
|
|
|
|
|
|
// state-based action
|
|
|
|
if (stateAction != null) {
|
|
|
|
switch (stateAction) {
|
2015-02-13 09:45:38 +01:00
|
|
|
case BEATMAP: // clear all scores
|
2015-02-13 08:43:34 +01:00
|
|
|
if (stateActionNode == null || stateActionNode.osuFileIndex == -1)
|
|
|
|
break;
|
|
|
|
OsuFile osu = stateActionNode.osuFiles.get(stateActionNode.osuFileIndex);
|
|
|
|
ScoreDB.deleteScore(osu);
|
|
|
|
if (stateActionNode == focusNode) {
|
|
|
|
focusScores = null;
|
|
|
|
scoreMap.remove(osu.version);
|
|
|
|
}
|
|
|
|
break;
|
2015-02-13 09:45:38 +01:00
|
|
|
case SCORE: // clear single score
|
|
|
|
if (stateActionScore == null)
|
|
|
|
break;
|
|
|
|
ScoreDB.deleteScore(stateActionScore);
|
|
|
|
scoreMap = ScoreDB.getMapSetScores(focusNode.osuFiles.get(focusNode.osuFileIndex));
|
|
|
|
focusScores = getScoreDataForNode(focusNode, true);
|
|
|
|
startScore = 0;
|
|
|
|
break;
|
2015-02-13 08:43:34 +01:00
|
|
|
case BEATMAP_DELETE_CONFIRM: // delete song group
|
|
|
|
if (stateActionNode == null)
|
|
|
|
break;
|
|
|
|
OsuGroupNode
|
|
|
|
prev = OsuGroupList.get().getBaseNode(stateActionNode.index - 1),
|
|
|
|
next = OsuGroupList.get().getBaseNode(stateActionNode.index + 1);
|
|
|
|
int oldIndex = stateActionNode.index, focusNodeIndex = focusNode.index, startNodeIndex = startNode.index;
|
|
|
|
OsuGroupList.get().deleteSongGroup(stateActionNode);
|
|
|
|
if (oldIndex == focusNodeIndex) {
|
|
|
|
if (prev != null)
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(prev, -1, true, true);
|
2015-02-13 08:43:34 +01:00
|
|
|
else if (next != null)
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(next, -1, true, true);
|
2015-02-13 08:43:34 +01:00
|
|
|
else {
|
|
|
|
startNode = focusNode = null;
|
|
|
|
oldFocusNode = null;
|
|
|
|
randomStack = new Stack<SongNode>();
|
|
|
|
songInfo = null;
|
|
|
|
scoreMap = null;
|
|
|
|
focusScores = null;
|
|
|
|
}
|
|
|
|
} else if (oldIndex == startNodeIndex) {
|
|
|
|
if (startNode.prev != null)
|
|
|
|
startNode = startNode.prev;
|
|
|
|
else if (startNode.next != null)
|
|
|
|
startNode = startNode.next;
|
|
|
|
else {
|
|
|
|
startNode = null;
|
|
|
|
songInfo = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BEATMAP_DELETE_SELECT: // delete single song
|
|
|
|
if (stateActionNode == null)
|
|
|
|
break;
|
|
|
|
int index = stateActionNode.index;
|
|
|
|
OsuGroupList.get().deleteSong(stateActionNode);
|
|
|
|
if (stateActionNode == focusNode) {
|
|
|
|
if (stateActionNode.prev != null &&
|
|
|
|
!(stateActionNode.next != null && stateActionNode.next.index == index)) {
|
|
|
|
if (stateActionNode.prev.index == index)
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(stateActionNode.prev, 0, true, true);
|
2015-02-13 08:43:34 +01:00
|
|
|
else
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(stateActionNode.prev, -1, true, true);
|
2015-02-13 08:43:34 +01:00
|
|
|
} else if (stateActionNode.next != null) {
|
|
|
|
if (stateActionNode.next.index == index)
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(stateActionNode.next, 0, true, true);
|
2015-02-13 08:43:34 +01:00
|
|
|
else
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(stateActionNode.next, -1, true, true);
|
2015-02-13 08:43:34 +01:00
|
|
|
}
|
|
|
|
} else if (stateActionNode == startNode) {
|
|
|
|
if (startNode.prev != null)
|
|
|
|
startNode = startNode.prev;
|
|
|
|
else if (startNode.next != null)
|
|
|
|
startNode = startNode.next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RELOAD: // reload beatmaps
|
|
|
|
// reset state and node references
|
|
|
|
MusicController.reset();
|
|
|
|
startNode = focusNode = null;
|
|
|
|
scoreMap = null;
|
|
|
|
focusScores = null;
|
|
|
|
oldFocusNode = null;
|
|
|
|
randomStack = new Stack<SongNode>();
|
|
|
|
songInfo = null;
|
|
|
|
hoverOffset = 0f;
|
|
|
|
hoverIndex = -1;
|
|
|
|
search.setText("");
|
|
|
|
searchTimer = SEARCH_DELAY;
|
2015-02-16 03:38:54 +01:00
|
|
|
searchTransitionTimer = SEARCH_TRANSITION_TIME;
|
|
|
|
searchResultString = null;
|
2015-02-13 08:43:34 +01:00
|
|
|
|
|
|
|
// reload songs in new thread
|
|
|
|
reloadThread = new Thread() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-03-05 03:03:06 +01:00
|
|
|
// clear the beatmap cache
|
|
|
|
OsuDB.clearDatabase();
|
|
|
|
|
2015-02-13 08:43:34 +01:00
|
|
|
// invoke unpacker and parser
|
|
|
|
File beatmapDir = Options.getBeatmapDir();
|
|
|
|
OszUnpacker.unpackAllFiles(Options.getOSZDir(), beatmapDir);
|
|
|
|
OsuParser.parseAllFiles(beatmapDir);
|
|
|
|
|
|
|
|
// initialize song list
|
|
|
|
if (OsuGroupList.get().size() > 0) {
|
|
|
|
OsuGroupList.get().init();
|
2015-03-06 07:29:50 +01:00
|
|
|
setFocus(OsuGroupList.get().getRandomNode(), -1, true, true);
|
2015-02-13 08:43:34 +01:00
|
|
|
} else
|
|
|
|
MusicController.playThemeSong();
|
|
|
|
|
|
|
|
reloadThread = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
reloadThread.start();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
stateAction = null;
|
|
|
|
stateActionNode = null;
|
2015-02-13 09:45:38 +01:00
|
|
|
stateActionScore = null;
|
2015-02-13 08:43:34 +01:00
|
|
|
}
|
2014-07-05 20:29:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void leave(GameContainer container, StateBasedGame game)
|
|
|
|
throws SlickException {
|
|
|
|
search.setFocus(false);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shifts the startNode forward (+) or backwards (-) by a given number of nodes.
|
|
|
|
* Initiates sliding "animation" by shifting the button Y position.
|
2015-01-08 22:28:49 +01:00
|
|
|
* @param shift the number of nodes to shift
|
2014-06-30 04:17:04 +02:00
|
|
|
*/
|
|
|
|
private void changeIndex(int shift) {
|
2015-01-08 22:28:49 +01:00
|
|
|
if (shift == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int n = shift;
|
|
|
|
boolean shifted = false;
|
|
|
|
while (n != 0) {
|
2014-06-30 04:17:04 +02:00
|
|
|
if (startNode == null)
|
|
|
|
break;
|
2015-01-16 21:44:13 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
int height = container.getHeight();
|
2015-01-08 22:28:49 +01:00
|
|
|
if (n < 0 && startNode.prev != null) {
|
2014-06-30 04:17:04 +02:00
|
|
|
startNode = startNode.prev;
|
|
|
|
buttonY += buttonOffset / 4;
|
2015-02-16 03:38:54 +01:00
|
|
|
if (buttonY > headerY + height * 0.02f)
|
|
|
|
buttonY = headerY + height * 0.02f;
|
2015-01-08 22:28:49 +01:00
|
|
|
n++;
|
|
|
|
shifted = true;
|
|
|
|
} else if (n > 0 && startNode.next != null &&
|
2015-01-29 01:23:02 +01:00
|
|
|
OsuGroupList.get().getNode(startNode, MAX_SONG_BUTTONS) != null) {
|
2014-06-30 04:17:04 +02:00
|
|
|
startNode = startNode.next;
|
|
|
|
buttonY -= buttonOffset / 4;
|
2015-02-16 03:38:54 +01:00
|
|
|
if (buttonY < headerY - height * 0.02f)
|
|
|
|
buttonY = headerY - height * 0.02f;
|
2015-01-08 22:28:49 +01:00
|
|
|
n--;
|
|
|
|
shifted = true;
|
2014-06-30 04:17:04 +02:00
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
2015-01-08 22:28:49 +01:00
|
|
|
if (shifted) {
|
|
|
|
hoverOffset = 0f;
|
|
|
|
hoverIndex = -1;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a new focus node.
|
|
|
|
* @param node the base node; it will be expanded if it isn't already
|
2015-02-21 23:12:18 +01:00
|
|
|
* @param osuFileIndex the OsuFile element to focus; if out of bounds, it will be randomly chosen
|
|
|
|
* @param changeStartNode if true, startNode will be set to the first node in the group
|
2015-03-06 07:29:50 +01:00
|
|
|
* @param preview whether to start at the preview time (true) or beginning (false)
|
2014-06-30 04:17:04 +02:00
|
|
|
* @return the old focus node
|
|
|
|
*/
|
2015-03-06 07:29:50 +01:00
|
|
|
public OsuGroupNode setFocus(OsuGroupNode node, int osuFileIndex, boolean changeStartNode, boolean preview) {
|
2014-06-30 04:17:04 +02:00
|
|
|
if (node == null)
|
|
|
|
return null;
|
2014-07-11 01:13:53 +02:00
|
|
|
|
2015-01-08 22:28:49 +01:00
|
|
|
hoverOffset = 0f;
|
|
|
|
hoverIndex = -1;
|
2015-01-08 18:03:39 +01:00
|
|
|
songInfo = null;
|
2014-06-30 04:17:04 +02:00
|
|
|
OsuGroupNode oldFocus = focusNode;
|
|
|
|
|
|
|
|
// expand node before focusing it
|
2015-01-11 20:17:33 +01:00
|
|
|
int expandedIndex = OsuGroupList.get().getExpandedIndex();
|
2014-07-11 01:13:53 +02:00
|
|
|
if (node.index != expandedIndex) {
|
2015-01-11 20:17:33 +01:00
|
|
|
node = OsuGroupList.get().expand(node.index);
|
2014-07-11 01:13:53 +02:00
|
|
|
|
|
|
|
// if start node was previously expanded, move it
|
|
|
|
if (startNode != null && startNode.index == expandedIndex)
|
2015-02-21 23:12:18 +01:00
|
|
|
startNode = OsuGroupList.get().getBaseNode(startNode.index);
|
2014-07-11 01:13:53 +02:00
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-02-21 23:12:18 +01:00
|
|
|
// check osuFileIndex bounds
|
2014-06-30 04:17:04 +02:00
|
|
|
int length = node.osuFiles.size();
|
2015-02-21 23:12:18 +01:00
|
|
|
if (osuFileIndex < 0 || osuFileIndex > length - 1) // set a random index
|
|
|
|
osuFileIndex = (int) (Math.random() * length);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2014-07-11 01:13:53 +02:00
|
|
|
// change the focus node
|
2015-02-21 23:12:18 +01:00
|
|
|
if (changeStartNode || (startNode.index == 0 && startNode.osuFileIndex == -1 && startNode.prev == null))
|
2014-06-30 04:17:04 +02:00
|
|
|
startNode = node;
|
2015-02-21 23:12:18 +01:00
|
|
|
focusNode = OsuGroupList.get().getNode(node, osuFileIndex);
|
2014-08-25 05:48:52 +02:00
|
|
|
OsuFile osu = focusNode.osuFiles.get(focusNode.osuFileIndex);
|
2015-03-06 07:29:50 +01:00
|
|
|
MusicController.play(osu, true, preview);
|
2014-08-25 05:48:52 +02:00
|
|
|
Utils.loadGlyphs(osu);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-28 09:47:24 +01:00
|
|
|
// load scores
|
2015-01-29 06:56:30 +01:00
|
|
|
scoreMap = ScoreDB.getMapSetScores(osu);
|
2015-01-29 09:05:09 +01:00
|
|
|
focusScores = getScoreDataForNode(focusNode, true);
|
2015-01-29 01:23:02 +01:00
|
|
|
startScore = 0;
|
2015-01-28 09:47:24 +01:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// check startNode bounds
|
2015-01-29 01:23:02 +01:00
|
|
|
while (startNode.index >= OsuGroupList.get().size() + length - MAX_SONG_BUTTONS && startNode.prev != null)
|
2014-07-11 01:13:53 +02:00
|
|
|
startNode = startNode.prev;
|
|
|
|
|
|
|
|
// make sure focusNode is on the screen (TODO: cleanup...)
|
2015-01-29 01:23:02 +01:00
|
|
|
int val = focusNode.index + focusNode.osuFileIndex - (startNode.index + MAX_SONG_BUTTONS) + 1;
|
2014-07-11 01:13:53 +02:00
|
|
|
if (val > 0) // below screen
|
|
|
|
changeIndex(val);
|
|
|
|
else { // above screen
|
|
|
|
if (focusNode.index == startNode.index) {
|
|
|
|
val = focusNode.index + focusNode.osuFileIndex - (startNode.index + startNode.osuFileIndex);
|
|
|
|
if (val < 0)
|
|
|
|
changeIndex(val);
|
|
|
|
} else if (startNode.index > focusNode.index) {
|
|
|
|
val = focusNode.index - focusNode.osuFiles.size() + focusNode.osuFileIndex - startNode.index + 1;
|
|
|
|
if (val < 0)
|
|
|
|
changeIndex(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if start node is expanded and on group node, move it
|
|
|
|
if (startNode.index == focusNode.index && startNode.osuFileIndex == -1)
|
2014-06-30 04:17:04 +02:00
|
|
|
changeIndex(1);
|
|
|
|
|
|
|
|
return oldFocus;
|
|
|
|
}
|
|
|
|
|
2015-01-16 06:36:05 +01:00
|
|
|
/**
|
|
|
|
* Triggers a reset of game data upon entering this state.
|
|
|
|
*/
|
|
|
|
public void resetGameDataOnLoad() { resetGame = true; }
|
|
|
|
|
2015-01-16 21:44:13 +01:00
|
|
|
/**
|
|
|
|
* Triggers a reset of the music track upon entering this state.
|
|
|
|
*/
|
|
|
|
public void resetTrackOnLoad() { resetTrack = true; }
|
|
|
|
|
2015-02-13 08:43:34 +01:00
|
|
|
/**
|
|
|
|
* Performs an action based on a menu state upon entering this state.
|
|
|
|
* @param menuState the menu state determining the action
|
|
|
|
*/
|
2015-02-13 09:45:38 +01:00
|
|
|
public void doStateActionOnLoad(MenuState menuState) { doStateActionOnLoad(menuState, null, null); }
|
2015-02-13 08:43:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs an action based on a menu state upon entering this state.
|
|
|
|
* @param menuState the menu state determining the action
|
|
|
|
* @param node the song node to perform the action on
|
|
|
|
*/
|
|
|
|
public void doStateActionOnLoad(MenuState menuState, OsuGroupNode node) {
|
2015-02-13 09:45:38 +01:00
|
|
|
doStateActionOnLoad(menuState, node, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs an action based on a menu state upon entering this state.
|
|
|
|
* @param menuState the menu state determining the action
|
|
|
|
* @param scoreData the score data to perform the action on
|
|
|
|
*/
|
|
|
|
public void doStateActionOnLoad(MenuState menuState, ScoreData scoreData) {
|
|
|
|
doStateActionOnLoad(menuState, null, scoreData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs an action based on a menu state upon entering this state.
|
|
|
|
* @param menuState the menu state determining the action
|
|
|
|
* @param node the song node to perform the action on
|
|
|
|
* @param scoreData the score data to perform the action on
|
|
|
|
*/
|
|
|
|
private void doStateActionOnLoad(MenuState menuState, OsuGroupNode node, ScoreData scoreData) {
|
2015-02-13 08:43:34 +01:00
|
|
|
stateAction = menuState;
|
|
|
|
stateActionNode = node;
|
2015-02-13 09:45:38 +01:00
|
|
|
stateActionScore = scoreData;
|
2015-02-13 08:43:34 +01:00
|
|
|
}
|
|
|
|
|
2015-01-28 09:47:24 +01:00
|
|
|
/**
|
|
|
|
* Returns all the score data for an OsuGroupNode from scoreMap.
|
|
|
|
* If no score data is available for the node, return null.
|
|
|
|
* @param node the OsuGroupNode
|
2015-01-29 09:05:09 +01:00
|
|
|
* @param setTimeSince whether or not to set the "time since" field for the scores
|
2015-01-28 09:47:24 +01:00
|
|
|
* @return the ScoreData array
|
|
|
|
*/
|
2015-01-29 09:05:09 +01:00
|
|
|
private ScoreData[] getScoreDataForNode(OsuGroupNode node, boolean setTimeSince) {
|
2015-01-29 01:23:02 +01:00
|
|
|
if (scoreMap == null || scoreMap.isEmpty() || node.osuFileIndex == -1) // node not expanded
|
2015-01-28 09:47:24 +01:00
|
|
|
return null;
|
|
|
|
|
|
|
|
OsuFile osu = node.osuFiles.get(node.osuFileIndex);
|
|
|
|
ScoreData[] scores = scoreMap.get(osu.version);
|
|
|
|
if (scores == null || scores.length < 1) // no scores
|
|
|
|
return null;
|
|
|
|
|
|
|
|
ScoreData s = scores[0];
|
|
|
|
if (osu.beatmapID == s.MID && osu.beatmapSetID == s.MSID &&
|
|
|
|
osu.title.equals(s.title) && osu.artist.equals(s.artist) &&
|
2015-01-29 09:05:09 +01:00
|
|
|
osu.creator.equals(s.creator)) {
|
|
|
|
if (setTimeSince) {
|
|
|
|
for (int i = 0; i < scores.length; i++)
|
|
|
|
scores[i].getTimeSince();
|
|
|
|
}
|
2015-01-28 09:47:24 +01:00
|
|
|
return scores;
|
2015-01-29 09:05:09 +01:00
|
|
|
} else
|
2015-01-28 09:47:24 +01:00
|
|
|
return null; // incorrect map
|
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Starts the game.
|
|
|
|
*/
|
2014-07-03 05:38:30 +02:00
|
|
|
private void startGame() {
|
2014-07-15 06:20:36 +02:00
|
|
|
if (MusicController.isTrackLoading())
|
2014-06-30 04:17:04 +02:00
|
|
|
return;
|
|
|
|
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
2014-07-03 05:38:30 +02:00
|
|
|
OsuFile osu = MusicController.getOsuFile();
|
2014-06-30 04:17:04 +02:00
|
|
|
Display.setTitle(String.format("%s - %s", game.getTitle(), osu.toString()));
|
|
|
|
OsuParser.parseHitObjects(osu);
|
2015-03-01 17:06:46 +01:00
|
|
|
HitSound.setDefaultSampleSet(osu.sampleSet);
|
2015-03-01 06:03:06 +01:00
|
|
|
MultiClip.destroyExtraClips();
|
2015-01-15 06:56:30 +01:00
|
|
|
((Game) game.getState(Opsu.STATE_GAME)).setRestart(Game.Restart.NEW);
|
2014-06-30 04:17:04 +02:00
|
|
|
game.enterState(Opsu.STATE_GAME, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
|
|
|
}
|
|
|
|
}
|