Skip to content

Commit

Permalink
weapon class code and rename, add equipment class table filter, vario…
Browse files Browse the repository at this point in the history
…us other
  • Loading branch information
SJuliez committed Oct 27, 2024
1 parent a92e98d commit a654d22
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 297 deletions.
3 changes: 2 additions & 1 deletion megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,7 @@ MekSelectorDialog.Search.ArmorType=Armor Type:
MekSelectorDialog.Search.Any=Any
MekSelectorDialog.Search.or=Or
MekSelectorDialog.Search.and=And
MekSelectorDialog.Search.Combine=Note: TW and AS search filters can be used at the same time!
MekSelectorDialog.Search.AtLeast=at least
MekSelectorDialog.Search.EqualTo=equal to
MekSelectorDialog.Search.NoMoreThan=no more than
Expand All @@ -2174,7 +2175,7 @@ MekSelectorDialog.Search.Armor25=25% of maximum
MekSelectorDialog.Search.Armor50=50% of maximum
MekSelectorDialog.Search.Armor75=75% of maximum
MekSelectorDialog.Search.Armor90=90% of maximum
MekSelectorDialog.Search.WeaponClass=Weapon Type
MekSelectorDialog.Search.WeaponClass=Equipment Group
MekSelectorDialog.Search.Weapons=Weapons
MekSelectorDialog.Search.Equipment=Equipment
MekSelectorDialog.Search.Year=Design year:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ private void updateEnabled() {
pvTo.setEnabled(usePV.isSelected());

mvBetween.setEnabled(useMV.isSelected());
mvMode.setEnabled(useMV.isSelected());
mvFrom.setEnabled(useMV.isSelected());
mvAnd.setEnabled(useMV.isSelected());
mvTo.setEnabled(useMV.isSelected());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
*/
package megamek.client.ui.advancedsearch;

import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.FlatIconColors;
import com.formdev.flatlaf.extras.FlatSVGIcon;
import com.formdev.flatlaf.extras.components.FlatButton;
import megamek.client.ui.Messages;
import megamek.client.ui.baseComponents.AbstractButtonDialog;
import megamek.client.ui.swing.ButtonEsc;
Expand Down Expand Up @@ -45,7 +49,7 @@ public AdvancedSearchDialog2(JFrame parent, int allowedYear) {
year = allowedYear;
totalWarTab = new TWAdvancedSearchPanel(year);
advancedSearchPane.addTab("Total Warfare", totalWarTab);
advancedSearchPane.addTab("Alpha Strike", alphaStrikeTab);
advancedSearchPane.addTab("Alpha Strike", new TWAdvancedSearchPanel.StandardScrollPane(alphaStrikeTab));
initialize();
}

Expand Down Expand Up @@ -74,13 +78,24 @@ protected JPanel createButtonPanel() {
okButton.addActionListener(this::okButtonActionPerformed);
getRootPane().setDefaultButton(okButton);

JPanel notePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
notePanel.add(Box.createHorizontalStrut(20));
var noteLabel = new JLabel(Messages.getString("MekSelectorDialog.Search.Combine"));
noteLabel.putClientProperty(FlatClientProperties.STYLE, "foreground: mix($Label.foreground, #afa, 60%)");
notePanel.add(noteLabel);

JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 20, 0));
buttonPanel.setBorder(BorderFactory.createCompoundBorder(
new MatteBorder(1, 0, 0, 0, UIManager.getColor("Separator.foreground")),
new EmptyBorder(10, 0, 10, 0)));
buttonPanel.add(okButton);
buttonPanel.add(cancelButton);
return buttonPanel;

JPanel outerPanel = new JPanel(new GridLayout(1,1));
outerPanel.setBorder(BorderFactory.createCompoundBorder(
new MatteBorder(1, 0, 0, 0, UIManager.getColor("Separator.foreground")),
new EmptyBorder(10, 0, 10, 0)));
outerPanel.add(notePanel);
outerPanel.add(buttonPanel);

return outerPanel;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
*
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MegaMek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
package megamek.client.ui.advancedsearch;

import java.util.Locale;

