Minor main menu changes.

- Changed the time format displayed on the main menu to match osu!.
- If no beatmaps are loaded, redirect the user to the downloads menu instead of an empty song menu.

Also, start showing bar notifications at time 1 instead of 0 so it can be called in enter() methods without visual delays.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-19 22:10:38 -04:00
parent cb8c7c399c
commit fc5f56f75a
4 changed files with 45 additions and 10 deletions

View File

@ -680,7 +680,7 @@ public class UI {
* @param g the graphics context * @param g the graphics context
*/ */
public static void drawBarNotification(Graphics g) { public static void drawBarNotification(Graphics g) {
if (barNotifTimer == -1 || barNotifTimer >= BAR_NOTIFICATION_TIME) if (barNotifTimer <= 0 || barNotifTimer >= BAR_NOTIFICATION_TIME)
return; return;
float alpha = 1f; float alpha = 1f;

View File

@ -573,4 +573,18 @@ public class Utils {
} }
return null; 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);
}
} }

View File

@ -146,6 +146,9 @@ public class DownloadsMenu extends BasicGameState {
/** Beatmap set ID of the current beatmap being previewed, or -1 if none. */ /** Beatmap set ID of the current beatmap being previewed, or -1 if none. */
private int previewID = -1; private int previewID = -1;
/** The bar notification to send upon entering the state. */
private String barNotificationOnLoad;
// game-related variables // game-related variables
private GameContainer container; private GameContainer container;
private StateBasedGame game; private StateBasedGame game;
@ -739,6 +742,10 @@ public class DownloadsMenu extends BasicGameState {
startDownloadIndex = 0; startDownloadIndex = 0;
pageDir = Page.RESET; pageDir = Page.RESET;
previewID = -1; previewID = -1;
if (barNotificationOnLoad != null) {
UI.sendBarNotification(barNotificationOnLoad);
barNotificationOnLoad = null;
}
} }
@Override @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; }
} }

View File

@ -40,7 +40,6 @@ import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Stack; import java.util.Stack;
import java.util.concurrent.TimeUnit;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer; 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((MusicController.isPlaying()) ? "Now Playing:" : "Paused:", marginX, marginY + lineHeight);
g.drawString(String.format("%s: %s", osu.getArtist(), osu.getTitle()), marginX + 25, marginY + (lineHeight * 2)); 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 %s.",
g.drawString(String.format("opsu! has been running for %d minutes, %d seconds.", Utils.getTimeString((int) (System.currentTimeMillis() - osuStartTime) / 1000)),
TimeUnit.MILLISECONDS.toMinutes(time),
TimeUnit.MILLISECONDS.toSeconds(time) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))),
marginX, height - marginY - (lineHeight * 2)); 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())), new SimpleDateFormat("h:mm a").format(new Date())),
marginX, height - marginY - lineHeight); marginX, height - marginY - lineHeight);
@ -505,7 +501,7 @@ public class MainMenu extends BasicGameState {
else if (logoClicked) { else if (logoClicked) {
if (logo.contains(x, y, 0.25f) || playButton.contains(x, y, 0.25f)) { if (logo.contains(x, y, 0.25f) || playButton.contains(x, y, 0.25f)) {
SoundController.playSound(SoundEffect.MENUHIT); 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)) } else if (exitButton.contains(x, y, 0.25f))
container.exit(); container.exit();
} }
@ -532,7 +528,7 @@ public class MainMenu extends BasicGameState {
playButton.getImage().setAlpha(0f); playButton.getImage().setAlpha(0f);
exitButton.getImage().setAlpha(0f); exitButton.getImage().setAlpha(0f);
} else } else
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); enterSongMenu();
break; break;
case Input.KEY_D: case Input.KEY_D:
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
@ -607,4 +603,16 @@ public class MainMenu extends BasicGameState {
if (Options.isDynamicBackgroundEnabled() && !sameAudio && !MusicController.isThemePlaying()) if (Options.isDynamicBackgroundEnabled() && !sameAudio && !MusicController.isThemePlaying())
bgAlpha = 0f; 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));
}
} }