Search in sources :

Example 1 with PropertyLayout

use of org.terasology.rendering.nui.layouts.PropertyLayout in project Terasology by MovingBlocks.

the class PreviewWorldScreen method configureProperties.

private void configureProperties() {
    PropertyLayout propLayout = find("properties", PropertyLayout.class);
    propLayout.setOrdering(PropertyOrdering.byLabel());
    propLayout.clear();
    WorldConfigurator worldConfig = worldGenerator.getConfigurator();
    Map<String, Component> params = worldConfig.getProperties();
    for (String key : params.keySet()) {
        Class<? extends Component> clazz = params.get(key).getClass();
        Component comp = config.getModuleConfig(worldGenerator.getUri(), key, clazz);
        if (comp != null) {
            // use the data from the config instead of defaults
            worldConfig.setProperty(key, comp);
        }
    }
    ComponentLibrary compLib = subContext.get(ComponentLibrary.class);
    for (String label : params.keySet()) {
        PropertyProvider provider = new PropertyProvider() {

            @Override
            protected <T> Binding<T> createTextBinding(Object target, FieldMetadata<Object, T> fieldMetadata) {
                return new WorldConfigBinding<>(worldConfig, label, compLib, fieldMetadata);
            }

            @Override
            protected Binding<Float> createFloatBinding(Object target, FieldMetadata<Object, ?> fieldMetadata) {
                return new WorldConfigNumberBinding(worldConfig, label, compLib, fieldMetadata);
            }
        };
        Component target = params.get(label);
        List<Property<?, ?>> properties = provider.createProperties(target);
        propLayout.addProperties(label, properties);
    }
}
Also used : FieldMetadata(org.terasology.reflection.metadata.FieldMetadata) WorldConfigurator(org.terasology.world.generator.WorldConfigurator) PropertyLayout(org.terasology.rendering.nui.layouts.PropertyLayout) PropertyProvider(org.terasology.rendering.nui.properties.PropertyProvider) ComponentLibrary(org.terasology.entitySystem.metadata.ComponentLibrary) Component(org.terasology.entitySystem.Component) Property(org.terasology.rendering.nui.properties.Property)

Aggregations

Component (org.terasology.entitySystem.Component)1 ComponentLibrary (org.terasology.entitySystem.metadata.ComponentLibrary)1 FieldMetadata (org.terasology.reflection.metadata.FieldMetadata)1 PropertyLayout (org.terasology.rendering.nui.layouts.PropertyLayout)1 Property (org.terasology.rendering.nui.properties.Property)1 PropertyProvider (org.terasology.rendering.nui.properties.PropertyProvider)1 WorldConfigurator (org.terasology.world.generator.WorldConfigurator)1