It is currently 29 Apr 2024, 10:16
   
Text Size

Feature contribution - text search

Moderators: ubeefx, beholder, melvin, ShawnieBoy, Lodici, CCGHQ Admins

Feature contribution - text search

Postby IanGrainger » 25 Apr 2011, 11:30

Hi, I have added the ability to filter the cards on the deck editing screen using a text search (on name, type or ability).

If the owners of the project would like to include this feature I'd be happy to provide an SVN patch.
IanGrainger
 
Posts: 6
Joined: 25 Apr 2011, 11:23
Has thanked: 0 time
Been thanked: 0 time

Problem with ant script

Postby IanGrainger » 25 Apr 2011, 11:35

I also couldn't compile until I moved the 'copy resources' step in the build file to before the compile step, making the target:

Code: Select all
  <!-- build - Compile sources and copy resources to build directory -->
  <target depends="init" name="build">
     <copy includeemptydirs="false" todir="build">
      <fileset dir="resources">
        <exclude name="**/.svn"/>
      </fileset>
    </copy>
     <javac debug="true" debuglevel="${debuglevel}" destdir="build" source="${source}" target="${target}">
      <src path="src"/>
    </javac>
   
  </target>
HTH.
IanGrainger
 
Posts: 6
Joined: 25 Apr 2011, 11:23
Has thanked: 0 time
Been thanked: 0 time

Re: Feature contribution - text search

Postby Huggybaby » 25 Apr 2011, 16:57

That's cool, thanks IanGrainger!
User avatar
Huggybaby
Administrator
 
Posts: 3207
Joined: 15 Jan 2006, 19:44
Location: Finally out of Atlanta
Has thanked: 701 times
Been thanked: 594 times

Re: Feature contribution - text search

Postby ubeefx » 25 Apr 2011, 21:26

Thanks for your contribution! :D
If you pm me the svn patch I will see what I can do.
User avatar
ubeefx
DEVELOPER
 
Posts: 749
Joined: 23 Nov 2010, 19:16
Has thanked: 35 times
Been thanked: 249 times

Re: Feature contribution - text search

Postby beholder » 03 Aug 2011, 13:14

This feature is a must when making decks, all though a 'full' deck editor would be even better. I used the above mentioned patch (parts of it) and I love it. Finally a way to find all those goblins or knights or zombies or whatever :D
Maybe this basic functionality can be included now and made better in the future?
Attachments
card-explorer-text-filter.jpg
If debugging is the process of removing bugs, then programming must be the process of putting them in.
User avatar
beholder
Programmer
 
Posts: 123
Joined: 17 Jul 2011, 17:56
Location: Netherlands
Has thanked: 16 times
Been thanked: 25 times

Re: Feature contribution - text search

Postby IanGrainger » 03 Aug 2011, 13:18

Thanks for the +1! I really should include it - I was given access to source control three months ago... Sorry!

EDIT: Oh - what parts did you use/not use? Did you improve it? :)
IanGrainger
 
Posts: 6
Joined: 25 Apr 2011, 11:23
Has thanked: 0 time
Been thanked: 0 time

Re: Feature contribution - text search

Postby beholder » 03 Aug 2011, 14:51

The patch was incomplete. It had a reference to magic.model.MagicSubType.getName() that doesn't excist. I'm only a hobbyist programmer and new to java but I solved this (probably in a bad manner :P)
I didn't use the filter on type cause that's done with the checkboxes already. The rest is just small changes in styling etc.
But yeah, it works great and could be improved upon later. So thanks for making it :)
If debugging is the process of removing bugs, then programming must be the process of putting them in.
User avatar
beholder
Programmer
 
Posts: 123
Joined: 17 Jul 2011, 17:56
Location: Netherlands
Has thanked: 16 times
Been thanked: 25 times

Re: Feature contribution - text search

Postby IanGrainger » 03 Aug 2011, 15:14

beholder wrote:The patch was incomplete. It had a reference to magic.model.MagicSubType.getName() that doesn't excist. I'm only a hobbyist programmer and new to java but I solved this (probably in a bad manner :P)
I didn't use the filter on type cause that's done with the checkboxes already. The rest is just small changes in styling etc.
But yeah, it works great and could be improved upon later. So thanks for making it :)
Ah, presumably because the patch was for old code... What styling changes? I'm thinking I should put your patch in instead of mine... :)
IanGrainger
 
Posts: 6
Joined: 25 Apr 2011, 11:23
Has thanked: 0 time
Been thanked: 0 time

Re: Feature contribution - text search

Postby beholder » 03 Aug 2011, 17:58

IanGrainger wrote:... What styling changes?
I used braces on single statements to keep it consistent with the rest of the code, used enhanced for statements and I used magic.model.MagicSubType.hasSubType instead of magic.model.MagicCardDefinition.hasSubType to prevent Shapeshifters showing on every search (cause they are.. well every type :)).

