mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
still more Deck Editor changes
This commit is contained in:
parent
436c48b17e
commit
f74df18cc9
11 changed files with 132 additions and 69 deletions
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
package mage.client;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.client.cards.CardsStorage;
|
||||
|
|
@ -49,6 +50,7 @@ import mage.client.remote.Session;
|
|||
import mage.client.util.EDTExceptionHandler;
|
||||
import mage.client.util.gui.ArrowBuilder;
|
||||
import mage.components.ImagePanel;
|
||||
import mage.game.GameException;
|
||||
import mage.util.Logging;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
|
@ -68,6 +70,7 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
import java.util.prefs.Preferences;
|
||||
import mage.client.draft.DraftPane;
|
||||
import mage.sets.Sets;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -547,7 +550,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
this.tablesPane.setVisible(false);
|
||||
this.draftPane.setVisible(false);
|
||||
this.collectionViewerPane.setVisible(false);
|
||||
showDeckEditor(DeckEditorMode.Constructed, null, null);
|
||||
showDeckEditor(DeckEditorMode.Constructed, null, null);
|
||||
}//GEN-LAST:event_btnDeckEditorActionPerformed
|
||||
|
||||
private void btnCollectionViewerActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
|
|||
for (Iterator<Entry<UUID, MageCard>> i = cards.entrySet().iterator(); i.hasNext();) {
|
||||
Entry<UUID, MageCard> entry = i.next();
|
||||
if (!showCards.containsKey(entry.getKey())) {
|
||||
removeCard(entry.getKey());
|
||||
removeCardImg(entry.getKey());
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
|
@ -123,14 +123,16 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
|
|||
}
|
||||
}
|
||||
resizeArea();
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void removeCard(UUID cardId) {
|
||||
private void removeCardImg(UUID cardId) {
|
||||
for (Component comp: getComponents()) {
|
||||
if (comp instanceof Card) {
|
||||
if (((Card)comp).getCardId().equals(cardId)) {
|
||||
remove(comp);
|
||||
}
|
||||
}
|
||||
} else if (comp instanceof MageCard) {
|
||||
if (((MageCard)comp).getOriginal().getId().equals(cardId)) {
|
||||
remove(comp);
|
||||
|
|
@ -139,6 +141,11 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
|
|||
}
|
||||
}
|
||||
|
||||
public void removeCard(UUID cardId) {
|
||||
removeCardImg(cardId);
|
||||
cards.remove(cardId);
|
||||
}
|
||||
|
||||
|
||||
public void addCardEventListener(Listener<Event> listener) {
|
||||
cardEventSource.addListener(listener);
|
||||
|
|
@ -213,8 +220,6 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener
|
|||
}
|
||||
if (size.height != area.height || size.width != area.width) {
|
||||
setPreferredSize(area);
|
||||
revalidate();
|
||||
repaint();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -355,19 +355,19 @@ public class DeckGenerator {
|
|||
private static Card getBestBasicLand(ColoredManaSymbol color) {
|
||||
manaSource = color.toString();
|
||||
if (color.equals(ColoredManaSymbol.G)) {
|
||||
return CardImpl.createCard(Sets.findCard("Forest", GENERATE_RANDOM_BASIC_LAND));
|
||||
return Sets.findCard("Forest", GENERATE_RANDOM_BASIC_LAND);
|
||||
}
|
||||
if (color.equals(ColoredManaSymbol.R)) {
|
||||
return CardImpl.createCard(Sets.findCard("Mountain", GENERATE_RANDOM_BASIC_LAND));
|
||||
return Sets.findCard("Mountain", GENERATE_RANDOM_BASIC_LAND);
|
||||
}
|
||||
if (color.equals(ColoredManaSymbol.B)) {
|
||||
return CardImpl.createCard(Sets.findCard("Swamp", GENERATE_RANDOM_BASIC_LAND));
|
||||
return Sets.findCard("Swamp", GENERATE_RANDOM_BASIC_LAND);
|
||||
}
|
||||
if (color.equals(ColoredManaSymbol.U)) {
|
||||
return CardImpl.createCard(Sets.findCard("Island", GENERATE_RANDOM_BASIC_LAND));
|
||||
return Sets.findCard("Island", GENERATE_RANDOM_BASIC_LAND);
|
||||
}
|
||||
if (color.equals(ColoredManaSymbol.W)) {
|
||||
return CardImpl.createCard(Sets.findCard("Plains", GENERATE_RANDOM_BASIC_LAND));
|
||||
return Sets.findCard("Plains", GENERATE_RANDOM_BASIC_LAND);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class DecDeckImporter extends DeckImporterImpl {
|
|||
String lineName = line.substring(delim).trim();
|
||||
try {
|
||||
int num = Integer.parseInt(lineNum);
|
||||
String cardName = Sets.findCard(lineName);
|
||||
String cardName = Sets.findCard(lineName).getClass().getCanonicalName();
|
||||
if (cardName == null)
|
||||
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,12 @@
|
|||
|
||||
package mage.client.deckeditor;
|
||||
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.cards.CardsList;
|
||||
import mage.client.util.Event;
|
||||
import mage.client.util.Listener;
|
||||
import mage.view.CardsView;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -55,12 +60,26 @@ public class DeckArea extends javax.swing.JPanel {
|
|||
this.sideboardList.setVisible(show);
|
||||
}
|
||||
|
||||
public CardsList getDeckList() {
|
||||
return deckList;
|
||||
public void loadDeck(Deck deck, BigCard bigCard) {
|
||||
deckList.loadCards(new CardsView(deck.getCards()), bigCard, null, true);
|
||||
if (sideboardList.isVisible())
|
||||
sideboardList.loadCards(new CardsView(deck.getSideboard()), bigCard, null, true);
|
||||
}
|
||||
|
||||
public CardsList getSideboardList() {
|
||||
return sideboardList;
|
||||
public void addDeckEventListener(Listener<Event> listener) {
|
||||
deckList.addCardEventListener(listener);
|
||||
}
|
||||
|
||||
public void clearDeckEventListeners() {
|
||||
deckList.clearCardEventListeners();
|
||||
}
|
||||
|
||||
public void addSideboardEventListener(Listener<Event> listener) {
|
||||
sideboardList.addCardEventListener(listener);
|
||||
}
|
||||
|
||||
public void clearSideboardEventListeners() {
|
||||
sideboardList.clearCardEventListeners();
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
|
|
|
|||
|
|
@ -37,14 +37,12 @@ package mage.client.deckeditor;
|
|||
import mage.cards.Card;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.client.MageFrame;
|
||||
//import mage.client.deckeditor.collection.viewer.Huerotator2;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.Event;
|
||||
import mage.client.util.Listener;
|
||||
import mage.components.CardInfoPane;
|
||||
import mage.game.GameException;
|
||||
import mage.view.CardView;
|
||||
import mage.view.CardsView;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
|
@ -56,7 +54,9 @@ import java.util.ArrayList;
|
|||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.constants.Constants.DeckEditorMode;
|
||||
import mage.client.dialog.AddLandDialog;
|
||||
import mage.sets.Sets;
|
||||
|
||||
/**
|
||||
|
|
@ -93,8 +93,10 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
this.deck = deck;
|
||||
this.tableId = tableId;
|
||||
this.mode = mode;
|
||||
this.btnAddLand.setVisible(false);
|
||||
switch (mode) {
|
||||
case Limited:
|
||||
this.btnAddLand.setVisible(true);
|
||||
case Sideboard:
|
||||
this.btnSubmit.setVisible(true);
|
||||
this.cardSelector.loadCards(new ArrayList<Card>(deck.getSideboard()), this.bigCard, mode == DeckEditorMode.Limited);
|
||||
|
|
@ -126,8 +128,9 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
if (event.getEventName().equals("double-click")) {
|
||||
Card card = cardSelector.getCard((UUID) event.getSource());
|
||||
if (card != null) {
|
||||
deck.getCards().add(createCard(card.getClass()));
|
||||
deck.getCards().add(Sets.createCard(card.getClass()));
|
||||
if (mode == DeckEditorMode.Sideboard || mode == DeckEditorMode.Limited) {
|
||||
deck.getSideboard().remove(card);
|
||||
cardSelector.getCardsList().removeCard(card.getId());
|
||||
}
|
||||
if (cardInfoPane instanceof CardInfoPane) {
|
||||
|
|
@ -139,18 +142,19 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
}
|
||||
}
|
||||
);
|
||||
this.deckArea.getDeckList().clearCardEventListeners();
|
||||
this.deckArea.getDeckList().addCardEventListener(
|
||||
this.deckArea.clearDeckEventListeners();
|
||||
this.deckArea.addDeckEventListener(
|
||||
new Listener<Event> () {
|
||||
@Override
|
||||
public void event(Event event) {
|
||||
if (System.getProperty("draft") != null) {
|
||||
return;
|
||||
}
|
||||
if (event.getEventName().equals("double-click")) {
|
||||
for (Card card: deck.getCards()) {
|
||||
if (card.getId().equals((UUID)event.getSource())) {
|
||||
deck.getCards().remove(card);
|
||||
if (mode == DeckEditorMode.Limited || mode == DeckEditorMode.Sideboard) {
|
||||
deck.getSideboard().add(card);
|
||||
cardSelector.loadCards(new ArrayList<Card>(deck.getSideboard()), getBigCard(), mode == DeckEditorMode.Limited);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -164,28 +168,21 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
this.repaint();
|
||||
}
|
||||
|
||||
private BigCard getBigCard() {
|
||||
return this.bigCard;
|
||||
}
|
||||
|
||||
private void refreshDeck() {
|
||||
try {
|
||||
setCursor(new Cursor(Cursor.WAIT_CURSOR));
|
||||
this.txtDeckName.setText(deck.getName());
|
||||
deckArea.getDeckList().loadCards(new CardsView(deck.getCards()), bigCard, null, true);
|
||||
deckArea.getSideboardList().loadCards(new CardsView(deck.getSideboard()), bigCard, null, true);
|
||||
deckArea.loadDeck(deck, bigCard);
|
||||
}
|
||||
finally {
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
}
|
||||
}
|
||||
|
||||
private Card createCard(Class clazz) {
|
||||
try {
|
||||
Constructor<?> con = clazz.getConstructor(new Class[]{UUID.class});
|
||||
return (Card) con.newInstance(new Object[] {null});
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(DeckEditorPanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
|
||||
jSplitPane1 = new javax.swing.JSplitPane();
|
||||
|
|
@ -201,6 +198,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
btnExit = new javax.swing.JButton();
|
||||
btnImport = new javax.swing.JButton();
|
||||
btnSubmit = new javax.swing.JButton();
|
||||
btnAddLand = new javax.swing.JButton();
|
||||
|
||||
jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
|
||||
jSplitPane1.setResizeWeight(0.5);
|
||||
|
|
@ -266,6 +264,14 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
}
|
||||
});
|
||||
|
||||
btnAddLand.setText("Add Land");
|
||||
btnAddLand.setName("btnAddLand"); // NOI18N
|
||||
btnAddLand.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
btnAddLandActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
||||
jPanel1.setLayout(jPanel1Layout);
|
||||
jPanel1Layout.setHorizontalGroup(
|
||||
|
|
@ -292,6 +298,8 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
.addContainerGap()
|
||||
.addComponent(btnImport)
|
||||
.addContainerGap()
|
||||
.addComponent(btnAddLand)
|
||||
.addContainerGap()
|
||||
.addComponent(btnSubmit)))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
|
@ -311,6 +319,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(btnImport)
|
||||
.addComponent(btnAddLand)
|
||||
.addComponent(btnSubmit))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, isShowCardInfo ? 30 : 159, Short.MAX_VALUE)
|
||||
.addComponent(cardInfoPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
|
|
@ -386,7 +395,16 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
}//GEN-LAST:event_btnSaveActionPerformed
|
||||
|
||||
private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewActionPerformed
|
||||
deck = new Deck();
|
||||
if (mode == DeckEditorMode.Sideboard || mode == DeckEditorMode.Limited) {
|
||||
for (Card card: deck.getCards()) {
|
||||
deck.getSideboard().add(card);
|
||||
}
|
||||
deck.getCards().clear();
|
||||
cardSelector.loadCards(new ArrayList<Card>(deck.getSideboard()), this.bigCard, mode == DeckEditorMode.Limited);
|
||||
}
|
||||
else {
|
||||
deck = new Deck();
|
||||
}
|
||||
refreshDeck();
|
||||
}//GEN-LAST:event_btnNewActionPerformed
|
||||
|
||||
|
|
@ -429,6 +447,12 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
this.setVisible(false);
|
||||
}
|
||||
|
||||
private void btnAddLandActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
AddLandDialog addLand = new AddLandDialog();
|
||||
addLand.showDialog(deck);
|
||||
refreshDeck();
|
||||
}
|
||||
|
||||
public DeckImporter getDeckImporter(String file) {
|
||||
if (file.toLowerCase().endsWith("dec"))
|
||||
return new DecDeckImporter();
|
||||
|
|
@ -457,6 +481,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
|
||||
private JComponent cardInfoPane;
|
||||
private javax.swing.JButton btnSubmit;
|
||||
private javax.swing.JButton btnAddLand;
|
||||
}
|
||||
|
||||
class DeckFilter extends FileFilter {
|
||||
|
|
|
|||
|
|
@ -57,10 +57,10 @@ public class MWSDeckImporter extends DeckImporterImpl {
|
|||
ExpansionSet set = Sets.findSet(setCode);
|
||||
String cardName;
|
||||
if (set != null) {
|
||||
cardName = set.findCard(lineName);
|
||||
cardName = set.findCard(lineName).getClass().getCanonicalName();
|
||||
}
|
||||
else {
|
||||
cardName = Sets.findCard(lineName);
|
||||
cardName = Sets.findCard(lineName).getClass().getCanonicalName();
|
||||
}
|
||||
if (cardName == null)
|
||||
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public class TxtDeckImporter extends DeckImporterImpl {
|
|||
String lineName = line.substring(delim).trim();
|
||||
try {
|
||||
int num = Integer.parseInt(lineNum);
|
||||
String cardName = Sets.findCard(lineName);
|
||||
String cardName = Sets.findCard(lineName).getClass().getCanonicalName();
|
||||
if (cardName == null)
|
||||
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||
else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue