Skip to content

Commit

Permalink
Make 'f' toggle highlighted units. (#12712)
Browse files Browse the repository at this point in the history
Before this change, it would just highlight them without any logic to unhighlight.
  • Loading branch information
asvitkine committed Jul 10, 2024
1 parent c49dcaf commit 580e727
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1497,26 +1499,28 @@ protected boolean setCancelButton() {

/** Highlights movable units on the map for the current player. */
private void highlightMovableUnits() {
final List<Territory> allTerritories;
try (GameData.Unlocker ignored = getData().acquireReadLock()) {
allTerritories = new ArrayList<>(getData().getMap().getTerritories());
if (isHighlightingUnits) {
isHighlightingUnits = false;
getMap().setUnitHighlight(List.of());
return;
}
final Predicate<Unit> 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<Collection<Unit>> highlight = new ArrayList<>();
for (final Territory t : allTerritories) {
for (final Territory t : getData().getMap().getTerritories()) {
final List<Unit> movableUnits = t.getMatches(movableUnitOwnedByMe);
movableUnits.removeAll(unitScroller.getAllSkippedUnits());
if (!movableUnits.isEmpty()) {
highlight.add(movableUnits);
}
}
if (!highlight.isEmpty()) {
getMap().setUnitHighlight(highlight);
isHighlightingUnits = true;
}
}
}

0 comments on commit 580e727

Please sign in to comment.