bugfixing

This commit is contained in:
sharlotte
2021-09-11 10:50:30 +09:00
parent 816e20151a
commit f2d1d7fd4a
7 changed files with 129 additions and 241 deletions

View File

@@ -4,8 +4,8 @@ shar-stat.shield = Shield: {0}
shar-stat.payloadCapacity = Payloads: {0}²/{1}² shar-stat.payloadCapacity = Payloads: {0}²/{1}²
shar-stat.capacity = {0}: {1}/{2} shar-stat.capacity = {0}: {1}/{2}
shar-stat.power = Power: {0}/{1} shar-stat.power = Power: {0}/{1}
shar-stat.powerIn = Power Income: {0}/s shar-stat.powerIn = InPower: {0}/s
shar-stat.powerOut = Power Outcome: {0}/s shar-stat.powerOut = OutPower: {0}/s
shar-stat.ammos = Ammo: {0}/{1} shar-stat.ammos = Ammo: {0}/{1}
shar-stat.commandUnits = Commands: {0}/{1} shar-stat.commandUnits = Commands: {0}/{1}
shar-stat.reload = Reload: {0}% shar-stat.reload = Reload: {0}%

View File

@@ -123,7 +123,7 @@ public class BarInfo {
numbers.set(1, node.power.graph.getLastPowerStored() / node.power.graph.getLastCapacity()); numbers.set(1, node.power.graph.getLastPowerStored() / node.power.graph.getLastCapacity());
} }
else if(target instanceof PowerGenerator.GeneratorBuild generator){ else if(target instanceof PowerGenerator.GeneratorBuild generator){
strings.set(1, bundle.format("shar-stat.power", floatFormat(generator.getPowerProduction() * generator.timeScale() * 60f))); strings.set(1, bundle.format("shar-stat.powerIn", floatFormat(generator.getPowerProduction() * generator.timeScale() * 60f)));
colors.set(1, Pal.powerBar); colors.set(1, Pal.powerBar);
numbers.set(1, generator.productionEfficiency); numbers.set(1, generator.productionEfficiency);
} }
@@ -232,7 +232,7 @@ public class BarInfo {
} }
if(target instanceof Unit unit && target instanceof Payloadc pay && unit.type != null){ if(target instanceof Unit unit && unit.type != null && target instanceof Payloadc pay){
strings.set(4, bundle.format("shar-stat.payloadCapacity", floatFormat(Mathf.round(Mathf.sqrt(pay.payloadUsed()))), floatFormat(Mathf.round(Mathf.sqrt(unit.type().payloadCapacity))))); strings.set(4, bundle.format("shar-stat.payloadCapacity", floatFormat(Mathf.round(Mathf.sqrt(pay.payloadUsed()))), floatFormat(Mathf.round(Mathf.sqrt(unit.type().payloadCapacity)))));
colors.set(4, Pal.items); colors.set(4, Pal.items);
numbers.set(4, pay.payloadUsed() / unit.type().payloadCapacity); numbers.set(4, pay.payloadUsed() / unit.type().payloadCapacity);

View File

@@ -18,11 +18,13 @@ import arc.util.*;
import mindustry.*; import mindustry.*;
import mindustry.content.*; import mindustry.content.*;
import mindustry.core.*; import mindustry.core.*;
import mindustry.entities.Units;
import mindustry.entities.units.*; import mindustry.entities.units.*;
import mindustry.game.*; import mindustry.game.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.input.*; import mindustry.input.*;
import mindustry.logic.Ranged;
import mindustry.type.*; import mindustry.type.*;
import mindustry.ui.*; import mindustry.ui.*;
import mindustry.world.*; import mindustry.world.*;
@@ -52,6 +54,7 @@ public class HudUi {
float waveScrollPos; float waveScrollPos;
float itemScrollPos; float itemScrollPos;
Teamc shotTarget;
Teamc lockedTarget; Teamc lockedTarget;
ImageButton lockButton; ImageButton lockButton;
boolean locked = false; boolean locked = false;
@@ -98,8 +101,9 @@ public class HudUi {
} }
public void setEvents() { public void setEvents() {
Events.run(EventType.Trigger.update, ()->{ Events.run(EventType.Trigger.update, ()->{
OverDrawer.target = getTarget();
OverDrawer.locked = locked;
if(settings.getBool("deadTarget") && locked && lockedTarget != null && !Groups.all.contains(e -> e == lockedTarget)) { if(settings.getBool("deadTarget") && locked && lockedTarget != null && !Groups.all.contains(e -> e == lockedTarget)) {
lockedTarget = null; lockedTarget = null;
locked = false; locked = false;
@@ -115,6 +119,56 @@ public class HudUi {
if((input.keyDown(KeyCode.shiftRight) || input.keyDown(KeyCode.shiftLeft))){ if((input.keyDown(KeyCode.shiftRight) || input.keyDown(KeyCode.shiftLeft))){
if(input.keyTap(KeyCode.r)) lockButton.change(); if(input.keyTap(KeyCode.r)) lockButton.change();
} }
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);
}
}); });
Events.on(EventType.BlockDestroyEvent.class, e -> { Events.on(EventType.BlockDestroyEvent.class, e -> {
@@ -292,8 +346,8 @@ public class HudUi {
public TextureRegion getRegions(int i){ public TextureRegion getRegions(int i){
Teamc target = getTarget(); Teamc target = getTarget();
TextureRegion region = clear; TextureRegion region = clear;
if(i == 0){ if(i == 0){
if(target instanceof Healthc) region = SIcons.health; if(target instanceof Healthc) region = SIcons.health;
} else if(i == 1){ } else if(i == 1){
@@ -541,20 +595,19 @@ public class HudUi {
})); }));
add(new Table(ttt -> { add(new Table(ttt -> {
ttt.add(new Stack(){{ ttt.stack(
add(new Table(temp -> { new Table(temp -> {
temp.image(new ScaledNinePatchDrawable(new NinePatch(Icon.defenseSmall.getRegion()), modUiScale)); temp.image(new ScaledNinePatchDrawable(new NinePatch(Icon.defenseSmall.getRegion()), modUiScale));
temp.visibility = () -> getTarget() instanceof Unit; temp.visibility = () -> getTarget() instanceof Unit;
})); }),
new Table(temp -> {
add(new Table(temp -> {
Label label = new Label(() -> (getTarget() instanceof Unit u && u.type != null ? (int) u.type.armor + "" : "")); Label label = new Label(() -> (getTarget() instanceof Unit u && u.type != null ? (int) u.type.armor + "" : ""));
label.setColor(Pal.surge); label.setColor(Pal.surge);
label.setFontScale(Scl.scl(modUiScale) * 0.5f); label.setFontScale(Scl.scl(modUiScale) * 0.5f);
temp.add(label).center(); temp.add(label).center();
temp.pack(); temp.pack();
})); })
}}).padLeft(Scl.scl(modUiScale) * 2 * 8f).padBottom(Scl.scl(modUiScale) * 2 * 8f); ).padLeft(Scl.scl(modUiScale) * 2 * 8f).padBottom(Scl.scl(modUiScale) * 2 * 8f);
})); }));
}}; }};

View File

@@ -20,8 +20,8 @@ public class Main extends Mod {
}); });
Events.on(ClientLoadEvent.class, e -> { Events.on(ClientLoadEvent.class, e -> {
hud = new HudUi();
new SettingS().init(); new SettingS().init();
hud = new HudUi();
hud.addWaveTable(); hud.addWaveTable();
hud.addUnitTable(); hud.addUnitTable();
hud.addTable(); hud.addTable();

View File

@@ -4,9 +4,8 @@ import UnitInfo.ui.FreeBar;
import arc.*; import arc.*;
import arc.graphics.Color; import arc.graphics.Color;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.input.KeyCode;
import arc.math.*; import arc.math.*;
import arc.math.geom.Geometry; import arc.math.geom.Position;
import arc.scene.ui.layout.Scl; import arc.scene.ui.layout.Scl;
import arc.struct.Seq; import arc.struct.Seq;
import arc.util.*; import arc.util.*;
@@ -15,19 +14,14 @@ import mindustry.ai.Pathfinder;
import mindustry.ai.types.*; import mindustry.ai.types.*;
import mindustry.content.Fx; import mindustry.content.Fx;
import mindustry.core.Renderer; import mindustry.core.Renderer;
import mindustry.entities.*; import mindustry.entities.units.*;
import mindustry.entities.units.AIController;
import mindustry.entities.units.UnitCommand;
import mindustry.entities.units.UnitController;
import mindustry.game.*; import mindustry.game.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.logic.LUnitControl; import mindustry.logic.LUnitControl;
import mindustry.logic.Ranged;
import mindustry.ui.Fonts; import mindustry.ui.Fonts;
import mindustry.world.Block; import mindustry.world.Block;
import mindustry.world.Tile; import mindustry.world.Tile;
import mindustry.world.blocks.ControlBlock;
import mindustry.world.blocks.defense.turrets.*; import mindustry.world.blocks.defense.turrets.*;
import mindustry.world.blocks.distribution.MassDriver; import mindustry.world.blocks.distribution.MassDriver;
import mindustry.world.blocks.payloads.PayloadMassDriver; import mindustry.world.blocks.payloads.PayloadMassDriver;
@@ -39,22 +33,17 @@ import java.util.Objects;
import static UnitInfo.SVars.*; import static UnitInfo.SVars.*;
import static arc.Core.*; import static arc.Core.*;
import static arc.Core.input;
import static mindustry.Vars.*; import static mindustry.Vars.*;
import static mindustry.Vars.player;
public class OverDrawer { public class OverDrawer {
@Nullable public static Teamc target; public static Teamc target;
public static Seq<MassDriver.MassDriverBuild> linkedMasses = new Seq<>(); public static Seq<MassDriver.MassDriverBuild> linkedMasses = new Seq<>();
public static Seq<PayloadMassDriver.PayloadDriverBuild> linkedPayloadMasses = new Seq<>(); public static Seq<PayloadMassDriver.PayloadDriverBuild> linkedPayloadMasses = new Seq<>();
public static Seq<Building> linkedNodes = new Seq<>(); public static Seq<Building> linkedNodes = new Seq<>();
public static int otherCores; public static Seq<Building> linkedBuilds = new Seq<>();
public static Seq<Tile> pathTiles = new Seq<>(); public static Seq<Tile> pathTiles = new Seq<>();
public static int otherCores;
@SuppressWarnings("unchecked") public static boolean locked;
public static <T extends Teamc> T getTarget(){
return (T) (target = hud.getTarget());
}
public static void setEvent(){ public static void setEvent(){
Events.run(EventType.Trigger.draw, () -> { Events.run(EventType.Trigger.draw, () -> {
@@ -64,20 +53,19 @@ public class OverDrawer {
int[] paths = {0}; int[] paths = {0};
int[] units = {0}; int[] units = {0};
int[] logics = {0}; int[] logics = {0};
if(pathLine || unitLine || logicLine) Groups.unit.each(u -> { if(unitLine || logicLine) Groups.unit.each(u -> {
UnitController c = u.controller(); UnitController c = u.controller();
UnitCommand com = u.team.data().command; UnitCommand com = u.team.data().command;
if(c instanceof LogicAI ai){ if(c instanceof LogicAI ai &&
if(logics[0] <= settings.getInt("logiclinelimit") || (logicLine && (ai.control == LUnitControl.approach || ai.control == LUnitControl.move))) { logics[0] <= settings.getInt("logiclinelimit") &&
logicLine && (ai.control == LUnitControl.approach || ai.control == LUnitControl.move)) {
logics[0]++; logics[0]++;
Lines.stroke(1, u.team.color); Lines.stroke(1, u.team.color);
Lines.line(u.x(), u.y(), ai.moveX, ai.moveY); 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.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); Lines.line(u.x(), u.y(), ai.controller.x, ai.controller.y);
} }
return;
}
if(units[0] > settings.getInt("unitlinelimit") || //prevent lag if(units[0] > settings.getInt("unitlinelimit") || //prevent lag
!unitLine || //disabled !unitLine || //disabled
@@ -86,7 +74,7 @@ public class OverDrawer {
c instanceof BuilderAI || //not poly c instanceof BuilderAI || //not poly
c instanceof RepairAI || //not mega c instanceof RepairAI || //not mega
c instanceof DefenderAI || //not oct c instanceof DefenderAI || //not oct
c instanceof FormationAI || //not commanded unit by player c instanceof FormationAI || //not commanded unit
c instanceof FlyingAI || //not flying anyway c instanceof FlyingAI || //not flying anyway
com == UnitCommand.idle) return; //not idle com == UnitCommand.idle) return; //not idle
units[0]++; units[0]++;
@@ -127,12 +115,16 @@ public class OverDrawer {
if(settings.getBool("spawnerarrow")) spawner.getSpawns().each(t -> { if(settings.getBool("spawnerarrow")) spawner.getSpawns().each(t -> {
if(arrows[0] > settings.getInt("spawnarrowlimit")) return; if(arrows[0] > settings.getInt("spawnarrowlimit")) return;
arrows[0]++; arrows[0]++;
Drawf.circles(camera.position.x, camera.position.y, (player.unit() != null && player.unit().hitSize > 4 * 8f ? player.unit().hitSize * 1.5f : 4 * 8f) + sin - 4f); float leng = (player.unit() != null && player.unit().hitSize > 4 * 8f ? player.unit().hitSize * 1.5f : 4 * 8f) + sin;
Drawf.arrow(camera.position.x, camera.position.y, t.x * 8f, t.y * 8f, (player.unit() != null && player.unit().hitSize > 4 * 8f ? player.unit().hitSize * 1.5f : 4 * 8f) + sin, (Math.min(200 * 8f, Mathf.dst(camera.position.x, camera.position.y, t.x * 8f, t.y * 8f)) / (200 * 8f)) * (5f + sin)); float camx = camera.position.x;
float camy = camera.position.y;
Lines.stroke(1f + sin/2, Pal.accent);
Lines.circle(camx, camy, leng - 4f);
Drawf.arrow(camx, camy, t.worldx(), t.worldy(), leng, (Math.min(200 * 8f, Mathf.dst(camx, camy, t.worldx(), t.worldy())) / (200 * 8f)) * (5f + sin));
}); });
if(settings.getBool("blockstatus")) Groups.build.each(build -> { if(settings.getBool("blockstatus")) Groups.build.each(build -> {
if(Vars.player != null && Vars.player.team() == build.team) return; if(Vars.player != null && player.team() == build.team) return;
Block block = build.block; Block block = build.block;
if(block.enableDrawStatus && block.consumes.any()){ if(block.enableDrawStatus && block.consumes.any()){
@@ -148,8 +140,7 @@ public class OverDrawer {
} }
}); });
if(Core.settings.getBool("unithealthui")) if(Core.settings.getBool("unithealthui")) Groups.unit.each(FreeBar::draw);
Groups.unit.each(unit -> new FreeBar().draw(unit));
if(!mobile && !Vars.state.isPaused() && settings.getBool("gaycursor")) if(!mobile && !Vars.state.isPaused() && settings.getBool("gaycursor"))
Fx.mine.at(Core.input.mouseWorldX(), Core.input.mouseWorldY(), Tmp.c2.set(Color.red).shiftHue(Time.time * 1.5f)); Fx.mine.at(Core.input.mouseWorldX(), Core.input.mouseWorldY(), Tmp.c2.set(Color.red).shiftHue(Time.time * 1.5f));
@@ -226,37 +217,37 @@ public class OverDrawer {
} }
if(settings.getBool("linkedMass")){ if(settings.getBool("linkedMass")){
if(getTarget() instanceof MassDriver.MassDriverBuild mass) { if(target instanceof MassDriver.MassDriverBuild mass) {
linkedMasses.clear(); linkedMasses.clear();
drawMassLink(mass); drawMassLink(mass);
} }
else if(getTarget() instanceof PayloadMassDriver.PayloadDriverBuild mass) { else if(target instanceof PayloadMassDriver.PayloadDriverBuild mass) {
linkedPayloadMasses.clear(); linkedPayloadMasses.clear();
drawMassPayloadLink(mass); drawMassPayloadLink(mass);
} }
} }
if(settings.getBool("linkedNode") && getTarget() instanceof Building node){ if(settings.getBool("linkedNode") && target instanceof Building node){
linkedNodes.clear(); linkedNodes.clear();
drawNodeLink(node); drawNodeLink(node);
} }
if(settings.getBool("select") && getTarget() != null) { if(settings.getBool("select") && target != null) {
Posc entity = getTarget();
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++){
float rot = i * 90f + 45f + (-Time.time) % 360f; float rot = i * 90f + 45f + (-Time.time) % 360f;
float length = (entity instanceof Unit ? ((Unit)entity).hitSize : entity instanceof Building ? ((Building)entity).block.size * tilesize : 0) * 1.5f + 2.5f; float length = (target instanceof Unit u ? u.hitSize : target instanceof Building b ? b.block.size * tilesize : 0) * 1.5f + 2.5f;
Draw.color(Tmp.c1.set(hud.locked ? Color.orange : Color.darkGray).lerp(hud.locked ? Color.scarlet : Color.gray, Mathf.absin(Time.time, 3f, 1f)).a(settings.getInt("selectopacity") / 100f)); Draw.color(Tmp.c1.set(locked ? Color.orange : Color.darkGray).lerp(locked ? Color.scarlet : Color.gray, Mathf.absin(Time.time, 3f, 1f)).a(settings.getInt("selectopacity") / 100f));
Draw.rect("select-arrow", entity.x() + Angles.trnsx(rot, length), entity.y() + Angles.trnsy(rot, length), length / 1.9f, length / 1.9f, rot - 135f); Draw.rect("select-arrow", target.x() + Angles.trnsx(rot, length), target.y() + Angles.trnsy(rot, length), length / 1.9f, length / 1.9f, rot - 135f);
} }
if(settings.getBool("distanceLine") && player.unit() != null && !player.unit().dead && getTarget() != player.unit()) { //need selected other unit with living player if(settings.getBool("distanceLine") && player.unit() != null && !player.unit().dead && target != null) { //need selected other unit with living player
Teamc from = player.unit(); Teamc from = player.unit();
Teamc to = getTarget(); Position to = target;
if(player.unit() instanceof BlockUnitUnit bu) Tmp.v1.set(bu.x() + bu.tile().block.offset, bu.y() + bu.tile().block.offset).sub(to.x(), to.y()).limit(bu.tile().block.size * tilesize + sin + 0.5f); if(to == from) to = input.mouseWorld();
else Tmp.v1.set(from.x(), from.y()).sub(to.x(), to.y()).limit(player.unit().hitSize + sin + 0.5f); if(player.unit() instanceof BlockUnitUnit bu) Tmp.v1.set(bu.x() + bu.tile().block.offset, bu.y() + bu.tile().block.offset).sub(to.getX(), to.getY()).limit(bu.tile().block.size * tilesize + sin + 0.5f);
else Tmp.v1.set(from.x(), from.y()).sub(to.getX(), to.getY()).limit(player.unit().hitSize + sin + 0.5f);
float x2 = from.x() - Tmp.v1.x, y2 = from.y() - Tmp.v1.y, float x2 = from.x() - Tmp.v1.x, y2 = from.y() - Tmp.v1.y,
x1 = to.x() + Tmp.v1.x, y1 = to.y() + Tmp.v1.y; x1 = to.getX() + Tmp.v1.x, y1 = to.getY() + Tmp.v1.y;
int segs = (int) (to.dst(from.x(), from.y()) / tilesize); int segs = (int) (to.dst(from.x(), from.y()) / tilesize);
if(segs > 0){ if(segs > 0){
Lines.stroke(2.5f, Pal.gray); Lines.stroke(2.5f, Pal.gray);
@@ -265,8 +256,8 @@ public class OverDrawer {
Lines.dashLine(x1, y1, x2, y2, segs); Lines.dashLine(x1, y1, x2, y2, segs);
Fonts.outline.draw(Strings.fixed(to.dst(from.x(), from.y()), 2) + " (" + segs + "tiles)", 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.x() + Angles.trnsx(Angles.angle(from.x(), from.y(), to.getX(), to.getY()), player.unit().hitSize() + Math.min(segs, 6) * 8f),
from.y() + Angles.trnsy(Angles.angle(from.x(), from.y(), to.x(), to.y()), player.unit().hitSize() + 40) - 3, from.y() + Angles.trnsy(Angles.angle(from.x(), from.y(), to.getX(), to.getY()), player.unit().hitSize() + Math.min(segs, 6) * 8f) - 3,
Pal.accent, 0.25f, false, Align.center); Pal.accent, 0.25f, false, Align.center);
} }
} }
@@ -275,57 +266,7 @@ public class OverDrawer {
Draw.reset(); Draw.reset();
}); });
Events.run(EventType.Trigger.update, ()->{
if(settings.getBool("autoShooting")) {
Unit unit = player.unit();
if (unit.type == null) return;
boolean omni = unit.type.omniMovement;
boolean validHealTarget = unit.type.canHeal && target instanceof Building && ((Building) target).isValid() && target.team() == unit.team && ((Building) target).damaged() && target.within(unit, unit.type.range);
boolean boosted = (unit instanceof Mechc && unit.isFlying());
if ((unit.type != null && Units.invalidateTarget(target, unit, unit.type.range) && !validHealTarget) || state.isEditor()) {
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;
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(target == 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;
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) {
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) {
target = Geometry.findClosest(unit.x, unit.y, indexer.getDamaged(Team.sharded));
if (target != null && !unit.within(target, range)) {
target = null;
}
}
}
} else {
player.shooting = !boosted;
unit.rotation(Angles.angle(unit.x, unit.y, target.x(), target.y()));
unit.aim(target.x(), target.y());
}
}
unit.controlWeapons(player.shooting && !boosted);
}
});
} }
public static Tile getNextTile(Tile tile, int cost, Team team, int finder) { public static Tile getNextTile(Tile tile, int cost, Team team, int finder) {
@@ -421,7 +362,7 @@ public class OverDrawer {
} }
public static Seq<Building> getPowerLinkedBuilds(Building build) { public static Seq<Building> getPowerLinkedBuilds(Building build) {
Seq<Building> linkedBuilds = new Seq<>(); linkedBuilds.clear();
build.power.links.each(i -> linkedBuilds.add(world.build(i))); build.power.links.each(i -> linkedBuilds.add(world.build(i)));
build.proximity().each(linkedBuilds::add); build.proximity().each(linkedBuilds::add);
linkedBuilds.filter(b -> b != null && b.power != null); linkedBuilds.filter(b -> b != null && b.power != null);

View File

@@ -1,52 +1,24 @@
package UnitInfo.ui; package UnitInfo.ui;
import arc.*;
import arc.func.*;
import arc.graphics.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*; import arc.math.*;
import arc.scene.style.TextureRegionDrawable;
import arc.scene.ui.Tooltip;
import arc.struct.*; import arc.struct.*;
import arc.util.*;
import mindustry.*; import mindustry.*;
import mindustry.content.*;
import mindustry.core.UI;
import mindustry.entities.abilities.*; import mindustry.entities.abilities.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.ui.Styles;
import mindustry.world.blocks.defense.*;
import mindustry.world.blocks.defense.turrets.*;
import mindustry.world.blocks.payloads.Payload; import mindustry.world.blocks.payloads.Payload;
import static arc.Core.*; import static arc.Core.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class FreeBar { public class FreeBar {
public float value; public static void draw(Unit unit){
public void draw(Unit unit){
if(unit.dead()) return; if(unit.dead()) return;
float height = 2f;
if(Float.isNaN(value)) value = 0;
if(Float.isInfinite(value)) value = 1f;
value = Mathf.lerpDelta(value, Mathf.clamp(unit.healthf()), 0.15f);
Draw.z(Layer.flyingUnit + 1); Draw.z(Layer.flyingUnit + 1);
if(unit instanceof Payloadc payload && payload.payloadUsed() > 0){
int i = 0;
int row = 0;
for(Payload p : payload.payloads()){
new TextureRegionDrawable(p.icon()).draw(unit.x - (unit.type.hitSize + 4)/2 + i * 4, unit.y - 14 - 4 * row, 4,4);
if(++i > 2 * (unit.type.hitSize + 4)) row++;
}
}
Bits statuses = new Bits(); Bits statuses = new Bits();
Bits applied = unit.statusBits(); Bits applied = unit.statusBits();
if(!statuses.equals(applied) && applied != null){ if(!statuses.equals(applied) && applied != null){
@@ -54,15 +26,25 @@ public class FreeBar {
int row = 0; int row = 0;
for(StatusEffect effect : content.statusEffects()){ for(StatusEffect effect : content.statusEffects()){
if(applied.get(effect.id) && !effect.isHidden()){ if(applied.get(effect.id) && !effect.isHidden()){
new TextureRegionDrawable(effect.uiIcon).draw(unit.x - (unit.type.hitSize + 4)/2 + i * 4, unit.y - 6 + 4 * row, 4,4); Draw.rect(effect.uiIcon, unit.x - (unit.type.hitSize + 4)/2 + i * 4, unit.y - 4 + 4 * row, 4,4);
if(++i > 2 * (unit.type.hitSize + 4)) row++; if(++i > 2 * (unit.type.hitSize + 4)) row++;
} }
} }
statuses.set(applied); statuses.set(applied);
} }
if(unit instanceof Payloadc payload && payload.payloads().any()){
int i = 0;
int row = 0;
for(Payload p : payload.payloads()){
Draw.rect(p.icon(), unit.x - (unit.type.hitSize + 4)/2 + i * 4, unit.y - 12 - 4 * row, 4,4);
if(++i > 2 * (unit.type.hitSize + 4)) row++;
}
}
Draw.color(0.1f, 0.1f, 0.1f, (settings.getInt("baropacity") / 100f)); Draw.color(0.1f, 0.1f, 0.1f, (settings.getInt("baropacity") / 100f));
float width = unit.type.hitSize + 4f; float width = unit.type.hitSize + 4f;
float height = 2f;
float x = unit.x; float x = unit.x;
float y = unit.y - 8; float y = unit.y - 8;
for(int i : Mathf.signs) { for(int i : Mathf.signs) {
@@ -133,92 +115,4 @@ public class FreeBar {
Draw.reset(); Draw.reset();
} }
public void draw(Building build){
if(build.dead()
|| (!(build instanceof BaseTurret.BaseTurretBuild) && !(build instanceof Wall.WallBuild))) return;
float height = 2f;
if(Float.isNaN(value)) value = 0;
if(Float.isInfinite(value)) value = 1f;
value = Mathf.lerpDelta(value, Mathf.clamp(build.healthf()), 0.15f);
Draw.z(Layer.flyingUnit + 1);
Draw.color(0.1f, 0.1f, 0.1f, (settings.getInt("baropacity") / 100f));
float width = build.block.size * 8 / 2f + 4f;
float x = build.x;
float y = build.y - 8;
for(int i : Mathf.signs) {
for(int ii = 0; ii < 2; ii++){
float shadowx = x + ii * 0.25f;
float shadowy = y - ii * 0.5f;
Fill.poly(FloatSeq.with(
shadowx - (width / 2 + height), shadowy,
shadowx - width / 2, shadowy + i * height,
shadowx + width / 2, shadowy + i * height,
shadowx + (width / 2 + height), shadowy,
shadowx + width / 2, shadowy + i * -height,
shadowx - width / 2, shadowy + i * -height));
}
}
{
Draw.color(Pal.health.cpy().a((settings.getInt("baropacity") / 100f)));
float topWidth = - width / 2 + width * Mathf.clamp(build.healthf());
float moser = topWidth + height;
if(build.health <= 0) moser = (width / 2 + height) * (2 * Mathf.clamp(build.healthf()) - 1);
for(int i : Mathf.signs) {
Fill.poly(FloatSeq.with(
x - (width / 2 + height), y,
x - width / 2, y + i * height,
x + topWidth, y + i * height,
x + moser, y,
x + topWidth, y + i * -height,
x - width / 2, y + i * -height));
}
}
float h = 0;
Color color = Pal.ammo;
if(build instanceof ItemTurret.ItemTurretBuild) {
h = ((ItemTurret.ItemTurretBuild) build).totalAmmo / (((ItemTurret) build.block).maxAmmo * 1f);
if(((ItemTurret.ItemTurretBuild) build).hasAmmo()) color = ((ItemTurret) build.block).ammoTypes.findKey(((ItemTurret.ItemTurretBuild) build).peekAmmo(), true).color;
}
else if(build instanceof LiquidTurret.LiquidTurretBuild){
LiquidTurret.LiquidTurretBuild entity = (LiquidTurret.LiquidTurretBuild) build;
Func<Building, Liquid> current;
current = entity1 -> entity1.liquids == null ? Liquids.water : entity1.liquids.current();
h = entity.liquids == null ? 0f : entity.liquids.get(current.get(entity)) / entity.block.liquidCapacity;
color = current.get(entity).color;
}
else if(build instanceof PowerTurret.PowerTurretBuild){
PowerTurret.PowerTurretBuild entity = (PowerTurret.PowerTurretBuild) build;
h = entity.power.status;
color = Pal.powerBar;
}
if(Core.settings.getBool("range") && build instanceof BaseTurret.BaseTurretBuild) {
Drawf.dashCircle(build.x, build.y, ((BaseTurret.BaseTurretBuild) build).range(), build.team.color);
}
if(build instanceof Turret.TurretBuild) {
float topWidth = - width / 2 + width * Mathf.clamp(h);
float moser = topWidth + height;
if(h <= 0) moser = (width / 2 + height) * (2 * h - 1);
Draw.color(Tmp.c1.set(color).a(settings.getInt("baropacity") / 100f));
Fill.poly(FloatSeq.with(
x - (width / 2 + height), y,
x - width / 2, y + height,
x + topWidth, y + height,
x + moser, y,
x + topWidth, y - height,
x - width / 2, y - height));
}
Draw.reset();
}
} }