mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
Mostly working Drag n Drop deck editor
* Still trying to iron out how to signal back events from cards moving between different drag and drop targets to the DeckEditorPane
This commit is contained in:
parent
3c2c793f5d
commit
56a3c6dc8c
8 changed files with 379 additions and 86 deletions
|
|
@ -3,6 +3,7 @@ package mage.client.cards;
|
|||
import mage.cards.MageCard;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.view.CardView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
|
@ -15,11 +16,11 @@ import java.util.Collection;
|
|||
/**
|
||||
* Created by StravantUser on 2016-09-22.
|
||||
*/
|
||||
public class CardDraggerGlassPane extends JPanel implements MouseListener, MouseMotionListener {
|
||||
public class CardDraggerGlassPane implements MouseListener, MouseMotionListener {
|
||||
private DragCardSource source;
|
||||
private Component dragComponent;
|
||||
private JRootPane currentRoot;
|
||||
private Component oldGlassPane;
|
||||
private JComponent glassPane;
|
||||
private ArrayList<CardView> currentCards;
|
||||
private MageCard dragView;
|
||||
private DragCardTarget currentDragTarget;
|
||||
|
|
@ -28,10 +29,6 @@ public class CardDraggerGlassPane extends JPanel implements MouseListener, Mouse
|
|||
public CardDraggerGlassPane(DragCardSource source) {
|
||||
this.source = source;
|
||||
|
||||
// Listen on self
|
||||
setLayout(null);
|
||||
setOpaque(false);
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
public void beginDrag(Component c, MouseEvent e) {
|
||||
|
|
@ -45,19 +42,18 @@ public class CardDraggerGlassPane extends JPanel implements MouseListener, Mouse
|
|||
dragComponent = c;
|
||||
currentRoot = SwingUtilities.getRootPane(c);
|
||||
|
||||
// Pane
|
||||
glassPane = (JComponent)currentRoot.getGlassPane();
|
||||
glassPane.setLayout(null);
|
||||
glassPane.setOpaque(false);
|
||||
glassPane.setVisible(true);
|
||||
|
||||
// Hook up events
|
||||
c.addMouseListener(this);
|
||||
c.addMouseMotionListener(this);
|
||||
|
||||
// Switch glass pane to us
|
||||
oldGlassPane = currentRoot.getGlassPane();
|
||||
setVisible(false);
|
||||
currentRoot.setGlassPane(this);
|
||||
setVisible(true);
|
||||
revalidate();
|
||||
|
||||
// Event to local space
|
||||
e = SwingUtilities.convertMouseEvent(c, e, this);
|
||||
e = SwingUtilities.convertMouseEvent(c, e, glassPane);
|
||||
|
||||
// Get the cards to drag
|
||||
currentCards = new ArrayList<>(source.dragCardList());
|
||||
|
|
@ -70,15 +66,15 @@ public class CardDraggerGlassPane extends JPanel implements MouseListener, Mouse
|
|||
for (MouseMotionListener l : dragView.getMouseMotionListeners()) {
|
||||
dragView.removeMouseMotionListener(l);
|
||||
}
|
||||
this.add(dragView);
|
||||
dragView.setLocation(e.getX(), e.getY());
|
||||
glassPane.add(dragView);
|
||||
|
||||
// Notify the sounce
|
||||
source.dragCardBegin();
|
||||
|
||||
// Update the target
|
||||
currentDragTarget = null;
|
||||
updateCurrentTarget(SwingUtilities.convertMouseEvent(c, e, currentRoot), false);
|
||||
updateCurrentTarget(SwingUtilities.convertMouseEvent(glassPane, e, currentRoot), false);
|
||||
}
|
||||
|
||||
// e is relative to currentRoot
|
||||
|
|
@ -132,11 +128,9 @@ public class CardDraggerGlassPane extends JPanel implements MouseListener, Mouse
|
|||
// Convert the event into root coords
|
||||
e = SwingUtilities.convertMouseEvent(dragComponent, e, currentRoot);
|
||||
|
||||
// Switch back glass pane
|
||||
currentRoot.setGlassPane(oldGlassPane);
|
||||
|
||||
// Remove the drag card
|
||||
this.remove(dragView);
|
||||
glassPane.remove(dragView);
|
||||
glassPane.repaint();
|
||||
|
||||
// Update the target, and do the drop
|
||||
updateCurrentTarget(e, true);
|
||||
|
|
@ -148,10 +142,9 @@ public class CardDraggerGlassPane extends JPanel implements MouseListener, Mouse
|
|||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
// Update the view
|
||||
MouseEvent glassE = SwingUtilities.convertMouseEvent(dragComponent, e, this);
|
||||
MouseEvent glassE = SwingUtilities.convertMouseEvent(dragComponent, e, glassPane);
|
||||
dragView.setLocation(glassE.getX(), glassE.getY());
|
||||
dragView.repaint();
|
||||
|
||||
// Convert the event into root coords and update target
|
||||
e = SwingUtilities.convertMouseEvent(dragComponent, e, currentRoot);
|
||||
updateCurrentTarget(e, false);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import mage.client.util.Event;
|
|||
import mage.client.util.EventDispatcher;
|
||||
import mage.client.util.EventSource;
|
||||
import mage.client.util.Listener;
|
||||
import mage.view.CardView;
|
||||
import mage.view.SimpleCardView;
|
||||
|
||||
/**
|
||||
|
|
@ -53,6 +54,18 @@ public class CardEventSource implements EventSource<Event>, Serializable {
|
|||
dispatcher.fireEvent(new Event(card, message, number));
|
||||
}
|
||||
|
||||
public void removeSpecificCard(SimpleCardView card, String message) {
|
||||
dispatcher.fireEvent(new Event(card, message));
|
||||
}
|
||||
|
||||
public void addSpecificCardSideboard(SimpleCardView card, String message) {
|
||||
dispatcher.fireEvent(new Event(card, message));
|
||||
}
|
||||
|
||||
public void addSpecificCardMaindeck(SimpleCardView card, String message) {
|
||||
dispatcher.fireEvent(new Event(card, message));
|
||||
}
|
||||
|
||||
public void doubleClick(SimpleCardView card, String message) {
|
||||
dispatcher.fireEvent(new Event(card, message));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@ import mage.cards.MageCard;
|
|||
import mage.cards.decks.Deck;
|
||||
import mage.cards.decks.importer.DeckImporterUtil;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.CardViewColorComparator;
|
||||
import mage.client.util.CardViewCostComparator;
|
||||
import mage.client.util.CardViewRarityComparator;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
import mage.client.util.*;
|
||||
import mage.client.util.Event;
|
||||
import mage.constants.CardType;
|
||||
import mage.game.GameException;
|
||||
import mage.interfaces.plugin.CardPlugin;
|
||||
|
|
@ -19,6 +18,9 @@ import org.mage.card.arcane.CardRenderer;
|
|||
import org.mage.plugins.card.CardPluginImpl;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
import java.awt.*;
|
||||
|
|
@ -50,22 +52,25 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
|
||||
@Override
|
||||
public void dragCardBegin() {
|
||||
LOGGER.info("Begin drag");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragCardEnd(DragCardTarget target) {
|
||||
LOGGER.info("End drag (" + target + ")");
|
||||
if (target == this) {
|
||||
// Already handled by dragged onto handler
|
||||
} else if (target == null) {
|
||||
// Don't remove the cards, no target
|
||||
} else {
|
||||
// Remove dragged cards
|
||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
||||
for (ArrayList<CardView> stack : gridRow) {
|
||||
for (int i = 0; i < stack.size(); ++i) {
|
||||
CardView view = stack.get(i);
|
||||
if (view.isSelected()) {
|
||||
CardView card = stack.get(i);
|
||||
if (card.isSelected()) {
|
||||
stack.set(i, null);
|
||||
removeCardView(card);
|
||||
eventSource.removeSpecificCard(card, "remove-specific-card");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -309,41 +314,90 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
stack.addAll(stackInsertIndex, cards);
|
||||
}
|
||||
|
||||
// Remove empty rows / cols / spaces in stacks
|
||||
if (source == this) {
|
||||
// Remove empty rows / cols / spaces in stacks
|
||||
trimGrid();
|
||||
layoutGrid();
|
||||
cardScroll.repaint();
|
||||
} else {
|
||||
// Add new cards to grid
|
||||
for (CardView card : cards) {
|
||||
card.setSelected(true);
|
||||
addCardView(card, lastBigCard);
|
||||
if (role == Role.SIDEBOARD) {
|
||||
eventSource.addSpecificCardSideboard(card, "add-specific-card-sideboard");
|
||||
} else if (role == Role.MAINDECK) {
|
||||
eventSource.addSpecificCardMaindeck(card, "add-specific-card-maindeck");
|
||||
}
|
||||
|
||||
}
|
||||
layoutGrid();
|
||||
cardContent.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public void changeGUISize() {
|
||||
layoutGrid();
|
||||
cardContent.repaint();
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
// Remove all of the cards from us
|
||||
for (MageCard cardView : cardViews.values()) {
|
||||
cardContent.remove(cardView);
|
||||
}
|
||||
|
||||
// Clear out our tracking of stuff
|
||||
cardGrid.clear();
|
||||
maxStackSize.clear();
|
||||
allCards.clear();
|
||||
lastBigCard = null;
|
||||
clearCardEventListeners();
|
||||
}
|
||||
|
||||
public void addCardEventListener(Listener<Event> listener) {
|
||||
eventSource.addListener(listener);
|
||||
}
|
||||
|
||||
public void clearCardEventListeners() {
|
||||
eventSource.clearListeners();
|
||||
}
|
||||
|
||||
public void setRole(Role role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public enum Sort {
|
||||
NONE(new Comparator<CardView>() {
|
||||
NONE("No Sort", new Comparator<CardView>() {
|
||||
@Override
|
||||
public int compare(CardView o1, CardView o2) {
|
||||
// Always equal, sort into the first row
|
||||
return 0;
|
||||
}
|
||||
}),
|
||||
CMC(new CardViewCostComparator()),
|
||||
COLOR(new CardViewColorComparator()),
|
||||
RARITY(new CardViewRarityComparator());
|
||||
CMC("Converted Mana Cost", new CardViewCostComparator()),
|
||||
COLOR("Color", new CardViewColorComparator()),
|
||||
RARITY("Rarity", new CardViewRarityComparator());
|
||||
|
||||
Sort(Comparator<CardView> comparator) {
|
||||
Sort(String text, Comparator<CardView> comparator) {
|
||||
this.comparator = comparator;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public Comparator<CardView> getComparator() {
|
||||
return comparator;
|
||||
}
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
private Comparator<CardView> comparator;
|
||||
private String text;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Constants
|
||||
public static int CARD_WIDTH = 150;
|
||||
public static int COUNT_LABEL_HEIGHT = 20;
|
||||
public static int GRID_PADDING = 10;
|
||||
|
||||
|
|
@ -354,13 +408,21 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
private Map<UUID, MageCard> cardViews = new LinkedHashMap<>();
|
||||
private ArrayList<CardView> allCards = new ArrayList<>();
|
||||
|
||||
// Card listeners
|
||||
private CardEventSource eventSource = new CardEventSource();
|
||||
|
||||
// Last big card
|
||||
BigCard lastBigCard = null;
|
||||
|
||||
// Top bar with dropdowns for sort / filter / etc
|
||||
JButton sortButton;
|
||||
JButton filterButton;
|
||||
|
||||
// Popup for toolbar
|
||||
JPopupMenu filterPopup;
|
||||
|
||||
JPopupMenu sortPopup;
|
||||
JCheckBox separateCreaturesCb;
|
||||
|
||||
// Main two controls holding the scrollable card grid
|
||||
JScrollPane cardScroll;
|
||||
|
|
@ -374,6 +436,12 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
int selectionDragStartX;
|
||||
int selectionDragStartY;
|
||||
|
||||
// Card size mod
|
||||
float cardSizeMod = 1.0f;
|
||||
|
||||
// The role (maindeck or sideboard)
|
||||
Role role;
|
||||
|
||||
// Dragging
|
||||
private CardDraggerGlassPane dragger = new CardDraggerGlassPane(this);
|
||||
|
||||
|
|
@ -387,6 +455,11 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
private Sort cardSort = Sort.CMC;
|
||||
private boolean separateCreatures = true;
|
||||
|
||||
public enum Role {
|
||||
MAINDECK,
|
||||
SIDEBOARD
|
||||
}
|
||||
|
||||
// Constructor
|
||||
public DragCardGrid() {
|
||||
// Make sure that the card grid is populated with at least one (empty) stack to begin with
|
||||
|
|
@ -399,6 +472,13 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
sortButton = new JButton("Sort");
|
||||
filterButton = new JButton("Filter");
|
||||
|
||||
addFocusListener(new FocusAdapter() {
|
||||
@Override
|
||||
public void focusLost(FocusEvent e) {
|
||||
deselectAll();
|
||||
}
|
||||
});
|
||||
|
||||
// Tmp load button
|
||||
JButton loadButton = new JButton("Load");
|
||||
loadButton.addActionListener(new ActionListener() {
|
||||
|
|
@ -410,13 +490,33 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
|
||||
JPanel toolbar = new JPanel(new BorderLayout());
|
||||
JPanel toolbarInner = new JPanel();
|
||||
toolbar.setBackground(new Color(250, 250, 250, 150));
|
||||
//toolbar.setBackground(new Color(250, 250, 250, 150));
|
||||
toolbar.setOpaque(true);
|
||||
toolbarInner.setOpaque(false);
|
||||
toolbarInner.add(sortButton);
|
||||
toolbarInner.add(filterButton);
|
||||
toolbarInner.add(loadButton);
|
||||
toolbar.add(toolbarInner, BorderLayout.WEST);
|
||||
JPanel sliderPanel = new JPanel(new GridBagLayout());
|
||||
final JSlider sizeSlider = new JSlider(SwingConstants.HORIZONTAL, 0, 100, 50);
|
||||
sizeSlider.setPreferredSize(new Dimension(100, (int)sizeSlider.getPreferredSize().getHeight()));
|
||||
sizeSlider.addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (!sizeSlider.getValueIsAdjusting()) {
|
||||
// Fraction in [-1, 1]
|
||||
float sliderFrac = ((float) (sizeSlider.getValue() - 50)) / 50;
|
||||
// Convert to frac in [0.5, 2.0] exponentially
|
||||
cardSizeMod = (float) Math.pow(2, sliderFrac);
|
||||
// Update grid
|
||||
layoutGrid();
|
||||
cardContent.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
sliderPanel.add(new JLabel("Card Size:"));
|
||||
sliderPanel.add(sizeSlider);
|
||||
toolbar.add(sliderPanel, BorderLayout.EAST);
|
||||
this.add(toolbar, BorderLayout.NORTH);
|
||||
|
||||
// Content
|
||||
|
|
@ -456,19 +556,90 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
selectionPanel.setVisible(false);
|
||||
cardContent.add(selectionPanel, new Integer(1001));
|
||||
|
||||
// Load separate creatures setting
|
||||
separateCreatures = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DECK_EDITOR_LAST_SEPARATE_CREATURES, "false").equals("true");
|
||||
cardSort = Sort.valueOf(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DECK_EDITOR_LAST_SORT, Sort.NONE.toString()));
|
||||
|
||||
// Sort popup
|
||||
sortPopup = new JPopupMenu();
|
||||
sortPopup.setPreferredSize(new Dimension(300, 300));
|
||||
makeButtonPopup(sortButton, sortPopup);
|
||||
{
|
||||
sortPopup = new JPopupMenu();
|
||||
sortPopup.setLayout(new GridBagLayout());
|
||||
|
||||
JPanel sortMode = new JPanel();
|
||||
sortMode.setLayout(new GridLayout(Sort.values().length, 1, 0, 2));
|
||||
sortMode.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Sort by..."));
|
||||
GridBagConstraints sortModeC = new GridBagConstraints();
|
||||
sortModeC.gridx = 0; sortModeC.gridy = 0; sortModeC.gridwidth = 1; sortModeC.gridheight = 1;
|
||||
sortModeC.fill = GridBagConstraints.HORIZONTAL;
|
||||
sortPopup.add(sortMode, sortModeC);
|
||||
|
||||
ButtonGroup sortModeGroup = new ButtonGroup();
|
||||
for (final Sort s : Sort.values()) {
|
||||
JToggleButton button = new JToggleButton(s.getText());
|
||||
if (s == cardSort) {
|
||||
button.setSelected(true);
|
||||
}
|
||||
sortMode.add(button);
|
||||
sortModeGroup.add(button);
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
cardSort = s;
|
||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_DECK_EDITOR_LAST_SORT, s.toString());
|
||||
resort();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
JPanel sortOptions = new JPanel();
|
||||
sortOptions.setLayout(new BoxLayout(sortOptions, BoxLayout.Y_AXIS));
|
||||
sortOptions.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Sort options"));
|
||||
GridBagConstraints sortOptionsC = new GridBagConstraints();
|
||||
sortOptionsC.gridx = 0; sortOptionsC.gridy = 1; sortOptionsC.gridwidth = 1; sortOptionsC.gridheight = 1;
|
||||
sortPopup.add(sortOptions, sortOptionsC);
|
||||
|
||||
separateCreaturesCb = new JCheckBox();
|
||||
separateCreaturesCb.setText("Creatures in separate row");
|
||||
separateCreaturesCb.setSelected(separateCreatures);
|
||||
separateCreaturesCb.addItemListener(new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
separateCreatures = separateCreaturesCb.isSelected();
|
||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_DECK_EDITOR_LAST_SEPARATE_CREATURES, Boolean.toString(separateCreatures));
|
||||
resort();
|
||||
}
|
||||
});
|
||||
sortOptions.add(separateCreaturesCb);
|
||||
|
||||
sortPopup.pack();
|
||||
|
||||
makeButtonPopup(sortButton, sortPopup);
|
||||
}
|
||||
|
||||
// Filter popup
|
||||
filterPopup = new JPopupMenu();
|
||||
filterPopup.setPreferredSize(new Dimension(300, 300));
|
||||
makeButtonPopup(filterButton, filterPopup);
|
||||
|
||||
filterButton.setVisible(false);
|
||||
loadButton.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deselect all cards in this DragCardGrid
|
||||
*/
|
||||
private void deselectAll() {
|
||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
||||
for (ArrayList<CardView> stack : gridRow) {
|
||||
for (CardView card : stack) {
|
||||
if (card.isSelected()) {
|
||||
card.setSelected(false);
|
||||
cardViews.get(card.getId()).update(card);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -568,7 +739,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||
Deck deck = Deck.load(DeckImporterUtil.importDeck(file.getPath()), true, true);
|
||||
Logger.getLogger(DragCardGrid.class).info("Loaded " + deck.getCards().size());
|
||||
setCards(new CardsView(deck.getCards()));
|
||||
setCards(new CardsView(deck.getCards()), null);
|
||||
} catch (GameException ex) {
|
||||
JOptionPane.showMessageDialog(MageFrame.getDesktop(), ex.getMessage(), "Error loading deck", JOptionPane.ERROR_MESSAGE);
|
||||
} catch (Exception ex) {
|
||||
|
|
@ -586,8 +757,35 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
fcSelectDeck.setSelectedFile(null);
|
||||
}
|
||||
|
||||
// Resort the existing cards based on the current sort
|
||||
public void resort() {
|
||||
// First null out the grid and trim it down
|
||||
for (ArrayList<ArrayList<CardView>> gridRow : cardGrid) {
|
||||
for (ArrayList<CardView> stack : gridRow) {
|
||||
stack.clear();
|
||||
}
|
||||
}
|
||||
trimGrid();
|
||||
|
||||
// Now re-insert all of the cards using the current sort
|
||||
for (CardView card : allCards) {
|
||||
sortIntoGrid(card);
|
||||
}
|
||||
|
||||
// Deselect everything
|
||||
deselectAll();
|
||||
|
||||
// And finally rerender
|
||||
layoutGrid();
|
||||
repaint();
|
||||
}
|
||||
|
||||
// Update the contents of the card grid
|
||||
public void setCards(CardsView cardsView) {
|
||||
public void setCards(CardsView cardsView, BigCard bigCard) {
|
||||
if (bigCard != null) {
|
||||
lastBigCard = bigCard;
|
||||
}
|
||||
|
||||
// Remove all of the cards not in the cardsView
|
||||
boolean didModify = false; // Until contested
|
||||
for (int i = 0; i < cardGrid.size(); ++i) {
|
||||
|
|
@ -612,7 +810,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, bigCard);
|
||||
|
||||
try {
|
||||
// Put it into the appropirate place in the grid given the current sort
|
||||
|
|
@ -639,17 +837,25 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
}
|
||||
}
|
||||
|
||||
private void addCardView(final CardView card) {
|
||||
private void addCardView(final CardView card, BigCard bigCard) {
|
||||
allCards.add(card);
|
||||
|
||||
// Create the card view
|
||||
final MageCard cardPanel = Plugins.getInstance().getMageCard(card, null, new Dimension(100, 140), null, true);
|
||||
cardPanel.update(card);
|
||||
final MageCard cardPanel = Plugins.getInstance().getMageCard(card, bigCard, new Dimension(100, 140), null, true);
|
||||
cardPanel.setTextOffset(0);
|
||||
|
||||
cardPanel.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
cardClicked(card, e);
|
||||
if (e.getClickCount() == 1) {
|
||||
cardClicked(card, e);
|
||||
} else {
|
||||
if (e.isAltDown()) {
|
||||
eventSource.altDoubleClick(card, "alt-double-click");
|
||||
} else {
|
||||
eventSource.doubleClick(card, "double-click");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
cardPanel.addMouseMotionListener(new MouseAdapter() {
|
||||
|
|
@ -826,7 +1032,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
}
|
||||
|
||||
private int getCardWidth() {
|
||||
return CARD_WIDTH;
|
||||
return (int)(GUISizeHelper.editorCardDimension.width * cardSizeMod);
|
||||
}
|
||||
|
||||
private int getCardHeight() {
|
||||
|
|
@ -931,6 +1137,12 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: This class can't just be a JPanel, because a JPanel doesn't draw when it has Opaque = false, but
|
||||
* this class needs to go into a JLayeredPane while being translucent, so it NEEDS Opaque = false in order
|
||||
* to behave correctly.
|
||||
* Thus this simple class is needed to implement a translucent box in a JLayeredPane.
|
||||
*/
|
||||
class SelectionBox extends JComponent {
|
||||
public SelectionBox() {
|
||||
setOpaque(false);
|
||||
|
|
|
|||
|
|
@ -41,10 +41,7 @@ import java.awt.event.ComponentEvent;
|
|||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTable;
|
||||
|
|
@ -58,9 +55,7 @@ import mage.cards.Sets;
|
|||
import mage.cards.repository.CardCriteria;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.cards.CardGrid;
|
||||
import mage.client.cards.ICardGrid;
|
||||
import mage.client.cards.*;
|
||||
import mage.client.constants.Constants.SortBy;
|
||||
import mage.client.deckeditor.table.TableModel;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
|
|
@ -74,13 +69,14 @@ import mage.filter.predicate.mageobject.ColorPredicate;
|
|||
import mage.filter.predicate.mageobject.ColorlessPredicate;
|
||||
import mage.filter.predicate.other.CardTextPredicate;
|
||||
import mage.filter.predicate.other.ExpansionSetPredicate;
|
||||
import mage.view.CardView;
|
||||
import mage.view.CardsView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com, nantuko
|
||||
*/
|
||||
public class CardSelector extends javax.swing.JPanel implements ComponentListener {
|
||||
public class CardSelector extends javax.swing.JPanel implements ComponentListener, DragCardTarget {
|
||||
|
||||
private final List<Card> cards = new ArrayList<>();
|
||||
private BigCard bigCard;
|
||||
|
|
@ -1221,4 +1217,23 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragCardEnter(MouseEvent e) {
|
||||
// Nothing to do for now. We could show something
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragCardMove(MouseEvent e) {
|
||||
// Nothing to do for now. We could show something
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragCardExit(MouseEvent e) {
|
||||
// Nothing to do for now. We could show something
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dragCardDrop(MouseEvent e, DragCardSource source, Collection<CardView> cards) {
|
||||
// Nothing to do, just eat the dropped cards, they're being removed from the deck or sideboard
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,20 +36,20 @@
|
|||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="mage.client.cards.CardsList" name="sideboardList">
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
|
||||
<JSplitPaneConstraints position="right"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="mage.client.cards.CardsList" name="deckList">
|
||||
<Component class="mage.client.cards.DragCardGrid" name="dragCardGrid1">
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
|
||||
<JSplitPaneConstraints position="left"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
<Component class="mage.client.cards.DragCardGrid" name="dragCardGrid2">
|
||||
<Constraints>
|
||||
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout" value="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout$JSplitPaneConstraintsDescription">
|
||||
<JSplitPaneConstraints position="right"/>
|
||||
</Constraint>
|
||||
</Constraints>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
|
|
|
|||
|
|
@ -35,11 +35,13 @@ package mage.client.deckeditor;
|
|||
import mage.cards.decks.Deck;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.cards.CardsList;
|
||||
import mage.client.cards.DragCardGrid;
|
||||
import mage.client.constants.Constants.DeckEditorMode;
|
||||
import mage.client.util.Event;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
import mage.client.util.Listener;
|
||||
import mage.view.CardsView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
|
|
@ -54,13 +56,11 @@ public class DeckArea extends javax.swing.JPanel {
|
|||
*/
|
||||
public DeckArea() {
|
||||
initComponents();
|
||||
deckAreaSplitPane.setOpaque(false);
|
||||
deckList.setSortSetting(SortSettingDeck.getInstance());
|
||||
sideboardList.setSortSetting(SortSettingSideboard.getInstance());
|
||||
deckList.setOpaque(false);
|
||||
sideboardList.setOpaque(false);
|
||||
deckList.setDisplayNoCopies(true);
|
||||
sideboardList.setDisplayNoCopies(true);
|
||||
//deckAreaSplitPane.setOpaque(false);
|
||||
//deckList.setOpaque(false);
|
||||
//sideboardList.setOpaque(false);
|
||||
deckList.setRole(DragCardGrid.Role.MAINDECK);
|
||||
sideboardList.setRole(DragCardGrid.Role.SIDEBOARD);
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
|
|
@ -91,14 +91,16 @@ public class DeckArea extends javax.swing.JPanel {
|
|||
}
|
||||
|
||||
public void setDeckEditorMode(DeckEditorMode mode) {
|
||||
this.deckList.setDeckEditorMode(mode);
|
||||
this.sideboardList.setDeckEditorMode(mode);
|
||||
// Maybe we need this? Right now it isn't needed. Will add if it is.
|
||||
//this.deckList.setDeckEditorMode(mode);
|
||||
//this.sideboardList.setDeckEditorMode(mode);
|
||||
}
|
||||
|
||||
public void loadDeck(Deck deck, BigCard bigCard) {
|
||||
deckList.loadCards(new CardsView(deck.getCards()), bigCard, null);
|
||||
deckList.setCards(new CardsView(deck.getCards()), bigCard);
|
||||
Logger.getLogger(DeckArea.class).info("Loading, sideboard is visible=" + sideboardList.isVisible());
|
||||
if (sideboardList.isVisible()) {
|
||||
sideboardList.loadCards(new CardsView(deck.getSideboard()), bigCard, null);
|
||||
sideboardList.setCards(new CardsView(deck.getSideboard()), bigCard);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,13 +130,13 @@ public class DeckArea extends javax.swing.JPanel {
|
|||
private void initComponents() {
|
||||
|
||||
deckAreaSplitPane = new javax.swing.JSplitPane();
|
||||
sideboardList = new mage.client.cards.CardsList();
|
||||
deckList = new mage.client.cards.CardsList();
|
||||
deckList = new mage.client.cards.DragCardGrid();
|
||||
sideboardList = new mage.client.cards.DragCardGrid();
|
||||
|
||||
deckAreaSplitPane.setBorder(null);
|
||||
deckAreaSplitPane.setResizeWeight(0.6);
|
||||
deckAreaSplitPane.setRightComponent(sideboardList);
|
||||
deckAreaSplitPane.setLeftComponent(deckList);
|
||||
deckAreaSplitPane.setRightComponent(sideboardList);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
|
|
@ -148,18 +150,18 @@ public class DeckArea extends javax.swing.JPanel {
|
|||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
public CardsList getDeckList() {
|
||||
public DragCardGrid getDeckList() {
|
||||
return deckList;
|
||||
}
|
||||
|
||||
public CardsList getSideboardList() {
|
||||
public DragCardGrid getSideboardList() {
|
||||
return sideboardList;
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JSplitPane deckAreaSplitPane;
|
||||
private mage.client.cards.CardsList deckList;
|
||||
private mage.client.cards.CardsList sideboardList;
|
||||
private mage.client.cards.DragCardGrid deckList;
|
||||
private mage.client.cards.DragCardGrid sideboardList;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
deckArea.setOpaque(false);
|
||||
jPanel1.setOpaque(false);
|
||||
jSplitPane1.setOpaque(false);
|
||||
jSplitPane1.setResizeWeight(0.3);
|
||||
countdown = new Timer(1000,
|
||||
new ActionListener() {
|
||||
@Override
|
||||
|
|
@ -232,10 +233,10 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
}
|
||||
break;
|
||||
case "remove-main":
|
||||
DeckEditorPanel.this.deckArea.getDeckList().handleDoubleClick();
|
||||
//DeckEditorPanel.this.deckArea.getDeckList().handleDoubleClick();
|
||||
break;
|
||||
case "remove-sideboard":
|
||||
DeckEditorPanel.this.deckArea.getSideboardList().handleDoubleClick();
|
||||
//DeckEditorPanel.this.deckArea.getSideboardList().handleDoubleClick();
|
||||
break;
|
||||
}
|
||||
refreshDeck();
|
||||
|
|
@ -277,6 +278,19 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
case "set-number": {
|
||||
setCardNumberToCardsList(event, deck.getCards());
|
||||
}
|
||||
case "remove-specific-card": {
|
||||
SimpleCardView cardView = (SimpleCardView) event.getSource();
|
||||
for (Card card : deck.getCards()) {
|
||||
if (card.getId().equals(cardView.getId())) {
|
||||
deck.getCards().remove(card);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
case "add-specific-card-maindeck": {
|
||||
SimpleCardView cardView = (CardView) event.getSource();
|
||||
deck.getCards().add(CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber()).getCard());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// constructing phase or sideboarding during match -> card goes always to sideboard
|
||||
|
|
@ -296,10 +310,24 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
refreshDeck();
|
||||
break;
|
||||
}
|
||||
case "remove-specific-card": {
|
||||
SimpleCardView cardView = (SimpleCardView) event.getSource();
|
||||
for (Card card : deck.getCards()) {
|
||||
if (card.getId().equals(cardView.getId())) {
|
||||
deck.getCards().remove(card);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
case "add-specific-card-maindeck": {
|
||||
SimpleCardView cardView = (CardView) event.getSource();
|
||||
deck.getCards().add(CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber()).getCard());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
this.deckArea.clearSideboardEventListeners();
|
||||
this.deckArea.addSideboardEventListener(
|
||||
new Listener<Event>() {
|
||||
@Override
|
||||
|
|
@ -335,10 +363,36 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
case "set-number": {
|
||||
setCardNumberToCardsList(event, deck.getSideboard());
|
||||
}
|
||||
case "remove-specific-card": {
|
||||
cardView = (SimpleCardView) event.getSource();
|
||||
for (Card card : deck.getSideboard()) {
|
||||
if (card.getId().equals(cardView.getId())) {
|
||||
deck.getSideboard().remove(card);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
case "add-specific-card-sideboard": {
|
||||
cardView = (CardView) event.getSource();
|
||||
deck.getSideboard().add(CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber()).getCard());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// construct phase or sideboarding during match
|
||||
switch (event.getEventName()) {
|
||||
case "remove-specific-card": {
|
||||
SimpleCardView cardView = (SimpleCardView) event.getSource();
|
||||
for (Card card : deck.getSideboard()) {
|
||||
if (card.getId().equals(cardView.getId())) {
|
||||
deck.getSideboard().remove(card);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
case "add-specific-card-sideboard": {
|
||||
SimpleCardView cardView = (CardView) event.getSource();
|
||||
deck.getSideboard().add(CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber()).getCard());
|
||||
}
|
||||
case "double-click":
|
||||
case "alt-double-click":
|
||||
SimpleCardView cardView = (SimpleCardView) event.getSource();
|
||||
|
|
|
|||
|
|
@ -176,6 +176,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
public static final String KEY_TABLES_COLUMNS_WIDTH = "tablePanelColumnWidth";
|
||||
public static final String KEY_TABLES_COLUMNS_ORDER = "tablePanelColumnSort";
|
||||
|
||||
// last sort settings used in deck editor
|
||||
public static final String KEY_DECK_EDITOR_LAST_SORT = "deckEditorLastSort";
|
||||
public static final String KEY_DECK_EDITOR_LAST_SEPARATE_CREATURES = "deckEditorLastSeparateCreatures";
|
||||
|
||||
// positions of divider bars
|
||||
public static final String KEY_TABLES_DIVIDER_LOCATION_1 = "tablePanelDividerLocation1";
|
||||
public static final String KEY_TABLES_DIVIDER_LOCATION_2 = "tablePanelDividerLocation2";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue