add exclusive color button
All checks were successful
/ example-docker-compose (push) Successful in 14m48s

This commit is contained in:
Failure 2025-01-25 21:36:00 -08:00
parent 7795e06b1c
commit f551ff8f2c
4 changed files with 76 additions and 3 deletions

View file

@ -19,7 +19,7 @@ public enum MageTray {
private Image flashedImage;
private TrayIcon trayIcon;
private int state = 0;
private int state = 3;
public void install() {
if (!SystemTray.isSupported()) {

View file

@ -240,26 +240,44 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
if (limited) {
List<Predicate<MageObject>> predicates = new ArrayList<>();
List<Predicate<MageObject>> exclusion = new ArrayList<>();
if (this.tbGreen.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.GREEN));
} else {
exclusion.add(new ColorPredicate(ObjectColor.GREEN));
}
if (this.tbRed.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.RED));
} else {
exclusion.add(new ColorPredicate(ObjectColor.RED));
}
if (this.tbBlack.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.BLACK));
} else {
exclusion.add(new ColorPredicate(ObjectColor.BLACK));
}
if (this.tbBlue.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.BLUE));
} else {
exclusion.add(new ColorPredicate(ObjectColor.BLUE));
}
if (this.tbWhite.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.WHITE));
} else {
exclusion.add(new ColorPredicate(ObjectColor.WHITE));
}
if (this.tbColorless.isSelected()) {
predicates.add(ColorlessPredicate.instance);
} else {
exclusion.add(ColorlessPredicate.instance);
}
if (this.tbLimitColors.isSelected()) {
filter.add(Predicates.and(Predicates.not(Predicates.or(exclusion)), Predicates.or(predicates)));
} else {
filter.add(Predicates.or(predicates));
}
filter.add(Predicates.or(predicates));
predicates.clear();
if (this.tbLand.isSelected()) {
@ -349,6 +367,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
criteria.red(this.tbRed.isSelected());
criteria.white(this.tbWhite.isSelected());
criteria.colorless(this.tbColorless.isSelected());
criteria.limitColors(this.tbLimitColors.isSelected());
// if you add new type filter then sync it with CardType
if (this.tbLand.isSelected()) {
@ -562,6 +581,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
tbBlack = new javax.swing.JToggleButton();
tbWhite = new javax.swing.JToggleButton();
tbColorless = new javax.swing.JToggleButton();
tbLimitColors = new javax.swing.JToggleButton();
jSeparator1 = new javax.swing.JToolBar.Separator();
cbExpansionSet = new javax.swing.JComboBox<>();
btnExpansionSearch = new javax.swing.JButton();
@ -706,6 +726,23 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
}
});
tbColor.add(tbColorless);
tbLimitColors.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/lock.png"))); // NOI18N
tbLimitColors.setSelected(false);
tbLimitColors.setToolTipText("Limit results to ONLY these colors");
tbLimitColors.setActionCommand("LimitColors");
tbLimitColors.setFocusable(false);
tbLimitColors.setPreferredSize(new java.awt.Dimension(28, 28));
tbLimitColors.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
tbLimitColors.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/lock.png"))); // NOI18N
tbLimitColors.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
tbLimitColors.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tbLimitColorsActionPerformed(evt);
}
});
tbColor.add(tbLimitColors);
tbColor.add(jSeparator1);
reloadSetsCombobox();
@ -1451,7 +1488,11 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
private void tbColorlessActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbColorlessActionPerformed
filterCardsColor(evt.getModifiers(), evt.getActionCommand());
}//GEN-LAST:event_tbColorlessActionPerformed
private void tbLimitColorsActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbColorlessActionPerformed
filterCards();
}
private void tbCreaturesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbCreaturesActionPerformed
filterCardsType(evt.getModifiers(), evt.getActionCommand());
}//GEN-LAST:event_tbCreaturesActionPerformed
@ -1667,6 +1708,7 @@ 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 tbLimitColors;
private javax.swing.JToggleButton tbCommon;
private javax.swing.JToggleButton tbCreatures;
private javax.swing.JToggleButton tbEnchantments;

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

View file

@ -3,10 +3,13 @@ package mage.cards.repository;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.SelectArg;
import com.j256.ormlite.stmt.Where;
import mage.MageObject;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.filter.predicate.Predicate;
import java.sql.SQLException;
import java.util.ArrayList;
@ -39,6 +42,7 @@ public class CardCriteria {
private boolean red;
private boolean white;
private boolean colorless;
private boolean limitColors;
private Integer manaValue;
private String sortBy;
private Long start;
@ -68,6 +72,12 @@ public class CardCriteria {
this.minCardNumber = Integer.MIN_VALUE;
this.maxCardNumber = Integer.MAX_VALUE;
}
public CardCriteria limitColors(boolean limitColors) {
this.limitColors = limitColors;
return this;
}
public CardCriteria black(boolean black) {
this.black = black;
@ -311,35 +321,56 @@ public class CardCriteria {
clausesCount++;
}
List<String> exclusion = new ArrayList<>();
int colorClauses = 0;
if (black) {
where.eq("black", true);
colorClauses++;
} else {
exclusion.add("black");
}
if (blue) {
where.eq("blue", true);
colorClauses++;
} else {
exclusion.add("blue");
}
if (green) {
where.eq("green", true);
colorClauses++;
} else {
exclusion.add("green");
}
if (red) {
where.eq("red", true);
colorClauses++;
} else {
exclusion.add("red");
}
if (white) {
where.eq("white", true);
colorClauses++;
} else {
exclusion.add("white");
}
if (colorless) {
where.eq("black", false).eq("blue", false).eq("green", false).eq("red", false).eq("white", false);
where.and(5);
colorClauses++;
}
if (colorClauses > 0) {
where.or(colorClauses);
clausesCount++;
if (this.limitColors) {
for (String color : exclusion) {
where.not();
where.eq(color, true);
clausesCount++;
}
}
}
if (minCardNumber != Integer.MIN_VALUE) {