Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add additional filters to advance search #4131

Merged
merged 62 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
077e41c
add filter on EType
kuronekochomusuke Jan 23, 2023
8dd733f
add filter on EType 2
kuronekochomusuke Jan 23, 2023
1d3e1e5
add quirk filter
kuronekochomusuke Jan 23, 2023
50eecb9
add quirk filter 2
kuronekochomusuke Jan 23, 2023
12fa9cb
add quirk filter 3
kuronekochomusuke Jan 23, 2023
fb6631d
add quirk filter 4
kuronekochomusuke Jan 23, 2023
2c7f767
add quirk filter 5
kuronekochomusuke Jan 23, 2023
afa4ab2
add omni filter 5
kuronekochomusuke Jan 23, 2023
99993fa
add offical filter
kuronekochomusuke Jan 24, 2023
e4fad97
add tons bv filter
kuronekochomusuke Jan 24, 2023
68676e8
add engine type and clan engine filter
kuronekochomusuke Jan 24, 2023
886774c
add weapon quirk filter
kuronekochomusuke Jan 24, 2023
2295153
add source filter
kuronekochomusuke Jan 24, 2023
2d5a74e
add transport and space filters
kuronekochomusuke Jan 25, 2023
1a8c419
swap to range filters
kuronekochomusuke Jan 25, 2023
c0d720d
add caono filter
kuronekochomusuke Jan 25, 2023
1f87025
add entity type filter
kuronekochomusuke Jan 25, 2023
08bd5c0
add entity type filter 2
kuronekochomusuke Jan 25, 2023
d9a5f2d
reformat code
kuronekochomusuke Jan 25, 2023
1de3363
add quirk filter
kuronekochomusuke Jan 26, 2023
df39904
add quirk filter
kuronekochomusuke Jan 26, 2023
f203474
switch to jlist
kuronekochomusuke Jan 26, 2023
79e865c
include OR
kuronekochomusuke Jan 26, 2023
4542428
include OR
kuronekochomusuke Jan 26, 2023
07dbc8d
include OR
kuronekochomusuke Jan 26, 2023
9aa4a36
fix error from changing to jlist
kuronekochomusuke Jan 27, 2023
3f00495
use AdvancedSearchDialog2 with RandomArmyDialog
kuronekochomusuke Jan 27, 2023
ae92007
bug
kuronekochomusuke Jan 28, 2023
6b85593
bug
kuronekochomusuke Jan 28, 2023
527cfa9
bug
kuronekochomusuke Jan 28, 2023
164d85c
layout
kuronekochomusuke Jan 28, 2023
bb24608
quirks and or
kuronekochomusuke Jan 28, 2023
f24c0f7
add unit role filter
kuronekochomusuke Jan 28, 2023
a885aab
bug
kuronekochomusuke Jan 28, 2023
f48389a
add filter on EType
kuronekochomusuke Jan 29, 2023
1d92c72
layout
kuronekochomusuke Jan 29, 2023
fc51e10
doors, units, transport tab
kuronekochomusuke Jan 29, 2023
7babac3
isBetween
kuronekochomusuke Jan 29, 2023
4d43544
add transport filters
kuronekochomusuke Jan 30, 2023
55aa35c
add transport filters
kuronekochomusuke Jan 30, 2023
d2fe6ff
add filter on military
kuronekochomusuke Jan 31, 2023
e81ff93
unit count, out of
kuronekochomusuke Jan 31, 2023
a3e4a69
code cleanup
kuronekochomusuke Jan 31, 2023
949c2df
code formating
kuronekochomusuke Jan 31, 2023
a720cb6
add bv total
kuronekochomusuke Jan 31, 2023
9bf6837
fix warnings
kuronekochomusuke Jan 31, 2023
38b7e16
add filter tank turrets
kuronekochomusuke Feb 1, 2023
f147c0d
tab order and table total by col
kuronekochomusuke Feb 7, 2023
2ad84f0
jlabel
kuronekochomusuke Feb 7, 2023
5f104db
code cleanup
kuronekochomusuke Feb 8, 2023
8671fcc
code cleanup
kuronekochomusuke Feb 8, 2023
1c840bd
set blank to ranges to max instead of -1
kuronekochomusuke Feb 8, 2023
a1f3a73
add filters lower arms and hands
kuronekochomusuke Feb 9, 2023
10f6cf9
code cleanup
kuronekochomusuke Feb 9, 2023
54b618d
clear tab
kuronekochomusuke Feb 9, 2023
ecabdd9
TriStateItem
kuronekochomusuke Feb 9, 2023
eb36bb9
code cleanup
kuronekochomusuke Feb 10, 2023
85a5199
remove unneeded DefaultListModel
kuronekochomusuke Feb 12, 2023
2148ab2
code cleanup
kuronekochomusuke Feb 13, 2023
df85e73
code cleanup
kuronekochomusuke Feb 14, 2023
525284c
code cleanup
kuronekochomusuke Feb 14, 2023
43807a1
code cleanup
kuronekochomusuke Feb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1935,9 +1935,21 @@ MechSelectorDialog.Search.TableFilters=Table filters:
MechSelectorDialog.Search.UnitType=Unit Type:
MechSelectorDialog.Search.TechClass=Tech Class:
MechSelectorDialog.Search.TechLevel=Tech Level:
MechSelectorDialog.Search.Quirk=Quirk:
MechSelectorDialog.SupportVee=Support Vehicle
MechSelectorDialog.title=Select Unit
MechSelectorDialog.BV=Show BV calculation
MechSelectorDialog.Search.LAM=LAM
MechSelectorDialog.Search.Quad=Quad
MechSelectorDialog.Search.Tripod=Tripod
MechSelectorDialog.Search.QuadVee=Quad VEE
MechSelectorDialog.Search.SupportVTOL=Support VTOL
MechSelectorDialog.Search.FixedWingSupport=Fixed Wing Support
MechSelectorDialog.Search.SuperHeavyTank=Super Heavy Tank
MechSelectorDialog.Search.SupportTank=Support Tank
MechSelectorDialog.Search.LargeSupportTank=Large Support Tank



