mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Added card stacking for "other" cards.
This commit is contained in:
@@ -57,6 +57,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
|
||||
private final int landStackMax = 5;
|
||||
private final int tokenStackMax = 5;
|
||||
private final int othersStackMax = 5;
|
||||
|
||||
private final boolean mirror;
|
||||
|
||||
@@ -132,7 +133,6 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
return allLands;
|
||||
}
|
||||
|
||||
|
||||
private final CardStackRow collectAllTokens() {
|
||||
final CardStackRow allTokens = new CardStackRow();
|
||||
outerLoop:
|
||||
@@ -258,14 +258,16 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
int x = 0;
|
||||
int y = PlayArea.GUTTER_Y;
|
||||
|
||||
//System.out.println("-------- " + (mirror ? "^" : "_") + " (Positioning ) Card width = " + cardWidth + ". Playarea = " + playAreaWidth + " x " + playAreaHeight );
|
||||
System.out.println("-------- " + (mirror ? "^" : "_") + " (Positioning ) Card width = " + cardWidth + ". Playarea = " + playAreaWidth + " x " + playAreaHeight );
|
||||
for (final CardStackRow row : template) {
|
||||
int rowBottom = 0;
|
||||
x = PlayArea.GUTTER_X;
|
||||
for (int stackIndex = 0, stackCount = row.size(); stackIndex < stackCount; stackIndex++) {
|
||||
final CardStack stack = row.get(stackIndex);
|
||||
// Align others to the right.
|
||||
if (RowType.Other.isGoodFor(stack.get(0).getCard())) {
|
||||
if (RowType.Other.isGoodFor(stack.get(0).getCard()) ||
|
||||
(stack.get(0).getCard().isEnchantment() && !stack.get(0).getCard().isCreature() && !stack.get(0).getCard().isEnchanted() && !stack.get(0).getCard().isCloned() &&
|
||||
(!stack.get(0).getCard().isEnchantingCard() && ((Card) (stack.get(0).getCard().getEnchanting())).getController() == stack.get(0).getCard().getController()))) {
|
||||
x = (this.playAreaWidth - PlayArea.GUTTER_X) + this.extraCardSpacingX;
|
||||
for (int i = stackIndex, n = row.size(); i < n; i++) {
|
||||
CardStack r = row.get(i);
|
||||
@@ -301,7 +303,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
|
||||
int afterFirstRow;
|
||||
|
||||
//System.out.println( "======== " + ( mirror ? "^" : "_" ) + " (try arrange) Card width = " + cardWidth + ". PlayArea = " + playAreaWidth + " x " + playAreaHeight + " ========");
|
||||
System.out.println( "======== " + ( mirror ? "^" : "_" ) + " (try arrange) Card width = " + cardWidth + ". PlayArea = " + playAreaWidth + " x " + playAreaHeight + " ========");
|
||||
boolean landsFit, tokensFit, creaturesFit;
|
||||
if (this.mirror) {
|
||||
// Wrap all creatures and lands.
|
||||
@@ -369,9 +371,9 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
for (final CardStack stack : sourceRow) {
|
||||
final int rowWidth = currentRow.getWidth();
|
||||
final int stackWidth = stack.getWidth();
|
||||
//System.out.printf("Adding %s (+%dpx), current row is %dpx and has %s \n", stack, stackWidth, rowWidth, currentRow );
|
||||
System.out.printf("Adding %s (+%dpx), current row is %dpx and has %s \n", stack, stackWidth, rowWidth, currentRow );
|
||||
// If the row is not empty and this stack doesn't fit, add the row.
|
||||
if (rowWidth + stackWidth > this.playAreaWidth && !currentRow.isEmpty() ) {
|
||||
if (rowWidth + stackWidth > this.playAreaWidth && !currentRow.isEmpty()) {
|
||||
|
||||
// Stop processing if the row is too wide or tall.
|
||||
if (rowWidth > this.playAreaWidth || this.getRowsHeight(template) + sourceRow.getHeight() > this.playAreaHeight) {
|
||||
@@ -421,7 +423,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
private int planOthersRow(final List<CardStack> sourceRow, final int firstPile, final List<CardStackRow> template, final CardStackRow rowToFill) {
|
||||
int rowWidth = rowToFill.getWidth();
|
||||
|
||||
// System.out.println("This row has:" + rowToFill + "; want to add:" + sourceRow );
|
||||
System.out.println("This row has:" + rowToFill + "; want to add:" + sourceRow );
|
||||
for (int i = firstPile; i < sourceRow.size(); i++ ) {
|
||||
CardStack stack = sourceRow.get(i);
|
||||
|
||||
@@ -662,8 +664,12 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
|
||||
public CardStackRow(final List<CardPanel> cardPanels, final RowType type) {
|
||||
this();
|
||||
if (type == RowType.Other) {
|
||||
this.addAllOthers(cardPanels, type);
|
||||
} else {
|
||||
this.addAll(cardPanels, type);
|
||||
}
|
||||
}
|
||||
|
||||
private void addAll(final List<CardPanel> cardPanels, final RowType type) {
|
||||
for (final CardPanel panel : cardPanels) {
|
||||
@@ -676,6 +682,39 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an alternate method to addAll() that sorts "other" cards into stacks
|
||||
* based on sickness, cloning, counters, and cards attached to them. All cards
|
||||
* that aren't equipped/enchanted/enchanting/equipping/etc that are otherwise
|
||||
* the same get stacked.
|
||||
*/
|
||||
private void addAllOthers(final List<CardPanel> cardPanels, final RowType type) {
|
||||
for (final CardPanel panel : cardPanels) {
|
||||
if (!type.isGoodFor(panel.getCard()) || (panel.getAttachedToPanel() != null)) {
|
||||
continue;
|
||||
}
|
||||
boolean stackable = false;
|
||||
for (CardStack s : this) {
|
||||
Card otherCard = s.get(0).getCard();
|
||||
Card thisCard = panel.getCard();
|
||||
if (otherCard.getName().equals(thisCard.getName()) && s.size() < othersStackMax) {
|
||||
if (panel.getAttachedPanels().isEmpty()
|
||||
&& thisCard.getCounters().equals(otherCard.getCounters())
|
||||
&& (thisCard.isSick() == otherCard.isSick())
|
||||
&& (thisCard.isCloned() == otherCard.isCloned())) {
|
||||
s.add(panel);
|
||||
stackable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!stackable) {
|
||||
final CardStack stack = new CardStack();
|
||||
stack.add(panel);
|
||||
this.add(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(final Collection<? extends CardStack> c) {
|
||||
final boolean changed = super.addAll(c);
|
||||
|
||||
Reference in New Issue
Block a user