Search in sources :

Example 1 with BindButtonEvent

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

the class EventCopier method copyEvent.

public Event copyEvent(Event toBeCopied) {
    if (toBeCopied instanceof PlaySoundEvent) {
        return toBeCopied;
    } else if (toBeCopied instanceof BindButtonEvent) {
        BindButtonEvent originalEvent = (BindButtonEvent) toBeCopied;
        BindButtonEvent newEvent = (BindButtonEvent) createNewBindEvent(originalEvent);
        newEvent.prepare(originalEvent.getId(), originalEvent.getState(), originalEvent.getDelta());
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof KeyEvent) {
        KeyEvent originalEvent = (KeyEvent) toBeCopied;
        KeyEvent newEvent = createNewKeyEvent(originalEvent);
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof BindAxisEvent) {
        BindAxisEvent originalEvent = (BindAxisEvent) toBeCopied;
        BindAxisEvent newEvent = (BindAxisEvent) createNewBindEvent(originalEvent);
        newEvent.prepare(originalEvent.getId(), (float) originalEvent.getValue(), originalEvent.getDelta());
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof MouseAxisEvent) {
        MouseAxisEvent originalEvent = (MouseAxisEvent) toBeCopied;
        MouseAxisEvent newEvent = createNewMouseAxisEvent(originalEvent);
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof CameraTargetChangedEvent) {
        CameraTargetChangedEvent originalEvent = (CameraTargetChangedEvent) toBeCopied;
        return new CameraTargetChangedEvent(originalEvent.getOldTarget(), originalEvent.getNewTarget());
    } else if (toBeCopied instanceof CharacterMoveInputEvent) {
        CharacterMoveInputEvent originalEvent = (CharacterMoveInputEvent) toBeCopied;
        return new CharacterMoveInputEvent(originalEvent.getSequenceNumber(), originalEvent.getPitch(), originalEvent.getYaw(), originalEvent.getMovementDirection(), originalEvent.isRunning(), originalEvent.isCrouching(), originalEvent.isJumping(), originalEvent.getDeltaMs());
    } else if (toBeCopied instanceof MouseButtonEvent) {
        MouseButtonEvent originalEvent = (MouseButtonEvent) toBeCopied;
        MouseButtonEvent newEvent = new MouseButtonEvent(originalEvent.getButton(), originalEvent.getState(), originalEvent.getDelta());
        newEvent.setMousePosition(originalEvent.getMousePosition());
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof MouseWheelEvent) {
        MouseWheelEvent originalEvent = (MouseWheelEvent) toBeCopied;
        MouseWheelEvent newEvent = new MouseWheelEvent(originalEvent.getMousePosition(), originalEvent.getWheelTurns(), originalEvent.getDelta());
        inputEventSetup(newEvent, originalEvent);
        return newEvent;
    } else if (toBeCopied instanceof GetMaxSpeedEvent) {
        GetMaxSpeedEvent originalEvent = (GetMaxSpeedEvent) toBeCopied;
        GetMaxSpeedEvent newEvent = new GetMaxSpeedEvent(originalEvent.getBaseValue(), originalEvent.getMovementMode());
        newEvent.setModifiers(originalEvent.getModifiers());
        newEvent.setMultipliers(originalEvent.getMultipliers());
        newEvent.setPostModifiers(originalEvent.getPostModifiers());
        return newEvent;
    } else if (toBeCopied instanceof AttackEvent) {
        AttackEvent originalEvent = (AttackEvent) toBeCopied;
        AttackEvent newEvent = new AttackEvent(originalEvent.getInstigator(), originalEvent.getDirectCause());
        return newEvent;
    } else {
        return null;
    }
}
Also used : KeyEvent(org.terasology.engine.input.events.KeyEvent) CameraTargetChangedEvent(org.terasology.engine.input.cameraTarget.CameraTargetChangedEvent) BindButtonEvent(org.terasology.engine.input.BindButtonEvent) MouseWheelEvent(org.terasology.engine.input.events.MouseWheelEvent) GetMaxSpeedEvent(org.terasology.engine.logic.characters.GetMaxSpeedEvent) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) BindAxisEvent(org.terasology.engine.input.BindAxisEvent) MouseAxisEvent(org.terasology.engine.input.events.MouseAxisEvent) CharacterMoveInputEvent(org.terasology.engine.logic.characters.CharacterMoveInputEvent) MouseButtonEvent(org.terasology.engine.input.events.MouseButtonEvent) AttackEvent(org.terasology.engine.logic.characters.events.AttackEvent)

