diff --git a/forge-gui-desktop/src/main/java/forge/view/arcane/PlayArea.java b/forge-gui-desktop/src/main/java/forge/view/arcane/PlayArea.java index 1140d01211d..69a287c9792 100644 --- a/forge-gui-desktop/src/main/java/forge/view/arcane/PlayArea.java +++ b/forge-gui-desktop/src/main/java/forge/view/arcane/PlayArea.java @@ -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: @@ -202,7 +202,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen final CardStackRow tokens = collectAllTokens(); final CardStackRow creatures = new CardStackRow(this.getCardPanels(), RowType.CreatureNonToken); final CardStackRow others = new CardStackRow(this.getCardPanels(), RowType.Other); - + // should find an appropriate width of card int maxCardWidth = this.getCardWidthMax(); setCardWidth(maxCardWidth); @@ -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 sourceRow, final int firstPile, final List 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); @@ -652,7 +654,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen } } } - + private class CardStackRow extends ArrayList { private static final long serialVersionUID = 716489891951011846L; @@ -662,7 +664,11 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen public CardStackRow(final List cardPanels, final RowType type) { this(); - this.addAll(cardPanels, type); + if (type == RowType.Other) { + this.addAllOthers(cardPanels, type); + } else { + this.addAll(cardPanels, type); + } } private void addAll(final List cardPanels, final RowType type) { @@ -675,6 +681,39 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen this.add(stack); } } + + /** + * 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 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 c) {