add options menu as overlay

This commit is contained in:
yugecin
2017-01-19 16:03:53 +01:00
parent 04449abe62
commit e7eec14341
8 changed files with 297 additions and 190 deletions

View File

@@ -18,35 +18,14 @@
package itdelatrisu.opsu.states;
import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Opsu;
import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.Options.GameOption;
import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.audio.SoundController;
import itdelatrisu.opsu.audio.SoundEffect;
import itdelatrisu.opsu.ui.UI;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.FadeInTransition;
import org.newdawn.slick.state.transition.EmptyTransition;
import yugecin.opsudance.ui.OptionsOverlay;
import yugecin.opsudance.ui.OptionsOverlay.OptionTab;
/**
* "Game Options" state.
* <p>
* Players are able to view and change various game settings in this state.
*/
public class OptionsMenu extends BasicGameState implements OptionsOverlay.Parent {
public class OptionsMenu {
/** Option tabs. */
private static final OptionTab[] options = new OptionsOverlay.OptionTab[]{
public static final OptionTab[] normalOptions = new OptionsOverlay.OptionTab[]{
new OptionTab("Display", new GameOption[]{
GameOption.SCREEN_RESOLUTION,
GameOption.FULLSCREEN,
@@ -154,104 +133,4 @@ public class OptionsMenu extends BasicGameState implements OptionsOverlay.Parent
})
};
private StateBasedGame game;
private Input input;
private final int state;
private OptionsOverlay optionsOverlay;
public OptionsMenu(int state) {
this.state = state;
}
@Override
public void init(GameContainer container, StateBasedGame game)
throws SlickException {
this.game = game;
this.input = container.getInput();
optionsOverlay = new OptionsOverlay(this, options, 5, container);
}
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
// background
GameImage.OPTIONS_BG.getImage().draw();
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
optionsOverlay.render(g, mouseX, mouseY);
UI.draw(g);
}
@Override
public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
UI.update(delta);
MusicController.loopTrackIfEnded(false);
optionsOverlay.update(delta, input.getMouseX(), input.getMouseY());
}
@Override
public int getID() {
return state;
}
@Override
public void mouseReleased(int button, int x, int y) {
optionsOverlay.mouseReleased(button, x, y);
}
@Override
public void mousePressed(int button, int x, int y) {
optionsOverlay.mousePressed(button, x, y);
}
@Override
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
optionsOverlay.mouseDragged(oldx, oldy, newx, newy);
}
@Override
public void mouseWheelMoved(int newValue) {
optionsOverlay.mouseWheelMoved(newValue);
}
@Override
public void keyPressed(int key, char c) {
optionsOverlay.keyPressed(key, c);
}
/**
* This string is built with option values when entering the options menu.
* When leaving the options menu, this string is checked against the new optionstring with the same options.
* If those do not match, it means some option has change which requires a restart
*/
private String restartOptions;
@Override
public void enter(GameContainer container, StateBasedGame game)
throws SlickException {
UI.enter();
restartOptions = "" + Options.getResolutionIdx() + Options.isFullscreen() + Options.allowLargeResolutions() + Options.getSkinName();
}
@Override
public void leave(GameContainer container, StateBasedGame game) throws SlickException {
if (!("" + Options.getResolutionIdx() + Options.isFullscreen() + Options.allowLargeResolutions() + Options.getSkinName()).equals(restartOptions)) {
container.setForceExit(false);
container.exit();
return;
}
SoundController.playSound(SoundEffect.MENUBACK);
}
@Override
public void onLeave() {
game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition());
}
@Override
public void onSaveOption(GameOption option) {
}
}