Search in sources :

Example 46 with Vector2i

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

the class StringTextRenderer method getPreferredSize.

@Override
public Vector2i getPreferredSize(T value, Canvas canvas) {
    Font font = canvas.getCurrentStyle().getFont();
    String text = getString(value);
    if (wrap) {
        List<String> lines = TextLineBuilder.getLines(font, text, canvas.size().x);
        return font.getSize(lines);
    } else {
        return new Vector2i(font.getWidth(text), font.getLineHeight());
    }
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) Font(org.terasology.rendering.assets.font.Font)

Example 47 with Vector2i

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

the class InputSettingsScreen method addInputSection.

private void addInputSection(InputCategory category, ColumnLayout layout, Map<SimpleUri, RegisterBindButton> inputsById) {
    if (category != null) {
        layout.addWidget(new UISpace(new Vector2i(0, 16)));
        UILabel categoryHeader = new UILabel(translationSystem.translate(category.displayName()));
        categoryHeader.setFamily("subheading");
        layout.addWidget(categoryHeader);
        Set<SimpleUri> processedBinds = Sets.newHashSet();
        for (String bindId : category.ordering()) {
            SimpleUri bindUri = new SimpleUri(bindId);
            if (bindUri.isValid()) {
                RegisterBindButton bind = inputsById.get(new SimpleUri(bindId));
                if (bind != null) {
                    addInputBindRow(bindUri, bind, layout);
                    processedBinds.add(bindUri);
                }
            }
        }
        List<ExtensionBind> extensionBindList = Lists.newArrayList();
        for (Map.Entry<SimpleUri, RegisterBindButton> bind : inputsById.entrySet()) {
            if (bind.getValue().category().equals(category.id()) && !processedBinds.contains(bind.getKey())) {
                extensionBindList.add(new ExtensionBind(bind.getKey(), bind.getValue()));
            }
        }
        Collections.sort(extensionBindList);
        for (ExtensionBind extension : extensionBindList) {
            addInputBindRow(extension.uri, extension.bind, layout);
        }
    }
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) RegisterBindButton(org.terasology.input.RegisterBindButton) SimpleUri(org.terasology.engine.SimpleUri) UISpace(org.terasology.rendering.nui.widgets.UISpace) Vector2i(org.terasology.math.geom.Vector2i) Map(java.util.Map)

Example 48 with Vector2i

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

the class InputSettingsScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    ColumnLayout mainLayout = new ColumnLayout();
    mainLayout.setHorizontalSpacing(8);
    mainLayout.setVerticalSpacing(8);
    mainLayout.setFamily("option-grid");
    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));
    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);
        if (module.isCodeModule()) {
            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);
                        }
                    }
                }
            }
        }
    }
    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);
    }
    ScrollableArea area = find("area", ScrollableArea.class);
    area.setContent(mainLayout);
    WidgetUtil.trySubscribe(this, "reset", button -> {
        inputDeviceConfiguration.reset();
        bindsManager.getBindsConfig().setBinds(bindsManager.getDefaultBindsConfig());
    });
    WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) UISlider(org.terasology.rendering.nui.widgets.UISlider) RegisterBindButton(org.terasology.input.RegisterBindButton) ResolutionResult(org.terasology.module.ResolutionResult) SimpleUri(org.terasology.engine.SimpleUri) UICheckbox(org.terasology.rendering.nui.widgets.UICheckbox) DependencyResolver(org.terasology.module.DependencyResolver) Name(org.terasology.naming.Name) ModuleEnvironment(org.terasology.module.ModuleEnvironment) ScrollableArea(org.terasology.rendering.nui.layouts.ScrollableArea) ColumnLayout(org.terasology.rendering.nui.layouts.ColumnLayout) RowLayout(org.terasology.rendering.nui.layouts.RowLayout) InputCategory(org.terasology.input.InputCategory) UISpace(org.terasology.rendering.nui.widgets.UISpace) Vector2i(org.terasology.math.geom.Vector2i) FromModule(org.terasology.module.predicates.FromModule) Module(org.terasology.module.Module) FromModule(org.terasology.module.predicates.FromModule) ControllerInfo(org.terasology.config.ControllerConfig.ControllerInfo)

Example 49 with Vector2i

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

the class ColumnLayout method calculateRowSize.

private RowInfo calculateRowSize(List<UIWidget> row, Canvas canvas, Vector2i areaHint) {
    int availableWidth = areaHint.x - horizontalSpacing * (columns - 1);
    RowInfo rowInfo = new RowInfo();
    for (int i = 0; i < columns && i < row.size(); ++i) {
        UIWidget widget = row.get(i);
        Vector2i cellSize = new Vector2i(availableWidth, areaHint.y);
        if (!autoSizeColumns) {
            cellSize.x *= columnWidths[i];
        }
        if (widget != null) {
            Vector2i contentSize = canvas.calculateRestrictedSize(widget, cellSize);
            rowInfo.widgetSizes.add(contentSize);
            rowInfo.height = Math.max(rowInfo.height, contentSize.y);
        } else {
            rowInfo.widgetSizes.add(new Vector2i(0, 0));
        }
    }
    return rowInfo;
}
Also used : Vector2i(org.terasology.math.geom.Vector2i) LayoutHint(org.terasology.rendering.nui.LayoutHint) UIWidget(org.terasology.rendering.nui.UIWidget)

Example 50 with Vector2i

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

the class ColumnLayout method getMaxContentSize.

@Override
public Vector2i getMaxContentSize(Canvas canvas) {
    Iterator<List<UIWidget>> rows = getRowIterator();
    Vector2i size = new Vector2i();
    int[] columnSizes = new int[columns];
    while (rows.hasNext()) {
        List<UIWidget> row = rows.next();
        int rowHeight = 0;
        for (int i = 0; i < row.size(); ++i) {
            Vector2i maxSize = canvas.calculateMaximumSize(row.get(i));
            columnSizes[i] = Math.max(columnSizes[i], maxSize.x);
            rowHeight = Math.max(rowHeight, maxSize.y);
        }
        size.y = TeraMath.addClampAtMax(size.y, rowHeight);
        if (rows.hasNext()) {
            size.y = TeraMath.addClampAtMax(size.y, verticalSpacing);
        }
    }
    long width = 0;
    for (int columnSize : columnSizes) {
        width += columnSize;
    }
    if (!autoSizeColumns) {
        for (int i = 0; i < columns; ++i) {
            width = Math.min(width, TeraMath.floorToInt(columnSizes[i] / columnWidths[i]));
        }
    }
    width += horizontalSpacing * (columns - 1);
    size.x = (int) Math.min(Integer.MAX_VALUE, width);
    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