Skip to content

Commit

Permalink
Merge pull request #4207 from kuronekochomusuke/filterTechLevelBase
Browse files Browse the repository at this point in the history
add filters tech level and tech base
  • Loading branch information
SJuliez authored Feb 28, 2023
2 parents ac45947 + 186ef0a commit 5f58490
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 13 deletions.
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 @@ -393,11 +399,11 @@ public String toString() {
}
}

private void loadTriStateItem(String[] s, JList l, int count) {
private void loadTriStateItem(List<String> s, JList l, int count) {
DefaultListModel dlma = new DefaultListModel();

for (int i = 0; i < s.length; i++) {
dlma.addElement(new TriStateItem("\u2610", s[i]));
for (String desc : s) {
dlma.addElement(new TriStateItem("\u2610", desc));
}

l.setModel(dlma);
Expand Down Expand Up @@ -441,10 +447,12 @@ private JPanel createBasePanel() {
loadYesNo(cInvalid);
loadYesNo(cFailedToLoadEquipment);

loadTriStateItem(EquipmentType.armorNames, listArmorType, 7);
loadTriStateItem(Mech.COCKPIT_STRING, listCockpitType, 7);
loadTriStateItem(EquipmentType.structureNames, listInternalsType, 7);
loadTriStateItem(EquipmentType.getArmorNames(), listArmorType, 7);
loadTriStateItem(Mech.getCockpitDescrtiption(), listCockpitType, 7);
loadTriStateItem(EquipmentType.getStructureNames(), 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
8 changes: 3 additions & 5 deletions megamek/src/megamek/common/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,13 @@ public String getShortEngineName() {
}
}

public static String[] getEngineTypes() {
List<String> engineTypes = new ArrayList<String>();
public static List<String> getEngineTypes() {
List<String> result = new ArrayList<String>();

for (int i = 0; i < Engine.NUM_ENGINE_TYPES; i++) {
engineTypes.add(Messages.getString("Engine." + TYPE_KEYS[i]));
result.add(Messages.getString("Engine." + TYPE_KEYS[i]));
}

String[] result = new String[ engineTypes.size() ];
engineTypes.toArray(result);
return result;
}

Expand Down
29 changes: 29 additions & 0 deletions megamek/src/megamek/common/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,35 @@ 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 List<String> getTechBaseDescriptions(){
List<String> result = new ArrayList<>();
result.add(Messages.getString("Entity.IS"));
result.add(Messages.getString("Entity.Clan"));
result.add(Messages.getString("Entity.MixedIS"));
result.add(Messages.getString("Entity.MixedClan"));

return result;
}

@Override
public int getBaseAvailability(int era) {
return compositeTechLevel.getBaseAvailability(era);
Expand Down
8 changes: 8 additions & 0 deletions megamek/src/megamek/common/EquipmentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -1512,4 +1512,12 @@ public boolean isAnyOf(String typeInternalName, String... typeInternalNames) {
public boolean is(String typeInternalName) {
return isAnyOf(typeInternalName);
}

public static List<String> getStructureNames() {
return Arrays.stream(structureNames).collect(Collectors.toList());
}

public static List<String> getArmorNames() {
return Arrays.stream(armorNames).collect(Collectors.toList());
}
}
4 changes: 4 additions & 0 deletions megamek/src/megamek/common/Mech.java
Original file line number Diff line number Diff line change
Expand Up @@ -6571,4 +6571,8 @@ public boolean isIndustrialMek() {
public boolean getsAutoExternalSearchlight() {
return true;
}

public static List<String> getCockpitDescrtiption() {
return Arrays.stream(COCKPIT_STRING).collect(Collectors.toList());
}
}
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
8 changes: 8 additions & 0 deletions megamek/src/megamek/common/SimpleTechLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

import megamek.common.options.OptionsConstants;

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

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

public static List<String> getDescriptions() {
return Arrays.stream(SimpleTechLevel.values()).map(e -> e.strVal).collect(Collectors.toList());
}
}

0 comments on commit 5f58490

Please sign in to comment.