Skip to content

Commit

Permalink
Merge pull request #12689 from BrentEaston/12688-Replace-state-copy-i…
Browse files Browse the repository at this point in the history
…ssue

12688-Replace with other should not update text of unchangeable labels
  • Loading branch information
uckelman authored Sep 14, 2023
2 parents 8aac302 + e5d708b commit 3726fc4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions vassal-app/src/main/java/VASSAL/build/GpIdChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import VASSAL.counters.PlaceMarker;
import VASSAL.counters.Properties;
import VASSAL.i18n.Resources;
import VASSAL.tools.NamedKeyStroke;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -288,7 +287,7 @@ protected void copyState(GamePiece oldPiece, GamePiece newPiece) {
// Do not copy the state of Marker traits, we want to see the new value from the new definition
if (newState != null && !(decoratorNew instanceof Marker)) {
// Do not copy Labeler (Text Label) label state UNLESS this Text Label has the capacity to be manually updated
if (!(decoratorNew instanceof Labeler) || ((((Labeler)decoratorNew).getLabelKey() != null) && !NamedKeyStroke.NULL_KEYSTROKE.equals(((Labeler)decoratorNew).getLabelKey()))) {
if (!(decoratorNew instanceof Labeler) || ((Labeler) decoratorNew).canChange()) {
decoratorNew.mySetState(newState);
}
}
Expand Down
5 changes: 5 additions & 0 deletions vassal-app/src/main/java/VASSAL/counters/Labeler.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ public NamedKeyStroke getLabelKey() {
return labelKey;
}

/** Can this Label be changed? */
public boolean canChange() {
return getLabelKey() != null && !NamedKeyStroke.NULL_KEYSTROKE.equals(getLabelKey());
}

@Override
public void mySetType(String type) {
commands = null;
Expand Down
7 changes: 7 additions & 0 deletions vassal-app/src/main/java/VASSAL/counters/Replace.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ protected void matchTraits(GamePiece base, GamePiece marker) {
candidate = null;
}
}
// Labels are only state matched if they are adjustable. Note this matches the behaviour of the Game Refresher
else if (currentMarker instanceof Labeler) {
if (((Labeler) currentMarker).canChange()) {
currentMarker.mySetState(candidate.myGetState());
candidate = null;
}
}
// Match all other Decorators on full type
else {
if (candidate.myGetType().equals(currentMarker.myGetType())) {
Expand Down

0 comments on commit 3726fc4

Please sign in to comment.