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 filters tech level and tech base #4207

Merged
merged 3 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,7 @@ MechSelectorDialog.Search.LowerArms=Lower Arms:
MechSelectorDialog.Search.Hands=Hands:
MechSelectorDialog.Search.Invalid=Invalid:
MechSelectorDialog.Search.FailedToLoadEquipment=Failed to load equipment:
MechSelectorDialog.Search.TechBase=Tech Base:

#Mechview (Lobby, MHQ, Etc)
MechView.ActiveFighters=Active Fighters
Expand Down
6 changes: 6 additions & 0 deletions megamek/i18n/megamek/common/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ Engine.Battery=\ Battery
Engine.Solar=\ Solar
Engine.MagLev=\ MagLev
Engine.External=\ External

Entity.sensor_range_vs_ground_target=Air to Ground Range
Entity.Clan=Clan
Entity.IS=Inner Sphere
Entity.MixedClan=Mixed Clan
Entity.MixedIS=Mixed Inner Sphere

EntityWeightClass.0=Ultra Light/PA(L)/Exoskeleton
EntityWeightClass.1=Light
EntityWeightClass.2=Medium
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class TWAdvancedSearchPanel extends JPanel implements ActionListener, Ite
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
private JLabel lblUnitType = new JLabel(Messages.getString("MechSelectorDialog.Search.UnitType"));
private JLabel lblTechClass = new JLabel(Messages.getString("MechSelectorDialog.Search.TechClass"));
private JLabel lblTechLevel = new JLabel(Messages.getString("MechSelectorDialog.Search.TechLevel"));
private JLabel lblTechLevelBase = new JLabel(Messages.getString("MechSelectorDialog.Search.TechLevel"));
private JComboBox<String> cboUnitType = new JComboBox<>();
private JComboBox<String> cboTechClass = new JComboBox<>();
private JComboBox<String> cboTechLevel = new JComboBox<>();
Expand Down Expand Up @@ -149,6 +149,12 @@ public class TWAdvancedSearchPanel extends JPanel implements ActionListener, Ite
private JLabel lblEngineType = new JLabel(Messages.getString("MechSelectorDialog.Search.Engine"));
private JList<TriStateItem> listEngineType = new JList<>(new DefaultListModel<TriStateItem>());
private JScrollPane spEngineType = new JScrollPane(listEngineType);
private JLabel lblTechLevel = new JLabel(Messages.getString("MechSelectorDialog.Search.TechLevel"));
private JList<TriStateItem> listTechLevel = new JList<>(new DefaultListModel<TriStateItem>());
private JScrollPane spTechLevel = new JScrollPane(listTechLevel);
private JLabel lblTechBase = new JLabel(Messages.getString("MechSelectorDialog.Search.TechBase"));
private JList<TriStateItem> listTechBase = new JList<>(new DefaultListModel<TriStateItem>());
private JScrollPane spTechBase = new JScrollPane(listTechBase);

