From 3cba93a96281e00601292abaa3a7e45e78f791b1 Mon Sep 17 00:00:00 2001 From: Buj <42136194+5GameMaker@users.noreply.github.com> Date: Mon, 25 Aug 2025 05:19:46 +0700 Subject: [PATCH] autoscale and text alignment flags for world labels (#11166) Co-authored-by: buj --- core/assets/contributors | 3 ++- core/src/mindustry/entities/comp/WorldLabelComp.java | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/assets/contributors b/core/assets/contributors index d382955c6c..35dd0f9021 100644 --- a/core/assets/contributors +++ b/core/assets/contributors @@ -183,4 +183,5 @@ RushieWashie ITY Iniquit DSFdsfWxp -Someone's Shadow \ No newline at end of file +Someone's Shadow +buj \ No newline at end of file diff --git a/core/src/mindustry/entities/comp/WorldLabelComp.java b/core/src/mindustry/entities/comp/WorldLabelComp.java index c283ce0bd1..51b63c536e 100644 --- a/core/src/mindustry/entities/comp/WorldLabelComp.java +++ b/core/src/mindustry/entities/comp/WorldLabelComp.java @@ -5,6 +5,7 @@ import arc.graphics.g2d.*; import arc.scene.ui.layout.*; import arc.util.*; import arc.util.pooling.*; +import mindustry.*; import mindustry.annotations.Annotations.*; import mindustry.gen.*; import mindustry.graphics.*; @@ -17,7 +18,7 @@ public abstract class WorldLabelComp implements Posc, Drawc, Syncc{ @Import int id; @Import float x, y; - public static final byte flagBackground = 1, flagOutline = 2; + public static final byte flagBackground = 1, flagOutline = 2, flagAlignLeft = 4, flagAlignRight = 8, flagAutoscale = 16; public String text = "sample text"; public float fontSize = 1f, z = Layer.playerName + 1; @@ -31,7 +32,7 @@ public abstract class WorldLabelComp implements Posc, Drawc, Syncc{ @Override public void draw(){ - drawAt(text, x, y, z, flags, fontSize, Align.center, Align.center); + drawAt(text, x, y, z, flags, fontSize, Align.center, (flags & flagAlignLeft) != 0 ? Align.left : (flags & flagAlignRight) != 0 ? Align.right : Align.center); } public static void drawAt(String text, float x, float y, float layer, int flags, float fontSize, int align, int lineAlign){ @@ -43,7 +44,9 @@ public abstract class WorldLabelComp implements Posc, Drawc, Syncc{ boolean ints = font.usesIntegerPositions(); font.setUseIntegerPositions(false); - font.getData().setScale(0.25f / Scl.scl(1f) * fontSize); + // Numbers below are obtained by the method of guessing and comparing results to regular labels. + font.getData().setScale(0.25f * fontSize / Scl.scl(1f) / + ((flags & flagAutoscale) != 0 ? 0.2f * Vars.renderer.camerascale + 0.05f : 1f)); layout.setText(font, text); int border = (flags & flagBackground) != 0 ? 1 : 0;