Search in sources :

Example 6 with BindableButton

use of org.terasology.input.BindableButton 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 : BindsConfiguration(org.terasology.config.facade.BindsConfiguration) EngineSubsystem(org.terasology.engine.subsystem.EngineSubsystem) DependencyResolver(org.terasology.module.DependencyResolver) ControllerInput(org.terasology.input.ControllerInput) LoggerFactory(org.slf4j.LoggerFactory) Config(org.terasology.config.Config) RegisterBindAxis(org.terasology.input.RegisterBindAxis) FromModule(org.terasology.module.predicates.FromModule) Collections.unmodifiableCollection(java.util.Collections.unmodifiableCollection) Lists(com.google.common.collect.Lists) ButtonEvent(org.terasology.input.events.ButtonEvent) ResolutionResult(org.terasology.module.ResolutionResult) Map(java.util.Map) Input(org.terasology.input.Input) BindableRealAxis(org.terasology.input.internal.BindableRealAxis) SimpleUri(org.terasology.engine.SimpleUri) MouseInput(org.terasology.input.MouseInput) BindAxisEvent(org.terasology.input.BindAxisEvent) BindableButton(org.terasology.input.BindableButton) AxisEvent(org.terasology.input.events.AxisEvent) AbstractBindableAxis(org.terasology.input.internal.AbstractBindableAxis) Name(org.terasology.naming.Name) ModuleManager(org.terasology.engine.module.ModuleManager) InputType(org.terasology.input.InputType) Context(org.terasology.context.Context) Logger(org.slf4j.Logger) BindableAxis(org.terasology.input.BindableAxis) Collection(java.util.Collection) ModuleEnvironment(org.terasology.module.ModuleEnvironment) BindableAxisImpl(org.terasology.input.internal.BindableAxisImpl) Maps(com.google.common.collect.Maps) List(java.util.List) BindsConfig(org.terasology.config.BindsConfig) DefaultBinding(org.terasology.input.DefaultBinding) RegisterBindButton(org.terasology.input.RegisterBindButton) BindButtonEvent(org.terasology.input.BindButtonEvent) Annotation(java.lang.annotation.Annotation) RegisterRealBindAxis(org.terasology.input.RegisterRealBindAxis) BindableButtonImpl(org.terasology.input.internal.BindableButtonImpl) BindableButton(org.terasology.input.BindableButton) RegisterBindButton(org.terasology.input.RegisterBindButton) SimpleUri(org.terasology.engine.SimpleUri)

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