Beautiful keys abstraction (decoupled from lwjgl key constants)

master
Ondřej Hruška 11 years ago
parent a9b38b9417
commit 3987b234bb
  1. 176
      src/mightypork/gamecore/backends/lwjgl/LwjglInputModule.java
  2. 3
      src/mightypork/gamecore/core/config/Config.java
  3. 3
      src/mightypork/gamecore/core/config/KeyStrokeProperty.java
  4. 4
      src/mightypork/gamecore/gui/screens/Overlay.java
  5. 4
      src/mightypork/gamecore/gui/screens/Screen.java
  6. 30
      src/mightypork/gamecore/input/InputModule.java
  7. 114
      src/mightypork/gamecore/input/Key.java
  8. 2
      src/mightypork/gamecore/input/KeyBinder.java
  9. 8
      src/mightypork/gamecore/input/KeyBinding.java
  10. 2
      src/mightypork/gamecore/input/KeyBindingPool.java
  11. 46
      src/mightypork/gamecore/input/KeyStroke.java
  12. 467
      src/mightypork/gamecore/input/Keys.java
  13. 2
      src/mightypork/gamecore/input/Trigger.java
  14. 4
      src/mightypork/rogue/RogueApp.java
  15. 4
      src/mightypork/rogue/screens/FpsOverlay.java
  16. 12
      src/mightypork/rogue/screens/game/LayerAskSave.java
  17. 8
      src/mightypork/rogue/screens/game/LayerDeath.java
  18. 16
      src/mightypork/rogue/screens/game/LayerInv.java
  19. 6
      src/mightypork/rogue/screens/game/LayerWin.java
  20. 22
      src/mightypork/rogue/screens/game/ScreenGame.java
  21. 4
      src/mightypork/rogue/screens/menu/ScreenMainMenu.java
  22. 4
      src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java
  23. 12
      src/mightypork/rogue/screens/story/ScreenStory.java
  24. 6
      src/mightypork/rogue/world/gui/interaction/MIPKeyboard.java

