use of org.terasology.nui.layouts.ColumnLayout in project Terasology by MovingBlocks.
the class ColumnLayoutTest method setup.
@BeforeEach
public void setup() {
columnLayout = new ColumnLayout();
itemAt1x1 = mock(UIWidget.class);
itemAt2x1 = mock(UIWidget.class);
itemAt3x1 = mock(UIWidget.class);
itemAt1x2 = mock(UIWidget.class);
itemAt2x2 = mock(UIWidget.class);
itemAt3x2 = mock(UIWidget.class);
canvas = mock(Canvas.class);
// +-----------------------------------+ +---+ +-------+
// | | |2x1| | |
// | 1x1 | +---+ | 3x1 |
// | | | |
// +-----------------------------------+ +-------+
when(canvas.calculateRestrictedSize(eq(itemAt1x1), any(Vector2i.class))).thenReturn(new Vector2i(50, 10));
when(canvas.calculateRestrictedSize(eq(itemAt2x1), any(Vector2i.class))).thenReturn(new Vector2i(5, 5));
when(canvas.calculateRestrictedSize(eq(itemAt3x1), any(Vector2i.class))).thenReturn(new Vector2i(10, 10));
// +--------------+ +---+ +--------------+
// | | |2x2| | |
// | 1x2 | +---+ | 3x2 |
// | | | |
// +--------------+ +--------------+
when(canvas.calculateRestrictedSize(eq(itemAt1x2), any(Vector2i.class))).thenReturn(new Vector2i(20, 10));
when(canvas.calculateRestrictedSize(eq(itemAt2x2), any(Vector2i.class))).thenReturn(new Vector2i(5, 5));
when(canvas.calculateRestrictedSize(eq(itemAt3x2), any(Vector2i.class))).thenReturn(new Vector2i(20, 10));
Vector2i availableSize = new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT);
when(canvas.size()).thenReturn(availableSize);
columnLayout.setColumns(3);
columnLayout.addWidget(itemAt1x1);
columnLayout.addWidget(itemAt2x1);
columnLayout.addWidget(itemAt3x1);
columnLayout.addWidget(itemAt1x2);
columnLayout.addWidget(itemAt2x2);
columnLayout.addWidget(itemAt3x2);
}
use of org.terasology.nui.layouts.ColumnLayout in project Terasology by MovingBlocks.
the class InputSettingsScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
ColumnLayout mainLayout = find("main", ColumnLayout.class);
UIButton azerty = find("azerty", UIButton.class);
if (azerty != null) {
azerty.subscribe(event -> {
BindCommands.AZERTY.forEach(this::setPrimaryBind);
bindsManager.registerBinds();
});
}
UIButton dvorak = find("dvorak", UIButton.class);
if (dvorak != null) {
dvorak.subscribe(event -> {
BindCommands.DVORAK.forEach(this::setPrimaryBind);
bindsManager.registerBinds();
});
}
UIButton neo = find("neo", UIButton.class);
if (neo != null) {
neo.subscribe(event -> {
BindCommands.NEO.forEach(this::setPrimaryBind);
bindsManager.registerBinds();
});
}
UISlider mouseSensitivity = new UISlider("mouseSensitivity");
mouseSensitivity.bindValue(BindHelper.bindBeanProperty("mouseSensitivity", inputDeviceConfiguration, Float.TYPE));
mouseSensitivity.setIncrement(0.025f);
mouseSensitivity.setPrecision(3);
UICheckbox mouseInverted = new UICheckbox("mouseYAxisInverted");
mouseInverted.bindChecked(BindHelper.bindBeanProperty("mouseYAxisInverted", inputDeviceConfiguration, Boolean.TYPE));
if (mainLayout != null) {
mainLayout.addWidget(new UILabel("mouseLabel", "subheading", translationSystem.translate("${engine:menu" + "#category-mouse}")));
mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#mouse" + "-sensitivity}") + ":"), mouseSensitivity).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-mouse}") + ":"), mouseInverted).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
}
Map<String, InputCategory> inputCategories = Maps.newHashMap();
Map<SimpleUri, RegisterBindButton> inputsById = Maps.newHashMap();
DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
ResolutionResult result = resolver.resolve(moduleId);
if (result.isSuccess()) {
try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
for (Class<?> holdingType : environment.getTypesAnnotatedWith(InputCategory.class, new FromModule(environment, moduleId))) {
InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
inputCategories.put(module.getId() + ":" + inputCategory.id(), inputCategory);
}
for (Class<?> bindEvent : environment.getTypesAnnotatedWith(RegisterBindButton.class, new FromModule(environment, moduleId))) {
if (BindButtonEvent.class.isAssignableFrom(bindEvent)) {
RegisterBindButton bindRegister = bindEvent.getAnnotation(RegisterBindButton.class);
inputsById.put(new SimpleUri(module.getId(), bindRegister.id()), bindRegister);
}
}
}
}
}
if (mainLayout != null) {
addInputSection(inputCategories.remove("engine:movement"), mainLayout, inputsById);
addInputSection(inputCategories.remove("engine:interaction"), mainLayout, inputsById);
addInputSection(inputCategories.remove("engine:inventory"), mainLayout, inputsById);
addInputSection(inputCategories.remove("engine:general"), mainLayout, inputsById);
for (InputCategory category : inputCategories.values()) {
addInputSection(category, mainLayout, inputsById);
}
mainLayout.addWidget(new UISpace(new Vector2i(1, 16)));
List<String> controllers = inputSystem.getControllerDevice().getControllers();
for (String name : controllers) {
ControllerInfo cfg = inputDeviceConfiguration.getController(name);
addInputSection(mainLayout, name, cfg);
}
}
WidgetUtil.trySubscribe(this, "reset", button -> {
inputDeviceConfiguration.reset();
bindsManager.getBindsConfig().setBinds(bindsManager.getDefaultBindsConfig());
});
WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
}
use of org.terasology.nui.layouts.ColumnLayout in project Terasology by MovingBlocks.
the class TelemetryScreen method refreshContent.
private void refreshContent() {
ColumnLayout mainLayout = new ColumnLayout();
mainLayout.setHorizontalSpacing(8);
mainLayout.setVerticalSpacing(8);
fetchTelemetryCategoriesFromEngineOnlyEnvironment();
for (Map.Entry<TelemetryCategory, Class> telemetryCategory : telemetryCategories.entrySet()) {
Class metricClass = telemetryCategory.getValue();
Optional<Metric> optional = metrics.getMetric(metricClass);
if (optional.isPresent()) {
Metric metric = optional.get();
Map<String, ?> map = metric.createTelemetryFieldToValue();
if (map != null) {
addTelemetrySection(telemetryCategory.getKey(), mainLayout, map);
}
}
}
ScrollableArea area = find("area", ScrollableArea.class);
if (area != null) {
area.setContent(mainLayout);
}
}
use of org.terasology.nui.layouts.ColumnLayout in project Terasology by MovingBlocks.
the class ObjectLayoutBuilder method populateConstructorParameters.
private void populateConstructorParameters(Binding<T> binding, ColumnLayout parameterLayout, UIButton createInstanceButton, Binding<Constructor<T>> selectedConstructor) {
parameterLayout.removeAllWidgets();
Parameter[] parameters = selectedConstructor.get().getParameters();
List<TypeInfo<?>> parameterTypes = Arrays.stream(parameters).map(Parameter::getParameterizedType).map(parameterType -> ReflectionUtil.resolveType(type.getType(), parameterType)).map(TypeInfo::of).collect(Collectors.toList());
List<Binding<?>> argumentBindings = parameterTypes.stream().map(parameterType -> new DefaultBinding<>(Defaults.defaultValue(parameterType.getRawType()))).collect(Collectors.toList());
createInstanceButton.subscribe(widget -> {
Object[] arguments = argumentBindings.stream().map(Binding::get).toArray();
try {
binding.set(selectedConstructor.get().newInstance(arguments));
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
});
if (argumentBindings.isEmpty()) {
// TODO: Translate
parameterLayout.addWidget(new UILabel("Constructor has no parameters"));
return;
}
ColumnLayout parametersExpandableLayout = WidgetUtil.createExpandableLayout(// TODO: Translate
"Constructor Parameters", this::createDefaultLayout, layout -> {
for (int i = 0; i < parameterTypes.size(); i++) {
TypeInfo<?> parameterType = parameterTypes.get(i);
Binding<?> argumentBinding = argumentBindings.get(i);
Parameter parameter = parameters[i];
Optional<UIWidget> optionalWidget = library.getBaseTypeWidget((Binding) argumentBinding, parameterType);
if (!optionalWidget.isPresent()) {
LOGGER.warn("Could not create widget for parameter of type {} of constructor {}", parameter, selectedConstructor.get());
continue;
}
UIWidget widget = optionalWidget.get();
String parameterLabelText = ReflectionUtil.typeToString(parameterType.getType(), true);
layout.addWidget(WidgetUtil.labelize(widget, parameterLabelText, LABEL_WIDGET_ID));
}
}, this::createDefaultLayout);
parameterLayout.addWidget(parametersExpandableLayout);
}
use of org.terasology.nui.layouts.ColumnLayout in project Terasology by MovingBlocks.
the class ObjectLayoutBuilder method populateNullLayout.
private void populateNullLayout(Binding<T> binding, ColumnLayout layout, UILabel nameWidget) {
// TODO: Translate
if (MODIFY_LABEL.equals(nameWidget.getText())) {
nameWidget.setText(NULL_LABEL);
}
List<Constructor<T>> constructors = Arrays.stream(type.getRawType().getConstructors()).map(constructor -> (Constructor<T>) constructor).collect(Collectors.toList());
if (constructors.isEmpty()) {
// TODO: Translate
UIBox box = buildErrorWidget("No accessible constructors found");
layout.addWidget(box);
return;
}
ColumnLayout parameterLayout = createDefaultLayout();
UIButton createInstanceButton = new UIButton();
// TODO: Translate
createInstanceButton.setText("Create Instance");
UIDropdownScrollable<Constructor<T>> constructorSelection = new UIDropdownScrollable<>();
Binding<Constructor<T>> selectedConstructor = new NotifyingBinding<Constructor<T>>(constructors.get(0)) {
@Override
protected void onSet() {
populateConstructorParameters(binding, parameterLayout, createInstanceButton, this);
}
};
constructorSelection.setOptions(constructors);
constructorSelection.bindSelection(selectedConstructor);
constructorSelection.setOptionRenderer(new StringTextRenderer<Constructor<T>>() {
@Override
public String getString(Constructor<T> value) {
return ReflectionUtil.resolvedMethodToString(type.getType(), value, true);
}
});
// TODO: Translate
constructorSelection.setTooltip("Select the constructor to use to create the new object");
layout.addWidget(constructorSelection);
layout.addWidget(parameterLayout);
layout.addWidget(createInstanceButton);
}
Aggregations