2014-07-16 22:01:36 +02:00
|
|
|
/*
|
|
|
|
* opsu! - an open-source osu! client
|
2015-01-16 18:05:44 +01:00
|
|
|
* Copyright (C) 2014, 2015 Jeffrey Han
|
2014-07-16 22:01:36 +02:00
|
|
|
*
|
|
|
|
* opsu! is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* opsu! is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with opsu!. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package itdelatrisu.opsu;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
import org.newdawn.slick.Image;
|
2015-01-16 08:26:13 +01:00
|
|
|
import org.newdawn.slick.Input;
|
2014-07-16 22:01:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Game mods.
|
|
|
|
*/
|
|
|
|
public enum GameMod {
|
2015-01-30 09:45:06 +01:00
|
|
|
EASY (0, GameImage.MOD_EASY, "EZ", 2, Input.KEY_Q, 0.5f,
|
|
|
|
"Reduces overall difficulty - larger circles, more forgiving HP drain, less accuracy required."),
|
|
|
|
NO_FAIL (1, GameImage.MOD_NO_FAIL, "NF", 1, Input.KEY_W, 0.5f,
|
|
|
|
"You can't fail. No matter what."),
|
|
|
|
HARD_ROCK (2, GameImage.MOD_HARD_ROCK, "HR", 16, Input.KEY_A, 1.06f,
|
|
|
|
"Everything just got a bit harder..."),
|
|
|
|
SUDDEN_DEATH (3, GameImage.MOD_SUDDEN_DEATH, "SD", 32, Input.KEY_S,
|
|
|
|
"Miss a note and fail."),
|
|
|
|
SPUN_OUT (4, GameImage.MOD_SPUN_OUT, "SO", 4096, Input.KEY_V, 0.9f,
|
|
|
|
"Spinners will be automatically completed."),
|
|
|
|
AUTO (5, GameImage.MOD_AUTO, "", 2048, Input.KEY_B,
|
|
|
|
"Watch a perfect automated play through the song.");
|
|
|
|
// HALF_TIME (6, GameImage.MOD_HALF_TIME, "HT", 256, Input.KEY_E, 0.3f,
|
|
|
|
// "Less zoom."),
|
|
|
|
// DOUBLE_TIME (7, GameImage.MOD_DOUBLE_TIME, "DT", 64, Input.KEY_D, 1.12f,
|
|
|
|
// "Zoooooooooom."),
|
|
|
|
// HIDDEN (8, GameImage.MOD_HIDDEN, "HD", 8, Input.KEY_F, 1.06f,
|
|
|
|
// "Play with no approach circles and fading notes for a slight score advantage."),
|
|
|
|
// FLASHLIGHT (9, GameImage.MOD_FLASHLIGHT, "FL", 1024, Input.KEY_G, 1.12f,
|
|
|
|
// "Restricted view area.");
|
2014-07-16 22:01:36 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The ID of the mod (used for positioning). */
|
2014-07-16 22:01:36 +02:00
|
|
|
private int id;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The file name of the mod image. */
|
2015-01-21 01:01:18 +01:00
|
|
|
private GameImage image;
|
2014-07-16 22:01:36 +02:00
|
|
|
|
2015-01-28 09:47:24 +01:00
|
|
|
/** The abbreviation for the mod. */
|
|
|
|
private String abbrev;
|
|
|
|
|
|
|
|
/** Bit value associated with the mod. */
|
|
|
|
private int bit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The shortcut key associated with the mod.
|
|
|
|
* See the osu! API: https://github.com/peppy/osu-api/wiki#mods
|
|
|
|
*/
|
2015-01-16 08:26:13 +01:00
|
|
|
private int key;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The score multiplier. */
|
2015-01-11 06:29:26 +01:00
|
|
|
private float multiplier;
|
|
|
|
|
2015-01-30 09:45:06 +01:00
|
|
|
/** The description of the mod. */
|
|
|
|
private String description;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Whether or not this mod is active. */
|
2014-07-16 22:01:36 +02:00
|
|
|
private boolean active = false;
|
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** The button containing the mod image (displayed in OptionsMenu screen). */
|
2014-12-30 06:00:58 +01:00
|
|
|
private MenuButton button;
|
2014-07-16 22:01:36 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Total number of mods. */
|
|
|
|
public static final int SIZE = values().length;
|
2014-07-16 22:01:36 +02:00
|
|
|
|
2015-01-22 06:44:45 +01:00
|
|
|
/** Array of GameMod objects in reverse order. */
|
|
|
|
public static final GameMod[] VALUES_REVERSED;
|
|
|
|
static {
|
|
|
|
VALUES_REVERSED = values();
|
|
|
|
Collections.reverse(Arrays.asList(VALUES_REVERSED));
|
2014-07-16 22:01:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* @param id the ID of the mod (for positioning).
|
2015-01-21 01:01:18 +01:00
|
|
|
* @param image the GameImage
|
2015-01-28 09:47:24 +01:00
|
|
|
* @param abbrev the two-letter abbreviation
|
|
|
|
* @param bit the bit
|
2015-01-16 08:26:13 +01:00
|
|
|
* @param key the shortcut key
|
2015-01-30 09:45:06 +01:00
|
|
|
* @param description the description
|
2014-07-16 22:01:36 +02:00
|
|
|
*/
|
2015-01-30 09:45:06 +01:00
|
|
|
GameMod(int id, GameImage image, String abbrev, int bit, int key, String description) {
|
2014-07-16 22:01:36 +02:00
|
|
|
this.id = id;
|
2015-01-21 01:01:18 +01:00
|
|
|
this.image = image;
|
2015-01-28 09:47:24 +01:00
|
|
|
this.abbrev = abbrev;
|
|
|
|
this.bit = bit;
|
2015-01-16 08:26:13 +01:00
|
|
|
this.key = key;
|
2015-01-11 06:29:26 +01:00
|
|
|
this.multiplier = 1f;
|
2015-01-30 09:45:06 +01:00
|
|
|
this.description = description;
|
2015-01-11 06:29:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
* @param id the ID of the mod (for positioning).
|
2015-01-21 01:01:18 +01:00
|
|
|
* @param image the GameImage
|
2015-01-28 09:47:24 +01:00
|
|
|
* @param abbrev the two-letter abbreviation
|
|
|
|
* @param bit the bit
|
2015-01-16 08:26:13 +01:00
|
|
|
* @param key the shortcut key
|
2015-01-11 06:29:26 +01:00
|
|
|
* @param multiplier the score multiplier
|
2015-01-30 09:45:06 +01:00
|
|
|
* @param description the description
|
2015-01-11 06:29:26 +01:00
|
|
|
*/
|
2015-01-30 09:45:06 +01:00
|
|
|
GameMod(int id, GameImage image, String abbrev, int bit, int key, float multiplier, String description) {
|
2015-01-11 06:29:26 +01:00
|
|
|
this.id = id;
|
2015-01-21 01:01:18 +01:00
|
|
|
this.image = image;
|
2015-01-28 09:47:24 +01:00
|
|
|
this.abbrev = abbrev;
|
|
|
|
this.bit = bit;
|
2015-01-16 08:26:13 +01:00
|
|
|
this.key = key;
|
2015-01-11 06:29:26 +01:00
|
|
|
this.multiplier = multiplier;
|
2015-01-30 09:45:06 +01:00
|
|
|
this.description = description;
|
2014-07-16 22:01:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the game mod.
|
|
|
|
* @param width the container width
|
|
|
|
* @param height the container height
|
|
|
|
*/
|
|
|
|
public void init(int width, int height) {
|
2015-01-21 01:01:18 +01:00
|
|
|
Image img = image.getImage();
|
|
|
|
|
|
|
|
// find coordinates
|
|
|
|
float offsetX = img.getWidth() * 1.5f;
|
|
|
|
float x = (width / 2f) - (offsetX * SIZE / 2.75f);
|
|
|
|
float y = (height * 0.8f) + (img.getHeight() / 2);
|
|
|
|
|
|
|
|
// create button
|
|
|
|
this.button = new MenuButton(img, x + (offsetX * id), y);
|
2015-02-02 06:15:16 +01:00
|
|
|
this.button.setHoverExpand(1.15f);
|
2015-01-29 07:50:26 +01:00
|
|
|
|
|
|
|
// reset state
|
|
|
|
this.active = false;
|
2014-07-16 22:01:36 +02:00
|
|
|
}
|
|
|
|
|
2015-01-28 09:47:24 +01:00
|
|
|
/**
|
|
|
|
* Returns the abbreviated name of the mod.
|
|
|
|
* @return the two-letter abbreviation
|
|
|
|
*/
|
|
|
|
public String getAbbreviation() { return abbrev; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the bit associated with the mod.
|
|
|
|
* @return the bit
|
|
|
|
*/
|
|
|
|
public int getBit() { return bit; }
|
|
|
|
|
2015-01-16 08:26:13 +01:00
|
|
|
/**
|
|
|
|
* Returns the shortcut key for the mod.
|
|
|
|
* @return the key
|
|
|
|
* @see org.newdawn.slick.Input
|
|
|
|
*/
|
|
|
|
public int getKey() { return key; }
|
|
|
|
|
2015-01-11 06:29:26 +01:00
|
|
|
/**
|
|
|
|
* Returns the score multiplier for the mod.
|
|
|
|
* @return the multiplier
|
|
|
|
*/
|
|
|
|
public float getMultiplier() { return multiplier; }
|
|
|
|
|
2015-01-30 09:45:06 +01:00
|
|
|
/**
|
|
|
|
* Returns a description of the mod.
|
|
|
|
* @return the description
|
|
|
|
*/
|
|
|
|
public String getDescription() { return description; }
|
|
|
|
|
2014-07-16 22:01:36 +02:00
|
|
|
/**
|
|
|
|
* Toggles the active status of the mod.
|
|
|
|
* @param checkInverse if true, perform checks for mutual exclusivity
|
|
|
|
*/
|
|
|
|
public void toggle(boolean checkInverse) {
|
|
|
|
active = !active;
|
|
|
|
|
|
|
|
if (checkInverse) {
|
|
|
|
if (AUTO.isActive()) {
|
|
|
|
if (this == AUTO) {
|
|
|
|
if (SPUN_OUT.isActive())
|
|
|
|
SPUN_OUT.toggle(false);
|
|
|
|
if (SUDDEN_DEATH.isActive())
|
|
|
|
SUDDEN_DEATH.toggle(false);
|
|
|
|
} else if (this == SPUN_OUT || this == SUDDEN_DEATH) {
|
|
|
|
if (active)
|
|
|
|
toggle(false);
|
|
|
|
}
|
2014-07-16 22:56:23 +02:00
|
|
|
}
|
|
|
|
if (SUDDEN_DEATH.isActive() && NO_FAIL.isActive()) {
|
2014-07-16 22:01:36 +02:00
|
|
|
if (this == SUDDEN_DEATH)
|
|
|
|
NO_FAIL.toggle(false);
|
|
|
|
else
|
|
|
|
SUDDEN_DEATH.toggle(false);
|
|
|
|
}
|
2014-07-16 22:56:23 +02:00
|
|
|
if (EASY.isActive() && HARD_ROCK.isActive()) {
|
|
|
|
if (this == EASY)
|
|
|
|
HARD_ROCK.toggle(false);
|
|
|
|
else
|
|
|
|
EASY.toggle(false);
|
|
|
|
}
|
2014-07-16 22:01:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether or not the mod is active.
|
|
|
|
* @return true if active
|
|
|
|
*/
|
|
|
|
public boolean isActive() { return active; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the image associated with the mod.
|
|
|
|
* @return the associated image
|
|
|
|
*/
|
2015-01-21 01:01:18 +01:00
|
|
|
public Image getImage() { return image.getImage(); }
|
2014-07-16 22:01:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws the game mod.
|
|
|
|
*/
|
2015-01-29 07:50:26 +01:00
|
|
|
public void draw() {
|
|
|
|
if (!active)
|
|
|
|
button.getImage().setAlpha(0.5f);
|
|
|
|
button.draw();
|
|
|
|
button.getImage().setAlpha(1.0f);
|
|
|
|
}
|
2014-07-16 22:01:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the coordinates are within the image bounds.
|
|
|
|
* @param x the x coordinate
|
|
|
|
* @param y the y coordinate
|
|
|
|
* @return true if within bounds
|
|
|
|
*/
|
|
|
|
public boolean contains(float x, float y) { return button.contains(x, y); }
|
2014-12-24 05:41:37 +01:00
|
|
|
|
|
|
|
/**
|
2015-02-02 06:15:16 +01:00
|
|
|
* Resets the hover fields for the button.
|
2014-12-24 05:41:37 +01:00
|
|
|
*/
|
2015-02-02 06:15:16 +01:00
|
|
|
public void resetHover() { button.resetHover(); }
|
2014-12-24 05:41:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the scale of the button depending on whether or not the cursor
|
|
|
|
* is hovering over the button.
|
|
|
|
* @param delta the delta interval
|
|
|
|
* @param x the x coordinate
|
|
|
|
* @param y the y coordinate
|
|
|
|
*/
|
|
|
|
public void hoverUpdate(int delta, float x, float y) { button.hoverUpdate(delta, x, y); }
|
2014-07-16 22:01:36 +02:00
|
|
|
}
|