Skip to content

Commit

Permalink
Add options overlay to the main menu. (#281, fixes #279)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed May 6, 2017
1 parent cf97b25 commit f4fa217
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/itdelatrisu/opsu/options/OptionsOverlay.java
Expand Up @@ -365,7 +365,6 @@ public void activate() {
if (dropdownMenus == null)
createDropdownMenus();
resetSearch();
searchField.setFocus(true);
for (Map.Entry<GameOption, DropdownMenu<Object>> entry : dropdownMenus.entrySet()) {
GameOption option = entry.getKey();
DropdownMenu<Object> menu = entry.getValue();
Expand Down Expand Up @@ -1068,6 +1067,7 @@ public void keyPressed(int key, char c) {

searchField.setFocus(true);
searchField.keyPressed(key, c);
searchField.setFocus(false);
if (!searchField.getText().equals(lastSearchText)) {
lastSearchText = searchField.getText().toLowerCase();
updateSearch();
Expand Down
108 changes: 91 additions & 17 deletions src/itdelatrisu/opsu/states/MainMenu.java
Expand Up @@ -29,7 +29,9 @@
import itdelatrisu.opsu.beatmap.BeatmapSetList;
import itdelatrisu.opsu.beatmap.BeatmapSetNode;
import itdelatrisu.opsu.downloads.Updater;
import itdelatrisu.opsu.options.OptionGroup;
import itdelatrisu.opsu.options.Options;
import itdelatrisu.opsu.options.OptionsOverlay;
import itdelatrisu.opsu.states.ButtonMenu.MenuState;
import itdelatrisu.opsu.ui.Colors;
import itdelatrisu.opsu.ui.Fonts;
Expand Down Expand Up @@ -141,6 +143,15 @@ private enum LogoState { DEFAULT, OPENING, OPEN, CLOSING }
/** Music info bar animation progress. */
private AnimatedValue musicInfoProgress = new AnimatedValue(600, 0f, 1f, AnimationEquation.OUT_CUBIC);

/** Options overlay. */
private OptionsOverlay optionsOverlay;

/** Whether the options overlay is being shown. */
private boolean showOptionsOverlay = false;

/** The options overlay show/hide animation progress. */
private AnimatedValue optionsOverlayProgress = new AnimatedValue(500, 0f, 1f, AnimationEquation.OUT_CUBIC);

/** The user button. */
private UserButton userButton;

Expand Down Expand Up @@ -186,10 +197,10 @@ public void init(GameContainer container, StateBasedGame game)
float exitOffset = (playImg.getWidth() - exitImg.getWidth()) / 3f;
logo = new MenuButton(logoImg, width / 2f, height / 2f);
playButton = new MenuButton(playImg,
width * 0.75f, (height / 2) - (logoImg.getHeight() / 5f)
width * 0.75f, (height / 2) - (logoImg.getHeight() / 5f)
);
exitButton = new MenuButton(exitImg,
width * 0.75f - exitOffset, (height / 2) + (exitImg.getHeight() / 2f)
width * 0.75f - exitOffset, (height / 2) + (exitImg.getHeight() / 2f)
);
final int logoAnimationDuration = 350;
logo.setHoverAnimationDuration(logoAnimationDuration);
Expand Down Expand Up @@ -277,6 +288,18 @@ public void init(GameContainer container, StateBasedGame game)
logoClose = new AnimatedValue(2200, centerOffsetX, 0, AnimationEquation.OUT_QUAD);
logoButtonAlpha = new AnimatedValue(200, 0f, 1f, AnimationEquation.LINEAR);

// options overlay
optionsOverlay = new OptionsOverlay(container, OptionGroup.ALL_OPTIONS, new OptionsOverlay.OptionsOverlayListener() {
@Override
public void close() {
showOptionsOverlay = false;
optionsOverlay.deactivate();
optionsOverlay.reset();
optionsOverlayProgress.setTime(0);
}
});
optionsOverlay.setConsumeAndClose(true);

// initialize user button
userButton = new UserButton(0, 0, Color.white);

Expand Down Expand Up @@ -458,6 +481,10 @@ else if (logoState == LogoState.OPENING)
);
Colors.WHITE_FADE.a = oldWhiteAlpha;

// options overlay
if (showOptionsOverlay || !optionsOverlayProgress.isFinished())
optionsOverlay.render(container, g);

// user overlay
if (showUserOverlay || !userOverlayProgress.isFinished())
userOverlay.render(container, g);
Expand All @@ -472,7 +499,7 @@ public void update(GameContainer container, StateBasedGame game, int delta)
if (MusicController.trackEnded())
nextTrack(false); // end of track: go to next track
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
if (showUserOverlay) {
if (showOptionsOverlay || showUserOverlay) {
logo.hoverUpdate(delta, false);
playButton.hoverUpdate(delta, false);
exitButton.hoverUpdate(delta, false);
Expand Down Expand Up @@ -523,6 +550,17 @@ public void update(GameContainer container, StateBasedGame game, int delta)
lastMeasureProgress = measureProgress;
}

// options overlay
if (optionsOverlayProgress.update(delta)) {
// slide in/out
float t = optionsOverlayProgress.getValue();
if (!showOptionsOverlay)
t = 1f - t;
optionsOverlay.setWidth((int) (optionsOverlay.getTargetWidth() * t));
optionsOverlay.setAlpha(t);
} else if (showOptionsOverlay)
optionsOverlay.update(delta);

// user overlay
if (userOverlayProgress.update(delta)) {
// fade in/out
Expand Down Expand Up @@ -612,7 +650,7 @@ public void enter(GameContainer container, StateBasedGame game)
String updateMessage = OpsuConstants.PROJECT_NAME + " is now up to date!";
final String version = Updater.get().getCurrentVersion();
if (version != null && Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
updateMessage += "\nClick to see changes.";
updateMessage += "\nClick to see what changed!";
UI.getNotificationManager().sendNotification(updateMessage, Colors.GREEN, new NotificationListener() {
@Override
public void click() {
Expand Down Expand Up @@ -657,16 +695,29 @@ public void click() {
downloadsButton.resetHover();
if (!userButton.contains(mouseX, mouseY))
userButton.resetHover();

// reset overlays
optionsOverlay.deactivate();
optionsOverlay.reset();
showOptionsOverlay = false;
optionsOverlayProgress.setTime(optionsOverlayProgress.getDuration());
userOverlay.deactivate();
showUserOverlay = false;
userOverlayProgress.setTime(userOverlayProgress.getDuration());
}

@Override
public void leave(GameContainer container, StateBasedGame game)
throws SlickException {
if (MusicController.isTrackDimmed())
MusicController.toggleTrackDimmed(1f);

// reset overlays
optionsOverlay.deactivate();
optionsOverlay.reset();
showOptionsOverlay = false;
userOverlay.deactivate();
showUserOverlay = false;
userOverlayProgress.setTime(userOverlayProgress.getDuration());
}

@Override
Expand All @@ -675,6 +726,10 @@ public void mousePressed(int button, int x, int y) {
if (button == Input.MOUSE_MIDDLE_BUTTON)
return;

if (showOptionsOverlay || !optionsOverlayProgress.isFinished() ||
showUserOverlay || !userOverlayProgress.isFinished())
return;

// music position bar
if (MusicController.isPlaying()) {
if (musicPositionBarContains(x, y)) {
Expand Down Expand Up @@ -752,12 +807,8 @@ public void mousePressed(int button, int x, int y) {
// start moving logo (if clicked)
if (logoState == LogoState.DEFAULT || logoState == LogoState.CLOSING) {
if (logo.contains(x, y, 0.25f)) {
logoState = LogoState.OPENING;
logoOpen.setTime(0);
logoTimer = 0;
playButton.getImage().setAlpha(0f);
exitButton.getImage().setAlpha(0f);
SoundController.playSound(SoundEffect.MENUHIT);
openLogoMenu();
return;
}
}
Expand Down Expand Up @@ -793,19 +844,27 @@ public void keyPressed(int key, char c) {
break;
case Input.KEY_P:
SoundController.playSound(SoundEffect.MENUHIT);
if (logoState == LogoState.DEFAULT || logoState == LogoState.CLOSING) {
logoState = LogoState.OPENING;
logoOpen.setTime(0);
logoTimer = 0;
playButton.getImage().setAlpha(0f);
exitButton.getImage().setAlpha(0f);
} else
if (logoState == LogoState.DEFAULT || logoState == LogoState.CLOSING)
openLogoMenu();
else
enterSongMenu();
break;
case Input.KEY_D:
SoundController.playSound(SoundEffect.MENUHIT);
game.enterState(Opsu.STATE_DOWNLOADSMENU, new EasedFadeOutTransition(), new FadeInTransition());
break;
case Input.KEY_O:
SoundController.playSound(SoundEffect.MENUHIT);
if ((logoState == LogoState.DEFAULT || logoState == LogoState.CLOSING) &&
!(input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)))
openLogoMenu();
else {
showOptionsOverlay = true;
optionsOverlayProgress.setTime(0);
optionsOverlay.activate();
input.consumeEvent(); // don't let options overlay consume this keypress
}
break;
case Input.KEY_F:
Options.toggleFPSCounter();
break;
Expand Down Expand Up @@ -869,6 +928,10 @@ public void reset() {
logoState = LogoState.DEFAULT;

musicInfoProgress.setTime(musicInfoProgress.getDuration());
optionsOverlay.deactivate();
optionsOverlay.reset();
showOptionsOverlay = false;
optionsOverlayProgress.setTime(optionsOverlayProgress.getDuration());
userOverlay.deactivate();
showUserOverlay = false;
userOverlayProgress.setTime(userOverlayProgress.getDuration());
Expand All @@ -888,6 +951,17 @@ public void reset() {
userButton.resetHover();
}

/**
* Opens the logo menu.
*/
private void openLogoMenu() {
logoState = LogoState.OPENING;
logoOpen.setTime(0);
logoTimer = 0;
playButton.getImage().setAlpha(0f);
exitButton.getImage().setAlpha(0f);
}

/**
* 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)
Expand Down

0 comments on commit f4fa217

Please sign in to comment.