Search in sources :

Example 1 with BindButtonSubscriber

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

SimpleUri (org.terasology.engine.core.SimpleUri)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 BindButtonEvent (org.terasology.engine.input.BindButtonEvent)1 BindButtonSubscriber (org.terasology.engine.input.BindButtonSubscriber)1 BindableButton (org.terasology.engine.input.BindableButton)1 BindableButtonImpl (org.terasology.engine.input.internal.BindableButtonImpl)1