From f5df00255f319a3d4e86953425e1af986a031d5f Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Fri, 16 Jan 2015 16:02:02 -0500 Subject: [PATCH] Moved track volume dimming into MusicController. - Fixes an issue where the first few milliseconds of the theme song would always play at full volume, even if container is not focused. - Allows easier application to any song. Signed-off-by: Jeffrey Han --- .../opsu/audio/MusicController.java | 20 +++++++++++++++++++ src/itdelatrisu/opsu/states/MainMenu.java | 18 +++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/itdelatrisu/opsu/audio/MusicController.java b/src/itdelatrisu/opsu/audio/MusicController.java index b9f0286a..13ab7367 100644 --- a/src/itdelatrisu/opsu/audio/MusicController.java +++ b/src/itdelatrisu/opsu/audio/MusicController.java @@ -71,6 +71,11 @@ public class MusicController { */ private static float pauseTime = 0f; + /** + * Whether the current track volume is dimmed. + */ + private static boolean trackDimmed = false; + // This class should not be instantiated. private MusicController() {} @@ -148,6 +153,7 @@ public class MusicController { else player.play(); pauseTime = 0f; + trackDimmed = false; } } @@ -302,6 +308,20 @@ public class MusicController { return (themePlaying && trackExists()); } + /** + * Returns whether or not the volume of the current track, if any, + * has been dimmed. + */ + public static boolean isTrackDimmed() { return trackDimmed; } + + /** + * Toggles the volume dim state of the current track. + */ + public static void toggleTrackDimmed() { + setVolume((trackDimmed) ? Options.getMusicVolume() : Options.getMusicVolume() / 3f); + trackDimmed = !trackDimmed; + } + /** * Stops and releases all sources, clears each of the specified Audio * buffers, destroys the OpenAL context, and resets SoundStore for future use. diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index 7297a693..612fecf3 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -106,11 +106,6 @@ public class MainMenu extends BasicGameState { */ private float bgAlpha = 0f; - /** - * Whether the theme song volume has been dimmed. - */ - private boolean volumeDimmed = false; - // game-related variables private GameContainer container; private StateBasedGame game; @@ -259,16 +254,9 @@ public class MainMenu extends BasicGameState { repoButton.hoverUpdate(delta, mouseX, mouseY); // window focus change: increase/decrease theme song volume - if (MusicController.isThemePlaying()) { - boolean hasFocus = container.hasFocus(); - if (volumeDimmed == hasFocus) { - if (hasFocus) // restored focus - MusicController.setVolume(Options.getMusicVolume()); - else // lost focus - MusicController.setVolume(Options.getMusicVolume() / 3f); - volumeDimmed = !hasFocus; - } - } + if (MusicController.isThemePlaying() && + MusicController.isTrackDimmed() == container.hasFocus()) + MusicController.toggleTrackDimmed(); // fade in background if (bgAlpha < 0.9f) {