Search in sources :

Example 1 with UISlider

use of org.terasology.rendering.nui.widgets.UISlider 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 UISlider

use of org.terasology.rendering.nui.widgets.UISlider 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());
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) UISlider(org.terasology.rendering.nui.widgets.UISlider) RegisterBindButton(org.terasology.input.RegisterBindButton) ResolutionResult(org.terasology.module.ResolutionResult) SimpleUri(org.terasology.engine.SimpleUri) UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox) DependencyResolver(org.terasology.module.DependencyResolver) Name(org.terasology.naming.Name) ModuleEnvironment(org.terasology.module.ModuleEnvironment) ScrollableArea(org.terasology.rendering.nui.layouts.ScrollableArea) ColumnLayout(org.terasology.rendering.nui.layouts.ColumnLayout) RowLayout(org.terasology.rendering.nui.layouts.RowLayout) InputCategory(org.terasology.input.InputCategory) UISpace(org.terasology.rendering.nui.widgets.UISpace) Vector2i(org.terasology.math.geom.Vector2i) FromModule(org.terasology.module.predicates.FromModule) Module(org.terasology.module.Module) FromModule(org.terasology.module.predicates.FromModule) ControllerInfo(org.terasology.config.ControllerConfig.ControllerInfo)

Example 3 with UISlider

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

the class AudioSettingsScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    UISlider sound = find("sound", UISlider.class);
    if (sound != null) {
        sound.setIncrement(0.05f);
        sound.setPrecision(2);
        sound.setMinimum(0);
        sound.setRange(1.0f);
        sound.bindValue(BindHelper.bindBeanProperty("soundVolume", config.getAudio(), Float.TYPE));
    }
    UISlider music = find("music", UISlider.class);
    if (music != null) {
        music.setIncrement(0.05f);
        music.setPrecision(2);
        music.setMinimum(0);
        music.setRange(1.0f);
        music.bindValue(BindHelper.bindBeanProperty("musicVolume", config.getAudio(), Float.TYPE));
    }
    WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
}
Also used : UISlider(org.terasology.rendering.nui.widgets.UISlider)

Example 4 with UISlider

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

the class VideoSettingsScreen method initialise.