Example 2 with BindButtonEvent

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

the class BindsSubsystem method registerButtonBinds.

private void registerButtonBinds(ModuleEnvironment environment) {
    Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterBindButton.class);
    for (Class<?> registerBindClass : classes) {
        RegisterBindButton info = registerBindClass.getAnnotation(RegisterBindButton.class);
        SimpleUri bindUri = new SimpleUri(environment.getModuleProviding(registerBindClass), info.id());
        if (BindButtonEvent.class.isAssignableFrom(registerBindClass)) {
            try {
                BindableButton bindButton = registerBindButton(bindUri, info.description(), (BindButtonEvent) registerBindClass.newInstance());
                bindButton.setMode(info.mode());
                bindButton.setRepeating(info.repeating());
                bindsConfiguration.getBinds(bindUri).stream().filter(input -> input != null).forEach(input -> linkBindButtonToInput(input, bindUri));
                logger.debug("Registered button bind: {}", bindUri);
            } catch (InstantiationException | IllegalAccessException e) {
                logger.error("Failed to register button bind \"{}\"", e);
            }
        } else {
            logger.error("Failed to register button bind \"{}\", does not extend BindButtonEvent", bindUri);
        }
    }
}
Also used : RegisterBindButton(org.terasology.engine.input.RegisterBindButton) BindsConfiguration(org.terasology.engine.config.facade.BindsConfiguration) BindAxisEvent(org.terasology.engine.input.BindAxisEvent) ModuleManager(org.terasology.engine.core.module.ModuleManager) RegisterBindAxis(org.terasology.engine.input.RegisterBindAxis) ControllerInput(org.terasology.input.ControllerInput) LoggerFactory(org.slf4j.LoggerFactory) BindsConfig(org.terasology.engine.config.BindsConfig) FromModule(org.terasology.gestalt.module.predicates.FromModule) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) Lists(com.google.common.collect.Lists) DefaultBinding(org.terasology.engine.input.DefaultBinding) Map(java.util.Map) Input(org.terasology.input.Input) RegisterRealBindAxis(org.terasology.engine.input.RegisterRealBindAxis) AbstractBindableAxis(org.terasology.engine.input.internal.AbstractBindableAxis) MouseInput(org.terasology.input.MouseInput) BindableButtonImpl(org.terasology.engine.input.internal.BindableButtonImpl) InputType(org.terasology.input.InputType) Logger(org.slf4j.Logger) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) Collection(java.util.Collection) AxisEvent(org.terasology.engine.input.events.AxisEvent) BindableAxisImpl(org.terasology.engine.input.internal.BindableAxisImpl) BindButtonEvent(org.terasology.engine.input.BindButtonEvent) Maps(com.google.common.collect.Maps) BindableButton(org.terasology.engine.input.BindableButton) SimpleUri(org.terasology.engine.core.SimpleUri) EngineSubsystem(org.terasology.engine.core.subsystem.EngineSubsystem) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) List(java.util.List) Context(org.terasology.engine.context.Context) Config(org.terasology.engine.config.Config) Annotation(java.lang.annotation.Annotation) BindableAxis(org.terasology.engine.input.BindableAxis) BindableRealAxis(org.terasology.engine.input.internal.BindableRealAxis) ButtonEvent(org.terasology.engine.input.events.ButtonEvent) Name(org.terasology.gestalt.naming.Name) BindableButton(org.terasology.engine.input.BindableButton) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) SimpleUri(org.terasology.engine.core.SimpleUri)

Example 3 with BindButtonEvent

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

BindButtonEvent (org.terasology.engine.input.BindButtonEvent)3 SimpleUri (org.terasology.engine.core.SimpleUri)2 BindAxisEvent (org.terasology.engine.input.BindAxisEvent)2 BindableButton (org.terasology.engine.input.BindableButton)2 BindableButtonImpl (org.terasology.engine.input.internal.BindableButtonImpl)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 List (java.util.List)1 Map (java.util.Map)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)1 BindsConfig (org.terasology.engine.config.BindsConfig)1 Config (org.terasology.engine.config.Config)1 BindsConfiguration (org.terasology.engine.config.facade.BindsConfiguration)1 Context (org.terasology.engine.context.Context)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1