Follow-up to a6ece30: allow changing volume anywhere with ALT key.

The master volume can now be changed (using the mouse wheel) with the ALT key pressed in any menu, as in osu!.

Also improved the handling of dimmed tracks.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-26 20:45:33 -04:00
parent 18e57fdb96
commit c15cd5cb4c
8 changed files with 88 additions and 3 deletions

View File

@ -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());
}
}

View File

@ -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);
}
/**

View File

@ -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) {

View File

@ -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;

View File

@ -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) {

View File

@ -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

View File

@ -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

View File

@ -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;