Skip to content

Commit

Permalink
Equipment Database: Allow showing all ammo (for ammo trailer units)
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Jul 15, 2023
1 parent 9e1bdc1 commit a22a802
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public abstract class AbstractEquipmentDatabaseView extends IView {
protected final JToggleButton hideOneShotButton = new JToggleButton(ONE_SHOT.getDisplayName());
protected final JToggleButton hideTorpedoButton = new JToggleButton(TORPEDO.getDisplayName());
protected final JToggleButton hideAPButton = new JToggleButton(AP.getDisplayName());
protected final JToggleButton hideUnusableAmmoButton = new JToggleButton(UNUSABLE_AMMO.getDisplayName(), true);
protected final JToggleButton hideUnavailButton = new JToggleButton(UNAVAILABLE.getDisplayName(), true);

protected final JTextField txtFilter = new JTextField("", 15);
Expand All @@ -90,15 +91,16 @@ public abstract class AbstractEquipmentDatabaseView extends IView {

private final Map<JToggleButton, EquipmentDatabaseCategory> hideToggles = Map.of(hideProtoButton, PROTOTYPE,
hideOneShotButton, ONE_SHOT, hideTorpedoButton, TORPEDO, hideAPButton, AP,
hideUnavailButton, UNAVAILABLE);
hideUnusableAmmoButton, UNUSABLE_AMMO, hideUnavailButton, UNAVAILABLE);

private static final String ADD_TEXT = " << Add ";

protected AbstractEquipmentDatabaseView(EntitySource eSource) {
super(eSource);
masterEquipmentModel = new EquipmentTableModel(eSource.getEntity(), eSource.getTechManager());
masterEquipmentTable = new EquipmentDatabaseTable(masterEquipmentModel);
masterEquipmentTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "add");
masterEquipmentTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "add");
masterEquipmentTable.getActionMap().put("add", addAction);

equipmentSorter = new TableRowSorter<>(masterEquipmentModel);
Expand Down Expand Up @@ -353,6 +355,7 @@ public void componentResized(ComponentEvent e) {
buttonPanel.add(hideOneShotButton);
buttonPanel.add(hideTorpedoButton);
buttonPanel.add(hideAPButton);
buttonPanel.add(hideUnusableAmmoButton);
buttonPanel.add(hideUnavailButton);

var hideFilterPanel = Box.createHorizontalBox();
Expand Down Expand Up @@ -592,7 +595,8 @@ private boolean hiddenEquipment(EquipmentType equipment) {
return (hideProtoButton.isSelected() && PROTOTYPE.passesFilter(equipment, getEntity()))
|| (hideOneShotButton.isSelected() && ONE_SHOT.passesFilter(equipment, getEntity()))
|| (hideTorpedoButton.isSelected() && TORPEDO.passesFilter(equipment, getEntity()))
|| (hideAPButton.isSelected() && AP.passesFilter(equipment, getEntity()));
|| (hideAPButton.isSelected() && AP.passesFilter(equipment, getEntity()))
|| (hideUnusableAmmoButton.isSelected() && UNUSABLE_AMMO.passesFilter(equipment, getEntity()));
}

/**
Expand Down
10 changes: 7 additions & 3 deletions megameklab/src/megameklab/ui/util/EquipmentDatabaseCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public enum EquipmentDatabaseCategory {
e -> (e instanceof Tank) || e.isSupportVehicle()),

AMMO ("Ammo",
(eq, en) -> (eq instanceof AmmoType) && !(eq instanceof BombType)
&& UnitUtil.canUseAmmo(en, (AmmoType) eq, false),
(eq, en) -> (eq instanceof AmmoType) && !(eq instanceof BombType),
// && UnitUtil.canUseAmmo(en, (AmmoType) eq, false),
e -> e.getWeightClass() != EntityWeightClass.WEIGHT_SMALL_SUPPORT),

OTHER ("Other",
Expand Down Expand Up @@ -111,8 +111,12 @@ public enum EquipmentDatabaseCategory {
|| ((WeaponType) eq).getAmmoType() == AmmoType.T_SRM_TORPEDO),
e -> !(e instanceof BattleArmor) && !(e instanceof Aero)),

UNAVAILABLE ("Unavailable")
UNAVAILABLE ("Unavailable"),
// TODO: Provide MM.ITechManager.isLegal in static form

UNUSABLE_AMMO("Ammo w/o Weapon",
(eq, en) -> (eq instanceof AmmoType) && !(eq instanceof BombType)
&& !UnitUtil.canUseAmmo(en, (AmmoType) eq, false))
;

private final static Set<EquipmentDatabaseCategory> showFilters = EnumSet.of(ENERGY, BALLISTIC, MISSILE,
Expand Down

0 comments on commit a22a802

Please sign in to comment.