Since this forum won't allow attaching .patch or .txt files ....

card-explorer-text-filter.patch | Open
Code: Select all
# HG changeset patch
# User LOL@LOLLOL
# Date 1312393185 -7200
# Node ID 373b640409640646cf86caaeb270ca74b427962a
# Parent  6d613d9e52a5e8f30ac502b5b58d819da20a63b8
card explorer text filter

diff -r 6d613d9e52a5 -r 373b64040964 src/magic/model/MagicCardDefinition.java
--- a/src/magic/model/MagicCardDefinition.java   Wed Aug 03 19:20:15 2011 +0200
+++ b/src/magic/model/MagicCardDefinition.java   Wed Aug 03 19:39:45 2011 +0200
@@ -574,4 +574,34 @@
          return IconImages.SPELL;
       }
    }
+   
+   public boolean subTypeHasText(String s) {
+      MagicSubType[] subTypeValues = MagicSubType.values();
+      for (final MagicSubType subtype : subTypeValues) {
+         if(subtype.hasSubType(subTypeFlags) && subtype.toString().toLowerCase().contains(s)) {
+            return true;
+         }
+      }
+      return false;
+   }
+      
+   public boolean abilityHasText(String s) {
+      MagicAbility[] abilityValues = MagicAbility.values();
+      for (final MagicAbility ability : abilityValues) {
+         if(hasAbility(ability) && ability.getName().toLowerCase().contains(s)) {
+            return true;
+         }
+      }
+      return false;
+   }
+   
+   public boolean hasText(String s) {
+      s = s.toLowerCase();
+      return (
+         fullName.toLowerCase().contains(s) ||
+         name.toLowerCase().contains(s) ||
+         subTypeHasText(s) ||
+         abilityHasText(s)
+      );
+   }
 }
diff -r 6d613d9e52a5 -r 373b64040964 src/magic/ui/ExplorerFilterPanel.java
--- a/src/magic/ui/ExplorerFilterPanel.java   Wed Aug 03 19:20:15 2011 +0200
+++ b/src/magic/ui/ExplorerFilterPanel.java   Wed Aug 03 19:39:45 2011 +0200
@@ -11,12 +11,16 @@
 import java.util.List;
 
 import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
 import javax.swing.ButtonGroup;
 import javax.swing.JCheckBox;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
+import javax.swing.JTextField;
 import javax.swing.border.TitledBorder;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
 
 import magic.data.CardDefinitions;
 import magic.model.MagicCardDefinition;
@@ -30,7 +34,7 @@
 import magic.ui.widget.TexturedPanel;
 import magic.ui.widget.TitleBar;
 
