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);
}
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;
}
}
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);
}
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));
}
}
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);
}
Aggregations