diff --git a/src/itdelatrisu/opsu/Utils.java b/src/itdelatrisu/opsu/Utils.java index e7f26138..0219473d 100644 --- a/src/itdelatrisu/opsu/Utils.java +++ b/src/itdelatrisu/opsu/Utils.java @@ -116,6 +116,15 @@ public class Utils { /** Volume display elapsed time. */ private static int volumeDisplay = -1; + /** The current bar notification string. */ + private static String barNotif; + + /** The current bar notification timer. */ + private static int barNotifTimer = -1; + + /** Duration, in milliseconds, to display bar notifications. */ + private static final int BAR_NOTIFICATION_TIME = 1250; + /** Set of all Unicode strings already loaded. */ private static HashSet loadedGlyphs = new HashSet(); @@ -694,6 +703,56 @@ public class Utils { FONT_SMALL.drawString(x + textMarginX, y, text, Color.white); } + /** + * Submits a bar notification for drawing. + * Must be called with {@link #drawBarNotification(Graphics)}. + * @param s the notification string + */ + public static void sendBarNotification(String s) { + if (s != null) { + barNotif = s; + barNotifTimer = 0; + } + } + + /** + * Updates the bar notification by a delta interval. + * @param delta the delta interval since the last call + */ + public static void updateBarNotification(int delta) { + if (barNotifTimer > -1 && barNotifTimer < BAR_NOTIFICATION_TIME) { + barNotifTimer += delta; + if (barNotifTimer > BAR_NOTIFICATION_TIME) + barNotifTimer = BAR_NOTIFICATION_TIME; + } + } + + /** + * Draws the notification sent from {@link #sendBarNotification(String)}. + * @param g the graphics context + */ + public static void drawBarNotification(Graphics g) { + if (barNotifTimer == -1 || barNotifTimer >= BAR_NOTIFICATION_TIME) + return; + + float alpha = 1f; + if (barNotifTimer >= BAR_NOTIFICATION_TIME * 0.9f) + alpha -= 1 - ((BAR_NOTIFICATION_TIME - barNotifTimer) / (BAR_NOTIFICATION_TIME * 0.1f)); + int midX = container.getWidth() / 2, midY = container.getHeight() / 2; + float barHeight = FONT_LARGE.getLineHeight() * (1f + 0.6f * Math.min(barNotifTimer * 15f / BAR_NOTIFICATION_TIME, 1f)); + float oldAlphaB = Utils.COLOR_BLACK_ALPHA.a, oldAlphaW = Utils.COLOR_WHITE_ALPHA.a; + Utils.COLOR_BLACK_ALPHA.a *= alpha; + Utils.COLOR_WHITE_ALPHA.a = alpha; + g.setColor(Utils.COLOR_BLACK_ALPHA); + g.fillRect(0, midY - barHeight / 2f, container.getWidth(), barHeight); + FONT_LARGE.drawString( + midX - FONT_LARGE.getWidth(barNotif) / 2f, + midY - FONT_LARGE.getLineHeight() / 2.2f, + barNotif, Utils.COLOR_WHITE_ALPHA); + Utils.COLOR_BLACK_ALPHA.a = oldAlphaB; + Utils.COLOR_WHITE_ALPHA.a = oldAlphaW; + } + /** * Takes a screenshot. * @author http://wiki.lwjgl.org/index.php?title=Taking_Screen_Shots diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index 7b2fbda3..b74f1c66 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -256,6 +256,7 @@ public class MainMenu extends BasicGameState { new SimpleDateFormat("h:mm a").format(new Date())), marginX, height - marginY - lineHeight); + Utils.drawBarNotification(g); Utils.drawVolume(g); Utils.drawFPS(); Utils.drawCursor(); @@ -276,6 +277,7 @@ public class MainMenu extends BasicGameState { throws SlickException { Utils.updateCursor(delta); Utils.updateVolumeDisplay(delta); + Utils.updateBarNotification(delta); int mouseX = input.getMouseX(), mouseY = input.getMouseY(); logo.hoverUpdate(delta, mouseX, mouseY, 0.25f); playButton.hoverUpdate(delta, mouseX, mouseY, 0.25f); @@ -388,10 +390,13 @@ public class MainMenu extends BasicGameState { // music button actions if (musicPlay.contains(x, y)) { - if (MusicController.isPlaying()) + if (MusicController.isPlaying()) { MusicController.pause(); - else if (!MusicController.isTrackLoading()) + Utils.sendBarNotification("Pause"); + } else if (!MusicController.isTrackLoading()) { MusicController.resume(); + Utils.sendBarNotification("Play"); + } } else if (musicNext.contains(x, y)) { boolean isTheme = MusicController.isThemePlaying(); SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU); @@ -404,6 +409,7 @@ public class MainMenu extends BasicGameState { } if (Options.isDynamicBackgroundEnabled() && !sameAudio && !MusicController.isThemePlaying()) bgAlpha = 0f; + Utils.sendBarNotification(">> Next"); } else if (musicPrevious.contains(x, y)) { if (!previous.isEmpty()) { SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU); @@ -412,6 +418,7 @@ public class MainMenu extends BasicGameState { bgAlpha = 0f; } else MusicController.setPosition(0); + Utils.sendBarNotification("<< Previous"); } // downloads button actions