Search in sources :

Example 1 with Vector2i

use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.

the class InputSettingsScreen method addInputSection.

private void addInputSection(ColumnLayout layout, String name, ControllerInfo info) {
    UILabel categoryHeader = new UILabel(name);
    categoryHeader.setFamily("subheading");
    layout.addWidget(categoryHeader);
    float columnRatio = 0.4f;
    UICheckbox invertX = new UICheckbox();
    invertX.bindChecked(BindHelper.bindBeanProperty("invertX", info, Boolean.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-x}")), invertX).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    UICheckbox invertY = new UICheckbox();
    invertY.bindChecked(BindHelper.bindBeanProperty("invertY", info, Boolean.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-y}")), invertY).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    UICheckbox invertZ = new UICheckbox();
    invertZ.bindChecked(BindHelper.bindBeanProperty("invertZ", info, Boolean.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-z}")), invertZ).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    UISlider mvmtDeadZone = new UISlider();
    mvmtDeadZone.setIncrement(0.01f);
    mvmtDeadZone.setMinimum(0);
    mvmtDeadZone.setRange(1);
    mvmtDeadZone.setPrecision(2);
    mvmtDeadZone.bindValue(BindHelper.bindBeanProperty("movementDeadZone", info, Float.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#movement-dead-zone}")), mvmtDeadZone).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    UISlider rotDeadZone = new UISlider();
    rotDeadZone.setIncrement(0.01f);
    rotDeadZone.setMinimum(0);
    rotDeadZone.setRange(1);
    rotDeadZone.setPrecision(2);
    rotDeadZone.bindValue(BindHelper.bindBeanProperty("rotationDeadZone", info, Float.TYPE));
    layout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#rotation-dead-zone}")), rotDeadZone).setColumnRatios(columnRatio).setHorizontalSpacing(horizontalSpacing));
    layout.addWidget(new UISpace(new Vector2i(0, 16)));
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) UISlider(org.terasology.rendering.nui.widgets.UISlider) RowLayout(org.terasology.rendering.nui.layouts.RowLayout) UISpace(org.terasology.rendering.nui.widgets.UISpace) Vector2i(org.terasology.math.geom.Vector2i) UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox)

Example 2 with Vector2i

use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.

the class SelectModulesScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    remoteModuleRegistryUpdater = Executors.newSingleThreadExecutor().submit(moduleManager.getInstallManager().updateRemoteRegistry());
    selectModulesConfig = config.getSelectModulesConfig();
    resolver = new DependencyResolver(moduleManager.getRegistry());
    modulesLookup = Maps.newHashMap();
    sortedModules = Lists.newArrayList();
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module latestVersion = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        if (!latestVersion.isOnClasspath()) {
            ModuleSelectionInfo info = ModuleSelectionInfo.local(latestVersion);
            modulesLookup.put(info.getMetadata().getId(), info);
            sortedModules.add(info);
        }
    }
    Collections.sort(sortedModules, moduleInfoComparator);
    allSortedModules = new ArrayList<>(sortedModules);
    final UIList<ModuleSelectionInfo> moduleList = find("moduleList", UIList.class);
    if (moduleList != null) {
        moduleList.setList(sortedModules);
        moduleList.setItemRenderer(new AbstractItemRenderer<ModuleSelectionInfo>() {

            public String getString(ModuleSelectionInfo value) {
                return value.getMetadata().getDisplayName().toString();
            }

            @Override
            public void draw(ModuleSelectionInfo value, Canvas canvas) {
                if (isSelectedGameplayModule(value) && value.isValidToSelect()) {
                    canvas.setMode("gameplay");
                } else if (value.isSelected() && value.isExplicitSelection()) {
                    canvas.setMode("enabled");
                } else if (value.isSelected()) {
                    canvas.setMode("dependency");
                } else if (!value.isPresent()) {
                    canvas.setMode("disabled");
                } else if (!value.isValidToSelect()) {
                    canvas.setMode("invalid");
                } else {
                    canvas.setMode("available");
                }
                canvas.drawText(getString(value), canvas.getRegion());
            }

            @Override
            public Vector2i getPreferredSize(ModuleSelectionInfo value, Canvas canvas) {
                String text = getString(value);
                return new Vector2i(canvas.getCurrentStyle().getFont().getWidth(text), canvas.getCurrentStyle().getFont().getLineHeight());
            }
        });
        // ItemActivateEventListener is triggered by double clicking
        moduleList.subscribe((widget, item) -> {
            if (item.isSelected() && moduleList.getSelection().isExplicitSelection()) {
                deselect(item);
            } else if (item.isValidToSelect()) {
                select(item);
            }
        });
        ResettableUIText moduleSearch = find("moduleSearch", ResettableUIText.class);
        if (moduleSearch != null) {
            moduleSearch.subscribe(new TextChangeEventListener() {

                @Override
                public void onTextChange(String oldText, String newText) {
                    filterText(newText);
                }
            });
        }
        final Binding<ModuleMetadata> moduleInfoBinding = new ReadOnlyBinding<ModuleMetadata>() {

            @Override
            public ModuleMetadata get() {
                if (moduleList.getSelection() != null) {
                    return moduleList.getSelection().getMetadata();
                }
                return null;
            }
        };
        UILabel name = find("name", UILabel.class);
        if (name != null) {
            name.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    if (moduleInfoBinding.get() != null) {
                        return moduleInfoBinding.get().getDisplayName().toString();
                    }
                    return "";
                }
            });
        }
        UILabel installedVersion = find("installedVersion", UILabel.class);
        if (installedVersion != null) {
            installedVersion.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    ModuleSelectionInfo sel = moduleList.getSelection();
                    if (sel == null) {
                        return "";
                    }
                    return sel.isPresent() ? sel.getMetadata().getVersion().toString() : translationSystem.translate("${engine:menu#module-version-installed-none}");
                }
            });
        }
        UILabel onlineVersion = find("onlineVersion", UILabel.class);
        if (onlineVersion != null) {
            onlineVersion.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    ModuleSelectionInfo sel = moduleList.getSelection();
                    if (sel == null) {
                        return "";
                    }
                    return (sel.getOnlineVersion() != null) ? sel.getOnlineVersion().getVersion().toString() : "none";
                }
            });
        }
        UILabel description = find("description", UILabel.class);
        if (description != null) {
            description.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    ModuleMetadata moduleMetadata = moduleInfoBinding.get();
                    if (moduleMetadata != null) {
                        String dependenciesNames;
                        List<DependencyInfo> dependencies = moduleMetadata.getDependencies();
                        if (dependencies != null && dependencies.size() > 0) {
                            dependenciesNames = translationSystem.translate("${engine:menu#module-dependencies-exist}") + ":" + '\n';
                            for (DependencyInfo dependency : dependencies) {
                                dependenciesNames += "   " + dependency.getId().toString() + '\n';
                            }
                        } else {
                            dependenciesNames = translationSystem.translate("${engine:menu#module-dependencies-empty}") + ".";
                        }
                        return moduleMetadata.getDescription().toString() + '\n' + '\n' + dependenciesNames;
                    }
                    return "";
                }
            });
        }
        UILabel status = find("status", UILabel.class);
        if (status != null) {
            status.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    ModuleSelectionInfo info = moduleList.getSelection();
                    if (info != null) {
                        if (isSelectedGameplayModule(info)) {
                            return translationSystem.translate("${engine:menu#module-status-activegameplay}");
                        } else if (info.isSelected() && info.isExplicitSelection()) {
                            return translationSystem.translate("${engine:menu#module-status-activated}");
                        } else if (info.isSelected()) {
                            return translationSystem.translate("${engine:menu#module-status-dependency}");
                        } else if (!info.isPresent()) {
                            return translationSystem.translate("${engine:menu#module-status-notpresent}");
                        } else if (info.isValidToSelect()) {
                            return translationSystem.translate("${engine:menu#module-status-available}");
                        } else {
                            return translationSystem.translate("${engine:menu#module-status-error}");
                        }
                    }
                    return "";
                }
            });
        }
        UIButton toggleActivate = find("toggleActivation", UIButton.class);
        if (toggleActivate != null) {
            toggleActivate.subscribe(button -> {
                ModuleSelectionInfo info = moduleList.getSelection();
                if (info != null) {
                    // Toggle
                    if (info.isSelected() && info.isExplicitSelection()) {
                        deselect(info);
                    } else if (info.isValidToSelect()) {
                        select(info);
                    }
                }
            });
            toggleActivate.bindEnabled(new ReadOnlyBinding<Boolean>() {

                @Override
                public Boolean get() {
                    ModuleSelectionInfo info = moduleList.getSelection();
                    return info != null && info.isPresent() && !isSelectedGameplayModule(info) && (info.isSelected() || info.isValidToSelect());
                }
            });
            toggleActivate.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    if (moduleList.getSelection() != null) {
                        if (moduleList.getSelection().isExplicitSelection()) {
                            return translationSystem.translate("${engine:menu#deactivate-module}");
                        } else {
                            return translationSystem.translate("${engine:menu#activate-module}");
                        }
                    }
                    // button should be disabled
                    return translationSystem.translate("${engine:menu#activate-module}");
                }
            });
        }
        UIButton downloadButton = find("download", UIButton.class);
        if (downloadButton != null) {
            downloadButton.subscribe(button -> {
                if (moduleList.getSelection() != null) {
                    ModuleSelectionInfo info = moduleList.getSelection();
                    startDownloadingNewestModulesRequiredFor(info);
                }
            });
            downloadButton.bindEnabled(new ReadOnlyBinding<Boolean>() {

                @Override
                public Boolean get() {
                    try {
                        return moduleList.getSelection().getOnlineVersion() != null;
                    } catch (NullPointerException e) {
                        return false;
                    }
                }
            });
            downloadButton.bindText(new ReadOnlyBinding<String>() {

                @Override
                public String get() {
                    ModuleSelectionInfo info = moduleList.getSelection();
                    if (info != null && !info.isPresent()) {
                        return translationSystem.translate("${engine:menu#download-module}");
                    } else {
                        return translationSystem.translate("${engine:menu#update-module}");
                    }
                }
            });
        }
        UIButton disableAll = find("disableAll", UIButton.class);
        if (disableAll != null) {
            disableAll.subscribe(button -> sortedModules.stream().filter(info -> info.isSelected() && info.isExplicitSelection()).forEach(this::deselect));
        }
        localOnlyCheckbox = find("localOnly", UICheckbox.class);
        localOnlyCheckbox.bindChecked(new Binding<Boolean>() {

            @Override
            public Boolean get() {
                filterText(moduleSearch.getText());
                prepareModuleList(selectModulesConfig.isChecked());
                return selectModulesConfig.isChecked();
            }

            @Override
            public void set(Boolean value) {
                selectModulesConfig.setIsChecked(value);
                filterText(moduleSearch.getText());
                prepareModuleList(value);
            }
        });
    }
    WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
}
Also used : TextChangeEventListener(org.terasology.rendering.nui.widgets.TextChangeEventListener) Name(org.terasology.naming.Name) UIButton(org.terasology.rendering.nui.widgets.UIButton) List(java.util.List) ArrayList(java.util.ArrayList) UIList(org.terasology.rendering.nui.widgets.UIList) Vector2i(org.terasology.math.geom.Vector2i) UILabel(org.terasology.rendering.nui.widgets.UILabel) ReadOnlyBinding(org.terasology.rendering.nui.databinding.ReadOnlyBinding) Canvas(org.terasology.rendering.nui.Canvas) ModuleMetadata(org.terasology.module.ModuleMetadata) UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox) DependencyInfo(org.terasology.module.DependencyInfo) DependencyResolver(org.terasology.module.DependencyResolver) ResettableUIText(org.terasology.rendering.nui.widgets.ResettableUIText) Module(org.terasology.module.Module)

