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-16 19:42:54 +01:00
|
|
|
import itdelatrisu.opsu.ErrorHandler;
|
2015-01-08 05:45:21 +01:00
|
|
|
import itdelatrisu.opsu.GameImage;
|
2014-12-30 06:00:58 +01:00
|
|
|
import itdelatrisu.opsu.MenuButton;
|
2015-02-01 08:10:17 +01:00
|
|
|
import itdelatrisu.opsu.MenuButton.Expand;
|
2014-06-30 04:17:04 +02:00
|
|
|
import itdelatrisu.opsu.Opsu;
|
2015-01-21 05:56:10 +01:00
|
|
|
import itdelatrisu.opsu.Options;
|
2014-07-02 09:02:11 +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;
|
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.MusicController;
|
|
|
|
import itdelatrisu.opsu.audio.SoundController;
|
|
|
|
import itdelatrisu.opsu.audio.SoundEffect;
|
2015-03-07 10:17:19 +01:00
|
|
|
import itdelatrisu.opsu.downloads.Updater;
|
2015-02-13 08:43:34 +01:00
|
|
|
import itdelatrisu.opsu.states.ButtonMenu.MenuState;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-16 19:42:54 +01:00
|
|
|
import java.awt.Desktop;
|
|
|
|
import java.io.IOException;
|
2014-06-30 04:17:04 +02:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Stack;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import org.newdawn.slick.Color;
|
|
|
|
import org.newdawn.slick.GameContainer;
|
|
|
|
import org.newdawn.slick.Graphics;
|
|
|
|
import org.newdawn.slick.Image;
|
|
|
|
import org.newdawn.slick.Input;
|
|
|
|
import org.newdawn.slick.SlickException;
|
|
|
|
import org.newdawn.slick.state.BasicGameState;
|
|
|
|
import org.newdawn.slick.state.StateBasedGame;
|
|
|
|
import org.newdawn.slick.state.transition.FadeInTransition;
|
|
|
|
import org.newdawn.slick.state.transition.FadeOutTransition;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "Main Menu" state.
|
|
|
|
* <ul>
|
|
|
|
* <li>[Play] - move to song selection menu
|
|
|
|
* <li>[Exit] - move to confirm exit menu
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
public class MainMenu extends BasicGameState {
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Idle time, in milliseconds, before returning the logo to its original position. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private static final short MOVE_DELAY = 5000;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Logo button that reveals other buttons on click. */
|
2014-12-30 06:00:58 +01:00
|
|
|
private MenuButton logo;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Whether or not the logo has been clicked. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private boolean logoClicked = false;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Delay timer, in milliseconds, before starting to move the logo back to the center. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private int logoTimer = 0;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Main "Play" and "Exit" buttons. */
|
2014-12-30 06:00:58 +01:00
|
|
|
private MenuButton playButton, exitButton;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Music control buttons. */
|
2014-12-30 06:00:58 +01:00
|
|
|
private MenuButton musicPlay, musicPause, musicNext, musicPrevious;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-02-01 08:10:17 +01:00
|
|
|
/** Button linking to Downloads menu. */
|
|
|
|
private MenuButton downloadsButton;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Button linking to repository. */
|
2015-01-16 19:42:54 +01:00
|
|
|
private MenuButton repoButton;
|
|
|
|
|
2015-03-07 10:17:19 +01:00
|
|
|
/** Button for installing updates. */
|
|
|
|
private MenuButton updateButton;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Application start time, for drawing the total running time. */
|
2014-06-30 04:17:04 +02:00
|
|
|
private long osuStartTime;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Indexes of previous songs. */
|
2015-01-15 06:56:30 +01:00
|
|
|
private Stack<Integer> previous;
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Background alpha level (for fade-in effect). */
|
2014-07-06 03:00:52 +02:00
|
|
|
private float bgAlpha = 0f;
|
2014-07-02 09:02:11 +02:00
|
|
|
|
2015-03-07 10:17:19 +01:00
|
|
|
/** Whether or not an update notification was already sent. */
|
|
|
|
private boolean updateNotification = false;
|
|
|
|
|
2015-02-15 06:25:07 +01:00
|
|
|
/** Music position bar coordinates and dimensions. */
|
|
|
|
private float musicBarX, musicBarY, musicBarWidth, musicBarHeight;
|
|
|
|
|
|
|
|
/** Music position bar background colors. */
|
|
|
|
private static final Color
|
|
|
|
BG_NORMAL = new Color(0, 0, 0, 0.25f),
|
|
|
|
BG_HOVER = new Color(0, 0, 0, 0.5f);
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// game-related variables
|
2014-12-21 23:02:11 +01:00
|
|
|
private GameContainer container;
|
2014-06-30 04:17:04 +02:00
|
|
|
private StateBasedGame game;
|
2014-12-24 05:41:37 +01:00
|
|
|
private Input input;
|
2014-06-30 04:17:04 +02:00
|
|
|
private int state;
|
|
|
|
|
|
|
|
public MainMenu(int state) {
|
|
|
|
this.state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void init(GameContainer container, StateBasedGame game)
|
|
|
|
throws SlickException {
|
2014-12-21 23:02:11 +01:00
|
|
|
this.container = container;
|
2014-06-30 04:17:04 +02:00
|
|
|
this.game = game;
|
2014-12-24 05:41:37 +01:00
|
|
|
this.input = container.getInput();
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
osuStartTime = System.currentTimeMillis();
|
|
|
|
previous = new Stack<Integer>();
|
|
|
|
|
|
|
|
int width = container.getWidth();
|
|
|
|
int height = container.getHeight();
|
|
|
|
|
2015-01-16 19:42:54 +01:00
|
|
|
// initialize menu buttons
|
2015-01-15 06:56:30 +01:00
|
|
|
Image logoImg = GameImage.MENU_LOGO.getImage();
|
2015-01-08 05:45:21 +01:00
|
|
|
Image playImg = GameImage.MENU_PlAY.getImage();
|
|
|
|
Image exitImg = GameImage.MENU_EXIT.getImage();
|
2014-06-30 04:17:04 +02:00
|
|
|
float exitOffset = (playImg.getWidth() - exitImg.getWidth()) / 3f;
|
2015-01-15 06:56:30 +01:00
|
|
|
logo = new MenuButton(logoImg, width / 2f, height / 2f);
|
|
|
|
playButton = new MenuButton(playImg,
|
|
|
|
width * 0.75f, (height / 2) - (logoImg.getHeight() / 5f)
|
2014-06-30 04:17:04 +02:00
|
|
|
);
|
2015-01-15 06:56:30 +01:00
|
|
|
exitButton = new MenuButton(exitImg,
|
2014-06-30 04:17:04 +02:00
|
|
|
width * 0.75f - exitOffset, (height / 2) + (exitImg.getHeight() / 2f)
|
|
|
|
);
|
2015-02-02 06:15:16 +01:00
|
|
|
logo.setHoverExpand(1.05f);
|
|
|
|
playButton.setHoverExpand(1.05f);
|
|
|
|
exitButton.setHoverExpand(1.05f);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
|
|
|
// initialize music buttons
|
2015-02-15 06:25:07 +01:00
|
|
|
int musicWidth = GameImage.MUSIC_PLAY.getImage().getWidth();
|
|
|
|
int musicHeight = GameImage.MUSIC_PLAY.getImage().getHeight();
|
|
|
|
musicPlay = new MenuButton(GameImage.MUSIC_PLAY.getImage(), width - (2 * musicWidth), musicHeight / 1.5f);
|
|
|
|
musicPause = new MenuButton(GameImage.MUSIC_PAUSE.getImage(), width - (2 * musicWidth), musicHeight / 1.5f);
|
|
|
|
musicNext = new MenuButton(GameImage.MUSIC_NEXT.getImage(), width - musicWidth, musicHeight / 1.5f);
|
|
|
|
musicPrevious = new MenuButton(GameImage.MUSIC_PREVIOUS.getImage(), width - (3 * musicWidth), musicHeight / 1.5f);
|
2015-02-02 06:15:16 +01:00
|
|
|
musicPlay.setHoverExpand(1.5f);
|
|
|
|
musicPause.setHoverExpand(1.5f);
|
|
|
|
musicNext.setHoverExpand(1.5f);
|
|
|
|
musicPrevious.setHoverExpand(1.5f);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-02-15 06:25:07 +01:00
|
|
|
// initialize music position bar location
|
|
|
|
musicBarX = width - musicWidth * 3.5f;
|
|
|
|
musicBarY = musicHeight * 1.25f;
|
|
|
|
musicBarWidth = musicWidth * 3f;
|
|
|
|
musicBarHeight = musicHeight * 0.11f;
|
|
|
|
|
2015-02-01 08:10:17 +01:00
|
|
|
// initialize downloads button
|
|
|
|
Image dlImg = GameImage.DOWNLOADS.getImage();
|
|
|
|
downloadsButton = new MenuButton(dlImg, width - dlImg.getWidth() / 2f, height / 2f);
|
2015-02-02 06:15:16 +01:00
|
|
|
downloadsButton.setHoverExpand(1.03f, Expand.LEFT);
|
2015-02-01 08:10:17 +01:00
|
|
|
|
2015-01-16 19:42:54 +01:00
|
|
|
// initialize repository button
|
2015-03-07 10:17:19 +01:00
|
|
|
float startX = width * 0.997f, startY = height * 0.997f;
|
2015-01-16 19:42:54 +01:00
|
|
|
if (Desktop.isDesktopSupported()) { // only if a webpage can be opened
|
|
|
|
Image repoImg = GameImage.REPOSITORY.getImage();
|
|
|
|
repoButton = new MenuButton(repoImg,
|
2015-03-07 10:17:19 +01:00
|
|
|
startX - repoImg.getWidth(), startY - repoImg.getHeight()
|
2015-01-16 19:42:54 +01:00
|
|
|
);
|
2015-02-02 06:15:16 +01:00
|
|
|
repoButton.setHoverExpand();
|
2015-03-07 10:17:19 +01:00
|
|
|
startX -= repoImg.getWidth() * 1.75f;
|
|
|
|
} else
|
|
|
|
startX -= width * 0.005f;
|
|
|
|
|
|
|
|
// initialize update button
|
|
|
|
Image bangImg = GameImage.BANG.getImage();
|
|
|
|
updateButton = new MenuButton(bangImg, startX - bangImg.getWidth(), startY - bangImg.getHeight());
|
|
|
|
updateButton.setHoverExpand(1.15f);
|
2015-01-16 19:42:54 +01:00
|
|
|
|
2014-12-30 06:41:32 +01:00
|
|
|
reset();
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void render(GameContainer container, StateBasedGame game, Graphics g)
|
|
|
|
throws SlickException {
|
2014-07-02 09:02:11 +02:00
|
|
|
int width = container.getWidth();
|
|
|
|
int height = container.getHeight();
|
2015-01-16 21:44:13 +01:00
|
|
|
|
2014-07-02 09:02:11 +02:00
|
|
|
// draw background
|
|
|
|
OsuFile osu = MusicController.getOsuFile();
|
|
|
|
if (Options.isDynamicBackgroundEnabled() &&
|
2015-02-10 03:40:38 +01:00
|
|
|
osu != null && osu.drawBG(width, height, bgAlpha, true))
|
2014-07-02 09:02:11 +02:00
|
|
|
;
|
2015-01-16 00:16:46 +01:00
|
|
|
else {
|
|
|
|
Image bg = GameImage.MENU_BG.getImage();
|
|
|
|
bg.setAlpha(bgAlpha);
|
|
|
|
bg.draw();
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-02-15 06:25:07 +01:00
|
|
|
// top/bottom horizontal bars
|
2015-01-18 18:39:30 +01:00
|
|
|
float oldAlpha = Utils.COLOR_BLACK_ALPHA.a;
|
|
|
|
Utils.COLOR_BLACK_ALPHA.a = 0.2f;
|
|
|
|
g.setColor(Utils.COLOR_BLACK_ALPHA);
|
|
|
|
g.fillRect(0, 0, width, height / 9f);
|
|
|
|
g.fillRect(0, height * 8 / 9f, width, height / 9f);
|
|
|
|
Utils.COLOR_BLACK_ALPHA.a = oldAlpha;
|
|
|
|
|
2015-02-01 08:10:17 +01:00
|
|
|
// draw downloads button
|
|
|
|
downloadsButton.draw();
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// draw buttons
|
|
|
|
if (logoTimer > 0) {
|
|
|
|
playButton.draw();
|
|
|
|
exitButton.draw();
|
|
|
|
}
|
|
|
|
logo.draw();
|
|
|
|
|
|
|
|
// draw music buttons
|
|
|
|
if (MusicController.isPlaying())
|
|
|
|
musicPause.draw();
|
|
|
|
else
|
|
|
|
musicPlay.draw();
|
|
|
|
musicNext.draw();
|
|
|
|
musicPrevious.draw();
|
2015-02-15 06:25:07 +01:00
|
|
|
|
|
|
|
// draw music position bar
|
|
|
|
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
|
|
|
g.setColor((musicPositionBarContains(mouseX, mouseY)) ? BG_HOVER : BG_NORMAL);
|
|
|
|
g.fillRoundRect(musicBarX, musicBarY, musicBarWidth, musicBarHeight, 4);
|
2014-06-30 04:17:04 +02:00
|
|
|
g.setColor(Color.white);
|
2015-02-15 06:25:07 +01:00
|
|
|
if (!MusicController.isTrackLoading() && osu != null) {
|
|
|
|
float musicBarPosition = Math.min((float) MusicController.getPosition() / osu.endTime, 1f);
|
|
|
|
g.fillRoundRect(musicBarX, musicBarY, musicBarWidth * musicBarPosition, musicBarHeight, 4);
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-01-16 19:42:54 +01:00
|
|
|
// draw repository button
|
|
|
|
if (repoButton != null)
|
|
|
|
repoButton.draw();
|
|
|
|
|
2015-03-07 10:17:19 +01:00
|
|
|
// draw update button
|
|
|
|
boolean showUpdateButton = Updater.get().showButton();
|
|
|
|
if (Updater.get().showButton()) {
|
|
|
|
Color updateColor = null;
|
|
|
|
switch (Updater.get().getStatus()) {
|
|
|
|
case UPDATE_AVAILABLE:
|
|
|
|
updateColor = Color.red;
|
|
|
|
break;
|
|
|
|
case UPDATE_DOWNLOADED:
|
|
|
|
updateColor = Color.green;
|
|
|
|
break;
|
|
|
|
case UPDATE_DOWNLOADING:
|
|
|
|
updateColor = Color.yellow;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
updateColor = Color.white;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
updateButton.draw(updateColor);
|
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// draw text
|
2015-01-18 18:39:30 +01:00
|
|
|
float marginX = width * 0.015f, marginY = height * 0.015f;
|
2014-07-02 09:02:11 +02:00
|
|
|
g.setFont(Utils.FONT_MEDIUM);
|
2015-01-18 18:39:30 +01:00
|
|
|
int lineHeight = Utils.FONT_MEDIUM.getLineHeight() * 9 / 10;
|
2014-06-30 04:17:04 +02:00
|
|
|
g.drawString(String.format("Loaded %d songs and %d beatmaps.",
|
2015-02-19 06:33:32 +01:00
|
|
|
OsuGroupList.get().getMapSetCount(), OsuGroupList.get().getMapCount()), marginX, marginY);
|
2014-07-15 06:20:36 +02:00
|
|
|
if (MusicController.isTrackLoading())
|
2015-01-18 18:39:30 +01:00
|
|
|
g.drawString("Track loading...", marginX, marginY + lineHeight);
|
2014-06-30 04:17:04 +02:00
|
|
|
else if (MusicController.trackExists()) {
|
2015-01-18 18:39:30 +01:00
|
|
|
g.drawString((MusicController.isPlaying()) ? "Now Playing:" : "Paused:", marginX, marginY + lineHeight);
|
2014-06-30 04:17:04 +02:00
|
|
|
g.drawString(String.format("%s: %s",
|
|
|
|
MusicController.getArtistName(),
|
|
|
|
MusicController.getTrackName()),
|
2015-01-18 18:39:30 +01:00
|
|
|
marginX + 25, marginY + (lineHeight * 2));
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
long time = System.currentTimeMillis() - osuStartTime;
|
|
|
|
g.drawString(String.format("opsu! has been running for %d minutes, %d seconds.",
|
|
|
|
TimeUnit.MILLISECONDS.toMinutes(time),
|
2015-01-16 21:44:13 +01:00
|
|
|
TimeUnit.MILLISECONDS.toSeconds(time) -
|
2014-07-09 19:36:42 +02:00
|
|
|
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))),
|
2015-01-18 18:39:30 +01:00
|
|
|
marginX, height - marginY - (lineHeight * 2));
|
2014-06-30 04:17:04 +02:00
|
|
|
g.drawString(String.format("The current time is %s.",
|
|
|
|
new SimpleDateFormat("h:mm a").format(new Date())),
|
2015-01-18 18:39:30 +01:00
|
|
|
marginX, height - marginY - lineHeight);
|
2014-06-30 04:17:04 +02:00
|
|
|
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.draw(g);
|
2015-02-26 08:06:34 +01:00
|
|
|
|
|
|
|
// tooltips
|
|
|
|
if (musicPositionBarContains(mouseX, mouseY))
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.drawTooltip(g, "Click to seek to a specific point in the song.", false);
|
2015-02-26 08:06:34 +01:00
|
|
|
else if (musicPlay.contains(mouseX, mouseY))
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.drawTooltip(g, (MusicController.isPlaying()) ? "Pause" : "Play", false);
|
2015-02-26 08:06:34 +01:00
|
|
|
else if (musicNext.contains(mouseX, mouseY))
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.drawTooltip(g, "Next track", false);
|
2015-02-26 08:06:34 +01:00
|
|
|
else if (musicPrevious.contains(mouseX, mouseY))
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.drawTooltip(g, "Previous track", false);
|
2015-03-07 10:17:19 +01:00
|
|
|
else if (showUpdateButton && updateButton.contains(mouseX, mouseY))
|
|
|
|
UI.drawTooltip(g, Updater.get().getStatus().getDescription(), true);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2014-07-02 16:14:15 +02:00
|
|
|
|
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-02-19 21:05:55 +01:00
|
|
|
logo.hoverUpdate(delta, mouseX, mouseY, 0.25f);
|
|
|
|
playButton.hoverUpdate(delta, mouseX, mouseY, 0.25f);
|
|
|
|
exitButton.hoverUpdate(delta, mouseX, mouseY, 0.25f);
|
2015-01-17 06:44:23 +01:00
|
|
|
if (repoButton != null)
|
|
|
|
repoButton.hoverUpdate(delta, mouseX, mouseY);
|
2015-03-07 10:17:19 +01:00
|
|
|
updateButton.hoverUpdate(delta, mouseX, mouseY);
|
2015-02-01 08:10:17 +01:00
|
|
|
downloadsButton.hoverUpdate(delta, mouseX, mouseY);
|
2015-02-26 08:06:34 +01:00
|
|
|
// ensure only one button is in hover state at once
|
|
|
|
if (musicPositionBarContains(mouseX, mouseY))
|
|
|
|
mouseX = mouseY = -1;
|
2014-12-24 05:41:37 +01:00
|
|
|
musicPlay.hoverUpdate(delta, mouseX, mouseY);
|
|
|
|
musicPause.hoverUpdate(delta, mouseX, mouseY);
|
2015-01-17 06:44:23 +01:00
|
|
|
if (musicPlay.contains(mouseX, mouseY))
|
2015-02-26 08:06:34 +01:00
|
|
|
mouseX = mouseY = -1;
|
2014-12-24 05:41:37 +01:00
|
|
|
musicNext.hoverUpdate(delta, mouseX, mouseY);
|
|
|
|
musicPrevious.hoverUpdate(delta, mouseX, mouseY);
|
2014-07-07 05:13:33 +02:00
|
|
|
|
2015-01-11 02:14:39 +01:00
|
|
|
// window focus change: increase/decrease theme song volume
|
2015-01-16 22:02:02 +01:00
|
|
|
if (MusicController.isThemePlaying() &&
|
|
|
|
MusicController.isTrackDimmed() == container.hasFocus())
|
2015-01-29 02:57:43 +01:00
|
|
|
MusicController.toggleTrackDimmed(0.33f);
|
2015-01-11 02:14:39 +01:00
|
|
|
|
2014-07-06 03:00:52 +02:00
|
|
|
// fade in background
|
|
|
|
if (bgAlpha < 0.9f) {
|
|
|
|
bgAlpha += delta / 1000f;
|
|
|
|
if (bgAlpha > 0.9f)
|
|
|
|
bgAlpha = 0.9f;
|
2014-07-02 09:02:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// buttons
|
2014-06-30 04:17:04 +02:00
|
|
|
if (logoClicked) {
|
|
|
|
if (logoTimer == 0) { // shifting to left
|
|
|
|
if (logo.getX() > container.getWidth() / 3.3f)
|
|
|
|
logo.setX(logo.getX() - delta);
|
|
|
|
else
|
|
|
|
logoTimer = 1;
|
|
|
|
} else if (logoTimer >= MOVE_DELAY) // timer over: shift back to center
|
|
|
|
logoClicked = false;
|
|
|
|
else { // increment timer
|
|
|
|
logoTimer += delta;
|
|
|
|
if (logoTimer <= 500) {
|
|
|
|
// fade in buttons
|
|
|
|
playButton.getImage().setAlpha(logoTimer / 400f);
|
|
|
|
exitButton.getImage().setAlpha(logoTimer / 400f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// fade out buttons
|
|
|
|
if (logoTimer > 0) {
|
|
|
|
float alpha = playButton.getImage().getAlpha();
|
|
|
|
if (alpha > 0f) {
|
|
|
|
playButton.getImage().setAlpha(alpha - (delta / 200f));
|
|
|
|
exitButton.getImage().setAlpha(alpha - (delta / 200f));
|
|
|
|
} else
|
|
|
|
logoTimer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// move back to original location
|
|
|
|
if (logo.getX() < container.getWidth() / 2) {
|
2014-07-15 19:21:37 +02:00
|
|
|
logo.setX(logo.getX() + (delta / 3f));
|
2014-06-30 04:17:04 +02:00
|
|
|
if (logo.getX() > container.getWidth() / 2)
|
|
|
|
logo.setX(container.getWidth() / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getID() { return state; }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void enter(GameContainer container, StateBasedGame game)
|
|
|
|
throws SlickException {
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.enter();
|
2015-03-07 10:17:19 +01:00
|
|
|
if (!updateNotification && Updater.get().getStatus() == Updater.Status.UPDATE_AVAILABLE) {
|
|
|
|
UI.sendBarNotification("An opsu! update is available.");
|
|
|
|
updateNotification = true;
|
|
|
|
}
|
2015-03-05 19:27:45 +01:00
|
|
|
|
2014-12-30 06:41:32 +01:00
|
|
|
// reset button hover states if mouse is not currently hovering over the button
|
|
|
|
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
2015-02-19 21:05:55 +01:00
|
|
|
if (!logo.contains(mouseX, mouseY, 0.25f))
|
2015-02-02 06:15:16 +01:00
|
|
|
logo.resetHover();
|
2015-02-19 21:05:55 +01:00
|
|
|
if (!playButton.contains(mouseX, mouseY, 0.25f))
|
2015-02-02 06:15:16 +01:00
|
|
|
playButton.resetHover();
|
2015-02-19 21:05:55 +01:00
|
|
|
if (!exitButton.contains(mouseX, mouseY, 0.25f))
|
2015-02-02 06:15:16 +01:00
|
|
|
exitButton.resetHover();
|
2014-12-30 06:41:32 +01:00
|
|
|
if (!musicPlay.contains(mouseX, mouseY))
|
2015-02-02 06:15:16 +01:00
|
|
|
musicPlay.resetHover();
|
2014-12-30 06:41:32 +01:00
|
|
|
if (!musicPause.contains(mouseX, mouseY))
|
2015-02-02 06:15:16 +01:00
|
|
|
musicPause.resetHover();
|
2014-12-30 06:41:32 +01:00
|
|
|
if (!musicNext.contains(mouseX, mouseY))
|
2015-02-02 06:15:16 +01:00
|
|
|
musicNext.resetHover();
|
2014-12-30 06:41:32 +01:00
|
|
|
if (!musicPrevious.contains(mouseX, mouseY))
|
2015-02-02 06:15:16 +01:00
|
|
|
musicPrevious.resetHover();
|
2015-01-16 19:42:54 +01:00
|
|
|
if (repoButton != null && !repoButton.contains(mouseX, mouseY))
|
2015-02-02 06:15:16 +01:00
|
|
|
repoButton.resetHover();
|
2015-03-07 10:17:19 +01:00
|
|
|
if (!updateButton.contains(mouseX, mouseY))
|
|
|
|
updateButton.resetHover();
|
2015-02-01 08:10:17 +01:00
|
|
|
if (!downloadsButton.contains(mouseX, mouseY))
|
2015-02-02 06:15:16 +01:00
|
|
|
downloadsButton.resetHover();
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void mousePressed(int button, int x, int y) {
|
2015-01-16 21:44:13 +01:00
|
|
|
// check mouse button
|
2015-02-13 09:45:38 +01:00
|
|
|
if (button == Input.MOUSE_MIDDLE_BUTTON)
|
2014-06-30 04:17:04 +02:00
|
|
|
return;
|
|
|
|
|
2015-02-15 06:25:07 +01:00
|
|
|
// music position bar
|
|
|
|
if (MusicController.isPlaying()) {
|
|
|
|
if (musicPositionBarContains(x, y)) {
|
|
|
|
float pos = (x - musicBarX) / musicBarWidth;
|
|
|
|
OsuFile osu = MusicController.getOsuFile();
|
|
|
|
MusicController.setPosition((int) (pos * osu.endTime));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// music button actions
|
|
|
|
if (musicPlay.contains(x, y)) {
|
2015-03-05 18:44:10 +01:00
|
|
|
if (MusicController.isPlaying()) {
|
2014-06-30 04:17:04 +02:00
|
|
|
MusicController.pause();
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.sendBarNotification("Pause");
|
2015-03-05 18:44:10 +01:00
|
|
|
} else if (!MusicController.isTrackLoading()) {
|
2014-06-30 04:17:04 +02:00
|
|
|
MusicController.resume();
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.sendBarNotification("Play");
|
2015-03-05 18:44:10 +01:00
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
} else if (musicNext.contains(x, y)) {
|
2015-03-06 07:29:50 +01:00
|
|
|
nextTrack();
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.sendBarNotification(">> Next");
|
2014-06-30 04:17:04 +02:00
|
|
|
} else if (musicPrevious.contains(x, y)) {
|
|
|
|
if (!previous.isEmpty()) {
|
|
|
|
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
|
2015-03-06 07:29:50 +01:00
|
|
|
menu.setFocus(OsuGroupList.get().getBaseNode(previous.pop()), -1, true, false);
|
2014-07-06 03:00:52 +02:00
|
|
|
if (Options.isDynamicBackgroundEnabled())
|
|
|
|
bgAlpha = 0f;
|
2014-06-30 04:17:04 +02:00
|
|
|
} else
|
|
|
|
MusicController.setPosition(0);
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.sendBarNotification("<< Previous");
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
|
2015-02-01 08:10:17 +01:00
|
|
|
// downloads button actions
|
|
|
|
else if (downloadsButton.contains(x, y)) {
|
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
|
|
|
game.enterState(Opsu.STATE_DOWNLOADSMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
|
|
|
}
|
|
|
|
|
2015-01-16 19:42:54 +01:00
|
|
|
// repository button actions
|
|
|
|
else if (repoButton != null && repoButton.contains(x, y)) {
|
|
|
|
try {
|
|
|
|
Desktop.getDesktop().browse(Options.REPOSITORY_URI);
|
|
|
|
} catch (IOException e) {
|
|
|
|
ErrorHandler.error("Could not browse to repository URI.", e, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-07 10:17:19 +01:00
|
|
|
// update button actions
|
|
|
|
else if (Updater.get().showButton() && updateButton.contains(x, y)) {
|
|
|
|
switch (Updater.get().getStatus()) {
|
|
|
|
case UPDATE_AVAILABLE:
|
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
|
|
|
Updater.get().startDownload();
|
|
|
|
break;
|
|
|
|
case UPDATE_DOWNLOADED:
|
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
|
|
|
Updater.get().prepareUpdate();
|
|
|
|
container.setForceExit(false);
|
|
|
|
container.exit();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
// start moving logo (if clicked)
|
|
|
|
else if (!logoClicked) {
|
2015-02-19 21:05:55 +01:00
|
|
|
if (logo.contains(x, y, 0.25f)) {
|
2014-06-30 04:17:04 +02:00
|
|
|
logoClicked = true;
|
|
|
|
logoTimer = 0;
|
|
|
|
playButton.getImage().setAlpha(0f);
|
|
|
|
exitButton.getImage().setAlpha(0f);
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// other button actions (if visible)
|
|
|
|
else if (logoClicked) {
|
2015-02-19 21:05:55 +01:00
|
|
|
if (logo.contains(x, y, 0.25f) || playButton.contains(x, y, 0.25f)) {
|
2015-01-08 01:29:51 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
2014-06-30 04:17:04 +02:00
|
|
|
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
2015-02-19 21:05:55 +01:00
|
|
|
} else if (exitButton.contains(x, y, 0.25f))
|
2014-12-21 23:02:11 +01:00
|
|
|
container.exit();
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 20:52:02 +01:00
|
|
|
@Override
|
|
|
|
public void mouseWheelMoved(int newValue) {
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.changeVolume((newValue < 0) ? -1 : 1);
|
2015-01-20 20:52:02 +01:00
|
|
|
}
|
|
|
|
|
2014-06-30 04:17:04 +02:00
|
|
|
@Override
|
|
|
|
public void keyPressed(int key, char c) {
|
|
|
|
switch (key) {
|
|
|
|
case Input.KEY_ESCAPE:
|
2014-07-05 20:29:48 +02:00
|
|
|
case Input.KEY_Q:
|
2015-02-13 08:43:34 +01:00
|
|
|
((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.EXIT);
|
|
|
|
game.enterState(Opsu.STATE_BUTTONMENU);
|
2014-07-05 20:29:48 +02:00
|
|
|
break;
|
|
|
|
case Input.KEY_P:
|
2015-03-06 07:29:50 +01:00
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
2014-07-05 20:29:48 +02:00
|
|
|
if (!logoClicked) {
|
|
|
|
logoClicked = true;
|
|
|
|
logoTimer = 0;
|
|
|
|
playButton.getImage().setAlpha(0f);
|
|
|
|
exitButton.getImage().setAlpha(0f);
|
2015-03-06 07:29:50 +01:00
|
|
|
} else
|
2014-07-05 20:29:48 +02:00
|
|
|
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
2015-03-06 07:29:50 +01:00
|
|
|
break;
|
|
|
|
case Input.KEY_D:
|
|
|
|
SoundController.playSound(SoundEffect.MENUHIT);
|
|
|
|
game.enterState(Opsu.STATE_DOWNLOADSMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
|
|
|
break;
|
|
|
|
case Input.KEY_R:
|
|
|
|
nextTrack();
|
2014-07-05 20:29:48 +02:00
|
|
|
break;
|
2015-01-21 04:19:14 +01:00
|
|
|
case Input.KEY_UP:
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.changeVolume(1);
|
2015-01-21 04:19:14 +01:00
|
|
|
break;
|
|
|
|
case Input.KEY_DOWN:
|
2015-03-05 19:27:45 +01:00
|
|
|
UI.changeVolume(-1);
|
2015-01-21 04:19:14 +01:00
|
|
|
break;
|
2015-03-05 20:40:57 +01:00
|
|
|
case Input.KEY_F7:
|
|
|
|
Options.setNextFPS(container);
|
|
|
|
break;
|
|
|
|
case Input.KEY_F10:
|
|
|
|
Options.toggleMouseDisabled();
|
|
|
|
break;
|
2014-06-30 04:17:04 +02:00
|
|
|
case Input.KEY_F12:
|
2014-07-02 01:32:03 +02:00
|
|
|
Utils.takeScreenShot();
|
2014-06-30 04:17:04 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-12-30 06:41:32 +01:00
|
|
|
}
|
|
|
|
|
2015-02-15 06:25:07 +01:00
|
|
|
/**
|
|
|
|
* Returns true if the coordinates are within the music position bar bounds.
|
|
|
|
* @param cx the x coordinate
|
|
|
|
* @param cy the y coordinate
|
|
|
|
*/
|
|
|
|
private boolean musicPositionBarContains(float cx, float cy) {
|
|
|
|
return ((cx > musicBarX && cx < musicBarX + musicBarWidth) &&
|
|
|
|
(cy > musicBarY && cy < musicBarY + musicBarHeight));
|
|
|
|
}
|
|
|
|
|
2014-12-30 06:41:32 +01:00
|
|
|
/**
|
|
|
|
* Resets the button states.
|
|
|
|
*/
|
|
|
|
public void reset() {
|
|
|
|
// reset logo
|
|
|
|
logo.setX(container.getWidth() / 2);
|
|
|
|
logoClicked = false;
|
|
|
|
logoTimer = 0;
|
|
|
|
|
2015-02-02 06:15:16 +01:00
|
|
|
logo.resetHover();
|
|
|
|
playButton.resetHover();
|
|
|
|
exitButton.resetHover();
|
|
|
|
musicPlay.resetHover();
|
|
|
|
musicPause.resetHover();
|
|
|
|
musicNext.resetHover();
|
|
|
|
musicPrevious.resetHover();
|
2015-03-07 10:17:19 +01:00
|
|
|
if (repoButton != null)
|
|
|
|
repoButton.resetHover();
|
|
|
|
updateButton.resetHover();
|
2015-02-02 06:15:16 +01:00
|
|
|
downloadsButton.resetHover();
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|
2015-03-06 07:29:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Plays the next track, and adds the previous one to the stack.
|
|
|
|
*/
|
|
|
|
private void nextTrack() {
|
|
|
|
boolean isTheme = MusicController.isThemePlaying();
|
|
|
|
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
|
|
|
|
OsuGroupNode node = menu.setFocus(OsuGroupList.get().getRandomNode(), -1, true, false);
|
|
|
|
boolean sameAudio = false;
|
|
|
|
if (node != null) {
|
|
|
|
sameAudio = MusicController.getOsuFile().audioFilename.equals(node.osuFiles.get(0).audioFilename);
|
|
|
|
if (!isTheme && !sameAudio)
|
|
|
|
previous.add(node.index);
|
|
|
|
}
|
|
|
|
if (Options.isDynamicBackgroundEnabled() && !sameAudio && !MusicController.isThemePlaying())
|
|
|
|
bgAlpha = 0f;
|
|
|
|
}
|
2014-06-30 04:17:04 +02:00
|
|
|
}
|