use of org.terasology.nui.layouts.PropertyLayout in project Terasology by MovingBlocks.
the class AutoConfigWidgetFactory method buildWidgetFor.
/**
* Creates {@link UIWidget} for {@link AutoConfig}
*
* @param config for creating widget
* @return UIWidget created for config
*/
public UIWidget buildWidgetFor(AutoConfig config) {
PropertyLayout container = new PropertyLayout();
container.setRowConstraints("[min]");
Collection<Property<?, ?>> widgetProperties = new ArrayList<>();
for (Setting<?> setting : config.getSettings()) {
Optional<UIWidget> settingWidget = settingWidgetFactory.createWidgetFor(setting);
if (!settingWidget.isPresent()) {
logger.error("Couldn't find a widget for the Setting [{}]", setting.getHumanReadableName());
continue;
}
widgetProperties.add(new Property<>(translationSystem.translate(setting.getHumanReadableName()), null, settingWidget.get(), translationSystem.translate(setting.getDescription())));
}
container.addProperties(translationSystem.translate(config.getName()), widgetProperties);
return container;
}
use of org.terasology.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(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);
}
}
use of org.terasology.nui.layouts.PropertyLayout 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);
}
}
Aggregations