Search in sources :

Example 1 with UICheckbox

use of org.terasology.rendering.nui.widgets.UICheckbox 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)));
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) UISlider(org.terasology.rendering.nui.widgets.UISlider) RowLayout(org.terasology.rendering.nui.layouts.RowLayout) UISpace(org.terasology.rendering.nui.widgets.UISpace) Vector2i(org.terasology.math.geom.Vector2i) UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox)

Example 2 with UICheckbox

use of org.terasology.rendering.nui.widgets.UICheckbox 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);
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) Field(java.lang.reflect.Field) RowLayout(org.terasology.rendering.nui.layouts.RowLayout) UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox)

Example 3 with UICheckbox

use of org.terasology.rendering.nui.widgets.UICheckbox 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);
        }
    }
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox) RowLayout(org.terasology.rendering.nui.layouts.RowLayout) ArrayList(java.util.ArrayList) List(java.util.List) UISpace(org.terasology.rendering.nui.widgets.UISpace) Map(java.util.Map)

Example 4 with UICheckbox

use of org.terasology.rendering.nui.widgets.UICheckbox in project Terasology by MovingBlocks.

the class TelemetryScreen method addGroupEnablingListener.

/**
 * Add a listener to the checkbox in the telemetry category row.
 * If this checkbox is checked, all the sub telemetry fields will be enabled/disabled.
 */
private void addGroupEnablingListener() {
    fetchTelemetryCategoriesFromEnvironment();
    for (Map.Entry<TelemetryCategory, Class> telemetryCategory : telemetryCategories.entrySet()) {
        if (!telemetryCategory.getKey().isOneMapMetric()) {
            UICheckbox uiCheckbox = this.find(telemetryCategory.getKey().id(), UICheckbox.class);
            if (uiCheckbox == null) {
                continue;
            }
            uiCheckbox.subscribe((checkbox) -> {
                Map<String, Boolean> bindingMap = config.getTelemetryConfig().getMetricsUserPermissionConfig().getBindingMap();
                if (bindingMap.containsKey(telemetryCategory.getKey().id())) {
                    boolean isGroupEnable = bindingMap.get(telemetryCategory.getKey().id());
                    Set<Field> fields = ReflectionUtils.getFields(telemetryCategory.getValue(), ReflectionUtils.withAnnotation(TelemetryField.class));
                    for (Field field : fields) {
                        String fieldName = telemetryCategory.getKey().id() + ":" + field.getName();
                        bindingMap.put(fieldName, isGroupEnable);
                    }
                }
            });
        }
    }
}
Also used : Field(java.lang.reflect.Field) UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox) Map(java.util.Map)

Example 5 with UICheckbox

use of org.terasology.rendering.nui.widgets.UICheckbox in project Terasology by MovingBlocks.

the class TelemetryScreen method addEnablingAllTelemetryListener.

/**
 * Add a listener to the telemetryEnable checkbox. If the checkbox os enabled/disabled, it will enable/disable all the telemetry field.
 */
private void addEnablingAllTelemetryListener() {
    UICheckbox uiCheckbox = this.find("telemetryEnabled", UICheckbox.class);
    if (uiCheckbox != null) {
        uiCheckbox.subscribe((checkbox) -> {
            boolean telemetryEnabled = config.getTelemetryConfig().isTelemetryEnabled();
            Map<String, Boolean> bindingMap = config.getTelemetryConfig().getMetricsUserPermissionConfig().getBindingMap();
            for (Map.Entry<String, Boolean> entry : bindingMap.entrySet()) {
                entry.setValue(telemetryEnabled);
            }
            fetchTelemetryCategoriesFromEnvironment();
            for (Map.Entry<TelemetryCategory, Class> telemetryCategory : telemetryCategories.entrySet()) {
                UICheckbox categoryBox = this.find(telemetryCategory.getKey().id(), UICheckbox.class);
                if (categoryBox != null) {
                    categoryBox.setEnabled(telemetryEnabled);
                }
                Set<Field> fields = ReflectionUtils.getFields(telemetryCategory.getValue(), ReflectionUtils.withAnnotation(TelemetryField.class));
                for (Field field : fields) {
                    String fieldName = telemetryCategory.getKey().id() + ":" + field.getName();
                    UICheckbox fieldBox = this.find(fieldName, UICheckbox.class);
                    if (fieldBox != null) {
                        fieldBox.setEnabled(telemetryEnabled);
                    }
                }
            }
        });
    }
}
Also used : UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox) Field(java.lang.reflect.Field) Map(java.util.Map)

Aggregations

UICheckbox (org.terasology.rendering.nui.widgets.UICheckbox)7 RowLayout (org.terasology.rendering.nui.layouts.RowLayout)4 UILabel (org.terasology.rendering.nui.widgets.UILabel)4 Field (java.lang.reflect.Field)3 Map (java.util.Map)3 UISpace (org.terasology.rendering.nui.widgets.UISpace)3 Vector2i (org.terasology.math.geom.Vector2i)2 UISlider (org.terasology.rendering.nui.widgets.UISlider)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ControllerInfo (org.terasology.config.ControllerConfig.ControllerInfo)1 SimpleUri (org.terasology.engine.SimpleUri)1 InputCategory (org.terasology.input.InputCategory)1 RegisterBindButton (org.terasology.input.RegisterBindButton)1 DependencyResolver (org.terasology.module.DependencyResolver)1 Module (org.terasology.module.Module)1 ModuleEnvironment (org.terasology.module.ModuleEnvironment)1 ResolutionResult (org.terasology.module.ResolutionResult)1 FromModule (org.terasology.module.predicates.FromModule)1 Name (org.terasology.naming.Name)1