Skip to content

Commit

Permalink
reword the equipment search tab
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Oct 21, 2024
1 parent 20a6873 commit 3b8e964
Show file tree
Hide file tree
Showing 21 changed files with 645 additions and 575 deletions.
8 changes: 4 additions & 4 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2174,15 +2174,15 @@ 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=Has Weapon Type:
MekSelectorDialog.Search.Weapons=Has weapons:
MekSelectorDialog.Search.WeaponsAtLeast=At least
MekSelectorDialog.Search.Equipment=Has equipment:
MekSelectorDialog.Search.WeaponClass=Weapon Type
MekSelectorDialog.Search.Weapons=Weapons
MekSelectorDialog.Search.Equipment=Equipment
MekSelectorDialog.Search.Year=Design year:
MekSelectorDialog.Search.TableFilters=Table filters:
MekSelectorDialog.Search.UnitType=Unit Type:
MekSelectorDialog.Search.TechClass=Tech Class:
MekSelectorDialog.Search.TechLevel=Tech Level:
MekSelectorDialog.Search.TableFilter=Filter Text:
MekSelectorDialog.Search.Quirk=Quirk:
MekSelectorDialog.Search.Quirks=Quirks
MekSelectorDialog.Search.WeaponQuirk=Weapon Quirk:
Expand Down
28 changes: 28 additions & 0 deletions megamek/src/megamek/client/ui/advancedsearch/AndFilterToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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 megamek.common.MekSearchFilter;

public class AndFilterToken extends OperatorFT {

public AndFilterToken() {
super(MekSearchFilter.BoolOp.AND);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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;

public class EquipmentFilterToken implements FilterToken {


}
103 changes: 37 additions & 66 deletions megamek/src/megamek/client/ui/advancedsearch/EquipmentTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
import megamek.common.TechConstants;

import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Vector;
import java.util.List;

/**
* A table model for displaying equipment
* A table model for the advanced search weapon tab's equipment list
*/
public class EquipmentTableModel extends AbstractTableModel {

Expand All @@ -40,7 +41,7 @@ public class EquipmentTableModel extends AbstractTableModel {

private final TWAdvancedSearchPanel twAdvancedSearchPanel;
private int[] qty;
private Vector<EquipmentType> equipment = new Vector<>();
private List<EquipmentType> equipment = new ArrayList<>();

public EquipmentTableModel(TWAdvancedSearchPanel twAdvancedSearchPanel) {
this.twAdvancedSearchPanel = twAdvancedSearchPanel;
Expand All @@ -57,38 +58,26 @@ public int getColumnCount() {
}

public int getPreferredWidth(int col) {
switch (col) {
case COL_QTY:
return 40;
case COL_NAME:
return 400;
case COL_IS_CLAN:
return 75;
case COL_COST:
return 175;
case COL_LEVEL:
return 100;
default:
return 0;
}
return switch (col) {
case COL_QTY -> 40;
case COL_NAME -> 400;
case COL_IS_CLAN -> 75;
case COL_COST -> 175;
case COL_LEVEL -> 100;
default -> 0;
};
}

@Override
public String getColumnName(int column) {
switch (column) {
case COL_QTY:
return "Qty";
case COL_NAME:
return "Name";
case COL_IS_CLAN:
return "IS/Clan";
case COL_COST:
return "Cost";
case COL_LEVEL:
return "Lvl";
default:
return "?";
}
return switch (column) {
case COL_QTY -> "Qty";
case COL_NAME -> "Name";
case COL_IS_CLAN -> "IS/Clan";
case COL_COST -> "Cost";
case COL_LEVEL -> "Lvl";
default -> "?";
};
}

@Override
Expand All @@ -98,61 +87,43 @@ public Class<?> getColumnClass(int c) {

@Override
public boolean isCellEditable(int row, int col) {
switch (col) {
case COL_QTY:
return true;
default:
return false;
}
return col == COL_QTY;
}

// fill table with values
public void setData(Vector<EquipmentType> eq) {
public void setData(List<EquipmentType> eq) {
equipment = eq;
qty = new int[eq.size()];
Arrays.fill(qty, 1);
fireTableDataChanged();
}

public EquipmentType getEquipmentTypeAt(int row) {
return equipment.elementAt(row);
return equipment.get(row);
}

@Override
public Object getValueAt(int row, int col) {
if (row >= equipment.size()) {
return null;
}
EquipmentType eq = equipment.elementAt(row);
switch (col) {
case COL_QTY:
return qty[row] + "";
case COL_NAME:
return eq.getName();
case COL_IS_CLAN:
return TechConstants.getTechName(eq.getTechLevel(twAdvancedSearchPanel.gameYear));
case COL_COST:
return eq.getRawCost();
case COL_LEVEL:
return TechConstants.getSimpleLevelName(TechConstants
.convertFromNormalToSimple(eq
.getTechLevel(twAdvancedSearchPanel.gameYear)));
case COL_INTERNAL_NAME:
return eq.getInternalName();
default:
return "?";
}
EquipmentType eq = equipment.get(row);
return switch (col) {
case COL_QTY -> qty[row] + "";
case COL_NAME -> eq.getName();
case COL_IS_CLAN -> TechConstants.getTechName(eq.getTechLevel(twAdvancedSearchPanel.gameYear));
case COL_COST -> eq.getRawCost();
case COL_LEVEL -> TechConstants.getSimpleLevelName(
TechConstants.convertFromNormalToSimple(eq.getTechLevel(twAdvancedSearchPanel.gameYear)));
case COL_INTERNAL_NAME -> eq.getInternalName();
default -> "?";
};
}

@Override
public void setValueAt(Object value, int row, int col) {
switch (col) {
case COL_QTY:
qty[row] = Integer.parseInt((String) value);
fireTableCellUpdated(row, col);
break;
default:
break;
if (col == COL_QTY) {
qty[row] = Integer.parseInt((String) value);

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException Note

Potential uncaught 'java.lang.NumberFormatException'.
fireTableCellUpdated(row, col);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
*
* @author Arlith
*/
public class EquipmentFT extends FilterTokens {
public class EquipmentTypeFT extends EquipmentFilterToken {

public String internalName;
public String fullName;
public int qty;

public EquipmentFT(String in, String fn, int q) {
public EquipmentTypeFT(String in, String fn, int q) {
internalName = in;
fullName = fn;
qty = q;
Expand Down
28 changes: 28 additions & 0 deletions megamek/src/megamek/client/ui/advancedsearch/FilterToken.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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;

/**
* Marker interface for different tokens that can be in a filter expression.
*
* @author Arlith
*/
public interface FilterToken {

}
10 changes: 0 additions & 10 deletions megamek/src/megamek/client/ui/advancedsearch/FilterTokens.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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;

public class LeftParensFilterToken extends ParensFT {

public LeftParensFilterToken() {
super("(");
}
}
Loading

0 comments on commit 3b8e964

Please sign in to comment.