mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Support laying out panels in region display
This commit is contained in:
@@ -165,22 +165,24 @@ public abstract class DeckGeneratorBase {
|
||||
for (Entry<String, Integer> c : clrCnts.entrySet()) {
|
||||
String basicLandName = c.getKey();
|
||||
|
||||
|
||||
// calculate number of lands for each color
|
||||
final int nLand = Math.min(landsLeft, Math.round(cnt * c.getValue() / totalColor));
|
||||
tmpDeck.append("nLand-").append(basicLandName).append(":").append(nLand).append("\n");
|
||||
|
||||
// just to prevent a null exception by the deck size fixing code
|
||||
this.cardCounts.put(basicLandName, nLand);
|
||||
cardCounts.put(basicLandName, nLand);
|
||||
|
||||
PaperCard cp;
|
||||
if(edition != null)
|
||||
if (edition != null) {
|
||||
cp = pool.getCard(basicLandName, edition);
|
||||
else
|
||||
}
|
||||
else {
|
||||
cp = pool.getCard(basicLandName);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ import forge.card.CardRenderer.CardStackPosition;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardView;
|
||||
import forge.model.FModel;
|
||||
import forge.planarconquest.ConquestAction;
|
||||
import forge.planarconquest.ConquestCommander;
|
||||
import forge.planarconquest.ConquestData;
|
||||
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 float COMMANDER_ROW_PADDING = Utils.scale(16);
|
||||
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 CommanderRow commanderRow = add(new CommanderRow());
|
||||
@@ -53,6 +54,7 @@ public class ConquestMapScreen extends FScreen {
|
||||
@Override
|
||||
public final void onActivate() {
|
||||
update();
|
||||
regionDisplay.revalidate();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
@@ -87,10 +89,14 @@ public class ConquestMapScreen extends FScreen {
|
||||
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 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
|
||||
@@ -109,7 +115,30 @@ public class ConquestMapScreen extends FScreen {
|
||||
}
|
||||
|
||||
@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; }
|
||||
Region region = model.getCurrentRegion();
|
||||
|
||||
@@ -117,8 +146,8 @@ public class ConquestMapScreen extends FScreen {
|
||||
float y = COMMANDER_GAP;
|
||||
float w = getWidth() - 2 * x;
|
||||
float h = getHeight() - y;
|
||||
float regionFrameThickness = 15f / 443f * w;
|
||||
float regionFrameBaseHeight = 25f / 317f * h;
|
||||
float regionFrameThickness = w * REGION_FRAME_THICKNESS_MULTIPLIER;
|
||||
float regionFrameBaseHeight = h * REGION_FRAME_BASE_HEIGHT_MULTIPLIER;
|
||||
|
||||
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
|
||||
@@ -154,6 +183,7 @@ public class ConquestMapScreen extends FScreen {
|
||||
x += dx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class CommanderPanel extends FDisplayObject {
|
||||
private final int index;
|
||||
@@ -164,6 +194,11 @@ public class ConquestMapScreen extends FScreen {
|
||||
index = index0;
|
||||
}
|
||||
|
||||
private void setCommander(ConquestCommander commander0) {
|
||||
commander = commander0;
|
||||
card = commander != null ? Card.getCardForUi(commander.getCard()).getView() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics g) {
|
||||
float w = getWidth();
|
||||
@@ -172,10 +207,14 @@ public class ConquestMapScreen extends FScreen {
|
||||
|
||||
ConquestPlaneData planeData = model.getCurrentPlaneData();
|
||||
if (commander == null) {
|
||||
if (index >= 0) {
|
||||
List<ConquestCommander> commanders = planeData.getCommanders();
|
||||
if (index < commanders.size()) {
|
||||
commander = commanders.get(index);
|
||||
card = Card.getCardForUi(commander.getCard()).getView();
|
||||
setCommander(commanders.get(index));
|
||||
}
|
||||
}
|
||||
else { //negative index means region opponent
|
||||
setCommander(planeData.getRegionData(model.getCurrentRegion()).getCommander(-index - 1));
|
||||
}
|
||||
}
|
||||
if (card != null) {
|
||||
@@ -191,7 +230,7 @@ public class ConquestMapScreen extends FScreen {
|
||||
g.drawImage(FSkin.getImages().get(commander.getCurrentDayAction().getIcon()), x, y, actionIconSize, actionIconSize);
|
||||
}
|
||||
}
|
||||
else {
|
||||
else if (index > 0) {
|
||||
CQPref unlockPref;
|
||||
switch (index) {
|
||||
case 1:
|
||||
@@ -219,5 +258,4 @@ public class ConquestMapScreen extends FScreen {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ public enum ConquestAction {
|
||||
AttackNE(FSkinProp.IMG_ATTACK),
|
||||
AttackE(FSkinProp.IMG_ATTACK),
|
||||
Defend(FSkinProp.IMG_DEFEND),
|
||||
Recruit(FSkinProp.IMG_ATTACK),
|
||||
Study(FSkinProp.ICO_QUEST_ZEP),
|
||||
Recruit(FSkinProp.IMG_PHASING),
|
||||
Study(FSkinProp.IMG_COSTRESERVED),
|
||||
Deploy(FSkinProp.IMG_SUMMONSICK),
|
||||
ReturnToBase(FSkinProp.ICO_QUEST_ZEP),
|
||||
Travel(FSkinProp.ICO_QUEST_ZEP);
|
||||
ReturnToBase(FSkinProp.IMG_SUMMONSICK),
|
||||
Travel(FSkinProp.IMG_SUMMONSICK);
|
||||
|
||||
private final FSkinProp icon;
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ public class ConquestCommander {
|
||||
|
||||
private ConquestAction currentDayAction;
|
||||
|
||||
public ConquestCommander(PaperCard card0, DeckGenPool cardPool0) {
|
||||
public ConquestCommander(PaperCard card0, DeckGenPool cardPool0, boolean forAi) {
|
||||
card = card0;
|
||||
deck = ConquestUtil.generateHumanDeck(card0, cardPool0);
|
||||
deck = ConquestUtil.generateDeck(card0, cardPool0, forAi);
|
||||
}
|
||||
|
||||
public PaperCard getCard() {
|
||||
|
||||
@@ -61,7 +61,7 @@ public final class ConquestData {
|
||||
}
|
||||
|
||||
private void addCommander(PaperCard card) {
|
||||
ConquestCommander commander = new ConquestCommander(card, currentPlane.getCardPool());
|
||||
ConquestCommander commander = new ConquestCommander(card, currentPlane.getCardPool(), false);
|
||||
getCurrentPlaneData().getCommanders().add(commander);
|
||||
decks.put(commander.getDeck().getName(), commander.getDeck());
|
||||
collection.addAll(commander.getDeck().getMain());
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
package forge.planarconquest;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import forge.GuiBase;
|
||||
@@ -30,6 +32,7 @@ import forge.card.MagicColor;
|
||||
import forge.deck.generation.DeckGenPool;
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.FCollection;
|
||||
import forge.util.FCollectionView;
|
||||
|
||||
@@ -279,6 +282,7 @@ public enum ConquestPlane {
|
||||
commanders.add(pc);
|
||||
}
|
||||
int count = 0;
|
||||
if (!type.isBasicLand()) { //add all basic lands to all regions below
|
||||
for (Region region : regions) {
|
||||
if (region.pred.apply(pc)) {
|
||||
region.cardPool.add(pc);
|
||||
@@ -288,6 +292,7 @@ public enum ConquestPlane {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
//if card doesn't match any region's predicate,
|
||||
//make card available to all regions
|
||||
if (count == 0) {
|
||||
@@ -384,6 +389,16 @@ public enum ConquestPlane {
|
||||
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() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package forge.planarconquest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import forge.planarconquest.ConquestPlane.Region;
|
||||
|
||||
public class ConquestPlaneData {
|
||||
private final List<ConquestCommander> commanders = new ArrayList<ConquestCommander>();
|
||||
private final Map<Region, RegionData> regionDataLookup = new HashMap<Region, RegionData>();
|
||||
|
||||
private int wins, losses;
|
||||
|
||||
@@ -27,4 +32,34 @@ public class ConquestPlaneData {
|
||||
public int getLosses() {
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,20 +16,13 @@ import forge.deck.generation.IDeckGenPool;
|
||||
import forge.item.PaperCard;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.quest.QuestUtil;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.gui.SOptionPane;
|
||||
|
||||
public class ConquestUtil {
|
||||
private ConquestUtil() {}
|
||||
|
||||
public static Deck generateHumanDeck(PaperCard commander, IDeckGenPool pool) {
|
||||
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) {
|
||||
public static Deck generateDeck(PaperCard commander, IDeckGenPool pool, boolean forAi) {
|
||||
ColorSet colorID = commander.getRules().getColorIdentity();
|
||||
|
||||
List<String> colors = new ArrayList<String>();
|
||||
|
||||
Reference in New Issue
Block a user