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:
parent
553f091693
commit
90c10d21da
|
@ -168,6 +168,7 @@ public class Opsu extends StateBasedGame {
|
||||||
// start playing track at preview position
|
// start playing track at preview position
|
||||||
MusicController.pause();
|
MusicController.pause();
|
||||||
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
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));
|
this.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ public class GamePauseMenu extends BasicGameState {
|
||||||
MusicController.stop();
|
MusicController.stop();
|
||||||
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
||||||
SoundController.playSound(SoundEffect.MENUBACK);
|
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));
|
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||||
} else {
|
} else {
|
||||||
SoundController.playSound(SoundEffect.MENUBACK);
|
SoundController.playSound(SoundEffect.MENUBACK);
|
||||||
|
@ -182,7 +182,7 @@ public class GamePauseMenu extends BasicGameState {
|
||||||
MusicController.pause(); // lose state
|
MusicController.pause(); // lose state
|
||||||
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
||||||
SoundController.playSound(SoundEffect.MENUBACK);
|
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));
|
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,6 +151,7 @@ public class GameRanking extends BasicGameState {
|
||||||
MusicController.pause();
|
MusicController.pause();
|
||||||
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
||||||
SoundController.playSound(SoundEffect.MENUBACK);
|
SoundController.playSound(SoundEffect.MENUBACK);
|
||||||
|
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).resetGameDataOnLoad();
|
||||||
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||||
break;
|
break;
|
||||||
case Input.KEY_F12:
|
case Input.KEY_F12:
|
||||||
|
@ -174,13 +175,13 @@ public class GameRanking extends BasicGameState {
|
||||||
} else if (exitButton.contains(x, y)) {
|
} else if (exitButton.contains(x, y)) {
|
||||||
SoundController.playSound(SoundEffect.MENUBACK);
|
SoundController.playSound(SoundEffect.MENUBACK);
|
||||||
((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset();
|
((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));
|
game.enterState(Opsu.STATE_MAINMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||||
} else if (Utils.getBackButton().contains(x, y)) {
|
} else if (Utils.getBackButton().contains(x, y)) {
|
||||||
MusicController.pause();
|
MusicController.pause();
|
||||||
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
MusicController.playAt(MusicController.getOsuFile().previewTime, true);
|
||||||
SoundController.playSound(SoundEffect.MENUBACK);
|
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));
|
game.enterState(Opsu.STATE_SONGMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,6 +139,11 @@ public class SongMenu extends BasicGameState {
|
||||||
*/
|
*/
|
||||||
private Animation loader;
|
private Animation loader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not to reset game data upon entering the state.
|
||||||
|
*/
|
||||||
|
private boolean resetGame = false;
|
||||||
|
|
||||||
// game-related variables
|
// game-related variables
|
||||||
private GameContainer container;
|
private GameContainer container;
|
||||||
private StateBasedGame game;
|
private StateBasedGame game;
|
||||||
|
@ -586,8 +591,12 @@ public class SongMenu extends BasicGameState {
|
||||||
else if (MusicController.isPaused())
|
else if (MusicController.isPaused())
|
||||||
MusicController.resume();
|
MusicController.resume();
|
||||||
|
|
||||||
// destroy skin images, if any
|
// reset game data
|
||||||
GameImage.destroySkinImages();
|
if (resetGame) {
|
||||||
|
((Game) game.getState(Opsu.STATE_GAME)).resetGameData();
|
||||||
|
GameImage.destroySkinImages(); // destroy skin images, if any
|
||||||
|
resetGame = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -703,6 +712,11 @@ public class SongMenu extends BasicGameState {
|
||||||
return oldFocus;
|
return oldFocus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers a reset of game data upon entering this state.
|
||||||
|
*/
|
||||||
|
public void resetGameDataOnLoad() { resetGame = true; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the game.
|
* Starts the game.
|
||||||
* @param osu the OsuFile to send to the game
|
* @param osu the OsuFile to send to the game
|
||||||
|
|
Loading…
Reference in New Issue
Block a user