add options menu as overlay
This commit is contained in:
@@ -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) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ import org.newdawn.slick.gui.TextField;
|
||||
import yugecin.opsudance.core.DisplayContainer;
|
||||
import yugecin.opsudance.core.inject.InstanceContainer;
|
||||
import yugecin.opsudance.core.state.ComplexOpsuState;
|
||||
import yugecin.opsudance.ui.OptionsOverlay;
|
||||
|
||||
/**
|
||||
* "Song Selection" state.
|
||||
@@ -320,15 +321,21 @@ public class SongMenu extends ComplexOpsuState {
|
||||
/** Sort order dropdown menu. */
|
||||
private DropdownMenu<BeatmapSortOrder> sortMenu;
|
||||
|
||||
private final OptionsOverlay optionsOverlay;
|
||||
|
||||
public SongMenu(final DisplayContainer displayContainer, InstanceContainer instanceContainer) {
|
||||
super(displayContainer);
|
||||
this.instanceContainer = instanceContainer;
|
||||
optionsOverlay = new OptionsOverlay(this, displayContainer, OptionsMenu.normalOptions, 0);
|
||||
overlays.add(optionsOverlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void revalidate() {
|
||||
super.revalidate();
|
||||
|
||||
components.clear();
|
||||
|
||||
// header/footer coordinates
|
||||
headerY = displayContainer.height * 0.0075f + GameImage.MENU_MUSICNOTE.getImage().getHeight() +
|
||||
Fonts.BOLD.getLineHeight() + Fonts.DEFAULT.getLineHeight() +
|
||||
@@ -460,8 +467,6 @@ public class SongMenu extends ComplexOpsuState {
|
||||
|
||||
@Override
|
||||
public void render(Graphics g) {
|
||||
super.render(g);
|
||||
|
||||
g.setBackground(Color.black);
|
||||
|
||||
int width = displayContainer.width;
|
||||
@@ -711,6 +716,8 @@ public class SongMenu extends ComplexOpsuState {
|
||||
UI.getBackButton().draw();
|
||||
|
||||
UI.draw(g);
|
||||
|
||||
super.render(g);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -927,7 +934,7 @@ public class SongMenu extends ComplexOpsuState {
|
||||
return true;
|
||||
} else if (selectOptionsButton.contains(x, y)) {
|
||||
SoundController.playSound(SoundEffect.MENUHIT);
|
||||
// TODO d displayContainer.switchState(OptionsMenu.class);
|
||||
optionsOverlay.show();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1166,7 +1173,7 @@ public class SongMenu extends ComplexOpsuState {
|
||||
return true;
|
||||
case Input.KEY_O:
|
||||
if (input.isKeyDown(Input.KEY_LCONTROL) || input.isKeyDown(Input.KEY_RCONTROL)) {
|
||||
// TODO d displayContainer.switchState(OptionsMenu.class);
|
||||
optionsOverlay.show();
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@@ -1225,6 +1232,10 @@ public class SongMenu extends ComplexOpsuState {
|
||||
|
||||
@Override
|
||||
public boolean mouseWheelMoved(int newValue) {
|
||||
if (super.mouseWheelMoved(newValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Input input = displayContainer.input;
|
||||
|
||||
if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT)) {
|
||||
|
||||
Reference in New Issue
Block a user