Support laying out panels in region display

This commit is contained in:
drdev
2014-12-06 04:14:18 +00:00
parent ec6637bab7
commit dccf428bb8
8 changed files with 166 additions and 83 deletions

View File

@@ -165,22 +165,24 @@ public abstract class DeckGeneratorBase {
for (Entry<String, Integer> c : clrCnts.entrySet()) { for (Entry<String, Integer> c : clrCnts.entrySet()) {
String basicLandName = c.getKey(); String basicLandName = c.getKey();
// calculate number of lands for each color // calculate number of lands for each color
final int nLand = Math.min(landsLeft, Math.round(cnt * c.getValue() / totalColor)); final int nLand = Math.min(landsLeft, Math.round(cnt * c.getValue() / totalColor));
tmpDeck.append("nLand-").append(basicLandName).append(":").append(nLand).append("\n"); tmpDeck.append("nLand-").append(basicLandName).append(":").append(nLand).append("\n");
// just to prevent a null exception by the deck size fixing code // just to prevent a null exception by the deck size fixing code
this.cardCounts.put(basicLandName, nLand); cardCounts.put(basicLandName, nLand);
PaperCard cp; PaperCard cp;
if(edition != null) if (edition != null) {
cp = pool.getCard(basicLandName, edition); cp = pool.getCard(basicLandName, edition);
else }
else {
cp = pool.getCard(basicLandName); cp = pool.getCard(basicLandName);
}
String basicLandSet = cp.getEdition(); String basicLandSet = cp.getEdition();
for (int i=0; i < nLand; i++) { for (int i = 0; i < nLand; i++) {
tDeck.add(pool.getCard(cp.getName(), basicLandSet, -1), 1); tDeck.add(pool.getCard(cp.getName(), basicLandSet, -1), 1);
} }

View File

@@ -18,7 +18,6 @@ import forge.card.CardRenderer.CardStackPosition;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.card.CardView; import forge.game.card.CardView;
import forge.model.FModel; import forge.model.FModel;
import forge.planarconquest.ConquestAction;
import forge.planarconquest.ConquestCommander; import forge.planarconquest.ConquestCommander;
import forge.planarconquest.ConquestData; import forge.planarconquest.ConquestData;
import forge.planarconquest.ConquestPlane.Region; import forge.planarconquest.ConquestPlane.Region;
@@ -38,6 +37,8 @@ public class ConquestMapScreen extends FScreen {
private static final FSkinFont UNLOCK_WINS_FONT = FSkinFont.get(18); private static final FSkinFont UNLOCK_WINS_FONT = FSkinFont.get(18);
private static final float COMMANDER_ROW_PADDING = Utils.scale(16); private static final float COMMANDER_ROW_PADDING = Utils.scale(16);
private static final float COMMANDER_GAP = Utils.scale(12); private static final float COMMANDER_GAP = Utils.scale(12);
private static final float REGION_FRAME_THICKNESS_MULTIPLIER = 15f / 443f;
private static final float REGION_FRAME_BASE_HEIGHT_MULTIPLIER = 25f / 317f;
private final RegionDisplay regionDisplay = add(new RegionDisplay()); private final RegionDisplay regionDisplay = add(new RegionDisplay());
private final CommanderRow commanderRow = add(new CommanderRow()); private final CommanderRow commanderRow = add(new CommanderRow());
@@ -53,6 +54,7 @@ public class ConquestMapScreen extends FScreen {
@Override @Override
public final void onActivate() { public final void onActivate() {
update(); update();
regionDisplay.revalidate();
} }
public void update() { public void update() {
@@ -87,10 +89,14 @@ public class ConquestMapScreen extends FScreen {
regionDisplay.setBounds(0, startY, width, commanderRow.getTop() - startY); regionDisplay.setBounds(0, startY, width, commanderRow.getTop() - startY);
} }
private class RegionDisplay extends FDisplayObject { private class RegionDisplay extends FContainer {
private final TextRenderer textRenderer = new TextRenderer(); private final TextRenderer textRenderer = new TextRenderer();
private final CommanderPanel opponent1 = add(new CommanderPanel(-1)); //use negative indices to represent opponents
private final CommanderPanel opponent2 = add(new CommanderPanel(-2));
private final CommanderPanel opponent3 = add(new CommanderPanel(-3));
private final CommanderPanel deployedCommander = add(new CommanderPanel(-4));
public RegionDisplay() { private RegionDisplay() {
} }
@Override @Override
@@ -109,7 +115,30 @@ public class ConquestMapScreen extends FScreen {
} }
@Override @Override
public void draw(Graphics g) { protected void doLayout(float width, float height) {
float x = COMMANDER_GAP / 2;
float y = COMMANDER_GAP;
float w = width - 2 * x;
float h = height - y;
float regionFrameThickness = w * REGION_FRAME_THICKNESS_MULTIPLIER;
float regionFrameBaseHeight = h * REGION_FRAME_BASE_HEIGHT_MULTIPLIER;
x += regionFrameThickness;
y += regionFrameThickness;
w -= 2 * regionFrameThickness;
h -= regionFrameThickness + regionFrameBaseHeight;
float padding = COMMANDER_GAP;
float panelHeight = (h - 5 * padding) / 2;
float panelWidth = panelHeight / FCardPanel.ASPECT_RATIO;
opponent1.setBounds(x + padding, y + padding, panelWidth, panelHeight);
opponent2.setBounds(x + (w - panelWidth) / 2, y + padding, panelWidth, panelHeight);
opponent3.setBounds(x + w - padding - panelWidth, y + padding, panelWidth, panelHeight);
deployedCommander.setBounds(x + (w - panelWidth) / 2, y + h - padding - panelHeight, panelWidth, panelHeight);
}
@Override
public void drawBackground(Graphics g) {
if (model == null) { return; } if (model == null) { return; }
Region region = model.getCurrentRegion(); Region region = model.getCurrentRegion();
@@ -117,8 +146,8 @@ public class ConquestMapScreen extends FScreen {
float y = COMMANDER_GAP; float y = COMMANDER_GAP;
float w = getWidth() - 2 * x; float w = getWidth() - 2 * x;
float h = getHeight() - y; float h = getHeight() - y;
float regionFrameThickness = 15f / 443f * w; float regionFrameThickness = w * REGION_FRAME_THICKNESS_MULTIPLIER;
float regionFrameBaseHeight = 25f / 317f * h; float regionFrameBaseHeight = h * REGION_FRAME_BASE_HEIGHT_MULTIPLIER;
g.startClip(x + regionFrameThickness, y + regionFrameThickness, w - 2 * regionFrameThickness, h - regionFrameThickness - regionFrameBaseHeight); g.startClip(x + regionFrameThickness, y + regionFrameThickness, w - 2 * regionFrameThickness, h - regionFrameThickness - regionFrameBaseHeight);
g.drawImage((FImage)region.getArt(), x, y, w, h); //TODO: Maximize in frame while retaining proportions g.drawImage((FImage)region.getArt(), x, y, w, h); //TODO: Maximize in frame while retaining proportions
@@ -154,68 +183,77 @@ public class ConquestMapScreen extends FScreen {
x += dx; x += dx;
} }
} }
}
private class CommanderPanel extends FDisplayObject { private class CommanderPanel extends FDisplayObject {
private final int index; private final int index;
private CardView card; private CardView card;
private ConquestCommander commander; private ConquestCommander commander;
private CommanderPanel(int index0) { private CommanderPanel(int index0) {
index = index0; index = index0;
} }
@Override private void setCommander(ConquestCommander commander0) {
public void draw(Graphics g) { commander = commander0;
float w = getWidth(); card = commander != null ? Card.getCardForUi(commander.getCard()).getView() : null;
float h = getHeight(); }
g.drawRect(BORDER_THICKNESS, Color.WHITE, -BORDER_THICKNESS, -BORDER_THICKNESS, w + 2 * BORDER_THICKNESS, h + 2 * BORDER_THICKNESS);
ConquestPlaneData planeData = model.getCurrentPlaneData(); @Override
if (commander == null) { public void draw(Graphics g) {
float w = getWidth();
float h = getHeight();
g.drawRect(BORDER_THICKNESS, Color.WHITE, -BORDER_THICKNESS, -BORDER_THICKNESS, w + 2 * BORDER_THICKNESS, h + 2 * BORDER_THICKNESS);
ConquestPlaneData planeData = model.getCurrentPlaneData();
if (commander == null) {
if (index >= 0) {
List<ConquestCommander> commanders = planeData.getCommanders(); List<ConquestCommander> commanders = planeData.getCommanders();
if (index < commanders.size()) { if (index < commanders.size()) {
commander = commanders.get(index); setCommander(commanders.get(index));
card = Card.getCardForUi(commander.getCard()).getView();
} }
} }
if (card != null) { else { //negative index means region opponent
CardRenderer.drawCardWithOverlays(g, card, 0, 0, w, h, CardStackPosition.Top); setCommander(planeData.getRegionData(model.getCurrentRegion()).getCommander(-index - 1));
}
}
if (card != null) {
CardRenderer.drawCardWithOverlays(g, card, 0, 0, w, h, CardStackPosition.Top);
if (commander.getCurrentDayAction() != null) { if (commander.getCurrentDayAction() != null) {
float padding = w * CardRenderer.PADDING_MULTIPLIER; //adjust for card border float padding = w * CardRenderer.PADDING_MULTIPLIER; //adjust for card border
w -= 2 * padding; w -= 2 * padding;
h -= 2 * padding; h -= 2 * padding;
float actionIconSize = w / 2; float actionIconSize = w / 2;
float x = (padding + (w / 4)) - actionIconSize / 2; float x = (padding + (w / 4)) - actionIconSize / 2;
float y = (padding + h) - (h / 8) - actionIconSize / 2; float y = (padding + h) - (h / 8) - actionIconSize / 2;
g.drawImage(FSkin.getImages().get(commander.getCurrentDayAction().getIcon()), x, y, actionIconSize, actionIconSize); g.drawImage(FSkin.getImages().get(commander.getCurrentDayAction().getIcon()), x, y, actionIconSize, actionIconSize);
} }
}
else if (index > 0) {
CQPref unlockPref;
switch (index) {
case 1:
unlockPref = CQPref.WINS_TO_UNLOCK_COMMANDER_2;
break;
case 2:
unlockPref = CQPref.WINS_TO_UNLOCK_COMMANDER_3;
break;
default:
unlockPref = CQPref.WINS_TO_UNLOCK_COMMANDER_4;
break;
}
int winsToUnlock = FModel.getConquestPreferences().getPrefInt(unlockPref);
if (planeData.getWins() < winsToUnlock) {
g.setAlphaComposite(0.25f);
float imageSize = w * 0.75f;
g.drawImage(FSkinImage.LOCK, (w - imageSize) / 2, (h - imageSize) / 2, imageSize, imageSize);
g.resetAlphaComposite();
float y = (h + imageSize) / 2;
g.drawText(String.valueOf(winsToUnlock), UNLOCK_WINS_FONT, Color.WHITE, 0, y, w, h - y, false, HAlignment.CENTER, true);
} }
else { else {
CQPref unlockPref;
switch (index) {
case 1:
unlockPref = CQPref.WINS_TO_UNLOCK_COMMANDER_2;
break;
case 2:
unlockPref = CQPref.WINS_TO_UNLOCK_COMMANDER_3;
break;
default:
unlockPref = CQPref.WINS_TO_UNLOCK_COMMANDER_4;
break;
}
int winsToUnlock = FModel.getConquestPreferences().getPrefInt(unlockPref);
if (planeData.getWins() < winsToUnlock) {
g.setAlphaComposite(0.25f);
float imageSize = w * 0.75f;
g.drawImage(FSkinImage.LOCK, (w - imageSize) / 2, (h - imageSize) / 2, imageSize, imageSize);
g.resetAlphaComposite();
float y = (h + imageSize) / 2;
g.drawText(String.valueOf(winsToUnlock), UNLOCK_WINS_FONT, Color.WHITE, 0, y, w, h - y, false, HAlignment.CENTER, true);
}
else {
}
} }
} }
} }

View File

@@ -7,11 +7,11 @@ public enum ConquestAction {
AttackNE(FSkinProp.IMG_ATTACK), AttackNE(FSkinProp.IMG_ATTACK),
AttackE(FSkinProp.IMG_ATTACK), AttackE(FSkinProp.IMG_ATTACK),
Defend(FSkinProp.IMG_DEFEND), Defend(FSkinProp.IMG_DEFEND),
Recruit(FSkinProp.IMG_ATTACK), Recruit(FSkinProp.IMG_PHASING),
Study(FSkinProp.ICO_QUEST_ZEP), Study(FSkinProp.IMG_COSTRESERVED),
Deploy(FSkinProp.IMG_SUMMONSICK), Deploy(FSkinProp.IMG_SUMMONSICK),
ReturnToBase(FSkinProp.ICO_QUEST_ZEP), ReturnToBase(FSkinProp.IMG_SUMMONSICK),
Travel(FSkinProp.ICO_QUEST_ZEP); Travel(FSkinProp.IMG_SUMMONSICK);
private final FSkinProp icon; private final FSkinProp icon;

View File

@@ -10,9 +10,9 @@ public class ConquestCommander {
private ConquestAction currentDayAction; private ConquestAction currentDayAction;
public ConquestCommander(PaperCard card0, DeckGenPool cardPool0) { public ConquestCommander(PaperCard card0, DeckGenPool cardPool0, boolean forAi) {
card = card0; card = card0;
deck = ConquestUtil.generateHumanDeck(card0, cardPool0); deck = ConquestUtil.generateDeck(card0, cardPool0, forAi);
} }
public PaperCard getCard() { public PaperCard getCard() {

View File

@@ -61,7 +61,7 @@ public final class ConquestData {
} }
private void addCommander(PaperCard card) { private void addCommander(PaperCard card) {
ConquestCommander commander = new ConquestCommander(card, currentPlane.getCardPool()); ConquestCommander commander = new ConquestCommander(card, currentPlane.getCardPool(), false);
getCurrentPlaneData().getCommanders().add(commander); getCurrentPlaneData().getCommanders().add(commander);
decks.put(commander.getDeck().getName(), commander.getDeck()); decks.put(commander.getDeck().getName(), commander.getDeck());
collection.addAll(commander.getDeck().getMain()); collection.addAll(commander.getDeck().getMain());

View File

@@ -17,6 +17,8 @@
*/ */
package forge.planarconquest; package forge.planarconquest;
import java.util.HashSet;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import forge.GuiBase; import forge.GuiBase;
@@ -30,6 +32,7 @@ import forge.card.MagicColor;
import forge.deck.generation.DeckGenPool; import forge.deck.generation.DeckGenPool;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.model.FModel; import forge.model.FModel;
import forge.util.Aggregates;
import forge.util.FCollection; import forge.util.FCollection;
import forge.util.FCollectionView; import forge.util.FCollectionView;
@@ -279,13 +282,15 @@ public enum ConquestPlane {
commanders.add(pc); commanders.add(pc);
} }
int count = 0; int count = 0;
for (Region region : regions) { if (!type.isBasicLand()) { //add all basic lands to all regions below
if (region.pred.apply(pc)) { for (Region region : regions) {
region.cardPool.add(pc); if (region.pred.apply(pc)) {
if (isCommander) { region.cardPool.add(pc);
region.commanders.add(pc); if (isCommander) {
region.commanders.add(pc);
}
count++;
} }
count++;
} }
} }
//if card doesn't match any region's predicate, //if card doesn't match any region's predicate,
@@ -384,6 +389,16 @@ public enum ConquestPlane {
return commanders; return commanders;
} }
public ConquestCommander getRandomOpponent(ConquestCommander[] used) {
HashSet<PaperCard> cards = new HashSet<PaperCard>(commanders);
for (int i = 0; i < used.length; i++) {
if (used[i] != null) {
cards.remove(used[i]);
}
}
return new ConquestCommander(Aggregates.random(cards), cardPool, true);
}
public String toString() { public String toString() {
return name; return name;
} }

View File

@@ -1,10 +1,15 @@
package forge.planarconquest; package forge.planarconquest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import forge.planarconquest.ConquestPlane.Region;
public class ConquestPlaneData { public class ConquestPlaneData {
private final List<ConquestCommander> commanders = new ArrayList<ConquestCommander>(); private final List<ConquestCommander> commanders = new ArrayList<ConquestCommander>();
private final Map<Region, RegionData> regionDataLookup = new HashMap<Region, RegionData>();
private int wins, losses; private int wins, losses;
@@ -27,4 +32,34 @@ public class ConquestPlaneData {
public int getLosses() { public int getLosses() {
return losses; return losses;
} }
public RegionData getRegionData(Region region) {
RegionData regionData = regionDataLookup.get(region);
if (regionData == null) {
regionData = new RegionData(region);
regionDataLookup.put(region, regionData);
}
return regionData;
}
public class RegionData {
private final Region region;
private final ConquestCommander[] commanders = new ConquestCommander[4];
private RegionData(Region region0) {
region = region0;
commanders[0] = region.getRandomOpponent(commanders);
commanders[1] = region.getRandomOpponent(commanders);
commanders[2] = region.getRandomOpponent(commanders);
//leave commanders[3] open for deployed commander
}
public Region getRegion() {
return region;
}
public ConquestCommander getCommander(int index) {
return commanders[index];
}
}
} }

View File

@@ -16,20 +16,13 @@ import forge.deck.generation.IDeckGenPool;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.properties.ForgeConstants; import forge.properties.ForgeConstants;
import forge.quest.QuestUtil; import forge.quest.QuestUtil;
import forge.util.Aggregates;
import forge.util.FileUtil; import forge.util.FileUtil;
import forge.util.gui.SOptionPane; import forge.util.gui.SOptionPane;
public class ConquestUtil { public class ConquestUtil {
private ConquestUtil() {} private ConquestUtil() {}
public static Deck generateHumanDeck(PaperCard commander, IDeckGenPool pool) { public static Deck generateDeck(PaperCard commander, IDeckGenPool pool, boolean forAi) {
return generateDeck(commander, pool, false);
}
public static Deck generateAiDeck(Iterable<PaperCard> commanderOptions, IDeckGenPool pool) {
return generateDeck(Aggregates.random(commanderOptions), pool, true);
}
private static Deck generateDeck(PaperCard commander, IDeckGenPool pool, boolean forAi) {
ColorSet colorID = commander.getRules().getColorIdentity(); ColorSet colorID = commander.getRules().getColorIdentity();
List<String> colors = new ArrayList<String>(); List<String> colors = new ArrayList<String>();