diff --git a/game-app/game-core/src/main/java/games/strategy/triplea/ui/UnitChooser.java b/game-app/game-core/src/main/java/games/strategy/triplea/ui/UnitChooser.java index 7cd81e59b62..ea0099c09f0 100644 --- a/game-app/game-core/src/main/java/games/strategy/triplea/ui/UnitChooser.java +++ b/game-app/game-core/src/main/java/games/strategy/triplea/ui/UnitChooser.java @@ -62,7 +62,6 @@ public final class UnitChooser extends JPanel { private final JLabel leftToSelect = new JLabel(); private final boolean allowMultipleHits; private JButton autoSelectButton; - private JButton selectNoneButton; private final Predicate> match; private final ScrollableTextFieldListener textFieldListener = new ScrollableTextFieldListener() { @@ -80,22 +79,13 @@ public void changedValue(final ScrollableTextField field) { UnitChooser( final Collection units, - final Map> dependent, - final boolean allowTwoHit, - final UiContext uiContext) { - this(units, List.of(), dependent, allowTwoHit, uiContext); - } - - private UnitChooser( - final Collection units, - final Collection defaultSelections, - final Map> dependent, + final @Nullable Map> dependents, final boolean allowTwoHit, final UiContext uiContext) { this( units, - defaultSelections, - dependent, + List.of(), + dependents, UnitSeparator.SeparatorCategories.builder().build(), allowTwoHit, uiContext); @@ -167,7 +157,6 @@ void setMax(final int max) { total = max; textFieldListener.changedValue(null); autoSelectButton.setVisible(false); - selectNoneButton.setVisible(false); } void setMaxAndShowMaxButton(final int max) { @@ -176,6 +165,10 @@ void setMaxAndShowMaxButton(final int max) { autoSelectButton.setText("Max"); } + public void setAllButtonVisible(boolean visible) { + autoSelectButton.setVisible(visible); + } + public void setTitle(final String title) { this.title.setText(title); this.title.setVisible(true); @@ -288,8 +281,6 @@ private void layoutEntries() { title.setVisible(false); final Insets emptyInsets = new Insets(0, 0, 0, 0); final Dimension buttonSize = new Dimension(80, 20); - selectNoneButton = new JButton("None"); - selectNoneButton.setPreferredSize(buttonSize); autoSelectButton = new JButton("All"); autoSelectButton.setPreferredSize(buttonSize); add( @@ -306,7 +297,6 @@ private void layoutEntries() { emptyInsets, 0, 0)); - selectNoneButton.addActionListener(e -> selectNone()); autoSelectButton.addActionListener(e -> autoSelect()); int rowIndex = 1; for (final ChooserEntry entry : entries) { @@ -343,8 +333,6 @@ private void layoutEntries() { 0, 0)); if (match != null) { - autoSelectButton.setVisible(false); - selectNoneButton.setVisible(false); checkMatches(); } } @@ -385,12 +373,6 @@ List getSelectedDamagedMultipleHitPointUnits() { return selectedUnits; } - private void selectNone() { - for (final ChooserEntry entry : entries) { - entry.selectNone(); - } - } - // does not take into account multiple hit points private void autoSelect() { if (total == -1) { @@ -463,13 +445,12 @@ public final class ChooserEntry { allowMultipleHits && category.getHitPoints() > 1 && category.getDamaged() < category.getHitPoints() - 1; - hitTexts = new ArrayList<>(Math.max(1, category.getHitPoints() - category.getDamaged())); - defaultHits = new ArrayList<>(Math.max(1, category.getHitPoints() - category.getDamaged())); + final int maxHitPoints = Math.max(1, category.getHitPoints() - category.getDamaged()); + hitTexts = new ArrayList<>(maxHitPoints); + defaultHits = new ArrayList<>(maxHitPoints); final int numUnits = category.getUnits().size(); int hitsUsedSoFar = 0; - for (int i = 0, m = Math.max(1, category.getHitPoints() - category.getDamaged()); - i < m; - i++) { + for (int i = 0; i < maxHitPoints; i++) { // TODO: check if default value includes damaged points or not final int hitsToUse = Math.min(numUnits, (defaultValue - hitsUsedSoFar)); hitsUsedSoFar += hitsToUse; diff --git a/game-app/game-core/src/main/java/games/strategy/triplea/ui/panel/move/MovePanel.java b/game-app/game-core/src/main/java/games/strategy/triplea/ui/panel/move/MovePanel.java index 999b275e28c..32ef7385ffb 100644 --- a/game-app/game-core/src/main/java/games/strategy/triplea/ui/panel/move/MovePanel.java +++ b/game-app/game-core/src/main/java/games/strategy/triplea/ui/panel/move/MovePanel.java @@ -314,6 +314,7 @@ public Collection getAirTransportsToLoad( false, getMap().getUiContext(), transportsToLoadMatch); + chooser.setAllButtonVisible(false); chooser.setTitle("Select air transports to load"); if (!confirmUnitChooserDialog(chooser, "What transports do you want to load")) { return List.of(); @@ -861,6 +862,7 @@ private Collection getUnitsToUnload( false, getMap().getUiContext(), transportsToUnloadMatch); + chooser.setAllButtonVisible(false); if (!confirmUnitChooserDialog(chooser, "Select transports to unload")) { return List.of(); } @@ -1273,6 +1275,7 @@ private Collection getTransportsToLoad( false, getMap().getUiContext(), transportsToLoadMatch); + chooser.setAllButtonVisible(false); if (!confirmUnitChooserDialog(chooser, "Select transports to load")) { return List.of(); } @@ -1345,6 +1348,7 @@ private void allowSpecificUnitSelection( false, getMap().getUiContext(), matchCriteria); + chooser.setAllButtonVisible(false); final String text = "Select units to move from " + getFirstSelectedTerritory() + "."; if (!confirmUnitChooserDialog(chooser, text)) { units.clear(); @@ -1398,7 +1402,6 @@ private List userChooseUnits( final Set defaultSelections, final Predicate> unitsToLoadMatch, final List unitsToLoad) { - // Allow player to select which to load. final UnitChooser chooser = new UnitChooser( @@ -1409,6 +1412,7 @@ private List userChooseUnits( false, getMap().getUiContext(), unitsToLoadMatch); + chooser.setAllButtonVisible(false); chooser.setTitle("Load air transports"); if (!confirmUnitChooserDialog(chooser, "What units do you want to load")) { return List.of();