Follow-up to 516e628: Fix resetting game data too soon.

Instead of resetting immediately, set a variable in SongMenu to reset data when entering the state.  Fixes some weird behaviors, and also allows resetting in more scenarios.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-01-16 00:36:05 -05:00
parent 553f091693
commit 90c10d21da
4 changed files with 22 additions and 6 deletions

View File

@ -168,6 +168,7 @@ public class Opsu extends StateBasedGame {
// start playing track at preview position
MusicController.pause();
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
((SongMenu) this.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad();
this.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
return false;
}

View File

@ -138,7 +138,7 @@ public class GamePauseMenu extends BasicGameState {
MusicController.stop();
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
SoundController.playSound(SoundEffect.MENUBACK);
gameState.resetGameData();
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad();
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
} else {
SoundController.playSound(SoundEffect.MENUBACK);
@ -182,7 +182,7 @@ public class GamePauseMenu extends BasicGameState {
MusicController.pause(); // lose state
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
SoundController.playSound(SoundEffect.MENUBACK);
gameState.resetGameData();
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad();
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
}
}

View File

@ -151,6 +151,7 @@ public class GameRanking extends BasicGameState {
MusicController.pause();
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
SoundController.playSound(SoundEffect.MENUBACK);
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad();
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
break;
case Input.KEY_F12:
@ -174,13 +175,13 @@ public class GameRanking extends BasicGameState {
} else if (exitButton.contains(x, y)) {
SoundController.playSound(SoundEffect.MENUBACK);
((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset();
((Game) game.getState(Opsu.STATE_GAME)).resetGameData();
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad();
game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
} else if (Utils.getBackButton().contains(x, y)) {
MusicController.pause();
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
SoundController.playSound(SoundEffect.MENUBACK);
((Game) game.getState(Opsu.STATE_GAME)).resetGameData();
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad();
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
}
}

View File

@ -139,6 +139,11 @@ public class SongMenu extends BasicGameState {
*/
private Animation loader;
/**
* Whether or not to reset game data upon entering the state.
*/
private boolean resetGame = false;
// game-related variables
private GameContainer container;
private StateBasedGame game;
@ -586,8 +591,12 @@ public class SongMenu extends BasicGameState {
else if (MusicController.isPaused())
MusicController.resume();
// destroy skin images, if any
GameImage.destroySkinImages();
// reset game data
if (resetGame) {
((Game) game.getState(Opsu.STATE_GAME)).resetGameData();
GameImage.destroySkinImages(); // destroy skin images, if any
resetGame = false;
}
}
@Override
@ -703,6 +712,11 @@ public class SongMenu extends BasicGameState {
return oldFocus;
}
/**
* Triggers a reset of game data upon entering this state.
*/
public void resetGameDataOnLoad() { resetGame = true; }
/**
* Starts the game.
* @param osu the OsuFile to send to the game