From 8269d79e560268a30b25bdcb171fe83af1f0b3b2 Mon Sep 17 00:00:00 2001 From: dead inside <54301439+MEEPofFaith@users.noreply.github.com> Date: Mon, 9 May 2022 14:06:55 -0700 Subject: [PATCH] Liquid Output Display (#6788) * Liquid Output Display * hshfhqwehpvoipwjovpwiqffjvpwqenoij0n89f4v123f2v40q9j8hbnwqvceinopjj90cmqwvinv21904uinfhu0bnv9j90h84g bvb8024q3bh80b3498vcfj932ndjqdjponjewopnviqvnifjwp9ghpnewuubgqjiojpdfoekwdckmpqwpkmidpkewpjndqvjwnfnj8132nt345879ytgh342890yu4598yhubn4t9hrj[tevpkofkwemfvewrphojfekpcfoerkfwmvfh23bng0398g9834ifvrfnwurbgiwnwgherhnwenhgpvrnnivjpjnipfqwjniwqfejnipofvniwejpfqjwociomjefjjmvcmj21m4f98v00ngbhegwefgpjroiewjfqfwpiojnmem * Pull to separate function The javadoc description could be different * In case mods have liquid icons larger than 32x32 --- .../mindustry/entities/comp/BuildingComp.java | 1 + core/src/mindustry/world/Block.java | 4 ++++ .../blocks/production/GenericCrafter.java | 23 ++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/core/src/mindustry/entities/comp/BuildingComp.java b/core/src/mindustry/entities/comp/BuildingComp.java index c857182bc6..d425f8e580 100644 --- a/core/src/mindustry/entities/comp/BuildingComp.java +++ b/core/src/mindustry/entities/comp/BuildingComp.java @@ -1119,6 +1119,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc, /** Draw the block overlay that is shown when a cursor is over the block. */ public void drawSelect(){ + block.drawOverlay(x, y, rotation); } public void drawDisabled(){ diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 74cda8b373..eea8429354 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -396,6 +396,7 @@ public class Block extends UnlockableContent implements Senseable{ /** Drawn when you are placing a block. */ public void drawPlace(int x, int y, int rotation, boolean valid){ drawPotentialLinks(x, y); + drawOverlay(x * tilesize + offset, y * tilesize + offset, rotation); } public void drawPotentialLinks(int x, int y){ @@ -444,6 +445,9 @@ public class Block extends UnlockableContent implements Senseable{ return width; } + /** Drawn when placing and when hovering over. */ + public void drawOverlay(float x, float y, int rotation){ + } public float sumAttribute(@Nullable Attribute attr, int x, int y){ if(attr == null) return 0; Tile tile = world.tile(x, y); diff --git a/core/src/mindustry/world/blocks/production/GenericCrafter.java b/core/src/mindustry/world/blocks/production/GenericCrafter.java index 1b91b64d81..2e6b2bb97e 100644 --- a/core/src/mindustry/world/blocks/production/GenericCrafter.java +++ b/core/src/mindustry/world/blocks/production/GenericCrafter.java @@ -2,6 +2,7 @@ package mindustry.world.blocks.production; import arc.graphics.g2d.*; import arc.math.*; +import arc.math.geom.*; import arc.struct.*; import arc.util.*; import arc.util.io.*; @@ -15,6 +16,8 @@ import mindustry.world.*; import mindustry.world.draw.*; import mindustry.world.meta.*; +import static mindustry.Vars.*; + public class GenericCrafter extends Block{ /** Written to outputItems as a single-element array if outputItems is null. */ public @Nullable ItemStack outputItem; @@ -138,6 +141,24 @@ public class GenericCrafter extends Block{ drawer.getRegionsToOutline(this, out); } + @Override + public void drawOverlay(float x, float y, int rotation){ + if(outputLiquids != null){ + for(int i = 0; i < outputLiquids.length; i++){ + int dir = liquidOutputDirections.length > i ? liquidOutputDirections[i] + rotation : -1; + + if(dir != -1){ + Draw.rect( + outputLiquids[i].liquid.fullIcon, + x + Geometry.d4x(dir) * (size * tilesize / 2f + 4), + y + Geometry.d4y(dir) * (size * tilesize / 2f + 4), + 8f, 8f + ); + } + } + } + } + public class GenericCrafterBuild extends Building{ public float progress; public float totalProgress; @@ -303,4 +324,4 @@ public class GenericCrafter extends Block{ if(legacyReadWarmup) read.f(); } } -} \ No newline at end of file +}