Example 3 with Vector2i

use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.

the class CardLayout method getPreferredContentSize.

/**
 * Retrieves the preferred content size of this {@code CardLayout}.
 * This is the minimum size this layout will take, given no space restrictions.
 *
 * @param canvas The {@code Canvas} on which this {@code CardLayout} is drawn
 * @param sizeHint A {@link Vector2i} representing the space available for widgets to be drawn in this layout
 * @return A {@code Vector2i} representing the preferred content size of this {@code CardLayout}
 */
@Override
public Vector2i getPreferredContentSize(Canvas canvas, Vector2i sizeHint) {
    int maxX = 0;
    int maxY = 0;
    for (UIWidget uiWidget : widgets.values()) {
        Vector2i preferredContentSize = uiWidget.getPreferredContentSize(canvas, sizeHint);
        maxX = Math.max(maxX, preferredContentSize.x);
        maxY = Math.max(maxY, preferredContentSize.y);
    }
    return new Vector2i(maxX, maxY);
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) LayoutHint(org.terasology.rendering.nui.LayoutHint) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 4 with Vector2i

use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.

the class CardLayout method getMaxContentSize.

/**
 * Retrieves the maximum content size of this {@code CardLayout}.
 *
 * @param canvas The {@code Canvas} on which this {@code CardLayout} is drawn
 * @return A {@code Vector2i} representing the maximum content size of this {@code CardLayout}
 */
