Follow-up to #38: loop tracks on states by default.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-07 19:04:45 -05:00
parent 447fd93e60
commit 8c24ef97c7
10 changed files with 26 additions and 15 deletions

2
.gitignore vendored
View File

@ -4,7 +4,7 @@
/Songs/ /Songs/
/.opsu.log /.opsu.log
/.opsu.cfg /.opsu.cfg
/.opsu.db /.opsu.db*
/.opsu_scores.db /.opsu_scores.db
# Eclipse # Eclipse

View File

@ -161,7 +161,6 @@ public class Opsu extends StateBasedGame {
String[] icons = { "icon16.png", "icon32.png" }; String[] icons = { "icon16.png", "icon32.png" };
app.setIcons(icons); app.setIcons(icons);
app.setForceExit(true); app.setForceExit(true);
app.setUpdateOnlyWhenVisible(false);
app.start(); app.start();

View File

@ -138,6 +138,7 @@ public class Utils {
container.setShowFPS(false); container.setShowFPS(false);
container.getInput().enableKeyRepeat(); container.getInput().enableKeyRepeat();
container.setAlwaysRender(true); container.setAlwaysRender(true);
container.setUpdateOnlyWhenVisible(false);
int width = container.getWidth(); int width = container.getWidth();
int height = container.getHeight(); int height = container.getHeight();

View File

@ -70,9 +70,8 @@ public class MusicController {
* @param osu the OsuFile to play * @param osu the OsuFile to play
* @param loop whether or not to loop the track * @param loop whether or not to loop the track
* @param preview whether to start at the preview time (true) or beginning (false) * @param preview whether to start at the preview time (true) or beginning (false)
* @param reset plays at the preview time even if it has the same preview time as the last
*/ */
public static void play(final OsuFile osu, final boolean loop, final boolean preview, final boolean reset) { public static void play(final OsuFile osu, final boolean loop, final boolean preview) {
// new track: load and play // new track: load and play
if (lastOsu == null || !osu.audioFilename.equals(lastOsu.audioFilename)) { if (lastOsu == null || !osu.audioFilename.equals(lastOsu.audioFilename)) {
reset(); reset();
@ -95,7 +94,7 @@ public class MusicController {
} }
// new track position: play at position // new track position: play at position
else if (osu.previewTime != lastOsu.previewTime || reset) else if (osu.previewTime != lastOsu.previewTime)
playAt(osu.previewTime, loop); playAt(osu.previewTime, loop);
lastOsu = osu; lastOsu = osu;
@ -277,13 +276,22 @@ public class MusicController {
*/ */
public static boolean trackEnded() { return trackEnded; } public static boolean trackEnded() { return trackEnded; }
/**
* Loops the current track if it has ended.
* @param preview whether to start at the preview time (true) or beginning (false)
*/
public static void loopTrackIfEnded(boolean preview) {
if (trackEnded && trackExists())
playAt((preview) ? lastOsu.previewTime : 0, false);
}
/** /**
* Plays the theme song. * Plays the theme song.
*/ */
public static void playThemeSong() { public static void playThemeSong() {
OsuFile osu = Options.getOsuTheme(); OsuFile osu = Options.getOsuTheme();
if (osu != null) { if (osu != null) {
play(osu, true, false, false); play(osu, true, false);
themePlaying = true; themePlaying = true;
} }
} }

View File

@ -28,6 +28,7 @@ import itdelatrisu.opsu.OsuGroupNode;
import itdelatrisu.opsu.ScoreData; import itdelatrisu.opsu.ScoreData;
import itdelatrisu.opsu.UI; import itdelatrisu.opsu.UI;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.audio.SoundController; import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect; import itdelatrisu.opsu.audio.SoundEffect;
@ -584,6 +585,7 @@ public class ButtonMenu extends BasicGameState {
public void update(GameContainer container, StateBasedGame game, int delta) public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException { throws SlickException {
UI.update(delta); UI.update(delta);
MusicController.loopTrackIfEnded(false);
if (menuState != null) if (menuState != null)
menuState.update(container, delta, input.getMouseX(), input.getMouseY()); menuState.update(container, delta, input.getMouseX(), input.getMouseY());
} }

View File

@ -28,6 +28,7 @@ import itdelatrisu.opsu.OsuParser;
import itdelatrisu.opsu.OszUnpacker; import itdelatrisu.opsu.OszUnpacker;
import itdelatrisu.opsu.UI; import itdelatrisu.opsu.UI;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.audio.SoundController; import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect; import itdelatrisu.opsu.audio.SoundEffect;
import itdelatrisu.opsu.downloads.BloodcatServer; import itdelatrisu.opsu.downloads.BloodcatServer;
@ -319,6 +320,7 @@ public class DownloadsMenu extends BasicGameState {
public void update(GameContainer container, StateBasedGame game, int delta) public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException { throws SlickException {
UI.update(delta); UI.update(delta);
MusicController.loopTrackIfEnded(false);
int mouseX = input.getMouseX(), mouseY = input.getMouseY(); int mouseX = input.getMouseX(), mouseY = input.getMouseY();
UI.getBackButton().hoverUpdate(delta, mouseX, mouseY); UI.getBackButton().hoverUpdate(delta, mouseX, mouseY);
prevPage.hoverUpdate(delta, mouseX, mouseY); prevPage.hoverUpdate(delta, mouseX, mouseY);

View File

@ -125,7 +125,8 @@ public class GameRanking extends BasicGameState {
if (data.isGameplay()) { if (data.isGameplay()) {
retryButton.hoverUpdate(delta, mouseX, mouseY); retryButton.hoverUpdate(delta, mouseX, mouseY);
exitButton.hoverUpdate(delta, mouseX, mouseY); exitButton.hoverUpdate(delta, mouseX, mouseY);
} } else
MusicController.loopTrackIfEnded(true);
UI.getBackButton().hoverUpdate(delta, mouseX, mouseY); UI.getBackButton().hoverUpdate(delta, mouseX, mouseY);
} }

View File

@ -312,6 +312,8 @@ public class MainMenu extends BasicGameState {
public void update(GameContainer container, StateBasedGame game, int delta) public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException { throws SlickException {
UI.update(delta); UI.update(delta);
if (MusicController.trackEnded())
nextTrack(); // end of track: go to next track
int mouseX = input.getMouseX(), mouseY = input.getMouseY(); int mouseX = input.getMouseX(), mouseY = input.getMouseY();
logo.hoverUpdate(delta, mouseX, mouseY, 0.25f); logo.hoverUpdate(delta, mouseX, mouseY, 0.25f);
playButton.hoverUpdate(delta, mouseX, mouseY, 0.25f); playButton.hoverUpdate(delta, mouseX, mouseY, 0.25f);
@ -377,9 +379,6 @@ public class MainMenu extends BasicGameState {
logo.setX(container.getWidth() / 2); logo.setX(container.getWidth() / 2);
} }
} }
if (MusicController.trackEnded())
nextTrack();
} }
@Override @Override

View File

@ -25,6 +25,7 @@ import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.Options.GameOption; import itdelatrisu.opsu.Options.GameOption;
import itdelatrisu.opsu.UI; import itdelatrisu.opsu.UI;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.audio.SoundController; import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect; import itdelatrisu.opsu.audio.SoundEffect;
@ -259,6 +260,7 @@ public class OptionsMenu extends BasicGameState {
public void update(GameContainer container, StateBasedGame game, int delta) public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException { throws SlickException {
UI.update(delta); UI.update(delta);
MusicController.loopTrackIfEnded(false);
int mouseX = input.getMouseX(), mouseY = input.getMouseY(); int mouseX = input.getMouseX(), mouseY = input.getMouseY();
UI.getBackButton().hoverUpdate(delta, mouseX, mouseY); UI.getBackButton().hoverUpdate(delta, mouseX, mouseY);
} }

View File

@ -460,6 +460,7 @@ public class SongMenu extends BasicGameState {
public void update(GameContainer container, StateBasedGame game, int delta) public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException { throws SlickException {
UI.update(delta); UI.update(delta);
MusicController.loopTrackIfEnded(true);
int mouseX = input.getMouseX(), mouseY = input.getMouseY(); int mouseX = input.getMouseX(), mouseY = input.getMouseY();
UI.getBackButton().hoverUpdate(delta, mouseX, mouseY); UI.getBackButton().hoverUpdate(delta, mouseX, mouseY);
selectModsButton.hoverUpdate(delta, mouseX, mouseY); selectModsButton.hoverUpdate(delta, mouseX, mouseY);
@ -566,10 +567,6 @@ public class SongMenu extends BasicGameState {
hoverOffset = 0f; hoverOffset = 0f;
hoverIndex = -1; hoverIndex = -1;
} }
if (MusicController.trackEnded()) {
OsuFile osu = focusNode.osuFiles.get(focusNode.osuFileIndex);
MusicController.play(osu, false, true, true);
}
} }
@Override @Override
@ -1167,7 +1164,7 @@ public class SongMenu extends BasicGameState {
startNode = node; startNode = node;
focusNode = OsuGroupList.get().getNode(node, osuFileIndex); focusNode = OsuGroupList.get().getNode(node, osuFileIndex);
OsuFile osu = focusNode.osuFiles.get(focusNode.osuFileIndex); OsuFile osu = focusNode.osuFiles.get(focusNode.osuFileIndex);
MusicController.play(osu, false, preview, false); MusicController.play(osu, false, preview);
Utils.loadGlyphs(osu); Utils.loadGlyphs(osu);
// load scores // load scores