enum AdvancedSearchEquipmentClass {
EMPTY, AUTOCANNON, RAC, ULTRA, LIGHT, MACHINE_GUN, GAUSS, BALLISTIC, PLASMA, ENERGY, LASER, PULSE, RE_ENGINEERED, PPC, TASER, FLAMER, MISSILE,
LRM, MRM, SRM, PHYSICAL, AMS, PRACTICAL_PHYSICAL, INFANTRY_SUIT, PROBE;

public boolean matches(String name) {
if (this == EMPTY) {
return true;
}
name = name.toLowerCase(Locale.ROOT);
if (name.contains("ammo")) {
return false;
}
if (this == PHYSICAL) {
return name.contains("backhoe") || name.contains("saw") || name.contains("whip") || name.contains("claw") ||
name.contains("combine") || name.contains("flail") || name.contains("hatchet") || name.contains("driver") ||
name.contains("lance") || name.contains("mace") || name.contains("drill") || name.contains("ram") ||
name.contains("blade") || name.contains("cutter") || name.contains("shield") || name.contains("welder") ||
name.contains("sword") || name.contains("talons") || name.contains("wrecking");
} else if (this == PRACTICAL_PHYSICAL) {
return name.contains("claw") || name.contains("flail") || name.contains("hatchet") || name.contains("lance")
|| name.contains("mace") || name.contains("blade") || name.contains("shield") || name.contains("sword")
|| name.contains("talons");
} else if (this == MISSILE) {
return name.contains("lrm") || name.contains("mrm") || name.contains("srm");
} else if (this == RE_ENGINEERED) {
return name.contains("engineered");
} else if (this == ENERGY) {
return LASER.matches(name) || PPC.matches(name) || FLAMER.matches(name);
} else if (this == MACHINE_GUN) {
return (name.contains("mg") || name.contains("machine")) && !name.contains("ammo");
} else if (this == BALLISTIC) {
return AUTOCANNON.matches(name) || GAUSS.matches(name) || MACHINE_GUN.matches(name);
} else if (this == RAC) {
return name.contains("rotary");
} else if (this == ULTRA) {
return name.contains("ultraa");
} else if (this == INFANTRY_SUIT) {
return (name.contains("suit") || name.contains(" kit") || name.contains(", standard") || name.contains(", concealed")
|| name.contains("clothing") || name.contains("vest") || name.contains("chainmail") || name.contains("parka"))
&& !name.contains("ecm") && !name.contains("generic") && !name.contains("suite");
} else if (this == AMS) {
return name.contains("ams") || name.contains("antimiss");
} else if (this == PROBE) {
return name.contains("probe");
} else if (name.contains(name().toLowerCase(Locale.ROOT)) && !name.contains("ammo")) {
return true;
}
return false;
}

@Override
public String toString() {
return switch (this) {
case EMPTY -> "";
case AUTOCANNON -> "Autocannon";
case ULTRA -> "Ultra A/C";
case LIGHT -> "Light A/C";
case MACHINE_GUN -> "Machine Gun";
case GAUSS -> "Gauss";
case BALLISTIC -> "Ballistic";
case PLASMA -> "Plasma";
case ENERGY -> "Energy";
case LASER -> "Laser";
case PULSE -> "Pulse Laser";
case RE_ENGINEERED -> "Re-Engineered Laser";
case PPC -> "PPC";
case TASER -> "Taser";
case FLAMER -> "Flamer";
case MISSILE -> "Missile";
case PHYSICAL -> "Physical (inc. industrial equipment)";
case PRACTICAL_PHYSICAL -> "Physical (weapons only)";
case INFANTRY_SUIT -> "Infantry Armor Suits";
case PROBE -> "Active Probes";
default -> super.toString();
};
}
}
22 changes: 11 additions & 11 deletions megamek/src/megamek/client/ui/advancedsearch/MekSearchFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private ExpNode createFTFromTokensRecursively(Iterator<FilterToken> toks, ExpNod
currNode = new ExpNode();
}

