Added bar notifications.
Currently used in main menu music buttons. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
ebf629d261
commit
fb5515efb8
|
@ -116,6 +116,15 @@ public class Utils {
|
||||||
/** Volume display elapsed time. */
|
/** Volume display elapsed time. */
|
||||||
private static int volumeDisplay = -1;
|
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. */
|
/** Set of all Unicode strings already loaded. */
|
||||||
private static HashSet<String> loadedGlyphs = new HashSet<String>();
|
private static HashSet<String> loadedGlyphs = new HashSet<String>();
|
||||||
|
|
||||||
|
@ -694,6 +703,56 @@ public class Utils {
|
||||||
FONT_SMALL.drawString(x + textMarginX, y, text, Color.white);
|
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.
|
* Takes a screenshot.
|
||||||
* @author http://wiki.lwjgl.org/index.php?title=Taking_Screen_Shots
|
* @author http://wiki.lwjgl.org/index.php?title=Taking_Screen_Shots
|
||||||
|
|
|
@ -256,6 +256,7 @@ public class MainMenu extends BasicGameState {
|
||||||
new SimpleDateFormat("h:mm a").format(new Date())),
|
new SimpleDateFormat("h:mm a").format(new Date())),
|
||||||
marginX, height - marginY - lineHeight);
|
marginX, height - marginY - lineHeight);
|
||||||
|
|
||||||
|
Utils.drawBarNotification(g);
|
||||||
Utils.drawVolume(g);
|
Utils.drawVolume(g);
|
||||||
Utils.drawFPS();
|
Utils.drawFPS();
|
||||||
Utils.drawCursor();
|
Utils.drawCursor();
|
||||||
|
@ -276,6 +277,7 @@ public class MainMenu extends BasicGameState {
|
||||||
throws SlickException {
|
throws SlickException {
|
||||||
Utils.updateCursor(delta);
|
Utils.updateCursor(delta);
|
||||||
Utils.updateVolumeDisplay(delta);
|
Utils.updateVolumeDisplay(delta);
|
||||||
|
Utils.updateBarNotification(delta);
|
||||||
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
||||||
logo.hoverUpdate(delta, mouseX, mouseY, 0.25f);
|
logo.hoverUpdate(delta, mouseX, mouseY, 0.25f);
|
||||||
playButton.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
|
// music button actions
|
||||||
if (musicPlay.contains(x, y)) {
|
if (musicPlay.contains(x, y)) {
|
||||||
if (MusicController.isPlaying())
|
if (MusicController.isPlaying()) {
|
||||||
MusicController.pause();
|
MusicController.pause();
|
||||||
else if (!MusicController.isTrackLoading())
|
Utils.sendBarNotification("Pause");
|
||||||
|
} else if (!MusicController.isTrackLoading()) {
|
||||||
MusicController.resume();
|
MusicController.resume();
|
||||||
|
Utils.sendBarNotification("Play");
|
||||||
|
}
|
||||||
} else if (musicNext.contains(x, y)) {
|
} else if (musicNext.contains(x, y)) {
|
||||||
boolean isTheme = MusicController.isThemePlaying();
|
boolean isTheme = MusicController.isThemePlaying();
|
||||||
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
|
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
|
||||||
|
@ -404,6 +409,7 @@ public class MainMenu extends BasicGameState {
|
||||||
}
|
}
|
||||||
if (Options.isDynamicBackgroundEnabled() && !sameAudio && !MusicController.isThemePlaying())
|
if (Options.isDynamicBackgroundEnabled() && !sameAudio && !MusicController.isThemePlaying())
|
||||||
bgAlpha = 0f;
|
bgAlpha = 0f;
|
||||||
|
Utils.sendBarNotification(">> Next");
|
||||||
} else if (musicPrevious.contains(x, y)) {
|
} else if (musicPrevious.contains(x, y)) {
|
||||||
if (!previous.isEmpty()) {
|
if (!previous.isEmpty()) {
|
||||||
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
|
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
|
||||||
|
@ -412,6 +418,7 @@ public class MainMenu extends BasicGameState {
|
||||||
bgAlpha = 0f;
|
bgAlpha = 0f;
|
||||||
} else
|
} else
|
||||||
MusicController.setPosition(0);
|
MusicController.setPosition(0);
|
||||||
|
Utils.sendBarNotification("<< Previous");
|
||||||
}
|
}
|
||||||
|
|
||||||
// downloads button actions
|
// downloads button actions
|
||||||
|
|
Loading…
Reference in New Issue
Block a user