Search in sources :

Example 31 with Vector2i

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

the class LayeredZoneRegionFunction method getLayerRange.

private LayerRange getLayerRange(int x, int z, Region region) {
    Vector2i pos = new Vector2i(x, z);
    if (!layerRangeMap.containsKey(pos)) {
        int surfaceHeight = (int) Math.floor(region.getFacet(SurfaceHeightFacet.class).getWorld(pos));
        boolean aboveground = ordering > 0;
        int cumulativeDistanceSmall = 0;
        int cumulativeDistanceLarge = 0;
        LayerRange layerRange = null;
        List<LayeredZoneRegionFunction> layers = aboveground ? abovegroundLayers : undergroundLayers;
        int layerIndex;
        for (layerIndex = 0; layerIndex < layers.size(); layerIndex++) {
            LayeredZoneRegionFunction currentLayer = layers.get(layerIndex);
            int thickness = currentLayer.layerThickness.get(x, z);
            cumulativeDistanceLarge += thickness;
            if (this.equals(currentLayer)) {
                if (aboveground) {
                    layerRange = new LayerRange().setMin(surfaceHeight + cumulativeDistanceSmall).setMax(surfaceHeight + cumulativeDistanceLarge);
                    break;
                } else {
                    layerRange = new LayerRange().setMin(surfaceHeight - cumulativeDistanceLarge).setMax(surfaceHeight - cumulativeDistanceSmall);
                    break;
                }
            }
            cumulativeDistanceSmall += thickness;
        }
        if (layers.size() <= 0 || layerRange == null) {
            throw new IllegalStateException("Layer for zone '" + parent + "' not found in list of " + (aboveground ? "aboveground" : "underground") + " layers.");
        }
        if (layerIndex == layers.size() - 1) {
            // At one of the edge layers
            if (aboveground) {
                layerRange.unsetMax();
            } else {
                layerRange.unsetMin();
            }
        }
        layerRangeMap.put(pos, layerRange);
    }
    return layerRangeMap.get(pos);
}
Also used : SurfaceHeightFacet(org.terasology.world.generation.facets.SurfaceHeightFacet) Vector2i(org.terasology.math.geom.Vector2i)

Example 32 with Vector2i

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

the class SubSampledNoise method getSubset.

private float[] getSubset(float[] fullData, Rect2i fullRegion, Rect2i subRegion) {
    if (subRegion.sizeX() != fullRegion.sizeX() || subRegion.sizeY() != fullRegion.sizeY()) {
        float[] result = new float[subRegion.sizeX() * subRegion.sizeY()];
        Vector2i offset = new Vector2i(subRegion.minX() - fullRegion.minX(), subRegion.minY() - fullRegion.minY());
        for (int y = 0; y < subRegion.sizeY(); ++y) {
            System.arraycopy(fullData, offset.getX() + fullRegion.sizeX() * (y + offset.getY()), result, subRegion.sizeX() * y, subRegion.sizeX());
        }
        return result;
    } else {
        return fullData;
    }
}
Also used : Vector2i(org.terasology.math.geom.Vector2i)

Example 33 with Vector2i

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

the class InventoryGrid method getPreferredContentSize.

@Override
public Vector2i getPreferredContentSize(Canvas canvas, Vector2i sizeHint) {
    int numSlots = getNumSlots();
    if (numSlots == 0 || cells.isEmpty()) {
        return Vector2i.zero();
    }
    Vector2i cellSize = canvas.calculatePreferredSize(cells.get(0));
    if (cellSize.getX() == 0 || cellSize.getY() == 0) {
        return Vector2i.zero();
    }
    int horizontalCells = Math.min(Math.min(maxHorizontalCells, numSlots), sizeHint.getX() / cellSize.getX());
    int verticalCells = ((numSlots - 1) / horizontalCells) + 1;
    return new Vector2i(horizontalCells * cellSize.x, verticalCells * cellSize.y);
}
Also used : Vector2i(org.terasology.math.geom.Vector2i)

Example 34 with Vector2i

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

the class InventoryGrid method onDraw.

@Override
public void onDraw(Canvas canvas) {
    int numSlots = getNumSlots();
    if (numSlots == 0 || cells.isEmpty()) {
        return;
    }
    Vector2i cellSize = canvas.calculatePreferredSize(cells.get(0));
    if (cellSize.getX() == 0 || cellSize.getY() == 0) {
        return;
    }
    canvas.addInteractionRegion(interactionListener);
    int horizontalCells = Math.max(1, Math.min(maxHorizontalCells, canvas.size().getX() / cellSize.getX()));
    for (int i = 0; i < numSlots && i < cells.size(); ++i) {
        int horizPos = i % horizontalCells;
        int vertPos = i / horizontalCells;
        canvas.drawWidget(cells.get(i), Rect2i.createFromMinAndSize(horizPos * cellSize.x, vertPos * cellSize.y, cellSize.x, cellSize.y));
    }
}
Also used : Vector2i(org.terasology.math.geom.Vector2i)

Example 35 with Vector2i

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

the class CardLayoutTest method setup.

@Before
public void setup() {
    cardLayout = new CardLayout();
    widget1 = mock(UIWidget.class);
    widget2 = mock(UIWidget.class);
    widget3 = mock(UIWidget.class);
    canvas = mock(Canvas.class);
    // +-----------------------------------+  +---+  +-------+
    // |                                   |  |1x2|  |       |
    // |               1x1                 |  +---+  |       |
    // |                                   |         |  1x3  |
    // +-----------------------------------+         |       |
    // |       |
    // +-------+
    when(widget1.getPreferredContentSize(eq(canvas), any(Vector2i.class))).thenReturn(new Vector2i(50, 10));
    when(widget2.getPreferredContentSize(eq(canvas), any(Vector2i.class))).thenReturn(new Vector2i(5, 5));
    when(widget3.getPreferredContentSize(eq(canvas), any(Vector2i.class))).thenReturn(new Vector2i(10, 15));
    when(widget1.getId()).thenReturn("widget1");
    when(widget2.getId()).thenReturn("widget2");
    when(widget3.getId()).thenReturn("widget3");
    Vector2i availableSize = new Vector2i(200, 200);
    when(canvas.size()).thenReturn(availableSize);
    cardLayout.addWidget(widget1);
    cardLayout.addWidget(widget2);
    cardLayout.addWidget(widget3);
}
Also used : Canvas(org.terasology.rendering.nui.Canvas) Vector2i(org.terasology.math.geom.Vector2i) UIWidget(org.terasology.rendering.nui.UIWidget) Before(org.junit.Before)

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