@ -4,6 +4,7 @@ package mightypork.gamecore.backends.lwjgl;
import mightypork.gamecore.core.App;
import mightypork.gamecore.core.events.UserQuitRequest;
import mightypork.gamecore.input.InputModule;
import mightypork.gamecore.input.Key;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.input.events.KeyEvent;
import mightypork.gamecore.input.events.MouseButtonEvent;
@ -24,6 +25,7 @@ import org.lwjgl.opengl.Display;
* @author Ondřej Hruška (MightyPork)
*/
public class LwjglInputModule extends InputModule implements Updateable {
/** Current mouse position */
private static final Vect mousePos = new Vect() {
@ -47,14 +49,6 @@ public class LwjglInputModule extends InputModule implements Updateable {
};
@Override
public void destroy()
{
Mouse.destroy();
Keyboard.destroy();
}
@Override
protected void initDevices()
{
@ -67,6 +61,143 @@ public class LwjglInputModule extends InputModule implements Updateable {
}
}
@Override
protected void initKeyCodes()
{
Keys.NONE.setCode(Keyboard.KEY_NONE);
Keys.NUM_1.setCode(Keyboard.KEY_1);
Keys.NUM_2.setCode(Keyboard.KEY_2);
Keys.NUM_3.setCode(Keyboard.KEY_3);
Keys.NUM_4.setCode(Keyboard.KEY_4);
Keys.NUM_5.setCode(Keyboard.KEY_5);
Keys.NUM_6.setCode(Keyboard.KEY_6);
Keys.NUM_7.setCode(Keyboard.KEY_7);
Keys.NUM_8.setCode(Keyboard.KEY_8);
Keys.NUM_9.setCode(Keyboard.KEY_9);
Keys.NUM_0.setCode(Keyboard.KEY_0);
Keys.Q.setCode(Keyboard.KEY_Q);
Keys.W.setCode(Keyboard.KEY_W);
Keys.E.setCode(Keyboard.KEY_E);
Keys.R.setCode(Keyboard.KEY_R);
Keys.T.setCode(Keyboard.KEY_T);
Keys.Y.setCode(Keyboard.KEY_Y);
Keys.U.setCode(Keyboard.KEY_U);
Keys.I.setCode(Keyboard.KEY_I);
Keys.O.setCode(Keyboard.KEY_O);
Keys.P.setCode(Keyboard.KEY_P);
Keys.A.setCode(Keyboard.KEY_A);
Keys.S.setCode(Keyboard.KEY_S);
Keys.D.setCode(Keyboard.KEY_D);
Keys.F.setCode(Keyboard.KEY_F);
Keys.G.setCode(Keyboard.KEY_G);
Keys.H.setCode(Keyboard.KEY_H);
Keys.J.setCode(Keyboard.KEY_J);
Keys.K.setCode(Keyboard.KEY_K);
Keys.L.setCode(Keyboard.KEY_L);
Keys.Z.setCode(Keyboard.KEY_Z);
Keys.X.setCode(Keyboard.KEY_X);
Keys.C.setCode(Keyboard.KEY_C);
Keys.V.setCode(Keyboard.KEY_V);
Keys.B.setCode(Keyboard.KEY_B);
Keys.N.setCode(Keyboard.KEY_N);
Keys.M.setCode(Keyboard.KEY_M);
Keys.MINUS.setCode(Keyboard.KEY_MINUS);
Keys.EQUALS.setCode(Keyboard.KEY_EQUALS);
Keys.SLASH.setCode(Keyboard.KEY_SLASH);
Keys.BACKSLASH.setCode(Keyboard.KEY_BACKSLASH);
Keys.BRACKET_LEFT.setCode(Keyboard.KEY_LBRACKET);
Keys.BRACKET_RIGHT.setCode(Keyboard.KEY_RBRACKET);
Keys.SEMICOLON.setCode(Keyboard.KEY_SEMICOLON);
Keys.APOSTROPHE.setCode(Keyboard.KEY_APOSTROPHE);
Keys.GRAVE.setCode(Keyboard.KEY_GRAVE);
Keys.COMMA.setCode(Keyboard.KEY_COMMA);
Keys.PERIOD.setCode(Keyboard.KEY_PERIOD);
Keys.SPACE.setCode(Keyboard.KEY_SPACE);
Keys.BACKSPACE.setCode(Keyboard.KEY_BACK);
Keys.TAB.setCode(Keyboard.KEY_TAB);
Keys.ESCAPE.setCode(Keyboard.KEY_ESCAPE);
Keys.APPS.setCode(Keyboard.KEY_APPS);
Keys.POWER.setCode(Keyboard.KEY_POWER);
Keys.SLEEP.setCode(Keyboard.KEY_SLEEP);
//Keys.MENU.setCode(Keyboard.KEY_MENU); // not defined
Keys.F1.setCode(Keyboard.KEY_F1);
Keys.F2.setCode(Keyboard.KEY_F2);
Keys.F3.setCode(Keyboard.KEY_F3);
Keys.F4.setCode(Keyboard.KEY_F4);
Keys.F5.setCode(Keyboard.KEY_F5);
Keys.F6.setCode(Keyboard.KEY_F6);
Keys.F7.setCode(Keyboard.KEY_F7);
Keys.F8.setCode(Keyboard.KEY_F8);
Keys.F9.setCode(Keyboard.KEY_F9);
Keys.F10.setCode(Keyboard.KEY_F10);
Keys.F11.setCode(Keyboard.KEY_F11);
Keys.F12.setCode(Keyboard.KEY_F12);
Keys.F13.setCode(Keyboard.KEY_F13);
Keys.F14.setCode(Keyboard.KEY_F14);
Keys.F15.setCode(Keyboard.KEY_F15);
Keys.CAPS_LOCK.setCode(Keyboard.KEY_CAPITAL);
Keys.SCROLL_LOCK.setCode(Keyboard.KEY_SCROLL);
Keys.NUM_LOCK.setCode(Keyboard.KEY_NUMLOCK);
Keys.NUMPAD_MINUS.setCode(Keyboard.KEY_SUBTRACT);
Keys.NUMPAD_PLUSS.setCode(Keyboard.KEY_ADD);
Keys.NUMPAD_0.setCode(Keyboard.KEY_NUMPAD0);
Keys.NUMPAD_1.setCode(Keyboard.KEY_NUMPAD1);
Keys.NUMPAD_2.setCode(Keyboard.KEY_NUMPAD2);
Keys.NUMPAD_3.setCode(Keyboard.KEY_NUMPAD3);
Keys.NUMPAD_4.setCode(Keyboard.KEY_NUMPAD4);
Keys.NUMPAD_5.setCode(Keyboard.KEY_NUMPAD5);
Keys.NUMPAD_6.setCode(Keyboard.KEY_NUMPAD6);
Keys.NUMPAD_7.setCode(Keyboard.KEY_NUMPAD7);
Keys.NUMPAD_8.setCode(Keyboard.KEY_NUMPAD8);
Keys.NUMPAD_9.setCode(Keyboard.KEY_NUMPAD9);
Keys.NUMPAD_DECIMAL.setCode(Keyboard.KEY_DECIMAL);
Keys.NUMPAD_ENTER.setCode(Keyboard.KEY_NUMPADENTER);
Keys.NUMPAD_DIVIDE.setCode(Keyboard.KEY_DIVIDE);
Keys.NUMPAD_MULTIPLY.setCode(Keyboard.KEY_MULTIPLY);
Keys.CONTROL_LEFT.setCode(Keyboard.KEY_LCONTROL);
Keys.CONTROL_RIGHT.setCode(Keyboard.KEY_RCONTROL);
Keys.ALT_LEFT.setCode(Keyboard.KEY_LMENU);
Keys.ALT_RIGHT.setCode(Keyboard.KEY_RMENU);
Keys.SHIFT_LEFT.setCode(Keyboard.KEY_LSHIFT);
Keys.SHIFT_RIGHT.setCode(Keyboard.KEY_RSHIFT);
Keys.META_LEFT.setCode(Keyboard.KEY_LMETA);
Keys.META_RIGHT.setCode(Keyboard.KEY_RMETA);
Keys.UP.setCode(Keyboard.KEY_UP);
Keys.DOWN.setCode(Keyboard.KEY_DOWN);
Keys.LEFT.setCode(Keyboard.KEY_LEFT);
Keys.RIGHT.setCode(Keyboard.KEY_RIGHT);
Keys.HOME.setCode(Keyboard.KEY_HOME);
Keys.END.setCode(Keyboard.KEY_END);
Keys.PAGE_UP.setCode(Keyboard.KEY_PRIOR);
Keys.PAGE_DOWN.setCode(Keyboard.KEY_NEXT);
Keys.RETURN.setCode(Keyboard.KEY_RETURN);
Keys.PAUSE.setCode(Keyboard.KEY_PAUSE);
Keys.INSERT.setCode(Keyboard.KEY_INSERT);
Keys.DELETE.setCode(Keyboard.KEY_DELETE);
Keys.SYSRQ.setCode(Keyboard.KEY_SYSRQ);
}
@Override
public void destroy()
{
Mouse.destroy();
Keyboard.destroy();
}
private final VectVar mouseMove = Vect.makeVar();
private final VectVar mouseLastPos = Vect.makeVar();
@ -158,9 +289,9 @@ public class LwjglInputModule extends InputModule implements Updateable {
@Override
public boolean isKeyDown(int key)
public boolean isKeyDown(Key key)
{
return Keyboard.isKeyDown(key);
return key.isDefined() && Keyboard.isKeyDown(key.getCode());
}
@ -169,29 +300,4 @@ public class LwjglInputModule extends InputModule implements Updateable {
{
return Mouse.isButtonDown(button);
}
@Override
public int getActiveModKeys()
{
int mods = 0;
if (isKeyDown(Keys.L_ALT) || isKeyDown(Keys.R_ALT)) {
mods |= Keys.MOD_ALT;
}
if (isKeyDown(Keys.L_SHIFT) || isKeyDown(Keys.R_SHIFT)) {
mods |= Keys.MOD_SHIFT;
}
if (isKeyDown(Keys.L_CONTROL) || isKeyDown(Keys.R_CONTROL)) {
mods |= Keys.MOD_CONTROL;
}
if (isKeyDown(Keys.L_META) || isKeyDown(Keys.R_META)) {
mods |= Keys.MOD_META;
}
return mods;
}
}

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.Map;
import mightypork.gamecore.core.WorkDir;
import mightypork.gamecore.input.Key;
import mightypork.gamecore.input.KeyStroke;
import mightypork.utils.config.propmgr.Property;
import mightypork.utils.config.propmgr.PropertyManager;
@ -256,7 +257,7 @@ public class Config {
* @param key stroke key
* @param mod stroke modifiers
*/
public void setKeyStroke(String cfgKey, int key, int mod)
public void setKeyStroke(String cfgKey, Key key, int mod)
{
final KeyStrokeProperty kp = strokes.get(prefixKeyStroke(cfgKey));
if (kp == null) {

@ -1,6 +1,7 @@
package mightypork.gamecore.core.config;
import mightypork.gamecore.input.Key;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.utils.config.propmgr.Property;
@ -27,7 +28,7 @@ public class KeyStrokeProperty extends Property<KeyStroke> {
if (string != null) {
// keep the same instance
final int backup_key = value.getKey();
final Key backup_key = value.getKey();
final int backup_mod = value.getMod();
value.fromDataString(string);

@ -9,7 +9,7 @@ import mightypork.gamecore.core.App;
import mightypork.gamecore.graphics.Renderable;
import mightypork.gamecore.gui.components.layout.ConstraintLayout;
import mightypork.gamecore.gui.events.LayoutChangeListener;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
@ -63,7 +63,7 @@ public abstract class Overlay extends BusNode implements Comparable<Overlay>, Up
@Override
public final void bindKey(KeyStroke stroke, Edge edge, Runnable task)
public final void bindKey(KeyStroke stroke, Trigger edge, Runnable task)
{
keybindings.bindKey(stroke, edge, task);
}

@ -5,7 +5,7 @@ import mightypork.gamecore.core.App;
import mightypork.gamecore.graphics.Renderable;
import mightypork.gamecore.gui.events.LayoutChangeEvent;
import mightypork.gamecore.gui.events.LayoutChangeListener;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.input.KeyBinder;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
@ -44,7 +44,7 @@ public abstract class Screen extends BusNode implements Renderable, RectBound, K
@Override
public final void bindKey(KeyStroke stroke, Edge edge, Runnable task)
public final void bindKey(KeyStroke stroke, Trigger edge, Runnable task)
{
keybindings.bindKey(stroke, edge, task);
}

@ -18,17 +18,28 @@ public abstract class InputModule extends BackendModule implements KeyBinder {
@Override
public final void init()
{
initKeyCodes();
initDevices();
keybindings = new KeyBindingPool();
addChildClient(keybindings);
initDevices();
}
/**
* Initialize key codes for keys in {@link Keys}
*/
protected abstract void initKeyCodes();
/**
* Initialize input devices (set up infrastructure for getting the input)
*/
protected abstract void initDevices();
@Override
public void bindKey(KeyStroke stroke, Edge edge, Runnable task)
public void bindKey(KeyStroke stroke, Trigger edge, Runnable task)
{
keybindings.bindKey(stroke, edge, task);
}
@ -67,25 +78,20 @@ public abstract class InputModule extends BackendModule implements KeyBinder {
/**
* Check if key is down (constant from the {@link Keys} class)
* Check if key is down. The key comes from the Keys class, so the code is
* the one assigned in initKeyCodes()
*
* @param key key to check
* @return is down
*/
public abstract boolean isKeyDown(int key);
public abstract boolean isKeyDown(Key key);
/**
* Check mouse button state
*
* @param button button to test (0 left, 1 right, 2 middle)
* @return button is down
* @param button button to test (0 left, 1 right, 2 middle, 3,4,5... extra)
* @return true if the button exists and is down
*/
public abstract boolean isMouseButtonDown(int button);
/**
* @return bit mask of active mod keys
*/
public abstract int getActiveModKeys();
}

@ -0,0 +1,114 @@
package mightypork.gamecore.input;
import java.util.HashSet;
import java.util.Set;
import mightypork.gamecore.core.App;
/**
* Abstraction above a physical keyboard key.<br>
* Provides name, aliases, and the {@link InputModule} may assign it a numeric
* code that corresponds to the underlying keyboard system.
*
* @author Ondřej Hruška (MightyPork)
*/
public class Key {
private int code = -1;
private final String name;
private final Set<String> aliases = new HashSet<>(1);
/**
* Create a key. Note that both name and aliases are converted to uppercase,
* and all underscores are ignored when the aliases are matched.
*
* @param name key name (primary alias)
* @param aliases extra aliases (used for matching)
*/
public Key(String name, String... aliases) {
// assign name and aliases, converting both to uppercase
this.name = name;
this.aliases.add(prepareForMatch(name));
for (String al : aliases) {
this.aliases.add(prepareForMatch(al));
}
}
public boolean isDown()
{
return App.input().isKeyDown(this);
}
/**
* Set a key code. This can be used by the {@link InputModule} to store a
* numeric code in the key.
*
* @param code a code to assign
*/
public void setCode(int code)
{
this.code = code;
}
/**
* Check if the provided alias matches this key.<br>
* Both the primary alias and the extra aliases are considered.
*
* @param alias
* @return true if matches (this is the key)
*/
public boolean matches(String alias)
{
if (alias == null) return false;
return aliases.contains(prepareForMatch(alias));
}
private String prepareForMatch(String matched)
{
return matched.toUpperCase().replace("_", "");
}
/**
* Get key name (primary alias).
*
* @return name (uppercase)
*/
public String getName()
{
return name;
}
/**
* Get the numeric code assigned to this key. If none is assigned, the value
* is -1.
*
* @return numeric key code.
*/
public int getCode()
{
return code;
}
/**
* Get if this key is not a NONE or undefined key.
*
* @return true if the key is defined.
*/
public boolean isDefined()
{
return code > 0;
}
}

@ -18,7 +18,7 @@ public interface KeyBinder {
* @param stroke trigger keystroke
* @param task handler; can be {@link Runnable} or {@link Action}
*/
void bindKey(KeyStroke stroke, Edge edge, Runnable task);
void bindKey(KeyStroke stroke, Trigger edge, Runnable task);
/**

@ -14,7 +14,7 @@ public class KeyBinding implements KeyEventHandler {
private final KeyStroke keystroke;
private Runnable handler;
private final Edge edge;
private final Trigger edge;
private boolean wasDown = false;
@ -23,7 +23,7 @@ public class KeyBinding implements KeyEventHandler {
* @param stroke trigger keystroke
* @param handler action
*/
public KeyBinding(KeyStroke stroke, Edge edge, Runnable handler) {
public KeyBinding(KeyStroke stroke, Trigger edge, Runnable handler) {
this.keystroke = stroke;
this.handler = handler;
this.edge = edge;
@ -58,8 +58,8 @@ public class KeyBinding implements KeyEventHandler {
final boolean nowDown = keystroke.isDown();
boolean trigger = false;
trigger |= (edge == Edge.FALLING && (!wasDown && nowDown));
trigger |= (edge == Edge.RISING && (wasDown && !nowDown));
trigger |= (edge == Trigger.FALLING && (!wasDown && nowDown));
trigger |= (edge == Trigger.RISING && (wasDown && !nowDown));
wasDown = nowDown;
// run handler when event was met

@ -27,7 +27,7 @@ public class KeyBindingPool implements KeyBinder, KeyEventHandler {
* @param task handler
*/
@Override
public void bindKey(KeyStroke stroke, Edge edge, Runnable task)
public void bindKey(KeyStroke stroke, Trigger edge, Runnable task)
{
for (final KeyBinding kb : bindings) {
if (kb.matches(stroke)) {

@ -1,11 +1,8 @@
package mightypork.gamecore.input;
import mightypork.gamecore.core.App;
import mightypork.utils.string.StringUtil;
import org.lwjgl.input.Keyboard;
/**
* Key stroke description
@ -14,8 +11,8 @@ import org.lwjgl.input.Keyboard;
*/
public class KeyStroke {
private int mod;
private int key;
private byte mod;
private Key key;
/**
@ -24,7 +21,7 @@ public class KeyStroke {
* @param key key code
* @param modmask modifiers
*/
public KeyStroke(int key, int modmask) {
public KeyStroke(Key key, int modmask) {
setTo(key, modmask);
}
@ -37,44 +34,37 @@ public class KeyStroke {
* @param key key code
* @param modmask modifiers
*/
public void setTo(int key, int modmask)
public void setTo(Key key, int modmask)
{
this.key = key;
this.mod = modmask | Keys.keyToMod(key); // for mods alone
this.mod = (byte) (modmask | Keys.keyToMod(key)); // for mods alone
}
/**
* Create a new keystroke without modifiers
*
* @param key key code
* @param key key
*/
public KeyStroke(int key) {
public KeyStroke(Key key) {
this(key, Keys.MOD_NONE);
}
/**
* @return true if the keystroke is currently down & modifiers match.
* Get if the key is down and modifiers match
*
* @return true if the key is currently down & modifiers match
*/
public boolean isDown()
{
boolean st = Keyboard.isKeyDown(key);
st &= (App.input().getActiveModKeys() == mod);
return st;
return key.isDown() && (Keys.getActiveMod() == mod);
}
public String toDataString()
{
String s = "";
if (mod != Keys.MOD_NONE) s = Keys.modToString(mod);
s += Keys.keyToString(key);
return s;
return Keys.modToString(mod) + "+" + key.getName();
}
@ -95,21 +85,21 @@ public class KeyStroke {
final String keyStr = StringUtil.fromLastChar(dataString1, '+');
final String modStr = StringUtil.toLastChar(dataString1, '+');
setTo(Keys.keyFromString(keyStr), Keys.modFromString(modStr));
setTo(Keys.stringToKey(keyStr), Keys.stringToMod(modStr));
} else {
setTo(Keys.keyFromString(dataString1), Keys.MOD_NONE);
setTo(Keys.stringToKey(dataString1), Keys.MOD_NONE);
}
}
public int getKey()
public Key getKey()
{
return key;
}
public int getMod()
public byte getMod()
{
return mod;
}
@ -127,7 +117,7 @@ public class KeyStroke {
{
final int prime = 31;
int result = 1;
result = prime * result + key;
result = prime * result + key.getCode();
result = prime * result + mod;
return result;
}
@ -140,7 +130,7 @@ public class KeyStroke {
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
final KeyStroke other = (KeyStroke) obj;
if (key != other.key) return false;
if (key.getCode() != other.key.getCode()) return false;
if (mod != other.mod) return false;
return true;
}

@ -1,142 +1,153 @@
package mightypork.gamecore.input;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import mightypork.gamecore.core.App;
import mightypork.utils.logging.Log;
import org.lwjgl.input.Keyboard;
/**
* Key constants, from LWJGL {@link Keyboard}
* Key constants & translation table.
*
* @author Ondřej Hruška (MightyPork)
*/
public class Keys {
//@formatter:off
public static final Key NONE = new Key("NONE", "NULL");
public static final int NONE = Keyboard.KEY_NONE;
public static final int ESCAPE = Keyboard.KEY_ESCAPE;
public static final int NUM_1 = Keyboard.KEY_1;
public static final int NUM_2 = Keyboard.KEY_2;
public static final int NUM_3 = Keyboard.KEY_3;
public static final int NUM_4 = Keyboard.KEY_4;
public static final int NUM_5 = Keyboard.KEY_5;
public static final int NUM_6 = Keyboard.KEY_6;
public static final int NUM_7 = Keyboard.KEY_7;
public static final int NUM_8 = Keyboard.KEY_8;
public static final int NUM_9 = Keyboard.KEY_9;
public static final int NUM_0 = Keyboard.KEY_0;
public static final Key NUM_0 = new Key("0", "ZERO");
public static final Key NUM_1 = new Key("1", "ONE");
public static final Key NUM_2 = new Key("2", "TWO");
public static final Key NUM_3 = new Key("3", "THREE");
public static final Key NUM_4 = new Key("4", "FOUR");
public static final Key NUM_5 = new Key("5", "FIVE");
public static final Key NUM_6 = new Key("6", "SIX");
public static final Key NUM_7 = new Key("7", "SEVEN");
public static final Key NUM_8 = new Key("8", "EIGHT");
public static final Key NUM_9 = new Key("9", "NINE");
public static final int Q = Keyboard.KEY_Q;
public static final int W = Keyboard.KEY_W;
public static final int E = Keyboard.KEY_E;
public static final int R = Keyboard.KEY_R;
public static final int T = Keyboard.KEY_T;
public static final int Y = Keyboard.KEY_Y;
public static final int U = Keyboard.KEY_U;
public static final int I = Keyboard.KEY_I;
public static final int O = Keyboard.KEY_O;
public static final int P = Keyboard.KEY_P;
public static final int A = Keyboard.KEY_A;
public static final int S = Keyboard.KEY_S;
public static final int D = Keyboard.KEY_D;
public static final int F = Keyboard.KEY_F;
public static final int G = Keyboard.KEY_G;
public static final int H = Keyboard.KEY_H;
public static final int J = Keyboard.KEY_J;
public static final int K = Keyboard.KEY_K;
public static final int L = Keyboard.KEY_L;
public static final int Z = Keyboard.KEY_Z;
public static final int X = Keyboard.KEY_X;
public static final int C = Keyboard.KEY_C;
public static final int V = Keyboard.KEY_V;
public static final int B = Keyboard.KEY_B;
public static final int N = Keyboard.KEY_N;
public static final int M = Keyboard.KEY_M;
public static final Key Q = new Key("Q");
public static final Key W = new Key("W");
public static final Key E = new Key("E");
public static final Key R = new Key("R");
public static final Key T = new Key("T");
public static final Key Y = new Key("Y");
public static final Key U = new Key("U");
public static final Key I = new Key("I");
public static final Key O = new Key("O");
public static final Key P = new Key("P");
public static final Key A = new Key("A");
public static final Key S = new Key("S");
public static final Key D = new Key("D");
public static final Key F = new Key("F");
public static final Key G = new Key("G");
public static final Key H = new Key("H");
public static final Key J = new Key("J");
public static final Key K = new Key("K");
public static final Key L = new Key("L");
public static final Key Z = new Key("Z");
public static final Key X = new Key("X");
public static final Key C = new Key("C");
public static final Key V = new Key("V");
public static final Key B = new Key("B");
public static final Key N = new Key("N");
public static final Key M = new Key("M");
public static final int MINUS = Keyboard.KEY_MINUS;
public static final int EQUALS = Keyboard.KEY_EQUALS;
public static final int SLASH = Keyboard.KEY_SLASH;
public static final int BACKSLASH = Keyboard.KEY_BACKSLASH;
public static final int L_BRACKET = Keyboard.KEY_LBRACKET;
public static final int R_BRACKET = Keyboard.KEY_RBRACKET;
public static final int SEMICOLON = Keyboard.KEY_SEMICOLON;
public static final int APOSTROPHE = Keyboard.KEY_APOSTROPHE;
public static final int GRAVE = Keyboard.KEY_GRAVE;
public static final int COMMA = Keyboard.KEY_COMMA;
public static final int PERIOD = Keyboard.KEY_PERIOD;
public static final Key MINUS = new Key("MINUS", "DASH");
public static final Key EQUALS = new Key("EQUALS");
public static final Key SLASH = new Key("SLASH");
public static final Key BACKSLASH = new Key("BACKSLASH");
public static final Key BRACKET_LEFT = new Key("LBRACKET", "LEFT_BRACKET");
public static final Key BRACKET_RIGHT = new Key("RBRACKET", "RIGHT_BRACKET");
public static final Key SEMICOLON = new Key("SEMICOLON");
public static final Key APOSTROPHE = new Key("APOSTROPHE", "APOS");
public static final Key GRAVE = new Key("GRAVE", "ACCENT");
public static final Key COMMA = new Key("COMMA");
public static final Key PERIOD = new Key("PERIOD", "DOT", "POINT");
public static final int SPACE = Keyboard.KEY_SPACE;
public static final int BACKSPACE = Keyboard.KEY_BACK;
public static final int TAB = Keyboard.KEY_TAB;
public static final Key SPACE = new Key("SPACE", "SPACEBAR");
public static final Key BACKSPACE = new Key("BACKSPACE", "BACK");
public static final Key TAB = new Key("TAB", "TABULATOR", "INDENT");
public static final Key ESCAPE = new Key("ESC", "ESCAPE");
public static final int F1 = Keyboard.KEY_F1;
public static final int F2 = Keyboard.KEY_F2;
public static final int F3 = Keyboard.KEY_F3;
public static final int F4 = Keyboard.KEY_F4;
public static final int F5 = Keyboard.KEY_F5;
public static final int F6 = Keyboard.KEY_F6;
public static final int F7 = Keyboard.KEY_F7;
public static final int F8 = Keyboard.KEY_F8;
public static final int F9 = Keyboard.KEY_F9;
public static final int F10 = Keyboard.KEY_F10;
public static final int F11 = Keyboard.KEY_F11;
public static final int F12 = Keyboard.KEY_F12;
public static final int F13 = Keyboard.KEY_F13;
public static final int F14 = Keyboard.KEY_F14;
public static final int F15 = Keyboard.KEY_F15;
// those probably can't be used
public static final Key APPS = new Key("APPS");
public static final Key POWER = new Key("POWER");
public static final Key SLEEP = new Key("SLEEP");
public static final Key MENU = new Key("MENU");
public static final Key F1 = new Key("F1");
public static final Key F2 = new Key("F2");
public static final Key F3 = new Key("F3");
public static final Key F4 = new Key("F4");
public static final Key F5 = new Key("F5");
public static final Key F6 = new Key("F6");
public static final Key F7 = new Key("F7");
public static final Key F8 = new Key("F8");
public static final Key F9 = new Key("F9");
public static final Key F10 = new Key("F10");
public static final Key F11 = new Key("F11");
public static final Key F12 = new Key("F12");
public static final Key F13 = new Key("F13");
public static final Key F14 = new Key("F14");
public static final Key F15 = new Key("F15");
public static final int CAPS_LOCK = Keyboard.KEY_CAPITAL;
public static final int SCROLL_LOCK = Keyboard.KEY_SCROLL;
public static final int NUM_LOCK = Keyboard.KEY_NUMLOCK;
// probably not possible to bind to those.
public static final Key CAPS_LOCK = new Key("CAPSLOCK", "CAPS", "CAPITAL");
public static final Key SCROLL_LOCK = new Key("SCROLL", "SCROLL_LOCK");
public static final Key NUM_LOCK = new Key("NUMLOCK");
public static final int NUMPAD_MINUS = Keyboard.KEY_SUBTRACT;
public static final int NUMPAD_PLUSS = Keyboard.KEY_ADD;
public static final int NUMPAD_0 = Keyboard.KEY_NUMPAD0;
public static final int NUMPAD_1 = Keyboard.KEY_NUMPAD1;
public static final int NUMPAD_2 = Keyboard.KEY_NUMPAD2;
public static final int NUMPAD_3 = Keyboard.KEY_NUMPAD3;
public static final int NUMPAD_4 = Keyboard.KEY_NUMPAD4;
public static final int NUMPAD_5 = Keyboard.KEY_NUMPAD5;
public static final int NUMPAD_6 = Keyboard.KEY_NUMPAD6;
public static final int NUMPAD_7 = Keyboard.KEY_NUMPAD7;
public static final int NUMPAD_8 = Keyboard.KEY_NUMPAD8;
public static final int NUMPAD_9 = Keyboard.KEY_NUMPAD9;
public static final int NUMPAD_DECIMAL = Keyboard.KEY_DECIMAL;
public static final int NUMPAD_ENTER = Keyboard.KEY_NUMPADENTER;
public static final int NUMPAD_DIVIDE = Keyboard.KEY_DIVIDE;
public static final int NUMPAD_MULTIPLY = Keyboard.KEY_MULTIPLY;
public static final Key NUMPAD_MINUS = new Key("SUBTRACT", "NUMPAD_MINUS", "NUMPAD_SUBTRACT");
public static final Key NUMPAD_PLUSS = new Key("ADD", "NUMPAD_PLUS", "NUMPAD_ADD");
public static final Key NUMPAD_0 = new Key("NUMPAD_0");
public static final Key NUMPAD_1 = new Key("NUMPAD_1");
public static final Key NUMPAD_2 = new Key("NUMPAD_2");
public static final Key NUMPAD_3 = new Key("NUMPAD_3");
public static final Key NUMPAD_4 = new Key("NUMPAD_4");
public static final Key NUMPAD_5 = new Key("NUMPAD_5");
public static final Key NUMPAD_6 = new Key("NUMPAD_6");
public static final Key NUMPAD_7 = new Key("NUMPAD_7");
public static final Key NUMPAD_8 = new Key("NUMPAD_8");
public static final Key NUMPAD_9 = new Key("NUMPAD_9");
public static final Key NUMPAD_DECIMAL = new Key("DECIMAL", "NUMPAD_DECIMAL", "NUMPAD_PERIOD", "NUMPAD_POINT");
public static final Key NUMPAD_ENTER = new Key("NUMPAD_ENTER", "NUMPADRETURN", "NUMPAD_RETURN");
public static final Key NUMPAD_DIVIDE = new Key("DIVIDE", "NUMPAD_DIVIDE", "NUMPAD_SLASH");
public static final Key NUMPAD_MULTIPLY = new Key("MULTIPLY", "NUMPAD_MULTIPLY", "NUMPAD_ASTERISK");
public static final int L_CONTROL = Keyboard.KEY_LCONTROL;
public static final int R_CONTROL = Keyboard.KEY_RCONTROL;
public static final int L_ALT = Keyboard.KEY_LMENU;
public static final int R_ALT = Keyboard.KEY_RMENU;
public static final int L_SHIFT = Keyboard.KEY_LSHIFT;
public static final int R_SHIFT = Keyboard.KEY_RSHIFT;
public static final int L_META = Keyboard.KEY_LMETA;
public static final int R_META = Keyboard.KEY_RMETA;
public static final Key CONTROL_LEFT = new Key("LCONTROL", "LEFT_CONTROL", "LCTRL", "LEFT_CTRL");
public static final Key CONTROL_RIGHT = new Key("RCONTROL", "RIGHT_CONTROL", "RCTRL", "RIGHT_CTRL");
public static final Key ALT_LEFT = new Key("LALT", "LMENU", "LEFT_MENU");
public static final Key ALT_RIGHT = new Key("RALT", "RMENU", "RIGHT_MENU");
public static final Key SHIFT_LEFT = new Key("LSHIFT", "LEFT_SHIFT");
public static final Key SHIFT_RIGHT = new Key("RSHIFT", "RIGHT_SHIFT");
public static final Key META_LEFT = new Key("LMETA", "LEFT_META", "LWIN", "LEFT_WIN");
public static final Key META_RIGHT = new Key("RMETA", "RIGHT_META", "RWIN", "RIGHT_WIN");
public static final int UP = Keyboard.KEY_UP;
public static final int DOWN = Keyboard.KEY_DOWN;
public static final int LEFT = Keyboard.KEY_LEFT;
public static final int RIGHT = Keyboard.KEY_RIGHT;
public static final Key UP = new Key("UP", "ARROW_UP");
public static final Key DOWN = new Key("DOWN", "ARROW_DOWN");
public static final Key LEFT = new Key("LEFT", "ARROW_LEFT");
public static final Key RIGHT = new Key("RIGHT", "ARROW_RIGHT");
public static final int HOME = Keyboard.KEY_HOME;
public static final int END = Keyboard.KEY_END;
public static final Key HOME = new Key("HOME");
public static final Key END = new Key("END");
public static final int PAGE_UP = Keyboard.KEY_PRIOR;
public static final int PAGE_DOWN = Keyboard.KEY_NEXT;
public static final Key PAGE_UP = new Key("PAGE_UP", "PGUP", "PRIOR");
public static final Key PAGE_DOWN = new Key("PAGE_DOWN", "PGDN", "NEXT");
public static final int RETURN = Keyboard.KEY_RETURN;
public static final int PAUSE = Keyboard.KEY_PAUSE;
public static final int INSERT = Keyboard.KEY_INSERT;
public static final int DELETE = Keyboard.KEY_DELETE;
public static final Key RETURN = new Key("ENTER", "RETURN", "CR");
public static final Key PAUSE = new Key("PAUSE", "BREAK");
public static final Key INSERT = new Key("INSERT");
public static final Key DELETE = new Key("DELETE");
public static final Key SYSRQ = new Key("SYSRQ"); // wtf is this anyway?
// here go modifier bits
public static final byte MOD_NONE = 0;
public static final byte MOD_ALT = 1;
public static final byte MOD_CONTROL = 2;
@ -144,122 +155,220 @@ public class Keys {
public static final byte MOD_META = 8;
//@formatter:on
private static HashMap<String, String> loadAliasMap = new HashMap<>();
private static HashMap<String, String> saveAliasMap = new HashMap<>();
private static Map<Integer, Key> lookupByCode = new HashMap<>(100);
private static List<Key> keyList = new ArrayList<>(100);
static {
// init maps
loadAliasMap.put("ENTER", "RETURN");
loadAliasMap.put("PGDN", "NEXT");
loadAliasMap.put("PGUP", "PRIOR");
loadAliasMap.put("PAGE_DOWN", "NEXT");
loadAliasMap.put("PAGE_UP", "PRIOR");
loadAliasMap.put("SPACEBAR", "SPACE");
loadAliasMap.put("ESC", "ESCAPE");
loadAliasMap.put("NUMPAD_DIVIDE", "DIVIDE");
loadAliasMap.put("NUMPAD_MULTIPLY", "MULTIPLY");
loadAliasMap.put("NUMPAD_ADD", "ADD");
loadAliasMap.put("NUMPAD_SUBTRACT", "SUBTRACT");
loadAliasMap.put("CAPS_LOCK", "CAPITAL");
loadAliasMap.put("SCROLL_LOCK", "SROLL");
loadAliasMap.put("NUM_LOCK", "NUMLOCK");
loadAliasMap.put("BACKSPACE", "BACK");
// define none key
NONE.setCode(0);
saveAliasMap.put("RETURN", "ENTER");
saveAliasMap.put("ESCAPE", "ESC");
saveAliasMap.put("NEXT", "PGDN");
saveAliasMap.put("PRIOR", "PGUP");
saveAliasMap.put("DIVIDE", "NUMPAD_DIVIDE");
saveAliasMap.put("MULTIPLY", "NUMPAD_MULTIPLY");
saveAliasMap.put("ADD", "NUMPAD_ADD");
saveAliasMap.put("SUBTRACT", "NUMPAD_SUBTRACT");
saveAliasMap.put("CAPITAL", "CAPS_LOCK");
saveAliasMap.put("SROLL", "SCROLL_LOCK");
saveAliasMap.put("NUMLOCK", "NUM_LOCK");
saveAliasMap.put("BACK", "BACKSPACE");
// Use reflection to find keys
Field[] fields = Keys.class.getFields();
try {
for (Field field : fields) {
int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers) && Modifier.isFinal(modifiers) && field.getType().equals(Key.class)) {
keyList.add((Key) field.get(null));
}
}
} catch (Exception e) {}
}
public static int keyFromString(String key)
/**
* Build lookup table by key codes
*/
private static void buildCodeLookupTable()
{
String key1 = key;
if (loadAliasMap.containsKey(key1)) key1 = loadAliasMap.get(key1);
lookupByCode.clear();
lookupByCode.put(NONE.getCode(), NONE);
final int index = Keyboard.getKeyIndex(key1);
if (index == Keys.NONE && !key1.equals("NONE")) {
Log.w("Could not parse key: " + key + " (" + key1 + ")");
for (Key k : keyList) {
if (!k.isDefined()) continue;
if (!lookupByCode.containsKey(k.getCode())) {
lookupByCode.put(k.getCode(), k);
}
}
if (lookupByCode.size() == 1) {
// NONE alone
Log.w("Key codes are not ininitialized.");
}
}
/**
* Convert a key name to a key code.
*
* @param keyStr key name
* @return the key, or NONE if none matches
*/
public static Key stringToKey(String keyStr)
{
for (Key k : keyList) {
if (k.matches(keyStr)) return k;
}
return index;
Log.w("No such key: " + keyStr);
return NONE;
}
public static int modFromString(String mod)
/**
* Convert a mod description to a mod mask. A mod description is a string
* containing CTRL,ALT,SHIFT,META, as in CTRL+ALT.<br>
* If none of the mod identifiers are found in the description, a MOD_NONE
* is returned.<br>
* This method is used for parsing keystroke, together with nameToKey().
*
* @param modStr mod description (eg. CTRL+ALT)
* @return mod mask
*/
public static int stringToMod(String modStr)
{
int mod_mask = Keys.MOD_NONE;
int mod_mask = MOD_NONE;
modStr = modStr.toUpperCase();
if (mod.contains("CTRL")) {
mod_mask |= Keys.MOD_CONTROL;
if (modStr.contains("CTRL")) {
mod_mask |= MOD_CONTROL;
}
if (mod.contains("ALT")) {
mod_mask |= Keys.MOD_ALT;
if (modStr.contains("ALT")) {
mod_mask |= MOD_ALT;
}
if (mod.contains("SHIFT")) {
mod_mask |= Keys.MOD_SHIFT;
if (modStr.contains("SHIFT")) {
mod_mask |= MOD_SHIFT;
}
if (mod.contains("META") || mod.contains("WIN")) {
mod_mask |= Keys.MOD_META;
if (modStr.contains("META") || modStr.contains("WIN")) {
mod_mask |= MOD_META;
}
return mod_mask;
}
public static String modToString(int mod)
/**
* Convert a mod mask to a mod description, in a format recognized by
* stringToMod() - joining mods by +.
*
* @param modMask mod mask
* @return mods as string (CTRL+ALT)
*/
public static String modToString(int modMask)
{
String s = "";
if ((mod & Keys.MOD_CONTROL) != 0) {
s += "CTRL+";
if ((modMask & MOD_CONTROL) != 0) {
s += "CTRL";
}
if ((mod & Keys.MOD_ALT) != 0) {
s += "ALT+";
if ((modMask & MOD_ALT) != 0) {
if (!s.isEmpty()) s += "+";
s += "ALT";
}
if ((mod & Keys.MOD_SHIFT) != 0) {
s += "SHIFT+";
if ((modMask & MOD_SHIFT) != 0) {
if (!s.isEmpty()) s += "+";
s += "SHIFT";
}
if ((mod & Keys.MOD_META) != 0) {
s += "META+";
if ((modMask & MOD_META) != 0) {
if (!s.isEmpty()) s += "+";
s += "META";
}
return s;
}
public static String keyToString(int key)
/**
* Get a {@link Key} for key code.
*
* @param keyCode code
* @return key instance, or NONE if no key matches.
*/
public static Key codeToKey(int keyCode)
{
String s = Keyboard.getKeyName(key);
if (saveAliasMap.containsKey(s)) s = saveAliasMap.get(s);
if (s == null) {
Log.w("Could not stringify key: " + key);
s = "NONE";
if (lookupByCode.isEmpty()) buildCodeLookupTable();
Key k = lookupByCode.get(keyCode);
if (k == null) {
Log.w("No key for code: " + keyCode);
k = NONE;
}
return s.toUpperCase();
return k;
}
public static int keyToMod(int key)
/**
* Convert a key to mod mask, in case the key is one of the mod keys.
*
* @param key the key
* @return mod mask corresponding to the key
*/
public static int keyToMod(Key key)
{
if (key == L_SHIFT || key == R_SHIFT) return MOD_SHIFT;
if (key == L_CONTROL || key == R_CONTROL) return MOD_CONTROL;
if (key == L_ALT || key == R_ALT) return MOD_ALT;
if (key == L_META || key == R_META) return MOD_META;
if (key == SHIFT_LEFT || key == SHIFT_RIGHT) return MOD_SHIFT;
if (key == CONTROL_LEFT || key == CONTROL_RIGHT) return MOD_CONTROL;
if (key == ALT_LEFT || key == ALT_RIGHT) return MOD_ALT;
if (key == META_LEFT || key == META_RIGHT) return MOD_META;
return MOD_NONE;
}
/**
* Get if the given key is down (call it's "isDown()" method).<br>
* This method is here just for completeness, since the getActiveMod() is
* also here.
*
* @param key the key to check
* @return true if the key is down
*/
public static boolean isKeyDown(Key key)
{
return key.isDown();
}
/**
* Get currently active key modifiers
*
* @return active mod mask (mod bits ored)
*/
public static int getActiveMod()
{
int mods = 0;
InputModule inp = App.input();
if (inp.isKeyDown(Keys.ALT_LEFT) || inp.isKeyDown(Keys.ALT_RIGHT)) {
mods |= Keys.MOD_ALT;
}
if (inp.isKeyDown(Keys.SHIFT_LEFT) || inp.isKeyDown(Keys.SHIFT_RIGHT)) {
mods |= Keys.MOD_SHIFT;
}
if (inp.isKeyDown(Keys.CONTROL_LEFT) || inp.isKeyDown(Keys.CONTROL_RIGHT)) {
mods |= Keys.MOD_CONTROL;
}
if (inp.isKeyDown(Keys.META_LEFT) || inp.isKeyDown(Keys.META_RIGHT)) {
mods |= Keys.MOD_META;
}
return mods;
}
}

@ -4,7 +4,7 @@ package mightypork.gamecore.input;
/**
* Type of keystroke (falling / rising edge)
*/
public enum Edge
public enum Trigger
{
/** Activated by falling edge (press) */
FALLING,

@ -15,7 +15,7 @@ import mightypork.gamecore.graphics.GraphicsModule;
import mightypork.gamecore.gui.events.ViewportChangeEvent;
import mightypork.gamecore.gui.events.ViewportChangeListener;
import mightypork.gamecore.gui.screens.ScreenRegistry;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.RogueStateRequest;
@ -117,7 +117,7 @@ public final class RogueApp extends BaseApp implements ViewportChangeListener, S
private void bindEventToKey(final BusEvent<?> event, String strokeName)
{
getInput().bindKey(Config.getKeyStroke(strokeName), Edge.RISING, new Runnable() {
getInput().bindKey(Config.getKeyStroke(strokeName), Trigger.RISING, new Runnable() {
@Override
public void run()

@ -7,7 +7,7 @@ import mightypork.gamecore.graphics.fonts.IFont;
import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.Overlay;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.resources.Res;
import mightypork.utils.math.AlignX;
import mightypork.utils.math.color.pal.RGB;
@ -33,7 +33,7 @@ public class FpsOverlay extends Overlay {
/*
* Toggle key: F3
*/
bindKey(Config.getKeyStroke("global.fps_meter"), Edge.RISING, new Action() {
bindKey(Config.getKeyStroke("global.fps_meter"), Trigger.RISING, new Action() {
@Override
public void execute()

@ -12,7 +12,7 @@ import mightypork.gamecore.gui.components.layout.linear.LinearLayout;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.impl.FadingLayer;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.screens.game.ScreenGame.GScrState;
import mightypork.rogue.world.WorldProvider;
@ -121,13 +121,13 @@ public class LayerAskSave extends FadingLayer {
btn2.setAction(discard);
btn3.setAction(cancel);
bindKey(Config.getKeyStroke("general.close"), Edge.RISING, cancel);
bindKey(Config.getKeyStroke("general.cancel"), Edge.RISING, cancel);
bindKey(Config.getKeyStroke("general.close"), Trigger.RISING, cancel);
bindKey(Config.getKeyStroke("general.cancel"), Trigger.RISING, cancel);
bindKey(Config.getKeyStroke("general.yes"), Edge.RISING, save);
bindKey(Config.getKeyStroke("general.confirm"), Edge.RISING, save);
bindKey(Config.getKeyStroke("general.yes"), Trigger.RISING, save);
bindKey(Config.getKeyStroke("general.confirm"), Trigger.RISING, save);
bindKey(Config.getKeyStroke("general.no"), Edge.RISING, discard);
bindKey(Config.getKeyStroke("general.no"), Trigger.RISING, discard);
}

@ -14,7 +14,7 @@ import mightypork.gamecore.gui.components.painters.ImagePainter;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.impl.FadingLayer;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.RogueStateRequest;
@ -89,9 +89,9 @@ public class LayerDeath extends FadingLayer {
btn1.setAction(load);
btn2.setAction(quit);
bindKey(Config.getKeyStroke("game.load"), Edge.RISING, load);
bindKey(Config.getKeyStroke("general.confirm"), Edge.RISING, load);
bindKey(Config.getKeyStroke("general.close"), Edge.RISING, quit);
bindKey(Config.getKeyStroke("game.load"), Trigger.RISING, load);
bindKey(Config.getKeyStroke("general.confirm"), Trigger.RISING, load);
bindKey(Config.getKeyStroke("general.close"), Trigger.RISING, quit);
}

@ -8,7 +8,7 @@ import mightypork.gamecore.gui.components.layout.GridLayout;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.impl.FadingLayer;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.screens.game.ScreenGame.GScrState;
@ -155,7 +155,7 @@ public class LayerInv extends FadingLayer {
gl.put(txp2, pos, 0, 1, 1);
txp2.setVPaddingPercent(25);
bindKey(keyClose, Edge.RISING, new Runnable() {
bindKey(keyClose, Trigger.RISING, new Runnable() {
@Override
public void run()
@ -165,7 +165,7 @@ public class LayerInv extends FadingLayer {
}
});
bindKey(keyUse, Edge.RISING, new Runnable() {
bindKey(keyUse, Trigger.RISING, new Runnable() {
@Override
public void run()
@ -178,7 +178,7 @@ public class LayerInv extends FadingLayer {
}
});
bindKey(keyDrop, Edge.RISING, new Runnable() {
bindKey(keyDrop, Trigger.RISING, new Runnable() {
@Override
public void run()
@ -233,7 +233,7 @@ public class LayerInv extends FadingLayer {
private void setupGridWalkKeys()
{
bindKey(Config.getKeyStroke("game.inv.move.left"), Edge.RISING, new Runnable() {
bindKey(Config.getKeyStroke("game.inv.move.left"), Trigger.RISING, new Runnable() {
@Override
public void run()
@ -250,7 +250,7 @@ public class LayerInv extends FadingLayer {
}
});
bindKey(Config.getKeyStroke("game.inv.move.right"), Edge.RISING, new Runnable() {
bindKey(Config.getKeyStroke("game.inv.move.right"), Trigger.RISING, new Runnable() {
@Override
public void run()
@ -267,7 +267,7 @@ public class LayerInv extends FadingLayer {
}
});
bindKey(Config.getKeyStroke("game.inv.move.up"), Edge.RISING, new Runnable() {
bindKey(Config.getKeyStroke("game.inv.move.up"), Trigger.RISING, new Runnable() {
@Override
public void run()
@ -284,7 +284,7 @@ public class LayerInv extends FadingLayer {
}
});
bindKey(Config.getKeyStroke("game.inv.move.down"), Edge.RISING, new Runnable() {
bindKey(Config.getKeyStroke("game.inv.move.down"), Trigger.RISING, new Runnable() {
@Override
public void run()

@ -13,7 +13,7 @@ import mightypork.gamecore.gui.components.painters.ImagePainter;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.impl.FadingLayer;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.RogueStateRequest;
@ -69,8 +69,8 @@ public class LayerWin extends FadingLayer {
btn1.setAction(quit);
bindKey(Config.getKeyStroke("general.confirm"), Edge.RISING, quit);
bindKey(Config.getKeyStroke("general.close"), Edge.RISING, quit);
bindKey(Config.getKeyStroke("general.confirm"), Trigger.RISING, quit);
bindKey(Config.getKeyStroke("general.close"), Trigger.RISING, quit);
}

@ -7,7 +7,7 @@ import mightypork.gamecore.core.config.Config;
import mightypork.gamecore.core.events.UserQuitRequest;
import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.ActionGroup;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.Const;
import mightypork.rogue.RogueStateManager.RogueState;
@ -246,17 +246,17 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler, GameW
addLayer(worldLayer = new LayerMapView(this));
addLayer(askSaveLayer = new LayerAskSave(this));
bindKey(Config.getKeyStroke("game.pause"), Edge.RISING, actionTogglePause);
bindKey(Config.getKeyStroke("game.pause"), Trigger.RISING, actionTogglePause);
bindKey(Config.getKeyStroke("game.inventory"), Edge.RISING, actionToggleInv);
bindKey(Config.getKeyStroke("game.drop"), Edge.RISING, actionDropLastPickedItem);
bindKey(Config.getKeyStroke("game.eat"), Edge.RISING, actionEat);
bindKey(Config.getKeyStroke("game.minimap"), Edge.RISING, actionToggleMinimap);
bindKey(Config.getKeyStroke("game.zoom"), Edge.RISING, actionToggleZoom);
bindKey(Config.getKeyStroke("game.inventory"), Trigger.RISING, actionToggleInv);
bindKey(Config.getKeyStroke("game.drop"), Trigger.RISING, actionDropLastPickedItem);
bindKey(Config.getKeyStroke("game.eat"), Trigger.RISING, actionEat);
bindKey(Config.getKeyStroke("game.minimap"), Trigger.RISING, actionToggleMinimap);
bindKey(Config.getKeyStroke("game.zoom"), Trigger.RISING, actionToggleZoom);
bindKey(Config.getKeyStroke("game.load"), Edge.RISING, actionLoad);
bindKey(Config.getKeyStroke("game.save"), Edge.RISING, actionSave);
bindKey(Config.getKeyStroke("game.quit"), Edge.RISING, actionMenu);
bindKey(Config.getKeyStroke("game.load"), Trigger.RISING, actionLoad);
bindKey(Config.getKeyStroke("game.save"), Trigger.RISING, actionSave);
bindKey(Config.getKeyStroke("game.quit"), Trigger.RISING, actionMenu);
// bindKey(new KeyStroke(Keys.W), Edge.RISING, new Runnable() {
//
@ -284,7 +284,7 @@ public class ScreenGame extends RogueScreen implements PlayerDeathHandler, GameW
worldActions.setEnabled(true);
// CHEAT - X-ray
bindKey(Config.getKeyStroke("game.cheat.xray"), Edge.RISING, new Runnable() {
bindKey(Config.getKeyStroke("game.cheat.xray"), Trigger.RISING, new Runnable() {
@Override
public void run()

@ -12,7 +12,7 @@ import mightypork.gamecore.gui.components.painters.ImagePainter;
import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.RogueStateRequest;
@ -103,7 +103,7 @@ public class ScreenMainMenu extends RogueScreen {
});
rows.add(btn, 2);
bindKey(Config.getKeyStroke("general.close"), Edge.RISING, new Runnable() {
bindKey(Config.getKeyStroke("general.close"), Trigger.RISING, new Runnable() {
@Override
public void run()

@ -8,7 +8,7 @@ import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.resources.Res;
import mightypork.rogue.RogueStateManager.RogueState;
import mightypork.rogue.events.RogueStateRequest;
@ -76,7 +76,7 @@ public class ScreenSelectWorld extends RogueScreen {
rows.add(slot3);
// escape to quitn from here
bindKey(Config.getKeyStroke("general.close"), Edge.RISING, new Runnable() {
bindKey(Config.getKeyStroke("general.close"), Trigger.RISING, new Runnable() {
@Override
public void run()

@ -10,7 +10,7 @@ import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.gui.screens.impl.LayerColor;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.input.events.MouseButtonEvent;
@ -213,11 +213,11 @@ public class ScreenStory extends RogueScreen implements MouseButtonHandler {
addLayer(new LayerColor(this, Color.fromHex(0x040c1e), 0));
addLayer(slideLayer = new LayerSlide(this));
bindKey(new KeyStroke(Keys.SPACE), Edge.RISING, next);
bindKey(new KeyStroke(Keys.RIGHT), Edge.RISING, next);
bindKey(new KeyStroke(Keys.BACKSPACE), Edge.RISING, prev);
bindKey(new KeyStroke(Keys.LEFT), Edge.RISING, prev);
bindKey(Config.getKeyStroke("general.close"), Edge.RISING, close);
bindKey(new KeyStroke(Keys.SPACE), Trigger.RISING, next);
bindKey(new KeyStroke(Keys.RIGHT), Trigger.RISING, next);
bindKey(new KeyStroke(Keys.BACKSPACE), Trigger.RISING, prev);
bindKey(new KeyStroke(Keys.LEFT), Trigger.RISING, prev);
bindKey(Config.getKeyStroke("general.close"), Trigger.RISING, close);
}
private int slide = 0;

@ -7,7 +7,7 @@ import java.util.List;
import mightypork.gamecore.backends.lwjgl.LwjglInputModule;
import mightypork.gamecore.core.config.Config;
import mightypork.gamecore.input.Edge;
import mightypork.gamecore.input.Trigger;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys;
@ -63,7 +63,7 @@ public class MIPKeyboard extends MapInteractionPlugin implements DelegatingClien
for (int i = 0; i < 4; i++) {
final int j = i;
kbp.bindKey(keys[i], Edge.RISING, new Runnable() {
kbp.bindKey(keys[i], Trigger.RISING, new Runnable() {
@Override
public void run()
@ -103,7 +103,7 @@ public class MIPKeyboard extends MapInteractionPlugin implements DelegatingClien
if (mapView.plc.getPlayer().getMoveProgress() < 0.8) return false;
if (LwjglInputModule.getActiveModKeys() != Keys.MOD_NONE) return false;
if (LwjglInputModule.getActiveKeyMod() != Keys.MOD_NONE) return false;
for (int i = 0; i < 4; i++) {
if (keys[i].isDown()) {

Loading…
Cancel
Save