mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
spjspj - Allow appending from the clipboard in deck editor
This commit is contained in:
parent
9227c4615f
commit
7a8055172d
2 changed files with 54 additions and 1 deletions
|
@ -71,6 +71,7 @@ import mage.remote.Session;
|
|||
import mage.view.CardView;
|
||||
import mage.view.SimpleCardView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -693,7 +694,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
btnImport.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
Object[] options = {"File", "Clipboard"};
|
||||
Object[] options = {"File", "Clipboard", "Append from Clipboard"};
|
||||
|
||||
int n = JOptionPane.showOptionDialog(MageFrame.getDesktop(),
|
||||
"Where would you like to import from?",
|
||||
|
@ -713,6 +714,8 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
break;
|
||||
case 1:
|
||||
btnImportFromClipboardActionPerformed(evt);
|
||||
case 2:
|
||||
btnImportFromClipboardActionWAppendPerformed(evt);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -865,6 +868,33 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param evt ActionEvent
|
||||
*/
|
||||
private void btnImportFromClipboardActionWAppendPerformed(ActionEvent evt) {
|
||||
final DeckImportFromClipboardDialog dialog = new DeckImportFromClipboardDialog();
|
||||
dialog.pack();
|
||||
dialog.setVisible(true);
|
||||
|
||||
dialog.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosed(WindowEvent e) {
|
||||
Deck deckToAppend = null;
|
||||
try {
|
||||
deckToAppend = Deck.load(DeckImporterUtil.importDeck(dialog.getTmpPath()), true, true);
|
||||
if (deckToAppend != null) {
|
||||
deck = Deck.append(deckToAppend, deck);
|
||||
refreshDeck();
|
||||
}
|
||||
} catch (GameException e1) {
|
||||
JOptionPane.showMessageDialog(MageFrame.getDesktop(), e1.getMessage(), "Error loading deck", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadActionPerformed
|
||||
//fcSelectDeck.setCurrentDirectory(new File());
|
||||
String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", "");
|
||||
|
|
|
@ -57,6 +57,29 @@ public class Deck implements Serializable {
|
|||
return Deck.load(deckCardLists, ignoreErrors, true);
|
||||
}
|
||||
|
||||
public static Deck append(Deck deckToAppend, Deck currentDeck) throws GameException {
|
||||
List<String> deckCardNames = new ArrayList<>();
|
||||
|
||||
for (Card card : deckToAppend.getCards()) {
|
||||
if (card != null) {
|
||||
currentDeck.cards.add(card);
|
||||
deckCardNames.add(card.getName());
|
||||
}
|
||||
}
|
||||
List<String> sbCardNames = new ArrayList<>();
|
||||
for (Card card : deckToAppend.getSideboard()) {
|
||||
if (card != null) {
|
||||
currentDeck.sideboard.add(card);
|
||||
deckCardNames.add(card.getName());
|
||||
}
|
||||
}
|
||||
Collections.sort(deckCardNames);
|
||||
Collections.sort(sbCardNames);
|
||||
String deckString = deckCardNames.toString() + sbCardNames.toString();
|
||||
currentDeck.setDeckHashCode(DeckUtil.fixedHash(deckString));
|
||||
return currentDeck;
|
||||
}
|
||||
|
||||
public static Deck load(DeckCardLists deckCardLists, boolean ignoreErrors, boolean mockCards) throws GameException {
|
||||
Deck deck = new Deck();
|
||||
deck.setName(deckCardLists.getName());
|
||||
|
|
Loading…
Reference in a new issue