#Mechview (Lobby, MHQ, Etc)
MechView.ActiveFighters=Active Fighters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import megamek.client.ui.swing.table.MegamekTable;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.*;
import megamek.common.options.IOption;
import megamek.common.options.IOptionGroup;
import megamek.common.options.Quirks;
import megamek.common.options.WeaponQuirks;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
Expand All @@ -36,7 +40,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
import java.util.stream.Collectors;

/**
* Panel that allows the user to create a unit filter.
Expand Down Expand Up @@ -119,6 +125,20 @@ public class TWAdvancedSearchPanel extends JPanel implements ActionListener, Ite
private JLabel lblArmorType = new JLabel(Messages.getString("MechSelectorDialog.Search.ArmorType"));
private JComboBox<String> cboArmorType = new JComboBox<>();

private JCheckBox cbxEnableQuirkSearch = new JCheckBox(Messages.getString("MechSelectorDialog.Search.Enable"));
private JLabel lblQuirkType = new JLabel(Messages.getString("MechSelectorDialog.Search.Quirk"));
private JComboBox<String> cboQuirkType = new JComboBox<>();

private JCheckBox cbxFilterLAM = new JCheckBox(Messages.getString("MechSelectorDialog.Search.LAM"));
private JCheckBox cbxfilterQuad= new JCheckBox(Messages.getString("MechSelectorDialog.Search.Quad"));
private JCheckBox cbxFilterTripod = new JCheckBox(Messages.getString("MechSelectorDialog.Search.Tripod"));
private JCheckBox cbxfilterQuadVee = new JCheckBox(Messages.getString("MechSelectorDialog.Search.QuadVee"));
private JCheckBox cbxfilterSupportVTOL = new JCheckBox(Messages.getString("MechSelectorDialog.Search.SupportVTOL"));
private JCheckBox cbxfilterFixedWingSupport = new JCheckBox(Messages.getString("MechSelectorDialog.Search.FixedWingSupport"));
private JCheckBox cbxFilterSuperHeavyTank = new JCheckBox(Messages.getString("MechSelectorDialog.Search.SuperHeavyTank"));
private JCheckBox cbxFilterSupportTank = new JCheckBox(Messages.getString("MechSelectorDialog.Search.SupportTank"));
private JCheckBox cbxFilterLargeSupportTank = new JCheckBox(Messages.getString("MechSelectorDialog.Search.LargeSupportTank"));

private JComboBox<String> cboQty = new JComboBox<>();

/** The game's current year. */
Expand Down Expand Up @@ -165,6 +185,36 @@ public TWAdvancedSearchPanel(int year) {
cboArmorType.setEnabled(false);
lblArmorType.setEnabled(false);

Quirks quirks = new Quirks();
List<String> qs = new ArrayList<>();
for (final Enumeration<IOptionGroup> optionGroups = quirks.getGroups(); optionGroups.hasMoreElements();) {
final IOptionGroup group = optionGroups.nextElement();
for (final Enumeration<IOption> options = group.getOptions(); options.hasMoreElements(); ) {
final IOption option = options.nextElement();
if (option != null) {
qs.add(option.getDisplayableNameWithValue());
}
}
}
WeaponQuirks weaponquirks = new WeaponQuirks();
for (final Enumeration<IOptionGroup> optionGroups = weaponquirks.getGroups(); optionGroups.hasMoreElements();) {
final IOptionGroup group = optionGroups.nextElement();
for (final Enumeration<IOption> options = group.getOptions(); options.hasMoreElements(); ) {
final IOption option = options.nextElement();
if (option != null) {
qs.add(option.getDisplayableNameWithValue());
}
}
}
qs = qs.stream().sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList());

