From 120457916aeefb49aeb30162389e20b7ea564e57 Mon Sep 17 00:00:00 2001 From: Max O'Cull Date: Fri, 11 Oct 2019 19:57:18 -0400 Subject: [PATCH 1/5] Add username labels to map/minimap --- .../mindustry/graphics/MinimapRenderer.java | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java b/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java index 92c8497b26..13bca1f4eb 100644 --- a/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java @@ -9,10 +9,14 @@ import io.anuke.arc.math.*; import io.anuke.arc.math.geom.*; import io.anuke.arc.scene.ui.layout.*; import io.anuke.arc.util.*; +import io.anuke.arc.util.pooling.*; +import io.anuke.mindustry.content.TypeIDs; import io.anuke.mindustry.entities.*; import io.anuke.mindustry.entities.type.*; import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.io.*; +import io.anuke.mindustry.ui.*; +import io.anuke.mindustry.ui.dialogs.*; import io.anuke.mindustry.world.*; import static io.anuke.mindustry.Vars.*; @@ -68,7 +72,7 @@ public class MinimapRenderer implements Disposable{ region = new TextureRegion(texture); } - public void drawEntities(float x, float y, float w, float h){ + public void drawEntities(float x, float y, float w, float h, boolean withLabels){ updateUnitArray(); float sz = baseSize * zoom; @@ -82,12 +86,25 @@ public class MinimapRenderer implements Disposable{ for(Unit unit : units){ float rx = (unit.x - rect.x) / rect.width * w, ry = (unit.y - rect.y) / rect.width * h; Draw.color(unit.getTeam().color); + + if (unit.getTypeID() == TypeIDs.player) { + Player pl = (Player) unit; + if (!pl.isLocal) { + // Only display names for other players. + drawLabel(x + rx, y + ry, pl.name, unit.getTeam().color); + } + } + Fill.rect(x + rx, y + ry, Scl.scl(baseSize / 2f), Scl.scl(baseSize / 2f)); } Draw.color(); } + public void drawEntities(float x, float y, float w, float h){ + drawEntities(x, y, w, h, false); + } + public TextureRegion getRegion(){ if(texture == null) return null; @@ -145,4 +162,27 @@ public class MinimapRenderer implements Disposable{ pixmap = null; } } + + public void drawLabel(float x, float y, String text, Color color) { + BitmapFont font = Fonts.outline; + GlyphLayout l = Pools.obtain(GlyphLayout.class, GlyphLayout::new); + boolean ints = font.usesIntegerPositions(); + font.getData().setScale(1 / 1.5f / Scl.scl(1f)); + font.setUseIntegerPositions(false); + + l.setText(font, text, color, 90f, Align.left, true); + float yOffset = 20f; + float margin = 3f; + + Draw.color(0f, 0f, 0f, 0.2f); + Fill.rect(x, y + yOffset - l.height/2f, l.width + margin, l.height + margin); + Draw.color(); + font.setColor(color); + font.draw(text, x - l.width/2f, y + yOffset, 90f, Align.left, true); + font.setUseIntegerPositions(ints); + + font.getData().setScale(1f); + + Pools.free(l); + } } From 23b7176d5aff9b9ca66be6e82276de6af7912e20 Mon Sep 17 00:00:00 2001 From: Max O'Cull Date: Fri, 11 Oct 2019 20:00:00 -0400 Subject: [PATCH 2/5] Remove extraneous withLabels argument --- core/src/io/anuke/mindustry/graphics/MinimapRenderer.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java b/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java index 13bca1f4eb..516203cee4 100644 --- a/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java @@ -72,7 +72,7 @@ public class MinimapRenderer implements Disposable{ region = new TextureRegion(texture); } - public void drawEntities(float x, float y, float w, float h, boolean withLabels){ + public void drawEntities(float x, float y, float w, float h){ updateUnitArray(); float sz = baseSize * zoom; @@ -101,10 +101,6 @@ public class MinimapRenderer implements Disposable{ Draw.color(); } - public void drawEntities(float x, float y, float w, float h){ - drawEntities(x, y, w, h, false); - } - public TextureRegion getRegion(){ if(texture == null) return null; From 243862804a60239d49c6e3f8e2228bffb9fbd164 Mon Sep 17 00:00:00 2001 From: Max O'Cull Date: Sat, 12 Oct 2019 12:41:26 -0400 Subject: [PATCH 3/5] Remove labels from minimap, keep on larger map --- core/src/io/anuke/mindustry/graphics/MinimapRenderer.java | 8 ++++++-- core/src/io/anuke/mindustry/ui/Minimap.java | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java b/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java index 516203cee4..790792d824 100644 --- a/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java @@ -72,7 +72,7 @@ public class MinimapRenderer implements Disposable{ region = new TextureRegion(texture); } - public void drawEntities(float x, float y, float w, float h){ + public void drawEntities(float x, float y, float w, float h, boolean withLabels){ updateUnitArray(); float sz = baseSize * zoom; @@ -87,7 +87,7 @@ public class MinimapRenderer implements Disposable{ float rx = (unit.x - rect.x) / rect.width * w, ry = (unit.y - rect.y) / rect.width * h; Draw.color(unit.getTeam().color); - if (unit.getTypeID() == TypeIDs.player) { + if (withLabels && unit instanceof Player) { Player pl = (Player) unit; if (!pl.isLocal) { // Only display names for other players. @@ -101,6 +101,10 @@ public class MinimapRenderer implements Disposable{ Draw.color(); } + public void drawEntities(float x, float y, float w, float h){ + drawEntities(x, y, w, h, true); + } + public TextureRegion getRegion(){ if(texture == null) return null; diff --git a/core/src/io/anuke/mindustry/ui/Minimap.java b/core/src/io/anuke/mindustry/ui/Minimap.java index d4cba3bc33..dc2817e8f0 100644 --- a/core/src/io/anuke/mindustry/ui/Minimap.java +++ b/core/src/io/anuke/mindustry/ui/Minimap.java @@ -36,7 +36,7 @@ public class Minimap extends Table{ Draw.rect(renderer.minimap.getRegion(), x + width / 2f, y + height / 2f, width, height); if(renderer.minimap.getTexture() != null){ - renderer.minimap.drawEntities(x, y, width, height); + renderer.minimap.drawEntities(x, y, width, height, false); } } }).size(140f); From b5bec065fe89b3d58a998aa10f52868ecdedf1a9 Mon Sep 17 00:00:00 2001 From: Max O'Cull Date: Sat, 12 Oct 2019 13:15:47 -0400 Subject: [PATCH 4/5] Fix mis-coloring of entity "tile" --- core/src/io/anuke/mindustry/graphics/MinimapRenderer.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java b/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java index 790792d824..47d496e463 100644 --- a/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java @@ -84,8 +84,8 @@ public class MinimapRenderer implements Disposable{ rect.set((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize); for(Unit unit : units){ - float rx = (unit.x - rect.x) / rect.width * w, ry = (unit.y - rect.y) / rect.width * h; - Draw.color(unit.getTeam().color); + float rx = (unit.x - rect.x) / rect.width * w; + float ry = (unit.y - rect.y) / rect.width * h; if (withLabels && unit instanceof Player) { Player pl = (Player) unit; @@ -95,6 +95,7 @@ public class MinimapRenderer implements Disposable{ } } + Draw.color(unit.getTeam().color); Fill.rect(x + rx, y + ry, Scl.scl(baseSize / 2f), Scl.scl(baseSize / 2f)); } From 898956d833f07540f2f158c7c6f6739a549d1b75 Mon Sep 17 00:00:00 2001 From: Max O'Cull Date: Sun, 20 Oct 2019 17:03:54 -0400 Subject: [PATCH 5/5] Fix compact formatting --- core/src/io/anuke/mindustry/graphics/MinimapRenderer.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java b/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java index 47d496e463..c997caae80 100644 --- a/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/MinimapRenderer.java @@ -87,9 +87,9 @@ public class MinimapRenderer implements Disposable{ float rx = (unit.x - rect.x) / rect.width * w; float ry = (unit.y - rect.y) / rect.width * h; - if (withLabels && unit instanceof Player) { + if(withLabels && unit instanceof Player){ Player pl = (Player) unit; - if (!pl.isLocal) { + if(!pl.isLocal){ // Only display names for other players. drawLabel(x + rx, y + ry, pl.name, unit.getTeam().color); } @@ -164,7 +164,7 @@ public class MinimapRenderer implements Disposable{ } } - public void drawLabel(float x, float y, String text, Color color) { + public void drawLabel(float x, float y, String text, Color color){ BitmapFont font = Fonts.outline; GlyphLayout l = Pools.obtain(GlyphLayout.class, GlyphLayout::new); boolean ints = font.usesIntegerPositions();