Search in sources :

Example 6 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class ColumnLayoutTest method testThreeColumnsAutosizedMinimallySized.

@Test
public void testThreeColumnsAutosizedMinimallySized() throws Exception {
    columnLayout.setAutoSizeColumns(true);
    columnLayout.setFillVerticalSpace(false);
    Vector2i result = columnLayout.getPreferredContentSize(canvas, canvas.size());
    assertEquals(75, result.x);
    assertEquals(20, result.y);
    columnLayout.onDraw(canvas);
    verify(canvas).drawWidget(itemAt1x1, RectUtility.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2), ((CANVAS_HEIGHT - 20) / 2), 50, 10));
    verify(canvas).drawWidget(itemAt2x1, RectUtility.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50, ((CANVAS_HEIGHT - 20) / 2), 5, 10));
    verify(canvas).drawWidget(itemAt3x1, RectUtility.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50 + 5, ((CANVAS_HEIGHT - 20) / 2), 20, 10));
    verify(canvas).drawWidget(itemAt1x2, RectUtility.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2), ((CANVAS_HEIGHT - 20) / 2) + 10, 50, 10));
    verify(canvas).drawWidget(itemAt2x2, RectUtility.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50, ((CANVAS_HEIGHT - 20) / 2) + 10, 5, 10));
    verify(canvas).drawWidget(itemAt3x2, RectUtility.createFromMinAndSize(((CANVAS_WIDTH - 75) / 2) + 50 + 5, ((CANVAS_HEIGHT - 20) / 2) + 10, 20, 10));
}
Also used : Vector2i(org.joml.Vector2i) Test(org.junit.jupiter.api.Test)

Example 7 with Vector2i

use of org.joml.Vector2i 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);
}
Also used : ColumnLayout(org.terasology.nui.layouts.ColumnLayout) Canvas(org.terasology.nui.Canvas) Vector2i(org.joml.Vector2i) UIWidget(org.terasology.nui.UIWidget) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class ZoomableLayoutTest method testZoomOut.

@Test
public void testZoomOut() throws Exception {
    zoomableLayout.onDraw(canvas);
    // zoom out 2x from top left corner
    zoomableLayout.zoom(2, 2, new Vector2i(0, 0));
    zoomableLayout.onDraw(canvas);
    // world size doubled
    assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH * 2 * 2, WORLD_HEIGHT * 2));
    assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
    assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / (WORLD_WIDTH * 2 * 2), CANVAS_HEIGHT / (WORLD_HEIGHT * 2)));
    verify(canvas).drawWidget(item1, new Rectanglei(new Vector2i(ceilToInt(pos1.x / 4), ceilToInt(pos1.y / 4)), new Vector2i(ceilToInt((pos1.x + size1.x) / 4), ceilToInt((pos1.y + size1.y) / 4))));
    verify(canvas).drawWidget(item2, new Rectanglei(new Vector2i(ceilToInt(pos2.x / 4), ceilToInt(pos2.y / 4)), new Vector2i(ceilToInt((pos2.x + size2.x) / 4), ceilToInt((pos2.y + size2.y) / 4))));
    verify(canvas).drawWidget(item3, new Rectanglei(new Vector2i(ceilToInt(pos3.x / 4), ceilToInt(pos3.y / 4)), new Vector2i(ceilToInt((pos3.x + size3.x) / 4), ceilToInt((pos3.y + size3.y) / 4))));
}
Also used : Vector2f(org.joml.Vector2f) Vector2i(org.joml.Vector2i) Rectanglei(org.terasology.joml.geom.Rectanglei) Test(org.junit.jupiter.api.Test)

Example 9 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class ZoomableLayoutTest method testScaling.

@Test
public void testScaling() throws Exception {
    zoomableLayout.onDraw(canvas);
    // world size scaled to fit ratio of screen size - world size now 200 x 100
    assertEquals(zoomableLayout.getWindowSize(), new Vector2f(WORLD_WIDTH * 2, WORLD_HEIGHT));
    assertEquals(zoomableLayout.getScreenSize(), new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT));
    assertEquals(zoomableLayout.getPixelSize(), new Vector2f(CANVAS_WIDTH / (WORLD_WIDTH * 2), CANVAS_HEIGHT / WORLD_HEIGHT));
    // coordinates on widgets scaled down by half
    verify(canvas).drawWidget(item1, new Rectanglei(new Vector2i(ceilToInt(pos1.x / 2), ceilToInt(pos1.y / 2)), new Vector2i(ceilToInt((pos1.x + size1.x) / 2), ceilToInt((pos1.y + size1.y) / 2))));
    verify(canvas).drawWidget(item2, new Rectanglei(new Vector2i(ceilToInt(pos2.x / 2), ceilToInt(pos2.y / 2)), new Vector2i(ceilToInt((pos2.x + size2.x) / 2), ceilToInt((pos2.y + size2.y) / 2))));
    verify(canvas).drawWidget(item3, new Rectanglei(new Vector2i(ceilToInt(pos3.x / 2), ceilToInt(pos3.y / 2)), new Vector2i(ceilToInt((pos3.x + size3.x) / 2), ceilToInt((pos3.y + size3.y) / 2))));
}
Also used : Vector2f(org.joml.Vector2f) Vector2i(org.joml.Vector2i) Rectanglei(org.terasology.joml.geom.Rectanglei) Test(org.junit.jupiter.api.Test)

Example 10 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class PlayerFactory method findSpawnPos.

private Optional<Vector3f> findSpawnPos(Vector3fc targetPos, float entityHeight) {
    int targetBlockX = TeraMath.floorToInt(targetPos.x());
    int targetBlockY = TeraMath.floorToInt(targetPos.y());
    int targetBlockZ = TeraMath.floorToInt(targetPos.z());
    Vector2i center = new Vector2i(targetBlockX, targetBlockZ);
    for (Vector2ic pos : SpiralIterable.clockwise(center).maxRadius(32).scale(2).build()) {
        Vector3i testPos = new Vector3i(pos.x(), targetBlockY, pos.y());
        Vector3i spawnPos = findOpenVerticalPosition(testPos, entityHeight);
        if (spawnPos != null) {
            return Optional.of(new Vector3f(spawnPos.x(), spawnPos.y() + entityHeight, spawnPos.z()));
        }
    }
    return Optional.empty();
}
Also used : Vector2ic(org.joml.Vector2ic) Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) Vector2i(org.joml.Vector2i)

Aggregations

Vector2i (org.joml.Vector2i)41 Test (org.junit.jupiter.api.Test)12 Rectanglei (org.terasology.joml.geom.Rectanglei)9 Canvas (org.terasology.nui.Canvas)9 UILabel (org.terasology.nui.widgets.UILabel)6 List (java.util.List)5 Objects (java.util.Objects)5 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)5 Vector2f (org.joml.Vector2f)4 Vector2ic (org.joml.Vector2ic)4 Module (org.terasology.gestalt.module.Module)4 Name (org.terasology.gestalt.naming.Name)4 UIButton (org.terasology.nui.widgets.UIButton)4 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Collection (java.util.Collection)3 Comparator (java.util.Comparator)3 Iterator (java.util.Iterator)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3