diff --git a/src/java/schema/Main.java b/src/java/schema/Main.java index 3644885..dd735ab 100644 --- a/src/java/schema/Main.java +++ b/src/java/schema/Main.java @@ -5,6 +5,7 @@ import arc.util.*; import mindustry.mod.*; import schema.input.*; +import schema.tools.*; import schema.ui.*; import schema.ui.dialogs.*; import schema.ui.fragments.*; @@ -17,6 +18,9 @@ public class Main extends Mod { // region components + /** Combines the vanilla and schema overlay. */ + public static Overlay overlay; + /** Advanced input system lying in the foundation of the mod. */ public static InputSystem insys; @@ -67,6 +71,7 @@ public void init() { ui.minimapfrag=mapfrag.getAgent(); ui.loadfrag = loadfrag.getAgent(); + Reflect.set(renderer, "overlays", overlay.getAgent()); // TODO override inventory too Reflect.set(mindustry.input.InputHandler.class, control.input, "config", config.getAgent()); @@ -83,6 +88,7 @@ public void init() { } catch (Throwable e) { err(e); } log("=> [green]Unhooking events..."); + clear(mindustry.graphics.OverlayRenderer.class); clear(mindustry.input.InputHandler.class); clear(mindustry.ui.fragments.PlacementFragment.class); } @@ -92,6 +98,8 @@ public void load() { // these styles are used for building dialogs and fragments and thus are loaded here Style.load(); + overlay = new Overlay(); + insys = mobile ? null : new DesktopInput(); keybind = new KeybindDialog(); diff --git a/src/java/schema/input/DesktopInput.java b/src/java/schema/input/DesktopInput.java index 73d6006..17f1d15 100644 --- a/src/java/schema/input/DesktopInput.java +++ b/src/java/schema/input/DesktopInput.java @@ -277,10 +277,10 @@ protected void updateState() { } @Override - protected void drawPlans() {} + public void drawPlans() {} @Override - protected void drawOverlay() { + public void drawOverlay() { if (commandMode) drawCommand(); if (controlMode) drawControl(); else controlFade = 0f; diff --git a/src/java/schema/input/InputSystem.java b/src/java/schema/input/InputSystem.java index 4585beb..7465d76 100644 --- a/src/java/schema/input/InputSystem.java +++ b/src/java/schema/input/InputSystem.java @@ -14,6 +14,7 @@ import mindustry.gen.*; import mindustry.graphics.*; import mindustry.input.*; +import mindustry.world.*; import mindustry.world.blocks.*; import static arc.Core.*; @@ -39,6 +40,9 @@ public abstract class InputSystem { /** Alpha value of the control mode overlay. */ protected float controlFade; + /** Selected block, the one in your hand. I dunno how else to explain. */ + public Block block; + // region general /** Updates the main logic of the input system. */ @@ -48,10 +52,10 @@ public abstract class InputSystem { protected abstract void updateState(); /** Draws the building plans of the player and its teammates. */ - protected abstract void drawPlans(); + public abstract void drawPlans(); /** Draws the remaining elements of the interface. */ - protected abstract void drawOverlay(); + public abstract void drawOverlay(); // endregion // region draw @@ -226,15 +230,6 @@ public void remove() {} @Override public void updateState() { insys.updateState(); } - @Override - public void drawBottom() { insys.drawPlans(); } - - @Override - public void drawTop() { insys.drawOverlay(); } - - @Override - public void panCamera(Vec2 pos) { insys.setCam(pos); } - @Override public boolean isPlacing() { return false; } diff --git a/src/java/schema/tools/Overlay.java b/src/java/schema/tools/Overlay.java new file mode 100644 index 0000000..756b283 --- /dev/null +++ b/src/java/schema/tools/Overlay.java @@ -0,0 +1,65 @@ +package schema.tools; + +import arc.graphics.*; +import arc.graphics.g2d.*; +import arc.math.*; +import mindustry.graphics.*; + +import static arc.Core.*; +import static mindustry.Vars.*; +import static schema.Main.*; + +/** Component that renders overlay elements: command and control mode, blocks configuration, objectives and so on. */ +public class Overlay { + + /** Distance from which spawners are visible. */ + public static final float spawnerMargin = 16f * tilesize; + + /** Draws the elements of both vanilla and schema overlay */ + public void draw() { + state.rules.objectives.eachRunning(o -> { + for (var marker : o.markers) marker.draw(); + }); + + if (config.shown()) config.selected().drawConfigure(); + insys.drawOverlay(); + + if (state.hasSpawns()) { + Lines.stroke(2f); + Draw.color(Color.gray, Color.lightGray, Mathf.absin(4f, 1f)); + + spawner.getSpawns().each(s -> s.within(player, state.rules.dropZoneRadius + spawnerMargin), s -> { + + Draw.alpha(1f - (player.dst(s) - state.rules.dropZoneRadius) / spawnerMargin); + Lines.dashCircle(s.worldx(), s.worldy(), state.rules.dropZoneRadius); + }); + } + + if (insys.block == null && !scene.hasMouse()) { + var build = insys.selectedBuilding(); + if (build != null && build.team == player.team()) { + + build.drawSelect(); + + if (build.block.drawDisabled && !build.enabled) build.drawDisabled(); + } + } + } + + // region agent + + /** Returns the agent of this component. */ + public Agent getAgent() { return new Agent(); } + + /** Agent that redirects method calls from the original component to the new one. */ + public class Agent extends OverlayRenderer { + + @Override + public void drawBottom() { insys.drawPlans(); } + + @Override + public void drawTop() { draw(); } + } + + // endregion +}