Search in sources :

Example 1 with BindableButton

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

the class BindsSubsystem method registerAxisBinds.

private void registerAxisBinds(ModuleEnvironment environment) {
    Iterable<Class<?>> classes = environment.getTypesAnnotatedWith(RegisterBindAxis.class);
    for (Class<?> registerBindClass : classes) {
        RegisterBindAxis info = registerBindClass.getAnnotation(RegisterBindAxis.class);
        Name moduleId = environment.getModuleProviding(registerBindClass);
        SimpleUri id = new SimpleUri(moduleId, info.id());
        if (BindAxisEvent.class.isAssignableFrom(registerBindClass)) {
            BindableButton positiveButton = getBindButton(new SimpleUri(info.positiveButton()));
            BindableButton negativeButton = getBindButton(new SimpleUri(info.negativeButton()));
            if (positiveButton == null) {
                logger.warn("Failed to register axis \"{}\", missing positive button \"{}\"", id, info.positiveButton());
                continue;
            }
            if (negativeButton == null) {
                logger.warn("Failed to register axis \"{}\", missing negative button \"{}\"", id, info.negativeButton());
                continue;
            }
            try {
                BindableAxis bindAxis = registerBindAxis(id.toString(), (BindAxisEvent) registerBindClass.newInstance(), positiveButton, negativeButton);
                bindAxis.setSendEventMode(info.eventMode());
                logger.debug("Registered axis bind: {}", id);
            } catch (InstantiationException | IllegalAccessException e) {
                logger.error("Failed to register axis bind \"{}\"", id, e);
            }
        } else {
            logger.error("Failed to register axis bind \"{}\", does not extend BindAxisEvent", id);
        }
    }
}
Also used : BindableButton(org.terasology.input.BindableButton) RegisterBindAxis(org.terasology.input.RegisterBindAxis) SimpleUri(org.terasology.engine.SimpleUri) AbstractBindableAxis(org.terasology.input.internal.AbstractBindableAxis) BindableAxis(org.terasology.input.BindableAxis) Name(org.terasology.naming.Name)

Example 2 with BindableButton

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

Example 3 with BindableButton

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

the class BindsSubsystem method linkBindButtonToController.

private void linkBindButtonToController(ControllerInput button, SimpleUri bindId) {
    BindableButton bindInfo = buttonLookup.get(bindId);
    controllerBinds.put(button, bindInfo);
}
Also used : BindableButton(org.terasology.input.BindableButton)

Example 4 with BindableButton

use of org.terasology.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);
    assertThat(button, is(not(nullValue())));
    assertThat(button.getId(), is(new SimpleUri(TEST_MODULE, "testEvent")));
    assertThat(button.getDisplayName(), is("${engine-tests:menu#theTestEvent}"));
}
Also used : BindableButton(org.terasology.input.BindableButton) SimpleUri(org.terasology.engine.SimpleUri) Test(org.junit.Test)

Example 5 with BindableButton

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

the class BindsSubsystem method linkBindButtonToKey.

@Override
public void linkBindButtonToKey(int key, SimpleUri bindId) {
    BindableButton bindInfo = buttonLookup.get(bindId);
    keyBinds.put(key, bindInfo);
}
Also used : BindableButton(org.terasology.input.BindableButton)

Aggregations

BindableButton (org.terasology.input.BindableButton)6 SimpleUri (org.terasology.engine.SimpleUri)3 BindableAxis (org.terasology.input.BindableAxis)2 RegisterBindAxis (org.terasology.input.RegisterBindAxis)2 AbstractBindableAxis (org.terasology.input.internal.AbstractBindableAxis)2 Name (org.terasology.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 List (java.util.List)1 Map (java.util.Map)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 BindsConfig (org.terasology.config.BindsConfig)1 Config (org.terasology.config.Config)1 BindsConfiguration (org.terasology.config.facade.BindsConfiguration)1 Context (org.terasology.context.Context)1