overlays, draw an optionmenu

This commit is contained in:
yugecin 2016-11-12 22:30:22 +01:00
parent a3659d7a7d
commit b584dcaf68
4 changed files with 260 additions and 0 deletions

View File

@ -62,6 +62,8 @@ public class Container extends AppGameContainer {
getDelta();
while (running())
gameLoop();
} catch(Exception e) {
e.printStackTrace();
} finally {
// destroy the game container
close_sub();

View File

@ -72,6 +72,7 @@ import org.newdawn.slick.state.transition.EasedFadeOutTransition;
import org.newdawn.slick.state.transition.EmptyTransition;
import org.newdawn.slick.state.transition.FadeInTransition;
import yugecin.opsudance.*;
import yugecin.opsudance.ui.SBOverlay;
/**
* "Game" state.
@ -271,10 +272,12 @@ public class Game extends BasicGameState {
private final int state;
private final Cursor mirrorCursor;
private final SBOverlay sbOverlay;
public Game(int state) {
this.state = state;
mirrorCursor = new Cursor(true);
sbOverlay = new SBOverlay();
}
@Override
@ -287,6 +290,8 @@ public class Game extends BasicGameState {
int width = container.getWidth();
int height = container.getHeight();
sbOverlay.init(input, width, height);
// create offscreen graphics
offscreen = new Image(width, height);
gOffscreen = offscreen.getGraphics();
@ -635,6 +640,8 @@ public class Game extends BasicGameState {
else
UI.draw(g);
sbOverlay.render(g);
if (!Dancer.hidewatermark) {
Fonts.SMALL.drawString(0.3f, 0.3f, "opsu!dance " + Updater.get().getCurrentVersion() + " by robin_be | https://github.com/yugecin/opsu-dance");
}
@ -647,6 +654,7 @@ public class Game extends BasicGameState {
Pippi.update(delta);
yugecin.opsudance.spinners.Spinner.update(delta);
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
sbOverlay.update(mouseX, mouseY);
skipButton.hoverUpdate(delta, mouseX, mouseY);
if (isReplay || GameMod.AUTO.isActive())
playbackSpeed.getButton().hoverUpdate(delta, mouseX, mouseY);
@ -924,6 +932,11 @@ public class Game extends BasicGameState {
@Override
public void keyPressed(int key, char c) {
if (sbOverlay.keyPressed(key)) {
return;
}
int trackPosition = MusicController.getPosition();
int mouseX = input.getMouseX();
int mouseY = input.getMouseY();
@ -1064,8 +1077,16 @@ public class Game extends BasicGameState {
}
}
@Override
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
sbOverlay.mouseDragged(oldx, oldy, newx, newy);
}
@Override
public void mousePressed(int button, int x, int y) {
if (sbOverlay.mousePressed(button, x, y)) {
return;
}
// watching replay
if (isReplay || GameMod.AUTO.isActive()) {
if (button == Input.MOUSE_MIDDLE_BUTTON)
@ -1369,6 +1390,8 @@ public class Game extends BasicGameState {
SoundController.mute(false);
}
sbOverlay.setGameObjects(gameObjects);
Pippi.reset();
mirrorFrom = 0;
mirrorTo = gameObjects.length;

View File

@ -0,0 +1,117 @@
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2016 yugecin
*
* opsu!dance 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!dance 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!dance. If not, see <http://www.gnu.org/licenses/>.
*/
package yugecin.opsudance.ui;
import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.ui.Colors;
import itdelatrisu.opsu.ui.Fonts;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
public class OptionsOverlay {
private int width;
private int height;
private static Options.GameOption[] options = new Options.GameOption[] {
Options.GameOption.DANCE_MOVER,
Options.GameOption.DANCE_MOVER_DIRECTION,
Options.GameOption.DANCE_SLIDER_MOVER_TYPE,
Options.GameOption.DANCE_SPINNER,
Options.GameOption.DANCE_SPINNER_DELAY,
Options.GameOption.DANCE_LAZY_SLIDERS,
Options.GameOption.DANCE_CIRCLE_STREAMS,
Options.GameOption.DANCE_ONLY_CIRCLE_STACKS,
Options.GameOption.DANCE_CIRLCE_IN_SLOW_SLIDERS,
Options.GameOption.DANCE_CIRLCE_IN_LAZY_SLIDERS,
Options.GameOption.DANCE_MIRROR,
Options.GameOption.DANCE_DRAW_APPROACH,
Options.GameOption.DANCE_OBJECT_COLOR_OVERRIDE,
Options.GameOption.DANCE_OBJECT_COLOR_OVERRIDE_MIRRORED,
Options.GameOption.DANCE_RGB_OBJECT_INC,
Options.GameOption.DANCE_CURSOR_COLOR_OVERRIDE,
Options.GameOption.DANCE_CURSOR_MIRROR_COLOR_OVERRIDE,
Options.GameOption.DANCE_CURSOR_ONLY_COLOR_TRAIL,
Options.GameOption.DANCE_RGB_CURSOR_INC,
Options.GameOption.DANCE_CURSOR_TRAIL_OVERRIDE,
Options.GameOption.DANCE_REMOVE_BG,
Options.GameOption.DANCE_HIDE_OBJECTS,
Options.GameOption.DANCE_HIDE_UI,
Options.GameOption.DANCE_HIDE_WATERMARK,
Options.GameOption.PIPPI_ENABLE,
Options.GameOption.PIPPI_ANGLE_INC_MUL,
Options.GameOption.PIPPI_ANGLE_INC_MUL_SLIDER,
Options.GameOption.PIPPI_SLIDER_FOLLOW_EXPAND,
Options.GameOption.PIPPI_PREVENT_WOBBLY_STREAMS,
};
private int textHeight;
private Input input;
public void init(Input input, int width, int height) {
this.input = input;
this.width = width;
this.height = height;
textHeight = Fonts.SMALL.getLineHeight();
}
public void render(Graphics g) {
int hoverIdx = getOptionIdxAt(input.getMouseY());
float a = Color.black.a;
Color.black.a = 0.8f;
g.setColor(Color.black);
g.fillRect(0, 0, width, height);
Color.black.a = a;
for (int i = 0; i < options.length; i++) {
drawOption(g, options[i], i, hoverIdx == i);
}
}
// I know... kill me
private void drawOption(Graphics g, Options.GameOption option, int pos, boolean focus) {
float y = pos * (textHeight + 5);
Color color = (focus) ? Color.cyan : Color.white;
Fonts.MEDIUM.drawString(width / 6 * 2, y, option.getName(), color);
Fonts.MEDIUM.drawString(width / 3 * 2, y, option.getValueString(), color);
g.setColor(Colors.WHITE_ALPHA);
g.drawLine(0, y + textHeight + 3, width, y + textHeight + 3 + 1);
}
private int getOptionIdxAt(int y) {
int index = y / (textHeight + 5);
if (index >= options.length) {
return -1;
}
return index;
}
public void update(int mouseX, int mouseY) {
}
public boolean mousePressed(int button, int x, int y) {
return false;
}
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
}
}