for (String q : qs) {
cboQuirkType.addItem(q);
}

cboQuirkType.setEnabled(false);
lblQuirkType.setEnabled(false);

for (int i = 0; i < EquipmentType.structureNames.length; i++) {
cboInternalsType.addItem(EquipmentType.structureNames[i]);
}
Expand All @@ -183,12 +233,33 @@ public TWAdvancedSearchPanel(int year) {
cbxEnableInternalsSearch.addItemListener(this);
cbxEnableArmorSearch.setHorizontalTextPosition(SwingConstants.LEFT);
cbxEnableArmorSearch.addItemListener(this);
cbxEnableQuirkSearch.setHorizontalTextPosition(SwingConstants.LEFT);
cbxEnableQuirkSearch.addItemListener(this);

for (int i = 1; i <= 20; i++) {
cboQty.addItem(Integer.toString(i));
}
cboQty.setSelectedIndex(0);

cbxFilterLAM.setHorizontalTextPosition(SwingConstants.RIGHT);
cbxFilterLAM.addItemListener(this);
cbxfilterQuad.setHorizontalTextPosition(SwingConstants.RIGHT);
cbxfilterQuad.addItemListener(this);
cbxFilterTripod.setHorizontalTextPosition(SwingConstants.RIGHT);
cbxFilterTripod.addItemListener(this);
cbxfilterQuadVee.setHorizontalTextPosition(SwingConstants.RIGHT);
cbxfilterQuadVee.addItemListener(this);
cbxfilterSupportVTOL.setHorizontalTextPosition(SwingConstants.RIGHT);
cbxfilterSupportVTOL.addItemListener(this);
cbxfilterFixedWingSupport.setHorizontalTextPosition(SwingConstants.RIGHT);
cbxfilterFixedWingSupport.addItemListener(this);
cbxFilterSuperHeavyTank.setHorizontalTextPosition(SwingConstants.RIGHT);
cbxFilterSuperHeavyTank.addItemListener(this);
cbxFilterSupportTank.setHorizontalTextPosition(SwingConstants.RIGHT);
cbxFilterSupportTank.addItemListener(this);
cbxFilterLargeSupportTank.setHorizontalTextPosition(SwingConstants.RIGHT);
cbxFilterLargeSupportTank.addItemListener(this);

// Setup table filter combo boxes
DefaultComboBoxModel<String> unitTypeModel = new DefaultComboBoxModel<>();
unitTypeModel.addElement(Messages.getString("MechSelectorDialog.All"));
Expand Down Expand Up @@ -304,59 +375,64 @@ public TWAdvancedSearchPanel(int year) {
c.weighty = 0;
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.WEST;
c.insets = new Insets(0, 10, 0, 0);
c.gridx = 0; c.gridy = 0;
this.add(lblWalk, c);
c.gridx = 1; c.gridy = 0;
c.insets = new Insets(0, 0, 0, 0);
c.anchor = GridBagConstraints.EAST;
JPanel panWalk = new JPanel();
panWalk.add(cWalk);
panWalk.add(tWalk);
this.add(panWalk, c);
c.gridx = 3; c.gridy = 0;
c.insets = new Insets(0, 40, 0, 0);
c.gridwidth = 4;
c.insets = new Insets(0, 10, 0, 0);
JPanel p1Panel = new JPanel();
p1Panel.add(lblWalk);
p1Panel.add(cWalk);
p1Panel.add(tWalk);
p1Panel.add(lblJump);
p1Panel.add(cJump);
p1Panel.add(tJump);
p1Panel.add(lblArmor);
p1Panel.add(cArmor);
this.add(p1Panel, c);

c.gridx = 0; c.gridy++;;
c.gridwidth = 1;
c.insets = new Insets(0, 10, 0, 0);
c.anchor = GridBagConstraints.WEST;
JPanel cockpitPanel = new JPanel();
cockpitPanel.add(cbxEnableCockpitSearch,BorderLayout.WEST);
cockpitPanel.add(lblCockpitType,BorderLayout.WEST);
cockpitPanel.add(cboCockpitType,BorderLayout.EAST);
this.add(cockpitPanel, c);

c.gridx = 0; c.gridy = 1;
c.anchor = GridBagConstraints.WEST;
c.insets = new Insets(0, 10, 0, 0);
this.add(lblJump, c);
c.insets = new Insets(0, 0, 0, 0);
c.gridx = 1; c.gridy = 1;
c.anchor = GridBagConstraints.EAST;
JPanel panJump = new JPanel();
panJump.add(cJump);
panJump.add(tJump);
this.add(panJump, c);
c.anchor = GridBagConstraints.WEST;
c.gridx = 3; c.gridy = 1;
c.insets = new Insets(0, 40, 0, 0);
c.gridx = 1;
JPanel internalsPanel = new JPanel();
internalsPanel.add(cbxEnableInternalsSearch);
internalsPanel.add(lblInternalsType);
internalsPanel.add(cboInternalsType,BorderLayout.EAST);
this.add(internalsPanel, c);

c.anchor = GridBagConstraints.WEST;
c.gridx = 0; c.gridy++;
c.insets = new Insets(0, 10, 0, 0);
this.add(lblArmor, c);
c.insets = new Insets(0, 0, 0, 0);
c.gridx = 1;
this.add(cArmor, c);
c.gridx = 3;
c.insets = new Insets(0, 40, 0, 0);
c.gridx = 0; c.gridy++;;
JPanel armorPanel = new JPanel();
armorPanel.add(cbxEnableArmorSearch);
armorPanel.add(lblArmorType);
armorPanel.add(cboArmorType,BorderLayout.EAST);
this.add(armorPanel, c);
c.gridx = 1;
JPanel quirkPanel = new JPanel();
quirkPanel.add(cbxEnableQuirkSearch);
quirkPanel.add(lblQuirkType);
quirkPanel.add(cboQuirkType,BorderLayout.EAST);
this.add(quirkPanel, c);

c.anchor = GridBagConstraints.WEST;
c.gridx = 0; c.gridy++;
c.gridwidth = 4;
c.insets = new Insets(0, 10, 0, 0);
JPanel filterEntityPanel = new JPanel();
filterEntityPanel.add(cbxFilterLAM);
filterEntityPanel.add(cbxFilterTripod);
filterEntityPanel.add(cbxfilterQuad);
filterEntityPanel.add(cbxfilterQuadVee);
filterEntityPanel.add(cbxfilterSupportVTOL);
filterEntityPanel.add(cbxfilterFixedWingSupport);
filterEntityPanel.add(cbxFilterSupportTank);
filterEntityPanel.add(cbxFilterLargeSupportTank);
filterEntityPanel.add(cbxFilterSuperHeavyTank);
this.add(filterEntityPanel, c);

c.anchor = GridBagConstraints.CENTER;
c.insets = new Insets(16, 0, 0, 0);
Expand Down Expand Up @@ -458,6 +534,9 @@ public void itemStateChanged(ItemEvent e) {
} else if (e.getSource().equals(cbxEnableArmorSearch)) {
cboArmorType.setEnabled(!cboArmorType.isEnabled());
lblArmorType.setEnabled(!lblArmorType.isEnabled());
} else if (e.getSource().equals(cbxEnableQuirkSearch)) {
cboQuirkType.setEnabled(!cboQuirkType.isEnabled());
lblQuirkType.setEnabled(!lblQuirkType.isEnabled());
}
}

Expand Down Expand Up @@ -830,9 +909,20 @@ public void clearValues() {
tblEquipment.clearSelection();
txtEqExp.setText("");
cbxEnableArmorSearch.setSelected(false);
cbxEnableQuirkSearch.setSelected(false);
cbxEnableCockpitSearch.setSelected(false);
cbxEnableInternalsSearch.setSelected(false);
cboArmorType.setSelectedIndex(0);
cboQuirkType.setSelectedIndex(0);
cbxFilterLAM.setSelected(false);
cbxfilterQuad.setSelected(false);
cbxFilterTripod.setSelected(false);
cbxfilterQuadVee.setSelected(false);
cbxfilterSupportVTOL.setSelected(false);
cbxfilterFixedWingSupport.setSelected(false);
cbxFilterSuperHeavyTank.setSelected(false);
cbxFilterSupportTank.setSelected(false);
cbxFilterLargeSupportTank.setSelected(false);
cboCockpitType.setSelectedIndex(0);
cboInternalsType.setSelectedIndex(0);
mechFilter = null;
Expand Down Expand Up @@ -892,6 +982,11 @@ protected void updateMechSearchFilter() {
mechFilter.armorType = cboArmorType.getSelectedIndex();
}

mechFilter.checkQuirkType = cbxEnableQuirkSearch.isSelected();
if (cbxEnableQuirkSearch.isSelected()) {
mechFilter.quirkType = cboQuirkType.getSelectedItem().toString();
}

mechFilter.checkInternalsType = cbxEnableInternalsSearch.isSelected();
if (cbxEnableInternalsSearch.isSelected()) {
mechFilter.internalsType = cboInternalsType.getSelectedIndex();
Expand All @@ -901,6 +996,16 @@ protected void updateMechSearchFilter() {
if (cbxEnableCockpitSearch.isSelected()) {
mechFilter.cockpitType = cboCockpitType.getSelectedIndex();
}

mechFilter.filterLAM = cbxFilterLAM.isSelected();
mechFilter.filterQuad = cbxfilterQuad.isSelected();
mechFilter.filterTripod = cbxFilterTripod.isSelected();
mechFilter.filterQuadVee = cbxfilterQuadVee.isSelected();
mechFilter.filterSupportVTOL = cbxfilterSupportVTOL.isSelected();
mechFilter.filterFixedWingSupport = cbxfilterFixedWingSupport.isSelected();
mechFilter.filterSuperHeavyTank = cbxFilterSuperHeavyTank.isSelected();
mechFilter.filterSupportTank = cbxFilterSupportTank.isSelected();
mechFilter.filterLargeSupportTank = cbxFilterLargeSupportTank.isSelected();
}

public class WeaponClassTableModel extends AbstractTableModel {
Expand Down
56 changes: 56 additions & 0 deletions megamek/src/megamek/common/MechSearchFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package megamek.common;

import com.sun.source.tree.ExpressionTree;
import megamek.client.ui.swing.unitSelector.TWAdvancedSearchPanel;
import org.apache.logging.log4j.LogManager;

Expand Down Expand Up @@ -48,12 +49,26 @@ public enum BoolOp { AND, OR, NOP }

public boolean checkArmorType;
public int armorType;

public boolean checkQuirkType;
public String quirkType;
public boolean checkInternalsType;
public int internalsType;
public boolean checkCockpitType;
public int cockpitType;

public boolean checkEquipment;

public boolean filterLAM;
public boolean filterQuad;
public boolean filterTripod;
public boolean filterQuadVee;
public boolean filterSupportVTOL;
public boolean filterFixedWingSupport;
public boolean filterSuperHeavyTank;
public boolean filterSupportTank;
public boolean filterLargeSupportTank;

public ExpressionTree equipmentCriteria;


Expand All @@ -62,6 +77,8 @@ public MechSearchFilter()
isDisabled = true;
checkArmorType = checkInternalsType = checkCockpitType = false;
checkEquipment = false;
filterLAM = filterQuad = filterTripod = filterQuadVee = filterSupportVTOL = false;
filterFixedWingSupport = filterSuperHeavyTank = filterSupportTank = filterLargeSupportTank = false;
equipmentCriteria = new ExpressionTree();
}

Expand Down Expand Up @@ -350,6 +367,45 @@ public static boolean isMatch(MechSummary mech, MechSearchFilter f) {
return false;
}

long l = 0;
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
if (f.filterLAM) {
l = l | Entity.ETYPE_LAND_AIR_MECH;
}
if (f.filterQuad) {
l = l | Entity.ETYPE_QUAD_MECH;
}
if (f.filterTripod) {
l = l | Entity.ETYPE_TRIPOD_MECH;
}
if (f.filterQuadVee) {
l = l | Entity.ETYPE_QUADVEE;
}
if (f.filterSupportVTOL) {
l = l | Entity.ETYPE_SUPPORT_VTOL;
}
if (f.filterFixedWingSupport) {
l = l | Entity.ETYPE_FIXED_WING_SUPPORT;
}
if (f.filterSuperHeavyTank) {
l = l | Entity.ETYPE_SUPER_HEAVY_TANK;
}
if (f.filterSupportTank) {
l = l | Entity.ETYPE_SUPPORT_TANK;
}
if (f.filterLargeSupportTank) {
l = l | Entity.ETYPE_LARGE_SUPPORT_TANK;
}

if ((!((mech.getEntityType() & l) > 0)) && (l != 0)) {
return false;
}

if (f.checkQuirkType) {
if ((!mech.getQuirkNames().contains(f.quirkType)) && (!mech.getWeaponQuirkNames().contains(f.quirkType))) {
return false;
}
}

return true;
}

Expand Down
Loading