@Override
@SuppressWarnings("unchecked")
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    UIDropdown<Preset> videoQuality = find("graphicsPreset", UIDropdown.class);
    if (videoQuality != null) {
        videoQuality.setOptionRenderer(new ToStringTextRenderer<>(translationSystem));
        videoQuality.setOptions(Lists.newArrayList(Preset.CUSTOM, Preset.MINIMAL, Preset.LOW, Preset.MEDIUM, Preset.HIGH, Preset.ULTRA));
        videoQuality.bindSelection(new PresetBinding(config.getRendering()));
    }
    UIDropdown<ViewDistance> viewDistance = find("viewDistance", UIDropdown.class);
    if (viewDistance != null) {
        viewDistance.setOptionRenderer(new ToStringTextRenderer<>(translationSystem));
        viewDistance.setOptions(Arrays.asList(ViewDistance.values()));
        viewDistance.bindSelection(BindHelper.bindBeanProperty("viewDistance", config.getRendering(), ViewDistance.class));
    }
    UIDropdown<WaterReflection> waterReflection = find("reflections", UIDropdown.class);
    if (waterReflection != null) {
        waterReflection.setOptionRenderer(new ToStringTextRenderer<>(translationSystem));
        waterReflection.setOptions(Lists.newArrayList(WaterReflection.SKY, WaterReflection.GLOBAL, WaterReflection.LOCAL));
        waterReflection.bindSelection(new WaterReflectionBinding(config.getRendering()));
    }
    UIDropdown<ScreenshotSize> screenshotSize = find("screenshotSize", UIDropdown.class);
    if (screenshotSize != null) {
        screenshotSize.setOptionRenderer(new ToStringTextRenderer<>(translationSystem));
        screenshotSize.setOptions(Arrays.asList(ScreenshotSize.values()));
        screenshotSize.bindSelection(BindHelper.bindBeanProperty("screenshotSize", config.getRendering(), ScreenshotSize.class));
    }
    UIDropdown<String> screenshotFormat = find("screenshotFormat", UIDropdown.class);
    if (screenshotFormat != null) {
        screenshotFormat.setOptions(Arrays.asList(ImageIO.getWriterFileSuffixes()));
        screenshotFormat.bindSelection(BindHelper.bindBeanProperty("screenshotFormat", config.getRendering(), String.class));
    }
    UIDropdown<Integer> blur = find("blur", UIDropdown.class);
    if (blur != null) {
        blur.setOptions(Lists.newArrayList(0, 1, 2, 3));
        blur.bindSelection(BindHelper.bindBeanProperty("blurIntensity", config.getRendering(), Integer.TYPE));
        blur.setOptionRenderer(new StringTextRenderer<Integer>() {

            @Override
            public String getString(Integer value) {
                switch(value) {
                    case 1:
                        return translationSystem.translate("${engine:menu#camera-blur-some}");
                    case 2:
                        return translationSystem.translate("${engine:menu#camera-blur-normal}");
                    case 3:
                        return translationSystem.translate("${engine:menu#camera-blur-max}");
                    default:
                        return translationSystem.translate("${engine:menu#camera-blur-off}");
                }
            }
        });
    }
    UIDropdown<DynamicShadows> dynamicShadows = find("shadows", UIDropdown.class);
    if (dynamicShadows != null) {
        dynamicShadows.setOptionRenderer(new ToStringTextRenderer<>(translationSystem));
        dynamicShadows.setOptions(Arrays.asList(DynamicShadows.values()));
        dynamicShadows.bindSelection(new DynamicShadowsBinding(config.getRendering()));
    }
    final UISlider fovSlider = find("fov", UISlider.class);
    if (fovSlider != null) {
        fovSlider.setIncrement(5.0f);
        fovSlider.setPrecision(0);
        fovSlider.setMinimum(70);
        fovSlider.setRange(50);
        fovSlider.bindValue(BindHelper.bindBeanProperty("fieldOfView", config.getRendering(), Float.TYPE));
    }
    final UISlider frameLimitSlider = find("frameLimit", UISlider.class);
    if (frameLimitSlider != null) {
        frameLimitSlider.setIncrement(5.0f);
        frameLimitSlider.setPrecision(0);
        frameLimitSlider.setMinimum(30);
        // Goes up to 205 (which is off)
        frameLimitSlider.setRange(175);
        // Frame limit > 200 is just displayed and treated as "off"
        frameLimitSlider.setLabelFunction(input -> {
            if (input > 200) {
                // Spaces to get wider than "200" (otherwise the display jumps around)
                return " Off ";
            } else {
                return String.valueOf(input.intValue());
            }
        });
        frameLimitSlider.bindValue(new Binding<Float>() {

            @Override
            public Float get() {
                if (config.getRendering().getFrameLimit() == -1) {
                    return 205f;
                } else {
                    return (float) config.getRendering().getFrameLimit();
                }
            }

            @Override
            public void set(Float value) {
                int frameLimit = value.intValue();
                if (frameLimit > 200) {
                    config.getRendering().setFrameLimit(-1);
                } else {
                    config.getRendering().setFrameLimit(frameLimit);
                }
            }
        });
    }
    final UISlider particleEffectLimitSlider = find("particleEffectLimit", UISlider.class);
    if (particleEffectLimitSlider != null) {
        particleEffectLimitSlider.setIncrement(1.0f);
        particleEffectLimitSlider.setPrecision(0);
        particleEffectLimitSlider.setMinimum(0);
        particleEffectLimitSlider.setRange(50);
        particleEffectLimitSlider.setLabelFunction(input -> {
            if (input == 0) {
                return " Off ";
            } else {
                return String.valueOf(input.intValue());
            }
        });
        particleEffectLimitSlider.bindValue(new Binding<Float>() {

            @Override
            public Float get() {
                return (float) config.getRendering().getParticleEffectLimit();
            }

            @Override
            public void set(Float value) {
                int particleEffectLimit = value.intValue();
                config.getRendering().setParticleEffectLimit(particleEffectLimit);
            }
        });
    }
    final UISlider fboScaleSlider = find("fboScale", UISlider.class);
    if (fboScaleSlider != null) {
        fboScaleSlider.setIncrement(5.0f);
        fboScaleSlider.setPrecision(0);
        fboScaleSlider.setMinimum(25);
        fboScaleSlider.setRange(200);
        fboScaleSlider.setLabelFunction(input -> String.valueOf(input.intValue()) + "%");
        fboScaleSlider.bindValue(new Binding<Float>() {

            @Override
            public Float get() {
                return (float) config.getRendering().getFboScale();
            }

            @Override
            public void set(Float value) {
                config.getRendering().setFboScale(value.intValue());
            }
        });
    }
    UIDropdown<CameraSetting> cameraSetting = find("camera", UIDropdown.class);
    if (cameraSetting != null) {
        cameraSetting.setOptionRenderer(new ToStringTextRenderer<>(translationSystem));
        cameraSetting.setOptions(Arrays.asList(CameraSetting.values()));
        cameraSetting.bindSelection(new CameraSettingBinding(config.getRendering()));
    }
    UIDropdown<DisplayModeSetting> displaySetting = find("displayModeSetting", UIDropdown.class);
    if (displaySetting != null) {
        displaySetting.setOptionRenderer(new ToStringTextRenderer<>(translationSystem));
        displaySetting.setOptions(Arrays.asList(DisplayModeSetting.values()));
        displaySetting.bindSelection(BindHelper.bindBeanProperty("displayModeSetting", displayDevice, DisplayModeSetting.class));
    }
    WidgetUtil.tryBindCheckbox(this, "menu-animations", BindHelper.bindBeanProperty("animatedMenu", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "oculusVrSupport", BindHelper.bindBeanProperty("vrSupport", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "animateGrass", BindHelper.bindBeanProperty("animateGrass", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "animateWater", BindHelper.bindBeanProperty("animateWater", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "volumetricFog", BindHelper.bindBeanProperty("volumetricFog", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "inscattering", BindHelper.bindBeanProperty("inscattering", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "cloudShadow", BindHelper.bindBeanProperty("cloudShadows", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "extraLighting", BindHelper.bindBeanProperty("normalMapping", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "parallax", BindHelper.bindBeanProperty("parallaxMapping", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "filmGrain", BindHelper.bindBeanProperty("filmGrain", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "motionBlur", BindHelper.bindBeanProperty("motionBlur", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "bobbing", BindHelper.bindBeanProperty("cameraBobbing", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "outline", BindHelper.bindBeanProperty("outline", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "vsync", BindHelper.bindBeanProperty("vSync", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "eyeAdaptation", BindHelper.bindBeanProperty("eyeAdaptation", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "ssao", BindHelper.bindBeanProperty("ssao", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "clampLighting", BindHelper.bindBeanProperty("clampLighting", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "bloom", BindHelper.bindBeanProperty("bloom", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "lightShafts", BindHelper.bindBeanProperty("lightShafts", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "vignette", BindHelper.bindBeanProperty("vignette", config.getRendering(), Boolean.TYPE));
    WidgetUtil.tryBindCheckbox(this, "flickeringLight", BindHelper.bindBeanProperty("flickeringLight", config.getRendering(), Boolean.TYPE));
    if (fovSlider != null) {
        WidgetUtil.trySubscribe(this, "fovReset", widget -> fovSlider.setValue(100.0f));
    }
    WidgetUtil.trySubscribe(this, "close", button -> saveSettings());
}
Also used : ViewDistance(org.terasology.rendering.world.viewDistance.ViewDistance) UISlider(org.terasology.rendering.nui.widgets.UISlider)

Aggregations

UISlider (org.terasology.rendering.nui.widgets.UISlider)4 Vector2i (org.terasology.math.geom.Vector2i)2 RowLayout (org.terasology.rendering.nui.layouts.RowLayout)2 UICheckbox (org.terasology.rendering.nui.widgets.UICheckbox)2 UILabel (org.terasology.rendering.nui.widgets.UILabel)2 UISpace (org.terasology.rendering.nui.widgets.UISpace)2 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 ColumnLayout (org.terasology.rendering.nui.layouts.ColumnLayout)1 ScrollableArea (org.terasology.rendering.nui.layouts.ScrollableArea)1 ViewDistance (org.terasology.rendering.world.viewDistance.ViewDistance)1