Skip to content

Commit

Permalink
12688-Replace with other should not update text of unchangeable labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent committed Sep 13, 2023
1 parent b28514e commit 37567b7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vassal-app/src/main/java/VASSAL/build/GpIdChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,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
8 changes: 8 additions & 0 deletions vassal-app/src/main/java/VASSAL/counters/Replace.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import VASSAL.configure.BooleanConfigurer;
import VASSAL.i18n.PieceI18nData;
import VASSAL.i18n.Resources;
import VASSAL.tools.NamedKeyStroke;

import javax.swing.KeyStroke;
import java.util.ArrayList;
Expand Down Expand Up @@ -183,6 +184,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 37567b7

Please sign in to comment.