Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12688-Replace with other should not update text of unchangeable labels #12689

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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