mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
Support rendering grid overlays based on event record
This commit is contained in:
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -18290,6 +18290,9 @@ forge-gui/src/main/java/forge/planarconquest/ConquestController.java -text
|
||||
forge-gui/src/main/java/forge/planarconquest/ConquestData.java -text
|
||||
forge-gui/src/main/java/forge/planarconquest/ConquestDataIO.java -text
|
||||
forge-gui/src/main/java/forge/planarconquest/ConquestDeckMap.java -text
|
||||
forge-gui/src/main/java/forge/planarconquest/ConquestEvent.java -text
|
||||
forge-gui/src/main/java/forge/planarconquest/ConquestEventRecord.java -text
|
||||
forge-gui/src/main/java/forge/planarconquest/ConquestLocation.java -text
|
||||
forge-gui/src/main/java/forge/planarconquest/ConquestOpponent.java -text
|
||||
forge-gui/src/main/java/forge/planarconquest/ConquestPlane.java -text
|
||||
forge-gui/src/main/java/forge/planarconquest/ConquestPlaneData.java -text
|
||||
|
||||
@@ -7,25 +7,22 @@ import com.badlogic.gdx.graphics.Color;
|
||||
import forge.Graphics;
|
||||
import forge.assets.FImage;
|
||||
import forge.assets.FSkinColor;
|
||||
import forge.assets.FSkinFont;
|
||||
import forge.card.CardDetailUtil;
|
||||
import forge.card.CardRenderer;
|
||||
import forge.card.CardDetailUtil.DetailColors;
|
||||
import forge.model.FModel;
|
||||
import forge.planarconquest.ConquestData;
|
||||
import forge.planarconquest.ConquestOpponent;
|
||||
import forge.planarconquest.ConquestPlane;
|
||||
import forge.planarconquest.ConquestEventRecord;
|
||||
import forge.planarconquest.ConquestLocation;
|
||||
import forge.planarconquest.ConquestPlane.Region;
|
||||
import forge.planarconquest.ConquestPlaneData;
|
||||
import forge.screens.FScreen;
|
||||
import forge.toolbox.FList;
|
||||
import forge.toolbox.FList.ListItemRenderer;
|
||||
import forge.toolbox.FScrollPane;
|
||||
import forge.util.collect.FCollectionView;
|
||||
|
||||
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 UNCONQUERED_COLOR = FSkinColor.alphaColor(Color.BLACK, 0.2f);
|
||||
|
||||
private final PlaneGrid planeGrid;
|
||||
private ConquestData model;
|
||||
@@ -80,8 +77,12 @@ public class ConquestMapScreen extends FScreen {
|
||||
float w = getWidth();
|
||||
float h = getHeight();
|
||||
float regionHeight = w / CardRenderer.CARD_ART_RATIO;
|
||||
float colWidth = w / GRID_COLS;
|
||||
float rowHeight = regionHeight / GRID_ROWS;
|
||||
int cols = Region.COLS_PER_REGION;
|
||||
int rows = Region.ROWS_PER_REGION;
|
||||
float colWidth = w / cols;
|
||||
float rowHeight = regionHeight / rows;
|
||||
ConquestPlaneData planeData = model.getCurrentPlaneData();
|
||||
ConquestLocation currentLocation = model.getCurrentLocation();
|
||||
|
||||
g.startClip(0, 0, w, h);
|
||||
|
||||
@@ -124,10 +125,36 @@ public class ConquestMapScreen extends FScreen {
|
||||
g.fillGradientRect(color1, color2, false, x, y, w, regionHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//draw event icon and overlay based on event record for each event in the region
|
||||
for (int r = 0; r < rows; r++) {
|
||||
for (int c = 0; c < cols; c++) {
|
||||
ConquestEventRecord record = planeData.getRecord(i, r, c);
|
||||
if (record == null || record.getWins() == 0) {
|
||||
//draw fog of war by default if area hasn't been conquered
|
||||
Color color = FOG_OF_WAR_COLOR;
|
||||
|
||||
//if any bordering grid square has been conquered, instead show unconquered color
|
||||
for (ConquestLocation loc : currentLocation.getNeighbors(i, r, c)) {
|
||||
if (loc.getRegion() == null) {
|
||||
color = UNCONQUERED_COLOR;
|
||||
break;
|
||||
}
|
||||
record = planeData.getRecord(loc.getRegionIndex(), loc.getRow(), loc.getCol());
|
||||
if (record != null && record.getWins() > 0) {
|
||||
color = UNCONQUERED_COLOR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g.fillRect(color, x + c * colWidth, y + r * rowHeight, colWidth, rowHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//draw row lines
|
||||
float y0 = y;
|
||||
for (int r = 0; r < GRID_ROWS; r++) {
|
||||
for (int r = 0; r < rows; r++) {
|
||||
g.drawLine(1, Color.BLACK, 0, y0, w, y0);
|
||||
y0 += rowHeight;
|
||||
}
|
||||
@@ -143,7 +170,7 @@ public class ConquestMapScreen extends FScreen {
|
||||
|
||||
//draw column lines
|
||||
float x0 = x + colWidth;
|
||||
for (int c = 1; c < GRID_COLS; c++) {
|
||||
for (int c = 1; c < cols; c++) {
|
||||
g.drawLine(1, Color.BLACK, x0, 0, x0, h);
|
||||
x0 += colWidth;
|
||||
}
|
||||
@@ -154,7 +181,7 @@ public class ConquestMapScreen extends FScreen {
|
||||
@Override
|
||||
protected ScrollBounds layoutAndGetScrollBounds(float visibleWidth, float visibleHeight) {
|
||||
float regionHeight = visibleWidth / CardRenderer.CARD_ART_RATIO;
|
||||
float rowHeight = regionHeight / GRID_ROWS;
|
||||
float rowHeight = regionHeight / Region.ROWS_PER_REGION;
|
||||
float height = model.getCurrentPlane().getRegions().size() * regionHeight;
|
||||
height += 2 * rowHeight; //account for portal row at top and bottom
|
||||
return new ScrollBounds(visibleWidth, height);
|
||||
|
||||
@@ -23,7 +23,6 @@ import forge.deck.Deck;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.planarconquest.ConquestPlane.Region;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.util.ItemPool;
|
||||
|
||||
@@ -51,10 +50,10 @@ public final class ConquestData {
|
||||
private int progress = 100;
|
||||
private int planewalkerPosition = 0;
|
||||
private int difficulty;
|
||||
private ConquestPlane startingPlane, currentPlane;
|
||||
private int currentRegionIndex;
|
||||
private ConquestPlane startingPlane;
|
||||
private PaperCard planeswalker;
|
||||
private ISkinImage planeswalkerToken;
|
||||
private final ConquestLocation currentLocation = new ConquestLocation();
|
||||
private final EnumMap<ConquestPlane, ConquestPlaneData> planeDataMap = new EnumMap<ConquestPlane, ConquestPlaneData>(ConquestPlane.class);
|
||||
|
||||
private final HashSet<PaperCard> collection = new HashSet<PaperCard>();
|
||||
@@ -69,7 +68,7 @@ public final class ConquestData {
|
||||
name = name0;
|
||||
difficulty = difficulty0;
|
||||
startingPlane = startingPlane0;
|
||||
currentPlane = startingPlane0;
|
||||
currentLocation.travelToPlane(startingPlane);
|
||||
planeswalker = planeswalker0;
|
||||
planeswalkerToken = PlaneswalkerAchievements.getTrophyImage(planeswalker.getName());
|
||||
collection.add(planeswalker);
|
||||
@@ -103,10 +102,15 @@ public final class ConquestData {
|
||||
}
|
||||
|
||||
public ConquestPlane getCurrentPlane() {
|
||||
return currentPlane;
|
||||
return currentLocation.getPlane();
|
||||
}
|
||||
|
||||
public ConquestLocation getCurrentLocation() {
|
||||
return currentLocation;
|
||||
}
|
||||
|
||||
public ConquestPlaneData getCurrentPlaneData() {
|
||||
ConquestPlane currentPlane = getCurrentPlane();
|
||||
ConquestPlaneData planeData = planeDataMap.get(currentPlane);
|
||||
if (planeData == null) {
|
||||
planeData = new ConquestPlaneData(currentPlane);
|
||||
@@ -115,32 +119,6 @@ public final class ConquestData {
|
||||
return planeData;
|
||||
}
|
||||
|
||||
public Region getCurrentRegion() {
|
||||
return currentPlane.getRegions().get(currentRegionIndex);
|
||||
}
|
||||
public boolean setCurrentRegion(Region region) {
|
||||
int index = currentPlane.getRegions().indexOf(region);
|
||||
if (index != -1 && currentRegionIndex != index) {
|
||||
currentRegionIndex = index;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void incrementRegion(int dir) {
|
||||
if (dir > 0) {
|
||||
currentRegionIndex++;
|
||||
if (currentRegionIndex >= currentPlane.getRegions().size()) {
|
||||
currentRegionIndex = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
currentRegionIndex--;
|
||||
if (currentRegionIndex < 0) {
|
||||
currentRegionIndex = currentPlane.getRegions().size() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HashSet<PaperCard> getCollection() {
|
||||
return collection;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package forge.planarconquest;
|
||||
|
||||
public class ConquestEvent {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package forge.planarconquest;
|
||||
|
||||
public class ConquestEventRecord {
|
||||
private int wins, losses;
|
||||
private int winStreakBest = 0;
|
||||
private int winStreakCurrent = 0;
|
||||
|
||||
public void addWin() {
|
||||
wins++;
|
||||
winStreakCurrent++;
|
||||
if (winStreakCurrent > winStreakBest) {
|
||||
winStreakBest = winStreakCurrent;
|
||||
}
|
||||
}
|
||||
|
||||
public void addLoss(ConquestCommander opponent) {
|
||||
losses++;
|
||||
winStreakCurrent = 0;
|
||||
}
|
||||
|
||||
public int getWins() {
|
||||
return wins;
|
||||
}
|
||||
|
||||
public int getLosses() {
|
||||
return losses;
|
||||
}
|
||||
|
||||
public int getWinStreakBest() {
|
||||
return winStreakBest;
|
||||
}
|
||||
|
||||
public int getWinStreakCurrent() {
|
||||
return winStreakCurrent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package forge.planarconquest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forge.planarconquest.ConquestPlane.Region;
|
||||
|
||||
public class ConquestLocation {
|
||||
private ConquestPlane plane;
|
||||
private int regionIndex;
|
||||
private int row;
|
||||
private int col;
|
||||
|
||||
public ConquestLocation() {
|
||||
}
|
||||
|
||||
public ConquestPlane getPlane() {
|
||||
return plane;
|
||||
}
|
||||
|
||||
public Region getRegion() {
|
||||
if (regionIndex == -1 || regionIndex == plane.getRegions().size()) {
|
||||
return null; //indicates we're on portal row
|
||||
}
|
||||
return plane.getRegions().get(regionIndex);
|
||||
}
|
||||
|
||||
public int getRegionIndex() {
|
||||
return regionIndex;
|
||||
}
|
||||
|
||||
public int getRow() {
|
||||
return row;
|
||||
}
|
||||
|
||||
public int getCol() {
|
||||
return col;
|
||||
}
|
||||
|
||||
public void travelToPlane(ConquestPlane plane0) {
|
||||
if (plane == plane0) { return; }
|
||||
if (plane == null /*|| plane0 follows plane in travel order */) {
|
||||
regionIndex = -1; //start on bottom portal row
|
||||
}
|
||||
else {
|
||||
regionIndex = plane.getRegions().size(); //start on top portal row
|
||||
}
|
||||
plane = plane0;
|
||||
}
|
||||
|
||||
public List<ConquestLocation> getNeighbors() {
|
||||
return getNeighbors(regionIndex, row, col);
|
||||
}
|
||||
public List<ConquestLocation> getNeighbors(int regionIndex0, int row0, int col0) {
|
||||
List<ConquestLocation> locations = new ArrayList<ConquestLocation>();
|
||||
if (row0 > 0) {
|
||||
|
||||
}
|
||||
else if (regionIndex0 > 0) {
|
||||
|
||||
}
|
||||
return locations;
|
||||
}
|
||||
}
|
||||
@@ -272,7 +272,8 @@ public enum ConquestPlane {
|
||||
}
|
||||
|
||||
public static class Region {
|
||||
public static final int OPPONENTS_PER_REGION = 15;
|
||||
public static final int ROWS_PER_REGION = 3;
|
||||
public static final int COLS_PER_REGION = 3;
|
||||
|
||||
private final String name;
|
||||
private final String artCardName;
|
||||
@@ -327,7 +328,7 @@ public enum ConquestPlane {
|
||||
|
||||
//each region should have 15 opponents include one boss
|
||||
private void generateOpponents() {
|
||||
int opponentsBeforeBoss = OPPONENTS_PER_REGION; //TODO: Reduce by 1 when boss added below
|
||||
int opponentsBeforeBoss = ROWS_PER_REGION * COLS_PER_REGION; //TODO: Reduce by 1 when boss added below
|
||||
HashSet<PaperCard> cards = new HashSet<PaperCard>(commanders);
|
||||
if (cards.size() < opponentsBeforeBoss) {
|
||||
//if not enough commanders, add normal creatures as non-commander opponents
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
package forge.planarconquest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.planarconquest.ConquestPlane.Region;
|
||||
|
||||
public class ConquestPlaneData {
|
||||
private final List<ConquestCommander> commanders = new ArrayList<ConquestCommander>();
|
||||
private final Map<String, Integer> winsPerOpponent = new HashMap<String, Integer>();
|
||||
private final Map<String, Integer> lossesPerOpponent = new HashMap<String, Integer>();
|
||||
private final ConquestPlane plane;
|
||||
private final ConquestEventRecord[][][] records;
|
||||
|
||||
private int wins, losses;
|
||||
private int winStreakBest = 0;
|
||||
@@ -21,29 +15,11 @@ public class ConquestPlaneData {
|
||||
|
||||
public ConquestPlaneData(ConquestPlane plane0) {
|
||||
plane = plane0;
|
||||
records = new ConquestEventRecord[plane.getRegions().size()][Region.ROWS_PER_REGION][Region.COLS_PER_REGION];
|
||||
}
|
||||
|
||||
public List<ConquestCommander> getCommanders() {
|
||||
return commanders;
|
||||
}
|
||||
|
||||
public boolean hasCommander(PaperCard pc) {
|
||||
for (ConquestCommander c : commanders) {
|
||||
if (c.getCard() == pc) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getWinsAgainst(PaperCard pc) {
|
||||
Integer wins = winsPerOpponent.get(pc.getName());
|
||||
return wins == null ? 0 : wins.intValue();
|
||||
}
|
||||
|
||||
public int getLossesAgainst(PaperCard pc) {
|
||||
Integer losses = lossesPerOpponent.get(pc.getName());
|
||||
return losses == null ? 0 : losses.intValue();
|
||||
public ConquestEventRecord getRecord(int regionIndex, int row, int col) {
|
||||
return records[regionIndex][row][col];
|
||||
}
|
||||
|
||||
public void addWin(ConquestCommander opponent) {
|
||||
@@ -52,13 +28,11 @@ public class ConquestPlaneData {
|
||||
if (winStreakCurrent > winStreakBest) {
|
||||
winStreakBest = winStreakCurrent;
|
||||
}
|
||||
winsPerOpponent.put(opponent.getName(), getWinsAgainst(opponent.getCard()) + 1);
|
||||
}
|
||||
|
||||
public void addLoss(ConquestCommander opponent) {
|
||||
losses++;
|
||||
winStreakCurrent = 0;
|
||||
lossesPerOpponent.put(opponent.getName(), getLossesAgainst(opponent.getCard()) + 1);
|
||||
}
|
||||
|
||||
public int getWins() {
|
||||
|
||||
Reference in New Issue
Block a user