Skip to content

Commit

Permalink
replace vanilla overlay renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
xzxADIxzx committed Feb 28, 2025
1 parent 6430e87 commit 5ed5f2f
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 13 deletions.
8 changes: 8 additions & 0 deletions src/java/schema/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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;

Expand Down Expand Up @@ -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());

Expand All @@ -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);
}
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/java/schema/input/DesktopInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 6 additions & 11 deletions src/java/schema/input/InputSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.input.*;
import mindustry.world.*;
import mindustry.world.blocks.*;

import static arc.Core.*;
Expand All @@ -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. */
Expand All @@ -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
Expand Down Expand Up @@ -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; }

Expand Down
65 changes: 65 additions & 0 deletions src/java/schema/tools/Overlay.java
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 5ed5f2f

Please sign in to comment.