Search in sources :

Example 1 with Input

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());
}
Also used : Input(org.terasology.input.Input)

Example 2 with Input

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);
    }
}
Also used : Input(org.terasology.input.Input) SimpleUri(org.terasology.engine.SimpleUri)

Example 3 with Input

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);
}
Also used : Input(org.terasology.input.Input) Identifier(net.java.games.input.Component.Identifier) Button(net.java.games.input.Component.Identifier.Button) Component(net.java.games.input.Component) ButtonState(org.terasology.input.ButtonState) ControllerInfo(org.terasology.config.ControllerConfig.ControllerInfo) ControllerAction(org.terasology.input.device.ControllerAction)

Example 4 with Input

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;
}
Also used : Input(org.terasology.input.Input) KeyboardAction(org.terasology.input.device.KeyboardAction) ButtonState(org.terasology.input.ButtonState)

Example 5 with Input

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()));
}
Also used : Input(org.terasology.input.Input) SimpleUri(org.terasology.engine.SimpleUri) Test(org.junit.Test)

Aggregations

Input (org.terasology.input.Input)14 SimpleUri (org.terasology.engine.SimpleUri)6 BindsConfig (org.terasology.config.BindsConfig)3 ControllerInput (org.terasology.input.ControllerInput)3 DefaultBinding (org.terasology.input.DefaultBinding)3 MouseInput (org.terasology.input.MouseInput)3 Annotation (java.lang.annotation.Annotation)2 Map (java.util.Map)2 ModuleManager (org.terasology.engine.module.ModuleManager)2 BindAxisEvent (org.terasology.input.BindAxisEvent)2 BindableAxis (org.terasology.input.BindableAxis)2 ButtonState (org.terasology.input.ButtonState)2 RegisterBindButton (org.terasology.input.RegisterBindButton)2 RegisterRealBindAxis (org.terasology.input.RegisterRealBindAxis)2 AbstractBindableAxis (org.terasology.input.internal.AbstractBindableAxis)2 Name (org.terasology.naming.Name)2 UIButton (org.terasology.rendering.nui.widgets.UIButton)2 UILabel (org.terasology.rendering.nui.widgets.UILabel)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Lists (com.google.common.collect.Lists)1