Skip to content

Commit 7327ee7

Browse files
authored
Merge pull request #4716 from cwisniew/fix-4706
Correctly centre map labels and fix colors for some old labels that had wrong coloring.
2 parents 8c8fdc2 + 28fa281 commit 7327ee7

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/main/java/net/rptools/maptool/client/ui/zone/renderer/ZoneRenderer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,9 @@ private void renderLabels(Graphics2D g, PlayerView view) {
12201220
timer.start("labels-1.1");
12211221
ScreenPoint sp = ScreenPoint.fromZonePointRnd(this, zp.x, zp.y);
12221222
var dim = flabel.getDimensions(g, label.getLabel());
1223-
Rectangle bounds = flabel.render(g, (int) sp.x, (int) sp.y, label.getLabel());
1223+
Rectangle bounds =
1224+
flabel.render(
1225+
g, (int) (sp.x - dim.width / 2), (int) (sp.y - dim.height / 2), label.getLabel());
12241226
labelLocationList.add(new LabelLocation(bounds, label));
12251227
timer.stop("labels-1.1");
12261228
}

src/main/java/net/rptools/maptool/model/transform/campaign/LabelFontAndBGTransform.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,22 @@ public class LabelFontAndBGTransform implements ModelVersionTransformation {
2828
/** The end label tag that we want to replace. */
2929
private static final String endLabelTag = "</net.rptools.maptool.model.Label>";
3030

31+
/** The pattern that we want o match for 0 foreground color. */
32+
private static final String replace0ForegroundTags =
33+
"<foregroundColor>0</foregroundColor>[^<]*" + endLabelTag;
34+
35+
/**
36+
* The foreground color that we want to use for the label where the legacy foreground color is 0.
37+
*/
38+
private static final Color legacyForegroundColor = new Color(0.0f, 0.0f, 0.0f, 1.0f);
39+
40+
private static final String foreground0Replacement =
41+
"<foregroundColor>" + legacyForegroundColor.getRGB() + "</foregroundColor>\n" + endLabelTag;
42+
3143
/** The background color that we want to use for the new label tag. */
3244
private static final Color legacyBackgroundColor = new Color(0.82f, 0.82f, 0.82f, 1.0f);
3345

34-
/** The replacement string that we want to use for the end label tag. */
46+
/** The replacement string that we want to use for the new label tag. */
3547
private static final String replacement =
3648
"<backgroundColor>"
3749
+ legacyBackgroundColor.getRGB()
@@ -54,8 +66,13 @@ public class LabelFontAndBGTransform implements ModelVersionTransformation {
5466
/** The pattern that we want to use to match the end label tag. */
5567
private static final Pattern pattern = Pattern.compile(endLabelTag, Pattern.DOTALL);
5668

69+
/** The pattern that we want to use to match the legacy foreground color of 0. */
70+
private static final Pattern replace0Foreground =
71+
Pattern.compile(replace0ForegroundTags, Pattern.DOTALL);
72+
5773
@Override
5874
public String transform(String xml) {
59-
return pattern.matcher(xml).replaceAll(replacement);
75+
String replace0 = replace0Foreground.matcher(xml).replaceAll(foreground0Replacement);
76+
return pattern.matcher(replace0).replaceAll(replacement);
6077
}
6178
}

0 commit comments

Comments
 (0)