From 6029cbfd8d522654d1c9d43f7fdd9da6e2fecd21 Mon Sep 17 00:00:00 2001 From: spjspj Date: Sun, 16 Oct 2016 22:03:20 +1100 Subject: [PATCH 1/4] spjspj - Do a count for supertypes and subtypes of all implemented cards. --- .../java/mage/client/cards/DragCardGrid.java | 4 +- Utils/gen_types_list.pl | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 Utils/gen_types_list.pl diff --git a/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java b/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java index 9c82a0915d4..58c30543a97 100644 --- a/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java +++ b/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java @@ -744,8 +744,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg sortButton = new JButton("Sort"); filterButton = new JButton("Filter"); visibilityButton = new JButton("Visibility"); - selectByButton = new JButton("Select By .."); - analyseButton = new JButton("Analyse Mana"); + selectByButton = new JButton("Select By"); + analyseButton = new JButton("Mana"); // Name and count label deckNameAndCountLabel = new JLabel(); diff --git a/Utils/gen_types_list.pl b/Utils/gen_types_list.pl new file mode 100644 index 00000000000..d80bb5dc899 --- /dev/null +++ b/Utils/gen_types_list.pl @@ -0,0 +1,57 @@ +#!/usr/bin/perl -w + +## +# File: gen_types_list.pl +# Author: spjspj +# Purpose: To open all card java files and work out if any have duplicate cardNumber / expansionSetCode +## + +use strict; +use Scalar::Util qw(looks_like_number); + +my $dir_listing = "dir \/a \/b \/s ..\\Mage.Sets\\ | find \".java\" |"; + +open (DIR_LISTING, "$dir_listing"); +my %types; +my %types_files; + +while () +{ + chomp; + my $file = $_; + + my $name = ""; + my $cardNum = ""; + + open (JAVA_FILE, "$file"); + + while () + { + chomp; + + # Eg: this.subtype.add("Human"); + my $line = $_; + if ($line =~ m/this.subtype.add.*"([^"]*)".;/) + { + $types{$1}++; + $types_files{$1} .= $file . ",,,"; + } + if ($line =~ m/this.supertype.add.*"([^"]*)"/) + { + $types{$1}++; + $types_files{$1} .= $file . ",,,"; + } + } + + close (JAVA_FILE); +} +my $key; +foreach $key (sort keys (%types)) +{ + print ("$types{$key} = $key .... "); + if ($types{$key} < 10) + { + print (" In files:$types_files{$key}"); + } + print ("\n"); +} From 6f6c04a4a20c1381e86a80f2bdb1779bdf8f34ff Mon Sep 17 00:00:00 2001 From: spjspj Date: Sun, 16 Oct 2016 22:04:43 +1100 Subject: [PATCH 2/4] spjspj - Do a count for supertypes and subtypes of all implemented cards. --- Utils/gen_types_list.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Utils/gen_types_list.pl b/Utils/gen_types_list.pl index d80bb5dc899..d94beeca697 100644 --- a/Utils/gen_types_list.pl +++ b/Utils/gen_types_list.pl @@ -3,7 +3,8 @@ ## # File: gen_types_list.pl # Author: spjspj -# Purpose: To open all card java files and work out if any have duplicate cardNumber / expansionSetCode +# Purpose: To open all card java files and count all subtypes/supertypes +# Purpose: Ones with unique splleings (sic.) are possibly incorrect! ## use strict; From 1114eeb13358c4d99036a549ef841403fa29e9b6 Mon Sep 17 00:00:00 2001 From: spjspj Date: Sun, 16 Oct 2016 22:05:13 +1100 Subject: [PATCH 3/4] spjspj - Do a count for supertypes and subtypes of all implemented cards. --- Utils/gen_types_list.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Utils/gen_types_list.pl b/Utils/gen_types_list.pl index d94beeca697..c85d86a94c8 100644 --- a/Utils/gen_types_list.pl +++ b/Utils/gen_types_list.pl @@ -4,7 +4,7 @@ # File: gen_types_list.pl # Author: spjspj # Purpose: To open all card java files and count all subtypes/supertypes -# Purpose: Ones with unique splleings (sic.) are possibly incorrect! +# Purpose: Ones with unique spellings are possibly incorrect! ## use strict; From 56cb226634aa8a109184e519cd94c97fb42b97b8 Mon Sep 17 00:00:00 2001 From: spjspj Date: Tue, 18 Oct 2016 01:34:30 +1100 Subject: [PATCH 4/4] spjspj - Add in a 'Duplicate' (of selection) right click menu option for FREE_BUILDING mode --- .../java/mage/client/cards/DragCardGrid.java | 42 ++++++++++- .../java/mage/client/deckeditor/DeckArea.java | 23 +++++- Mage.Common/src/mage/view/CardView.java | 73 +++++++++++++++++++ 3 files changed, 131 insertions(+), 7 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java b/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java index 58c30543a97..ee968304b7f 100644 --- a/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java +++ b/Mage.Client/src/main/java/mage/client/cards/DragCardGrid.java @@ -53,6 +53,7 @@ import mage.cards.MageCard; import mage.cards.decks.DeckCardInfo; import mage.cards.decks.DeckCardLayout; import mage.client.MageFrame; +import mage.client.constants.Constants; import mage.client.dialog.PreferencesDialog; import mage.client.plugins.impl.Plugins; import mage.client.util.CardViewCardTypeComparator; @@ -76,6 +77,7 @@ import org.mage.card.arcane.CardRenderer; public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarget { private final static Logger LOGGER = Logger.getLogger(DragCardGrid.class); + private Constants.DeckEditorMode mode; @Override public Collection dragCardList() { @@ -363,7 +365,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg // Add new cards to grid for (CardView card : cards) { card.setSelected(true); - addCardView(card); + addCardView(card, false); eventSource.addSpecificCard(card, "add-specific-card"); } layoutGrid(); @@ -448,6 +450,10 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg return new DeckCardLayout(info, saveSettings().toString()); } + public void setDeckEditorMode(Constants.DeckEditorMode mode) { + this.mode = mode; + } + public enum Sort { NONE("No Sort", new Comparator() { @Override @@ -570,6 +576,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg void cardsSelected(); void hideCards(Collection card); + + void duplicateCards(Collection cards); void showAll(); }; @@ -740,6 +748,9 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg setLayout(new BorderLayout()); setOpaque(false); + // Editting mode + this.mode = Constants.DeckEditorMode.LIMITED_BUILDING; + // Toolbar sortButton = new JButton("Sort"); filterButton = new JButton("Filter"); @@ -1077,6 +1088,12 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg } } + private void duplicateSelection() { + Collection toDuplicate = dragCardList(); + for (DragCardGridListener l : listeners) { + l.duplicateCards(toDuplicate); + } + } private void showAll() { for (DragCardGridListener l : listeners) { l.showAll(); @@ -1448,7 +1465,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg for (CardView newCard : cardsView.values()) { if (!cardViews.containsKey(newCard.getId())) { // Is a new card - addCardView(newCard); + addCardView(newCard, false); // Put it into the appropirate place in the grid given the current sort sortIntoGrid(newCard); @@ -1471,7 +1488,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg for (CardView newCard : cardsView.values()) { if (!cardViews.containsKey(newCard.getId())) { // Add the new card - addCardView(newCard); + addCardView(newCard, false); // Add the new card to tracking Map> forSetCode; @@ -1589,10 +1606,17 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg JMenuItem hide = new JMenuItem("Hide"); hide.addActionListener(e2 -> hideSelection()); menu.add(hide); + + // Show 'Duplicate Selection' for FREE_BUILDING + if (this.mode == Constants.DeckEditorMode.FREE_BUILDING) { + JMenuItem duplicateSelection = new JMenuItem("Duplicate Selection"); + duplicateSelection.addActionListener(e2 -> duplicateSelection()); + menu.add(duplicateSelection); + } menu.show(e.getComponent(), e.getX(), e.getY()); } - private void addCardView(final CardView card) { + public void addCardView(final CardView card, boolean duplicated) { allCards.add(card); // Update counts @@ -1651,6 +1675,16 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg // And add it cardContent.add(cardPanel); cardViews.put(card.getId(), cardPanel); + + if (duplicated) { + sortIntoGrid(card); + eventSource.addSpecificCard(card, "add-specific-card"); + // Update layout + layoutGrid(); + // Update draw + cardScroll.revalidate(); + repaint(); + } } private final ArrayList listeners = new ArrayList<>(); diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/DeckArea.java b/Mage.Client/src/main/java/mage/client/deckeditor/DeckArea.java index 7c226c282c9..66b6c7a90b5 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/DeckArea.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/DeckArea.java @@ -135,6 +135,15 @@ public class DeckArea extends javax.swing.JPanel { hiddenCards.clear(); loadDeck(lastDeck, lastBigCard); } + + @Override + public void duplicateCards(Collection cards) { + sideboardList.deselectAll(); + for (CardView card : cards) { + CardView newCard = new CardView(card); + deckList.addCardView(newCard, true); + } + } }); sideboardList.addDragCardGridListener(new DragCardGrid.DragCardGridListener() { @Override @@ -156,6 +165,15 @@ public class DeckArea extends javax.swing.JPanel { hiddenCards.clear(); loadDeck(lastDeck, lastBigCard); } + + @Override + public void duplicateCards(Collection cards) { + deckList.deselectAll(); + for (CardView card : cards) { + CardView newCard = new CardView(card); + sideboardList.addCardView(newCard, true); + } + } }); } @@ -223,9 +241,8 @@ public class DeckArea extends javax.swing.JPanel { } public void setDeckEditorMode(DeckEditorMode mode) { - // Maybe we need this? Right now it isn't needed. Will add if it is. - //this.deckList.setDeckEditorMode(mode); - //this.sideboardList.setDeckEditorMode(mode); + this.deckList.setDeckEditorMode(mode); + this.sideboardList.setDeckEditorMode(mode); } private Set filterHidden(Set cards) { diff --git a/Mage.Common/src/mage/view/CardView.java b/Mage.Common/src/mage/view/CardView.java index 69b27f15dcf..190c68bf016 100644 --- a/Mage.Common/src/mage/view/CardView.java +++ b/Mage.Common/src/mage/view/CardView.java @@ -138,6 +138,79 @@ public class CardView extends SimpleCardView { this(card, game, false); this.id = cardId; } + + + public CardView(CardView cardView) { + super(cardView.id, cardView.expansionSetCode, cardView.cardNumber, cardView.usesVariousArt, cardView.tokenSetCode, cardView.gameObject, cardView.tokenDescriptor); + + this.id = UUID.randomUUID(); + this.parentId = cardView.parentId; + this.name = cardView.name; + this.displayName = cardView.displayName; + this.rules = cardView.rules; + this.power = cardView.power; + this.toughness = cardView.toughness; + this.loyalty = cardView.loyalty; + this.startingLoyalty = cardView.startingLoyalty; + this.cardTypes = cardView.cardTypes; + this.subTypes = cardView.subTypes; + this.superTypes = cardView.superTypes; + this.color = cardView.color; + this.frameColor = cardView.frameColor; + this.frameStyle = cardView.frameStyle; + this.manaCost = cardView.manaCost; + this.convertedManaCost = cardView.convertedManaCost; + this.rarity = cardView.rarity; + + this.mageObjectType = cardView.mageObjectType; + + this.isAbility = cardView.isAbility; + this.abilityType = cardView.abilityType; + this.isToken = cardView.isToken; + + this.ability = null; + this.type = cardView.type; + + this.transformable = cardView.transformable; + if (cardView.secondCardFace != null) { + this.secondCardFace = new CardView(cardView.secondCardFace); + } else { + this.secondCardFace = null; + } + this.transformed = cardView.transformed; + + this.flipCard = cardView.flipCard; + this.faceDown = cardView.faceDown; + + this.alternateName = cardView.alternateName; + this.originalName = cardView.originalName; + + this.isSplitCard = cardView.isSplitCard; + this.leftSplitName = cardView.leftSplitName; + this.leftSplitCosts = cardView.leftSplitCosts; + this.leftSplitRules = null; + this.rightSplitName = cardView.rightSplitName; + this.rightSplitCosts = cardView.rightSplitCosts; + this.rightSplitRules = null; + + this.targets = null; + + this.pairedCard = cardView.pairedCard; + this.paid = cardView.paid; + this.counters = null; + + this.controlledByOwner = cardView.controlledByOwner; + + this.zone = cardView.zone; + + this.rotate = cardView.rotate; + this.hideInfo = cardView.hideInfo; + + this.isPlayable = cardView.isPlayable; + this.isChoosable = cardView.isChoosable; + this.selected = cardView.selected; + this.canAttack = cardView.canAttack; + } /** *