Search in sources :

Example 1 with PropertyProvider

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

the class ActionNode method getProperties.

@Override
public PropertyProvider getProperties() {
    // TODO: The CoreRegistry usage came from the previous code.
    PropertyProvider provider = new PropertyProvider(CoreRegistry.get(ReflectFactory.class), CoreRegistry.get(OneOfProviderFactory.class));
    provider.createProperties(action);
    return provider;
}
Also used : ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) OneOfProviderFactory(org.terasology.nui.properties.OneOfProviderFactory) PropertyProvider(org.terasology.nui.properties.PropertyProvider)

Example 2 with PropertyProvider

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

the class BehaviorEditorScreen method initialise.

@Override
public void initialise() {
    entityProperties = find("entity_properties", PropertyLayout.class);
    behaviorEditor = find("tree", BehaviorEditor.class);
    properties = find("properties", PropertyLayout.class);
    selectTree = find("select_tree", UIDropdown.class);
    selectEntity = find("select_entity", UIDropdown.class);
    palette = find("palette", UIList.class);
    behaviorEditor.initialize(context);
    behaviorEditor.bindSelection(new Binding<RenderableNode>() {

        private PropertyProvider provider = new PropertyProvider(context.get(ReflectFactory.class), providerFactory);

        @Override
        public RenderableNode get() {
            return selectedNode;
        }

        @Override
        public void set(RenderableNode value) {
            onNodeSelected(value, provider);
        }
    });
    Binding<List<BehaviorTree>> treeBinding = new ReadOnlyBinding<List<BehaviorTree>>() {

        @Override
        public List<BehaviorTree> get() {
            return behaviorSystem.getTrees();
        }
    };
    selectTree.bindOptions(treeBinding);
    providerFactory.register("behaviorTrees", treeBinding);
    selectTree.bindSelection(new Binding<BehaviorTree>() {

        @Override
        public BehaviorTree get() {
            return behaviorEditor.getTree();
        }

        @Override
        public void set(BehaviorTree value) {
            onTreeSelected(value);
        }
    });
    selectEntity.bindOptions(new ReadOnlyBinding<List<Interpreter>>() {

        @Override
        public List<Interpreter> get() {
            return behaviorSystem.getInterpreters();
        }
    });
    selectEntity.bindSelection(new Binding<Interpreter>() {

        private PropertyProvider provider = new PropertyProvider(context.get(ReflectFactory.class), providerFactory);

        @Override
        public Interpreter get() {
            return selectedInterpreter;
        }

        @Override
        public void set(Interpreter value) {
            onEntitySelected(value, provider);
        }
    });
    palette.bindSelection(new Binding<BehaviorNodeComponent>() {

        @Override
        public BehaviorNodeComponent get() {
            return null;
        }

        @Override
        public void set(BehaviorNodeComponent value) {
            onPaletteSelected(value);
        }
    });
    palette.bindList(new ReadOnlyBinding<List<BehaviorNodeComponent>>() {

        @Override
        public List<BehaviorNodeComponent> get() {
            return paletteItems;
        }
    });
    palette.setItemRenderer(new ToStringTextRenderer<BehaviorNodeComponent>() {

        @Override
        public String getTooltip(BehaviorNodeComponent value) {
            return value.description;
        }
    });
    WidgetUtil.trySubscribe(this, "copy", button -> onCopyPressed());
    WidgetUtil.trySubscribe(this, "layout", button -> onLayoutPressed());
    WidgetUtil.trySubscribe(this, "new", button -> onNewPressed());
    WidgetUtil.trySubscribe(this, "assign", button -> onAssignPressed());
    WidgetUtil.trySubscribe(this, "remove", button -> onRemovePressed());
    WidgetUtil.trySubscribe(this, "debug_run", button -> {
        if (selectedInterpreter != null) {
            selectedInterpreter.run();
        }
    });
    WidgetUtil.trySubscribe(this, "debug_pause", button -> {
        if (selectedInterpreter != null) {
            selectedInterpreter.pause();
        }
    });
    WidgetUtil.trySubscribe(this, "debug_reset", button -> {
        if (selectedInterpreter != null) {
            selectedInterpreter.reset();
        }
    });
    WidgetUtil.trySubscribe(this, "debug_step", button -> {
        if (selectedInterpreter != null) {
            selectedInterpreter.tick(0.1f);
        }
    });
    paletteItems = findPaletteItems();
}
Also used : Interpreter(org.terasology.engine.logic.behavior.Interpreter) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) UIList(org.terasology.nui.widgets.UIList) BehaviorTree(org.terasology.engine.logic.behavior.asset.BehaviorTree) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) PropertyLayout(org.terasology.nui.layouts.PropertyLayout) PropertyProvider(org.terasology.nui.properties.PropertyProvider) UIDropdown(org.terasology.nui.widgets.UIDropdown) List(java.util.List) UIList(org.terasology.nui.widgets.UIList)

