use of org.terasology.input.Input in project Terasology by MovingBlocks.
the class ChangeBindingPopup method initialise.
@Override
public void initialise() {
defaultBinds = bindsManager.getDefaultBindsConfig();
bindButton = find("new-binding", UIInputBind.class);
WidgetUtil.trySubscribe(this, "remove", button -> bindButton.setNewInput(null));
WidgetUtil.trySubscribe(this, "ok", button -> {
Input newInput = bindButton.getNewInput();
currBinds = bindsManager.getBindsConfig();
if (currBinds.isBound(newInput) && !newInput.equals(bindButton.getInput())) {
ConfirmChangePopup popup = getManager().pushScreen(ConfirmChangePopup.ASSET_URI, ConfirmChangePopup.class);
popup.setButtonData(bindButton);
} else {
bindButton.saveInput();
getManager().popScreen();
}
});
WidgetUtil.trySubscribe(this, "cancel", button -> getManager().popScreen());
}
use of org.terasology.input.Input in project Terasology by MovingBlocks.
the class LocalPlayerSystem method startAutoMove.
/**
* Append the input for moving forward to the keyboard command queue to simulate pressing of the forward key.
* For an input that repeats, the key must be in Down state before Repeat state can be applied to it.
*/
private void startAutoMove() {
isAutoMove = false;
List<Input> inputs = bindsManager.getBindsConfig().getBinds(new SimpleUri("engine:forwards"));
Input forwardKey = getValidKey(inputs);
if (forwardKey != null) {
isAutoMove = true;
inputSystem.simulateSingleKeyStroke(forwardKey);
inputSystem.simulateRepeatedKeyStroke(forwardKey);
}
}
use of org.terasology.input.Input in project Terasology by MovingBlocks.
the class JInputControllerDevice method convertEvent.
private ControllerAction convertEvent(Controller c, Event event) {
Component comp = event.getComponent();
Identifier id = comp.getIdentifier();
float axisValue = comp.getPollData();
Input input;
ButtonState state = ButtonState.UP;
if (id instanceof Identifier.Button) {
state = event.getValue() != 0 ? ButtonState.DOWN : ButtonState.UP;
Integer buttonId = buttonMap.get(id);
if (buttonId == null) {
// button not registered
return null;
}
input = InputType.CONTROLLER_BUTTON.getInput(buttonId);
} else if (id instanceof Identifier.Axis) {
ControllerInfo info = config.getController(c.getName());
if (id.equals(Identifier.Axis.X)) {
if (Math.abs(axisValue) < info.getMovementDeadZone()) {
axisValue = 0;
}
input = InputType.CONTROLLER_AXIS.getInput(ControllerId.X_AXIS);
} else if (id.equals(Identifier.Axis.Y)) {
if (Math.abs(axisValue) < info.getMovementDeadZone()) {
axisValue = 0;
}
input = InputType.CONTROLLER_AXIS.getInput(ControllerId.Y_AXIS);
} else if (id.equals(Identifier.Axis.Z)) {
if (Math.abs(axisValue) < info.getMovementDeadZone()) {
axisValue = 0;
}
input = InputType.CONTROLLER_AXIS.getInput(ControllerId.Z_AXIS);
} else if (id.equals(Identifier.Axis.RX)) {
if (Math.abs(axisValue) < info.getRotationDeadZone()) {
axisValue = 0;
}
input = InputType.CONTROLLER_AXIS.getInput(ControllerId.RX_AXIS);
} else if (id.equals(Identifier.Axis.RY)) {
if (Math.abs(axisValue) < info.getRotationDeadZone()) {
axisValue = 0;
}
input = InputType.CONTROLLER_AXIS.getInput(ControllerId.RY_AXIS);
} else if (id.equals(Identifier.Axis.POV)) {
// the poll data float value is actually an ID in this case
boolean isX = (axisValue == Component.POV.LEFT) || (axisValue == Component.POV.RIGHT);
boolean isY = (axisValue == Component.POV.UP) || (axisValue == Component.POV.DOWN);
if (isX || isY) {
input = InputType.CONTROLLER_AXIS.getInput(isX ? ControllerId.POVX_AXIS : ControllerId.POVY_AXIS);
if ((axisValue == Component.POV.UP) || (axisValue == Component.POV.LEFT)) {
axisValue = -1;
}
if ((axisValue == Component.POV.DOWN) || (axisValue == Component.POV.RIGHT)) {
axisValue = 1;
}
} else {
// TODO: handle 8-button POVs
return null;
}
} else {
// unrecognized axis
return null;
}
} else {
// unrecognized id (e.g. Identifier.Key)
return null;
}
return new ControllerAction(input, c.getName(), state, axisValue);
}
use of org.terasology.input.Input in project Terasology by MovingBlocks.
the class LwjglKeyboardDevice method getInputQueue.
@Override
public Queue<KeyboardAction> getInputQueue() {
Queue<KeyboardAction> result = Queues.newArrayDeque();
while (Keyboard.next()) {
ButtonState state;
if (Keyboard.isRepeatEvent()) {
state = ButtonState.REPEAT;
} else {
state = (Keyboard.getEventKeyState()) ? ButtonState.DOWN : ButtonState.UP;
}
Input input = InputType.KEY.getInput(Keyboard.getEventKey());
result.add(new KeyboardAction(input, state, Keyboard.getEventCharacter()));
}
return result;
}
use of org.terasology.input.Input in project Terasology by MovingBlocks.
the class BindsSubsystemTest method testUpdateBinds.
@Test
public void testUpdateBinds() {
registerBindButtonClasses.add(TestEventButton.class);
bindsSubsystem.updateConfigWithDefaultBinds();
List<Input> defaultBinds = bindsSubsystem.getDefaultBindsConfig().getBinds(new SimpleUri(TEST_MODULE, "testEvent"));
assertThat(defaultBinds.size(), is(1));
assertThat(defaultBinds.get(0).getType(), is(InputType.KEY));
assertThat(defaultBinds.get(0).getId(), is(KeyId.T));
assertThat(defaultBinds.get(0).getName(), is(Key.T.getName()));
assertThat(defaultBinds.get(0).getDisplayName(), is(Key.T.getDisplayName()));
List<Input> binds = bindsSubsystem.getBindsConfig().getBinds(new SimpleUri(TEST_MODULE, "testEvent"));
assertThat(binds.size(), is(1));
assertThat(binds.get(0).getType(), is(InputType.KEY));
assertThat(binds.get(0).getId(), is(KeyId.T));
assertThat(binds.get(0).getName(), is(Key.T.getName()));
assertThat(binds.get(0).getDisplayName(), is(Key.T.getDisplayName()));
}
Aggregations