From 32cdd3b1eacf0e0b9a7eaa2b874142b7414312b5 Mon Sep 17 00:00:00 2001 From: Jonathan Skeate Date: Sat, 30 Dec 2017 14:35:15 -0500 Subject: [PATCH] Add rarity filters to deck editor --- .../mage/client/deckeditor/CardSelector.form | 103 ++++++++++++ .../mage/client/deckeditor/CardSelector.java | 154 +++++++++++++++++- 2 files changed, 254 insertions(+), 3 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.form b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.form index 478bd33dc4..d5ab60e950 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.form +++ b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.form @@ -500,6 +500,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java index d889a61e12..80c5600598 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java @@ -55,6 +55,7 @@ import mage.client.util.GUISizeHelper; import mage.client.util.gui.FastSearchUtil; import mage.client.util.sets.ConstructedFormats; import mage.constants.CardType; +import mage.constants.Rarity; import mage.filter.FilterCard; import mage.filter.predicate.Predicate; import mage.filter.predicate.Predicates; @@ -214,8 +215,8 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene this.cards.add(card); } filterCards(); - } - + } + public void loadCards(BigCard bigCard) { this.bigCard = bigCard; this.btnBooster.setVisible(true); @@ -225,7 +226,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene // cbExpansionSet.setModel(new DefaultComboBoxModel<>(ConstructedFormats.getTypes())); // Action event on Expansion set triggers loadCards method cbExpansionSet.setSelectedIndex(0); - } + } private FilterCard buildFilter() { FilterCard filter = new FilterCard(); @@ -328,6 +329,24 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene // criteria.types(CardType.TRIBAL); // criteria.types(CardType.CONSPIRACY); + if (this.tbCommon.isSelected()) { + criteria.rarities(Rarity.COMMON); + criteria.rarities(Rarity.LAND); + } + if (this.tbUncommon.isSelected()) { + criteria.rarities(Rarity.UNCOMMON); + } + if (this.tbRare.isSelected()) { + criteria.rarities(Rarity.RARE); + } + if (this.tbMythic.isSelected()) { + criteria.rarities(Rarity.MYTHIC); + } + if (this.tbSpecial.isSelected()) { + criteria.rarities(Rarity.SPECIAL); + criteria.rarities(Rarity.BONUS); + } + if (this.cbExpansionSet.isVisible()) { String expansionSelection = this.cbExpansionSet.getSelectedItem().toString(); if (!expansionSelection.equals("- All Sets")) { @@ -376,6 +395,19 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene filterCards(); } + private void filterCardsRarity(int modifiers, String actionCommand) { + // ALT or CTRL button was pushed + if ((modifiers & ActionEvent.ALT_MASK) == ActionEvent.ALT_MASK || (modifiers & ActionEvent.CTRL_MASK) == ActionEvent.CTRL_MASK) { + boolean invert = (modifiers & ActionEvent.ALT_MASK) == ActionEvent.ALT_MASK; + tbCommon.setSelected(inverter(invert, tbCommon.getActionCommand(), actionCommand)); + tbUncommon.setSelected(inverter(invert, tbUncommon.getActionCommand(), actionCommand)); + tbRare.setSelected(inverter(invert, tbRare.getActionCommand(), actionCommand)); + tbMythic.setSelected(inverter(invert, tbMythic.getActionCommand(), actionCommand)); + tbSpecial.setSelected(inverter(invert, tbSpecial.getActionCommand(), actionCommand)); + } + filterCards(); + } + private void filterCards() { FilterCard filter = buildFilter(); try { @@ -494,6 +526,13 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene jSeparator4 = new javax.swing.JToolBar.Separator(); jToggleListView = new javax.swing.JToggleButton(); jToggleCardView = new javax.swing.JToggleButton(); + jSeparator5 = new javax.swing.JToolBar.Separator(); + tbRarities = new javax.swing.JToolBar(); + tbCommon = new javax.swing.JToggleButton(); + tbUncommon = new javax.swing.JToggleButton(); + tbRare = new javax.swing.JToggleButton(); + tbMythic = new javax.swing.JToggleButton(); + tbSpecial = new javax.swing.JToggleButton(); cardSelectorScrollPane = new javax.swing.JScrollPane(); cardSelectorBottomPanel = new javax.swing.JPanel(); jButtonAddToMain = new javax.swing.JButton(); @@ -841,6 +880,88 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene } }); tbTypes.add(jToggleCardView); + tbTypes.add(jSeparator5); + + tbRarities.setFloatable(false); + tbRarities.setRollover(true); + tbRarities.setToolTipText("Hold the ALT-key while clicking to deselect all other card rarities or hold the CTRL-key to only select all other card rarities."); + + tbCommon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/rarity_common_20.png"))); // NOI18N + tbCommon.setSelected(true); + tbCommon.setToolTipText("Common
" + + tbRarities.getToolTipText()); + tbCommon.setActionCommand("Common"); + tbCommon.setFocusable(false); + tbCommon.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + tbCommon.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + tbCommon.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + tbCommonActionPerformed(evt); + } + }); + tbRarities.add(tbCommon); + + tbUncommon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/rarity_uncommon_20.png"))); // NOI18N + tbUncommon.setSelected(true); + tbUncommon.setToolTipText("Uncommon
" + + tbUncommon.getToolTipText()); + tbUncommon.setActionCommand("Uncommon"); + tbUncommon.setFocusable(false); + tbUncommon.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + tbUncommon.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + tbUncommon.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + tbUncommonActionPerformed(evt); + } + }); + tbRarities.add(tbUncommon); + + tbRare.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/rarity_rare_20.png"))); // NOI18N + tbRare.setSelected(true); + tbRare.setToolTipText("Rare
" + + tbRarities.getToolTipText()); + tbRare.setActionCommand("Rare"); + tbRare.setFocusable(false); + tbRare.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + tbRare.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + tbRare.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + tbRareActionPerformed(evt); + } + }); + tbRarities.add(tbRare); + + tbMythic.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/rarity_mythic_20.png"))); // NOI18N + tbMythic.setSelected(true); + tbMythic.setToolTipText("Mythic
" + + tbRarities.getToolTipText()); + tbMythic.setActionCommand("Mythic"); + tbMythic.setFocusable(false); + tbMythic.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + tbMythic.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + tbMythic.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + tbMythicActionPerformed(evt); + } + }); + tbRarities.add(tbMythic); + + tbSpecial.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/rarity_special_20.png"))); // NOI18N + tbSpecial.setSelected(true); + tbSpecial.setToolTipText("Special
" + + tbRarities.getToolTipText()); + tbSpecial.setActionCommand("Special"); + tbSpecial.setFocusable(false); + tbSpecial.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + tbSpecial.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + tbSpecial.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + tbSpecialActionPerformed(evt); + } + }); + tbRarities.add(tbSpecial); + + tbTypes.add(tbRarities); cardSelectorScrollPane.setToolTipText("Double click to add the card to the main deck.
\nALT + Double click to add the card to the sideboard."); @@ -1224,6 +1345,26 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene FastSearchUtil.showFastSearchForStringComboBox(cbExpansionSet, "Select set or expansion"); }//GEN-LAST:event_btnExpansionSearchActionPerformed + private void tbCommonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbCommonActionPerformed + filterCardsRarity(evt.getModifiers(), evt.getActionCommand()); + }//GEN-LAST:event_tbCommonActionPerformed + + private void tbUncommonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbUncommonActionPerformed + filterCardsRarity(evt.getModifiers(), evt.getActionCommand()); + }//GEN-LAST:event_tbUncommonActionPerformed + + private void tbRareActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbRareActionPerformed + filterCardsRarity(evt.getModifiers(), evt.getActionCommand()); + }//GEN-LAST:event_tbRareActionPerformed + + private void tbMythicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbMythicActionPerformed + filterCardsRarity(evt.getModifiers(), evt.getActionCommand()); + }//GEN-LAST:event_tbMythicActionPerformed + + private void tbSpecialActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbSpecialActionPerformed + filterCardsRarity(evt.getModifiers(), evt.getActionCommand()); + }//GEN-LAST:event_tbSpecialActionPerformed + private void toggleViewMode() { if (currentView instanceof CardGrid) { jToggleListView.setSelected(true); @@ -1288,6 +1429,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene private javax.swing.JToolBar.Separator jSeparator2; private javax.swing.JToolBar.Separator jSeparator3; private javax.swing.JToolBar.Separator jSeparator4; + private javax.swing.JToolBar.Separator jSeparator5; private javax.swing.JToolBar.Separator jSeparator6; private javax.swing.JTextField jTextFieldSearch; private javax.swing.JToggleButton jToggleCardView; @@ -1297,15 +1439,21 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene private javax.swing.JToggleButton tbBlue; private javax.swing.JToolBar tbColor; private javax.swing.JToggleButton tbColorless; + private javax.swing.JToggleButton tbCommon; private javax.swing.JToggleButton tbCreatures; private javax.swing.JToggleButton tbEnchantments; private javax.swing.JToggleButton tbGreen; private javax.swing.JToggleButton tbInstants; private javax.swing.JToggleButton tbLand; + private javax.swing.JToggleButton tbMythic; private javax.swing.JToggleButton tbPlaneswalkers; + private javax.swing.JToggleButton tbRare; + private javax.swing.JToolBar tbRarities; private javax.swing.JToggleButton tbRed; private javax.swing.JToggleButton tbSorceries; + private javax.swing.JToggleButton tbSpecial; private javax.swing.JToolBar tbTypes; + private javax.swing.JToggleButton tbUncommon; private javax.swing.JToggleButton tbWhite; // End of variables declaration//GEN-END:variables