Implemented various keyboard shortcuts.

- Main menu:
-- 'd': opens downloads menu
-- 'r': plays random track
- Song menu:
-- SHIFT+DEL: opens beatmap deletion menu

Other changes:
- In the main menu, tracks now play from the beginning instead of the preview time.
- Fixed "next page" icon sometimes showing in the downloads menu when a next page didn't exist.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-06 01:29:50 -05:00
parent 0a1b10fbdb
commit 81601d41aa
5 changed files with 69 additions and 42 deletions

View File

@ -67,8 +67,11 @@ public class MusicController {
/**
* Plays an audio file at the preview position.
* If the audio file is already playing, then nothing will happen.
* @param osu the OsuFile to play
* @param loop whether or not to loop the track
* @param preview whether to start at the preview time (true) or beginning (false)
*/
public static void play(final OsuFile osu, final boolean loop) {
public static void play(final OsuFile osu, final boolean loop, final boolean preview) {
// new track: load and play
if (lastOsu == null || !osu.audioFilename.equals(lastOsu.audioFilename)) {
reset();
@ -80,7 +83,7 @@ public class MusicController {
trackLoader = new Thread() {
@Override
public void run() {
loadTrack(osu.audioFilename, osu.previewTime, loop);
loadTrack(osu.audioFilename, (preview) ? osu.previewTime : 0, loop);
}
};
trackLoader.start();
@ -279,7 +282,7 @@ public class MusicController {
public static void playThemeSong() {
OsuFile osu = Options.getOsuTheme();
if (osu != null) {
play(osu, true);
play(osu, true, false);
themePlaying = true;
}
}

View File

@ -517,7 +517,7 @@ public class DownloadsMenu extends BasicGameState {
// initialize song list
OsuGroupList.get().reset();
OsuGroupList.get().init();
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).setFocus(node, -1, true);
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).setFocus(node, -1, true, true);
// send notification
UI.sendBarNotification((dirs.length == 1) ? "Imported 1 new song." :
@ -544,7 +544,7 @@ public class DownloadsMenu extends BasicGameState {
SoundController.playSound(SoundEffect.MENUCLICK);
rankedOnly = !rankedOnly;
lastQuery = null;
pageDir = Page.CURRENT;
pageDir = Page.RESET;
resetSearchTimer();
return;
}

View File

@ -396,22 +396,12 @@ public class MainMenu extends BasicGameState {
UI.sendBarNotification("Play");
}
} else if (musicNext.contains(x, y)) {
boolean isTheme = MusicController.isThemePlaying();
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
OsuGroupNode node = menu.setFocus(OsuGroupList.get().getRandomNode(), -1, true);
boolean sameAudio = false;
if (node != null) {
sameAudio = MusicController.getOsuFile().audioFilename.equals(node.osuFiles.get(0).audioFilename);
if (!isTheme && !sameAudio)
previous.add(node.index);
}
if (Options.isDynamicBackgroundEnabled() && !sameAudio && !MusicController.isThemePlaying())
bgAlpha = 0f;
nextTrack();
UI.sendBarNotification(">> Next");
} else if (musicPrevious.contains(x, y)) {
if (!previous.isEmpty()) {
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
menu.setFocus(OsuGroupList.get().getBaseNode(previous.pop()), -1, true);
menu.setFocus(OsuGroupList.get().getBaseNode(previous.pop()), -1, true, false);
if (Options.isDynamicBackgroundEnabled())
bgAlpha = 0f;
} else
@ -469,16 +459,21 @@ public class MainMenu extends BasicGameState {
game.enterState(Opsu.STATE_BUTTONMENU);
break;
case Input.KEY_P:
SoundController.playSound(SoundEffect.MENUHIT);
if (!logoClicked) {
logoClicked = true;
logoTimer = 0;
playButton.getImage().setAlpha(0f);
exitButton.getImage().setAlpha(0f);
SoundController.playSound(SoundEffect.MENUHIT);
} else {
SoundController.playSound(SoundEffect.MENUHIT);
} else
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
}
break;
case Input.KEY_D:
SoundController.playSound(SoundEffect.MENUHIT);
game.enterState(Opsu.STATE_DOWNLOADSMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
break;
case Input.KEY_R:
nextTrack();
break;
case Input.KEY_UP:
UI.changeVolume(1);
@ -526,4 +521,21 @@ public class MainMenu extends BasicGameState {
musicPrevious.resetHover();
downloadsButton.resetHover();
}
/**
* Plays the next track, and adds the previous one to the stack.
*/
private void nextTrack() {
boolean isTheme = MusicController.isThemePlaying();
SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
OsuGroupNode node = menu.setFocus(OsuGroupList.get().getRandomNode(), -1, true, false);
boolean sameAudio = false;
if (node != null) {
sameAudio = MusicController.getOsuFile().audioFilename.equals(node.osuFiles.get(0).audioFilename);
if (!isTheme && !sameAudio)
previous.add(node.index);
}
if (Options.isDynamicBackgroundEnabled() && !sameAudio && !MusicController.isThemePlaying())
bgAlpha = 0f;
}
}

View File

@ -507,14 +507,14 @@ public class SongMenu extends BasicGameState {
if (search.getText().isEmpty()) { // cleared search
// use previous start/focus if possible
if (oldFocusNode != null)
setFocus(oldFocusNode.getNode(), oldFocusNode.getIndex(), true);
setFocus(oldFocusNode.getNode(), oldFocusNode.getIndex(), true, true);
else
setFocus(OsuGroupList.get().getRandomNode(), -1, true);
setFocus(OsuGroupList.get().getRandomNode(), -1, true, true);
} else {
int size = OsuGroupList.get().size();
searchResultString = String.format("%d match%s found!",
size, (size == 1) ? "" : "es");
setFocus(OsuGroupList.get().getRandomNode(), -1, true);
setFocus(OsuGroupList.get().getRandomNode(), -1, true, true);
}
oldFocusNode = null;
} else if (!search.getText().isEmpty())
@ -618,7 +618,7 @@ public class SongMenu extends BasicGameState {
int oldFocusFileIndex = focusNode.osuFileIndex;
focusNode = null;
OsuGroupList.get().init();
setFocus(oldFocusBase, oldFocusFileIndex, true);
setFocus(oldFocusBase, oldFocusFileIndex, true, true);
}
return;
}
@ -647,14 +647,14 @@ public class SongMenu extends BasicGameState {
} else {
// focus the node
SoundController.playSound(SoundEffect.MENUCLICK);
setFocus(node, 0, false);
setFocus(node, 0, false, true);
}
}
// clicked node is a new group
else {
SoundController.playSound(SoundEffect.MENUCLICK);
setFocus(node, -1, false);
setFocus(node, -1, false, true);
}
// restore hover data
@ -731,11 +731,11 @@ public class SongMenu extends BasicGameState {
SongNode prev;
if (randomStack.isEmpty() || (prev = randomStack.pop()) == null)
break;
setFocus(prev.getNode(), prev.getIndex(), true);
setFocus(prev.getNode(), prev.getIndex(), true, true);
} else {
// random track, add previous to stack
randomStack.push(new SongNode(OsuGroupList.get().getBaseNode(focusNode.index), focusNode.osuFileIndex));
setFocus(OsuGroupList.get().getRandomNode(), -1, true);
setFocus(OsuGroupList.get().getRandomNode(), -1, true, true);
}
break;
case Input.KEY_F3:
@ -750,6 +750,17 @@ public class SongMenu extends BasicGameState {
((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.RELOAD);
game.enterState(Opsu.STATE_BUTTONMENU);
break;
case Input.KEY_DELETE:
if (focusNode == null)
break;
if (input.isKeyDown(Input.KEY_RSHIFT) || input.isKeyDown(Input.KEY_LSHIFT)) {
SoundController.playSound(SoundEffect.MENUHIT);
MenuState ms = (focusNode.osuFileIndex == -1 || focusNode.osuFiles.size() == 1) ?
MenuState.BEATMAP_DELETE_CONFIRM : MenuState.BEATMAP_DELETE_SELECT;
((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(ms, focusNode);
game.enterState(Opsu.STATE_BUTTONMENU);
}
break;
case Input.KEY_F7:
Options.setNextFPS(container);
break;
@ -784,7 +795,7 @@ public class SongMenu extends BasicGameState {
OsuGroupNode oldStartNode = startNode;
float oldHoverOffset = hoverOffset;
int oldHoverIndex = hoverIndex;
setFocus(next, 0, false);
setFocus(next, 0, false, true);
if (startNode == oldStartNode) {
hoverOffset = oldHoverOffset;
hoverIndex = oldHoverIndex;
@ -800,7 +811,7 @@ public class SongMenu extends BasicGameState {
OsuGroupNode oldStartNode = startNode;
float oldHoverOffset = hoverOffset;
int oldHoverIndex = hoverIndex;
setFocus(prev, (prev.index == focusNode.index) ? 0 : prev.osuFiles.size() - 1, false);
setFocus(prev, (prev.index == focusNode.index) ? 0 : prev.osuFiles.size() - 1, false, true);
if (startNode == oldStartNode) {
hoverOffset = oldHoverOffset;
hoverIndex = oldHoverIndex;
@ -902,7 +913,7 @@ public class SongMenu extends BasicGameState {
// set focus node if not set (e.g. theme song playing)
if (focusNode == null && OsuGroupList.get().size() > 0)
setFocus(OsuGroupList.get().getRandomNode(), -1, true);
setFocus(OsuGroupList.get().getRandomNode(), -1, true, true);
// reset music track
else if (resetTrack) {
@ -972,9 +983,9 @@ public class SongMenu extends BasicGameState {
OsuGroupList.get().deleteSongGroup(stateActionNode);
if (oldIndex == focusNodeIndex) {
if (prev != null)
setFocus(prev, -1, true);
setFocus(prev, -1, true, true);
else if (next != null)
setFocus(next, -1, true);
setFocus(next, -1, true, true);
else {
startNode = focusNode = null;
oldFocusNode = null;
@ -1003,14 +1014,14 @@ public class SongMenu extends BasicGameState {
if (stateActionNode.prev != null &&
!(stateActionNode.next != null && stateActionNode.next.index == index)) {
if (stateActionNode.prev.index == index)
setFocus(stateActionNode.prev, 0, true);
setFocus(stateActionNode.prev, 0, true, true);
else
setFocus(stateActionNode.prev, -1, true);
setFocus(stateActionNode.prev, -1, true, true);
} else if (stateActionNode.next != null) {
if (stateActionNode.next.index == index)
setFocus(stateActionNode.next, 0, true);
setFocus(stateActionNode.next, 0, true, true);
else
setFocus(stateActionNode.next, -1, true);
setFocus(stateActionNode.next, -1, true, true);
}
} else if (stateActionNode == startNode) {
if (startNode.prev != null)
@ -1050,7 +1061,7 @@ public class SongMenu extends BasicGameState {
// initialize song list
if (OsuGroupList.get().size() > 0) {
OsuGroupList.get().init();
setFocus(OsuGroupList.get().getRandomNode(), -1, true);
setFocus(OsuGroupList.get().getRandomNode(), -1, true, true);
} else
MusicController.playThemeSong();
@ -1120,9 +1131,10 @@ public class SongMenu extends BasicGameState {
* @param node the base node; it will be expanded if it isn't already
* @param osuFileIndex the OsuFile element to focus; if out of bounds, it will be randomly chosen
* @param changeStartNode if true, startNode will be set to the first node in the group
* @param preview whether to start at the preview time (true) or beginning (false)
* @return the old focus node
*/
public OsuGroupNode setFocus(OsuGroupNode node, int osuFileIndex, boolean changeStartNode) {
public OsuGroupNode setFocus(OsuGroupNode node, int osuFileIndex, boolean changeStartNode, boolean preview) {
if (node == null)
return null;
@ -1151,7 +1163,7 @@ public class SongMenu extends BasicGameState {
startNode = node;
focusNode = OsuGroupList.get().getNode(node, osuFileIndex);
OsuFile osu = focusNode.osuFiles.get(focusNode.osuFileIndex);
MusicController.play(osu, true);
MusicController.play(osu, true, preview);
Utils.loadGlyphs(osu);
// load scores

View File

@ -130,7 +130,7 @@ public class Splash extends BasicGameState {
if (Options.isThemeSongEnabled())
MusicController.playThemeSong();
else
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).setFocus(OsuGroupList.get().getRandomNode(), -1, true);
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).setFocus(OsuGroupList.get().getRandomNode(), -1, true, true);
}
// play the theme song