diff --git a/src/itdelatrisu/opsu/Options.java b/src/itdelatrisu/opsu/Options.java index deea7f16..d208d585 100644 --- a/src/itdelatrisu/opsu/Options.java +++ b/src/itdelatrisu/opsu/Options.java @@ -18,6 +18,8 @@ package itdelatrisu.opsu; +import itdelatrisu.opsu.audio.MusicController; + import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -496,7 +498,7 @@ public class Options { public static void setMasterVolume(GameContainer container, float volume) { if (volume >= 0f && volume <= 1f) { GameOption.MASTER_VOLUME.setValue((int) (volume * 100f)); - container.setMusicVolume(getMasterVolume() * getMusicVolume()); + MusicController.setVolume(getMasterVolume() * getMusicVolume()); } } diff --git a/src/itdelatrisu/opsu/audio/MusicController.java b/src/itdelatrisu/opsu/audio/MusicController.java index b7c5e78a..7c93c15d 100644 --- a/src/itdelatrisu/opsu/audio/MusicController.java +++ b/src/itdelatrisu/opsu/audio/MusicController.java @@ -71,6 +71,9 @@ public class MusicController { /** Whether the current track volume is dimmed. */ private static boolean trackDimmed = false; + /** The track dim level, if dimmed. */ + private static float dimLevel = 1f; + // This class should not be instantiated. private MusicController() {} @@ -291,7 +294,7 @@ public class MusicController { * @param volume [0, 1] */ public static void setVolume(float volume) { - SoundStore.get().setMusicVolume(volume); + SoundStore.get().setMusicVolume((isTrackDimmed()) ? volume * dimLevel : volume); } /** @@ -336,8 +339,9 @@ public class MusicController { */ public static void toggleTrackDimmed(float multiplier) { float volume = Options.getMusicVolume() * Options.getMasterVolume(); - setVolume((trackDimmed) ? volume : volume * multiplier); + dimLevel = (isTrackDimmed()) ? 1f : multiplier; trackDimmed = !trackDimmed; + setVolume(volume); } /** diff --git a/src/itdelatrisu/opsu/states/ButtonMenu.java b/src/itdelatrisu/opsu/states/ButtonMenu.java index a1a83f1d..dde1172b 100644 --- a/src/itdelatrisu/opsu/states/ButtonMenu.java +++ b/src/itdelatrisu/opsu/states/ButtonMenu.java @@ -75,6 +75,13 @@ public class ButtonMenu extends BasicGameState { public void leave(GameContainer container, StateBasedGame game) { Button.CANCEL.click(container, game); } + + @Override + public void scroll(GameContainer container, StateBasedGame game, int newValue) { + Input input = container.getInput(); + if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT)) + super.scroll(container, game, newValue); + } }, BEATMAP_DELETE_SELECT (new Button[] { Button.DELETE_GROUP, Button.DELETE_SONG, Button.CANCEL_DELETE }) { @Override @@ -88,6 +95,11 @@ public class ButtonMenu extends BasicGameState { public void leave(GameContainer container, StateBasedGame game) { Button.CANCEL_DELETE.click(container, game); } + + @Override + public void scroll(GameContainer container, StateBasedGame game, int newValue) { + MenuState.BEATMAP.scroll(container, game, newValue); + } }, BEATMAP_DELETE_CONFIRM (new Button[] { Button.DELETE_CONFIRM, Button.CANCEL_DELETE }) { @Override @@ -99,6 +111,11 @@ public class ButtonMenu extends BasicGameState { public void leave(GameContainer container, StateBasedGame game) { Button.CANCEL_DELETE.click(container, game); } + + @Override + public void scroll(GameContainer container, StateBasedGame game, int newValue) { + MenuState.BEATMAP.scroll(container, game, newValue); + } }, RELOAD (new Button[] { Button.RELOAD_CONFIRM, Button.RELOAD_CANCEL }) { @Override @@ -114,6 +131,11 @@ public class ButtonMenu extends BasicGameState { public void leave(GameContainer container, StateBasedGame game) { Button.RELOAD_CANCEL.click(container, game); } + + @Override + public void scroll(GameContainer container, StateBasedGame game, int newValue) { + MenuState.BEATMAP.scroll(container, game, newValue); + } }, SCORE (new Button[] { Button.DELETE_SCORE, Button.CLOSE }) { @Override @@ -125,6 +147,11 @@ public class ButtonMenu extends BasicGameState { public void leave(GameContainer container, StateBasedGame game) { Button.CLOSE.click(container, game); } + + @Override + public void scroll(GameContainer container, StateBasedGame game, int newValue) { + MenuState.BEATMAP.scroll(container, game, newValue); + } }, MODS (new Button[] { Button.RESET_MODS, Button.CLOSE }) { @Override @@ -218,6 +245,11 @@ public class ButtonMenu extends BasicGameState { } } } + + @Override + public void scroll(GameContainer container, StateBasedGame game, int newValue) { + MenuState.BEATMAP.scroll(container, game, newValue); + } }; /** The buttons in the state. */ @@ -355,6 +387,16 @@ public class ButtonMenu extends BasicGameState { */ public String[] getTitle(GameContainer container, StateBasedGame game) { return new String[0]; } + /** + * Processes a mouse wheel movement. + * @param container the game container + * @param game the game + * @param newValue the amount that the mouse wheel moved + */ + public void scroll(GameContainer container, StateBasedGame game, int newValue) { + UI.changeVolume((newValue < 0) ? -1 : 1); + } + /** * Processes a state enter request. * @param container the game container @@ -601,6 +643,12 @@ public class ButtonMenu extends BasicGameState { menuState.click(container, game, x, y); } + @Override + public void mouseWheelMoved(int newValue) { + if (menuState != null) + menuState.scroll(container, game, newValue); + } + @Override public void keyPressed(int key, char c) { switch (key) { diff --git a/src/itdelatrisu/opsu/states/DownloadsMenu.java b/src/itdelatrisu/opsu/states/DownloadsMenu.java index 2d3c0ac6..db2cc1f6 100644 --- a/src/itdelatrisu/opsu/states/DownloadsMenu.java +++ b/src/itdelatrisu/opsu/states/DownloadsMenu.java @@ -653,6 +653,12 @@ public class DownloadsMenu extends BasicGameState { @Override public void mouseWheelMoved(int newValue) { + // change volume + if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT)) { + UI.changeVolume((newValue < 0) ? -1 : 1); + return; + } + // block input during beatmap importing if (importThread != null) return; diff --git a/src/itdelatrisu/opsu/states/GameRanking.java b/src/itdelatrisu/opsu/states/GameRanking.java index 7b229b43..327f9c41 100644 --- a/src/itdelatrisu/opsu/states/GameRanking.java +++ b/src/itdelatrisu/opsu/states/GameRanking.java @@ -136,6 +136,12 @@ public class GameRanking extends BasicGameState { @Override public int getID() { return state; } + @Override + public void mouseWheelMoved(int newValue) { + if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT)) + UI.changeVolume((newValue < 0) ? -1 : 1); + } + @Override public void keyPressed(int key, char c) { switch (key) { diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index cc879207..999b4420 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -418,6 +418,13 @@ public class MainMenu extends BasicGameState { downloadsButton.resetHover(); } + @Override + public void leave(GameContainer container, StateBasedGame game) + throws SlickException { + if (MusicController.isTrackDimmed()) + MusicController.toggleTrackDimmed(1f); + } + @Override public void mousePressed(int button, int x, int y) { // check mouse button diff --git a/src/itdelatrisu/opsu/states/OptionsMenu.java b/src/itdelatrisu/opsu/states/OptionsMenu.java index dc63b301..ce7953d5 100644 --- a/src/itdelatrisu/opsu/states/OptionsMenu.java +++ b/src/itdelatrisu/opsu/states/OptionsMenu.java @@ -342,6 +342,12 @@ public class OptionsMenu extends BasicGameState { option.drag(container, diff); } + @Override + public void mouseWheelMoved(int newValue) { + if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT)) + UI.changeVolume((newValue < 0) ? -1 : 1); + } + @Override public void keyPressed(int key, char c) { // key entry state diff --git a/src/itdelatrisu/opsu/states/SongMenu.java b/src/itdelatrisu/opsu/states/SongMenu.java index 6770aeb8..87704504 100644 --- a/src/itdelatrisu/opsu/states/SongMenu.java +++ b/src/itdelatrisu/opsu/states/SongMenu.java @@ -898,6 +898,12 @@ public class SongMenu extends BasicGameState { @Override public void mouseWheelMoved(int newValue) { + // change volume + if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT)) { + UI.changeVolume((newValue < 0) ? -1 : 1); + return; + } + // block input if (reloadThread != null || beatmapMenuTimer > -1) return;