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:
parent
18e57fdb96
commit
c15cd5cb4c
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
package itdelatrisu.opsu;
|
package itdelatrisu.opsu;
|
||||||
|
|
||||||
|
import itdelatrisu.opsu.audio.MusicController;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -496,7 +498,7 @@ public class Options {
|
||||||
public static void setMasterVolume(GameContainer container, float volume) {
|
public static void setMasterVolume(GameContainer container, float volume) {
|
||||||
if (volume >= 0f && volume <= 1f) {
|
if (volume >= 0f && volume <= 1f) {
|
||||||
GameOption.MASTER_VOLUME.setValue((int) (volume * 100f));
|
GameOption.MASTER_VOLUME.setValue((int) (volume * 100f));
|
||||||
container.setMusicVolume(getMasterVolume() * getMusicVolume());
|
MusicController.setVolume(getMasterVolume() * getMusicVolume());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,9 @@ public class MusicController {
|
||||||
/** Whether the current track volume is dimmed. */
|
/** Whether the current track volume is dimmed. */
|
||||||
private static boolean trackDimmed = false;
|
private static boolean trackDimmed = false;
|
||||||
|
|
||||||
|
/** The track dim level, if dimmed. */
|
||||||
|
private static float dimLevel = 1f;
|
||||||
|
|
||||||
// This class should not be instantiated.
|
// This class should not be instantiated.
|
||||||
private MusicController() {}
|
private MusicController() {}
|
||||||
|
|
||||||
|
@ -291,7 +294,7 @@ public class MusicController {
|
||||||
* @param volume [0, 1]
|
* @param volume [0, 1]
|
||||||
*/
|
*/
|
||||||
public static void setVolume(float volume) {
|
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) {
|
public static void toggleTrackDimmed(float multiplier) {
|
||||||
float volume = Options.getMusicVolume() * Options.getMasterVolume();
|
float volume = Options.getMusicVolume() * Options.getMasterVolume();
|
||||||
setVolume((trackDimmed) ? volume : volume * multiplier);
|
dimLevel = (isTrackDimmed()) ? 1f : multiplier;
|
||||||
trackDimmed = !trackDimmed;
|
trackDimmed = !trackDimmed;
|
||||||
|
setVolume(volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,6 +75,13 @@ public class ButtonMenu extends BasicGameState {
|
||||||
public void leave(GameContainer container, StateBasedGame game) {
|
public void leave(GameContainer container, StateBasedGame game) {
|
||||||
Button.CANCEL.click(container, 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 }) {
|
BEATMAP_DELETE_SELECT (new Button[] { Button.DELETE_GROUP, Button.DELETE_SONG, Button.CANCEL_DELETE }) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -88,6 +95,11 @@ public class ButtonMenu extends BasicGameState {
|
||||||
public void leave(GameContainer container, StateBasedGame game) {
|
public void leave(GameContainer container, StateBasedGame game) {
|
||||||
Button.CANCEL_DELETE.click(container, 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 }) {
|
BEATMAP_DELETE_CONFIRM (new Button[] { Button.DELETE_CONFIRM, Button.CANCEL_DELETE }) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -99,6 +111,11 @@ public class ButtonMenu extends BasicGameState {
|
||||||
public void leave(GameContainer container, StateBasedGame game) {
|
public void leave(GameContainer container, StateBasedGame game) {
|
||||||
Button.CANCEL_DELETE.click(container, 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 }) {
|
RELOAD (new Button[] { Button.RELOAD_CONFIRM, Button.RELOAD_CANCEL }) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -114,6 +131,11 @@ public class ButtonMenu extends BasicGameState {
|
||||||
public void leave(GameContainer container, StateBasedGame game) {
|
public void leave(GameContainer container, StateBasedGame game) {
|
||||||
Button.RELOAD_CANCEL.click(container, 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 }) {
|
SCORE (new Button[] { Button.DELETE_SCORE, Button.CLOSE }) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -125,6 +147,11 @@ public class ButtonMenu extends BasicGameState {
|
||||||
public void leave(GameContainer container, StateBasedGame game) {
|
public void leave(GameContainer container, StateBasedGame game) {
|
||||||
Button.CLOSE.click(container, 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 }) {
|
MODS (new Button[] { Button.RESET_MODS, Button.CLOSE }) {
|
||||||
@Override
|
@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. */
|
/** 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]; }
|
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.
|
* Processes a state enter request.
|
||||||
* @param container the game container
|
* @param container the game container
|
||||||
|
@ -601,6 +643,12 @@ public class ButtonMenu extends BasicGameState {
|
||||||
menuState.click(container, game, x, y);
|
menuState.click(container, game, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseWheelMoved(int newValue) {
|
||||||
|
if (menuState != null)
|
||||||
|
menuState.scroll(container, game, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(int key, char c) {
|
public void keyPressed(int key, char c) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
|
|
|
@ -653,6 +653,12 @@ public class DownloadsMenu extends BasicGameState {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseWheelMoved(int newValue) {
|
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
|
// block input during beatmap importing
|
||||||
if (importThread != null)
|
if (importThread != null)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -136,6 +136,12 @@ public class GameRanking extends BasicGameState {
|
||||||
@Override
|
@Override
|
||||||
public int getID() { return state; }
|
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
|
@Override
|
||||||
public void keyPressed(int key, char c) {
|
public void keyPressed(int key, char c) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
|
|
|
@ -418,6 +418,13 @@ public class MainMenu extends BasicGameState {
|
||||||
downloadsButton.resetHover();
|
downloadsButton.resetHover();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void leave(GameContainer container, StateBasedGame game)
|
||||||
|
throws SlickException {
|
||||||
|
if (MusicController.isTrackDimmed())
|
||||||
|
MusicController.toggleTrackDimmed(1f);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(int button, int x, int y) {
|
public void mousePressed(int button, int x, int y) {
|
||||||
// check mouse button
|
// check mouse button
|
||||||
|
|
|
@ -342,6 +342,12 @@ public class OptionsMenu extends BasicGameState {
|
||||||
option.drag(container, diff);
|
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
|
@Override
|
||||||
public void keyPressed(int key, char c) {
|
public void keyPressed(int key, char c) {
|
||||||
// key entry state
|
// key entry state
|
||||||
|
|
|
@ -898,6 +898,12 @@ public class SongMenu extends BasicGameState {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseWheelMoved(int newValue) {
|
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
|
// block input
|
||||||
if (reloadThread != null || beatmapMenuTimer > -1)
|
if (reloadThread != null || beatmapMenuTimer > -1)
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user