From 65d7bd1350f50c799058b4753d3fc4b1852751b7 Mon Sep 17 00:00:00 2001 From: sharlotte Date: Thu, 5 Aug 2021 13:00:11 +0900 Subject: [PATCH] clean up --- src/UnitInfo/SVars.java | 4 ++ src/UnitInfo/core/HudUi.java | 82 +++++++++++++++--------------------- src/UnitInfo/core/Main.java | 9 ++-- 3 files changed, 43 insertions(+), 52 deletions(-) diff --git a/src/UnitInfo/SVars.java b/src/UnitInfo/SVars.java index 39c6c29..dd9635c 100644 --- a/src/UnitInfo/SVars.java +++ b/src/UnitInfo/SVars.java @@ -2,8 +2,10 @@ package UnitInfo; import UnitInfo.core.*; import arc.files.*; +import arc.graphics.g2d.TextureRegion; import arc.struct.*; +import static arc.Core.atlas; import static mindustry.Vars.*; public class SVars { @@ -13,4 +15,6 @@ public class SVars { public static SettingS settingAdder = new SettingS(); public static HudUi hud = new HudUi(); public static PlayerParser playerinfo = new PlayerParser(); + + public static TextureRegion clear = atlas.find("clear"); } diff --git a/src/UnitInfo/core/HudUi.java b/src/UnitInfo/core/HudUi.java index 53f4e48..73f0798 100644 --- a/src/UnitInfo/core/HudUi.java +++ b/src/UnitInfo/core/HudUi.java @@ -1,5 +1,6 @@ package UnitInfo.core; +import UnitInfo.SVars; import UnitInfo.ui.*; import arc.*; import arc.graphics.*; @@ -26,8 +27,7 @@ import mindustry.graphics.*; import mindustry.input.*; import mindustry.logic.*; import mindustry.type.*; -import mindustry.type.ammo.ItemAmmoType; -import mindustry.type.ammo.PowerAmmoType; +import mindustry.type.ammo.*; import mindustry.ui.*; import mindustry.world.*; import mindustry.world.blocks.*; @@ -36,8 +36,6 @@ import mindustry.world.blocks.distribution.MassDriver; import mindustry.world.blocks.power.PowerNode; import mindustry.world.blocks.storage.*; -import java.util.Objects; - import static arc.Core.*; import static mindustry.Vars.*; @@ -74,14 +72,11 @@ public class HudUi { Seq colors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear); Seq lastColors = Seq.with(Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear); CoresItemsDisplay coreItems = new CoresItemsDisplay(Team.baseTeams); - @Nullable Teamc target; public Seq linkedMasses = new Seq<>(); public Seq linkedNodes = new Seq<>(); - boolean remoteChanged = false; - @SuppressWarnings("unchecked") public T getTarget(){ if(locked && lockedTarget != null) { @@ -217,20 +212,17 @@ public class HudUi { Lines.dashLine(x1, y1, x2, y2, segs); Lines.stroke(2f, Pal.placing); Lines.dashLine(x1, y1, x2, y2, segs); - Lines.stroke(1f, Pal.accent); + + Fonts.outline.draw(Strings.fixed(to.dst(from.x(), from.y()), 2) + " (" + segs + "tiles)", + from.x() + Angles.trnsx(Angles.angle(from.x(), from.y(), to.x(), to.y()), player.unit().hitSize() + 40), + from.y() + Angles.trnsy(Angles.angle(from.x(), from.y(), to.x(), to.y()), player.unit().hitSize() + 40) - 3, + Pal.accent, 0.25f, false, Align.center); } - }; + } Draw.reset(); }); - Events.on(EventType.ResetEvent.class, e -> { - if(settings.getBool("allTeam")) coreItems.teams = Team.all; - else coreItems.teams = Team.baseTeams; - coreItems.resetUsed(); - coreItems.tables.each(Group::clear); - }); - Events.run(EventType.Trigger.update, ()->{ if((input.keyDown(KeyCode.shiftRight) || input.keyDown(KeyCode.shiftLeft))){ if(input.keyTap(KeyCode.r)) lockButton.change(); @@ -246,36 +238,31 @@ public class HudUi { target = null; } - float mouseAngle = unit.angleTo(unit.aimX(), unit.aimY()); boolean aimCursor = omni && player.shooting && unit.type.hasWeapons() && unit.type.faceTarget && !boosted && unit.type.rotateShooting; - if (aimCursor) { - unit.lookAt(mouseAngle); - } else { - unit.lookAt(unit.prefRotation()); - } + unit.lookAt(aimCursor ? mouseAngle : unit.prefRotation()); //update shooting if not building + not mining - if (!player.unit().activelyBuilding() && player.unit().mineTile == null) { - //autofire targeting - if (input.keyDown(KeyCode.mouseLeft)) { + if(!player.unit().activelyBuilding() && player.unit().mineTile == null) { + if(input.keyDown(KeyCode.mouseLeft)) { player.shooting = !boosted; unit.aim(player.mouseX = Core.input.mouseWorldX(), player.mouseY = Core.input.mouseWorldY()); - } else if (target == null) { + } else if(target == null) { player.shooting = false; - if (unit instanceof BlockUnitUnit b) { - if (b.tile() instanceof ControlBlock c && !c.shouldAutoTarget()) { + 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; target = Units.closestTarget(build.team, build.x, build.y, range, u -> u.checkTarget(targetAir, targetGround), u -> targetGround); - } else target = null; - } else if (unit.type != null) { + } + else target = null; + } else if(unit.type != null) { float range = unit.hasWeapons() ? unit.range() : 0f; target = 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 && target == null) { + if(unit.type.canHeal && target == null) { target = Geometry.findClosest(unit.x, unit.y, indexer.getDamaged(Team.sharded)); if (target != null && !unit.within(target, range)) { target = null; @@ -291,6 +278,13 @@ public class HudUi { unit.controlWeapons(player.shooting && !boosted); } }); + + Events.on(EventType.ResetEvent.class, e -> { + if(settings.getBool("allTeam")) coreItems.teams = Team.all; + else coreItems.teams = Team.baseTeams; + coreItems.resetUsed(); + coreItems.tables.each(Group::clear); + }); } public void reset(int index, Seq