ExpNode newChild = new ExpNode(ft.weaponClass, ft.qty, ft.atleast);
ExpNode newChild = new ExpNode(ft.equipmentClass, ft.qty, ft.atleast);
currNode.children.add(newChild);
return createFTFromTokensRecursively(toks, currNode);
}
Expand Down Expand Up @@ -969,7 +969,7 @@ private boolean evaluate(List<String> eq, List<Integer> qty, ExpNode n) {
// Base Case: See if any of the equipment matches the leaf node in
// sufficient quantity
if (n.children.isEmpty()) {
if (n.weaponClass != null) {
if (n.equipmentClass != null) {
// Since weapon classes can match across different types of equipment, we have
// to sum up
// all equipment that matches the weaponClass value.
Expand All @@ -981,7 +981,7 @@ private boolean evaluate(List<String> eq, List<Integer> qty, ExpNode n) {
// Now, stream that map, filtering on a match with the WeaponClass, then extract
// the quantities and sum them up.
int total = nameQtyPairs.stream()
.filter(p -> n.weaponClass.matches(p.getKey()))
.filter(p -> n.equipmentClass.matches(p.getKey()))
.map(Map.Entry::getValue)
.reduce(0, Integer::sum);

Expand Down Expand Up @@ -1088,7 +1088,7 @@ public static class ExpNode {
public ExpNode parent;
public BoolOp operation;
public String name;
public WeaponClass weaponClass;
public AdvancedSearchEquipmentClass equipmentClass;
public int qty;
public List<ExpNode> children;
public boolean atleast;
Expand All @@ -1111,7 +1111,7 @@ public ExpNode(ExpNode e) {
// if (e.name != null) {
name = e.name;
// }
weaponClass = e.weaponClass;
equipmentClass = e.equipmentClass;
Iterator<ExpNode> nodeIter = e.children.iterator();
children = new LinkedList<>();
while (nodeIter.hasNext()) {
Expand All @@ -1122,17 +1122,17 @@ public ExpNode(ExpNode e) {
public ExpNode(String n, int q, boolean atleast) {
parent = null;
name = n;
weaponClass = null;
equipmentClass = null;
qty = q;
operation = BoolOp.NOP;
children = new LinkedList<>();
this.atleast = atleast;
}

public ExpNode(WeaponClass n, int q, boolean atleast) {
public ExpNode(AdvancedSearchEquipmentClass n, int q, boolean atleast) {
parent = null;
name = null;
weaponClass = n;
equipmentClass = n;
qty = q;
operation = BoolOp.NOP;
children = new LinkedList<>();
Expand All @@ -1149,11 +1149,11 @@ public String toString() {
} else {
return qty + " " + name + "s";
}
} else if (weaponClass != null) {
} else if (equipmentClass != null) {
if (qty == 1) {
return qty + " " + weaponClass.toString();
return qty + " " + equipmentClass.toString();
} else {
return qty + " " + weaponClass.toString() + "s";
return qty + " " + equipmentClass.toString() + "s";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class QuirksSearchTab extends JPanel {
listWeaponQuirkType = new TriStateItemList(new WeaponQuirks(), 17);

JPanel unitQuirksPanel = new JPanel(new BorderLayout());
JPanel quirkIEPanel = new JPanel(new FlowLayout());
JPanel quirkIEPanel = new JPanel();
quirkIEPanel.add(new JLabel(Messages.getString("MekSelectorDialog.Search.Quirk")));
quirkIEPanel.add(Box.createHorizontalStrut(15));
quirkIEPanel.add(new JLabel("\u2611"));
Expand All @@ -57,9 +57,12 @@ class QuirksSearchTab extends JPanel {
quirkIEPanel.add(cQuirkExclude);
unitQuirksPanel.add(quirkIEPanel, BorderLayout.NORTH);
unitQuirksPanel.add(new JScrollPane(listQuirkType.getComponent()), BorderLayout.CENTER);
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
buttonPanel.add(btnQuirksClear);
unitQuirksPanel.add(buttonPanel, BorderLayout.SOUTH);

JPanel weaponQuirkPanel = new JPanel(new BorderLayout());
JPanel weaponQuirkIEPanel = new JPanel(new FlowLayout());
JPanel weaponQuirkIEPanel = new JPanel();
weaponQuirkIEPanel.add(new JLabel(Messages.getString("MekSelectorDialog.Search.WeaponQuirk")));
weaponQuirkIEPanel.add(Box.createHorizontalStrut(15));
weaponQuirkIEPanel.add(new JLabel("\u2611"));
Expand Down
Loading

0 comments on commit a654d22

Please sign in to comment.