convert buttonmenu

This commit is contained in:
yugecin 2017-01-18 19:06:45 +01:00
parent 4416416813
commit c03897a47d
5 changed files with 239 additions and 277 deletions

View File

@ -87,7 +87,7 @@ public class Opsu extends StateBasedGame {
public void initStatesList(GameContainer container) throws SlickException { public void initStatesList(GameContainer container) throws SlickException {
//addState(new Splash(STATE_SPLASH)); //addState(new Splash(STATE_SPLASH));
//addState(new MainMenu(STATE_MAINMENU)); //addState(new MainMenu(STATE_MAINMENU));
addState(new ButtonMenu(STATE_BUTTONMENU)); //addState(new ButtonMenu(STATE_BUTTONMENU));
//addState(new SongMenu(STATE_SONGMENU)); //addState(new SongMenu(STATE_SONGMENU));
addState(new Game(STATE_GAME)); addState(new Game(STATE_GAME));
addState(new GamePauseMenu(STATE_GAMEPAUSEMENU)); addState(new GamePauseMenu(STATE_GAMEPAUSEMENU));

View File

@ -20,7 +20,6 @@ package itdelatrisu.opsu.states;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.GameMod; import itdelatrisu.opsu.GameMod;
import itdelatrisu.opsu.Opsu;
import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.ScoreData; import itdelatrisu.opsu.ScoreData;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
@ -39,114 +38,112 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.newdawn.slick.Color; import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException; import yugecin.opsudance.core.DisplayContainer;
import org.newdawn.slick.state.BasicGameState; import yugecin.opsudance.core.inject.InstanceContainer;
import org.newdawn.slick.state.StateBasedGame; import yugecin.opsudance.core.state.BaseOpsuState;
import org.newdawn.slick.state.transition.EmptyTransition;
import org.newdawn.slick.state.transition.FadeInTransition;
/** /**
* Generic button menu state. * Generic button menu state.
* <p> * <p>
* Displays a header and a set of defined options to the player. * Displays a header and a set of defined options to the player.
*/ */
public class ButtonMenu extends BasicGameState { public class ButtonMenu extends BaseOpsuState {
/** Menu states. */ /** Menu states. */
public enum MenuState { public enum MenuState {
/** The exit confirmation screen. */ /** The exit confirmation screen. */
EXIT (new Button[] { Button.YES, Button.NO }) { EXIT (new Button[] { Button.YES, Button.NO }) {
@Override @Override
public String[] getTitle(GameContainer container, StateBasedGame game) { public String[] getTitle() {
return new String[] { "Are you sure you want to exit opsu!?" }; return new String[] { "Are you sure you want to exit opsu!?" };
} }
@Override @Override
public void leave(GameContainer container, StateBasedGame game) { public void leave() {
Button.NO.click(container, game); Button.NO.click();
} }
}, },
/** The initial beatmap management screen (for a non-"favorite" beatmap). */ /** The initial beatmap management screen (for a non-"favorite" beatmap). */
BEATMAP (new Button[] { Button.CLEAR_SCORES, Button.FAVORITE_ADD, Button.DELETE, Button.CANCEL }) { BEATMAP (new Button[] { Button.CLEAR_SCORES, Button.FAVORITE_ADD, Button.DELETE, Button.CANCEL }) {
@Override @Override
public String[] getTitle(GameContainer container, StateBasedGame game) { public String[] getTitle() {
BeatmapSetNode node = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getNode(); BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode();
String beatmapString = (node != null) ? BeatmapSetList.get().getBaseNode(node.index).toString() : ""; String beatmapString = (node != null) ? BeatmapSetList.get().getBaseNode(node.index).toString() : "";
return new String[] { beatmapString, "What do you want to do with this beatmap?" }; return new String[] { beatmapString, "What do you want to do with this beatmap?" };
} }
@Override @Override
public void leave(GameContainer container, StateBasedGame game) { public void leave() {
Button.CANCEL.click(container, game); Button.CANCEL.click();
} }
@Override @Override
public void scroll(GameContainer container, StateBasedGame game, int newValue) { public void mouseWheelMoved(int newValue) {
Input input = container.getInput(); if (displayContainer.input.isKeyDown(Input.KEY_LALT) || displayContainer.input.isKeyDown(Input.KEY_RALT)) {
if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT)) super.mouseWheelMoved(newValue);
super.scroll(container, game, newValue); }
} }
}, },
/** The initial beatmap management screen (for a "favorite" beatmap). */ /** The initial beatmap management screen (for a "favorite" beatmap). */
BEATMAP_FAVORITE (new Button[] { Button.CLEAR_SCORES, Button.FAVORITE_REMOVE, Button.DELETE, Button.CANCEL }) { BEATMAP_FAVORITE (new Button[] { Button.CLEAR_SCORES, Button.FAVORITE_REMOVE, Button.DELETE, Button.CANCEL }) {
@Override @Override
public String[] getTitle(GameContainer container, StateBasedGame game) { public String[] getTitle() {
return BEATMAP.getTitle(container, game); return BEATMAP.getTitle();
} }
@Override @Override
public void leave(GameContainer container, StateBasedGame game) { public void leave() {
BEATMAP.leave(container, game); BEATMAP.leave();
} }
@Override @Override
public void scroll(GameContainer container, StateBasedGame game, int newValue) { public void mouseWheelMoved(int newValue) {
BEATMAP.scroll(container, game, newValue); BEATMAP.mouseWheelMoved(newValue);
} }
}, },
/** The beatmap deletion screen for a beatmap set with multiple beatmaps. */ /** The beatmap deletion screen for a beatmap set with multiple beatmaps. */
BEATMAP_DELETE_SELECT (new Button[] { Button.DELETE_GROUP, Button.DELETE_SONG, Button.CANCEL_DELETE }) { BEATMAP_DELETE_SELECT (new Button[] { Button.DELETE_GROUP, Button.DELETE_SONG, Button.CANCEL_DELETE }) {
@Override @Override
public String[] getTitle(GameContainer container, StateBasedGame game) { public String[] getTitle() {
BeatmapSetNode node = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getNode(); BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode();
String beatmapString = (node != null) ? node.toString() : ""; String beatmapString = (node != null) ? node.toString() : "";
return new String[] { String.format("Are you sure you wish to delete '%s' from disk?", beatmapString) }; return new String[] { String.format("Are you sure you wish to delete '%s' from disk?", beatmapString) };
} }
@Override @Override
public void leave(GameContainer container, StateBasedGame game) { public void leave() {
Button.CANCEL_DELETE.click(container, game); Button.CANCEL_DELETE.click();
} }
@Override @Override
public void scroll(GameContainer container, StateBasedGame game, int newValue) { public void mouseWheelMoved(int newValue) {
MenuState.BEATMAP.scroll(container, game, newValue); MenuState.BEATMAP.mouseWheelMoved(newValue);
} }
}, },
/** The beatmap deletion screen for a single beatmap. */ /** The beatmap deletion screen for a single beatmap. */
BEATMAP_DELETE_CONFIRM (new Button[] { Button.DELETE_CONFIRM, Button.CANCEL_DELETE }) { BEATMAP_DELETE_CONFIRM (new Button[] { Button.DELETE_CONFIRM, Button.CANCEL_DELETE }) {
@Override @Override
public String[] getTitle(GameContainer container, StateBasedGame game) { public String[] getTitle() {
return BEATMAP_DELETE_SELECT.getTitle(container, game); return BEATMAP_DELETE_SELECT.getTitle();
} }
@Override @Override
public void leave(GameContainer container, StateBasedGame game) { public void leave() {
Button.CANCEL_DELETE.click(container, game); Button.CANCEL_DELETE.click();
} }
@Override @Override
public void scroll(GameContainer container, StateBasedGame game, int newValue) { public void mouseWheelMoved(int newValue) {
MenuState.BEATMAP.scroll(container, game, newValue); MenuState.BEATMAP.mouseWheelMoved(newValue);
} }
}, },
/** The beatmap reloading confirmation screen. */ /** The beatmap reloading confirmation screen. */
RELOAD (new Button[] { Button.RELOAD_CONFIRM, Button.RELOAD_CANCEL }) { RELOAD (new Button[] { Button.RELOAD_CONFIRM, Button.RELOAD_CANCEL }) {
@Override @Override
public String[] getTitle(GameContainer container, StateBasedGame game) { public String[] getTitle() {
return new String[] { return new String[] {
"You have requested a full process of your beatmaps.", "You have requested a full process of your beatmaps.",
"This could take a few minutes.", "This could take a few minutes.",
@ -155,70 +152,68 @@ public class ButtonMenu extends BasicGameState {
} }
@Override @Override
public void leave(GameContainer container, StateBasedGame game) { public void leave() {
Button.RELOAD_CANCEL.click(container, game); Button.RELOAD_CANCEL.click();
} }
@Override @Override
public void scroll(GameContainer container, StateBasedGame game, int newValue) { public void mouseWheelMoved(int newValue) {
MenuState.BEATMAP.scroll(container, game, newValue); MenuState.BEATMAP.mouseWheelMoved(newValue);
} }
}, },
/** The score management screen. */ /** The score management screen. */
SCORE (new Button[] { Button.DELETE_SCORE, Button.CLOSE }) { SCORE (new Button[] { Button.DELETE_SCORE, Button.CLOSE }) {
@Override @Override
public String[] getTitle(GameContainer container, StateBasedGame game) { public String[] getTitle() {
return new String[] { "Score Management" }; return new String[] { "Score Management" };
} }
@Override @Override
public void leave(GameContainer container, StateBasedGame game) { public void leave() {
Button.CLOSE.click(container, game); Button.CLOSE.click();
} }
@Override @Override
public void scroll(GameContainer container, StateBasedGame game, int newValue) { public void mouseWheelMoved(int newValue) {
MenuState.BEATMAP.scroll(container, game, newValue); MenuState.BEATMAP.mouseWheelMoved(newValue);
} }
}, },
/** The game mod selection screen. */ /** The game mod selection screen. */
MODS (new Button[] { Button.RESET_MODS, Button.CLOSE }) { MODS (new Button[] { Button.RESET_MODS, Button.CLOSE }) {
@Override @Override
public String[] getTitle(GameContainer container, StateBasedGame game) { public String[] getTitle() {
return new String[] { return new String[] {
"Mods provide different ways to enjoy gameplay. Some have an effect on the score you can achieve during ranked play. Others are just for fun." "Mods provide different ways to enjoy gameplay. Some have an effect on the score you can achieve during ranked play. Others are just for fun."
}; };
} }
@Override @Override
protected float getBaseY(GameContainer container, StateBasedGame game) { protected float getBaseY(DisplayContainer displayContainer) {
return container.getHeight() * 2f / 3; return displayContainer.height * 2f / 3;
} }
@Override @Override
public void enter(GameContainer container, StateBasedGame game) { public void enter() {
super.enter(container, game); super.enter();
for (GameMod mod : GameMod.values()) for (GameMod mod : GameMod.values()) {
mod.resetHover(); mod.resetHover();
}
} }
@Override @Override
public void leave(GameContainer container, StateBasedGame game) { public void leave() {
Button.CLOSE.click(container, game); Button.CLOSE.click();
} }
@Override @Override
public void draw(GameContainer container, StateBasedGame game, Graphics g) { public void render(Graphics g) {
int width = container.getWidth();
int height = container.getHeight();
// score multiplier (TODO: fade in color changes) // score multiplier (TODO: fade in color changes)
float mult = GameMod.getScoreMultiplier(); float mult = GameMod.getScoreMultiplier();
String multString = String.format("Score Multiplier: %.2fx", mult); String multString = String.format("Score Multiplier: %.2fx", mult);
Color multColor = (mult == 1f) ? Color.white : (mult > 1f) ? Color.green : Color.red; Color multColor = (mult == 1f) ? Color.white : (mult > 1f) ? Color.green : Color.red;
float multY = Fonts.LARGE.getLineHeight() * 2 + height * 0.06f; float multY = Fonts.LARGE.getLineHeight() * 2 + displayContainer.height * 0.06f;
Fonts.LARGE.drawString( Fonts.LARGE.drawString(
(width - Fonts.LARGE.getWidth(multString)) / 2f, (displayContainer.width - Fonts.LARGE.getWidth(multString)) / 2f,
multY, multString, multColor); multY, multString, multColor);
// category text // category text
@ -232,27 +227,28 @@ public class ButtonMenu extends BasicGameState {
for (GameMod mod : GameMod.values()) for (GameMod mod : GameMod.values())
mod.draw(); mod.draw();
super.draw(container, game, g); super.render(g);
} }
@Override @Override
public void update(GameContainer container, int delta, int mouseX, int mouseY) { public void preRenderUpdate() {
super.update(container, delta, mouseX, mouseY); super.preRenderUpdate();
GameMod hoverMod = null; GameMod hoverMod = null;
for (GameMod mod : GameMod.values()) { for (GameMod mod : GameMod.values()) {
mod.hoverUpdate(delta, mod.isActive()); mod.hoverUpdate(displayContainer.renderDelta, mod.isActive());
if (hoverMod == null && mod.contains(mouseX, mouseY)) if (hoverMod == null && mod.contains(displayContainer.mouseX, displayContainer.mouseY))
hoverMod = mod; hoverMod = mod;
} }
// tooltips // tooltips
if (hoverMod != null) if (hoverMod != null) {
UI.updateTooltip(delta, hoverMod.getDescription(), true); UI.updateTooltip(displayContainer.renderDelta, hoverMod.getDescription(), true);
}
} }
@Override @Override
public void keyPress(GameContainer container, StateBasedGame game, int key, char c) { public void keyPressed(int key, char c) {
super.keyPress(container, game, key, c); super.keyPressed(key, c);
for (GameMod mod : GameMod.values()) { for (GameMod mod : GameMod.values()) {
if (key == mod.getKey()) { if (key == mod.getKey()) {
mod.toggle(true); mod.toggle(true);
@ -262,8 +258,8 @@ public class ButtonMenu extends BasicGameState {
} }
@Override @Override
public void click(GameContainer container, StateBasedGame game, int cx, int cy) { public void mousePressed(int cx, int cy) {
super.click(container, game, cx, cy); super.mousePressed(cx, cy);
for (GameMod mod : GameMod.values()) { for (GameMod mod : GameMod.values()) {
if (mod.contains(cx, cy)) { if (mod.contains(cx, cy)) {
boolean prevState = mod.isActive(); boolean prevState = mod.isActive();
@ -276,11 +272,14 @@ public class ButtonMenu extends BasicGameState {
} }
@Override @Override
public void scroll(GameContainer container, StateBasedGame game, int newValue) { public void mouseWheelMoved(int newValue) {
MenuState.BEATMAP.scroll(container, game, newValue); MenuState.BEATMAP.mouseWheelMoved(newValue);
} }
}; };
public static DisplayContainer displayContainer;
public static InstanceContainer instanceContainer;
/** The buttons in the state. */ /** The buttons in the state. */
private final Button[] buttons; private final Button[] buttons;
@ -306,15 +305,10 @@ public class ButtonMenu extends BasicGameState {
/** /**
* Initializes the menu state. * Initializes the menu state.
* @param container the game container
* @param game the game
* @param button the center button image
* @param buttonL the left button image
* @param buttonR the right button image
*/ */
public void init(GameContainer container, StateBasedGame game, Image button, Image buttonL, Image buttonR) { public void revalidate(Image button, Image buttonL, Image buttonR) {
float center = container.getWidth() / 2f; float center = displayContainer.width / 2;
float baseY = getBaseY(container, game); float baseY = getBaseY(displayContainer);
float offsetY = button.getHeight() * 1.25f; float offsetY = button.getHeight() * 1.25f;
menuButtons = new MenuButton[buttons.length]; menuButtons = new MenuButton[buttons.length];
@ -328,25 +322,21 @@ public class ButtonMenu extends BasicGameState {
/** /**
* Returns the base Y coordinate for the buttons. * Returns the base Y coordinate for the buttons.
* @param container the game container
* @param game the game
*/ */
protected float getBaseY(GameContainer container, StateBasedGame game) { protected float getBaseY(DisplayContainer displayContainer) {
float baseY = container.getHeight() * 0.2f; float baseY = displayContainer.height * 0.2f;
baseY += ((getTitle(container, game).length - 1) * Fonts.LARGE.getLineHeight()); baseY += ((getTitle().length - 1) * Fonts.LARGE.getLineHeight());
return baseY; return baseY;
} }
/** /**
* Draws the title and buttons to the graphics context. * Draws the title and buttons to the graphics context.
* @param container the game container
* @param game the game
* @param g the graphics context * @param g the graphics context
*/ */
public void draw(GameContainer container, StateBasedGame game, Graphics g) { public void render(Graphics g) {
// draw title // draw title
if (actualTitle != null) { if (actualTitle != null) {
float marginX = container.getWidth() * 0.015f, marginY = container.getHeight() * 0.01f; float marginX = displayContainer.width * 0.015f, marginY = displayContainer.height * 0.01f;
int lineHeight = Fonts.LARGE.getLineHeight(); int lineHeight = Fonts.LARGE.getLineHeight();
for (int i = 0, size = actualTitle.size(); i < size; i++) for (int i = 0, size = actualTitle.size(); i < size; i++)
Fonts.LARGE.drawString(marginX, marginY + (i * lineHeight), actualTitle.get(i), Color.white); Fonts.LARGE.drawString(marginX, marginY + (i * lineHeight), actualTitle.get(i), Color.white);
@ -361,17 +351,13 @@ public class ButtonMenu extends BasicGameState {
/** /**
* Updates the menu state. * Updates the menu state.
* @param container the game container
* @param delta the delta interval
* @param mouseX the mouse x coordinate
* @param mouseY the mouse y coordinate
*/ */
public void update(GameContainer container, int delta, int mouseX, int mouseY) { public void preRenderUpdate() {
float center = container.getWidth() / 2f; float center = displayContainer.width / 2f;
boolean centerOffsetUpdated = centerOffset.update(delta); boolean centerOffsetUpdated = centerOffset.update(displayContainer.renderDelta);
float centerOffsetX = centerOffset.getValue(); float centerOffsetX = centerOffset.getValue();
for (int i = 0; i < buttons.length; i++) { for (int i = 0; i < buttons.length; i++) {
menuButtons[i].hoverUpdate(delta, mouseX, mouseY); menuButtons[i].hoverUpdate(displayContainer.renderDelta, displayContainer.mouseX, displayContainer.mouseY);
// move button to center // move button to center
if (centerOffsetUpdated) if (centerOffsetUpdated)
@ -381,15 +367,11 @@ public class ButtonMenu extends BasicGameState {
/** /**
* Processes a mouse click action. * Processes a mouse click action.
* @param container the game container
* @param game the game
* @param cx the x coordinate
* @param cy the y coordinate
*/ */
public void click(GameContainer container, StateBasedGame game, int cx, int cy) { public void mousePressed(int x, int y) {
for (int i = 0; i < buttons.length; i++) { for (int i = 0; i < buttons.length; i++) {
if (menuButtons[i].contains(cx, cy)) { if (menuButtons[i].contains(x, y)) {
buttons[i].click(container, game); buttons[i].click();
break; break;
} }
} }
@ -397,42 +379,34 @@ public class ButtonMenu extends BasicGameState {
/** /**
* Processes a key press action. * Processes a key press action.
* @param container the game container
* @param game the game
* @param key the key code that was pressed (see {@link org.newdawn.slick.Input}) * @param key the key code that was pressed (see {@link org.newdawn.slick.Input})
* @param c the character of the key that was pressed * @param c the character of the key that was pressed
*/ */
public void keyPress(GameContainer container, StateBasedGame game, int key, char c) { public void keyPressed(int key, char c) {
int index = Character.getNumericValue(c) - 1; int index = Character.getNumericValue(c) - 1;
if (index >= 0 && index < buttons.length) if (index >= 0 && index < buttons.length)
buttons[index].click(container, game); buttons[index].click();
} }
/** /**
* Retrieves the title strings for the menu state (via override). * Retrieves the title strings for the menu state (via override).
* @param container the game container
* @param game the game
*/ */
public String[] getTitle(GameContainer container, StateBasedGame game) { return new String[0]; } public String[] getTitle() { return new String[0]; }
/** /**
* Processes a mouse wheel movement. * Processes a mouse wheel movement.
* @param container the game container
* @param game the game
* @param newValue the amount that the mouse wheel moved * @param newValue the amount that the mouse wheel moved
*/ */
public void scroll(GameContainer container, StateBasedGame game, int newValue) { public void mouseWheelMoved(int newValue) {
UI.changeVolume((newValue < 0) ? -1 : 1); UI.changeVolume((newValue < 0) ? -1 : 1);
} }
/** /**
* Processes a state enter request. * Processes a state enter request.
* @param container the game container
* @param game the game
*/ */
public void enter(GameContainer container, StateBasedGame game) { public void enter() {
float center = container.getWidth() / 2f; float center = displayContainer.width / 2f;
float centerOffsetX = container.getWidth() * OFFSET_WIDTH_RATIO; float centerOffsetX = displayContainer.width * OFFSET_WIDTH_RATIO;
centerOffset = new AnimatedValue(700, centerOffsetX, 0, AnimationEquation.OUT_BOUNCE); centerOffset = new AnimatedValue(700, centerOffsetX, 0, AnimationEquation.OUT_BOUNCE);
for (int i = 0; i < buttons.length; i++) { for (int i = 0; i < buttons.length; i++) {
menuButtons[i].setX(center + ((i % 2 == 0) ? centerOffsetX : centerOffsetX * -1)); menuButtons[i].setX(center + ((i % 2 == 0) ? centerOffsetX : centerOffsetX * -1));
@ -440,150 +414,149 @@ public class ButtonMenu extends BasicGameState {
} }
// create title string list // create title string list
actualTitle = new ArrayList<String>(); actualTitle = new ArrayList<>();
String[] title = getTitle(container, game); String[] title = getTitle();
int maxLineWidth = (int) (container.getWidth() * 0.96f); int maxLineWidth = (int) (displayContainer.width * 0.96f);
for (int i = 0; i < title.length; i++) { for (String aTitle : title) {
// wrap text if too long // wrap text if too long
if (Fonts.LARGE.getWidth(title[i]) > maxLineWidth) { if (Fonts.LARGE.getWidth(aTitle) > maxLineWidth) {
List<String> list = Fonts.wrap(Fonts.LARGE, title[i], maxLineWidth, false); List<String> list = Fonts.wrap(Fonts.LARGE, aTitle, maxLineWidth, false);
actualTitle.addAll(list); actualTitle.addAll(list);
} else } else {
actualTitle.add(title[i]); actualTitle.add(aTitle);
}
} }
} }
/** /**
* Processes a state exit request (via override). * Processes a state exit request (via override).
* @param container the game container
* @param game the game
*/ */
public void leave(GameContainer container, StateBasedGame game) {} public void leave() {}
}; }
/** Button types. */ /** Button types. */
private enum Button { private enum Button {
YES ("Yes", Color.green) { YES ("Yes", Color.green) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
container.exit(); displayContainer.exitRequested = true;
} }
}, },
NO ("No", Color.red) { NO ("No", Color.red) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
game.enterState(Opsu.STATE_MAINMENU, new EmptyTransition(), new FadeInTransition()); displayContainer.switchState(MainMenu.class);
} }
}, },
CLEAR_SCORES ("Clear local scores", Color.magenta) { CLEAR_SCORES ("Clear local scores", Color.magenta) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
BeatmapSetNode node = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getNode(); BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode();
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).doStateActionOnLoad(MenuState.BEATMAP, node); instanceContainer.provide(SongMenu.class).doStateActionOnLoad(MenuState.BEATMAP, node);
game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); displayContainer.switchState(SongMenu.class);
} }
}, },
FAVORITE_ADD ("Add to Favorites", Color.blue) { FAVORITE_ADD ("Add to Favorites", Color.blue) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
BeatmapSetNode node = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getNode(); BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode();
node.getBeatmapSet().setFavorite(true); node.getBeatmapSet().setFavorite(true);
game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); displayContainer.switchState(SongMenu.class);
} }
}, },
FAVORITE_REMOVE ("Remove from Favorites", Color.blue) { FAVORITE_REMOVE ("Remove from Favorites", Color.blue) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
BeatmapSetNode node = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getNode(); BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode();
node.getBeatmapSet().setFavorite(false); node.getBeatmapSet().setFavorite(false);
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).doStateActionOnLoad(MenuState.BEATMAP_FAVORITE); instanceContainer.provide(SongMenu.class).doStateActionOnLoad(MenuState.BEATMAP_FAVORITE);
game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); displayContainer.switchState(SongMenu.class);
} }
}, },
DELETE ("Delete...", Color.red) { DELETE ("Delete...", Color.red) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
BeatmapSetNode node = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getNode(); BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode();
MenuState ms = (node.beatmapIndex == -1 || node.getBeatmapSet().size() == 1) ? MenuState ms = (node.beatmapIndex == -1 || node.getBeatmapSet().size() == 1) ?
MenuState.BEATMAP_DELETE_CONFIRM : MenuState.BEATMAP_DELETE_SELECT; MenuState.BEATMAP_DELETE_CONFIRM : MenuState.BEATMAP_DELETE_SELECT;
((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(ms, node); instanceContainer.provide(ButtonMenu.class).setMenuState(ms, node);
game.enterState(Opsu.STATE_BUTTONMENU); displayContainer.switchState(ButtonMenu.class);
} }
}, },
CANCEL ("Cancel", Color.gray) { CANCEL ("Cancel", Color.gray) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); displayContainer.switchState(SongMenu.class);
} }
}, },
DELETE_CONFIRM ("Yes, delete this beatmap!", Color.red) { DELETE_CONFIRM ("Yes, delete this beatmap!", Color.red) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
BeatmapSetNode node = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getNode(); BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode();
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).doStateActionOnLoad(MenuState.BEATMAP_DELETE_CONFIRM, node); instanceContainer.provide(SongMenu.class).doStateActionOnLoad(MenuState.BEATMAP_DELETE_CONFIRM, node);
game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); displayContainer.switchState(SongMenu.class);
} }
}, },
DELETE_GROUP ("Yes, delete all difficulties!", Color.red) { DELETE_GROUP ("Yes, delete all difficulties!", Color.red) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
DELETE_CONFIRM.click(container, game); DELETE_CONFIRM.click();
} }
}, },
DELETE_SONG ("Yes, but only this difficulty", Color.red) { DELETE_SONG ("Yes, but only this difficulty", Color.red) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
BeatmapSetNode node = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getNode(); BeatmapSetNode node = instanceContainer.provide(ButtonMenu.class).getNode();
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).doStateActionOnLoad(MenuState.BEATMAP_DELETE_SELECT, node); instanceContainer.provide(SongMenu.class).doStateActionOnLoad(MenuState.BEATMAP_DELETE_SELECT, node);
game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); displayContainer.switchState(SongMenu.class);
} }
}, },
CANCEL_DELETE ("Nooooo! I didn't mean to!", Color.gray) { CANCEL_DELETE ("Nooooo! I didn't mean to!", Color.gray) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
CANCEL.click(container, game); CANCEL.click();
} }
}, },
RELOAD_CONFIRM ("Let's do it!", Color.green) { RELOAD_CONFIRM ("Let's do it!", Color.green) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).doStateActionOnLoad(MenuState.RELOAD); instanceContainer.provide(SongMenu.class).doStateActionOnLoad(MenuState.RELOAD);
game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); displayContainer.switchState(SongMenu.class);
} }
}, },
RELOAD_CANCEL ("Cancel", Color.red) { RELOAD_CANCEL ("Cancel", Color.red) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
CANCEL.click(container, game); CANCEL.click();
} }
}, },
DELETE_SCORE ("Delete score", Color.green) { DELETE_SCORE ("Delete score", Color.green) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
ScoreData scoreData = ((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).getScoreData(); ScoreData scoreData = instanceContainer.provide(ButtonMenu.class).getScoreData();
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).doStateActionOnLoad(MenuState.SCORE, scoreData); instanceContainer.provide(SongMenu.class).doStateActionOnLoad(MenuState.SCORE, scoreData);
game.enterState(Opsu.STATE_SONGMENU, new EmptyTransition(), new FadeInTransition()); displayContainer.switchState(SongMenu.class);
} }
}, },
CLOSE ("Close", Color.gray) { CLOSE ("Close", Color.gray) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
CANCEL.click(container, game); CANCEL.click();
} }
}, },
RESET_MODS ("Reset All Mods", Color.red) { RESET_MODS ("Reset All Mods", Color.red) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click() {
SoundController.playSound(SoundEffect.MENUCLICK); SoundController.playSound(SoundEffect.MENUCLICK);
for (GameMod mod : GameMod.values()) { for (GameMod mod : GameMod.values()) {
if (mod.isActive()) if (mod.isActive())
@ -592,6 +565,9 @@ public class ButtonMenu extends BasicGameState {
} }
}; };
public static DisplayContainer displayContainer;
public static InstanceContainer instanceContainer;
/** The text to show on the button. */ /** The text to show on the button. */
private final String text; private final String text;
@ -620,10 +596,8 @@ public class ButtonMenu extends BasicGameState {
/** /**
* Processes a mouse click action (via override). * Processes a mouse click action (via override).
* @param container the game container
* @param game the game
*/ */
public void click(GameContainer container, StateBasedGame game) {} public void click() {}
} }
/** The current menu state. */ /** The current menu state. */
@ -635,98 +609,89 @@ public class ButtonMenu extends BasicGameState {
/** The score data to process in the state. */ /** The score data to process in the state. */
private ScoreData scoreData; private ScoreData scoreData;
// game-related variables public ButtonMenu(DisplayContainer displayContainer, InstanceContainer instanceContainer) {
private GameContainer container; super(displayContainer);
private StateBasedGame game; Button.displayContainer = MenuState.displayContainer = displayContainer;
private Input input; Button.instanceContainer = MenuState.instanceContainer = instanceContainer;
private final int state;
public ButtonMenu(int state) {
this.state = state;
} }
@Override @Override
public void init(GameContainer container, StateBasedGame game) public void revalidate() {
throws SlickException { super.revalidate();
this.container = container;
this.game = game;
this.input = container.getInput();
// initialize buttons // initialize buttons
Image button = GameImage.MENU_BUTTON_MID.getImage(); Image button = GameImage.MENU_BUTTON_MID.getImage();
button = button.getScaledCopy(container.getWidth() / 2, button.getHeight()); button = button.getScaledCopy(displayContainer.width / 2, button.getHeight());
Image buttonL = GameImage.MENU_BUTTON_LEFT.getImage(); Image buttonL = GameImage.MENU_BUTTON_LEFT.getImage();
Image buttonR = GameImage.MENU_BUTTON_RIGHT.getImage(); Image buttonR = GameImage.MENU_BUTTON_RIGHT.getImage();
for (MenuState ms : MenuState.values()) for (MenuState ms : MenuState.values()) {
ms.init(container, game, button, buttonL, buttonR); ms.revalidate(button, buttonL, buttonR);
}
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g)
throws SlickException {
g.setBackground(Color.black);
if (menuState != null)
menuState.draw(container, game, g);
}
@Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {
UI.update(delta);
MusicController.loopTrackIfEnded(false);
if (menuState != null)
menuState.update(container, delta, input.getMouseX(), input.getMouseY());
}
@Override
public int getID() { return state; }
@Override
public void mousePressed(int button, int x, int y) {
// check mouse button
if (button == Input.MOUSE_MIDDLE_BUTTON)
return;
if (menuState != null)
menuState.click(container, game, x, y);
}
@Override
public void mouseWheelMoved(int newValue) {
if (menuState != null)
menuState.scroll(container, game, newValue);
}
@Override
public void keyPressed(int key, char c) {
switch (key) {
case Input.KEY_ESCAPE:
if (menuState != null)
menuState.leave(container, game);
break;
case Input.KEY_F7:
// TODO
//Options.setNextFPS(displayContainer);
break;
case Input.KEY_F10:
Options.toggleMouseDisabled();
break;
case Input.KEY_F12:
Utils.takeScreenShot();
break;
default:
if (menuState != null)
menuState.keyPress(container, game, key, c);
break;
} }
} }
@Override @Override
public void enter(GameContainer container, StateBasedGame game) public void render(Graphics g) {
throws SlickException { super.render(g);
g.setBackground(Color.black);
if (menuState == null) {
return;
}
menuState.render(g);
}
@Override
public void preRenderUpdate() {
super.preRenderUpdate();
UI.update(displayContainer.renderDelta);
MusicController.loopTrackIfEnded(false);
menuState.preRenderUpdate();
}
@Override
public boolean mousePressed(int button, int x, int y) {
if (button == Input.MOUSE_MIDDLE_BUTTON) {
return false;
}
menuState.mousePressed(x, y);
return true;
}
@Override
public boolean mouseWheelMoved(int newValue) {
menuState.mouseWheelMoved(newValue);
return true;
}
@Override
public boolean keyPressed(int key, char c) {
switch (key) {
case Input.KEY_ESCAPE:
menuState.leave();
return true;
case Input.KEY_F7:
// TODO
//Options.setNextFPS(displayContainer);
return true;
case Input.KEY_F10:
Options.toggleMouseDisabled();
return true;
case Input.KEY_F12:
Utils.takeScreenShot();
return true;
}
menuState.keyPressed(key, c);
return true;
}
@Override
public void enter() {
super.enter();
UI.enter(); UI.enter();
if (menuState != null) menuState.enter();
menuState.enter(container, game);
} }
/** /**

View File

@ -20,7 +20,6 @@ package itdelatrisu.opsu.states;
import itdelatrisu.opsu.ErrorHandler; import itdelatrisu.opsu.ErrorHandler;
import itdelatrisu.opsu.GameImage; import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Opsu;
import itdelatrisu.opsu.Options; import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.Utils; import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.audio.MusicController; import itdelatrisu.opsu.audio.MusicController;
@ -47,8 +46,6 @@ import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics; import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image; import org.newdawn.slick.Image;
import org.newdawn.slick.Input; import org.newdawn.slick.Input;
import org.newdawn.slick.state.transition.EasedFadeOutTransition;
import org.newdawn.slick.state.transition.FadeInTransition;
import yugecin.opsudance.core.DisplayContainer; import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.inject.InstanceContainer; import yugecin.opsudance.core.inject.InstanceContainer;
import yugecin.opsudance.core.state.BaseOpsuState; import yugecin.opsudance.core.state.BaseOpsuState;
@ -647,9 +644,8 @@ public class MainMenu extends BaseOpsuState {
logoTimer = 0; logoTimer = 0;
break; break;
} }
// TODO instanceContainer.provide(ButtonMenu.class).setMenuState(MenuState.EXIT);
//((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.EXIT); displayContainer.switchState(ButtonMenu.class);
//game.enterState(Opsu.STATE_BUTTONMENU);
return true; return true;
case Input.KEY_P: case Input.KEY_P:
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);

View File

@ -783,7 +783,7 @@ public class SongMenu extends BaseOpsuState {
MenuState state = focusNode.getBeatmapSet().isFavorite() ? MenuState state = focusNode.getBeatmapSet().isFavorite() ?
MenuState.BEATMAP_FAVORITE : MenuState.BEATMAP; MenuState.BEATMAP_FAVORITE : MenuState.BEATMAP;
instanceContainer.provide(ButtonMenu.class).setMenuState(state, focusNode); instanceContainer.provide(ButtonMenu.class).setMenuState(state, focusNode);
// TODO d displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(ButtonMenu.class);
} }
return; return;
} }
@ -1053,7 +1053,7 @@ public class SongMenu extends BaseOpsuState {
} else { } else {
// score management // score management
instanceContainer.provide(ButtonMenu.class).setMenuState(MenuState.SCORE, focusScores[rank]); instanceContainer.provide(ButtonMenu.class).setMenuState(MenuState.SCORE, focusScores[rank]);
// TODO d displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(ButtonMenu.class);
} }
return true; return true;
} }
@ -1084,18 +1084,17 @@ public class SongMenu extends BaseOpsuState {
searchTimer = SEARCH_DELAY; searchTimer = SEARCH_DELAY;
searchTransitionTimer = 0; searchTransitionTimer = 0;
searchResultString = null; searchResultString = null;
} else { } else*/ {
// return to main menu // return to main menu
SoundController.playSound(SoundEffect.MENUBACK); SoundController.playSound(SoundEffect.MENUBACK);
((MainMenu) game.getState(Opsu.STATE_MAINMENU)).reset(); instanceContainer.provide(MainMenu.class).reset(); // TODO d is this needed
game.enterState(Opsu.STATE_MAINMENU, new EasedFadeOutTransition(), new FadeInTransition()); displayContainer.switchState(MainMenu.class);
} }
*/
return true; return true;
case Input.KEY_F1: case Input.KEY_F1:
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
instanceContainer.provide(ButtonMenu.class).setMenuState(MenuState.MODS); instanceContainer.provide(ButtonMenu.class).setMenuState(MenuState.MODS);
// TODO d displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(ButtonMenu.class);
return true; return true;
case Input.KEY_F2: case Input.KEY_F2:
if (focusNode == null) if (focusNode == null)
@ -1124,7 +1123,7 @@ public class SongMenu extends BaseOpsuState {
MenuState state = focusNode.getBeatmapSet().isFavorite() ? MenuState state = focusNode.getBeatmapSet().isFavorite() ?
MenuState.BEATMAP_FAVORITE : MenuState.BEATMAP; MenuState.BEATMAP_FAVORITE : MenuState.BEATMAP;
instanceContainer.provide(ButtonMenu.class).setMenuState(state, focusNode); instanceContainer.provide(ButtonMenu.class).setMenuState(state, focusNode);
// TODO d displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(ButtonMenu.class);
return true; return true;
case Input.KEY_F5: case Input.KEY_F5:
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUHIT);
@ -1132,7 +1131,7 @@ public class SongMenu extends BaseOpsuState {
reloadBeatmaps(false); reloadBeatmaps(false);
else { else {
instanceContainer.provide(ButtonMenu.class).setMenuState(MenuState.RELOAD); instanceContainer.provide(ButtonMenu.class).setMenuState(MenuState.RELOAD);
// TODO d displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(ButtonMenu.class);
} }
return true; return true;
case Input.KEY_DELETE: case Input.KEY_DELETE:
@ -1143,7 +1142,7 @@ public class SongMenu extends BaseOpsuState {
MenuState ms = (focusNode.beatmapIndex == -1 || focusNode.getBeatmapSet().size() == 1) ? MenuState ms = (focusNode.beatmapIndex == -1 || focusNode.getBeatmapSet().size() == 1) ?
MenuState.BEATMAP_DELETE_CONFIRM : MenuState.BEATMAP_DELETE_SELECT; MenuState.BEATMAP_DELETE_CONFIRM : MenuState.BEATMAP_DELETE_SELECT;
instanceContainer.provide(ButtonMenu.class).setMenuState(ms, focusNode); instanceContainer.provide(ButtonMenu.class).setMenuState(ms, focusNode);
// TODO d displayContainer.switchState(ButtonMenu.class); displayContainer.switchState(ButtonMenu.class);
} }
return true; return true;
case Input.KEY_F7: case Input.KEY_F7:

View File

@ -17,6 +17,7 @@
*/ */
package yugecin.opsudance.core.inject; package yugecin.opsudance.core.inject;
import itdelatrisu.opsu.states.ButtonMenu;
import itdelatrisu.opsu.states.MainMenu; import itdelatrisu.opsu.states.MainMenu;
import itdelatrisu.opsu.states.SongMenu; import itdelatrisu.opsu.states.SongMenu;
import itdelatrisu.opsu.states.Splash; import itdelatrisu.opsu.states.Splash;
@ -56,6 +57,7 @@ public class OpsuDanceInjector extends Injector {
bind(Splash.class).asEagerSingleton(); bind(Splash.class).asEagerSingleton();
bind(MainMenu.class).asEagerSingleton(); bind(MainMenu.class).asEagerSingleton();
bind(ButtonMenu.class).asEagerSingleton();
bind(SongMenu.class).asEagerSingleton(); bind(SongMenu.class).asEagerSingleton();
} }