View File

@ -0,0 +1,118 @@
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2016 yugecin
*
* opsu!dance 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!dance 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!dance. If not, see <http://www.gnu.org/licenses/>.
*/
package yugecin.opsudance.ui;
import itdelatrisu.opsu.audio.MusicController;
import itdelatrisu.opsu.objects.GameObject;
import itdelatrisu.opsu.ui.Fonts;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import java.util.HashMap;
public class SBOverlay {
public static boolean isActive = true;
private boolean hide;
private boolean menu;
private int width;
private int height;
private int speed;
private GameObject[] gameObjects;
private HashMap[] optionsMap;
private final OptionsOverlay options;
public SBOverlay() {
options = new OptionsOverlay();
}
public void init(Input input, int width, int height) {
this.width = width;
this.height = height;
speed = 10;
gameObjects = new GameObject[0];
options.init(input, width, height);
}
public void render(Graphics g) {
if (!isActive || hide) {
return;
}
int lh = Fonts.SMALL.getLineHeight();
Fonts.SMALL.drawString(10, height - 50, "speed: C " + (speed / 10f) + " V", Color.cyan);
Fonts.SMALL.drawString(10, height - 50 - lh, "Menu: N", Color.cyan);
Fonts.SMALL.drawString(10, height - 50 - lh * 2, "HIDE: H", Color.cyan);
if (menu) {
options.render(g);
}
}
public void update(int mouseX, int mouseY) {
if (!isActive) {
return;
}
if (menu) {
options.update(mouseX, mouseY);
}
}
public boolean keyPressed(int key) {
if (!isActive) {
return false;
}
if (key == Input.KEY_C && speed > 0) {
speed -= 1;
if (speed == 0) {
MusicController.pause();
} else {
MusicController.setPitch(speed / 10f);
}
} else if (key == Input.KEY_V && speed < 21) {
if (speed == 0) {
MusicController.resume();
}
speed += 1;
MusicController.setPitch(speed / 10f);
} else if (key == Input.KEY_H) {
hide = !hide;
} else if (key == Input.KEY_N) {
menu = !menu;
}
return false;
}
public void setGameObjects(GameObject[] gameObjects) {
if (this.gameObjects.length != gameObjects.length) {
optionsMap = new HashMap[gameObjects.length];
}
this.gameObjects = gameObjects;
}
public boolean mousePressed(int button, int x, int y) {
return menu && options.mousePressed(button, x, y);
}
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
if (menu) options.mouseDragged(oldx, oldy, newx, newy);
}
}