Search in sources :

Example 1 with BindableButtonImpl

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));
}
Also used : BindableButton(org.terasology.engine.input.BindableButton) HashMap(java.util.HashMap) SimpleUri(org.terasology.engine.core.SimpleUri) BindableButtonImpl(org.terasology.engine.input.internal.BindableButtonImpl) Test(org.junit.jupiter.api.Test)

Example 2 with BindableButtonImpl

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

Example 3 with BindableButtonImpl

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;
}
Also used : BindableButton(org.terasology.engine.input.BindableButton) BindButtonEvent(org.terasology.engine.input.BindButtonEvent) BindButtonSubscriber(org.terasology.engine.input.BindButtonSubscriber) SimpleUri(org.terasology.engine.core.SimpleUri) BindableButtonImpl(org.terasology.engine.input.internal.BindableButtonImpl) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Aggregations

BindableButtonImpl (org.terasology.engine.input.internal.BindableButtonImpl)3 SimpleUri (org.terasology.engine.core.SimpleUri)2 BindableButton (org.terasology.engine.input.BindableButton)2 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 BindButtonEvent (org.terasology.engine.input.BindButtonEvent)1 BindButtonSubscriber (org.terasology.engine.input.BindButtonSubscriber)1