Added star fountains to main menu.
- Added MusicController methods to get measure progress (similar to beat progress). - Workaround for inaccurate track positions after looping by not looping. - Make sure star duration is positive. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
@@ -35,6 +35,7 @@ import itdelatrisu.opsu.ui.Colors;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.MenuButton;
|
||||
import itdelatrisu.opsu.ui.MenuButton.Expand;
|
||||
import itdelatrisu.opsu.ui.StarFountain;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
import itdelatrisu.opsu.ui.animations.AnimatedValue;
|
||||
import itdelatrisu.opsu.ui.animations.AnimationEquation;
|
||||
@@ -53,8 +54,8 @@ 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.EasedFadeOutTransition;
|
||||
import org.newdawn.slick.state.transition.FadeInTransition;
|
||||
|
||||
/**
|
||||
* "Main Menu" state.
|
||||
@@ -116,6 +117,12 @@ public class MainMenu extends BasicGameState {
|
||||
/** Music position bar coordinates and dimensions. */
|
||||
private float musicBarX, musicBarY, musicBarWidth, musicBarHeight;
|
||||
|
||||
/** Last measure progress value. */
|
||||
private float lastMeasureProgress = 0f;
|
||||
|
||||
/** The star fountain. */
|
||||
private StarFountain starFountain;
|
||||
|
||||
// game-related variables
|
||||
private GameContainer container;
|
||||
private StateBasedGame game;
|
||||
@@ -214,6 +221,9 @@ public class MainMenu extends BasicGameState {
|
||||
restartButton.setHoverAnimationEquation(AnimationEquation.LINEAR);
|
||||
restartButton.setHoverRotate(360);
|
||||
|
||||
// initialize star fountain
|
||||
starFountain = new StarFountain(width, height);
|
||||
|
||||
// logo animations
|
||||
float centerOffsetX = width / 5f;
|
||||
logoOpen = new AnimatedValue(400, 0, centerOffsetX, AnimationEquation.OUT_QUAD);
|
||||
@@ -248,6 +258,9 @@ public class MainMenu extends BasicGameState {
|
||||
g.fillRect(0, height * 8 / 9f, width, height / 9f);
|
||||
Colors.BLACK_ALPHA.a = oldAlpha;
|
||||
|
||||
// draw star fountain
|
||||
starFountain.draw();
|
||||
|
||||
// draw downloads button
|
||||
downloadsButton.draw();
|
||||
|
||||
@@ -329,7 +342,7 @@ public class MainMenu extends BasicGameState {
|
||||
throws SlickException {
|
||||
UI.update(delta);
|
||||
if (MusicController.trackEnded())
|
||||
nextTrack(); // end of track: go to next track
|
||||
nextTrack(false); // end of track: go to next track
|
||||
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
||||
logo.hoverUpdate(delta, mouseX, mouseY, 0.25f);
|
||||
playButton.hoverUpdate(delta, mouseX, mouseY, 0.25f);
|
||||
@@ -349,6 +362,7 @@ public class MainMenu extends BasicGameState {
|
||||
noHoverUpdate |= contains;
|
||||
musicNext.hoverUpdate(delta, !noHoverUpdate && musicNext.contains(mouseX, mouseY));
|
||||
musicPrevious.hoverUpdate(delta, !noHoverUpdate && musicPrevious.contains(mouseX, mouseY));
|
||||
starFountain.update(delta);
|
||||
|
||||
// window focus change: increase/decrease theme song volume
|
||||
if (MusicController.isThemePlaying() &&
|
||||
@@ -360,6 +374,14 @@ public class MainMenu extends BasicGameState {
|
||||
if (!(Options.isDynamicBackgroundEnabled() && beatmap != null && beatmap.isBackgroundLoading()))
|
||||
bgAlpha.update(delta);
|
||||
|
||||
// check measure progress
|
||||
Float measureProgress = MusicController.getMeasureProgress(2);
|
||||
if (measureProgress != null) {
|
||||
if (measureProgress < lastMeasureProgress)
|
||||
starFountain.burst(true);
|
||||
lastMeasureProgress = measureProgress;
|
||||
}
|
||||
|
||||
// buttons
|
||||
int centerX = container.getWidth() / 2;
|
||||
float currentLogoButtonAlpha;
|
||||
@@ -432,6 +454,10 @@ public class MainMenu extends BasicGameState {
|
||||
}
|
||||
}
|
||||
|
||||
// reset measure info
|
||||
lastMeasureProgress = 0f;
|
||||
starFountain.clear();
|
||||
|
||||
// reset button hover states if mouse is not currently hovering over the button
|
||||
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
||||
if (!logo.contains(mouseX, mouseY, 0.25f))
|
||||
@@ -489,7 +515,7 @@ public class MainMenu extends BasicGameState {
|
||||
}
|
||||
return;
|
||||
} else if (musicNext.contains(x, y)) {
|
||||
nextTrack();
|
||||
nextTrack(true);
|
||||
UI.sendBarNotification(">> Next");
|
||||
return;
|
||||
} else if (musicPrevious.contains(x, y)) {
|
||||
@@ -598,7 +624,7 @@ public class MainMenu extends BasicGameState {
|
||||
game.enterState(Opsu.STATE_DOWNLOADSMENU, new EasedFadeOutTransition(), new FadeInTransition());
|
||||
break;
|
||||
case Input.KEY_R:
|
||||
nextTrack();
|
||||
nextTrack(true);
|
||||
break;
|
||||
case Input.KEY_UP:
|
||||
UI.changeVolume(1);
|
||||
@@ -656,9 +682,16 @@ public class MainMenu extends BasicGameState {
|
||||
|
||||
/**
|
||||
* Plays the next track, and adds the previous one to the stack.
|
||||
* @param user {@code true} if this was user-initiated, false otherwise (track end)
|
||||
*/
|
||||
private void nextTrack() {
|
||||
private void nextTrack(boolean user) {
|
||||
boolean isTheme = MusicController.isThemePlaying();
|
||||
if (isTheme && !user) {
|
||||
// theme was playing, restart
|
||||
// NOTE: not looping due to inaccurate track positions after loop
|
||||
MusicController.playAt(0, false);
|
||||
return;
|
||||
}
|
||||
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
|
||||
BeatmapSetNode node = menu.setFocus(BeatmapSetList.get().getRandomNode(), -1, true, false);
|
||||
boolean sameAudio = false;
|
||||
|
||||
Reference in New Issue
Block a user