strip Input handling

This commit is contained in:
yugecin 2017-05-27 00:37:02 +02:00
parent 42bc11ef75
commit a5efe7e649
18 changed files with 280 additions and 1160 deletions

View File

@ -131,6 +131,9 @@ then run (code is compiled automatically when you run)
<exclude name="org/newdawn/slick/Music.*" />
<exclude name="org/newdawn/slick/Input.*" />
<exclude name="org/newdawn/slick/Input$NullOutputStream.*" />
<exclude name="org/newdawn/slick/MouseListener.*" />
<exclude name="org/newdawn/slick/KeyListener.*" />
<exclude name="org/newdawn/slick/InputListener.*" />
<exclude name="org/newdawn/slick/gui/TextField.*" />
<exclude name="org/newdawn/slick/openal/AudioInputStream*" />
<exclude name="org/newdawn/slick/openal/OpenALStreamPlayer*" />

View File

@ -125,6 +125,9 @@
<exclude>org/newdawn/slick/Music.*</exclude>
<exclude>org/newdawn/slick/Input.*</exclude>
<exclude>org/newdawn/slick/Input$NullOutputStream.*</exclude>
<exclude>org/newdawn/slick/MouseListener.*</exclude>
<exclude>org/newdawn/slick/KeyListener.*</exclude>
<exclude>org/newdawn/slick/InputListener.*</exclude>
<exclude>org/newdawn/slick/gui/TextField.*</exclude>
<exclude>org/newdawn/slick/openal/AudioInputStream*</exclude>
<exclude>org/newdawn/slick/openal/OpenALStreamPlayer*</exclude>

View File

