From 580e727ed5fd132e4cd36038092feac0600b09ca Mon Sep 17 00:00:00 2001 From: asvitkine Date: Wed, 10 Jul 2024 17:03:10 -0400 Subject: [PATCH] Make 'f' toggle highlighted units. (#12712) Before this change, it would just highlight them without any logic to unhighlight. --- .../strategy/triplea/ui/panel/move/MovePanel.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/game-app/game-headed/src/main/java/games/strategy/triplea/ui/panel/move/MovePanel.java b/game-app/game-headed/src/main/java/games/strategy/triplea/ui/panel/move/MovePanel.java index 61ba027dbe..d75053baf9 100644 --- a/game-app/game-headed/src/main/java/games/strategy/triplea/ui/panel/move/MovePanel.java +++ b/game-app/game-headed/src/main/java/games/strategy/triplea/ui/panel/move/MovePanel.java @@ -113,6 +113,8 @@ public class MovePanel extends AbstractMovePanel { @Getter(onMethod_ = @Override) private final CollapsiblePanel unitScrollerPanel; + private boolean isHighlightingUnits; + private final UnitSelectionListener unitSelectionListener = new UnitSelectionListener() { @Override @@ -1497,26 +1499,28 @@ protected boolean setCancelButton() { /** Highlights movable units on the map for the current player. */ private void highlightMovableUnits() { - final List allTerritories; - try (GameData.Unlocker ignored = getData().acquireReadLock()) { - allTerritories = new ArrayList<>(getData().getMap().getTerritories()); + if (isHighlightingUnits) { + isHighlightingUnits = false; + getMap().setUnitHighlight(List.of()); + return; } final Predicate movableUnitOwnedByMe = PredicateBuilder.of(Matches.unitIsOwnedBy(getData().getSequence().getStep().getPlayerId())) .and(Matches.unitHasMovementLeft()) // if not non combat, cannot move aa units .andIf(!nonCombat, Matches.unitCanNotMoveDuringCombatMove().negate()) + .and(not(unitScroller.getAllSkippedUnits()::contains)) .build(); final Collection> highlight = new ArrayList<>(); - for (final Territory t : allTerritories) { + for (final Territory t : getData().getMap().getTerritories()) { final List movableUnits = t.getMatches(movableUnitOwnedByMe); - movableUnits.removeAll(unitScroller.getAllSkippedUnits()); if (!movableUnits.isEmpty()) { highlight.add(movableUnits); } } if (!highlight.isEmpty()) { getMap().setUnitHighlight(highlight); + isHighlightingUnits = true; } } }