mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Add a View DeckList option to the Home screen. A couple points:
1) It only works for pre-constructed decks (currently) 2) Probably can be expanded to Theme decks by generating a sample to display 3) TODO - button should be enabled/disabled as appropriate 4) currently doesn't obey FSkin
This commit is contained in:
@@ -1,11 +1,16 @@
|
|||||||
package forge.control.home;
|
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.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
@@ -22,6 +27,7 @@ import forge.deck.generate.Generate3ColorDeck;
|
|||||||
import forge.deck.generate.Generate5ColorDeck;
|
import forge.deck.generate.Generate5ColorDeck;
|
||||||
import forge.deck.generate.GenerateThemeDeck;
|
import forge.deck.generate.GenerateThemeDeck;
|
||||||
import forge.game.GameType;
|
import forge.game.GameType;
|
||||||
|
import forge.item.CardPrinted;
|
||||||
import forge.view.GuiTopLevel;
|
import forge.view.GuiTopLevel;
|
||||||
import forge.view.home.ViewConstructed;
|
import forge.view.home.ViewConstructed;
|
||||||
|
|
||||||
@@ -463,4 +469,90 @@ public class ControlConstructed {
|
|||||||
|
|
||||||
return deckNames.toArray();
|
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<String, Integer> deckMap = new HashMap<String, Integer>();
|
||||||
|
|
||||||
|
for (final Entry<CardPrinted, Integer> 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<String> dmKeys = new ArrayList<String>();
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,15 +134,14 @@ public class ControlDock {
|
|||||||
*/
|
*/
|
||||||
public void endTurn() {
|
public void endTurn() {
|
||||||
// Big thanks to you, Gameplay Guru, since I was too lazy to figure this
|
// Big thanks to you, Gameplay Guru, since I was too lazy to figure this
|
||||||
// out
|
// out before release. Doublestrike 24-11-11
|
||||||
// before release. Doublestrike 24-11-11
|
|
||||||
System.err.println("forge.control.match > ControlDock > endTurn()");
|
System.err.println("forge.control.match > ControlDock > endTurn()");
|
||||||
System.out.println("Should skip to the end of turn, or entire turn.");
|
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...");
|
System.err.println("If some gameplay guru could implement this, that would be great...");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* End turn.
|
* View deck list.
|
||||||
*/
|
*/
|
||||||
public void viewDeckList() {
|
public void viewDeckList() {
|
||||||
new DeckListAction(NewConstants.Lang.GuiDisplay.HUMAN_DECKLIST).actionPerformed(null);
|
new DeckListAction(NewConstants.Lang.GuiDisplay.HUMAN_DECKLIST).actionPerformed(null);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ public class ViewConstructed extends JPanel {
|
|||||||
private int counter;
|
private int counter;
|
||||||
private JList lstColorsHuman, lstColorsAI, lstThemesHuman,
|
private JList lstColorsHuman, lstColorsAI, lstThemesHuman,
|
||||||
lstThemesAI, lstDecksHuman, lstDecksAI;
|
lstThemesAI, lstDecksHuman, lstDecksAI;
|
||||||
|
private JButton viewHumanDeckList, viewAIDeckList;
|
||||||
private ControlConstructed control;
|
private ControlConstructed control;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,6 +74,18 @@ public class ViewConstructed extends JPanel {
|
|||||||
this.add(new OrPanel(), "w 5%!, h 30%!");
|
this.add(new OrPanel(), "w 5%!, h 30%!");
|
||||||
this.add(new JScrollPane(lstDecksHuman), constraints + ", wrap");
|
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
|
// AI deck options area
|
||||||
JLabel lblAI = new JLabel("Choose a deck for the AI player:");
|
JLabel lblAI = new JLabel("Choose a deck for the AI player:");
|
||||||
lblAI.setFont(skin.getFont1().deriveFont(Font.BOLD, 16));
|
lblAI.setFont(skin.getFont1().deriveFont(Font.BOLD, 16));
|
||||||
@@ -85,6 +98,17 @@ public class ViewConstructed extends JPanel {
|
|||||||
this.add(new OrPanel(), "w 5%!, h 30%!");
|
this.add(new OrPanel(), "w 5%!, h 30%!");
|
||||||
this.add(new JScrollPane(lstDecksAI), constraints + ", wrap");
|
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
|
// List box properties
|
||||||
this.lstColorsHuman.setName("lstColorsHuman");
|
this.lstColorsHuman.setName("lstColorsHuman");
|
||||||
this.lstThemesHuman.setName("lstThemesHuman");
|
this.lstThemesHuman.setName("lstThemesHuman");
|
||||||
|
|||||||
@@ -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");
|
final JLabel btnViewDeckList = new DockButton(skin.getIcon("dock.decklist"), "View Deck List");
|
||||||
btnViewDeckList.addMouseListener(new MouseAdapter() {
|
btnViewDeckList.addMouseListener(new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user