@ -306,7 +306,7 @@ public class DownloadsMenu extends ComplexOpsuState {
// search
searchTimer = SEARCH_DELAY;
searchResultString = "Loading data from server...";
search = new TextField(displayContainer, Fonts.DEFAULT, baseX, searchY, searchWidth, Fonts.MEDIUM.getLineHeight()) {
search = new TextField(Fonts.DEFAULT, baseX, searchY, searchWidth, Fonts.MEDIUM.getLineHeight()) {
@Override
public boolean isFocusable() {
return false;

View File

@ -1150,7 +1150,7 @@ public class Game extends ComplexOpsuState {
break;
case Input.KEY_R:
// restart
if (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL)) {
if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
if (trackPosition < beatmap.objects[0].getTime()) {
retries--; // don't count this retry (cancel out later increment)
}
@ -1161,7 +1161,7 @@ public class Game extends ComplexOpsuState {
break;
case Input.KEY_S:
// save checkpoint
if (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL)) {
if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
if (isLeadIn()) {
break;
}
@ -1177,7 +1177,7 @@ public class Game extends ComplexOpsuState {
break;
case Input.KEY_L:
// load checkpoint
if (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL)) {
if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
int checkpoint = OPTION_CHECKPOINT.val * 1000;
if (checkpoint == 0 || checkpoint > beatmap.endTime)
break; // invalid checkpoint
@ -1396,7 +1396,7 @@ public class Game extends ComplexOpsuState {
keys = ReplayFrame.KEY_K2;
}
if (keys != ReplayFrame.KEY_NONE) {
gameKeyReleased(keys, displayContainer.input.getMouseX(), displayContainer.input.getMouseY(), MusicController.getPosition());
gameKeyReleased(keys, input.getMouseX(), input.getMouseY(), MusicController.getPosition());
}
return true;

View File

@ -109,7 +109,7 @@ public class GamePauseMenu extends BaseOpsuState {
return true;
}
if (key == Input.KEY_R && (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL))) {
if (key == Input.KEY_R && (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL))) {
gameState.setRestart(Game.Restart.MANUAL);
displayContainer.switchState(gameState);
return true;

View File

@ -389,7 +389,7 @@ public class SongMenu extends ComplexOpsuState {
// search
int textFieldX = (int) (displayContainer.width * 0.7125f + Fonts.BOLD.getWidth("Search: "));
int textFieldY = (int) (headerY + Fonts.BOLD.getLineHeight() / 2);
searchTextField = new TextField(displayContainer, Fonts.BOLD, textFieldX, textFieldY, (int) (displayContainer.width * 0.99f) - textFieldX, Fonts.BOLD.getLineHeight()) {
searchTextField = new TextField(Fonts.BOLD, textFieldX, textFieldY, (int) (displayContainer.width * 0.99f) - textFieldX, Fonts.BOLD.getLineHeight()) {
@Override
public boolean isFocusable() {
return false;
@ -1042,8 +1042,6 @@ public class SongMenu extends ComplexOpsuState {
return true;
}
Input input = displayContainer.input;
switch (key) {
case Input.KEY_ESCAPE:
if (reloadThread != null) {
@ -1204,9 +1202,9 @@ public class SongMenu extends ComplexOpsuState {
// check mouse button (right click scrolls faster on songs)
int multiplier;
if (displayContainer.input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
multiplier = 10;
} else if (displayContainer.input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
} else if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
multiplier = 1;
} else {
return false;
@ -1226,8 +1224,6 @@ public class SongMenu extends ComplexOpsuState {
return true;
}
Input input = displayContainer.input;
if (isInputBlocked()) {
return true;
}
@ -1768,7 +1764,7 @@ public class SongMenu extends ComplexOpsuState {
}
// turn on "auto" mod if holding "ctrl" key
if (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL)) {
if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
if (!GameMod.AUTO.isActive())
GameMod.AUTO.toggle(true);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,10 @@
package org.newdawn.slick;
/**
* A listener that will be notified of keyboard and mouse events
* Edited for opsu!
*
* @author kevin
*/
public interface InputListener extends MouseListener, KeyListener {
}

View File

@ -0,0 +1,27 @@
package org.newdawn.slick;
/**
* Describes classes capable of responding to key presses
* Edited for opsu!
*
* @author kevin
*/
public interface KeyListener {
/**
* Notification that a key was pressed
*
* @param key The key code that was pressed (@see org.newdawn.slick.Input)
* @param c The character of the key that was pressed
*/
boolean keyPressed(int key, char c);
/**
* Notification that a key was released
*
* @param key The key code that was released (@see org.newdawn.slick.Input)
* @param c The character of the key that was released
*/
boolean keyReleased(int key, char c);
}

View File

@ -0,0 +1,46 @@
package org.newdawn.slick;
/**
* Description of classes that respond to mouse related input events
* Edited for opsu!
*
* @author kevin
*/
public interface MouseListener {
/**
* Notification that the mouse wheel position was updated
*
* @param delta The amount of the wheel has moved
*/
boolean mouseWheelMoved(int delta);
/**
* Notification that a mouse button was pressed
*
* @param button The index of the button (starting at 0)
* @param x The x position of the mouse when the button was pressed
* @param y The y position of the mouse when the button was pressed
*/
boolean mousePressed(int button, int x, int y);
/**
* Notification that a mouse button was released
*
* @param button The index of the button (starting at 0)
* @param x The x position of the mouse when the button was released
* @param y The y position of the mouse when the button was released
*/
boolean mouseReleased(int button, int x, int y);
/**
* Notification that mouse cursor was dragged
*
* @param oldx The old x position of the mouse
* @param oldy The old y position of the mouse
* @param newx The new x position of the mouse
* @param newy The new y position of the mouse
*/
boolean mouseDragged(int oldx, int oldy, int newx, int newy);
}

View File

@ -34,10 +34,11 @@ import org.newdawn.slick.Font;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.geom.Rectangle;
import yugecin.opsudance.core.DisplayContainer;
import yugecin.opsudance.core.components.ActionListener;
import yugecin.opsudance.core.components.Component;
import static yugecin.opsudance.core.InstanceContainer.*;
/**
* A single text field supporting text entry
*
@ -48,8 +49,6 @@ public class TextField extends Component {
private static final int INITIAL_KEY_REPEAT_INTERVAL = 400;
private static final int KEY_REPEAT_INTERVAL = 50;
private final DisplayContainer displayContainer;
private String value = "";
private Font font;
private int maxCharacter = 10000;
@ -65,8 +64,7 @@ public class TextField extends Component {
private ActionListener listener;
public TextField(DisplayContainer displayContainer, Font font, int x, int y, int width, int height) {
this.displayContainer = displayContainer;
public TextField(Font font, int x, int y, int width, int height) {
this.font = font;
this.x = x;
this.y = y;
@ -97,7 +95,7 @@ public class TextField extends Component {
public void render(Graphics g) {
if (lastKey != -1) {
if (displayContainer.input.isKeyDown(lastKey)) {
if (input.isKeyDown(lastKey)) {
if (repeatTimer < System.currentTimeMillis()) {
repeatTimer = System.currentTimeMillis() + KEY_REPEAT_INTERVAL;
keyPressed(lastKey, lastChar);
@ -173,7 +171,7 @@ public class TextField extends Component {
if (key != -1)
{
if ((key == Input.KEY_V) &&
((displayContainer.input.isKeyDown(Input.KEY_LCONTROL)) || (displayContainer.input.isKeyDown(Input.KEY_RCONTROL)))) {
((input.isKeyDown(Input.KEY_LCONTROL)) || (input.isKeyDown(Input.KEY_RCONTROL)))) {
String text = Sys.getClipboard();
if (text != null) {
doPaste(text);
@ -208,7 +206,7 @@ public class TextField extends Component {
}
*/ } else if (key == Input.KEY_BACK) {
if ((cursorPos > 0) && (value.length() > 0)) {
if (displayContainer.input.isKeyDown(Input.KEY_LCONTROL) || displayContainer.input.isKeyDown(Input.KEY_RCONTROL)) {
if (input.isKeyDown(Input.KEY_LCONTROL) || input.isKeyDown(Input.KEY_RCONTROL)) {
int sp = 0;
boolean startSpace = Character.isWhitespace(value.charAt(cursorPos - 1));
boolean charSeen = false;

View File

@ -59,7 +59,7 @@ import static yugecin.opsudance.options.Options.*;
/**
* based on org.newdawn.slick.AppGameContainer
*/
public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListener, ResolutionChangedListener, SkinChangedListener {
public class DisplayContainer implements ErrorDumpable, ResolutionChangedListener, SkinChangedListener {
private static SGL GL = Renderer.get();
@ -72,7 +72,6 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
public final DisplayMode nativeDisplayMode;
private Graphics graphics;
public Input input;
public int width;
public int height;
@ -208,12 +207,12 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
setUPS(OPTION_TARGET_UPS.val);
setFPS(targetFPS[targetFPSIndex]);
state = startingState;
state.enter();
fpsState = new FpsRenderState();
bubNotifState = new BubNotifState();
barNotifState = new BarNotificationState();
state = startingState;
state.enter();
}
@ -281,7 +280,6 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
public void setup() throws Exception {
width = height = -1;
Input.disableControllers();
Display.setTitle("opsu!dance");
setupResolutionOptionlist(nativeDisplayMode.getWidth(), nativeDisplayMode.getHeight());
updateDisplayMode(OPTION_SCREEN_RESOLUTION.getValueString());
@ -434,10 +432,12 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
graphics = new Graphics(width, height);
graphics.setAntiAlias(false);
input = new Input(height);
input.enableKeyRepeat();
input.addKeyListener(this);
input.addMouseListener(this);
if (input == null) {
input = new Input(height);
input.enableKeyRepeat();
input.addListener(new GlobalInputListener());
input.addMouseListener(bubNotifState);
}
sout("GL ready");
@ -469,6 +469,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
state.writeErrorDump(dump);
}
// TODO change this
public boolean isInState(Class<? extends OpsuState> state) {
return state.isInstance(state);
}
@ -494,65 +495,10 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
public void switchStateInstantly(OpsuState state) {
this.state.leave();
input.removeListener(this.state);
this.state = state;
this.state.enter();
input.addListener(this.state);
}
/*
* input events below, see org.newdawn.slick.KeyListener & org.newdawn.slick.MouseListener
*/
@Override
public void keyPressed(int key, char c) {
state.keyPressed(key, c);
}
@Override
public void keyReleased(int key, char c) {
state.keyReleased(key, c);
}
@Override
public void mouseWheelMoved(int change) {
state.mouseWheelMoved(change);
}
@Override
public void mouseClicked(int button, int x, int y, int clickCount) { }
@Override
public void mousePressed(int button, int x, int y) {
state.mousePressed(button, x, y);
}
@Override
public void mouseReleased(int button, int x, int y) {
if (bubNotifState.mouseReleased(x, y)) {
return;
}
state.mouseReleased(button, x, y);
}
@Override
public void mouseMoved(int oldx, int oldy, int newx, int newy) { }
@Override
public void mouseDragged(int oldx, int oldy, int newx, int newy) {
state.mouseDragged(oldx, oldy, newx, newy);
}
@Override
public void setInput(Input input) { }
@Override
public boolean isAcceptingInput() {
return true;
}
@Override
public void inputEnded() { }
@Override
public void inputStarted() { }
}

View File

@ -0,0 +1,83 @@
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2017 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.core;
import itdelatrisu.opsu.states.Game;
import itdelatrisu.opsu.ui.UI;
import org.newdawn.slick.Input;
import org.newdawn.slick.InputListener;
import yugecin.opsudance.events.BarNotifListener;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*;
public class GlobalInputListener implements InputListener {
@Override
public boolean keyPressed(int key, char c) {
return false;
}
@Override
public boolean keyReleased(int key, char c) {
if (key == Input.KEY_F7) {
OPTION_TARGET_FPS.clickListItem((targetFPSIndex + 1) % targetFPS.length);
BarNotifListener.EVENT.make().onBarNotif(String.format("Frame limiter: %s",
OPTION_TARGET_FPS.getValueString()));
return true;
}
if (key == Input.KEY_F10) {
OPTION_DISABLE_MOUSE_BUTTONS.toggle();
return true;
}
if (key == Input.KEY_F12) {
config.takeScreenShot();
return true;
}
if (key == Input.KEY_S && input.isKeyDown(Input.KEY_LMENU) && input.isKeyDown(Input.KEY_LSHIFT) &&
input.isKeyDown(Input.KEY_LCONTROL) && !displayContainer.isInState(Game.class)) {
skinservice.reloadSkin();
}
return false;
}
@Override
public boolean mouseWheelMoved(int delta) {
if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT)) {
UI.changeVolume((delta < 0) ? -1 : 1);
return true;
}
return false;
}
@Override
public boolean mousePressed(int button, int x, int y) {
return false;
}
@Override
public boolean mouseReleased(int button, int x, int y) {
return false;
}
@Override
public boolean mouseDragged(int oldx, int oldy, int newx, int newy) {
return false;
}
}

View File

@ -23,6 +23,7 @@ import itdelatrisu.opsu.beatmap.OszUnpacker;
import itdelatrisu.opsu.downloads.Updater;
import itdelatrisu.opsu.replay.ReplayImporter;
import itdelatrisu.opsu.states.*;
import org.newdawn.slick.Input;
import org.newdawn.slick.util.FileSystemLocation;
import org.newdawn.slick.util.ResourceLoader;
import yugecin.opsudance.options.Configuration;
@ -51,6 +52,7 @@ public class InstanceContainer {
public static Updater updater;
public static DisplayContainer displayContainer;
public static Input input;
public static GameObjectRenderer gameObjectRenderer;

View File

@ -17,18 +17,11 @@
*/
package yugecin.opsudance.core.state;
import itdelatrisu.opsu.states.Game;
import itdelatrisu.opsu.ui.UI;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import yugecin.opsudance.events.BarNotifListener;
import yugecin.opsudance.events.ResolutionChangedListener;
import java.io.StringWriter;
import static yugecin.opsudance.options.Options.*;
import static yugecin.opsudance.core.InstanceContainer.*;
public abstract class BaseOpsuState implements OpsuState, ResolutionChangedListener {
/**
@ -91,33 +84,11 @@ public abstract class BaseOpsuState implements OpsuState, ResolutionChangedListe
@Override
public boolean keyReleased(int key, char c) {
if (key == Input.KEY_F7) {
OPTION_TARGET_FPS.clickListItem((targetFPSIndex + 1) % targetFPS.length);
BarNotifListener.EVENT.make().onBarNotif(String.format("Frame limiter: %s",
OPTION_TARGET_FPS.getValueString()));
return true;
}
if (key == Input.KEY_F10) {
OPTION_DISABLE_MOUSE_BUTTONS.toggle();
return true;
}
if (key == Input.KEY_F12) {
config.takeScreenShot();
return true;
}
Input input = displayContainer.input;
if (key == Input.KEY_S && input.isKeyDown(Input.KEY_LMENU) && input.isKeyDown(Input.KEY_LSHIFT) &&input.isKeyDown(Input.KEY_LCONTROL) && !displayContainer.isInState(Game.class)) {
skinservice.reloadSkin();
}
return false;
}
@Override
public boolean mouseWheelMoved(int delta) {
if (displayContainer.input.isKeyDown(Input.KEY_LALT) || displayContainer.input.isKeyDown(Input.KEY_RALT)) {
UI.changeVolume((delta < 0) ? -1 : 1);
return true;
}
return false;
}

View File

@ -18,9 +18,10 @@
package yugecin.opsudance.core.state;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.InputListener;
import yugecin.opsudance.core.errorhandling.ErrorDumpable;
public interface OpsuState extends ErrorDumpable {
public interface OpsuState extends ErrorDumpable, InputListener {
void update();
void preRenderUpdate();
@ -33,34 +34,4 @@ public interface OpsuState extends ErrorDumpable {
*/
boolean onCloseRequest();
/**
* @return false to stop event bubbling
*/
boolean keyPressed(int key, char c);
/**
* @return false to stop event bubbling
*/
boolean keyReleased(int key, char c);
/**
* @return false to stop event bubbling
*/
boolean mouseWheelMoved(int delta);
/**
* @return false to stop event bubbling
*/
boolean mousePressed(int button, int x, int y);
/**
* @return false to stop event bubbling
*/
boolean mouseReleased(int button, int x, int y);
/**
* @return false to stop event bubbling
*/
boolean mouseDragged(int oldx, int oldy, int newx, int newy);
}

View File

@ -21,6 +21,7 @@ import itdelatrisu.opsu.ui.Fonts;
import itdelatrisu.opsu.ui.animations.AnimationEquation;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.MouseListener;
import yugecin.opsudance.events.BubNotifListener;
import yugecin.opsudance.events.ResolutionChangedListener;
import yugecin.opsudance.events.SkinChangedListener;
@ -29,9 +30,9 @@ import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import static yugecin.opsudance.core.InstanceContainer.displayContainer;
import static yugecin.opsudance.core.InstanceContainer.*;
public class BubNotifState implements BubNotifListener, ResolutionChangedListener, SkinChangedListener {
public class BubNotifState implements MouseListener, BubNotifListener, ResolutionChangedListener, SkinChangedListener {
public static final int IN_TIME = 633;
public static final int DISPLAY_TIME = 7000 + IN_TIME;
@ -71,18 +72,6 @@ public class BubNotifState implements BubNotifListener, ResolutionChangedListene
} while (iter.hasNext());
}
public boolean mouseReleased(int x, int y) {
if (x < Notification.finalX) {
return false;
}
for (Notification bubble : bubbles) {
if (bubble.mouseReleased(x, y)) {
return true;
}
}
return false;
}
private void calculatePositions() {
Notification.width = (int) (displayContainer.width * 0.1703125f);
Notification.baseLine = (int) (displayContainer.height * 0.9645f);
@ -146,6 +135,34 @@ public class BubNotifState implements BubNotifListener, ResolutionChangedListene
calculatePositions();
}
@Override
public boolean mouseWheelMoved(int delta) {
return false;
}
@Override
public boolean mousePressed(int button, int x, int y) {
return false;
}
@Override
public boolean mouseReleased(int button, int x, int y) {
if (x < Notification.finalX) {
return false;
}
for (Notification bubble : bubbles) {
if (bubble.mouseReleased(x, y)) {
return true;
}
}
return false;
}
@Override
public boolean mouseDragged(int oldx, int oldy, int newx, int newy) {
return false;
}
private static class Notification {
private final static int HOVER_ANIM_TIME = 150;

View File

@ -146,7 +146,7 @@ public class OptionsOverlay extends OverlayOpsuState {
dropdownMenus = new HashMap<>();
visibleDropdownMenus = new LinkedList<>();
searchField = new TextField(displayContainer, null, 0, 0, 0, 0);
searchField = new TextField(null, 0, 0, 0, 0);
searchField.setMaxLength(20);
scrollHandler = new KineticScrolling();