use of org.terasology.rendering.nui.layouts.RowLayout in project Terasology by MovingBlocks.
the class InputSettingsScreen method addInputSection.
private void addInputSection(ColumnLayout layout, String name, ControllerInfo info) {
UILabel categoryHeader = new UILabel(name);
categoryHeader.setFamily("subheading");
layout.addWidget(categoryHeader);
float columnRatio = 0.4f;
UICheckbox invertX = new UICheckbox();
invertX.bindChecked(BindHelper.bindBeanProperty("invertX", info, Boolean.TYPE));
layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-x}")), invertX).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
UICheckbox invertY = new UICheckbox();
invertY.bindChecked(BindHelper.bindBeanProperty("invertY", info, Boolean.TYPE));
layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-y}")), invertY).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
UICheckbox invertZ = new UICheckbox();
invertZ.bindChecked(BindHelper.bindBeanProperty("invertZ", info, Boolean.TYPE));
layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-z}")), invertZ).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
UISlider mvmtDeadZone = new UISlider();
mvmtDeadZone.setIncrement(0.01f);
mvmtDeadZone.setMinimum(0);
mvmtDeadZone.setRange(1);
mvmtDeadZone.setPrecision(2);
mvmtDeadZone.bindValue(BindHelper.bindBeanProperty("movementDeadZone", info, Float.TYPE));
layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#movement-dead-zone}")), mvmtDeadZone).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
UISlider rotDeadZone = new UISlider();
rotDeadZone.setIncrement(0.01f);
rotDeadZone.setMinimum(0);
rotDeadZone.setRange(1);
rotDeadZone.setPrecision(2);
rotDeadZone.bindValue(BindHelper.bindBeanProperty("rotationDeadZone", info, Float.TYPE));
layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#rotation-dead-zone}")), rotDeadZone).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
layout.addWidget(new UISpace(new Vector2i(0, 16)));
}
use of org.terasology.rendering.nui.layouts.RowLayout in project Terasology by MovingBlocks.
the class TelemetryScreen method addTelemetryField.
/**
* Add a new row in the menu, the new row includes the field name and value.
* @param type the type(name) of the this field
* @param value the value of this field
* @param layout the layout where the new line will be added
* @param isWithCheckbox whether add a check box in the line
* @param telemetryCategory the TelemetryCategory that this field belongs to
*/
private void addTelemetryField(String type, Object value, ColumnLayout layout, boolean isWithCheckbox, TelemetryCategory telemetryCategory) {
RowLayout newRow;
if (isWithCheckbox) {
String fieldName = telemetryCategory.id() + ":" + type;
UICheckbox uiCheckbox = new UICheckbox(fieldName);
Map<String, Boolean> bindingMap = config.getTelemetryConfig().getMetricsUserPermissionConfig().getBindingMap();
if (!bindingMap.containsKey(fieldName)) {
bindingMap.put(fieldName, config.getTelemetryConfig().isTelemetryEnabled());
}
Binding<Boolean> binding = getBindingFromBooleanMap(bindingMap, fieldName);
uiCheckbox.bindChecked(binding);
uiCheckbox.subscribe((checkbox) -> {
if (bindingMap.get(fieldName)) {
bindingMap.put(telemetryCategory.id(), true);
} else {
Set<Field> fields = ReflectionUtils.getFields(telemetryCategories.get(telemetryCategory), ReflectionUtils.withAnnotation(TelemetryField.class));
boolean isOneEnabled = false;
for (Field field : fields) {
isOneEnabled = isOneEnabled || bindingMap.get(telemetryCategory.id() + ":" + field.getName());
}
if (!isOneEnabled) {
bindingMap.put(telemetryCategory.id(), false);
}
}
});
newRow = new RowLayout(new UILabel(type), new UILabel(value.toString()), uiCheckbox).setColumnRatios(0.4f, 0.5f, 0.1f).setHorizontalSpacing(horizontalSpacing);
} else {
newRow = new RowLayout(new UILabel(type), new UILabel(value.toString())).setColumnRatios(0.4f, 0.5f).setHorizontalSpacing(horizontalSpacing);
}
layout.addWidget(newRow);
}
use of org.terasology.rendering.nui.layouts.RowLayout in project Terasology by MovingBlocks.
the class TelemetryScreen method addTelemetrySection.
/**
* Add a new section with represents a new metrics type.
* @param telemetryCategory the annotation of the new metric
* @param layout the layout where the new section will be added
* @param map the map which includes the telemetry field name and value
*/
private void addTelemetrySection(TelemetryCategory telemetryCategory, ColumnLayout layout, Map<String, ?> map) {
UILabel categoryHeader = new UILabel(translationSystem.translate(telemetryCategory.displayName()));
categoryHeader.setFamily("subheading");
UICheckbox uiCheckbox = new UICheckbox(telemetryCategory.id());
Map<String, Boolean> bindingMap = config.getTelemetryConfig().getMetricsUserPermissionConfig().getBindingMap();
if (!bindingMap.containsKey(telemetryCategory.id())) {
bindingMap.put(telemetryCategory.id(), config.getTelemetryConfig().isTelemetryEnabled());
}
Binding<Boolean> binding = getBindingFromBooleanMap(bindingMap, telemetryCategory.id());
uiCheckbox.bindChecked(binding);
RowLayout newRow = new RowLayout(categoryHeader, new UISpace(), uiCheckbox).setColumnRatios(0.4f, 0.5f, 0.1f).setHorizontalSpacing(horizontalSpacing);
layout.addWidget(newRow);
List<Map.Entry<String, ?>> telemetryFields = sortFields(map);
for (Map.Entry entry : telemetryFields) {
Object value = entry.getValue();
if (value == null) {
value = "Value unknown yet";
}
boolean isWithCheckbox = !telemetryCategory.isOneMapMetric();
if (value instanceof List) {
List list = (List) value;
addTelemetryField(entry.getKey().toString(), list, layout, isWithCheckbox, telemetryCategory);
} else {
addTelemetryField(entry.getKey().toString(), value, layout, isWithCheckbox, telemetryCategory);
}
}
}
use of org.terasology.rendering.nui.layouts.RowLayout in project Terasology by MovingBlocks.
the class InputSettingsScreen method addInputBindRow.
private void addInputBindRow(SimpleUri uri, RegisterBindButton bind, ColumnLayout layout) {
BindsConfig bindConfig = bindsManager.getBindsConfig();
List<Input> binds = bindConfig.getBinds(uri);
UIButton primaryInputBind = new UIButton();
primaryInputBind.bindText(new BindingText(binds, 0));
primaryInputBind.subscribe(event -> {
ChangeBindingPopup popup = getManager().pushScreen(ChangeBindingPopup.ASSET_URI, ChangeBindingPopup.class);
popup.setBindingData(uri, bind, 0);
});
UIButton secondaryInputBind = new UIButton();
secondaryInputBind.bindText(new BindingText(binds, 1));
secondaryInputBind.subscribe(event -> {
ChangeBindingPopup popup = getManager().pushScreen(ChangeBindingPopup.ASSET_URI, ChangeBindingPopup.class);
popup.setBindingData(uri, bind, 1);
});
layout.addWidget(new RowLayout(new UILabel(translationSystem.translate(bind.description())), primaryInputBind, secondaryInputBind).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
}
use of org.terasology.rendering.nui.layouts.RowLayout 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());
}
Aggregations