@Override
public Vector2i getMaxContentSize(Canvas canvas) {
    int maxX = 0;
    int maxY = 0;
    for (UIWidget uiWidget : widgets.values()) {
        Vector2i maxContentSize = uiWidget.getMaxContentSize(canvas);
        maxX = Math.max(maxX, maxContentSize.x);
        maxY = Math.max(maxY, maxContentSize.y);
    }
    return new Vector2i(maxX, maxY);
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) LayoutHint(org.terasology.rendering.nui.LayoutHint) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 5 with Vector2i

use of org.terasology.math.geom.Vector2i in project Terasology by MovingBlocks.

the class ColumnLayout method getPreferredContentSize.

@Override
public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) {
    Vector2i availableSize = new Vector2i(areaHint);
    int numRows = TeraMath.ceilToInt((float) widgetList.size() / columns);
    if (numRows > 0) {
        availableSize.y -= verticalSpacing * (numRows - 1);
    }
    if (columns > 0) {
        availableSize.x -= horizontalSpacing * (columns - 1);
    }
    Iterator<List<UIWidget>> rows = getRowIterator();
    Vector2i size = new Vector2i();
    int[] columnSizes = new int[columns];
    while (rows.hasNext()) {
        List<UIWidget> row = rows.next();
        RowInfo rowInfo = calculateRowSize(row, canvas, availableSize);
        size.y += rowInfo.height;
        if (rows.hasNext()) {
            size.y += verticalSpacing;
        }
        for (int i = 0; i < rowInfo.widgetSizes.size(); ++i) {
            columnSizes[i] = Math.max(columnSizes[i], rowInfo.widgetSizes.get(i).getX());
        }
    }
    for (int columnSize : columnSizes) {
        size.x += columnSize;
    }
    if (!autoSizeColumns) {
        for (int i = 0; i < columns; ++i) {
            size.x = Math.max(size.x, TeraMath.floorToInt(columnSizes[i] / columnWidths[i]));
        }
    }
    size.x += horizontalSpacing * (columns - 1);
    return size;
}
Also used : List(java.util.List) Vector2i(org.terasology.math.geom.Vector2i) LayoutHint(org.terasology.rendering.nui.LayoutHint) UIWidget(org.terasology.rendering.nui.UIWidget)

Aggregations

Vector2i (org.terasology.math.geom.Vector2i)76 UIWidget (org.terasology.rendering.nui.UIWidget)17 Rect2i (org.terasology.math.geom.Rect2i)14 BaseVector2i (org.terasology.math.geom.BaseVector2i)13 LayoutHint (org.terasology.rendering.nui.LayoutHint)13 List (java.util.List)9 Test (org.junit.Test)9 Vector2f (org.terasology.math.geom.Vector2f)6 Canvas (org.terasology.rendering.nui.Canvas)5 SubRegion (org.terasology.rendering.nui.SubRegion)5 UIStyle (org.terasology.rendering.nui.skin.UIStyle)5 UILabel (org.terasology.rendering.nui.widgets.UILabel)5 Before (org.junit.Before)4 Font (org.terasology.rendering.assets.font.Font)4 Color (org.terasology.rendering.nui.Color)4 Border (org.terasology.math.Border)3 Vector3f (org.terasology.math.geom.Vector3f)3 Mesh (org.terasology.rendering.assets.mesh.Mesh)3 HorizontalAlign (org.terasology.rendering.nui.HorizontalAlign)3 Sets (com.google.common.collect.Sets)2