diff --git a/src/itdelatrisu/opsu/UI.java b/src/itdelatrisu/opsu/UI.java index ab5e44d1..b5a2e95c 100644 --- a/src/itdelatrisu/opsu/UI.java +++ b/src/itdelatrisu/opsu/UI.java @@ -680,7 +680,7 @@ public class UI { * @param g the graphics context */ public static void drawBarNotification(Graphics g) { - if (barNotifTimer == -1 || barNotifTimer >= BAR_NOTIFICATION_TIME) + if (barNotifTimer <= 0 || barNotifTimer >= BAR_NOTIFICATION_TIME) return; float alpha = 1f; diff --git a/src/itdelatrisu/opsu/Utils.java b/src/itdelatrisu/opsu/Utils.java index 2449d184..41091324 100644 --- a/src/itdelatrisu/opsu/Utils.java +++ b/src/itdelatrisu/opsu/Utils.java @@ -573,4 +573,18 @@ public class Utils { } return null; } + + /** + * Returns a formatted time string for a given number of seconds. + * @param seconds the number of seconds + * @return the time as a readable string + */ + public static String getTimeString(int seconds) { + if (seconds < 60) + return (seconds == 1) ? "1 second" : String.format("%d seconds", seconds); + else if (seconds < 3600) + return String.format("%02d:%02d", seconds / 60, seconds % 60); + else + return String.format("%02d:%02d:%02d", seconds / 3600, (seconds / 60) % 60, seconds % 60); + } } diff --git a/src/itdelatrisu/opsu/states/DownloadsMenu.java b/src/itdelatrisu/opsu/states/DownloadsMenu.java index 4223a230..077e325d 100644 --- a/src/itdelatrisu/opsu/states/DownloadsMenu.java +++ b/src/itdelatrisu/opsu/states/DownloadsMenu.java @@ -146,6 +146,9 @@ public class DownloadsMenu extends BasicGameState { /** Beatmap set ID of the current beatmap being previewed, or -1 if none. */ private int previewID = -1; + /** The bar notification to send upon entering the state. */ + private String barNotificationOnLoad; + // game-related variables private GameContainer container; private StateBasedGame game; @@ -739,6 +742,10 @@ public class DownloadsMenu extends BasicGameState { startDownloadIndex = 0; pageDir = Page.RESET; previewID = -1; + if (barNotificationOnLoad != null) { + UI.sendBarNotification(barNotificationOnLoad); + barNotificationOnLoad = null; + } } @Override @@ -789,4 +796,10 @@ public class DownloadsMenu extends BasicGameState { } } } + + /** + * Sends a bar notification upon entering the state. + * @param s the notification string + */ + public void notifyOnLoad(String s) { barNotificationOnLoad = s; } } diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index 15c97efe..b4534910 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -40,7 +40,6 @@ import java.io.IOException; 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; @@ -281,13 +280,10 @@ public class MainMenu extends BasicGameState { g.drawString((MusicController.isPlaying()) ? "Now Playing:" : "Paused:", marginX, marginY + lineHeight); g.drawString(String.format("%s: %s", osu.getArtist(), osu.getTitle()), marginX + 25, marginY + (lineHeight * 2)); } - long time = System.currentTimeMillis() - osuStartTime; - g.drawString(String.format("opsu! has been running for %d minutes, %d seconds.", - TimeUnit.MILLISECONDS.toMinutes(time), - TimeUnit.MILLISECONDS.toSeconds(time) - - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))), + g.drawString(String.format("opsu! has been running for %s.", + Utils.getTimeString((int) (System.currentTimeMillis() - osuStartTime) / 1000)), marginX, height - marginY - (lineHeight * 2)); - g.drawString(String.format("The current time is %s.", + g.drawString(String.format("It is currently %s.", new SimpleDateFormat("h:mm a").format(new Date())), marginX, height - marginY - lineHeight); @@ -505,7 +501,7 @@ public class MainMenu extends BasicGameState { else if (logoClicked) { if (logo.contains(x, y, 0.25f) || playButton.contains(x, y, 0.25f)) { SoundController.playSound(SoundEffect.MENUHIT); - game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + enterSongMenu(); } else if (exitButton.contains(x, y, 0.25f)) container.exit(); } @@ -532,7 +528,7 @@ public class MainMenu extends BasicGameState { playButton.getImage().setAlpha(0f); exitButton.getImage().setAlpha(0f); } else - game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + enterSongMenu(); break; case Input.KEY_D: SoundController.playSound(SoundEffect.MENUHIT); @@ -607,4 +603,16 @@ public class MainMenu extends BasicGameState { if (Options.isDynamicBackgroundEnabled() && !sameAudio && !MusicController.isThemePlaying()) bgAlpha = 0f; } + + /** + * Enters the song menu, or the downloads menu if no beatmaps are loaded. + */ + private void enterSongMenu() { + int state = Opsu.STATE_SONGMENU; + if (OsuGroupList.get().getMapSetCount() == 0) { + ((DownloadsMenu) game.getState(Opsu.STATE_DOWNLOADSMENU)).notifyOnLoad("Download some beatmaps to get started!"); + state = Opsu.STATE_DOWNLOADSMENU; + } + game.enterState(state, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); + } }