// Transports
private JButton btnTransportsClear = new JButton(Messages.getString("MechSelectorDialog.ClearTab"));
Expand Down Expand Up @@ -445,6 +451,8 @@ private JPanel createBasePanel() {
loadTriStateItem(Mech.COCKPIT_STRING, listCockpitType, 7);
loadTriStateItem(EquipmentType.structureNames, listInternalsType, 7);
loadTriStateItem(Engine.getEngineTypes(), listEngineType, 5);
loadTriStateItem(SimpleTechLevel.getDescriptions(), listTechLevel, 5);
loadTriStateItem(Entity.getTechBaseDescriptions(), listTechBase, 4);

for (int i = 1; i <= 20; i++) {
cboQty.addItem(Integer.toString(i));
Expand Down Expand Up @@ -577,6 +585,17 @@ private JPanel createBasePanel() {
enginePanel.add(clanEnginePanel, BorderLayout.SOUTH);
basePanel.add(enginePanel, c);

c.gridx = 0; c.gridy++;;
JPanel techLevelPanel = new JPanel(new BorderLayout());
techLevelPanel.add(lblTechLevel, BorderLayout.NORTH);
techLevelPanel.add(spTechLevel, BorderLayout.CENTER);
basePanel.add(techLevelPanel, c);
c.gridx = 1;
JPanel techBasePanel = new JPanel(new BorderLayout());
techBasePanel.add(lblTechBase, BorderLayout.NORTH);
techBasePanel.add(spTechBase, BorderLayout.CENTER);
basePanel.add(techBasePanel, c);

c.weighty = 1;
JPanel blankPanel = new JPanel();
c.gridx = 0; c.gridy++;;
Expand Down Expand Up @@ -1230,7 +1249,7 @@ private JPanel createWeaponEqPanel() {
cboPanel.add(cboUnitType);
cboPanel.add(lblTechClass);
cboPanel.add(cboTechClass);
cboPanel.add(lblTechLevel, c);
cboPanel.add(lblTechLevelBase, c);
cboPanel.add(cboTechLevel, c);
weaponEqPanel.add(cboPanel, c);
c.gridwidth = 1;
Expand Down Expand Up @@ -1797,6 +1816,8 @@ private void clearBase() {
clearTriStateItem(listCockpitType);
clearTriStateItem(listEngineType);
clearTriStateItem(listInternalsType);
clearTriStateItem(listTechLevel);
clearTriStateItem(listTechBase);
}

private void clearTransports() {
Expand Down Expand Up @@ -2026,6 +2047,8 @@ private void updateBase() {
updateTriStateItemInteger(mechFilter.cockpitType, mechFilter.cockpitTypeExclude, listCockpitType);
updateTriStateItemInteger(mechFilter.internalsType, mechFilter.internalsTypeExclude, listInternalsType);
updateTriStateItemString(mechFilter.engineType, mechFilter.engineTypeExclude, listEngineType);
updateTriStateItemString(mechFilter.techLevel, mechFilter.techLevelExclude, listTechLevel);
updateTriStateItemString(mechFilter.techBase, mechFilter.techBaseExclude, listTechBase);
}

private void updateTransports() {
Expand Down
24 changes: 24 additions & 0 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,30 @@ public SimpleTechLevel getStaticTechLevel() {
return compositeTechLevel.getStaticTechLevel();
}

public String getTechBaseDescription() {
String techBase = "";
if (isMixedTech()) {
if (isClan()) {
techBase += Messages.getString("Entity.MixedClan");
} else {
techBase += Messages.getString("Entity.MixedIS");
}
} else {
if (isClan()) {
techBase += Messages.getString("Entity.Clan");
} else {
techBase += Messages.getString("Entity.IS");
}
}

return techBase;
}

public static String[] getTechBaseDescriptions(){
return new String[] {Messages.getString("Entity.IS"), Messages.getString("Entity.Clan"),
Messages.getString("Entity.MixedIS"), Messages.getString("Entity.MixedClan")};
}

@Override
public int getBaseAvailability(int era) {
return compositeTechLevel.getBaseAvailability(era);
Expand Down
22 changes: 22 additions & 0 deletions megamek/src/megamek/common/MechSearchFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ public enum BoolOp { AND, OR, NOP }

public List<Integer> cockpitType = new ArrayList<>();
public List<Integer> cockpitTypeExclude = new ArrayList<>();

public List<String> techLevel = new ArrayList<>();
public List<String> techLevelExclude = new ArrayList<>();

public List<String> techBase = new ArrayList<>();
public List<String> techBaseExclude = new ArrayList<>();
public int quirkInclude;
public int quirkExclude;
public List<String> quirkType = new ArrayList<>();
Expand Down Expand Up @@ -672,6 +678,22 @@ public static boolean isMatch(MechSummary mech, MechSearchFilter f) {
return false;
}

if ((!f.techLevel.isEmpty()) && (!anyMatch(f.techLevel, mech.getTechLevel()))) {
return false;
}

if ((!f.techLevelExclude.isEmpty()) && (anyMatch(f.techLevelExclude, mech.getTechLevel()))) {
return false;
}

if ((!f.techBase.isEmpty()) && (!anyMatch(f.techBase, mech.getTechBase()))) {
return false;
}

if ((!f.techBaseExclude.isEmpty()) && (anyMatch(f.techBaseExclude, mech.getTechBase()))) {
return false;
}

if (f.quirkInclude == 0) {
if ((!f.quirkType.isEmpty()) && (!allMatch(f.quirkType, mech.getQuirkNames()))) {
return false;
Expand Down
18 changes: 18 additions & 0 deletions megamek/src/megamek/common/MechSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class MechSummary implements Serializable, ASCardDisplayable {
private File sourceFile;
private String source;
private boolean invalid;
private String techLevel;
private String techBase;
private boolean failedToLoadEquipment;
private String entryName; // for files in zips
private int year;
Expand Down Expand Up @@ -247,6 +249,14 @@ public boolean getInvalid() {
return invalid;
}

public String getTechLevel() {
return techLevel;
}

public String getTechBase() {
return techBase;
}

public boolean getFailedToLoadEquipment() {
return failedToLoadEquipment;
}
Expand Down Expand Up @@ -795,6 +805,14 @@ public void setInvalid(boolean b) {
this.invalid = b;
}

public void setTechLevel(String s) {
this.techLevel = s;
}

public void setTechBase(String s) {
this.techBase = s;
}

public void setFailedToLoadEquipment(boolean b) {
this.failedToLoadEquipment = b;
}
Expand Down
3 changes: 3 additions & 0 deletions megamek/src/megamek/common/MechSummaryCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,9 @@ private MechSummary getSummary(Entity e, File f, String entry) {
ms.setInvalid(false);
}

ms.setTechLevel(e.getStaticTechLevel().toString());
ms.setTechBase(e.getTechBaseDescription());

ms.setFailedToLoadEquipment(e.getFailedEquipment().hasNext());

ms.setGyroType(e.getGyroType());
Expand Down
7 changes: 7 additions & 0 deletions megamek/src/megamek/common/SimpleTechLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import megamek.common.options.OptionsConstants;

import java.util.Arrays;
import java.util.stream.Collectors;

/**
* An enum for the various rules levels
*
Expand Down Expand Up @@ -112,4 +115,8 @@ public static SimpleTechLevel convertCompoundToSimple(int level) {
public static SimpleTechLevel getGameTechLevel(Game game) {
return SimpleTechLevel.parse(game.getOptions().stringOption(OptionsConstants.ALLOWED_TECHLEVEL));
}

public static String[] getDescriptions() {
return Arrays.stream(SimpleTechLevel.values()).map(e -> e.strVal).collect(Collectors.toList()).toArray(String []::new);
}
}