Search in sources :

Example 1 with Property

use of org.terasology.rendering.nui.properties.Property 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)

Example 2 with Property

use of org.terasology.rendering.nui.properties.Property in project Terasology by MovingBlocks.

the class PropertyLayout method expand.

private void expand(Collection<Property<?, ?>> properties, MigLayout layout) {
    List<Property<?, ?>> props = Lists.newArrayList(properties);
    Collections.sort(props, propertyComparator);
    for (Property<?, ?> property : props) {
        UILabel label = property.getLabel();
        UIWidget editor = property.getEditor();
        editor.setTooltip(property.getDescription());
        layout.addWidget(label, new CCHint("newline"));
        layout.addWidget(editor, new CCHint());
    }
    invalidate();
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) Property(org.terasology.rendering.nui.properties.Property) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 3 with Property

use of org.terasology.rendering.nui.properties.Property in project Terasology by MovingBlocks.

the class BehaviorEditorScreen method onEntitySelected.

private void onEntitySelected(Interpreter value, PropertyProvider provider) {
    if (selectedInterpreter != null) {
        selectedInterpreter.setCallback(null);
    }
    selectedInterpreter = value;
    if (selectedInterpreter != null) {
        EntityRef entity = value.actor().getEntity();
        onTreeSelected(selectedInterpreter.getTree());
        entityProperties.clear();
        for (Component component : entity.iterateComponents()) {
            String name = component.getClass().getSimpleName().replace("Component", "");
            List<Property<?, ?>> componentProperties = provider.createProperties(component);
            entityProperties.addProperties(name, componentProperties);
        }
        selectedInterpreter.setCallback(behaviorEditor);
    }
}
Also used : BehaviorComponent(org.terasology.logic.behavior.BehaviorComponent) Component(org.terasology.entitySystem.Component) EntityRef(org.terasology.entitySystem.entity.EntityRef) Property(org.terasology.rendering.nui.properties.Property)

Aggregations

Property (org.terasology.rendering.nui.properties.Property)3 Component (org.terasology.entitySystem.Component)2 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 ComponentLibrary (org.terasology.entitySystem.metadata.ComponentLibrary)1 BehaviorComponent (org.terasology.logic.behavior.BehaviorComponent)1 FieldMetadata (org.terasology.reflection.metadata.FieldMetadata)1 UIWidget (org.terasology.rendering.nui.UIWidget)1 PropertyLayout (org.terasology.rendering.nui.layouts.PropertyLayout)1 PropertyProvider (org.terasology.rendering.nui.properties.PropertyProvider)1 UILabel (org.terasology.rendering.nui.widgets.UILabel)1 WorldConfigurator (org.terasology.world.generator.WorldConfigurator)1