diff --git a/core/src/mindustry/game/MapObjectives.java b/core/src/mindustry/game/MapObjectives.java index f6ba92d67f..625e0c002c 100644 --- a/core/src/mindustry/game/MapObjectives.java +++ b/core/src/mindustry/game/MapObjectives.java @@ -4,6 +4,8 @@ import arc.*; import arc.func.*; import arc.graphics.*; import arc.graphics.g2d.*; +import arc.math.*; +import arc.scene.ui.layout.*; import arc.util.*; import mindustry.content.*; import mindustry.ctype.*; @@ -22,7 +24,7 @@ public class MapObjectives{ }; public static Prov[] allMarkerTypes = new Prov[]{ - TextMarker::new, ShapeMarker::new, ShapeTextMarker::new + TextMarker::new, ShapeMarker::new, ShapeTextMarker::new, MinimapMarker::new }; /** Research a specific piece of content in the tech tree. */ @@ -419,6 +421,33 @@ public class MapObjectives{ } } + /** Displays a circle on the minimap. */ + public static class MinimapMarker extends ObjectiveMarker{ + //in tiles. + public float x, y, radius = 5f, stroke = 11f; + public Color color = Team.malis.color; + + public MinimapMarker(float x, float y){ + this.x = x; + this.y = y; + } + + public MinimapMarker(){ + } + + @Override + public void drawMinimap(MinimapRenderer minimap){ + minimap.transform(Tmp.v1.set(x * tilesize, y * tilesize)); + + float rad = minimap.scale(radius * tilesize); + float fin = Interp.pow2Out.apply((Time.globalTime / 100f) % 1f); + + Lines.stroke(Scl.scl((1f - fin) * stroke + 0.1f), color); + Lines.circle(Tmp.v1.x, Tmp.v1.y, rad * fin); + Draw.reset(); + } + } + /** Displays a shape with an outline and color. */ public static class ShapeMarker extends ObjectiveMarker{ public float x, y, radius = 6f, rotation = 0f; @@ -492,6 +521,8 @@ public class MapObjectives{ /** Called in the overlay draw layer.*/ public void draw(){} + /** Called in the small & large map. */ + public void drawMinimap(MinimapRenderer minimap){} /** Add any UI elements necessary. */ public void added(){} /** Remove any UI elements, if necessary. */ diff --git a/core/src/mindustry/graphics/MinimapRenderer.java b/core/src/mindustry/graphics/MinimapRenderer.java index b69e6982f7..44a2ce0bbf 100644 --- a/core/src/mindustry/graphics/MinimapRenderer.java +++ b/core/src/mindustry/graphics/MinimapRenderer.java @@ -29,6 +29,9 @@ public class MinimapRenderer{ private Rect rect = new Rect(); private float zoom = 4; + private float lastX, lastY, lastW, lastH, lastScl; + private boolean worldSpace; + public MinimapRenderer(){ Events.on(WorldLoadEvent.class, event -> { reset(); @@ -97,6 +100,13 @@ public class MinimapRenderer{ } public void drawEntities(float x, float y, float w, float h, float scaling, boolean withLabels){ + lastX = x; + lastY = y; + lastW = w; + lastH = h; + lastScl = scaling; + worldSpace = withLabels; + if(!withLabels){ updateUnitArray(); }else{ @@ -175,6 +185,13 @@ public class MinimapRenderer{ if(withLabels){ drawSpawns(x, y, w, h, scaling); } + + if(state.rules.objectives.size > 0){ + var first = state.rules.objectives.first(); + for(var marker : first.markers){ + marker.drawMinimap(this); + } + } } public void drawSpawns(float x, float y, float w, float h, float scaling){ @@ -186,13 +203,13 @@ public class MinimapRenderer{ Draw.color(state.rules.waveTeam.color, Tmp.c2.set(state.rules.waveTeam.color).value(1.2f), Mathf.absin(Time.time, 16f, 1f)); + float rad = scale(state.rules.dropZoneRadius); + float curve = Mathf.curve(Time.time % 240f, 120f, 240f); + for(Tile tile : spawner.getSpawns()){ float tx = ((tile.x + 0.5f) / world.width()) * w; float ty = ((tile.y + 0.5f) / world.height()) * h; - float rad = (state.rules.dropZoneRadius / (baseSize / 2f)) * 5f * scaling; - float curve = Mathf.curve(Time.time % 240f, 120f, 240f); - Draw.rect(icon, x + tx, y + ty, icon.width, icon.height); Lines.circle(x + tx, y + ty, rad); if(curve > 0f) Lines.circle(x + tx, y + ty, rad * Interp.pow3Out.apply(curve)); @@ -201,8 +218,19 @@ public class MinimapRenderer{ Draw.reset(); } - public void drawEntities(float x, float y, float w, float h){ - drawEntities(x, y, w, h, 1f, true); + //TODO horrible code, everywhere. + public Vec2 transform(Vec2 position){ + if(!worldSpace){ + position.sub(rect.x, rect.y).scl(lastW / rect.width, lastH / rect.height); + }else{ + position.scl(1f / world.unitWidth(), 1f / world.unitHeight()).scl(lastW, lastH); + } + + return position.add(lastX, lastY); + } + + public float scale(float radius){ + return (radius / (baseSize / 2f)) * 5f * lastScl; } public @Nullable TextureRegion getRegion(){