Search in sources :

Example 1 with SettingBinding

use of org.terasology.engine.config.flexible.bindings.SettingBinding in project Terasology by MovingBlocks.

the class ColorConstraintWidgetFactory method bindWidgetToSetting.

@Override
protected void bindWidgetToSetting(UIWidget widget) {
    UIImage img = widget.find("image", UIImage.class);
    if (img != null) {
        ResourceUrn uri = TextureUtil.getTextureUriForColor(Color.WHITE);
        Texture tex = assetManager.getAsset(uri, Texture.class).get();
        img.setImage(tex);
        img.bindTint(new SettingBinding<>(getSetting()));
    }
    UISlider slider = widget.find("tone", UISlider.class);
    slider.setIncrement(0.01f);
    // ensure a certain width
    Function<Object, String> constant = Functions.constant("  ");
    slider.setLabelFunction(constant);
    slider.bindValue(new MappingBinding<>(new SettingBinding<>(getSetting()), this::findClosestColor, this::findClosestIndex));
}
Also used : UISlider(org.terasology.nui.widgets.UISlider) SettingBinding(org.terasology.engine.config.flexible.bindings.SettingBinding) UIImage(org.terasology.nui.widgets.UIImage) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Texture(org.terasology.engine.rendering.assets.texture.Texture)

Aggregations

SettingBinding (org.terasology.engine.config.flexible.bindings.SettingBinding)1 Texture (org.terasology.engine.rendering.assets.texture.Texture)1 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)1 UIImage (org.terasology.nui.widgets.UIImage)1 UISlider (org.terasology.nui.widgets.UISlider)1