merge UI updates
commit
438a81c725
|
@ -45,7 +45,7 @@ public class CardStatistics {
|
|||
|
||||
private final Collection<MagicCardDefinition> cards;
|
||||
|
||||
private int totalCards;
|
||||
public int totalCards;
|
||||
public final int[] totalTypes=new int[NR_OF_TYPES];
|
||||
|
||||
private final int[] totalRarity=new int[MagicRarity.length];
|
||||
|
|
|
@ -10,6 +10,7 @@ import magic.model.MagicRandom;
|
|||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
@ -49,7 +50,8 @@ public class DeckUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean saveDeck(final String filename,final MagicPlayerDefinition player) {
|
||||
public static boolean saveDeck(final String filename, final MagicDeck deck) {
|
||||
|
||||
final List<SortedMap<String,Integer>> cardMaps=new ArrayList<SortedMap<String,Integer>>();
|
||||
boolean isSuccessful = true;
|
||||
|
||||
|
@ -57,7 +59,7 @@ public class DeckUtils {
|
|||
cardMaps.add(new TreeMap<String, Integer>());
|
||||
}
|
||||
|
||||
for (final MagicCardDefinition cardDefinition : player.getDeck()) {
|
||||
for (final MagicCardDefinition cardDefinition : deck) {
|
||||
final String name=cardDefinition.getName();
|
||||
final int index;
|
||||
if (cardDefinition.isLand()) {
|
||||
|
@ -87,7 +89,7 @@ public class DeckUtils {
|
|||
writer.newLine();
|
||||
}
|
||||
}
|
||||
final String description = player.getDeck().getDescription();
|
||||
final String description = deck.getDescription();
|
||||
if (description != null) {
|
||||
writer.write(">" + description);
|
||||
}
|
||||
|
@ -101,18 +103,85 @@ public class DeckUtils {
|
|||
}
|
||||
|
||||
return isSuccessful;
|
||||
|
||||
}
|
||||
|
||||
public static void loadDeck(final String filename,final MagicPlayerDefinition player) {
|
||||
private static String getDeckFileContent(final String filename) {
|
||||
String content = "";
|
||||
try { //load deck
|
||||
try {
|
||||
content = FileIO.toStr(new File(filename));
|
||||
} catch (final IOException ex) {
|
||||
System.err.println("ERROR! Unable to load " + filename);
|
||||
System.err.println(ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
private static MagicDeck parseDeckFileContent(final String content) {
|
||||
|
||||
final Scanner sc = new Scanner(content);
|
||||
final int[] colorCount = new int[MagicColor.NR_COLORS];
|
||||
final MagicDeck deck = new MagicDeck();
|
||||
final MagicDeck unsupported = new MagicDeck();
|
||||
|
||||
while (sc.hasNextLine()) {
|
||||
final String line = sc.nextLine().trim();
|
||||
if (!line.isEmpty()&&!line.startsWith("#")) {
|
||||
if (line.startsWith(">")) {
|
||||
deck.setDescription(line.substring(1));
|
||||
} else {
|
||||
final int index = line.indexOf(' ');
|
||||
final int amount = Integer.parseInt(line.substring(0,index));
|
||||
final String name=line.substring(index+1).trim();
|
||||
final MagicCardDefinition cardDefinition = CardDefinitions.getCard(name);
|
||||
for (int count=amount;count>0;count--) {
|
||||
final int colorFlags=cardDefinition.getColorFlags();
|
||||
for (final MagicColor color : MagicColor.values()) {
|
||||
if (color.hasColor(colorFlags)) {
|
||||
colorCount[color.ordinal()]++;
|
||||
}
|
||||
}
|
||||
if (cardDefinition.isValid()) {
|
||||
deck.add(cardDefinition);
|
||||
} else {
|
||||
unsupported.add(cardDefinition);
|
||||
break; // multiple copies of unsupported card -> ignore other copies
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sc.close();
|
||||
|
||||
showUnsupportedCards(unsupported);
|
||||
|
||||
return deck;
|
||||
}
|
||||
|
||||
public static MagicDeck loadDeckFromFile(final String filename) {
|
||||
MagicDeck deck = null;
|
||||
final String content = getDeckFileContent(filename);
|
||||
if (content != "") {
|
||||
try {
|
||||
deck = parseDeckFileContent(content);
|
||||
deck.setName(new File(filename).getName());
|
||||
} catch (Exception e) {
|
||||
System.err.println("Invalid deck file (" + filename + ") - " + e.toString());
|
||||
JOptionPane.showMessageDialog(
|
||||
MagicMain.rootFrame,
|
||||
"Failed to parse this deck file.\n\n" + e.toString(),
|
||||
"Invalid Deck File",
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
}
|
||||
return deck;
|
||||
}
|
||||
|
||||
public static void loadDeck(final String filename,final MagicPlayerDefinition player) {
|
||||
|
||||
final String content = getDeckFileContent(filename);
|
||||
if (content == "") { return; }
|
||||
|
||||
final Scanner sc = new Scanner(content);
|
||||
final int[] colorCount = new int[MagicColor.NR_COLORS];
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package magic.ui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
|
@ -8,8 +9,8 @@ import javax.swing.JFileChooser;
|
|||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import magic.MagicMain;
|
||||
import magic.data.DeckUtils;
|
||||
import magic.model.MagicCubeDefinition;
|
||||
import magic.model.MagicDeck;
|
||||
import magic.model.MagicDeckConstructionRule;
|
||||
import magic.model.MagicPlayerDefinition;
|
||||
|
@ -24,13 +25,22 @@ public class DeckEditorScreen
|
|||
private static ExplorerPanel content;
|
||||
private final MagicFrame frame;
|
||||
|
||||
public DeckEditorScreen(final MagicFrame frame0, final int mode, final MagicPlayerDefinition player, final MagicCubeDefinition cube) {
|
||||
super(getScreenContent(frame0, mode, player, cube), frame0);
|
||||
// CTR
|
||||
public DeckEditorScreen(final MagicFrame frame0, final int mode) {
|
||||
super(getScreenContent(frame0, mode), frame0);
|
||||
this.frame = frame0;
|
||||
}
|
||||
public DeckEditorScreen(final MagicFrame frame0, final int mode, final MagicPlayerDefinition player) {
|
||||
super(getScreenContent(frame0, mode, player), frame0);
|
||||
this.frame = frame0;
|
||||
}
|
||||
|
||||
private static JPanel getScreenContent(MagicFrame frame, final int mode, final MagicPlayerDefinition player, final MagicCubeDefinition cube) {
|
||||
content = new ExplorerPanel(frame, mode, player, cube);
|
||||
private static JPanel getScreenContent(MagicFrame frame, final int mode, final MagicPlayerDefinition player) {
|
||||
content = new ExplorerPanel(frame, mode, player);
|
||||
return content;
|
||||
}
|
||||
private static JPanel getScreenContent(MagicFrame frame, final int mode) {
|
||||
content = new ExplorerPanel(frame, mode, true);
|
||||
return content;
|
||||
}
|
||||
|
||||
|
@ -60,7 +70,32 @@ public class DeckEditorScreen
|
|||
*/
|
||||
@Override
|
||||
public List<MenuButton> getMiddleActions() {
|
||||
return null;
|
||||
final List<MenuButton> buttons = new ArrayList<MenuButton>();
|
||||
buttons.add(new MenuButton("Load deck", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
loadDeck();
|
||||
}
|
||||
}, "Load deck from file"));
|
||||
if (content.getPlayer() == null) {
|
||||
buttons.add(new MenuButton("Save", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
saveDeck();
|
||||
}
|
||||
}, "Save deck to file"));
|
||||
buttons.add(new MenuButton("Clear", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (JOptionPane.showConfirmDialog(
|
||||
MagicMain.rootFrame,
|
||||
"Remove all cards from the deck?") == JOptionPane.YES_OPTION) {
|
||||
createNewEmptyDeck();
|
||||
}
|
||||
}
|
||||
}, "Clear all cards from deck"));
|
||||
}
|
||||
return buttons;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -68,7 +103,11 @@ public class DeckEditorScreen
|
|||
*/
|
||||
@Override
|
||||
public String getScreenCaption() {
|
||||
return "Deck Editor : " + content.getPlayer().getName();
|
||||
if (content.getPlayer() != null) {
|
||||
return "Deck Editor : " + content.getPlayer().getName();
|
||||
} else {
|
||||
return "Deck Editor";
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -80,14 +119,16 @@ public class DeckEditorScreen
|
|||
}
|
||||
|
||||
public void createNewEmptyDeck() {
|
||||
final MagicPlayerDefinition player=content.getPlayer();
|
||||
player.getDeck().clear();
|
||||
//duelPanel.updateDecksAfterEdit();
|
||||
content.updateDeck();
|
||||
final MagicPlayerDefinition player = content.getPlayer();
|
||||
if (player != null) {
|
||||
player.getDeck().clear();
|
||||
content.setDeck(player.getDeck());
|
||||
} else {
|
||||
content.setDeck(new MagicDeck());
|
||||
}
|
||||
}
|
||||
|
||||
public void loadDeck() {
|
||||
final MagicPlayerDefinition player = content.getPlayer();
|
||||
final JFileChooser fileChooser=new JFileChooser(DeckUtils.getDeckFolder());
|
||||
fileChooser.setDialogTitle("Load deck");
|
||||
fileChooser.setFileFilter(DeckUtils.DECK_FILEFILTER);
|
||||
|
@ -97,16 +138,17 @@ public class DeckEditorScreen
|
|||
final int action=fileChooser.showOpenDialog(this);
|
||||
if (action==JFileChooser.APPROVE_OPTION) {
|
||||
final String filename=fileChooser.getSelectedFile().getAbsolutePath();
|
||||
DeckUtils.loadDeck(filename,player);
|
||||
content.updateDeck();
|
||||
final MagicPlayerDefinition player = content.getPlayer();
|
||||
if (player != null) {
|
||||
DeckUtils.loadDeck(filename, player);
|
||||
content.setDeck(player.getDeck());
|
||||
} else {
|
||||
content.setDeck(DeckUtils.loadDeckFromFile(filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void saveDeck() {
|
||||
final MagicPlayerDefinition player = content.getPlayer();
|
||||
final JFileChooser fileChooser = new JFileChooser(DeckUtils.getDeckFolder());
|
||||
fileChooser.setDialogTitle("Save deck");
|
||||
fileChooser.setFileFilter(DeckUtils.DECK_FILEFILTER);
|
||||
|
@ -117,13 +159,13 @@ public class DeckEditorScreen
|
|||
if (!filename.endsWith(DeckUtils.DECK_EXTENSION)) {
|
||||
filename += DeckUtils.DECK_EXTENSION;
|
||||
}
|
||||
if (DeckUtils.saveDeck(filename, player)) {
|
||||
if (DeckUtils.saveDeck(filename, content.getDeck())) {
|
||||
String shortFilename = fileChooser.getSelectedFile().getName();
|
||||
if (shortFilename.indexOf(".dec") == -1) {
|
||||
shortFilename += ".dec";
|
||||
}
|
||||
player.getDeck().setName(shortFilename);
|
||||
content.updateDeck();
|
||||
content.getDeck().setName(shortFilename);
|
||||
content.setDeck(content.getDeck());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +177,11 @@ public class DeckEditorScreen
|
|||
*/
|
||||
@Override
|
||||
public boolean isScreenReadyToClose(final MagScreen nextScreen) {
|
||||
return validateDeck(content.getPlayer().getDeck(), nextScreen);
|
||||
if (content.getPlayer() != null) {
|
||||
return validateDeck(content.getPlayer().getDeck(), nextScreen);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -56,7 +56,7 @@ public class DeckEditorScreenOptions extends TexturedPanel implements IMenuOverl
|
|||
|
||||
final MenuPanel menu = new MenuPanel("Deck Options");
|
||||
|
||||
menu.addMenuItem("New empty deck", new AbstractAction() {
|
||||
menu.addMenuItem("Clear deck", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
screen.createNewEmptyDeck();
|
||||
|
|
|
@ -8,8 +8,6 @@ import javax.swing.AbstractAction;
|
|||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import magic.data.CubeDefinitions;
|
||||
import magic.model.MagicCubeDefinition;
|
||||
import magic.model.MagicDeck;
|
||||
import magic.model.MagicDuel;
|
||||
import magic.model.MagicPlayerDefinition;
|
||||
|
@ -112,8 +110,7 @@ public class DuelDecksScreen
|
|||
buttons.add(new MenuButton("Deck Editor", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final MagicCubeDefinition cubeDefinition = CubeDefinitions.getCubeDefinition(screenContent.getDuel().getConfiguration().getCube());
|
||||
frame.showDeckEditor(screenContent.getSelectedPlayer(), cubeDefinition);
|
||||
frame.showDeckEditor(screenContent.getSelectedPlayer());
|
||||
}
|
||||
}));
|
||||
buttons.add(new MenuButton("Swap Decks", new AbstractAction() {
|
||||
|
|
|
@ -121,7 +121,7 @@ public class DuelPanel extends TexturedPanel {
|
|||
|
||||
// deck statistics
|
||||
statsViewers[i] = new DeckStatisticsViewer();
|
||||
statsViewers[i].setPlayer(player);
|
||||
statsViewers[i].setDeck(player.getDeck());
|
||||
statsViewers[i].setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
statsViewers[i].setMaximumSize(DeckStatisticsViewer.PREFERRED_SIZE);
|
||||
|
||||
|
@ -265,7 +265,7 @@ public class DuelPanel extends TexturedPanel {
|
|||
for (int i = 0; i < statsViewers.length; i++) {
|
||||
cardTables[i].setCards(duel.getPlayers()[i].getDeck());
|
||||
cardTables[i].setTitle(generateTitle(duel.getPlayers()[i].getDeck()));
|
||||
statsViewers[i].setPlayer(duel.getPlayers()[i]);
|
||||
statsViewers[i].setDeck(duel.getPlayers()[i].getDeck());
|
||||
deckDescriptionViewers[i].setPlayer(duel.getPlayers()[i]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@ package magic.ui;
|
|||
import magic.data.CardDefinitions;
|
||||
import magic.model.MagicCardDefinition;
|
||||
import magic.model.MagicColor;
|
||||
import magic.model.MagicCubeDefinition;
|
||||
import magic.model.MagicPlayerProfile;
|
||||
import magic.model.MagicRarity;
|
||||
import magic.model.MagicSubType;
|
||||
import magic.model.MagicType;
|
||||
|
@ -73,23 +71,14 @@ public class ExplorerFilterPanel extends TexturedPanel implements ActionListener
|
|||
private final JRadioButton[] rarityFilterChoices;
|
||||
private final JTextField nameTextField;
|
||||
private final JButton resetButton;
|
||||
private final int mode;
|
||||
private final MagicPlayerProfile profile;
|
||||
private final MagicCubeDefinition cube;
|
||||
|
||||
private boolean disableUpdate; // so when we change several filters, it doesn't update until the end
|
||||
|
||||
public ExplorerFilterPanel(
|
||||
final JFrame frame,
|
||||
final ExplorerPanel explorerPanel,
|
||||
final int mode,
|
||||
final MagicPlayerProfile profile,
|
||||
final MagicCubeDefinition cube) {
|
||||
final int mode) {
|
||||
this.frame = frame;
|
||||
this.explorerPanel=explorerPanel;
|
||||
this.mode=mode;
|
||||
this.profile=profile;
|
||||
this.cube=cube;
|
||||
|
||||
disableUpdate = false;
|
||||
|
||||
|
@ -283,27 +272,6 @@ public class ExplorerFilterPanel extends TexturedPanel implements ActionListener
|
|||
return false;
|
||||
}
|
||||
|
||||
/* if (cube!=null&&!cube.containsCard(cardDefinition)) {
|
||||
return false;
|
||||
} */
|
||||
|
||||
/* switch (mode) {
|
||||
case ExplorerPanel.LAND:
|
||||
if (!cardDefinition.isLand()) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case ExplorerPanel.SPELL:
|
||||
if (cardDefinition.isLand()) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
} */
|
||||
|
||||
/* if (profile!=null&&!cardDefinition.isBasic()&&!cardDefinition.isPlayable(profile)) {
|
||||
return false;
|
||||
} */
|
||||
|
||||
// search text in name, abilities, type, text, etc.
|
||||
final String filterString = nameTextField.getText();
|
||||
if (filterString.length() > 0) {
|
||||
|
|
|
@ -2,10 +2,8 @@ package magic.ui;
|
|||
|
||||
import magic.data.CardImagesProvider;
|
||||
import magic.model.MagicCardDefinition;
|
||||
import magic.model.MagicCubeDefinition;
|
||||
import magic.model.MagicDeck;
|
||||
import magic.model.MagicPlayerDefinition;
|
||||
import magic.model.MagicPlayerProfile;
|
||||
import magic.model.MagicRandom;
|
||||
import magic.ui.viewer.CardViewer;
|
||||
import magic.ui.viewer.DeckStatisticsViewer;
|
||||
|
@ -46,30 +44,47 @@ public class ExplorerPanel extends TexturedPanel implements ActionListener {
|
|||
|
||||
protected final MagicFrame frame;
|
||||
private final MagicPlayerDefinition player;
|
||||
|
||||
private final CardTable cardPoolTable;
|
||||
private final CardTable deckTable;
|
||||
private CardTable deckTable;
|
||||
private final CardViewer cardViewer;
|
||||
private final DeckStatisticsViewer statsViewer;
|
||||
private final ExplorerFilterPanel filterPanel;
|
||||
private final JButton addButton;
|
||||
private final JButton removeButton;
|
||||
|
||||
private List<MagicCardDefinition> cardPoolDefs;
|
||||
private MagicDeck deckDefs;
|
||||
private final boolean isDeckEditor;
|
||||
private MagicDeck deck;
|
||||
|
||||
public ExplorerPanel(final MagicFrame frame) {
|
||||
this(frame, ExplorerPanel.ALL, null, null);
|
||||
this(frame, ExplorerPanel.ALL, null, false);
|
||||
}
|
||||
public ExplorerPanel(final MagicFrame frame, final int mode, final boolean isDeckEditor) {
|
||||
this(frame, mode, null, isDeckEditor);
|
||||
}
|
||||
public ExplorerPanel(final MagicFrame frame, final int mode, final MagicPlayerDefinition player) {
|
||||
this(frame, mode, player, (player != null));
|
||||
}
|
||||
|
||||
public ExplorerPanel(
|
||||
private ExplorerPanel(
|
||||
final MagicFrame frame,
|
||||
final int mode,
|
||||
final MagicPlayerDefinition player,
|
||||
final MagicCubeDefinition cube) {
|
||||
final boolean isDeckEditor0) {
|
||||
|
||||
this.frame=frame;
|
||||
this.player=player;
|
||||
this.isDeckEditor = isDeckEditor0;
|
||||
|
||||
if (isDeckEditor0) {
|
||||
if (player != null) {
|
||||
this.deck = player.getDeck();
|
||||
} else {
|
||||
this.deck = new MagicDeck();
|
||||
}
|
||||
} else {
|
||||
this.deck = null;
|
||||
}
|
||||
|
||||
setBackground(FontsAndBorders.MAGSCREEN_FADE_COLOR);
|
||||
|
||||
|
@ -138,12 +153,7 @@ public class ExplorerPanel extends TexturedPanel implements ActionListener {
|
|||
leftScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
add(leftScrollPane);
|
||||
|
||||
// filters
|
||||
MagicPlayerProfile profile=null;
|
||||
if (isEditingDeck()) {
|
||||
profile=getPlayer().getProfile();
|
||||
}
|
||||
filterPanel = new ExplorerFilterPanel(frame, this, mode, profile, cube);
|
||||
filterPanel = new ExplorerFilterPanel(frame, this, mode);
|
||||
|
||||
final JScrollPane filterScrollPane = new JScrollPane(filterPanel);
|
||||
filterScrollPane.setBorder(FontsAndBorders.NO_BORDER);
|
||||
|
@ -162,7 +172,7 @@ public class ExplorerPanel extends TexturedPanel implements ActionListener {
|
|||
cardPoolTable = new CardTable(cardPoolDefs, cardViewer, generatePoolTitle(), false);
|
||||
cardPoolTable.addMouseListener(new CardPoolMouseListener());
|
||||
|
||||
deckDefs = getPlayer().getDeck();
|
||||
deckDefs = this.deck;
|
||||
deckTable = new CardTable(deckDefs, cardViewer, generateDeckTitle(deckDefs), true);
|
||||
deckTable.addMouseListener(new DeckMouseListener());
|
||||
|
||||
|
@ -176,7 +186,8 @@ public class ExplorerPanel extends TexturedPanel implements ActionListener {
|
|||
cardsPanel = cardsSplitPane;
|
||||
|
||||
// update deck stats
|
||||
statsViewer.setPlayer(getPlayer());
|
||||
statsViewer.setDeck(this.deck);
|
||||
|
||||
} else {
|
||||
// no deck
|
||||
cardPoolTable = new CardTable(cardPoolDefs, cardViewer);
|
||||
|
@ -233,6 +244,7 @@ public class ExplorerPanel extends TexturedPanel implements ActionListener {
|
|||
final int index = MagicRandom.nextRNGInt(cardPoolDefs.size());
|
||||
cardViewer.setCard(cardPoolDefs.get(index),0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String generatePoolTitle() {
|
||||
|
@ -240,7 +252,7 @@ public class ExplorerPanel extends TexturedPanel implements ActionListener {
|
|||
}
|
||||
|
||||
private boolean isEditingDeck() {
|
||||
return player != null;
|
||||
return (player != null) || this.isDeckEditor;
|
||||
}
|
||||
|
||||
public MagicPlayerDefinition getPlayer() {
|
||||
|
@ -261,10 +273,10 @@ public class ExplorerPanel extends TexturedPanel implements ActionListener {
|
|||
|
||||
public void updateDeck() {
|
||||
if(isEditingDeck()) {
|
||||
deckDefs = getPlayer().getDeck();
|
||||
deckDefs = this.deck;
|
||||
deckTable.setTitle(generateDeckTitle(deckDefs));
|
||||
deckTable.setCards(deckDefs);
|
||||
statsViewer.setPlayer(getPlayer());
|
||||
statsViewer.setDeck(deckDefs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,7 +285,7 @@ public class ExplorerPanel extends TexturedPanel implements ActionListener {
|
|||
|
||||
if (deckCards.size() > 0) {
|
||||
for(final MagicCardDefinition card : deckCards) {
|
||||
getPlayer().getDeck().remove(card);
|
||||
this.deck.remove(card);
|
||||
}
|
||||
|
||||
updateDeck();
|
||||
|
@ -289,7 +301,7 @@ public class ExplorerPanel extends TexturedPanel implements ActionListener {
|
|||
|
||||
if (cardPoolCards.size() > 0) {
|
||||
for(final MagicCardDefinition card : cardPoolCards) {
|
||||
getPlayer().getDeck().add(card);
|
||||
this.deck.add(card);
|
||||
}
|
||||
|
||||
updateDeck();
|
||||
|
@ -339,7 +351,7 @@ public class ExplorerPanel extends TexturedPanel implements ActionListener {
|
|||
final List<MagicCardDefinition> deckCards = deckTable.getSelectedCards();
|
||||
if (deckCards.size() > 0) {
|
||||
for(final MagicCardDefinition card : deckCards) {
|
||||
getPlayer().getDeck().add(card);
|
||||
deck.add(card);
|
||||
}
|
||||
|
||||
updateDeck();
|
||||
|
@ -357,4 +369,20 @@ public class ExplorerPanel extends TexturedPanel implements ActionListener {
|
|||
}
|
||||
}
|
||||
|
||||
public void setDeck(final MagicDeck deck0) {
|
||||
if (deck0 != null) {
|
||||
this.deck = deck0;
|
||||
if(isEditingDeck()) {
|
||||
deckDefs = this.deck;
|
||||
deckTable.setTitle(generateDeckTitle(deckDefs));
|
||||
deckTable.setCards(deckDefs);
|
||||
statsViewer.setDeck(deckDefs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MagicDeck getDeck() {
|
||||
return this.deck;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import magic.data.DuelConfig;
|
|||
import magic.data.GeneralConfig;
|
||||
import magic.data.IconImages;
|
||||
import magic.data.OSXAdapter;
|
||||
import magic.model.MagicCubeDefinition;
|
||||
import magic.model.MagicDeck;
|
||||
import magic.model.MagicDeckConstructionRule;
|
||||
import magic.model.MagicDuel;
|
||||
|
@ -91,8 +90,11 @@ public class MagicFrame extends JFrame {
|
|||
//
|
||||
// The various (Mag)screens that can currently be displayed.
|
||||
//
|
||||
public void showDeckEditor(final MagicPlayerDefinition player, final MagicCubeDefinition cube) {
|
||||
activateMagScreen(new DeckEditorScreen(this, ExplorerPanel.ALL, player, cube));
|
||||
public void showDeckEditor() {
|
||||
activateMagScreen(new DeckEditorScreen(this, ExplorerPanel.ALL));
|
||||
}
|
||||
public void showDeckEditor(final MagicPlayerDefinition player) {
|
||||
activateMagScreen(new DeckEditorScreen(this, ExplorerPanel.ALL, player));
|
||||
}
|
||||
public void showCardExplorerScreen() {
|
||||
activateMagScreen(new CardExplorerScreen(this));
|
||||
|
|
|
@ -44,6 +44,12 @@ public class MainMenuScreen extends MagScreen {
|
|||
frame.showCardExplorerScreen();
|
||||
}
|
||||
});
|
||||
menuPanel.addMenuItem("Deck editor", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
frame.showDeckEditor();
|
||||
}
|
||||
});
|
||||
menuPanel.addMenuItem("Settings", new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
|
|
@ -2,17 +2,19 @@ package magic.ui.viewer;
|
|||
|
||||
import magic.data.CardStatistics;
|
||||
import magic.model.MagicColor;
|
||||
import magic.model.MagicDeck;
|
||||
import magic.model.MagicPlayerDefinition;
|
||||
import magic.model.MagicPlayerProfile;
|
||||
import magic.ui.theme.ThemeFactory;
|
||||
import magic.ui.widget.FontsAndBorders;
|
||||
import magic.ui.widget.TexturedPanel;
|
||||
import magic.ui.widget.TitleBar;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
|
@ -25,7 +27,7 @@ public class DeckStatisticsViewer extends TexturedPanel implements ChangeListene
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final Dimension PREFERRED_SIZE = new Dimension(300, 170);
|
||||
public static final Dimension PREFERRED_SIZE = new Dimension(300, 190);
|
||||
|
||||
private final TitleBar titleBar;
|
||||
private final JPanel topPanel;
|
||||
|
@ -53,7 +55,7 @@ public class DeckStatisticsViewer extends TexturedPanel implements ChangeListene
|
|||
mainPanel.setOpaque(false);
|
||||
add(mainPanel,BorderLayout.CENTER);
|
||||
|
||||
topPanel=new JPanel(new FlowLayout(FlowLayout.LEFT,10,5));
|
||||
topPanel=new JPanel();
|
||||
topPanel.setOpaque(false);
|
||||
mainPanel.add(topPanel,BorderLayout.NORTH);
|
||||
|
||||
|
@ -97,22 +99,29 @@ public class DeckStatisticsViewer extends TexturedPanel implements ChangeListene
|
|||
|
||||
private void refreshCardTypeTotals(final CardStatistics statistics) {
|
||||
topPanel.removeAll();
|
||||
topPanel.setLayout(new MigLayout("insets 2, gap 6 0, wrap 2, flowy, center"));
|
||||
for (int index = 0; index < CardStatistics.NR_OF_TYPES; index++) {
|
||||
final int total = statistics.totalTypes[index];
|
||||
final JLabel label = new JLabel(Integer.toString(total));
|
||||
label.setForeground(textColor);
|
||||
label.setIcon(CardStatistics.TYPE_ICONS.get(index));
|
||||
label.setToolTipText(CardStatistics.TYPE_NAMES.get(index));
|
||||
label.setIconTextGap(4);
|
||||
topPanel.add(label);
|
||||
// card count
|
||||
final JLabel totalLabel = new JLabel(Integer.toString(total));
|
||||
totalLabel.setIcon(CardStatistics.TYPE_ICONS.get(index));
|
||||
totalLabel.setToolTipText(CardStatistics.TYPE_NAMES.get(index));
|
||||
totalLabel.setIconTextGap(4);
|
||||
topPanel.add(totalLabel, "w 35!");
|
||||
// card percentage
|
||||
final int percentage = (int)Math.round(((double)total / statistics.totalCards) * 100);
|
||||
final JLabel percentLabel = new JLabel(Integer.toString(percentage) + "%");
|
||||
percentLabel.setFont(FontsAndBorders.FONT0);
|
||||
topPanel.add(percentLabel, "h 12!, center, top");
|
||||
}
|
||||
topPanel.revalidate();
|
||||
}
|
||||
|
||||
public void setPlayer(final MagicPlayerDefinition player) {
|
||||
titleBar.setText("Deck Statistics : "+player.getName());
|
||||
public void setDeck(final MagicDeck deck) {
|
||||
|
||||
final CardStatistics statistics = new CardStatistics(deck);
|
||||
titleBar.setText("Deck Statistics : " + statistics.totalCards + " cards");
|
||||
|
||||
final CardStatistics statistics=new CardStatistics(player.getDeck());
|
||||
refreshCardTypeTotals(statistics);
|
||||
|
||||
lines.clear();
|
||||
|
@ -123,17 +132,18 @@ public class DeckStatisticsViewer extends TexturedPanel implements ChangeListene
|
|||
allLabel.setForeground(textColor);
|
||||
lines.add(allLabel);
|
||||
|
||||
final MagicPlayerProfile profile=player.getProfile();
|
||||
for (final MagicColor color : profile.getColors()) {
|
||||
final int index=color.ordinal();
|
||||
final JLabel label=new JLabel(color.getManaType().getIcon(true));
|
||||
label.setForeground(textColor);
|
||||
label.setHorizontalAlignment(JLabel.LEFT);
|
||||
label.setIconTextGap(5);
|
||||
label.setText("Cards : "+statistics.colorCount[index]+
|
||||
" Monocolor : "+statistics.colorMono[index]+
|
||||
" Lands : "+statistics.colorLands[index]);
|
||||
lines.add(label);
|
||||
for (int i = 0; i < statistics.colorCount.length; i++) {
|
||||
if (statistics.colorCount[i] > 0) {
|
||||
final MagicColor color = MagicColor.values()[i];
|
||||
final JLabel label=new JLabel(color.getManaType().getIcon(true));
|
||||
label.setForeground(textColor);
|
||||
label.setHorizontalAlignment(JLabel.LEFT);
|
||||
label.setIconTextGap(5);
|
||||
label.setText("Cards : "+statistics.colorCount[i]+
|
||||
" Monocolor : "+statistics.colorMono[i]+
|
||||
" Lands : "+statistics.colorLands[i]);
|
||||
lines.add(label);
|
||||
}
|
||||
}
|
||||
|
||||
for (int index=0;index<CardStatistics.MANA_CURVE_SIZE;index++) {
|
||||
|
@ -148,10 +158,12 @@ public class DeckStatisticsViewer extends TexturedPanel implements ChangeListene
|
|||
}
|
||||
revalidate();
|
||||
repaint();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged(final ChangeEvent event) {
|
||||
setPlayer((MagicPlayerDefinition)event.getSource());
|
||||
setDeck(((MagicPlayerDefinition)event.getSource()).getDeck());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ public class DeckViewer extends JPanel {
|
|||
}
|
||||
|
||||
public void updateAfterEdit() {
|
||||
statisticsViewer.setPlayer(player);
|
||||
statisticsViewer.setDeck(player.getDeck());
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -265,7 +265,7 @@ public class DeckViewer extends JPanel {
|
|||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent event) {
|
||||
frame.showDeckEditor(player, cubeDefinition);
|
||||
frame.showDeckEditor(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue