From 2007058eb1373693280b525054398a93b528f30a Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Wed, 28 Jan 2015 20:57:43 -0500 Subject: [PATCH] Quick fixes. - Fixed a crash when closing the application in the ranking screen when viewing a score. - Fixed a minor bug where OsuGroupList fields were not being erased upon restart. - Dim the track volume by 50% when viewing a score. Signed-off-by: Jeffrey Han --- src/itdelatrisu/opsu/Container.java | 4 ++++ src/itdelatrisu/opsu/Opsu.java | 20 +++++++++++++------ src/itdelatrisu/opsu/OsuGroupList.java | 14 +++++++++++-- .../opsu/audio/MusicController.java | 5 +++-- src/itdelatrisu/opsu/states/GameRanking.java | 14 +++++++++---- src/itdelatrisu/opsu/states/MainMenu.java | 2 +- src/itdelatrisu/opsu/states/SongMenu.java | 4 ++++ 7 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/itdelatrisu/opsu/Container.java b/src/itdelatrisu/opsu/Container.java index 1c502ac5..68a1709e 100644 --- a/src/itdelatrisu/opsu/Container.java +++ b/src/itdelatrisu/opsu/Container.java @@ -95,6 +95,10 @@ public class Container extends AppGameContainer { // prevent loading tracks from re-initializing OpenAL MusicController.reset(); + + // reset OsuGroupList data + if (OsuGroupList.get() != null) + OsuGroupList.get().reset(); } @Override diff --git a/src/itdelatrisu/opsu/Opsu.java b/src/itdelatrisu/opsu/Opsu.java index c040a9a0..e7e21a8e 100644 --- a/src/itdelatrisu/opsu/Opsu.java +++ b/src/itdelatrisu/opsu/Opsu.java @@ -175,12 +175,20 @@ public class Opsu extends StateBasedGame { if (id == STATE_GAME || id == STATE_GAMEPAUSEMENU || id == STATE_GAMERANKING) { // start playing track at preview position SongMenu songMenu = (SongMenu) this.getState(Opsu.STATE_SONGMENU); - songMenu.resetGameDataOnLoad(); - if (id == STATE_GAME) { - MusicController.pause(); - MusicController.resume(); - } else - songMenu.resetTrackOnLoad(); + if (id == STATE_GAMERANKING) { + GameData data = ((GameRanking) this.getState(Opsu.STATE_GAMERANKING)).getGameData(); + if (data != null && data.isGameplay()) { + songMenu.resetGameDataOnLoad(); + songMenu.resetTrackOnLoad(); + } + } else { + songMenu.resetGameDataOnLoad(); + if (id == STATE_GAME) { + MusicController.pause(); + MusicController.resume(); + } else + songMenu.resetTrackOnLoad(); + } Utils.resetCursor(); this.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black)); return false; diff --git a/src/itdelatrisu/opsu/OsuGroupList.java b/src/itdelatrisu/opsu/OsuGroupList.java index 064d04e3..d1acad28 100644 --- a/src/itdelatrisu/opsu/OsuGroupList.java +++ b/src/itdelatrisu/opsu/OsuGroupList.java @@ -48,10 +48,10 @@ public class OsuGroupList { private ArrayList nodes; /** Index of current expanded node (-1 if no node is expanded). */ - private int expandedIndex = -1; + private int expandedIndex; /** The last search query. */ - private String lastQuery = ""; + private String lastQuery; /** * Creates a new instance of this class (overwriting any previous instance). @@ -68,7 +68,17 @@ public class OsuGroupList { */ private OsuGroupList() { parsedNodes = new ArrayList(); + reset(); + } + + /** + * Resets the list's fields. + * This does not erase any parsed nodes. + */ + public void reset() { nodes = parsedNodes; + expandedIndex = -1; + lastQuery = ""; } /** diff --git a/src/itdelatrisu/opsu/audio/MusicController.java b/src/itdelatrisu/opsu/audio/MusicController.java index 46df6e44..181c4710 100644 --- a/src/itdelatrisu/opsu/audio/MusicController.java +++ b/src/itdelatrisu/opsu/audio/MusicController.java @@ -289,10 +289,11 @@ public class MusicController { /** * Toggles the volume dim state of the current track. + * @param multiplier the volume multiplier when the track is dimmed */ - public static void toggleTrackDimmed() { + public static void toggleTrackDimmed(float multiplier) { float volume = Options.getMusicVolume() * Options.getMasterVolume(); - setVolume((trackDimmed) ? volume : volume / 3f); + setVolume((trackDimmed) ? volume : volume * multiplier); trackDimmed = !trackDimmed; } diff --git a/src/itdelatrisu/opsu/states/GameRanking.java b/src/itdelatrisu/opsu/states/GameRanking.java index eee8fa19..b57987f8 100644 --- a/src/itdelatrisu/opsu/states/GameRanking.java +++ b/src/itdelatrisu/opsu/states/GameRanking.java @@ -171,7 +171,10 @@ public class GameRanking extends BasicGameState { throws SlickException { Display.setTitle(game.getTitle()); Utils.getBackButton().setScale(1f); - if (data.isGameplay()) + if (!data.isGameplay()) { + if (!MusicController.isTrackDimmed()) + MusicController.toggleTrackDimmed(0.5f); + } else SoundController.playSound(SoundEffect.APPLAUSE); } @@ -199,7 +202,10 @@ public class GameRanking extends BasicGameState { * Sets the associated GameData object. * @param data the GameData */ - public void setGameData(GameData data) { - this.data = data; - } + public void setGameData(GameData data) { this.data = data; } + + /** + * Returns the current GameData object (usually null unless state active). + */ + public GameData getGameData() { return data; } } diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index 839b15f2..9a630c3a 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -249,7 +249,7 @@ public class MainMenu extends BasicGameState { // window focus change: increase/decrease theme song volume if (MusicController.isThemePlaying() && MusicController.isTrackDimmed() == container.hasFocus()) - MusicController.toggleTrackDimmed(); + MusicController.toggleTrackDimmed(0.33f); // fade in background if (bgAlpha < 0.9f) { diff --git a/src/itdelatrisu/opsu/states/SongMenu.java b/src/itdelatrisu/opsu/states/SongMenu.java index d4491a49..24ad54e5 100644 --- a/src/itdelatrisu/opsu/states/SongMenu.java +++ b/src/itdelatrisu/opsu/states/SongMenu.java @@ -777,6 +777,10 @@ public class SongMenu extends BasicGameState { else if (MusicController.isPaused()) MusicController.resume(); + // undim track + if (MusicController.isTrackDimmed()) + MusicController.toggleTrackDimmed(1f); + // reset song stack randomStack = new Stack();