-public class ExplorerFilterPanel extends TexturedPanel implements ActionListener {
+public class ExplorerFilterPanel extends TexturedPanel implements ActionListener, DocumentListener {
    
    private static final long serialVersionUID = 1L;
 
@@ -64,6 +68,7 @@
    private final JCheckBox exactlyCheckBox;
    private final JCheckBox excludeCheckBox;
    private final JCheckBox multiCheckBox;
+   private final JTextField textFilterField;
    private final JRadioButton nameRadioButton;
    private final JRadioButton convertedRadioButton;
    private final int mode;
@@ -84,7 +89,8 @@
       final TitleBar titleBar=new TitleBar("Filter");
       add(titleBar,BorderLayout.NORTH);
 
-      final JPanel mainPanel=new JPanel(new BorderLayout(0,2));
+      final JPanel mainPanel=new JPanel();
+      mainPanel.setLayout(new BoxLayout( mainPanel, BoxLayout.Y_AXIS));
       mainPanel.setOpaque(false);
       mainPanel.setBorder(FontsAndBorders.BLACK_BORDER);
       add(mainPanel,BorderLayout.CENTER);
@@ -95,7 +101,7 @@
       final JPanel typeFilterPanel=new JPanel(new BorderLayout(8,0));
       typeFilterPanel.setOpaque(false);
       typeFilterPanel.setBorder(typeBorder);
-      mainPanel.add(typeFilterPanel,BorderLayout.NORTH);
+      mainPanel.add(typeFilterPanel);
 
       final JPanel leftTypeFilterPanel=new JPanel(new GridLayout(3,1));
       leftTypeFilterPanel.setOpaque(false);
@@ -125,7 +131,7 @@
       final JPanel colorFilterPanel=new JPanel(new BorderLayout());
       colorFilterPanel.setOpaque(false);
       colorFilterPanel.setBorder(colorBorder);
-      mainPanel.add(colorFilterPanel,BorderLayout.CENTER);
+      mainPanel.add(colorFilterPanel);
 
       colorCheckBoxes=new JCheckBox[MagicColor.NR_COLORS];
       final JPanel colorsPanel=new JPanel(new GridLayout(1,MagicColor.NR_COLORS));
@@ -169,13 +175,25 @@
       otherColorPanel.add(multiCheckBox);
       colorFilterPanel.add(otherColorPanel,BorderLayout.CENTER);
 
+      // Text
+      final TitledBorder textFilterBorder=BorderFactory.createTitledBorder("Text");
+      textFilterBorder.setTitleColor(textColor);
+      final JPanel textFilterPanel=new JPanel(new BorderLayout(8,0));
+      textFilterPanel.setOpaque(false);
+      textFilterPanel.setBorder(textFilterBorder);
+      textFilterField = new JTextField();
+      textFilterField.addActionListener(this);
+      textFilterField.getDocument().addDocumentListener(this);
+      textFilterPanel.add(textFilterField);
+      mainPanel.add(textFilterPanel);
+            
       // Sort
       final TitledBorder sortBorder=BorderFactory.createTitledBorder("Sort");
       sortBorder.setTitleColor(textColor);
       final JPanel sortFilterPanel=new JPanel(new BorderLayout(8,0));
       sortFilterPanel.setOpaque(false);
       sortFilterPanel.setBorder(sortBorder);
-      mainPanel.add(sortFilterPanel,BorderLayout.SOUTH);
+      mainPanel.add(sortFilterPanel);
 
       final ButtonGroup sortGroup=new ButtonGroup();
       nameRadioButton=new JRadioButton("Name",true);
@@ -244,6 +262,16 @@
          return false;
       }
       
+      // text
+      String filterString = textFilterField.getText();
+      String[] filters = filterString.split(" ");
+      for(int i=0; i<filters.length; i++) {
+         if(!cardDefinition.hasText(filters[i])) {
+            return false;
+         }
+      }
+      
+      // colors      
       boolean useColors=false;
       boolean validColors=false;
       for (int colorIndex=0;colorIndex<colorCheckBoxes.length;colorIndex++) {
@@ -287,4 +315,18 @@
       
       explorerPanel.updateCards();
    }
+
+   @Override
+   public void insertUpdate(DocumentEvent arg0) {
+      explorerPanel.updateCards();
+   }
+
+   @Override
+   public void removeUpdate(DocumentEvent arg0) {
+      explorerPanel.updateCards();
+   }
+   
+   @Override
+   public void changedUpdate(DocumentEvent arg0) {
+   }
 }
\ No newline at end of file
diff -r 6d613d9e52a5 -r 373b64040964 src/magic/ui/ExplorerPanel.java
--- a/src/magic/ui/ExplorerPanel.java   Wed Aug 03 19:20:15 2011 +0200
+++ b/src/magic/ui/ExplorerPanel.java   Wed Aug 03 19:39:45 2011 +0200
@@ -41,7 +41,7 @@
    
    private static final int CARD_WIDTH=DefaultResolutionProfile.CARD_VIEWER_WIDTH;
    private static final int CARD_HEIGHT=DefaultResolutionProfile.CARD_VIEWER_HEIGHT;
-   private static final int FILTER_HEIGHT=290;
+   private static final int FILTER_HEIGHT = 350;
    private static final int LINE_SPACING=4;
    private static final int LINE_WIDTH=200;
    private static final int LINE_WIDTH2=LINE_WIDTH+LINE_SPACING+2;
If debugging is the process of removing bugs, then programming must be the process of putting them in.
User avatar
beholder
Programmer
 
Posts: 123
Joined: 17 Jul 2011, 17:56
Location: Netherlands
Has thanked: 16 times
Been thanked: 25 times

Re: Feature contribution - text search

Postby beholder » 24 Aug 2011, 19:32

The text search is implemented now. I was holding back on this because of the upcoming deck editor but since that isn't done yet (and because I love building decks), I thought we have to do with this for now.

Thanks again for the patch! :)
If debugging is the process of removing bugs, then programming must be the process of putting them in.
User avatar
beholder
Programmer
 
Posts: 123
Joined: 17 Jul 2011, 17:56
Location: Netherlands
Has thanked: 16 times
Been thanked: 25 times

Re: Feature contribution - text search

Postby IanGrainger » 24 Aug 2011, 19:35

Haha sorry I failed to put it in myself. Thanks!
IanGrainger
 
Posts: 6
Joined: 25 Apr 2011, 11:23
Has thanked: 0 time
Been thanked: 0 time


Return to Magarena

Who is online

Users browsing this forum: No registered users and 49 guests


Who is online

In total there are 49 users online :: 0 registered, 0 hidden and 49 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 49 guests

Login Form