Example 3 with PropertyProvider

use of org.terasology.nui.properties.PropertyProvider 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(context.get(ReflectFactory.class), context.get(OneOfProviderFactory.class)) {

            @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.engine.world.generator.WorldConfigurator) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) OneOfProviderFactory(org.terasology.nui.properties.OneOfProviderFactory) PropertyLayout(org.terasology.nui.layouts.PropertyLayout) PropertyProvider(org.terasology.nui.properties.PropertyProvider) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) Component(org.terasology.gestalt.entitysystem.component.Component) Property(org.terasology.nui.properties.Property)

Example 4 with PropertyProvider

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

the class WorldSetupScreen method configureProperties.

/**
 * Assigns a {@link WorldConfigurator} for every world if it doesn't exist. Using
 * the WorldConfigurator it gets the properties associated with that world.
 */
private void configureProperties() {
    PropertyLayout propLayout = find("properties", PropertyLayout.class);
    propLayout.setOrdering(PropertyOrdering.byLabel());
    propLayout.clear();
    WorldConfigurator worldConfig;
    if (world.getWorldConfigurator() != null) {
        worldConfig = world.getWorldConfigurator();
    } else {
        worldConfig = worldGenerator.getConfigurator();
        world.setWorldConfigurator(worldConfig);
    }
    oldWorldConfig = worldConfig;
    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 = context.get(ComponentLibrary.class);
    for (String label : params.keySet()) {
        PropertyProvider provider = new PropertyProvider(context.get(ReflectFactory.class), context.get(OneOfProviderFactory.class)) {

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

            @Override
            protected Binding<Float> createFloatBinding(Object target, FieldMetadata<Object, ?> fieldMetadata) {
                return new WorldSetupScreen.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.engine.world.generator.WorldConfigurator) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) OneOfProviderFactory(org.terasology.nui.properties.OneOfProviderFactory) PropertyLayout(org.terasology.nui.layouts.PropertyLayout) PropertyProvider(org.terasology.nui.properties.PropertyProvider) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) Component(org.terasology.gestalt.entitysystem.component.Component) Property(org.terasology.nui.properties.Property)

Aggregations

PropertyProvider (org.terasology.nui.properties.PropertyProvider)4 ReflectFactory (org.terasology.reflection.reflect.ReflectFactory)4 PropertyLayout (org.terasology.nui.layouts.PropertyLayout)3 OneOfProviderFactory (org.terasology.nui.properties.OneOfProviderFactory)3 ComponentLibrary (org.terasology.engine.entitySystem.metadata.ComponentLibrary)2 WorldConfigurator (org.terasology.engine.world.generator.WorldConfigurator)2 Component (org.terasology.gestalt.entitysystem.component.Component)2 Property (org.terasology.nui.properties.Property)2 FieldMetadata (org.terasology.reflection.metadata.FieldMetadata)2 List (java.util.List)1 Interpreter (org.terasology.engine.logic.behavior.Interpreter)1 BehaviorTree (org.terasology.engine.logic.behavior.asset.BehaviorTree)1 ReadOnlyBinding (org.terasology.nui.databinding.ReadOnlyBinding)1 UIDropdown (org.terasology.nui.widgets.UIDropdown)1 UIList (org.terasology.nui.widgets.UIList)1