Tweak conquest map screen rendering to allow for portal rows

This commit is contained in:
drdev
2015-11-28 16:14:27 +00:00
parent 7a330763ef
commit e5a5855d2a

View File

@@ -19,40 +19,21 @@ import forge.planarconquest.ConquestPlane.Region;
import forge.screens.FScreen; import forge.screens.FScreen;
import forge.toolbox.FList; import forge.toolbox.FList;
import forge.toolbox.FList.ListItemRenderer; import forge.toolbox.FList.ListItemRenderer;
import forge.toolbox.FScrollPane;
import forge.util.collect.FCollectionView; import forge.util.collect.FCollectionView;
public class ConquestMapScreen extends FScreen { public class ConquestMapScreen extends FScreen {
private static final int GRID_ROWS = 3;
private static final int GRID_COLS = 3;
private static final Color FOG_OF_WAR_COLOR = FSkinColor.alphaColor(Color.BLACK, 0.6f); private static final Color FOG_OF_WAR_COLOR = FSkinColor.alphaColor(Color.BLACK, 0.6f);
private final FList<Region> lstRegions; private final PlaneGrid planeGrid;
private ConquestData model; private ConquestData model;
public ConquestMapScreen() { public ConquestMapScreen() {
super("", ConquestMenu.getMenu()); super("", ConquestMenu.getMenu());
lstRegions = add(new FList<Region>() { planeGrid = add(new PlaneGrid());
@Override
protected void drawBackground(Graphics g) {
//draw no background
}
@Override
public void drawOverlay(Graphics g) {
//draw no overlay
}
@Override
protected FSkinColor getItemFillColor(int index) {
return null;
}
@Override
protected boolean drawLineSeparators() {
return false;
}
@Override
protected float getPadding() {
return 0;
}
});
lstRegions.setListItemRenderer(new PlaneRenderer());
} }
@Override @Override
@@ -62,31 +43,22 @@ public class ConquestMapScreen extends FScreen {
@Override @Override
protected void doLayout(float startY, float width, float height) { protected void doLayout(float startY, float width, float height) {
lstRegions.setBounds(0, startY, width, height - startY); planeGrid.setBounds(0, startY, width, height - startY);
} }
public void update() { public void update() {
model = FModel.getConquest().getModel(); model = FModel.getConquest().getModel();
setHeaderCaption(model.getCurrentPlane().getName()); setHeaderCaption(model.getCurrentPlane().getName());
FCollectionView<Region> regions = model.getCurrentPlane().getRegions(); planeGrid.revalidate();
lstRegions.clear(); planeGrid.scrollToBottom(); //start at bottom and move up
for (int i = regions.size() - 1; i >= 0; i--) {
lstRegions.addItem(regions.get(i));
}
lstRegions.revalidate();
lstRegions.scrollToBottom(); //start at bottom and move up
} }
private class PlaneRenderer extends ListItemRenderer<ConquestPlane.Region> { private class PlaneGrid extends FScrollPane {
@Override
public float getItemHeight() {
return ConquestMapScreen.this.getWidth() / CardRenderer.CARD_ART_RATIO;
}
@Override @Override
public boolean tap(Integer index, Region region, float x, float y, int count) { public boolean tap(float x, float y, int count) {
float colWidth = getWidth() / cols; /*float colWidth = getWidth() / cols;
float rowHeight = getItemHeight() / rows; float rowHeight = getItemHeight() / rows;
int row = rows - (int)(y / rowHeight) - 1; int row = rows - (int)(y / rowHeight) - 1;
int col = (int)(x / colWidth); int col = (int)(x / colWidth);
@@ -99,126 +71,93 @@ public class ConquestMapScreen extends FScreen {
if (position > model.getProgress()) { if (position > model.getProgress()) {
return false; return false;
} }
model.setPlaneswalkerPosition(position); model.setPlaneswalkerPosition(position);*/
return true; return true;
} }
@Override @Override
public void drawValue(Graphics g, Integer index, Region region, public void draw(Graphics g) {
FSkinFont font, FSkinColor foreColor, FSkinColor backColor, float w = getWidth();
boolean pressed, float x, float y, float w, float h) { float h = getHeight();
float regionHeight = w / CardRenderer.CARD_ART_RATIO;
float colWidth = w / GRID_COLS;
float rowHeight = regionHeight / GRID_ROWS;
//draw background art g.startClip(0, 0, w, h);
FImage art = (FImage)region.getArt();
if (art != null) { float x = 0;
g.drawImage(art, x, y, w, h); float y = -getScrollTop();
//draw top portal row
if (y + rowHeight > 0) {
g.fillRect(Color.MAGENTA, 0, y, w, rowHeight);
} }
else { //draw fallback background color if needed y += rowHeight;
List<DetailColors> colors = CardDetailUtil.getBorderColors(region.getColorSet());
DetailColors dc = colors.get(0); FCollectionView<Region> regions = model.getCurrentPlane().getRegions();
Color color1 = FSkinColor.fromRGB(dc.r, dc.g, dc.b); for (int i = regions.size() - 1; i >= 0; i--) {
Color color2 = null; if (y + regionHeight <= 0) {
if (colors.size() > 1) { y += regionHeight;
dc = colors.get(1); continue;
color2 = FSkinColor.fromRGB(dc.r, dc.g, dc.b);
} }
if (color2 == null) { if (y > h) { break; }
g.fillRect(color1, x, y, w, h);
//draw background art
Region region = regions.get(i);
FImage art = (FImage)region.getArt();
if (art != null) {
g.drawImage(art, x, y, w, regionHeight);
} }
else { else { //draw fallback background color if needed
g.fillGradientRect(color1, color2, false, x, y, w, h); List<DetailColors> colors = CardDetailUtil.getBorderColors(region.getColorSet());
DetailColors dc = colors.get(0);
Color color1 = FSkinColor.fromRGB(dc.r, dc.g, dc.b);
Color color2 = null;
if (colors.size() > 1) {
dc = colors.get(1);
color2 = FSkinColor.fromRGB(dc.r, dc.g, dc.b);
}
if (color2 == null) {
g.fillRect(color1, x, y, w, regionHeight);
}
else {
g.fillGradientRect(color1, color2, false, x, y, w, regionHeight);
}
} }
}
int progress = model.getProgress(); //draw row lines
int regionCount = model.getCurrentPlane().getRegions().size(); float y0 = y;
FCollectionView<ConquestOpponent> opponents = region.getOpponents(); for (int r = 0; r < GRID_ROWS; r++) {
int regionIndex = regionCount - index - 1; g.drawLine(1, Color.BLACK, 0, y0, w, y0);
int startIndex = regionIndex * opponents.size(); y0 += rowHeight;
//draw path with opponents
float x0, y0;
float colWidth = w / cols;
float rowHeight = h / rows;
float iconSize = Math.min(colWidth, rowHeight) * 0.33f;
float iconBackdropRadius = iconSize * 0.75f;
float iconOffsetX = (colWidth - iconSize) / 2;
float iconOffsetY = (rowHeight - iconSize) / 2;
float lineThickness = iconSize / 4;
float prevX;
float prevY = y + h;
if (regionIndex % 2 == 0) {
prevX = x + colWidth / 2;
}
else {
prevX = x + w - colWidth / 2;
}
//draw line path
for (int i = 0; i < opponents.size(); i++) {
GridPosition pos = new GridPosition(startIndex, i);
x0 = x + colWidth * pos.col + colWidth / 2;
y0 = y + rowHeight * pos.row + rowHeight / 2;
if (i > 0 || startIndex > 0) { //extend path from previous region if any
g.drawLine(lineThickness, Color.WHITE, x0, y0, prevX, prevY);
} }
prevX = x0;
prevY = y0; y += regionHeight;
} }
//extend path to next region if not topmost region //draw bottom portal row
if (index > 0) { if (y <= h) {
g.drawLine(lineThickness, Color.WHITE, prevX, prevY, prevX, y); g.fillRect(Color.MAGENTA, 0, y, w, rowHeight);
g.drawLine(1, Color.BLACK, 0, y, w, y);
} }
//draw icons for stops along path for opponents //draw column lines
for (int i = 0; i < opponents.size(); i++) { float x0 = x + colWidth;
GridPosition pos = new GridPosition(startIndex, i); for (int c = 1; c < GRID_COLS; c++) {
x0 = x + colWidth * pos.col + iconOffsetX; g.drawLine(1, Color.BLACK, x0, 0, x0, h);
y0 = y + rowHeight * pos.row + iconOffsetY; x0 += colWidth;
g.fillCircle(Color.BLACK, x0 + iconSize / 2, y0 + iconSize / 2, iconBackdropRadius);
g.drawImage((FImage)opponents.get(i).getMapIcon(), x0, y0, iconSize, iconSize);
} }
//draw fog of war overlay if region not yet unlocked g.endClip();
if (startIndex > progress) {
g.fillRect(FOG_OF_WAR_COLOR, x, y, w, h);
}
else {
//draw planeswalker token above stop
int planeswalkerPosition = model.getPlaneswalkerPosition() - startIndex;
if (planeswalkerPosition >= 0 && planeswalkerPosition < opponents.size()) {
GridPosition pos = new GridPosition(startIndex, planeswalkerPosition);
x0 = x + colWidth * pos.col + iconOffsetX;
y0 = y + rowHeight * pos.row + iconOffsetY;
FImage token = (FImage)model.getPlaneswalkerToken();
float tokenWidth = iconSize * 2f;
float tokenHeight = tokenWidth * token.getHeight() / token.getWidth();
g.drawImage(token, x0 + (iconSize - tokenWidth) / 2, y0 - tokenHeight, tokenWidth, tokenHeight);
}
}
} }
}
//path through region should look like this: @Override
// 11 12 13 14 15 protected ScrollBounds layoutAndGetScrollBounds(float visibleWidth, float visibleHeight) {
// 10 09 08 07 06 float regionHeight = visibleWidth / CardRenderer.CARD_ART_RATIO;
// 01 02 03 04 05 float rowHeight = regionHeight / GRID_ROWS;
private static final int rows = 3; float height = model.getCurrentPlane().getRegions().size() * regionHeight;
private static final int cols = 5; height += 2 * rowHeight; //account for portal row at top and bottom
return new ScrollBounds(visibleWidth, height);
private static class GridPosition {
public final int row, col;
public GridPosition(int startIndex, int i) {
int totalRow = (startIndex + i) / cols;
row = rows - totalRow % rows - 1;
if (totalRow % 2 == 0) {
col = i % cols;
}
else {
col = cols - (i % cols) - 1;
}
} }
} }
} }