clean code up

This commit is contained in:
sharlottes
2022-04-19 00:08:49 +09:00
parent 81b2215c9a
commit de799fffd7
17 changed files with 306 additions and 431 deletions

View File

@@ -9,13 +9,10 @@ import arc.math.*;
import arc.math.geom.*;
import arc.scene.*;
import arc.scene.style.*;
import arc.scene.ui.layout.*;
import arc.util.Align;
import arc.util.Tmp;
import mindustry.graphics.*;
import mindustry.ui.*;
import static UnitInfo.SVars.modUiScale;
import mindustry.ui.Fonts;
public class SBar extends Element{
static final Rect scissor = new Rect();

View File

@@ -9,40 +9,22 @@ import mindustry.gen.Groups;
import mindustry.ui.Styles;
import static UnitInfo.core.OverDrawer.isInCamera;
import static arc.Core.settings;
public class BlockDraw extends OverDraw {
boolean status = false;
BlockDraw(String name, TextureRegionDrawable icon) {
super(name, icon);
registerOption("blockStatus");
}
@Override
public void draw() {
super.draw();
Groups.build.each(b->{
if(isInCamera(b.x, b.y, b.block.size/2f) && Vars.player.team() == b.team) b.drawStatus();
//this is shit.. VERY SHIT OH GOD
if(isInCamera(b.x, b.y, b.block.size/2f) && settings.getBool("blockStatus") && enabled) b.drawStatus();
});
}
@Override
public void displayStats(Table parent) {
super.displayStats(parent);
parent.background(Styles.squaret.up);
parent.check("enable block status", status&&enabled, b->status=b&&enabled).disabled(!enabled);
}
@Override
public <T> void onEnabled(T param) {
super.onEnabled(param);
if(param instanceof Table t) {
for (int i = 0; i < t.getChildren().size; i++) {
Element elem = t.getChildren().get(i);
if (elem instanceof CheckBox cb) cb.setDisabled(!enabled);
}
}
}
}

View File

@@ -24,6 +24,7 @@ import mindustry.world.blocks.distribution.MassDriver;
import mindustry.world.blocks.payloads.PayloadMassDriver;
import static arc.Core.atlas;
import static arc.Core.settings;
import static mindustry.Vars.*;
import static UnitInfo.SVars.*;
@@ -31,10 +32,11 @@ public class LinkDraw extends OverDraw {
Seq<MassDriver.MassDriverBuild> linkedMasses = new Seq<>();
Seq<PayloadMassDriver.PayloadDriverBuild> linkedPayloadMasses = new Seq<>();
Seq<Building> linkedNodes = new Seq<>();
boolean node = false, mass = false;
LinkDraw(String name, TextureRegionDrawable icon) {
super(name, icon);
registerOption("powerNode");
registerOption("massDriver");
}
@Override
@@ -43,11 +45,11 @@ public class LinkDraw extends OverDraw {
Draw.z(Layer.max);
if(target instanceof Building b){
if(node) {
if(settings.getBool("powerNode") && enabled) {
linkedNodes.clear();
drawNodeLink(b);
}
if(mass) {
if(settings.getBool("massDriver") && enabled) {
if (target instanceof MassDriver.MassDriverBuild mass) {
linkedMasses.clear();
drawMassLink(mass);
@@ -59,28 +61,6 @@ public class LinkDraw extends OverDraw {
}
}
@Override
public void displayStats(Table parent) {
super.displayStats(parent);
parent.background(Styles.squaret.up);
parent.check("enable power node", node&&enabled, b->node=b&&enabled).disabled(!enabled).row();
parent.check("enable mass driver", mass&&enabled, b->mass=b&&enabled).disabled(!enabled).row();
}
@Override
public <T> void onEnabled(T param) {
super.onEnabled(param);
if(param instanceof Table t) {
for (int i = 0; i < t.getChildren().size; i++) {
Element elem = t.getChildren().get(i);
if (elem instanceof CheckBox cb) cb.setDisabled(!enabled);
}
}
}
void drawMassPayloadLink(PayloadMassDriver.PayloadDriverBuild from){
float sin = Mathf.absin(Time.time, 6f, 1f);

View File

@@ -1,20 +1,53 @@
package UnitInfo.ui.draws;
import arc.scene.Element;
import arc.scene.style.TextureRegionDrawable;
import arc.scene.ui.CheckBox;
import arc.scene.ui.layout.Table;
import arc.struct.ObjectMap;
import arc.struct.Seq;
import mindustry.ui.Styles;
import static arc.Core.bundle;
import static arc.Core.settings;
public class OverDraw {
public TextureRegionDrawable icon;
public String name;
public boolean enabled =false;
public boolean enabled = false;
public Seq<String> options = new Seq<>();
OverDraw(String name, TextureRegionDrawable icon) {
this.name = name;
this.icon = icon;
}
public void displayStats(Table parent) {}
public void displayStats(Table parent) {
if(options.isEmpty()) return;
parent.background(Styles.squaret.up);
options.each(name-> parent.check(bundle.get("setting."+name+".name"), settings.getBool(name), b->settings.put(name, b)).tooltip(t->t.background(Styles.black8).add(bundle.get("setting."+name+".description"))).disabled(!enabled).row());
}
public void draw() {}
public <T> void onEnabled(T param) {}
public <T> void onEnabled(T param) {
if(param instanceof Table t) {
for (int i = 0; i < t.getChildren().size; i++) {
Element elem = t.getChildren().get(i);
if (elem instanceof CheckBox cb) cb.setDisabled(!enabled);
}
}
}
public void registerOption(String name) {
registerOption(name, settings.has(name) && settings.getBool(name));
}
public void registerOption(String name, boolean defaults) {
options.add(name);
settings.put(name, defaults);
}
}

View File

@@ -3,7 +3,7 @@ package UnitInfo.ui.draws;
import mindustry.gen.Icon;
public class OverDraws {
public static OverDraw range, link, unit, block;
public static OverDraw range, link, unit, block, util;
public static OverDraw[] all = {};
public static void init() {
@@ -11,6 +11,7 @@ public class OverDraws {
link = new LinkDraw("Link Draws", Icon.line);
unit = new UnitDraw("Unit Draws", Icon.units);
block = new BlockDraw("Block Draws", Icon.crafting);
all = new OverDraw[]{range, link, unit, block};
util = new UtilDraw("Utils", Icon.github);
all = new OverDraw[]{range, link, unit, block, util};
}
}

View File

@@ -1,20 +1,16 @@
package UnitInfo.ui.draws;
import arc.graphics.Color;
import arc.graphics.g2d.Draw;
import arc.graphics.g2d.Fill;
import arc.graphics.g2d.Lines;
import arc.graphics.g2d.*;
import arc.graphics.gl.FrameBuffer;
import arc.scene.Element;
import arc.scene.Group;
import arc.scene.style.TextureRegionDrawable;
import arc.scene.ui.CheckBox;
import arc.scene.ui.layout.Table;
import arc.struct.ObjectMap;
import arc.struct.Seq;
import mindustry.game.Team;
import mindustry.gen.Groups;
import mindustry.gen.Unit;
import mindustry.gen.*;
import mindustry.graphics.Drawf;
import mindustry.ui.Styles;
import mindustry.world.blocks.defense.turrets.BaseTurret;
@@ -23,17 +19,17 @@ import mindustry.world.blocks.defense.turrets.Turret;
import static UnitInfo.SVars.turretRange;
import static UnitInfo.core.OverDrawer.isInCamera;
import static arc.Core.graphics;
import static arc.Core.settings;
import static arc.Core.*;
import static mindustry.Vars.player;
public class RangeDraw extends OverDraw {
FrameBuffer effectBuffer = new FrameBuffer();
ObjectMap<Team, Seq<BaseTurret.BaseTurretBuild>> tmpbuildobj = new ObjectMap<>();
boolean ground = false, air = false;
ObjectMap<Team, Seq<BaseTurret.BaseTurretBuild>> turrets = new ObjectMap<>();
RangeDraw(String name, TextureRegionDrawable icon) {
super(name, icon);
registerOption("airRange");
registerOption("groundRange");
}
@Override
@@ -43,13 +39,13 @@ public class RangeDraw extends OverDraw {
effectBuffer.resize(graphics.getWidth(), graphics.getHeight());
Unit unit = player.unit();
tmpbuildobj.clear();
turrets.clear();
for(Team team : Team.baseTeams) {
Draw.drawRange(166 + (Team.baseTeams.length-team.id) * 3, 1, () -> effectBuffer.begin(Color.clear), () -> {
effectBuffer.end();
effectBuffer.blit(turretRange);
});
tmpbuildobj.put(team, new Seq<>());
turrets.put(team, new Seq<>());
}
Groups.build.each(b-> settings.getBool("aliceRange") || player.team() != b.team, b -> {
@@ -59,6 +55,8 @@ public class RangeDraw extends OverDraw {
int index = b.team.id;
Draw.color(b.team.color);
boolean air = settings.getBool("airRange") && enabled;
boolean ground = settings.getBool("groundRange") && enabled;
boolean valid = false;
if (unit == null) valid = true;
else if (b instanceof Turret.TurretBuild build) {
@@ -84,26 +82,4 @@ public class RangeDraw extends OverDraw {
}
});
}
@Override
public void displayStats(Table parent) {
super.displayStats(parent);
parent.background(Styles.squaret.up);
parent.check("enable ground", ground&&enabled, b->ground=b&&enabled).disabled(!enabled).row();
parent.check("enable air", air&&enabled, b->air=b&&enabled).disabled(!enabled).row();
}
@Override
public <T> void onEnabled(T param) {
super.onEnabled(param);
if(param instanceof Table t) {
for (int i = 0; i < t.getChildren().size; i++) {
Element elem = t.getChildren().get(i);
if (elem instanceof CheckBox cb) cb.setDisabled(!enabled);
}
}
}
}

View File

@@ -34,15 +34,20 @@ import java.util.Objects;
import static UnitInfo.core.OverDrawer.isInCamera;
import static UnitInfo.core.OverDrawer.isOutCamera;
import static arc.Core.settings;
import static mindustry.Vars.*;
public class UnitDraw extends OverDraw {
Seq<Tile> pathTiles = new Seq<>();
int otherCores;
boolean pathLine = false, unitLine = false, logicLine = false, bar = false, item = false;
UnitDraw(String name, TextureRegionDrawable icon) {
super(name, icon);
registerOption("pathLine");
registerOption("logicLine");
registerOption("unitLine");
registerOption("unitItem");
registerOption("unitBar");
}
@Override
@@ -53,14 +58,14 @@ public class UnitDraw extends OverDraw {
UnitController c = u.controller();
UnitCommand com = u.team.data().command;
if(logicLine && c instanceof LogicAI ai && (ai.control == LUnitControl.approach || ai.control == LUnitControl.move)) {
if(settings.getBool("logicLine") && c instanceof LogicAI ai && (ai.control == LUnitControl.approach || ai.control == LUnitControl.move)) {
Lines.stroke(1, u.team.color);
Lines.line(u.x(), u.y(), ai.moveX, ai.moveY);
Lines.stroke(0.5f + Mathf.absin(6f, 0.5f), Tmp.c1.set(Pal.logicOperations).lerp(Pal.sap, Mathf.absin(6f, 0.5f)));
Lines.line(u.x(), u.y(), ai.controller.x, ai.controller.y);
}
if(unitLine && !u.type.flying && com != UnitCommand.idle && !(c instanceof MinerAI || c instanceof BuilderAI || c instanceof RepairAI || c instanceof DefenderAI || c instanceof FormationAI || c instanceof FlyingAI)) {
if(settings.getBool("unitLine") && !u.type.flying && com != UnitCommand.idle && !(c instanceof MinerAI || c instanceof BuilderAI || c instanceof RepairAI || c instanceof DefenderAI || c instanceof FormationAI || c instanceof FlyingAI)) {
Lines.stroke(1, u.team.color);
otherCores = Groups.build.count(b -> b instanceof CoreBlock.CoreBuild && b.team != u.team);
@@ -75,16 +80,16 @@ public class UnitDraw extends OverDraw {
}
}
if(bar) FreeBar.draw(u);
if(settings.getBool("unitBar")) FreeBar.draw(u);
if(item && !renderer.pixelator.enabled() && u.item() != null && u.itemTime > 0.01f)
if(settings.getBool("unitItem") && !renderer.pixelator.enabled() && u.item() != null && u.itemTime > 0.01f)
Fonts.outline.draw(u.stack.amount + "",
u.x + Angles.trnsx(u.rotation + 180f, u.type.itemOffsetY),
u.y + Angles.trnsy(u.rotation + 180f, u.type.itemOffsetY) - 3,
Pal.accent, 0.25f * u.itemTime / Scl.scl(1f), false, Align.center);
});
if(pathLine) spawner.getSpawns().each(t -> {
if(settings.getBool("pathLine")) spawner.getSpawns().each(t -> {
Team enemyTeam = state.rules.waveTeam;
Lines.stroke(1, enemyTeam.color);
for(int p = 0; p < (Vars.state.rules.spawns.count(g->g.type.naval)>0?3:2); p++) {
@@ -113,29 +118,4 @@ public class UnitDraw extends OverDraw {
return tile1;
return getNextTile(tile1, cost, team, finder);
}
@Override
public void displayStats(Table parent) {
super.displayStats(parent);
parent.background(Styles.squaret.up);
parent.check("enable path line", pathLine&&enabled, b->pathLine=b&&enabled).disabled(!enabled).row();
parent.check("enable logic line", logicLine&&enabled, b->logicLine=b&&enabled).disabled(!enabled).row();
parent.check("enable unit line", unitLine&&enabled, b->unitLine=b&&enabled).disabled(!enabled).row();
parent.check("enable unit item", item&&enabled, b->item=b&&enabled).disabled(!enabled).row();
parent.check("enable unit bar", bar&&enabled, b->bar=b&&enabled).disabled(!enabled).row();
}
@Override
public <T> void onEnabled(T param) {
super.onEnabled(param);
if(param instanceof Table t) {
for (int i = 0; i < t.getChildren().size; i++) {
Element elem = t.getChildren().get(i);
if (elem instanceof CheckBox cb) cb.setDisabled(!enabled);
}
}
}
}

View File

@@ -0,0 +1,80 @@
package UnitInfo.ui.draws;
import arc.input.KeyCode;
import arc.math.Angles;
import arc.math.geom.Geometry;
import arc.scene.style.TextureRegionDrawable;
import mindustry.entities.Units;
import mindustry.game.Team;
import mindustry.gen.*;
import mindustry.logic.Ranged;
import mindustry.world.blocks.ControlBlock;
import mindustry.world.blocks.defense.turrets.Turret;
import static arc.Core.*;
import static mindustry.Vars.*;
public class UtilDraw extends OverDraw {
Teamc shotTarget;
UtilDraw(String name, TextureRegionDrawable icon) {
super(name, icon);
registerOption("autoShooting");
}
@Override
public void draw() {
super.draw();
if(!enabled) return;
if(settings.getBool("autoShooting")) {
Unit unit = player.unit();
if (unit.type == null) return;
boolean omni = unit.type.omniMovement;
boolean validHealTarget = unit.type.canHeal && shotTarget instanceof Building b && b.isValid() && b.damaged() && shotTarget.team() == unit.team && shotTarget.within(unit, unit.type.range);
boolean boosted = (unit instanceof Mechc && unit.isFlying());
if ((unit.type != null && Units.invalidateTarget(shotTarget, unit, unit.type.range) && !validHealTarget) || state.isEditor()) {
shotTarget = null;
}
float mouseAngle = unit.angleTo(unit.aimX(), unit.aimY());
boolean aimCursor = omni && player.shooting && unit.type.hasWeapons() && unit.type.faceTarget && !boosted && unit.type.rotateShooting;
unit.lookAt(aimCursor ? mouseAngle : unit.prefRotation());
//update shooting if not building + not mining
if(!player.unit().activelyBuilding() && player.unit().mineTile == null) {
if(input.keyDown(KeyCode.mouseLeft)) {
player.shooting = !boosted;
unit.aim(player.mouseX = input.mouseWorldX(), player.mouseY = input.mouseWorldY());
} else if(shotTarget == null) {
player.shooting = false;
if(unit instanceof BlockUnitUnit b) {
if(b.tile() instanceof ControlBlock c && !c.shouldAutoTarget()) {
Building build = b.tile();
float range = build instanceof Ranged ? ((Ranged) build).range() : 0f;
boolean targetGround = build instanceof Turret.TurretBuild && ((Turret) build.block).targetAir;
boolean targetAir = build instanceof Turret.TurretBuild && ((Turret) build.block).targetGround;
shotTarget = Units.closestTarget(build.team, build.x, build.y, range, u -> u.checkTarget(targetAir, targetGround), u -> targetGround);
}
else shotTarget = null;
} else if(unit.type != null) {
float range = unit.hasWeapons() ? unit.range() : 0f;
shotTarget = Units.closestTarget(unit.team, unit.x, unit.y, range, u -> u.checkTarget(unit.type.targetAir, unit.type.targetGround), u -> unit.type.targetGround);
if(unit.type.canHeal && shotTarget == null) {
shotTarget = Geometry.findClosest(unit.x, unit.y, indexer.getDamaged(Team.sharded));
if (shotTarget != null && !unit.within(shotTarget, range)) {
shotTarget = null;
}
}
}
} else {
player.shooting = !boosted;
unit.rotation(Angles.angle(unit.x, unit.y, shotTarget.x(), shotTarget.y()));
unit.aim(shotTarget.x(), shotTarget.y());
}
}
unit.controlWeapons(player.shooting && !boosted);
}
}
}

View File

@@ -25,6 +25,7 @@ public class PlayerDisplay extends WindowTable implements Updatable {
TextField search;
@Nullable Player target;
float heat;
ImageButton.ImageButtonStyle ustyle;
public PlayerDisplay() {
super("Player Display", Icon.players, t -> {});
@@ -36,6 +37,14 @@ public class PlayerDisplay extends WindowTable implements Updatable {
search = Elem.newField(null, f->{});
search.setMessageText(Core.bundle.get("players.search"));
ustyle = new ImageButton.ImageButtonStyle(){{
down = Styles.none;
up = Styles.none;
imageDownColor = Pal.accent;
imageUpColor = Color.white;
imageOverColor = Color.lightGray;
}};
top();
topBar();
@@ -66,13 +75,6 @@ public class PlayerDisplay extends WindowTable implements Updatable {
public Table rebuild(){
return new Table(table -> {
float h = 74f;
ImageButton.ImageButtonStyle ustyle = new ImageButton.ImageButtonStyle(){{
down = Styles.none;
up = Styles.none;
imageDownColor = Pal.accent;
imageUpColor = Color.white;
imageOverColor = Color.lightGray;
}};
Seq<Player> players = Groups.player.copy(new Seq<>());

View File

@@ -38,8 +38,8 @@ import mindustry.world.blocks.distribution.MassDriver;
import mindustry.world.blocks.payloads.Payload;
import mindustry.world.blocks.power.*;
import static UnitInfo.SVars.clear;
import static UnitInfo.SVars.modUiScale;
import static UnitInfo.SVars.*;
import static UnitInfo.SUtils.*;
import static arc.Core.*;
import static mindustry.Vars.*;
@@ -87,7 +87,7 @@ public class UnitDisplay extends WindowTable implements Updatable {
else if (target instanceof Building b && b.block != null) ui.content.show(b.block);
});
ttt.add(imagebt).update((i) -> {
i.getStyle().imageUp = reg.get().tint(Tmp.c1.set(SVars.hud.locked ? Color.red.cpy().shiftHue(2 * Time.time) : Color.white));
i.getStyle().imageUp = reg.get().tint(Tmp.c1.set(locked ? Color.red.cpy().shiftHue(2 * Time.time) : Color.white));
i.getStyle().imageDown = reg.get().tint(Tmp.c1.mul(Color.darkGray));
i.layout();
}).size(4 * 8f).get().parent = null;
@@ -161,13 +161,9 @@ public class UnitDisplay extends WindowTable implements Updatable {
resizeButton();
}
public static Teamc getTarget() {
return SVars.hud == null ? null : SVars.hud.getTarget();
}
public void lockTarget() {
SVars.hud.locked = !SVars.hud.locked;
SVars.hud.lockedTarget = SVars.hud.locked ? getTarget() : null;
locked = !locked;
target = locked ? getTarget() : null;
}
public void showMoving() {
@@ -337,10 +333,10 @@ public class UnitDisplay extends WindowTable implements Updatable {
if(getDrawable() != null)
getDrawable().draw(x + imageX, y + imageY, imageWidth * scaleX, imageHeight * scaleY);
}
}).size(Scl.scl(modUiScale) * iconLarge);
}).size(iconLarge);
}),
new Table(h -> {
h.defaults().growX().height(Scl.scl(modUiScale) * 9f).width(Scl.scl(modUiScale) * iconLarge).padTop(Scl.scl(modUiScale) * 18f);
h.defaults().growX().height(9f).width(iconLarge).padTop(18f);
h.add(new SBar(
() -> "",
() -> Pal.accent.cpy().lerp(Color.orange, mount.reload / weapon.reload),