From 37567b7642a908b893900669a3a6f813fe4839d4 Mon Sep 17 00:00:00 2001 From: Brent <90901032@westernsydney.edu.au> Date: Wed, 13 Sep 2023 10:59:25 +1000 Subject: [PATCH 1/2] 12688-Replace with other should not update text of unchangeable labels --- vassal-app/src/main/java/VASSAL/build/GpIdChecker.java | 2 +- vassal-app/src/main/java/VASSAL/counters/Labeler.java | 5 +++++ vassal-app/src/main/java/VASSAL/counters/Replace.java | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/vassal-app/src/main/java/VASSAL/build/GpIdChecker.java b/vassal-app/src/main/java/VASSAL/build/GpIdChecker.java index e69322441a..93a4940cb2 100644 --- a/vassal-app/src/main/java/VASSAL/build/GpIdChecker.java +++ b/vassal-app/src/main/java/VASSAL/build/GpIdChecker.java @@ -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); } } diff --git a/vassal-app/src/main/java/VASSAL/counters/Labeler.java b/vassal-app/src/main/java/VASSAL/counters/Labeler.java index 39a319bcac..54112ca1ba 100644 --- a/vassal-app/src/main/java/VASSAL/counters/Labeler.java +++ b/vassal-app/src/main/java/VASSAL/counters/Labeler.java @@ -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; diff --git a/vassal-app/src/main/java/VASSAL/counters/Replace.java b/vassal-app/src/main/java/VASSAL/counters/Replace.java index 97fb891107..914c38a1bd 100644 --- a/vassal-app/src/main/java/VASSAL/counters/Replace.java +++ b/vassal-app/src/main/java/VASSAL/counters/Replace.java @@ -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; @@ -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())) { From e5d708b587a3c77c539b360df8c0d6df0745db19 Mon Sep 17 00:00:00 2001 From: Brent <90901032@westernsydney.edu.au> Date: Wed, 13 Sep 2023 17:54:31 +1000 Subject: [PATCH 2/2] Checkstyle --- vassal-app/src/main/java/VASSAL/build/GpIdChecker.java | 1 - vassal-app/src/main/java/VASSAL/counters/Replace.java | 1 - 2 files changed, 2 deletions(-) diff --git a/vassal-app/src/main/java/VASSAL/build/GpIdChecker.java b/vassal-app/src/main/java/VASSAL/build/GpIdChecker.java index 93a4940cb2..e0c4fffddf 100644 --- a/vassal-app/src/main/java/VASSAL/build/GpIdChecker.java +++ b/vassal-app/src/main/java/VASSAL/build/GpIdChecker.java @@ -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; diff --git a/vassal-app/src/main/java/VASSAL/counters/Replace.java b/vassal-app/src/main/java/VASSAL/counters/Replace.java index 914c38a1bd..17d9c61afe 100644 --- a/vassal-app/src/main/java/VASSAL/counters/Replace.java +++ b/vassal-app/src/main/java/VASSAL/counters/Replace.java @@ -24,7 +24,6 @@ import VASSAL.configure.BooleanConfigurer; import VASSAL.i18n.PieceI18nData; import VASSAL.i18n.Resources; -import VASSAL.tools.NamedKeyStroke; import javax.swing.KeyStroke; import java.util.ArrayList;