Search in sources :

Example 6 with BindableButton

use of org.terasology.engine.input.BindableButton in project Terasology by MovingBlocks.

the class BindsSubsystem method linkBindButtonToMouse.

private void linkBindButtonToMouse(MouseInput mouseButton, SimpleUri bindId) {
    BindableButton bindInfo = buttonLookup.get(bindId);
    mouseButtonBinds.put(mouseButton, bindInfo);
}
Also used : BindableButton(org.terasology.engine.input.BindableButton)

Example 7 with BindableButton

use of org.terasology.engine.input.BindableButton in project Terasology by MovingBlocks.

the class BindsSubsystemTest method testRegisterBinds.

@Test
public void testRegisterBinds() {
    registerBindButtonClasses.add(TestEventButton.class);
    bindsSubsystem.updateConfigWithDefaultBinds();
    bindsSubsystem.registerBinds();
    BindableButton button = bindsSubsystem.getKeyBinds().get(KeyId.T);
    assertNotNull(button);
    assertEquals(button.getId(), new SimpleUri(TEST_MODULE, "testEvent"));
    assertEquals(button.getDisplayName(), "${engine-tests:menu#theTestEvent}");
}
Also used : BindableButton(org.terasology.engine.input.BindableButton) SimpleUri(org.terasology.engine.core.SimpleUri) Test(org.junit.jupiter.api.Test)

Example 8 with BindableButton

use of org.terasology.engine.input.BindableButton 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

BindableButton (org.terasology.engine.input.BindableButton)8 SimpleUri (org.terasology.engine.core.SimpleUri)5 BindableButtonImpl (org.terasology.engine.input.internal.BindableButtonImpl)3 Test (org.junit.jupiter.api.Test)2 BindButtonEvent (org.terasology.engine.input.BindButtonEvent)2 BindableAxis (org.terasology.engine.input.BindableAxis)2 RegisterBindAxis (org.terasology.engine.input.RegisterBindAxis)2 AbstractBindableAxis (org.terasology.engine.input.internal.AbstractBindableAxis)2 Name (org.terasology.gestalt.naming.Name)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Annotation (java.lang.annotation.Annotation)1 Collection (java.util.Collection)1 Collections.unmodifiableCollection (java.util.Collections.unmodifiableCollection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 BindsConfig (org.terasology.engine.config.BindsConfig)1