use of org.terasology.engine.input.internal.BindableButtonImpl in project Terasology by MovingBlocks.
the class InputSystemTests method testKeyBinding.
@Test
public void testKeyBinding() {
Map<Integer, BindableButton> keyBinds = new HashMap<>();
// mock binding to the TestEventButton, this is done by the BindsManager over the annotations by default
keyBinds.put(KeyId.T, new BindableButtonImpl(new SimpleUri("engine-tests", "testEvent"), "theTestEvent", new TestEventButton()));
when(bindsManager.getKeyBinds()).thenReturn(keyBinds);
pressKey(Key.T);
inputSystem.update(1f);
verify(clientEntity).send(Mockito.any(TestEventButton.class));
}
use of org.terasology.engine.input.internal.BindableButtonImpl in project Terasology by MovingBlocks.
the class BindsSubsystem method registerBindButton.
private BindableButton registerBindButton(SimpleUri bindId, String displayName, BindButtonEvent event) {
BindableButtonImpl bind = new BindableButtonImpl(bindId, displayName, event);
buttonLookup.put(bindId, bind);
buttonBinds.add(bind);
return bind;
}
use of org.terasology.engine.input.internal.BindableButtonImpl in project Terasology by MovingBlocks.
the class SortOrderSystem method postBegin.
/**
* Initializes sort order.
*/
public void postBegin() {
initialized = true;
controlPressed = false;
Map<Integer, BindableButton> keys = bindsManager.getKeyBinds();
BindButtonSubscriber controlSubscriber = new BindButtonSubscriber() {
@Override
public boolean onPress(float delta, EntityRef target) {
if (!containsConsole()) {
controlPressed = true;
} else {
controlPressed = false;
}
return false;
}
@Override
public boolean onRepeat(float delta, EntityRef target) {
return false;
}
@Override
public boolean onRelease(float delta, EntityRef target) {
controlPressed = false;
return false;
}
};
BindButtonSubscriber tabSubscriber = new BindButtonSubscriber() {
@Override
public boolean onPress(float delta, EntityRef target) {
if (controlPressed) {
target.send(new FocusChangedEvent());
}
return false;
}
@Override
public boolean onRepeat(float delta, EntityRef target) {
if (controlPressed) {
target.send(new FocusChangedEvent());
}
return false;
}
@Override
public boolean onRelease(float delta, EntityRef target) {
return false;
}
};
if (keys.containsKey(Keyboard.Key.RIGHT_CTRL.getId())) {
keys.get(Keyboard.Key.RIGHT_CTRL.getId()).subscribe(controlSubscriber);
} else {
keys.put(Keyboard.Key.RIGHT_CTRL.getId(), new BindableButtonImpl(new SimpleUri("ctrlMod"), "Control Modifier", new BindButtonEvent()));
keys.get(Keyboard.Key.RIGHT_CTRL.getId()).subscribe(controlSubscriber);
}
if (keys.containsKey(Keyboard.Key.LEFT_CTRL.getId())) {
keys.get(Keyboard.Key.LEFT_CTRL.getId()).subscribe(controlSubscriber);
} else {
keys.put(Keyboard.Key.LEFT_CTRL.getId(), new BindableButtonImpl(new SimpleUri("ctrlMod"), "Control Modifier", new BindButtonEvent()));
keys.get(Keyboard.Key.LEFT_CTRL.getId()).subscribe(controlSubscriber);
}
if (keys.containsKey(Keyboard.Key.TAB.getId())) {
keys.get(Keyboard.Key.TAB.getId()).subscribe(tabSubscriber);
} else {
keys.put(Keyboard.Key.TAB.getId(), new BindableButtonImpl(new SimpleUri("changeFocus"), "Change Focus", new BindButtonEvent()));
keys.get(Keyboard.Key.TAB.getId()).subscribe(tabSubscriber);
}
current = 0;
index = 0;
layersFilled = new ArrayList<>();
enabledWidgets = new ArrayList<>();
used = new ArrayList<>();
inSortOrder = false;
}
Aggregations