spjspj - Add in a 'Duplicate' (of selection) right click menu option for FREE_BUILDING mode

This commit is contained in:
spjspj 2016-10-18 01:34:30 +11:00
parent 1114eeb133
commit 56cb226634
3 changed files with 131 additions and 7 deletions

View file

@ -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<CardView> 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<CardView>() {
@Override
@ -570,6 +576,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
void cardsSelected();
void hideCards(Collection<CardView> card);
void duplicateCards(Collection<CardView> 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<CardView> 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<String, ArrayList<CardView>> 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<DragCardGridListener> listeners = new ArrayList<>();

View file

@ -135,6 +135,15 @@ public class DeckArea extends javax.swing.JPanel {
hiddenCards.clear();
loadDeck(lastDeck, lastBigCard);
}
@Override
public void duplicateCards(Collection<CardView> 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<CardView> 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<Card> filterHidden(Set<Card> cards) {

View file

@ -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;
}
/**
*