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;
|
|
|
|
|
|
|
|
import itdelatrisu.opsu.GUIMenuButton;
|
|
|
|
import itdelatrisu.opsu.MusicController;
|
|
|
|
import itdelatrisu.opsu.Opsu;
|
|
|
|
import itdelatrisu.opsu.OsuFile;
|
|
|
|
import itdelatrisu.opsu.OsuGroupNode;
|
|
|
|
import itdelatrisu.opsu.OsuParser;
|
2014-07-19 02:33:41 +02:00
|
|
|
import itdelatrisu.opsu.SongSort;
|
2014-07-01 07:14:03 +02:00
|
|
|
import itdelatrisu.opsu.SoundController;
|
2014-07-02 01:32:03 +02:00
|
|
|
import itdelatrisu.opsu.Utils;
|
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 {
|
|
|
|
/**
|
|
|
|
* The number of buttons to be shown on each screen.
|
|
|
|
*/
|
|
|
|
private static final int MAX_BUTTONS = 6;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
|
|
|
/**
|
|
|
|
* Current start node (topmost menu entry).
|
|
|
|
*/
|
|
|
|
private OsuGroupNode startNode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Current focused (selected) node.
|
|
|
|
*/
|
|
|
|
private OsuGroupNode focusNode;
|
|
|
|
|
2014-07-09 01:03:43 +02:00
|
|
|
/**
|
|
|
|
* The base node of the previous focus node.
|
|
|
|
*/
|
|
|
|
private OsuGroupNode oldFocusNode = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The file index of the previous focus node.
|
|
|
|
*/
|
|
|
|
private int oldFileIndex = -1;
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
/**
|
|
|
|
* Button coordinate values.
|
|
|
|
*/
|
|
|
|
private float
|
|
|
|
buttonX, buttonY, buttonOffset,
|
|
|
|
buttonWidth, buttonHeight;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The options button (to enter the "Game Options" menu).
|
|
|
|
*/
|
|
|
|
private GUIMenuButton optionsButton;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The search textfield.
|
|
|
|
*/
|
|
|
|
private TextField search;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delay timer, in milliseconds, before running another search.
|
|
|
|
* This is overridden by character entry (reset) and 'esc' (immediate search).
|
|
|
|
*/
|
|
|
|
private int searchTimer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Information text to display based on the search query.
|
|
|
|
*/
|
|
|
|
private String searchResultString;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search icon.
|
|
|
|
*/
|
|
|
|
private Image searchIcon;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Music note icon.
|
|
|
|
*/
|
|
|
|
private Image musicNote;
|
|
|
|
|
2014-07-18 03:16:15 +02:00
|
|
|
/**
|
|
|
|
* Loader animation.
|
|
|
|
*/
|
|
|
|
private Animation loader;
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// song button background & graphics context
|
|
|
|
Image menuBackground = new Image("menu-button-background.png").getScaledCopy(width / 2, height / 6);
|
|
|
|
OsuGroupNode.setBackground(menuBackground);
|
|
|
|
|
|
|
|
// song button coordinates
|
|
|
|
buttonX = width * 0.6f;
|
|
|
|
buttonY = height * 0.16f;
|
|
|
|
buttonWidth = menuBackground.getWidth();
|
|
|
|
buttonHeight = menuBackground.getHeight();
|
|
|
|
buttonOffset = (height * 0.8f) / MAX_BUTTONS;
|
|
|
|
|
|
|
|
// search
|
|
|
|
searchTimer = 0;
|
|
|
|
searchResultString = "Type to search!";
|
|
|
|
|
|
|
|
searchIcon = new Image("search.png");
|
2014-07-02 01:32:03 +02:00
|
|
|
float iconScale = Utils.FONT_BOLD.getLineHeight() * 2f / searchIcon.getHeight();
|
2014-06-30 04:17:04 +02:00
|
|
|
searchIcon = searchIcon.getScaledCopy(iconScale);
|
|
|
|
|
2014-07-19 02:33:41 +02:00
|
|
|
Image tab = Utils.getTabImage();
|
2014-06-30 04:17:04 +02:00
|
|
|
search = new TextField(
|
2014-07-02 01:32:03 +02:00
|
|
|
container, Utils.FONT_DEFAULT,
|
2014-07-19 02:33:41 +02:00
|
|
|
(int) buttonX + (tab.getWidth() / 2) + searchIcon.getWidth(),
|
|
|
|
(int) ((height * 0.15f) - (tab.getHeight() * 2.5f)),
|
2014-08-24 20:48:27 +02:00
|
|
|
(int) (buttonWidth / 2), Utils.FONT_DEFAULT.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);
|
|
|
|
|
|
|
|
// options button
|
|
|
|
Image optionsIcon = new Image("options.png").getScaledCopy(iconScale);
|
|
|
|
optionsButton = new GUIMenuButton(optionsIcon, search.getX() - (optionsIcon.getWidth() * 1.5f), search.getY());
|
2014-12-24 05:41:37 +01:00
|
|
|
optionsButton.setHoverScale(1.75f);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2014-07-18 03:16:15 +02:00
|
|
|
// music note
|
2014-08-24 20:48:27 +02:00
|
|
|
int musicNoteDim = (int) (Utils.FONT_LARGE.getLineHeight() * 0.75f + Utils.FONT_DEFAULT.getLineHeight());
|
2014-07-08 19:38:16 +02:00
|
|
|
musicNote = new Image("music-note.png").getScaledCopy(musicNoteDim, musicNoteDim);
|
2014-07-18 03:16:15 +02:00
|
|
|
|
|
|
|
// loader
|
|
|
|
SpriteSheet spr = new SpriteSheet(
|
|
|
|
new Image("loader.png").getScaledCopy(musicNoteDim / 48f),
|
|
|
|
musicNoteDim, musicNoteDim
|
|
|
|
);
|
|
|
|
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();
|
|
|
|
|
|
|
|
// background
|
|
|
|
if (focusNode != null)
|
|
|
|
focusNode.osuFiles.get(focusNode.osuFileIndex).drawBG(width, height, 1.0f);
|
|
|
|
|
|
|
|
// header setup
|
|
|
|
float lowerBound = height * 0.15f;
|
2014-07-02 01:32:03 +02:00
|
|
|
g.setColor(Utils.COLOR_BLACK_ALPHA);
|
2014-06-30 04:17:04 +02:00
|
|
|
g.fillRect(0, 0, width, lowerBound);
|
2014-07-02 01:32:03 +02:00
|
|
|
g.setColor(Utils.COLOR_BLUE_DIVIDER);
|
2014-06-30 04:17:04 +02:00
|
|
|
g.setLineWidth(2f);
|
|
|
|
g.drawLine(0, lowerBound, width, lowerBound);
|
|
|
|
g.resetLineWidth();
|
|
|
|
|
|
|
|
// header
|
|
|
|
if (focusNode != null) {
|
2014-07-18 03:16:15 +02:00
|
|
|
if (MusicController.isTrackLoading())
|
|
|
|
loader.draw();
|
|
|
|
else
|
|
|
|
musicNote.draw();
|
|
|
|
int iconWidth = musicNote.getWidth();
|
|
|
|
int iconHeight = musicNote.getHeight();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
String[] info = focusNode.getInfo();
|
|
|
|
g.setColor(Color.white);
|
2014-07-18 03:16:15 +02:00
|
|
|
Utils.FONT_LARGE.drawString(iconWidth + 5, -3, info[0]);
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.FONT_DEFAULT.drawString(
|
2014-08-24 20:48:27 +02:00
|
|
|
iconWidth + 5, -3 + Utils.FONT_LARGE.getLineHeight() * 0.75f, info[1]);
|
2014-07-18 03:16:15 +02:00
|
|
|
int headerY = iconHeight - 3;
|
2014-07-08 19:38:16 +02:00
|
|
|
Utils.FONT_BOLD.drawString(5, headerY, info[2]);
|
|
|
|
headerY += Utils.FONT_BOLD.getLineHeight() - 6;
|
|
|
|
Utils.FONT_DEFAULT.drawString(5, headerY, info[3]);
|
|
|
|
headerY += Utils.FONT_DEFAULT.getLineHeight() - 4;
|
|
|
|
Utils.FONT_SMALL.drawString(5, headerY, info[4]);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// song buttons
|
|
|
|
OsuGroupNode node = startNode;
|
|
|
|
for (int i = 0; i < MAX_BUTTONS && node != null; i++) {
|
|
|
|
node.draw(buttonX, buttonY + (i*buttonOffset), (node == focusNode));
|
2014-08-25 05:48:52 +02:00
|
|
|
Utils.loadGlyphs(node.osuFiles.get(0));
|
2014-06-30 04:17:04 +02:00
|
|
|
node = node.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// options button
|
|
|
|
optionsButton.draw();
|
|
|
|
|
|
|
|
// sorting tabs
|
2014-07-19 02:33:41 +02:00
|
|
|
SongSort.drawAll();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// search
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.FONT_BOLD.drawString(
|
|
|
|
search.getX(), search.getY() - Utils.FONT_BOLD.getLineHeight(),
|
2014-06-30 04:17:04 +02:00
|
|
|
searchResultString, Color.white
|
|
|
|
);
|
|
|
|
searchIcon.draw(search.getX() - searchIcon.getWidth(),
|
2014-07-02 01:32:03 +02:00
|
|
|
search.getY() - Utils.FONT_DEFAULT.getLineHeight());
|
2014-06-30 04:17:04 +02:00
|
|
|
g.setColor(Color.white);
|
|
|
|
search.render(container, g);
|
|
|
|
|
|
|
|
// scroll bar
|
|
|
|
if (focusNode != null) {
|
|
|
|
float scrollStartY = height * 0.16f;
|
|
|
|
float scrollEndY = height * 0.82f;
|
2014-07-02 01:32:03 +02:00
|
|
|
g.setColor(Utils.COLOR_BLACK_ALPHA);
|
2014-06-30 04:17:04 +02:00
|
|
|
g.fillRoundRect(width - 10, scrollStartY, 5, scrollEndY, 4);
|
|
|
|
g.setColor(Color.white);
|
|
|
|
g.fillRoundRect(width - 10, scrollStartY + (scrollEndY * startNode.index / Opsu.groups.size()), 5, 20, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
// back button
|
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);
|
|
|
|
optionsButton.hoverUpdate(delta, mouseX, mouseY);
|
2014-07-07 05:13:33 +02:00
|
|
|
|
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;
|
|
|
|
if (searchTimer >= SEARCH_DELAY) {
|
|
|
|
searchTimer = 0;
|
|
|
|
|
|
|
|
// store the start/focus nodes
|
|
|
|
if (focusNode != null) {
|
|
|
|
oldFocusNode = Opsu.groups.getBaseNode(focusNode.index);
|
|
|
|
oldFileIndex = focusNode.osuFileIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Opsu.groups.search(search.getText())) {
|
|
|
|
// empty search
|
|
|
|
if (search.getText().isEmpty())
|
|
|
|
searchResultString = "Type to search!";
|
|
|
|
|
|
|
|
// search produced new list: re-initialize it
|
|
|
|
startNode = focusNode = null;
|
|
|
|
if (Opsu.groups.size() > 0) {
|
2014-07-19 02:33:41 +02:00
|
|
|
Opsu.groups.init();
|
2014-06-30 04:17:04 +02:00
|
|
|
if (search.getText().isEmpty()) { // cleared search
|
|
|
|
// use previous start/focus if possible
|
|
|
|
if (oldFocusNode != null)
|
2014-07-11 01:13:53 +02:00
|
|
|
setFocus(oldFocusNode, oldFileIndex, true);
|
2014-06-30 04:17:04 +02:00
|
|
|
else
|
|
|
|
setFocus(Opsu.groups.getRandomNode(), -1, true);
|
|
|
|
} else {
|
2014-07-17 18:49:12 +02:00
|
|
|
int size = Opsu.groups.size();
|
|
|
|
searchResultString = String.format("%d match%s found!",
|
|
|
|
size, (size == 1) ? "" : "es");
|
2014-06-30 04:17:04 +02:00
|
|
|
setFocus(Opsu.groups.getRandomNode(), -1, true);
|
|
|
|
}
|
2014-07-09 01:03:43 +02:00
|
|
|
oldFocusNode = null;
|
|
|
|
oldFileIndex = -1;
|
2014-06-30 04:17:04 +02:00
|
|
|
} else if (!search.getText().isEmpty())
|
|
|
|
searchResultString = "No matches found. Hit 'esc' to reset.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// slide buttons
|
|
|
|
int height = container.getHeight();
|
|
|
|
float targetY = height * 0.16f;
|
|
|
|
if (buttonY > targetY) {
|
|
|
|
buttonY -= height * delta / 20000f;
|
|
|
|
if (buttonY < targetY)
|
|
|
|
buttonY = targetY;
|
|
|
|
} else if (buttonY < targetY) {
|
|
|
|
buttonY += height * delta / 20000f;
|
|
|
|
if (buttonY > targetY)
|
|
|
|
buttonY = targetY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getID() { return state; }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mousePressed(int button, int x, int y) {
|
|
|
|
// check mouse button
|
|
|
|
if (button != Input.MOUSE_LEFT_BUTTON)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// back
|
2014-07-02 01:32:03 +02:00
|
|
|
if (Utils.getBackButton().contains(x, y)) {
|
2014-07-01 07:14:03 +02:00
|
|
|
SoundController.playSound(SoundController.SOUND_MENUBACK);
|
2014-06-30 04:17:04 +02:00
|
|
|
game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// options
|
|
|
|
if (optionsButton.contains(x, y)) {
|
2014-07-03 00:24:19 +02:00
|
|
|
SoundController.playSound(SoundController.SOUND_MENUHIT);
|
2014-06-30 04:17:04 +02:00
|
|
|
game.enterState(Opsu.STATE_OPTIONS, new EmptyTransition(), new FadeInTransition(Color.black));
|
|
|
|
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);
|
2014-07-03 05:38:30 +02:00
|
|
|
SoundController.playSound(SoundController.SOUND_MENUCLICK);
|
2014-07-03 00:24:19 +02:00
|
|
|
OsuGroupNode oldFocusBase = Opsu.groups.getBaseNode(focusNode.index);
|
|
|
|
int oldFocusFileIndex = focusNode.osuFileIndex;
|
|
|
|
focusNode = null;
|
2014-07-19 02:33:41 +02:00
|
|
|
Opsu.groups.init();
|
2014-07-11 01:13:53 +02:00
|
|
|
setFocus(oldFocusBase, oldFocusFileIndex, 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
|
|
|
|
int expandedIndex = Opsu.groups.getExpandedIndex();
|
|
|
|
OsuGroupNode node = startNode;
|
|
|
|
for (int i = 0; i < MAX_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)) {
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// clicked node is already expanded
|
|
|
|
if (node.index == expandedIndex) {
|
2014-07-11 01:13:53 +02:00
|
|
|
if (node.osuFileIndex == focusNode.osuFileIndex) {
|
2014-06-30 04:17:04 +02:00
|
|
|
// if already focused, load the beatmap
|
2014-07-03 05:38:30 +02:00
|
|
|
startGame();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// focus the node
|
2014-07-09 01:03:43 +02:00
|
|
|
SoundController.playSound(SoundController.SOUND_MENUCLICK);
|
2014-06-30 04:17:04 +02:00
|
|
|
setFocus(node, 0, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-11 01:13:53 +02:00
|
|
|
// clicked node is a new group
|
|
|
|
else {
|
|
|
|
SoundController.playSound(SoundController.SOUND_MENUCLICK);
|
|
|
|
setFocus(node, -1, false);
|
|
|
|
break;
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void keyPressed(int key, char c) {
|
|
|
|
switch (key) {
|
|
|
|
case Input.KEY_ESCAPE:
|
|
|
|
if (!search.getText().isEmpty()) {
|
|
|
|
search.setText("");
|
|
|
|
searchTimer = SEARCH_DELAY;
|
2014-07-01 07:14:03 +02:00
|
|
|
} else {
|
|
|
|
SoundController.playSound(SoundController.SOUND_MENUBACK);
|
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:
|
|
|
|
game.enterState(Opsu.STATE_OPTIONS, new EmptyTransition(), new FadeInTransition(Color.black));
|
|
|
|
break;
|
|
|
|
case Input.KEY_F2:
|
|
|
|
setFocus(Opsu.groups.getRandomNode(), -1, true);
|
|
|
|
break;
|
|
|
|
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:
|
|
|
|
if (focusNode != null)
|
2014-07-03 05:38:30 +02:00
|
|
|
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) {
|
2014-07-09 01:03:43 +02:00
|
|
|
SoundController.playSound(SoundController.SOUND_MENUCLICK);
|
2014-07-11 01:13:53 +02:00
|
|
|
setFocus(next, 0, false);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Input.KEY_LEFT:
|
|
|
|
if (focusNode == null)
|
|
|
|
break;
|
|
|
|
OsuGroupNode prev = focusNode.prev;
|
|
|
|
if (prev != null) {
|
2014-07-09 01:03:43 +02:00
|
|
|
SoundController.playSound(SoundController.SOUND_MENUCLICK);
|
2014-07-11 01:13:53 +02:00
|
|
|
setFocus(prev, (prev.index == focusNode.index) ? 0 : prev.osuFiles.size() - 1, false);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Input.KEY_NEXT:
|
|
|
|
changeIndex(MAX_BUTTONS);
|
|
|
|
break;
|
|
|
|
case Input.KEY_PRIOR:
|
|
|
|
changeIndex(-MAX_BUTTONS);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// wait for user to finish typing
|
|
|
|
if (Character.isLetterOrDigit(c) || key == Input.KEY_BACK)
|
|
|
|
searchTimer = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
|
|
|
|
// check mouse button (right click scrolls faster)
|
|
|
|
int multiplier;
|
|
|
|
if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON))
|
|
|
|
multiplier = 4;
|
|
|
|
else if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON))
|
|
|
|
multiplier = 1;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
int diff = newy - oldy;
|
|
|
|
if (diff != 0) {
|
|
|
|
diff = ((diff < 0) ? 1 : -1) * multiplier;
|
|
|
|
changeIndex(diff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mouseWheelMoved(int newValue) {
|
|
|
|
changeIndex((newValue < 0) ? 1 : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
optionsButton.setScale(1f);
|
2014-12-21 00:17:04 +01:00
|
|
|
|
|
|
|
// stop playing the theme song
|
|
|
|
if (MusicController.isThemePlaying() && focusNode != null)
|
|
|
|
MusicController.play(focusNode.osuFiles.get(focusNode.osuFileIndex), true);
|
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.
|
|
|
|
*/
|
|
|
|
private void changeIndex(int shift) {
|
|
|
|
while (shift != 0) {
|
|
|
|
if (startNode == null)
|
|
|
|
break;
|
|
|
|
|
|
|
|
int height = container.getHeight();
|
|
|
|
if (shift < 0 && startNode.prev != null) {
|
|
|
|
startNode = startNode.prev;
|
|
|
|
buttonY += buttonOffset / 4;
|
|
|
|
if (buttonY > height * 0.18f)
|
|
|
|
buttonY = height * 0.18f;
|
|
|
|
shift++;
|
|
|
|
} else if (shift > 0 && startNode.next != null &&
|
2014-12-20 21:30:20 +01:00
|
|
|
Opsu.groups.getNode(startNode, MAX_BUTTONS) != null) {
|
2014-06-30 04:17:04 +02:00
|
|
|
startNode = startNode.next;
|
|
|
|
buttonY -= buttonOffset / 4;
|
|
|
|
if (buttonY < height * 0.14f)
|
|
|
|
buttonY = height * 0.14f;
|
|
|
|
shift--;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a new focus node.
|
|
|
|
* @param node the base node; it will be expanded if it isn't already
|
|
|
|
* @param pos the OsuFile element to focus; if out of bounds, it will be randomly chosen
|
2014-07-11 01:13:53 +02:00
|
|
|
* @param flag if true, startNode will be set to the first node in the group
|
2014-06-30 04:17:04 +02:00
|
|
|
* @return the old focus node
|
|
|
|
*/
|
|
|
|
public OsuGroupNode setFocus(OsuGroupNode node, int pos, boolean flag) {
|
|
|
|
if (node == null)
|
|
|
|
return null;
|
2014-07-11 01:13:53 +02:00
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
OsuGroupNode oldFocus = focusNode;
|
|
|
|
|
|
|
|
// expand node before focusing it
|
2014-07-11 01:13:53 +02:00
|
|
|
int expandedIndex = Opsu.groups.getExpandedIndex();
|
|
|
|
if (node.index != expandedIndex) {
|
|
|
|
node = Opsu.groups.expand(node.index);
|
|
|
|
|
|
|
|
// if start node was previously expanded, move it
|
|
|
|
if (startNode != null && startNode.index == expandedIndex)
|
|
|
|
startNode = node;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// check pos bounds
|
|
|
|
int length = node.osuFiles.size();
|
2014-07-11 01:13:53 +02:00
|
|
|
if (pos < 0 || pos > length - 1) // set a random pos
|
|
|
|
pos = (int) (Math.random() * length);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2014-07-11 01:13:53 +02:00
|
|
|
// change the focus node
|
2014-07-11 04:01:39 +02:00
|
|
|
if (flag || (startNode.index == 0 && startNode.osuFileIndex == -1 && startNode.prev == null))
|
2014-06-30 04:17:04 +02:00
|
|
|
startNode = node;
|
|
|
|
focusNode = Opsu.groups.getNode(node, pos);
|
2014-08-25 05:48:52 +02:00
|
|
|
OsuFile osu = focusNode.osuFiles.get(focusNode.osuFileIndex);
|
|
|
|
MusicController.play(osu, true);
|
|
|
|
Utils.loadGlyphs(osu);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// check startNode bounds
|
2014-07-11 01:13:53 +02:00
|
|
|
while (startNode.index >= Opsu.groups.size() + length - MAX_BUTTONS && startNode.prev != null)
|
|
|
|
startNode = startNode.prev;
|
|
|
|
|
|
|
|
// make sure focusNode is on the screen (TODO: cleanup...)
|
|
|
|
int val = focusNode.index + focusNode.osuFileIndex - (startNode.index + MAX_BUTTONS) + 1;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Starts the game.
|
|
|
|
* @param osu the OsuFile to send to 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;
|
|
|
|
|
2014-07-01 07:14:03 +02:00
|
|
|
SoundController.playSound(SoundController.SOUND_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);
|
2014-07-01 07:14:03 +02:00
|
|
|
SoundController.setSampleSet(osu.sampleSet);
|
2014-06-30 04:17:04 +02:00
|
|
|
Game.setRestart(Game.RESTART_NEW);
|
|
|
|
game.enterState(Opsu.STATE_GAME, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
|
|
|
}
|
|
|
|
}
|