remove options as overlay state

This commit is contained in:
yugecin 2018-07-08 10:39:37 +02:00
parent 5b129c10dd
commit d7e59531ea
No known key found for this signature in database
GPG Key ID: 2C5AC035A7068E44
6 changed files with 184 additions and 41 deletions

View File

@ -712,6 +712,10 @@ public class Game extends ComplexOpsuState {
} else {
displayContainer.cursor.draw(Utils.isGameKeyPressed());
}
if (OPTION_DANCE_ENABLE_SB.state) {
optionsOverlay.render(g);
}
UI.draw(g);
@ -721,6 +725,10 @@ public class Game extends ComplexOpsuState {
@Override
public void preRenderUpdate() {
super.preRenderUpdate();
if (OPTION_DANCE_ENABLE_SB.state) {
optionsOverlay.preRenderUpdate();
}
int delta = renderDelta;
@ -1098,6 +1106,10 @@ public class Game extends ComplexOpsuState {
return true;
}
if (OPTION_DANCE_ENABLE_SB.state && optionsOverlay.keyPressed(key, c)) {
return true;
}
if (gameFinished) {
return true;
}
@ -1233,7 +1245,8 @@ public class Game extends ComplexOpsuState {
if (super.mouseDragged(oldx, oldy, newx, newy)) {
return true;
}
return true;
return OPTION_DANCE_ENABLE_SB.state &&
optionsOverlay.mouseDragged(oldx, oldy, newx, newy);
}
@Override
@ -1241,6 +1254,10 @@ public class Game extends ComplexOpsuState {
if (super.mousePressed(button, x, y)) {
return true;
}
if (OPTION_DANCE_ENABLE_SB.state && optionsOverlay.mousePressed(button, x, y)) {
return true;
}
if (gameFinished) {
return true;
@ -1347,6 +1364,10 @@ public class Game extends ComplexOpsuState {
return true;
}
if (OPTION_DANCE_ENABLE_SB.state && optionsOverlay.mouseReleased(button, x, y)) {
return true;
}
if (gameFinished) {
return true;
}
@ -1375,6 +1396,10 @@ public class Game extends ComplexOpsuState {
if (super.keyReleased(key, c)) {
return true;
}
if (OPTION_DANCE_ENABLE_SB.state && optionsOverlay.keyReleased(key, c)) {
return true;
}
if (gameFinished) {
return true;
@ -1412,6 +1437,10 @@ public class Game extends ComplexOpsuState {
if (super.mouseWheelMoved(newValue)) {
return true;
}
if (OPTION_DANCE_ENABLE_SB.state && optionsOverlay.mouseWheelMoved(newValue)) {
return true;
}
if (OPTION_DISABLE_MOUSE_WHEEL.state) {
return true;
@ -1425,11 +1454,9 @@ public class Game extends ComplexOpsuState {
public void enter() {
overlays.clear();
if (OPTION_DANCE_ENABLE_SB.state) {
overlays.add(optionsOverlay);
overlays.add(moveStoryboardOverlay);
overlays.add(storyboardOverlay);
storyboardOverlay.onEnter();
optionsOverlay.revalidate();
}
super.enter();
@ -1691,6 +1718,8 @@ public class Game extends ComplexOpsuState {
if (OPTION_DANCE_ENABLE_SB.state) {
storyboardOverlay.onLeave();
}
optionsOverlay.hide();
isInGame = false;
// container.setMouseGrabbed(false);

View File

@ -469,11 +469,18 @@ public class MainMenu extends BaseOpsuState {
);
g.drawString(txt, textMarginX, textTopMarginY + textLineHeight * 2);
optionsOverlay.render(g);
if (optionsOverlay.isActive()) {
backButton.draw(g);
}
UI.draw(g);
}
@Override
public void preRenderUpdate() {
optionsOverlay.preRenderUpdate();
int delta = renderDelta;
final Iterator<PulseData> pulseDataIter = this.pulseData.iterator();
@ -667,6 +674,10 @@ public class MainMenu extends BaseOpsuState {
@Override
public boolean mousePressed(int button, int x, int y) {
if (optionsOverlay.mousePressed(button, x, y)) {
return true;
}
// check mouse button
if (button == Input.MOUSE_MIDDLE_BUTTON)
return false;
@ -787,6 +798,12 @@ public class MainMenu extends BaseOpsuState {
return true;
}
if (this.buttonPositions[1].contains(x, y, 0.25f)) {
SoundController.playSound(SoundEffect.MENUHIT);
optionsOverlay.show();
return true;
}
if (this.buttonPositions[2].contains(x, y, 0.25f)) {
displayContainer.exitRequested = true;
return true;
@ -798,7 +815,7 @@ public class MainMenu extends BaseOpsuState {
@Override
public boolean mouseWheelMoved(int newValue) {
if (super.mouseWheelMoved(newValue)) {
if (optionsOverlay.mouseWheelMoved(newValue)) {
return true;
}
@ -808,7 +825,7 @@ public class MainMenu extends BaseOpsuState {
@Override
public boolean keyPressed(int key, char c) {
if (super.keyPressed(key, c)) {
if (optionsOverlay.keyPressed(key, c)) {
return true;
}
@ -843,9 +860,28 @@ public class MainMenu extends BaseOpsuState {
case KEY_DOWN:
UI.changeVolume(-1);
return true;
case KEY_O:
if (input.isControlDown()) {
optionsOverlay.show();
}
}
return false;
}
@Override
public boolean keyReleased(int key, char c) {
return optionsOverlay.keyReleased(key, c);
}
@Override
public boolean mouseReleased(int button, int x, int y) {
return optionsOverlay.mouseReleased(button, x, y);
}
@Override
public boolean mouseDragged(int oldx, int oldy, int newx, int newy) {
return optionsOverlay.mouseDragged(oldx, oldy, newx, newy);
}
/**
* Returns true if the coordinates are within the music position bar bounds.
@ -886,6 +922,9 @@ public class MainMenu extends BaseOpsuState {
* Enters the song menu, or the downloads menu if no beatmaps are loaded.
*/
private void enterSongMenu() {
if (optionsOverlay.isActive()) {
optionsOverlay.hide();
}
OpsuState state = songMenuState;
if (BeatmapSetList.get().getMapSetCount() == 0) {
barNotifs.send("Download some beatmaps to get started!");

View File

@ -64,8 +64,6 @@ import org.newdawn.slick.Input;
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.gui.TextField;
import yugecin.opsudance.core.state.ComplexOpsuState;
import yugecin.opsudance.options.OptionGroups;
import yugecin.opsudance.ui.OptionsOverlay;
import static org.lwjgl.input.Keyboard.*;
import static yugecin.opsudance.core.InstanceContainer.*;
@ -310,12 +308,8 @@ public class SongMenu extends ComplexOpsuState {
/** Sort order dropdown menu. */
private DropdownMenu<BeatmapSortOrder> sortMenu;
private final OptionsOverlay optionsOverlay;
public SongMenu() {
super();
optionsOverlay = new OptionsOverlay(OptionGroups.normalOptions);
overlays.add(optionsOverlay);
}
@Override
@ -696,6 +690,8 @@ public class SongMenu extends ComplexOpsuState {
backButton.draw(g);
}
optionsOverlay.render(g);
UI.draw(g);
super.render(g);
@ -704,6 +700,8 @@ public class SongMenu extends ComplexOpsuState {
@Override
public void preRenderUpdate() {
super.preRenderUpdate();
optionsOverlay.preRenderUpdate();
int delta = renderDelta;
UI.update(delta);
@ -860,6 +858,10 @@ public class SongMenu extends ComplexOpsuState {
if (super.mousePressed(button, x, y)) {
return true;
}
if (optionsOverlay.mousePressed(button, x, y)) {
return true;
}
if (button == Input.MOUSE_MIDDLE_BUTTON) {
return false;
@ -879,6 +881,10 @@ public class SongMenu extends ComplexOpsuState {
if (super.mouseReleased(button, x, y)) {
return true;
}
if (optionsOverlay.mouseReleased(button, x, y)) {
return true;
}
if (button == Input.MOUSE_MIDDLE_BUTTON) {
return false;
@ -1025,6 +1031,10 @@ public class SongMenu extends ComplexOpsuState {
if (super.keyPressed(key, c)) {
return true;
}
if (optionsOverlay.keyPressed(key, c)) {
return true;
}
// block input
if ((reloadThread != null && key != KEY_ESCAPE) || beatmapMenuTimer > -1 || isScrollingToFocusNode) {
@ -1179,6 +1189,10 @@ public class SongMenu extends ComplexOpsuState {
if (super.mouseDragged(oldx, oldy, newx, newy)) {
return true;
}
if (optionsOverlay.mouseDragged(oldx, oldy, newx, newy)) {
return true;
}
if (isInputBlocked()) {
return true;
@ -1212,6 +1226,10 @@ public class SongMenu extends ComplexOpsuState {
if (super.mouseWheelMoved(newValue)) {
return true;
}
if (optionsOverlay.mouseWheelMoved(newValue)) {
return true;
}
if (isInputBlocked()) {
return true;
@ -1229,6 +1247,15 @@ public class SongMenu extends ComplexOpsuState {
changeIndex(shift);
return false;
}
@Override
public boolean keyReleased(int key, char c) {
if (super.keyReleased(key, c)) {
return true;
}
return optionsOverlay.keyReleased(key, c);
}
@Override
public void enter() {

View File

@ -31,10 +31,12 @@ import yugecin.opsudance.core.state.specialstates.BarNotificationState;
import yugecin.opsudance.core.state.specialstates.BubNotifState;
import yugecin.opsudance.core.state.specialstates.FpsRenderState;
import yugecin.opsudance.options.Configuration;
import yugecin.opsudance.options.OptionGroups;
import yugecin.opsudance.options.OptionsService;
import yugecin.opsudance.render.GameObjectRenderer;
import yugecin.opsudance.skinning.SkinService;
import yugecin.opsudance.ui.BackButton;
import yugecin.opsudance.ui.OptionsOverlay;
import yugecin.opsudance.utils.ManifestWrapper;
import java.io.File;
@ -65,6 +67,8 @@ public class InstanceContainer {
public static BarNotificationState barNotifs;
public static BubNotifState bubNotifs;
public static FpsRenderState fpsDisplay;
public static OptionsOverlay optionsOverlay;
public static Splash splashState;
public static MainMenu mainmenuState;
@ -115,6 +119,8 @@ public class InstanceContainer {
gameObjectRenderer = new GameObjectRenderer();
optionsOverlay = new OptionsOverlay(OptionGroups.normalOptions);
splashState = new Splash();
mainmenuState = new MainMenu();
buttonState = new ButtonMenu();

View File

@ -1,6 +1,6 @@
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2017 yugecin
* Copyright (C) 2017-2018 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
@ -33,6 +33,10 @@ public abstract class OverlayOpsuState implements OpsuState {
public void show() {
acceptInput = active = true;
}
public boolean isActive() {
return this.active;
}
@Override
public final void update() {

View File

@ -26,7 +26,7 @@ import itdelatrisu.opsu.ui.animations.AnimationEquation;
import org.lwjgl.input.Keyboard;
import org.newdawn.slick.*;
import org.newdawn.slick.gui.TextField;
import yugecin.opsudance.core.state.OverlayOpsuState;
import yugecin.opsudance.events.ResolutionChangedListener;
import yugecin.opsudance.options.*;
import yugecin.opsudance.utils.FontUtil;
@ -37,7 +37,7 @@ import java.util.Random;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*;
public class OptionsOverlay extends OverlayOpsuState {
public class OptionsOverlay implements ResolutionChangedListener {
private static final float BG_ALPHA = 0.7f;
private static final float LINEALPHA = 0.8f;
@ -58,6 +58,9 @@ public class OptionsOverlay extends OverlayOpsuState {
private static final float INDICATOR_ALPHA = 0.8f;
private static final Color COL_INDICATOR = new Color(Color.black);
private boolean active;
private boolean acceptInput;
private boolean dirty;
/** Duration, in ms, of the show (slide-in) animation. */
private static final int SHOWANIMATIONTIME = 1000;
@ -160,6 +163,7 @@ public class OptionsOverlay extends OverlayOpsuState {
public OptionsOverlay(OptionTab[] sections) {
this.sections = sections;
this.dirty = true;
dropdownMenus = new HashMap<>();
visibleDropdownMenus = new LinkedList<>();
@ -169,15 +173,28 @@ public class OptionsOverlay extends OverlayOpsuState {
scrollHandler = new KineticScrolling();
scrollHandler.setAllowOverScroll(true);
displayContainer.addResolutionChangedListener(this);
}
@Override
public void onResolutionChanged(int w, int h) {
this.dirty = true;
if (this.active) {
this.revalidate();
}
}
public boolean isActive() {
return this.active;
}
public void setListener(Listener listener) {
this.listener = listener;
}
@Override
public void revalidate() {
super.revalidate();
this.dirty = false;
boolean isWidescreen = displayContainer.isWidescreen();
targetWidth = (int) (width * (isWidescreen ? 0.4f : 0.5f));
@ -259,8 +276,11 @@ public class OptionsOverlay extends OverlayOpsuState {
searchImg = GameImage.SEARCH.getImage().getScaledCopy(searchImgSize, searchImgSize);
}
@Override
public void onRender(Graphics g) {
public void render(Graphics g) {
if (!this.active && this.currentWidth == 0) {
return;
}
g.setClip(navButtonSize, 0, currentWidth - navButtonSize, height);
// bg
@ -290,9 +310,6 @@ public class OptionsOverlay extends OverlayOpsuState {
renderNavigation(g);
// UI
backButton.draw(g);
// tooltip
renderTooltip(g);
@ -605,30 +622,35 @@ public class OptionsOverlay extends OverlayOpsuState {
g.resetTransform();
}
@Override
public void hide() {
if (!this.active) {
return;
}
acceptInput = active = false;
searchField.setFocused(false);
acceptInput = false;
SoundController.playSound(SoundEffect.MENUBACK);
hideAnimationTime = animationtime;
hideAnimationStartProgress = (float) animationtime / SHOWANIMATIONTIME;
}
@Override
public void show() {
navHoverTime = 0;
indicatorPos = -optionHeight;
indicatorOffsetToNextPos = 0;
indicatorMoveAnimationTime = 0;
indicatorHideAnimationTime = 0;
acceptInput = true;
active = true;
acceptInput = active = true;
animationtime = 0;
resetSearch();
if (this.dirty) {
this.revalidate();
}
}
@Override
public void onPreRenderUpdate() {
public void preRenderUpdate() {
if (!this.active && this.currentWidth == 0) {
return;
}
int delta = renderDelta;
int prevscrollpos = scrollHandler.getIntPosition();
@ -767,8 +789,11 @@ public class OptionsOverlay extends OverlayOpsuState {
COL_COMBOBOX_HOVER.a = showHideProgress;
}
@Override
public boolean onMousePressed(int button, int x, int y) {
public boolean mousePressed(int button, int x, int y) {
if (!this.active) {
return false;
}
if (keyEntryLeft || keyEntryRight) {
keyEntryLeft = keyEntryRight = false;
return true;
@ -793,8 +818,11 @@ public class OptionsOverlay extends OverlayOpsuState {
return true;
}
@Override
public boolean onMouseReleased(int button, int x, int y) {
public boolean mouseReleased(int button, int x, int y) {
if (!this.active) {
return false;
}
selectedOption = null;
if (isAdjustingSlider && listener != null) {
listener.onSaveOption(hoverOption);
@ -867,6 +895,7 @@ public class OptionsOverlay extends OverlayOpsuState {
}
if (backButton.contains(x, y)){
SoundController.playSound(SoundEffect.MENUBACK);
hide();
if (listener != null) {
listener.onLeaveOptionsMenu();
@ -875,8 +904,11 @@ public class OptionsOverlay extends OverlayOpsuState {
return true;
}
@Override
public boolean onMouseDragged(int oldx, int oldy, int newx, int newy) {
public boolean mouseDragged(int oldx, int oldy, int newx, int newy) {
if (!this.active) {
return false;
}
if (!isAdjustingSlider) {
int diff = newy - oldy;
if (diff != 0) {
@ -886,16 +918,22 @@ public class OptionsOverlay extends OverlayOpsuState {
return true;
}
@Override
public boolean onMouseWheelMoved(int delta) {
public boolean mouseWheelMoved(int delta) {
if (!this.active) {
return false;
}
if (!isAdjustingSlider) {
scrollHandler.scrollOffset(-delta);
}
return true;
}
@Override
public boolean onKeyPressed(int key, char c) {
public boolean keyPressed(int key, char c) {
if (!this.active) {
return false;
}
if (keyEntryRight) {
if (Utils.isValidGameKey(key)) {
OPTION_KEY_RIGHT.intval = key;
@ -922,6 +960,7 @@ public class OptionsOverlay extends OverlayOpsuState {
updateHoverOption(prevMouseX, prevMouseY);
return true;
}
SoundController.playSound(SoundEffect.MENUBACK);
hide();
if (listener != null) {
listener.onLeaveOptionsMenu();
@ -953,8 +992,7 @@ public class OptionsOverlay extends OverlayOpsuState {
return true;
}
@Override
public boolean onKeyReleased(int key, char c) {
public boolean keyReleased(int key, char c) {
return false;
}