Added a separate Game Mods menu.

- Replaces the mods being shown in the options menu.
- Added all the (base) mod icons to the menu, with the unimplemented ones grayed out.
- Added a rotation effect to MenuButton, and now multiple effects can be set at once.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-02-16 17:53:24 -05:00
parent 329d54c230
commit 69f5aa5748
9 changed files with 471 additions and 232 deletions

View File

@@ -19,6 +19,7 @@
package itdelatrisu.opsu.states;
import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.GameMod;
import itdelatrisu.opsu.MenuButton;
import itdelatrisu.opsu.Opsu;
import itdelatrisu.opsu.OsuGroupList;
@@ -121,6 +122,95 @@ public class ButtonMenu extends BasicGameState {
public void leave(GameContainer container, StateBasedGame game) {
Button.CLOSE.click(container, game);
}
},
MODS (new Button[] { Button.RESET_MODS, Button.CLOSE }) {
@Override
public String[] getTitle(GameContainer container, StateBasedGame game) {
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."
};
}
@Override
protected float getBaseY(GameContainer container, StateBasedGame game) {
return container.getHeight() * 2f / 3;
}
@Override
public void enter(GameContainer container, StateBasedGame game) {
super.enter(container, game);
for (GameMod mod : GameMod.values())
mod.resetHover();
}
@Override
public void leave(GameContainer container, StateBasedGame game) {
Button.CLOSE.click(container, game);
}
@Override
public void draw(GameContainer container, StateBasedGame game, Graphics g) {
super.draw(container, game, g);
int width = container.getWidth();
int height = container.getHeight();
// score multiplier (TODO: fade in color changes)
float mult = GameMod.getScoreMultiplier();
String multString = String.format("Score Multiplier: %.2fx", mult);
Color multColor = (mult == 1f) ? Color.white : (mult > 1f) ? Color.green : Color.red;
float multY = Utils.FONT_LARGE.getLineHeight() * 2 + height * 0.06f;
Utils.FONT_LARGE.drawString(
(width - Utils.FONT_LARGE.getWidth(multString)) / 2f,
multY, multString, multColor);
// category text
for (GameMod.Category category : GameMod.Category.values()) {
Utils.FONT_LARGE.drawString(category.getX(),
category.getY() - Utils.FONT_LARGE.getLineHeight() / 2f,
category.getName(), category.getColor());
}
// buttons (TODO: draw descriptions when hovering)
for (GameMod mod : GameMod.values())
mod.draw();
}
@Override
public void update(GameContainer container, int delta, int mouseX, int mouseY) {
super.update(container, delta, mouseX, mouseY);
for (GameMod mod : GameMod.values()) {
if (mod.isActive())
mod.hoverUpdate(delta, mod.getButtonX(), mod.getButtonY());
else
mod.hoverUpdate(delta, -1, -1);
}
}
@Override
public void keyPress(GameContainer container, StateBasedGame game, int key, char c) {
super.keyPress(container, game, key, c);
for (GameMod mod : GameMod.values()) {
if (key == mod.getKey()) {
mod.toggle(true);
break;
}
}
}
@Override
public void click(GameContainer container, StateBasedGame game, int cx, int cy) {
super.click(container, game, cx, cy);
for (GameMod mod : GameMod.values()) {
if (mod.contains(cx, cy)) {
boolean prevState = mod.isActive();
mod.toggle(true);
if (mod.isActive() != prevState)
SoundController.playSound(SoundEffect.MENUCLICK);
return;
}
}
}
};
/** The buttons in the state. */
@@ -153,23 +243,29 @@ public class ButtonMenu extends BasicGameState {
*/
public void init(GameContainer container, StateBasedGame game, Image button, Image buttonL, Image buttonR) {
float center = container.getWidth() / 2f;
float centerOffset = container.getWidth() * OFFSET_WIDTH_RATIO;
float baseY = container.getHeight() * 0.2f;
baseY += ((getTitle(container, game).length - 1) * Utils.FONT_LARGE.getLineHeight());
float baseY = getBaseY(container, game);
float offsetY = button.getHeight() * 1.25f;
menuButtons = new MenuButton[buttons.length];
for (int i = 0; i < buttons.length; i++) {
MenuButton b = new MenuButton(button, buttonL, buttonR,
center + ((i % 2 == 0) ? centerOffset * -1 : centerOffset),
baseY + (i * offsetY));
b.setText(String.format("%d. %s", i + 1, buttons[i].getText()),
Utils.FONT_XLARGE, Color.white);
MenuButton b = new MenuButton(button, buttonL, buttonR, center, baseY + (i * offsetY));
b.setText(String.format("%d. %s", i + 1, buttons[i].getText()), Utils.FONT_XLARGE, Color.white);
b.setHoverFade();
menuButtons[i] = b;
}
}
/**
* Returns the base Y coordinate for the buttons.
* @param container the game container
* @param game the game
*/
protected float getBaseY(GameContainer container, StateBasedGame game) {
float baseY = container.getHeight() * 0.2f;
baseY += ((getTitle(container, game).length - 1) * Utils.FONT_LARGE.getLineHeight());
return baseY;
}
/**
* Draws the title and buttons to the graphics context.
* @param container the game container
@@ -231,13 +327,14 @@ public class ButtonMenu extends BasicGameState {
}
/**
* Processes a key press action (numeric digits only).
* Processes a key press action.
* @param container the game container
* @param game the game
* @param digit the digit pressed
* @param key the key code that was pressed (see {@link org.newdawn.slick.Input})
* @param c the character of the key that was pressed
*/
public void keyPress(GameContainer container, StateBasedGame game, int digit) {
int index = digit - 1;
public void keyPress(GameContainer container, StateBasedGame game, int key, char c) {
int index = Character.getNumericValue(c) - 1;
if (index >= 0 && index < buttons.length)
buttons[index].click(container, game);
}
@@ -384,6 +481,16 @@ public class ButtonMenu extends BasicGameState {
public void click(GameContainer container, StateBasedGame game) {
CANCEL.click(container, game);
}
},
RESET_MODS ("Reset All Mods", Color.red) {
@Override
public void click(GameContainer container, StateBasedGame game) {
SoundController.playSound(SoundEffect.MENUHIT);
for (GameMod mod : GameMod.values()) {
if (mod.isActive())
mod.toggle(false);
}
}
};
/** The text to show on the button. */
@@ -500,7 +607,7 @@ public class ButtonMenu extends BasicGameState {
break;
default:
if (menuState != null)
menuState.keyPress(container, game, Character.getNumericValue(c));
menuState.keyPress(container, game, key, c);
break;
}
}

View File

@@ -229,6 +229,7 @@ public class DownloadsMenu extends BasicGameState {
// search
g.setColor(Color.white);
g.setLineWidth(2f);
search.render(container, g);
Utils.FONT_BOLD.drawString(
search.getX() + search.getWidth() * 0.01f, search.getY() + search.getHeight() * 1.3f,

View File

@@ -19,7 +19,6 @@
package itdelatrisu.opsu.states;
import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.GameMod;
import itdelatrisu.opsu.MenuButton;
import itdelatrisu.opsu.Opsu;
import itdelatrisu.opsu.Options;
@@ -171,10 +170,6 @@ public class OptionsMenu extends BasicGameState {
int width = container.getWidth();
int height = container.getHeight();
// game option coordinate modifiers
textY = 20 + (Utils.FONT_XLARGE.getLineHeight() * 3 / 2);
offsetY = (int) (((height * 0.8f) - textY) / maxOptionsScreen);
// option tabs
Image tabImage = GameImage.MENU_TAB.getImage();
int subtextWidth = Utils.FONT_DEFAULT.getWidth("Click or drag an option to change it.");
@@ -184,6 +179,10 @@ public class OptionsMenu extends BasicGameState {
((width - subtextWidth - tabImage.getWidth()) / 2) / OptionTab.SIZE);
for (OptionTab tab : OptionTab.values())
tab.button = new MenuButton(tabImage, tabX + (tab.ordinal() * tabOffset), tabY);
// game option coordinate modifiers
textY = (int) (tabY + tabImage.getHeight());
offsetY = (height - textY - GameImage.MENU_BACK.getImage().getHeight()) / maxOptionsScreen;
}
@Override
@@ -232,21 +231,6 @@ public class OptionsMenu extends BasicGameState {
g.drawLine(0, lineY, width, lineY);
g.resetLineWidth();
// game mods
Utils.FONT_LARGE.drawString(width / 30, height * 0.8f, "Game Mods:", Color.white);
boolean descDrawn = false;
for (GameMod mod : GameMod.values()) {
mod.draw();
if (!descDrawn && mod.contains(mouseX, mouseY)) {
Utils.FONT_DEFAULT.drawString(
(width - Utils.FONT_DEFAULT.getWidth(mod.getDescription())) / 2,
height * 0.975f - Utils.FONT_DEFAULT.getLineHeight(),
mod.getDescription(), Color.white
);
descDrawn = true;
}
}
Utils.getBackButton().draw();
// key entry state
@@ -272,8 +256,6 @@ public class OptionsMenu extends BasicGameState {
Utils.updateVolumeDisplay(delta);
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
Utils.getBackButton().hoverUpdate(delta, mouseX, mouseY);
for (GameMod mod : GameMod.values())
mod.hoverUpdate(delta, mouseX, mouseY);
}
@Override
@@ -309,17 +291,6 @@ public class OptionsMenu extends BasicGameState {
}
}
// game mods
for (GameMod mod : GameMod.values()) {
if (mod.contains(x, y)) {
boolean prevState = mod.isActive();
mod.toggle(true);
if (mod.isActive() != prevState)
SoundController.playSound(SoundEffect.MENUCLICK);
return;
}
}
// options (click only)
GameOption option = getClickedOption(y);
if (option != GameOption.NULL)
@@ -400,15 +371,6 @@ public class OptionsMenu extends BasicGameState {
currentTab = currentTab.next();
SoundController.playSound(SoundEffect.MENUCLICK);
break;
default:
// check mod shortcut keys
for (GameMod mod : GameMod.values()) {
if (key == mod.getKey()) {
mod.toggle(true);
break;
}
}
break;
}
}
@@ -417,8 +379,6 @@ public class OptionsMenu extends BasicGameState {
throws SlickException {
currentTab = OptionTab.DISPLAY;
Utils.getBackButton().resetHover();
for (GameMod mod : GameMod.values())
mod.resetHover();
}
/**

View File

@@ -359,9 +359,8 @@ public class SongMenu extends BasicGameState {
}
// selection buttons
// TODO
// GameImage.SELECTION_MODS.getImage().drawCentered(selectModsButton.getX(), selectModsButton.getY());
// selectModsButton.draw();
GameImage.SELECTION_MODS.getImage().drawCentered(selectModsButton.getX(), selectModsButton.getY());
selectModsButton.draw();
GameImage.SELECTION_RANDOM.getImage().drawCentered(selectRandomButton.getX(), selectRandomButton.getY());
selectRandomButton.draw();
GameImage.SELECTION_OPTIONS.getImage().drawCentered(selectMapOptionsButton.getX(), selectMapOptionsButton.getY());
@@ -714,9 +713,9 @@ public class SongMenu extends BasicGameState {
}
break;
case Input.KEY_F1:
// TODO: mods menu
// SoundController.playSound(SoundEffect.MENUHIT);
// game.enterState();
SoundController.playSound(SoundEffect.MENUHIT);
((ButtonMenu) game.getState(Opsu.STATE_BUTTONMENU)).setMenuState(MenuState.MODS);
game.enterState(Opsu.STATE_BUTTONMENU);
break;
case Input.KEY_F2:
if (focusNode == null)