diff --git a/src/main/java/forge/control/home/ControlConstructed.java b/src/main/java/forge/control/home/ControlConstructed.java index eab75ea71f8..456f650939a 100644 --- a/src/main/java/forge/control/home/ControlConstructed.java +++ b/src/main/java/forge/control/home/ControlConstructed.java @@ -1,11 +1,16 @@ package forge.control.home; +import java.awt.Toolkit; +import java.awt.datatransfer.StringSelection; +import java.awt.event.ActionEvent; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; +import java.util.Map.Entry; import javax.swing.JList; import javax.swing.JOptionPane; @@ -22,6 +27,7 @@ import forge.deck.generate.Generate3ColorDeck; import forge.deck.generate.Generate5ColorDeck; import forge.deck.generate.GenerateThemeDeck; import forge.game.GameType; +import forge.item.CardPrinted; import forge.view.GuiTopLevel; import forge.view.home.ViewConstructed; @@ -463,4 +469,90 @@ public class ControlConstructed { return deckNames.toArray(); } + + /** + * View deck list. + */ + public void viewDeckList(final String player) { + new DeckListAction(player).actionPerformed(null); + } + + /** + * Receives click and programmatic requests for viewing card in a player's deck + * + */ + private class DeckListAction { + public DeckListAction(final String playerIn) { + player = playerIn; + } + + private static final long serialVersionUID = 9874492387239847L; + private String player; + + public void actionPerformed(final ActionEvent e) { + if (player.equals("Human") && + (currentHumanSelection.getName().equals("lstColorsHuman") || + currentHumanSelection.getName().equals("lstThemesHuman"))) { + return; + } + if (player.equals("Computer") && + (currentAISelection.getName().equals("lstColorsAI") || + currentAISelection.getName().equals("lstThemesAI"))) { + return; + } + + Deck targetDeck = (player.equals("Human")) ? + AllZone.getDeckManager().getDeck(oa2sa(currentHumanSelection.getSelectedValues())[0]) : + AllZone.getDeckManager().getDeck(oa2sa(currentAISelection.getSelectedValues())[0]); + + final HashMap deckMap = new HashMap(); + + for (final Entry s : targetDeck.getMain()) { + deckMap.put(s.getKey().getName(), s.getValue()); + } + + final String nl = System.getProperty("line.separator"); + final StringBuilder deckList = new StringBuilder(); + String dName = targetDeck.getName(); + + if (dName == null) { + dName = ""; + } else { + deckList.append(dName + nl); + } + + final ArrayList dmKeys = new ArrayList(); + for (final String s : deckMap.keySet()) { + dmKeys.add(s); + } + + Collections.sort(dmKeys); + + for (final String s : dmKeys) { + deckList.append(deckMap.get(s) + " x " + s + nl); + } + + int rcMsg = -1138; + String ttl = player + "'s Decklist"; + if (!dName.equals("")) { + ttl += " - " + dName; + } + + final StringBuilder msg = new StringBuilder(); + if (deckMap.keySet().size() <= 32) { + msg.append(deckList.toString() + nl); + } else { + msg.append("Decklist too long for dialog." + nl + nl); + } + + msg.append("Copy Decklist to Clipboard?"); + + rcMsg = JOptionPane.showConfirmDialog(null, msg, ttl, JOptionPane.OK_CANCEL_OPTION); + + if (rcMsg == JOptionPane.OK_OPTION) { + final StringSelection ss = new StringSelection(deckList.toString()); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null); + } + } + } // End DeckListAction } diff --git a/src/main/java/forge/control/match/ControlDock.java b/src/main/java/forge/control/match/ControlDock.java index 9e53df433f1..b86d855d235 100644 --- a/src/main/java/forge/control/match/ControlDock.java +++ b/src/main/java/forge/control/match/ControlDock.java @@ -134,15 +134,14 @@ public class ControlDock { */ public void endTurn() { // Big thanks to you, Gameplay Guru, since I was too lazy to figure this - // out - // before release. Doublestrike 24-11-11 + // out before release. Doublestrike 24-11-11 System.err.println("forge.control.match > ControlDock > endTurn()"); System.out.println("Should skip to the end of turn, or entire turn."); System.err.println("If some gameplay guru could implement this, that would be great..."); } /** - * End turn. + * View deck list. */ public void viewDeckList() { new DeckListAction(NewConstants.Lang.GuiDisplay.HUMAN_DECKLIST).actionPerformed(null); diff --git a/src/main/java/forge/view/home/ViewConstructed.java b/src/main/java/forge/view/home/ViewConstructed.java index 9b6c6740df1..b4edb84939d 100644 --- a/src/main/java/forge/view/home/ViewConstructed.java +++ b/src/main/java/forge/view/home/ViewConstructed.java @@ -36,6 +36,7 @@ public class ViewConstructed extends JPanel { private int counter; private JList lstColorsHuman, lstColorsAI, lstThemesHuman, lstThemesAI, lstDecksHuman, lstDecksAI; + private JButton viewHumanDeckList, viewAIDeckList; private ControlConstructed control; /** @@ -72,6 +73,18 @@ public class ViewConstructed extends JPanel { this.add(new JScrollPane(lstThemesHuman), constraints); this.add(new OrPanel(), "w 5%!, h 30%!"); this.add(new JScrollPane(lstDecksHuman), constraints + ", wrap"); + + viewHumanDeckList = new JButton(); + viewHumanDeckList.setAction(new AbstractAction() { + public void actionPerformed(ActionEvent arg0) { + ViewConstructed.this.control.viewDeckList("Human"); + } + }); + viewHumanDeckList.setFont(skin.getFont1().deriveFont(Font.PLAIN, 13)); + viewHumanDeckList.setForeground(Color.BLACK); + viewHumanDeckList.setText("View Human Deck List"); + viewHumanDeckList.setVerticalTextPosition(SwingConstants.CENTER); + this.add(viewHumanDeckList, "w 20%!, h 3%!, gap 2% 2% 2% 0, wrap, span 5 1"); // AI deck options area JLabel lblAI = new JLabel("Choose a deck for the AI player:"); @@ -84,7 +97,18 @@ public class ViewConstructed extends JPanel { this.add(new JScrollPane(lstThemesAI), constraints); this.add(new OrPanel(), "w 5%!, h 30%!"); this.add(new JScrollPane(lstDecksAI), constraints + ", wrap"); - + + viewAIDeckList = new JButton(); + viewAIDeckList.setAction(new AbstractAction() { + public void actionPerformed(ActionEvent arg0) { + ViewConstructed.this.control.viewDeckList("Computer"); + } + }); + viewAIDeckList.setFont(skin.getFont1().deriveFont(Font.PLAIN, 13)); + viewAIDeckList.setForeground(Color.BLACK); + viewAIDeckList.setText("View AI Deck List"); + this.add(viewAIDeckList, "w 20%!, h 3%!, gap 5% 5% 2% 0, wrap, span 5 1"); + // List box properties this.lstColorsHuman.setName("lstColorsHuman"); this.lstThemesHuman.setName("lstThemesHuman"); diff --git a/src/main/java/forge/view/match/ViewDock.java b/src/main/java/forge/view/match/ViewDock.java index 6f181fd7a87..bc07bca3191 100644 --- a/src/main/java/forge/view/match/ViewDock.java +++ b/src/main/java/forge/view/match/ViewDock.java @@ -135,7 +135,6 @@ public class ViewDock extends FRoundedPanel { } }); - //TODO - get an icon for this final JLabel btnViewDeckList = new DockButton(skin.getIcon("dock.decklist"), "View Deck List"); btnViewDeckList.addMouseListener(new MouseAdapter() { @Override