mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Fix rounding issues with hexagon rendering
This commit is contained in:
@@ -173,15 +173,15 @@ public class CommandCenterScreen extends FScreen implements IVCommandCenter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doLayout(float startY, float width, float height) {
|
protected void doLayout(float startY, float width, float height) {
|
||||||
btnEndDay.setSize(width / 2, btnEndDay.getAutoSizeBounds().height);
|
//btnEndDay.setSize(width / 2, btnEndDay.getAutoSizeBounds().height);
|
||||||
btnEndDay.setPosition((width - btnEndDay.getWidth()) / 2, height - btnEndDay.getHeight());
|
//btnEndDay.setPosition((width - btnEndDay.getWidth()) / 2, height - btnEndDay.getHeight());
|
||||||
|
|
||||||
//float numCommanders = commanderRow.panels.length;
|
//float numCommanders = commanderRow.panels.length;
|
||||||
//float commanderWidth = (width - (numCommanders + 3) * COMMANDER_GAP) / numCommanders;
|
//float commanderWidth = (width - (numCommanders + 3) * COMMANDER_GAP) / numCommanders;
|
||||||
//float commanderRowHeight = commanderWidth * FCardPanel.ASPECT_RATIO + 2 * COMMANDER_ROW_PADDING;
|
//float commanderRowHeight = commanderWidth * FCardPanel.ASPECT_RATIO + 2 * COMMANDER_ROW_PADDING;
|
||||||
//commanderRow.setBounds(0, btnEndDay.getTop() - PLANE_NAME_FONT.getLineHeight() - 2 * FLabel.DEFAULT_INSETS - commanderRowHeight, width, commanderRowHeight);
|
//commanderRow.setBounds(0, btnEndDay.getTop() - PLANE_NAME_FONT.getLineHeight() - 2 * FLabel.DEFAULT_INSETS - commanderRowHeight, width, commanderRowHeight);
|
||||||
|
|
||||||
map.setBounds(0, startY, width, btnEndDay.getTop() - startY);
|
map.setBounds(0, startY, width, height - startY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PlaneMap extends FScrollPane implements IPlaneMapRenderer {
|
private class PlaneMap extends FScrollPane implements IPlaneMapRenderer {
|
||||||
@@ -200,19 +200,19 @@ public class CommandCenterScreen extends FScreen implements IVCommandCenter {
|
|||||||
return new ScrollBounds(visibleWidth, visibleHeight);
|
return new ScrollBounds(visibleWidth, visibleHeight);
|
||||||
}
|
}
|
||||||
mapData = model.getCurrentPlaneData().getMap();
|
mapData = model.getCurrentPlaneData().getMap();
|
||||||
mapData.setTileWidth(visibleWidth / 4 * zoom);
|
mapData.setTileWidth(Math.round(visibleWidth / 4 * zoom));
|
||||||
return new ScrollBounds(mapData.getWidth(), mapData.getHeight());
|
return new ScrollBounds(mapData.getWidth(), mapData.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void drawBackground(Graphics g0) {
|
protected void drawBackground(Graphics g0) {
|
||||||
if (mapData == null) { return; }
|
if (mapData == null) { return; }
|
||||||
g = g0;
|
g = g0;
|
||||||
mapData.draw(this, getScrollLeft(), getScrollTop(), getWidth(), getHeight());
|
mapData.draw(this, Math.round(getScrollLeft()), Math.round(getScrollTop()), Math.round(getWidth()), Math.round(getHeight()));
|
||||||
g = null;
|
g = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(HexagonTile tile, float x, float y, float w, float h) {
|
public void draw(HexagonTile tile, int x, int y, int w, int h) {
|
||||||
g.drawImage(FSkinImage.HEXAGON_TILE, x, y, w, h);
|
g.drawImage(FSkinImage.HEXAGON_TILE, x, y, w, h);
|
||||||
|
|
||||||
float pedestalWidth = w * 0.2f;//0.8f;
|
float pedestalWidth = w * 0.2f;//0.8f;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class ConquestPlaneMap {
|
|||||||
private final int gridSize;
|
private final int gridSize;
|
||||||
private final HexagonTile[][] grid;
|
private final HexagonTile[][] grid;
|
||||||
private int tileCount;
|
private int tileCount;
|
||||||
private float tileWidth, tileHeight;
|
private int tileWidth, tileHeight;
|
||||||
|
|
||||||
public ConquestPlaneMap(ConquestPlane plane) {
|
public ConquestPlaneMap(ConquestPlane plane) {
|
||||||
int size = (int)Math.round(Math.sqrt(plane.getCardPool().size() / 3)); //use card pool size to determine grid size
|
int size = (int)Math.round(Math.sqrt(plane.getCardPool().size() / 3)); //use card pool size to determine grid size
|
||||||
@@ -23,16 +23,16 @@ public class ConquestPlaneMap {
|
|||||||
generateRandomGrid();
|
generateRandomGrid();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTileWidth(float tileWidth0) {
|
public void setTileWidth(int tileWidth0) {
|
||||||
if (tileWidth == tileWidth0) { return; }
|
if (tileWidth == tileWidth0) { return; }
|
||||||
tileWidth = tileWidth0;
|
tileWidth = tileWidth0;
|
||||||
tileHeight = tileWidth * (float)FSkinProp.IMG_HEXAGON_TILE.getHeight() / (float)FSkinProp.IMG_HEXAGON_TILE.getWidth();
|
tileHeight = Math.round((float)tileWidth * (float)FSkinProp.IMG_HEXAGON_TILE.getHeight() / (float)FSkinProp.IMG_HEXAGON_TILE.getWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getWidth() {
|
public int getWidth() {
|
||||||
return tileWidth * 0.75f * (gridSize - 1) + tileWidth;
|
return tileWidth * 3 / 4 * (gridSize - 1) + tileWidth;
|
||||||
}
|
}
|
||||||
public float getHeight() {
|
public int getHeight() {
|
||||||
return tileHeight * gridSize + tileHeight / 2;
|
return tileHeight * gridSize + tileHeight / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,16 +52,16 @@ public class ConquestPlaneMap {
|
|||||||
return grid[q][r];
|
return grid[q][r];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw(IPlaneMapRenderer renderer, float scrollLeft, float scrollTop, float visibleWidth, float visibleHeight) {
|
public void draw(IPlaneMapRenderer renderer, int scrollLeft, int scrollTop, int visibleWidth, int visibleHeight) {
|
||||||
float dx = tileWidth * 0.75f;
|
int dx = tileWidth * 3 / 4;
|
||||||
int startQ = getIndexInRange((int)Math.floor((scrollLeft - tileWidth) / dx) + 1);
|
int startQ = getIndexInRange((int)Math.floor((float)(scrollLeft - tileWidth) / (float)dx) + 1);
|
||||||
int startR = getIndexInRange((int)Math.floor((scrollTop - tileHeight * 1.5f) / tileHeight) + 1);
|
int startR = getIndexInRange((int)Math.floor((float)(scrollTop - tileHeight * 1.5f) / (float)tileHeight) + 1);
|
||||||
int endQ = getIndexInRange((int)Math.floor((scrollLeft + visibleWidth - tileWidth) / dx) + 2);
|
int endQ = getIndexInRange((int)Math.floor((float)(scrollLeft + visibleWidth - tileWidth) / (float)dx) + 2);
|
||||||
int endR = getIndexInRange((int)Math.floor((scrollTop + visibleHeight - tileHeight * 1.5f) / tileHeight) + 2);
|
int endR = getIndexInRange((int)Math.floor((float)(scrollTop + visibleHeight - tileHeight * 1.5f) / (float)tileHeight) + 2);
|
||||||
|
|
||||||
float y;
|
int y;
|
||||||
float x = startQ * dx - scrollLeft;
|
int x = startQ * dx - scrollLeft;
|
||||||
float startY = startR * tileHeight - scrollTop;
|
int startY = startR * tileHeight - scrollTop;
|
||||||
for (int q = startQ; q <= endQ; q++) {
|
for (int q = startQ; q <= endQ; q++) {
|
||||||
y = startY;
|
y = startY;
|
||||||
if (q % 2 == 1) {
|
if (q % 2 == 1) {
|
||||||
@@ -89,7 +89,7 @@ public class ConquestPlaneMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static interface IPlaneMapRenderer {
|
public static interface IPlaneMapRenderer {
|
||||||
void draw(HexagonTile tile, float x, float y, float w, float h);
|
void draw(HexagonTile tile, int x, int y, int w, int h);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateRandomGrid() {
|
private void generateRandomGrid() {
|
||||||
|
|||||||
Reference in New Issue
Block a user