More easing types, cleanup
This commit is contained in:
@@ -8,6 +8,7 @@ import mightypork.rogue.input.events.MouseMotionEvent;
|
||||
import mightypork.utils.math.coord.Coord;
|
||||
import mightypork.utils.patterns.Destroyable;
|
||||
import mightypork.utils.patterns.Initializable;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -112,7 +113,7 @@ public class InputSystem implements KeyBinder, Destroyable, Initializable {
|
||||
int wheeld = Mouse.getEventDWheel();
|
||||
|
||||
if (button != -1 || wheeld != 0) App.broadcast(new MouseButtonEvent(pos, button, down, wheeld));
|
||||
if(!move.isZero()) App.broadcast(new MouseMotionEvent(pos, move));
|
||||
if (!move.isZero()) App.broadcast(new MouseMotionEvent(pos, move));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ public interface KeyBinder {
|
||||
|
||||
/**
|
||||
* Remove handler from a keystroke (id any)
|
||||
*
|
||||
* @param stroke stroke
|
||||
*/
|
||||
abstract void unbindKeyStroke(KeyStroke stroke);
|
||||
|
||||
@@ -14,7 +14,7 @@ public class KeyBinding implements KeyboardEvent.Listener {
|
||||
public KeyBinding(KeyStroke stroke, Runnable handler) {
|
||||
this.keystroke = stroke;
|
||||
this.handler = handler;
|
||||
|
||||
|
||||
wasActive = keystroke.isActive();
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@ public class KeyBinding implements KeyboardEvent.Listener {
|
||||
public void receive(KeyboardEvent event)
|
||||
{
|
||||
// ignore unrelated events
|
||||
if(!keystroke.getKeys().contains(event.getKey())) return;
|
||||
if (!keystroke.getKeys().contains(event.getKey())) return;
|
||||
|
||||
// run handler when event was met
|
||||
if (keystroke.isActive() && !wasActive) {
|
||||
handler.run();
|
||||
}
|
||||
|
||||
|
||||
wasActive = keystroke.isActive();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener {
|
||||
{
|
||||
for (KeyBinding kb : bindings) {
|
||||
if (kb.matches(stroke)) {
|
||||
Log.w("Duplicate KeyBinding ("+stroke+"), using newest handler.");
|
||||
Log.w("Duplicate KeyBinding (" + stroke + "), using newest handler.");
|
||||
kb.setHandler(task);
|
||||
return;
|
||||
}
|
||||
@@ -42,6 +42,7 @@ public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener {
|
||||
|
||||
/**
|
||||
* Remove handler from keystroke (id any)
|
||||
*
|
||||
* @param stroke stroke
|
||||
*/
|
||||
@Override
|
||||
@@ -58,11 +59,12 @@ public class KeyBindingPool implements KeyBinder, KeyboardEvent.Listener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void receive(KeyboardEvent event)
|
||||
{
|
||||
for(KeyBinding kb: bindings) {
|
||||
kb.receive(event);
|
||||
for (KeyBinding kb : bindings) {
|
||||
kb.receive(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package mightypork.rogue.input.events;
|
||||
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import mightypork.utils.patterns.subscription.Handleable;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
|
||||
/**
|
||||
* A keyboard event
|
||||
@@ -41,7 +41,8 @@ public class KeyboardEvent implements Handleable<KeyboardEvent.Listener> {
|
||||
{
|
||||
return down;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return true if key was just released
|
||||
*/
|
||||
@@ -75,11 +76,12 @@ public class KeyboardEvent implements Handleable<KeyboardEvent.Listener> {
|
||||
*/
|
||||
public void receive(KeyboardEvent event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return Keyboard.getKeyName(key)+":"+(down?"DOWN":"UP");
|
||||
return Keyboard.getKeyName(key) + ":" + (down ? "DOWN" : "UP");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user