From eb8f25cf3d473c71b481875171983fff152e1b4d Mon Sep 17 00:00:00 2001 From: Lodici Date: Mon, 24 Mar 2014 16:20:56 +0000 Subject: [PATCH] Cards in DeckViewScreen can be filtered by Creatures, Lands and Other Spells. --- resources/magic/data/icons/w_creatures.png | Bin 0 -> 993 bytes resources/magic/data/icons/w_lands.png | Bin 0 -> 1013 bytes resources/magic/data/icons/w_spells.png | Bin 0 -> 745 bytes src/magic/data/IconImages.java | 3 + src/magic/model/MagicCardDefinition.java | 7 + src/magic/ui/screen/DeckViewScreen.java | 201 ++++++++++++++++++--- src/magic/ui/screen/widget/ActionBar.java | 2 +- 7 files changed, 190 insertions(+), 23 deletions(-) create mode 100644 resources/magic/data/icons/w_creatures.png create mode 100644 resources/magic/data/icons/w_lands.png create mode 100644 resources/magic/data/icons/w_spells.png diff --git a/resources/magic/data/icons/w_creatures.png b/resources/magic/data/icons/w_creatures.png new file mode 100644 index 0000000000000000000000000000000000000000..8915fd7559cfab6025c6989241391359736983d8 GIT binary patch literal 993 zcmV<710MW|P)VGd000McNliru-U9~{Aq~>m;o$%P18zw~ zK~#9!-ImX5RCg4`KlkO$Bqo{=jfq-+ptRbeR851m4Mh-(E(CFBH(eBjF6yHAXSfk@ z(M>m96bm&diY-M=@n?&+VnnN=F^WbT+op9Unn@;eTzDotgNsC6^$W9j^ZkDBIrrRi z?|T6tsUBDai~xTDg@~vy#U%+K53~YHfCs>h@mP|UNIE3xo}|5!IwU180n{YvGfC$q zjY#@ZQZ9R-P10AADtfj~N?JWdkesBQk_wLTP|`L@kv)`3+9>I?q>>MINt!+dp!Jga zO}1asE=dck`zb&~lqH=2b^vRDr9jSF7bl6;1bhPw0Dk}%f&10XctJ61fqIiDM8xnU zGnxU^03~2JBE|22zmmzNw zD|}}t@oXyEjwR2zeoM2-7g7(%$CkAnxanpbF}V(B9R5{Yid;lgl8C?se9uMA11ErY z%@Wt~mfhKC!{mW$-m7z+dJHgTa*KSP>RYsITaTGdH}J9dYrNlQfLb^C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~ooNiRcpRDd=7p7g*ha(X{+a b{%hb9g03B61y_}C00000NkvXXu0mjfPPSiJ literal 0 HcmV?d00001 diff --git a/src/magic/data/IconImages.java b/src/magic/data/IconImages.java index 134fdbd241..5636d81504 100644 --- a/src/magic/data/IconImages.java +++ b/src/magic/data/IconImages.java @@ -34,6 +34,9 @@ public class IconImages { public static final ImageIcon LIFE_ICON = loadIcon("w_life.png"); public static final ImageIcon TARGET_ICON = loadIcon("w_target.png"); public static final ImageIcon CUBE_ICON = loadIcon("w_cube.png"); + public static final ImageIcon LANDS_ICON = loadIcon("w_lands.png"); + public static final ImageIcon CREATURES_ICON = loadIcon("w_creatures.png"); + public static final ImageIcon SPELLS_ICON = loadIcon("w_spells.png"); public static final ImageIcon ARENA=loadIcon("arena.png"); public static final ImageIcon ANY=loadIcon("any.png"); diff --git a/src/magic/model/MagicCardDefinition.java b/src/magic/model/MagicCardDefinition.java index 588c4e0d85..905326883e 100644 --- a/src/magic/model/MagicCardDefinition.java +++ b/src/magic/model/MagicCardDefinition.java @@ -103,6 +103,8 @@ public class MagicCardDefinition implements MagicAbilityStore { private String abilityProperty; private String requiresGroovy; + private Set cardType = EnumSet.noneOf(MagicType.class); + public MagicCardDefinition() { initialize(); } @@ -281,6 +283,11 @@ public class MagicCardDefinition implements MagicAbilityStore { assert colorFlags != 0 : "redundant color declaration: " + colorFlags; } } + cardType.add(type); + } + + public Set getCardType() { + return cardType; } public boolean hasType(final MagicType type) { diff --git a/src/magic/ui/screen/DeckViewScreen.java b/src/magic/ui/screen/DeckViewScreen.java index 8fe3a86cdb..bc6b99a4d0 100644 --- a/src/magic/ui/screen/DeckViewScreen.java +++ b/src/magic/ui/screen/DeckViewScreen.java @@ -1,19 +1,28 @@ package magic.ui.screen; +import java.awt.Color; import java.awt.Dimension; +import java.awt.Font; import java.awt.event.ActionEvent; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Set; import javax.swing.AbstractAction; +import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.SwingConstants; + +import net.miginfocom.swing.MigLayout; import magic.data.GeneralConfig; import magic.data.IconImages; import magic.model.MagicCard; import magic.model.MagicCardDefinition; import magic.model.MagicDeck; +import magic.model.MagicType; +import magic.ui.MagicFrame; import magic.ui.canvas.cards.CardsCanvas; import magic.ui.canvas.cards.CardsCanvas.LayoutMode; import magic.ui.canvas.cards.ICardCanvas; @@ -21,21 +30,36 @@ import magic.ui.screen.interfaces.IActionBar; import magic.ui.screen.interfaces.IStatusBar; import magic.ui.screen.widget.ActionBarButton; import magic.ui.screen.widget.MenuButton; -import magic.ui.widget.deck.DeckStatusPanel; @SuppressWarnings("serial") public class DeckViewScreen extends AbstractScreen implements IStatusBar, IActionBar { + private enum CardTypeFilter { + ALL("All cards"), + CREATURES("Creatures"), + LANDS("Lands"), + OTHER("Other Spells"); + private String caption; + private CardTypeFilter(final String caption) { + this.caption = caption; + } + @Override + public String toString() { + return caption; + } + } + private final static Dimension cardSize = GeneralConfig.PREFERRED_CARD_SIZE; private CardsCanvas content; private final MagicDeck deck; - private final DeckStatusPanel deckStatusPanel = new DeckStatusPanel(); + private final StatusPanel statusPanel; public DeckViewScreen(final MagicDeck deck) { this.deck = deck; + this.statusPanel = new StatusPanel(deck.getName(), getCardTypeCaption(CardTypeFilter.ALL, deck.size())); content = new CardsCanvas(cardSize); content.setAnimationEnabled(false); content.setStackDuplicateCards(true); @@ -44,10 +68,35 @@ public class DeckViewScreen setContent(content); } - private List getDeckCards(final MagicDeck deck) { + private List getDeckCards(final MagicDeck deck, final CardTypeFilter filterType) { + final List cards = new ArrayList(); - for (MagicCardDefinition magicCardDef : deck) { - cards.add(new MagicCard(magicCardDef, null, 0)); + + for (MagicCardDefinition cardDef : deck) { + + final Set cardType = cardDef.getCardType(); + + switch (filterType) { + case CREATURES: + if (cardType.contains(MagicType.Creature)) { + cards.add(new MagicCard(cardDef, null, 0)); + } + break; + case LANDS: + if (cardType.contains(MagicType.Land)) { + cards.add(new MagicCard(cardDef, null, 0)); + } + break; + case OTHER: + if (!cardType.contains(MagicType.Creature) && !cardType.contains(MagicType.Land)) { + cards.add(new MagicCard(cardDef, null, 0)); + } + break; + default: // ALL + cards.add(new MagicCard(cardDef, null, 0)); + break; + } + } if (cards.size() > 0) { Collections.sort(cards); @@ -55,6 +104,10 @@ public class DeckViewScreen } else { return null; } + + } + private List getDeckCards(final MagicDeck deck) { + return getDeckCards(deck, CardTypeFilter.ALL); } /* (non-Javadoc) @@ -92,28 +145,37 @@ public class DeckViewScreen @Override public List getMiddleActions() { final List buttons = new ArrayList(); + buttons.add( + new ActionBarButton( + "All", "Display all cards in deck.", + new ShowCardsAction(CardTypeFilter.ALL), false)); + buttons.add( + new ActionBarButton( + IconImages.CREATURES_ICON, + "Creatures", "Display only creature cards.", + new ShowCardsAction(CardTypeFilter.CREATURES), false) + ); + buttons.add( + new ActionBarButton( + IconImages.LANDS_ICON, + "Lands", "Display only land cards.", + new ShowCardsAction(CardTypeFilter.LANDS), false) + ); + buttons.add( + new ActionBarButton( + IconImages.SPELLS_ICON, + "Other Spells", "Display any other card that is not a creature or land.", + new ShowCardsAction(CardTypeFilter.OTHER), true) + ); buttons.add( new ActionBarButton( IconImages.HAND_ICON, - "Sample Hand", "See what kind of Hand you might be dealt from this deck.", - new AbstractAction() { - @Override - public void actionPerformed(final ActionEvent e) { - if (deck.size() >= 7) { - getFrame().showSampleHandGenerator(deck); - } else { - showInvalidActionMessage("A deck with a minimum of 7 cards is required first."); - } - } - }) + "Sample Hand", "Generate sample Hands from this deck.", + new SampleHandAction(deck, getFrame())) ); return buttons; } - private void showInvalidActionMessage(final String message) { - JOptionPane.showMessageDialog(this, message, "Invalid Action", JOptionPane.INFORMATION_MESSAGE); - } - /* (non-Javadoc) * @see magic.ui.MagScreen#canScreenClose() */ @@ -127,8 +189,103 @@ public class DeckViewScreen */ @Override public JPanel getStatusPanel() { - deckStatusPanel.setDeck(deck, true); - return deckStatusPanel; + return statusPanel; + } + + private class ShowCardsAction extends AbstractAction { + + private final CardTypeFilter filter; + + public ShowCardsAction(final CardTypeFilter filter) { + this.filter = filter; + } + + @Override + public void actionPerformed(ActionEvent e) { + showCards(filter); + } + + private void showCards(final CardTypeFilter filterType) { + final List cards = getDeckCards(deck, filterType); + content.refresh(cards, cardSize); + statusPanel.setContent(deck.getName(), getCardTypeCaption(filterType, cards.size())); + } + + } + + private String getCardTypeCaption(final CardTypeFilter cardType, final int cardCount) { + if (cardType != CardTypeFilter.ALL) { + final int percentage = (int)((cardCount / (double)deck.size()) * 100); + return cardType + " (" + cardCount + " cards, " + percentage + "%)"; + } else { + return cardType + " (" + cardCount + " cards)"; + } + } + + private class SampleHandAction extends AbstractAction { + + private final MagicDeck deck; + private final MagicFrame frame; + + public SampleHandAction(final MagicDeck deck, final MagicFrame frame) { + this.deck = deck; + this.frame = frame; + } + + @Override + public void actionPerformed(ActionEvent e) { + if (deck.size() >= 7) { + getFrame().showSampleHandGenerator(deck); + } else { + showInvalidActionMessage("A deck with a minimum of 7 cards is required first."); + } + } + + private void showInvalidActionMessage(final String message) { + JOptionPane.showMessageDialog( + frame, message, "Invalid Action", JOptionPane.INFORMATION_MESSAGE); + } + + } + + private class StatusPanel extends JPanel { + + // ui + private final MigLayout migLayout = new MigLayout(); + private final JLabel deckNameLabel = new JLabel(); + private final JLabel filterLabel = new JLabel(); + + public StatusPanel(final String deckName, final String filterCaption) { + setLookAndFeel(); + setContent(deckName, filterCaption); + } + + private void setLookAndFeel() { + setOpaque(false); + setLayout(migLayout); + // deck name label + deckNameLabel.setForeground(Color.WHITE); + deckNameLabel.setFont(new Font("Dialog", Font.PLAIN, 16)); + deckNameLabel.setHorizontalAlignment(SwingConstants.CENTER); + // filter label + filterLabel.setForeground(Color.WHITE); + filterLabel.setFont(new Font("Dialog", Font.ITALIC, 14)); + filterLabel.setHorizontalAlignment(SwingConstants.CENTER); + } + + private void refreshLayout() { + removeAll(); + migLayout.setLayoutConstraints("insets 0, gap 2, flowy"); + add(deckNameLabel, "w 100%"); + add(filterLabel, "w 100%"); + } + + public void setContent(final String deckName, final String filterCaption) { + deckNameLabel.setText(deckName); + filterLabel.setText(filterCaption); + refreshLayout(); + } + } } \ No newline at end of file diff --git a/src/magic/ui/screen/widget/ActionBar.java b/src/magic/ui/screen/widget/ActionBar.java index bd244a6ebe..2472020140 100644 --- a/src/magic/ui/screen/widget/ActionBar.java +++ b/src/magic/ui/screen/widget/ActionBar.java @@ -66,7 +66,7 @@ public class ActionBar extends TexturedPanel { panel.add(btn, "w 60, h 40"); btn.setEnabled(btn.isRunnable()); btn.setBorder(BorderFactory.createCompoundBorder( - BorderFactory.createMatteBorder(0, isFirstButton ? 1 : 0, 0, 1, Color.LIGHT_GRAY), + BorderFactory.createMatteBorder(0, isFirstButton ? 1 : 0, 0, btn.showSeparator() ? 1 : 0, Color.LIGHT_GRAY), BorderFactory.createEmptyBorder(0, 10, 0, 10))); btn.setBorderPainted(true); isFirstButton = false;