use of org.terasology.config.ControllerConfig.ControllerInfo in project Terasology by MovingBlocks.
the class JInputControllerDevice method convertEvent.
private ControllerAction convertEvent(Controller c, Event event) {
Component comp = event.getComponent();
Identifier id = comp.getIdentifier();
float axisValue = comp.getPollData();
Input input;
ButtonState state = ButtonState.UP;
if (id instanceof Identifier.Button) {
state = event.getValue() != 0 ? ButtonState.DOWN : ButtonState.UP;
Integer buttonId = buttonMap.get(id);
if (buttonId == null) {
// button not registered
return null;
}
input = InputType.CONTROLLER_BUTTON.getInput(buttonId);
} else if (id instanceof Identifier.Axis) {
ControllerInfo info = config.getController(c.getName());
if (id.equals(Identifier.Axis.X)) {
if (Math.abs(axisValue) < info.getMovementDeadZone()) {
axisValue = 0;
}
input = InputType.CONTROLLER_AXIS.getInput(ControllerId.X_AXIS);
} else if (id.equals(Identifier.Axis.Y)) {
if (Math.abs(axisValue) < info.getMovementDeadZone()) {
axisValue = 0;
}
input = InputType.CONTROLLER_AXIS.getInput(ControllerId.Y_AXIS);
} else if (id.equals(Identifier.Axis.Z)) {
if (Math.abs(axisValue) < info.getMovementDeadZone()) {
axisValue = 0;
}
input = InputType.CONTROLLER_AXIS.getInput(ControllerId.Z_AXIS);
} else if (id.equals(Identifier.Axis.RX)) {
if (Math.abs(axisValue) < info.getRotationDeadZone()) {
axisValue = 0;
}
input = InputType.CONTROLLER_AXIS.getInput(ControllerId.RX_AXIS);
} else if (id.equals(Identifier.Axis.RY)) {
if (Math.abs(axisValue) < info.getRotationDeadZone()) {
axisValue = 0;
}
input = InputType.CONTROLLER_AXIS.getInput(ControllerId.RY_AXIS);
} else if (id.equals(Identifier.Axis.POV)) {
// the poll data float value is actually an ID in this case
boolean isX = (axisValue == Component.POV.LEFT) || (axisValue == Component.POV.RIGHT);
boolean isY = (axisValue == Component.POV.UP) || (axisValue == Component.POV.DOWN);
if (isX || isY) {
input = InputType.CONTROLLER_AXIS.getInput(isX ? ControllerId.POVX_AXIS : ControllerId.POVY_AXIS);
if ((axisValue == Component.POV.UP) || (axisValue == Component.POV.LEFT)) {
axisValue = -1;
}
if ((axisValue == Component.POV.DOWN) || (axisValue == Component.POV.RIGHT)) {
axisValue = 1;
}
} else {
// TODO: handle 8-button POVs
return null;
}
} else {
// unrecognized axis
return null;
}
} else {
// unrecognized id (e.g. Identifier.Key)
return null;
}
return new ControllerAction(input, c.getName(), state, axisValue);
}
use of org.terasology.config.ControllerConfig.ControllerInfo in project Terasology by MovingBlocks.
the class InputSettingsScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
ColumnLayout mainLayout = new ColumnLayout();
mainLayout.setHorizontalSpacing(8);
mainLayout.setVerticalSpacing(8);
mainLayout.setFamily("option-grid");
UISlider mouseSensitivity = new UISlider("mouseSensitivity");
mouseSensitivity.bindValue(BindHelper.bindBeanProperty("mouseSensitivity", inputDeviceConfiguration, Float.TYPE));
mouseSensitivity.setIncrement(0.025f);
mouseSensitivity.setPrecision(3);
UICheckbox mouseInverted = new UICheckbox("mouseYAxisInverted");
mouseInverted.bindChecked(BindHelper.bindBeanProperty("mouseYAxisInverted", inputDeviceConfiguration, Boolean.TYPE));
mainLayout.addWidget(new UILabel("mouseLabel", "subheading", translationSystem.translate("${engine:menu#category-mouse}")));
mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#mouse-sensitivity}") + ":"), mouseSensitivity).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-mouse}") + ":"), mouseInverted).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
Map<String, InputCategory> inputCategories = Maps.newHashMap();
Map<SimpleUri, RegisterBindButton> inputsById = Maps.newHashMap();
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
if (module.isCodeModule()) {
ResolutionResult result = resolver.resolve(moduleId);
if (result.isSuccess()) {
try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
for (Class<?> holdingType : environment.getTypesAnnotatedWith(InputCategory.class, new FromModule(environment, moduleId))) {
InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
inputCategories.put(module.getId() + ":" + inputCategory.id(), inputCategory);
}
for (Class<?> bindEvent : environment.getTypesAnnotatedWith(RegisterBindButton.class, new FromModule(environment, moduleId))) {
if (BindButtonEvent.class.isAssignableFrom(bindEvent)) {
RegisterBindButton bindRegister = bindEvent.getAnnotation(RegisterBindButton.class);
inputsById.put(new SimpleUri(module.getId(), bindRegister.id()), bindRegister);
}
}
}
}
}
}
addInputSection(inputCategories.remove("engine:movement"), mainLayout, inputsById);
addInputSection(inputCategories.remove("engine:interaction"), mainLayout, inputsById);
addInputSection(inputCategories.remove("engine:inventory"), mainLayout, inputsById);
addInputSection(inputCategories.remove("engine:general"), mainLayout, inputsById);
for (InputCategory category : inputCategories.values()) {
addInputSection(category, mainLayout, inputsById);
}
mainLayout.addWidget(new UISpace(new Vector2i(1, 16)));
List<String> controllers = inputSystem.getControllerDevice().getControllers();
for (String name : controllers) {
ControllerInfo cfg = inputDeviceConfiguration.getController(name);
addInputSection(mainLayout, name, cfg);
}
ScrollableArea area = find("area", ScrollableArea.class);
area.setContent(mainLayout);
WidgetUtil.trySubscribe(this, "reset", button -> {
inputDeviceConfiguration.reset();
bindsManager.getBindsConfig().setBinds(bindsManager.getDefaultBindsConfig());
});
WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
}
use of org.terasology.config.ControllerConfig.ControllerInfo in project Terasology by MovingBlocks.
the class InputSystem method processControllerAxisInput.
private void processControllerAxisInput(ControllerAction action, Input input) {
BindableRealAxis axis = bindsManager.getControllerAxisBinds().get(input);
if (axis != null) {
ControllerInfo info = inputDeviceConfig.getController(action.getController());
boolean isX = action.getInput().getId() == ControllerId.X_AXIS;
boolean isY = action.getInput().getId() == ControllerId.Y_AXIS;
boolean isZ = action.getInput().getId() == ControllerId.Z_AXIS;
float f = (isX && info.isInvertX() || isY && info.isInvertY() || isZ && info.isInvertZ()) ? -1 : 1;
axis.setTargetValue(action.getAxisValue() * f);
}
}
Aggregations