From de799fffd7b9ef3a5c67eb08b1b222f02ec06b1a Mon Sep 17 00:00:00 2001 From: sharlottes Date: Tue, 19 Apr 2022 00:08:49 +0900 Subject: [PATCH] clean code up --- assets/bundles/bundle.properties | 73 +++---- src/UnitInfo/SUtils.java | 39 ++++ src/UnitInfo/SVars.java | 2 +- src/UnitInfo/core/HudUi.java | 241 ++++++--------------- src/UnitInfo/core/Main.java | 17 +- src/UnitInfo/core/OverDrawer.java | 17 -- src/UnitInfo/core/SettingS.java | 43 +--- src/UnitInfo/ui/SBar.java | 5 +- src/UnitInfo/ui/draws/BlockDraw.java | 26 +-- src/UnitInfo/ui/draws/LinkDraw.java | 30 +-- src/UnitInfo/ui/draws/OverDraw.java | 39 +++- src/UnitInfo/ui/draws/OverDraws.java | 5 +- src/UnitInfo/ui/draws/RangeDraw.java | 44 +--- src/UnitInfo/ui/draws/UnitDraw.java | 42 +--- src/UnitInfo/ui/draws/UtilDraw.java | 80 +++++++ src/UnitInfo/ui/windows/PlayerDisplay.java | 16 +- src/UnitInfo/ui/windows/UnitDisplay.java | 18 +- 17 files changed, 306 insertions(+), 431 deletions(-) create mode 100644 src/UnitInfo/ui/draws/UtilDraw.java diff --git a/assets/bundles/bundle.properties b/assets/bundles/bundle.properties index 938632f..42ada5e 100644 --- a/assets/bundles/bundle.properties +++ b/assets/bundles/bundle.properties @@ -19,31 +19,15 @@ shar-stat.waveItem = [lightgray]Item:[] #Settings setting.barstyle.name = Unit UI: Change Bar Style setting.barstyle.description = Changes the bar sprite in the unit information interface. -setting.infoUiScale.name = Information UI Scale -setting.infoUiScale.description = Sets the scale of the UnitInfo information interface. -setting.coreItemCheckRate.name = Resource UI: Update Rate -setting.coreItemCheckRate.description = Sets how often the core resources are checked.\nThe slower rate, the better gameplay performance gets. setting.wavemax.name = Wave UI: Wave Amount To Display setting.wavemax.description = Sets the limit of visible waves in the wave list. -setting.infoui.name = Display Information UI -setting.infoui.description = Enables the information interface on the left to display.\nWhen disabled, all associated updates will be stopped. -setting.waveui.name = Display Wave UI -setting.waveui.description = Enables the top-left wave interface to display.\nWhen disabled, all associated updates will be stopped. setting.pastwave.name = Wave UI: Display Previous Wave setting.pastwave.description = Displays the previous wave in the wave list.\nThe current wave is highlighted with red color. setting.emptywave.name = Wave UI: Display Empty Wave setting.emptywave.description = Displays empty waves in the wave list. -setting.itemcal.name = Resource UI: Calculate item inc/dec speed. -setting.itemcal.description = Calculate increase/decrease speed of core item and display results. setting.schem.name = Display Schematic HUD setting.schem.description = Displays schem hud on right-side, which helps quick select. -setting.rangeRadius.name = Near Range Margin -setting.rangeRadius.description = Sets the range detection distance. -setting.rangeNearby.name = Display Near Range -setting.rangeNearby.description = Enables automatic range display.\nIf you approach the range by a certain distance, the range is displayed in advance. -setting.allTargetRange.name = Display All Target Ranges -setting.allTargetRange.description = Displays all target ranges.\nThe range of targets that cannot be aimed at themselves is shown as gray. setting.aliceRange.name = Display Alice Range setting.aliceRange.description = Displays alice turret range too. setting.RangeShader.name = Enable Animation @@ -53,51 +37,44 @@ setting.selectopacity.name = Select Arrow Opacity setting.selectopacity.description = Sets the opacity of selection arrow. setting.baropacity.name = Health Bar Opacity setting.baropacity.description = Sets the opacity of the unit health bar. -setting.uiopacity.name = UI Background Opacity -setting.uiopacity.description = Sets the opacity of the interface background. -setting.softRangeOpacity.name = Range Opacity -setting.softRangeOpacity.description = Sets the opacity of range circle. -setting.pathlinelimit.name = Path Line Limit -setting.pathlinelimit.description = Too many lines may cause significant device lag.\nIt must be adjusted to the device environment. -setting.unitlinelimit.name = Unit Line Limit -setting.unitlinelimit.description = Too many lines may cause significant device lag.\nIt must be adjusted to the device environment. -setting.logiclinelimit.name = Logic Line Limit -setting.logiclinelimit.description = Too many lines may cause significant device lag.\nIt must be adjusted to the device environment. -setting.spawnarrowlimit.name = Spawn Arrow Limit -setting.spawnarrowlimit.description = Too many arrows may cause significant device lag.\nIt must be adjusted to the device environment. -setting.gaycursor.name = Enable Mouse Trail Effect -setting.gaycursor.description = Creates a rainbow effect under the mouse cursor. -setting.unithealthui.name = Display Unit Bar -setting.unithealthui.description = Displays brief information about health, ammo, shield, status effect, and payload in each unit. -setting.blockfont.name = Display Block Info -setting.blockfont.description = Displays brief information about health, shield, reload, etc., in each block. -setting.linkedMass.name = Display Mass Driver Link Line -setting.linkedMass.description = Indicates the mass drives associated with the selected mass driver(s) by drawing lines. -setting.linkedNode.name = Display Node Link Line -setting.linkedNode.description = Indicates the blocks electrically connected to the selected block(s) by drawing lines. +setting.blockStatus.name = enable Block Status +setting.blockStatus.description = display enemy block status too +setting.powerNode.name = enable Power Node +setting.powerNode.description = display power node link lines +setting.massDriver.name = enable Mass Driver +setting.massDriver.description = display mass driver link lines +setting.airRange.name = enable air range +setting.airRange.description = display turret range that can target air units +setting.groundRange.name = enable ground range +setting.groundRange.description = display turret range that can target ground units +setting.pathLine.name = enable Path Line +setting.pathLine.description = display wave ground unit's ai path lineline +setting.logicLine.name = enable Logic Line +setting.logicLine.description = display lines between logic processor and controlled units +setting.unitLine.name = enable Unit Line +setting.unitLine.description = display ai path each ground units +setting.unitItem.name = enable Unit Item +setting.unitItem.description = display item amount under each units +setting.unitBar.name = enable Unit Bar +setting.unitBar.description = display health bar under each units +setting.autoShooting.name = Enable Auto Shooting +setting.autoShooting.description = no don't do hack + +setting.spawnerarrow.name = Indicate Wave Spawn-Point +setting.spawnerarrow.description = Displays arrow pointing to wave spawn-points. setting.select.name = Display Selection Arrow setting.select.description = Shows which unit or block is selected. -setting.deadTarget.name = Keep Target Locked After Its Death -setting.deadTarget.description = Continues to display the coordinates and target information even after the locked target(s) dies. setting.distanceLine.name = Display Distance Line From Selected Target setting.distanceLine.description = Displays dotted lines and numbers to indicate how far away the target is. -setting.spawnerarrow.name = Indicate Wave Spawn-Point -setting.spawnerarrow.description = Displays arrow pointing to wave spawn-points. setting.elementdebug.name = Element Debug setting.elementdebug.description = Show all Element outline setting.hiddenElem.name = Display hidden element setting.hiddenElem.description = display hidden element outline too. -setting.autoShooting.name = Enable Auto Shooting -setting.autoShooting.description = no don't do hack - setting.shar-title = UnitInfo Settings setting.shar-ui = Overlay UI Settings -setting.shar-range = Auto Range Settings -setting.shar-opacity = Opacity Settings setting.shar-draw = Overdrawing Settings -setting.shar-etc = Other #Hud hud.schematic-list = Schematic List diff --git a/src/UnitInfo/SUtils.java b/src/UnitInfo/SUtils.java index f552914..0c31c70 100644 --- a/src/UnitInfo/SUtils.java +++ b/src/UnitInfo/SUtils.java @@ -3,17 +3,56 @@ package UnitInfo; import arc.graphics.g2d.*; import arc.math.Mathf; import arc.scene.style.*; +import arc.struct.Seq; +import arc.util.Nullable; import arc.util.Strings; +import mindustry.Vars; import mindustry.core.UI; import mindustry.entities.bullet.BulletType; import mindustry.entities.bullet.LightningBulletType; +import mindustry.gen.BlockUnitUnit; +import mindustry.gen.Groups; +import mindustry.gen.Teamc; +import mindustry.gen.Unit; import mindustry.type.UnitType; import mindustry.type.weapons.PointDefenseWeapon; import mindustry.type.weapons.RepairBeamWeapon; +import mindustry.world.Tile; import java.lang.reflect.*; +import static UnitInfo.SVars.locked; +import static UnitInfo.SVars.target; +import static arc.Core.input; +import static arc.Core.settings; +import static mindustry.Vars.player; + public class SUtils { + @SuppressWarnings("unchecked") + public static T getTarget(){ + if(locked && target != null) { + if(settings.getBool("deadTarget") && !Groups.all.contains(e -> e == target)) { + target = null; + locked = false; + } + else return (T) target; //if there is locked target, return it first. + } + + Seq units = Groups.unit.intersect(input.mouseWorldX(), input.mouseWorldY(), 4, 4); // well, 0.5tile is enough to search them + if(units.size > 0) + return (T) units.peek(); //if there is unit, return it. + else if(getTile() != null && getTile().build != null) + return (T) getTile().build; //if there isn't unit but there is build, return it. + else if(player.unit() instanceof BlockUnitUnit b && b.tile() != null) + return (T)b.tile(); + return (T) player.unit(); //if there aren't unit and not build, return player. + } + + @Nullable + public static Tile getTile(){ + return Vars.world.tileWorld(input.mouseWorldX(), input.mouseWorldY()); + } + public static Drawable getDrawable(TextureAtlas.AtlasRegion region, int left, int right, int top, int bottom){ int[] splits = {left, right, top, bottom}; int[] pads = region.pads; diff --git a/src/UnitInfo/SVars.java b/src/UnitInfo/SVars.java index 9440bc8..f81862a 100644 --- a/src/UnitInfo/SVars.java +++ b/src/UnitInfo/SVars.java @@ -11,7 +11,6 @@ import static arc.Core.settings; public class SVars { public static HudUi hud = new HudUi(); - public static float modUiScale = settings.getInt("infoUiScale"); public static TextureRegion clear = atlas.find("clear"); public static TextureRegion error = atlas.find("error"); public static RangeShader turretRange; @@ -19,4 +18,5 @@ public class SVars { public static Teamc target; public static boolean locked; public static boolean jsonGen = false; + public static float uiResumeRate = 3 * 60f; //default 3s } diff --git a/src/UnitInfo/core/HudUi.java b/src/UnitInfo/core/HudUi.java index 51d94b0..8267b71 100644 --- a/src/UnitInfo/core/HudUi.java +++ b/src/UnitInfo/core/HudUi.java @@ -1,204 +1,40 @@ package UnitInfo.core; import UnitInfo.ui.windows.*; + import arc.*; import arc.graphics.*; -import arc.graphics.g2d.*; -import arc.input.*; import arc.math.*; -import arc.math.geom.*; -import arc.scene.style.*; import arc.scene.ui.*; import arc.scene.ui.layout.*; -import arc.struct.*; import arc.util.*; -import mindustry.*; -import mindustry.entities.Units; import mindustry.game.*; import mindustry.gen.*; -import mindustry.logic.Ranged; +import mindustry.graphics.Pal; import mindustry.ui.*; -import mindustry.world.*; -import mindustry.world.blocks.*; -import mindustry.world.blocks.defense.turrets.*; +import static UnitInfo.SUtils.*; import static UnitInfo.SVars.*; import static arc.Core.*; import static mindustry.Vars.*; public class HudUi { - public Table waveInfoTable = new Table(); public SchemDisplay schemTable; - - public Teamc shotTarget; - public Teamc lockedTarget; - public boolean locked = false; - public boolean waveShown; - public float a; - - @SuppressWarnings("unchecked") - public T getTarget(){ - if(locked && lockedTarget != null) { - if(settings.getBool("deadTarget") && !Groups.all.contains(e -> e == lockedTarget)) { - lockedTarget = null; - locked = false; - } - else return (T) lockedTarget; //if there is locked target, return it first. - } - - Seq units = Groups.unit.intersect(input.mouseWorldX(), input.mouseWorldY(), 4, 4); // well, 0.5tile is enough to search them - if(units.size > 0) - return (T) units.peek(); //if there is unit, return it. - else if(getTile() != null && getTile().build != null) - return (T) getTile().build; //if there isn't unit but there is build, return it. - else if(player.unit() instanceof BlockUnitUnit b && b.tile() != null) - return (T)b.tile(); - return (T) player.unit(); //if there aren't unit and not build, return player. - } - - public @Nullable Tile getTile(){ - return Vars.world.tileWorld(input.mouseWorldX(), input.mouseWorldY()); - } - float heat = 0; public void setEvents() { Events.run(EventType.Trigger.update, ()->{ target = getTarget(); - if(settings.getBool("deadTarget") && locked && lockedTarget != null && !Groups.all.contains(e -> e == lockedTarget)) { - lockedTarget = null; - locked = false; - } - heat+=Time.delta; - if(heat>60) { - heat=0; + heat += Time.delta; + if(heat > 60) { + heat = 0; schemTable.setSchemTable(); } - - if(Scl.scl(modUiScale) != settings.getInt("infoUiScale") / 100f){ - modUiScale = settings.getInt("infoUiScale") / 100f; - if(modUiScale <= 0) { - Log.warn("ui scaling reached zero"); - modUiScale = 0.25f; - } - } - - 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); - } }); } - public void setLeftUnitTable(Table table) { - table.table(t -> { - t.center(); - int[] i = {0}; - - content.units().each(type -> Groups.unit.contains(u -> u.type == type && (state.rules.pvp ? (u.team != player.team()) : (u.team == state.rules.waveTeam)) && u.isBoss()), type -> { - t.table(tt -> - tt.stack( - new Table(ttt -> ttt.image(type.uiIcon).size(iconSmall)), - new Table(ttt -> { - ttt.right().bottom(); - Label label = new Label(() -> Groups.unit.count(u -> u.type == type && (state.rules.pvp ? (u.team != player.team()) : (u.team == state.rules.waveTeam)) && u.isBoss()) + ""); - label.setFontScale(0.75f); - ttt.add(label); - ttt.pack(); - }), - new Table(ttt -> { - ttt.top().right(); - Image image = new Image(Icon.warning.getRegion()).setScaling(Scaling.fit); - image.update(() -> image.setColor(Tmp.c2.set(Color.orange).lerp(Color.scarlet, Mathf.absin(Time.time, 2f, 1f)))); - ttt.add(image).size(Scl.scl(modUiScale) * 12f); - ttt.pack(); - }) - ).pad(6) - ); - if(++i[0] % 6 == 0) t.row(); - }); - t.row(); - i[0] = 0; - content.units().each(type -> Groups.unit.contains(u -> u.type == type && (state.rules.pvp ? (u.team != player.team()) : (u.team == state.rules.waveTeam)) && !u.isBoss()), type -> { - t.table(tt -> - tt.add(new Stack() {{ - add(new Table(ttt -> ttt.add(new Image(type.uiIcon)).size(iconSmall))); - add(new Table(ttt -> { - ttt.right().bottom(); - Label label = new Label(() -> Groups.unit.count(u -> u.type == type &&(state.rules.pvp ? (u.team != player.team()) : (u.team == state.rules.waveTeam)) && !u.isBoss()) + ""); - label.setFontScale(0.75f); - ttt.add(label); - ttt.pack(); - })); - }}).pad(6) - ); - if(++i[0] % 6 == 0) t.row(); - }); - }); - } - - public void setTile(Table table){ - table.table(t -> - t.table(Tex.underline2, head -> { - head.table(image -> { - image.left(); - image.image(() -> getTile() == null ? clear : getTile().floor().uiIcon == error ? clear : getTile().floor().uiIcon).size(iconSmall); - image.image(() -> getTile() == null ? clear : getTile().overlay().uiIcon == error ? clear : getTile().overlay().uiIcon).size(iconSmall); - image.image(() -> getTile() == null ? clear : getTile().block().uiIcon == error ? clear : getTile().block().uiIcon).size(iconSmall); - }); - Label label = new Label(() -> getTile() == null ? "(null, null)" : "(" + getTile().x + ", " + getTile().y + ")"); - head.add(label).center(); - }) - ); - } - public void addSchemTable() { Table table = ((Table) scene.find("minimap/position")).row(); schemTable = new SchemDisplay(); @@ -206,14 +42,65 @@ public class HudUi { } public void addWaveInfoTable() { - waveInfoTable = new Table(Tex.buttonEdge4, t -> { - t.defaults().width(34 * 8f).center(); - t.table().update(tt -> { - tt.clear(); - setTile(tt); - tt.row(); - setLeftUnitTable(tt); + Table waveInfoTable = new Table(Tex.buttonEdge4, table -> { + table.center(); + table.table(head -> { + head.table(image -> { + image.left(); + image.image(() -> getTile() == null || getTile().floor().uiIcon == error ? clear : getTile().floor().uiIcon).size(iconSmall); + image.image(() -> getTile() == null || getTile().overlay().uiIcon == error ? clear : getTile().overlay().uiIcon).size(iconSmall); + image.image(() -> getTile() == null || getTile().block().uiIcon == error ? clear : getTile().block().uiIcon).size(iconSmall); + }); + head.label(() -> Strings.format("(@, @)", getTile() == null ? "NaN" : getTile().x, getTile() == null ? "NaN" : getTile().y)).center(); }); + table.row(); + table.image().height(4f).color(Pal.gray).growX().row(); + /* + table.table(tttt -> { + tttt.center(); + int[] i = {0}; + + content.units().each(type -> Groups.unit.contains(u -> u.type == type && (state.rules.pvp ? (u.team != player.team()) : (u.team == state.rules.waveTeam)) && u.isBoss()), type -> { + tttt.table(stt -> + stt.stack( + new Table(ttt -> ttt.image(type.uiIcon).size(iconSmall)), + new Table(ttt -> { + ttt.right().bottom(); + Label label = new Label(() -> Groups.unit.count(u -> u.type == type && (state.rules.pvp ? (u.team != player.team()) : (u.team == state.rules.waveTeam)) && u.isBoss()) + ""); + label.setFontScale(0.75f); + ttt.add(label); + ttt.pack(); + }), + new Table(ttt -> { + ttt.top().right(); + Image image = new Image(Icon.warning.getRegion()).setScaling(Scaling.fit); + image.update(() -> image.setColor(Tmp.c2.set(Color.orange).lerp(Color.scarlet, Mathf.absin(Time.time, 2f, 1f)))); + ttt.add(image).size(12f); + ttt.pack(); + }) + ).pad(6) + ); + if(++i[0] % 6 == 0) tttt.row(); + }); + tttt.row(); + i[0] = 0; + content.units().each(type -> Groups.unit.contains(u -> u.type == type && (state.rules.pvp ? (u.team != player.team()) : (u.team == state.rules.waveTeam)) && !u.isBoss()), type -> { + tttt.table(ttt -> + ttt.add(new Stack() {{ + add(new Table(ttt -> ttt.add(new Image(type.uiIcon)).size(iconSmall))); + add(new Table(ttt -> { + ttt.right().bottom(); + Label label = new Label(() -> Groups.unit.count(u -> u.type == type &&(state.rules.pvp ? (u.team != player.team()) : (u.team == state.rules.waveTeam)) && !u.isBoss()) + ""); + label.setFontScale(0.75f); + ttt.add(label); + ttt.pack(); + })); + }}).pad(6) + ); + if(++i[0] % 6 == 0) tttt.row(); + }); + }); + */ }); Table waveTable = (Table) scene.find("waves"); diff --git a/src/UnitInfo/core/Main.java b/src/UnitInfo/core/Main.java index 71316e7..579e8f2 100644 --- a/src/UnitInfo/core/Main.java +++ b/src/UnitInfo/core/Main.java @@ -5,18 +5,15 @@ import UnitInfo.ui.*; import UnitInfo.ui.draws.OverDraws; import UnitInfo.ui.windows.*; import arc.*; -import arc.scene.ui.Dialog; -import arc.struct.Seq; -import arc.util.Log; +import arc.struct.*; import mindustry.*; import mindustry.game.EventType.*; import mindustry.mod.*; import static UnitInfo.SVars.*; -import static UnitInfo.ui.windows.UnitDisplay.getTarget; import static arc.Core.*; -import static mindustry.Vars.mobile; -import static mindustry.Vars.ui; +import static mindustry.Vars.*; +import static UnitInfo.SUtils.*; public class Main extends Mod { @Override @@ -51,17 +48,15 @@ public class Main extends Mod { hud.addSchemTable(); hud.setEvents(); OverDrawer.setEvent(); - if(jsonGen) ContentJSON.save(); - scene.add(new ElementDisplay()); - Seq.with( + Seq.with(scene.root, ui.picker, ui.editor, ui.controls, ui.restart, ui.join, ui.discord, ui.load, ui.custom, ui.language, ui.database, ui.settings, ui.host, ui.paused, ui.about, ui.bans, ui.admins, ui.traces, ui.maps, ui.content, ui.planet, ui.research, ui.mods, ui.schematics, ui.logic - ).each(dialog-> dialog.add(new ElementDisplay(dialog))); - + ).each(dialog-> dialog.addChild(new ElementDisplay(dialog))); + if(jsonGen) ContentJSON.save(); }); Events.on(WorldLoadEvent.class, e -> { diff --git a/src/UnitInfo/core/OverDrawer.java b/src/UnitInfo/core/OverDrawer.java index 7e00baa..ba86625 100644 --- a/src/UnitInfo/core/OverDrawer.java +++ b/src/UnitInfo/core/OverDrawer.java @@ -1,32 +1,17 @@ package UnitInfo.core; -import UnitInfo.ui.*; import UnitInfo.ui.draws.OverDraw; import UnitInfo.ui.draws.OverDraws; import arc.*; import arc.graphics.*; import arc.graphics.g2d.*; -import arc.graphics.gl.*; import arc.math.*; import arc.math.geom.*; -import arc.scene.ui.layout.*; -import arc.struct.*; import arc.util.*; -import mindustry.*; -import mindustry.ai.*; -import mindustry.ai.types.*; -import mindustry.entities.units.*; import mindustry.game.*; import mindustry.gen.*; import mindustry.graphics.*; -import mindustry.logic.*; import mindustry.ui.*; -import mindustry.world.*; -import mindustry.world.blocks.defense.turrets.*; -import mindustry.world.blocks.storage.*; -import mindustry.world.blocks.units.*; - -import java.util.Objects; import static UnitInfo.SVars.*; import static arc.Core.*; @@ -36,11 +21,9 @@ public class OverDrawer { public static void setEvent(){ Events.run(EventType.Trigger.draw, () -> { - float sin = Mathf.absin(Time.time, 6f, 1f); Draw.z(Layer.max); - //local drawing, drawn on player/camera position if(settings.getBool("spawnerarrow")) { float leng = (player.unit() != null && player.unit().hitSize > 4 * 8f ? player.unit().hitSize * 1.5f : 4 * 8f) + sin; Tmp.v1.set(camera.position); diff --git a/src/UnitInfo/core/SettingS.java b/src/UnitInfo/core/SettingS.java index 40ace74..2e17597 100644 --- a/src/UnitInfo/core/SettingS.java +++ b/src/UnitInfo/core/SettingS.java @@ -103,65 +103,32 @@ public class SettingS { settingUi.button(bundle.get("setting.shar-title"), Styles.cleart, dialog::show); }); - Seq> settingSeq = new Seq<>(); Seq tapSeq = new Seq<>(); addGraphicSlideSetting("barstyle", 0, 0, 5, 1, s -> s == 0 ? bundle.get("default-bar") : s + bundle.get("th-bar"), tapSeq); - addGraphicSlideSetting("infoUiScale", mobile ? 25 : 50, 25, 100, 5, s -> s + "%", tapSeq); - addGraphicSlideSetting("coreItemCheckRate", 60, 6, 180, 6, s -> Strings.fixed(s/60f,1) + bundle.get("sec"), tapSeq); addGraphicTypeSetting("wavemax", 0, 200,100, true, () -> true, s -> s + "waves", tapSeq); - addGraphicCheckSetting("infoui", true, tapSeq); addGraphicCheckSetting("pastwave", false, tapSeq); addGraphicCheckSetting("emptywave", true, tapSeq); - addGraphicCheckSetting("itemcal", false, tapSeq); addGraphicCheckSetting("schem", !mobile, tapSeq); //TODO: remove all drawing settings - Seq rangeSeq = new Seq<>(); - //addGraphicTypeSetting("rangeRadius", 0, 500, 70, true, () -> true, s -> s + "tiles", rangeSeq); - //addGraphicCheckSetting("rangeNearby", true, rangeSeq); - //addGraphicCheckSetting("allTargetRange", false, rangeSeq); - addGraphicCheckSetting("aliceRange", false, rangeSeq); - addGraphicCheckSetting("RangeShader", false, rangeSeq); - - Seq opacitySeq = new Seq<>(); - addGraphicSlideSetting("selectopacity", 50, 0, 100, 5, s -> s + "%", opacitySeq); - addGraphicSlideSetting("baropacity", 50, 0, 100, 5, s -> s + "%", opacitySeq); - addGraphicSlideSetting("uiopacity", 50, 0, 100, 5, s -> s + "%", opacitySeq); - addGraphicSlideSetting("softRangeOpacity", 60, 0, 100, 10, s -> s + "%", opacitySeq); - Seq drawSeq = new Seq<>(); - /* - addGraphicTypeSetting("pathlinelimit", 0, 5000, 50, true, () -> true, s -> s + "lines", drawSeq); - addGraphicTypeSetting("unitlinelimit", 0, 5000, 50, true, () -> true, s -> s + "lines", drawSeq); - addGraphicTypeSetting("logiclinelimit", 0, 5000, 50, true, () -> true, s -> s + "lines", drawSeq); - addGraphicTypeSetting("spawnarrowlimit", 0, 5000, 50, true, () -> true, s -> s + "arrows", drawSeq); - addGraphicCheckSetting("gaycursor", false, drawSeq); - addGraphicCheckSetting("unithealthui", true, drawSeq); - addGraphicCheckSetting("blockfont", false, drawSeq); - addGraphicCheckSetting("linkedMass", true, drawSeq); - addGraphicCheckSetting("linkedNode", false, drawSeq); - addGraphicCheckSetting("deadTarget", false, drawSeq); - */ + addGraphicSlideSetting("selectopacity", 50, 0, 100, 5, s -> s + "%", drawSeq); + addGraphicSlideSetting("baropacity", 50, 0, 100, 5, s -> s + "%", drawSeq); + addGraphicCheckSetting("aliceRange", false, drawSeq); + addGraphicCheckSetting("RangeShader", false, drawSeq); addGraphicCheckSetting("select", false, drawSeq); addGraphicCheckSetting("distanceLine", false, drawSeq); addGraphicCheckSetting("spawnerarrow", false, drawSeq); addGraphicCheckSetting("elementdebug", false, drawSeq); addGraphicCheckSetting("hiddenElem", false, drawSeq); - Seq etcSeq = new Seq<>(); - addGraphicCheckSetting("autoShooting", false, etcSeq); - - settingSeq.add(tapSeq, rangeSeq, opacitySeq); - settingSeq.add(drawSeq, etcSeq); + settingSeq.add(tapSeq, drawSeq); sharset.table(t -> { Seq buttons = new Seq<>(); buttons.add(new TextButton(bundle.get("setting.shar-ui"), Styles.clearToggleMenut)); - buttons.add(new TextButton(bundle.get("setting.shar-range"), Styles.clearToggleMenut)); - buttons.add(new TextButton(bundle.get("setting.shar-opacity"), Styles.clearToggleMenut)); buttons.add(new TextButton(bundle.get("setting.shar-draw"), Styles.clearToggleMenut)); - buttons.add(new TextButton(bundle.get("setting.shar-etc"), Styles.clearToggleMenut)); buttons.each(b -> b.clicked(() -> buttons.each(b1 -> b1.setChecked(b1 == b)))); t.table(Styles.black8, bt -> { bt.top().align(Align.top); diff --git a/src/UnitInfo/ui/SBar.java b/src/UnitInfo/ui/SBar.java index 189f6f4..707149a 100644 --- a/src/UnitInfo/ui/SBar.java +++ b/src/UnitInfo/ui/SBar.java @@ -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(); diff --git a/src/UnitInfo/ui/draws/BlockDraw.java b/src/UnitInfo/ui/draws/BlockDraw.java index 116a267..0ba5f38 100644 --- a/src/UnitInfo/ui/draws/BlockDraw.java +++ b/src/UnitInfo/ui/draws/BlockDraw.java @@ -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 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); - } - } - } } diff --git a/src/UnitInfo/ui/draws/LinkDraw.java b/src/UnitInfo/ui/draws/LinkDraw.java index 87875cf..f3318e7 100644 --- a/src/UnitInfo/ui/draws/LinkDraw.java +++ b/src/UnitInfo/ui/draws/LinkDraw.java @@ -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 linkedMasses = new Seq<>(); Seq linkedPayloadMasses = new Seq<>(); Seq 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 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); diff --git a/src/UnitInfo/ui/draws/OverDraw.java b/src/UnitInfo/ui/draws/OverDraw.java index 31b7cc7..d5dbba0 100644 --- a/src/UnitInfo/ui/draws/OverDraw.java +++ b/src/UnitInfo/ui/draws/OverDraw.java @@ -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 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 void onEnabled(T param) {} + + public 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); + } } diff --git a/src/UnitInfo/ui/draws/OverDraws.java b/src/UnitInfo/ui/draws/OverDraws.java index 53151c9..f030304 100644 --- a/src/UnitInfo/ui/draws/OverDraws.java +++ b/src/UnitInfo/ui/draws/OverDraws.java @@ -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}; } } diff --git a/src/UnitInfo/ui/draws/RangeDraw.java b/src/UnitInfo/ui/draws/RangeDraw.java index 249b9ec..70030dd 100644 --- a/src/UnitInfo/ui/draws/RangeDraw.java +++ b/src/UnitInfo/ui/draws/RangeDraw.java @@ -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> tmpbuildobj = new ObjectMap<>(); - boolean ground = false, air = false; + ObjectMap> 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 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); - } - } - } } diff --git a/src/UnitInfo/ui/draws/UnitDraw.java b/src/UnitInfo/ui/draws/UnitDraw.java index d3282aa..f99f43c 100644 --- a/src/UnitInfo/ui/draws/UnitDraw.java +++ b/src/UnitInfo/ui/draws/UnitDraw.java @@ -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 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 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); - } - } - } } diff --git a/src/UnitInfo/ui/draws/UtilDraw.java b/src/UnitInfo/ui/draws/UtilDraw.java new file mode 100644 index 0000000..94e7552 --- /dev/null +++ b/src/UnitInfo/ui/draws/UtilDraw.java @@ -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); + } + } +} diff --git a/src/UnitInfo/ui/windows/PlayerDisplay.java b/src/UnitInfo/ui/windows/PlayerDisplay.java index eeae6c8..bab1c34 100644 --- a/src/UnitInfo/ui/windows/PlayerDisplay.java +++ b/src/UnitInfo/ui/windows/PlayerDisplay.java @@ -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 players = Groups.player.copy(new Seq<>()); diff --git a/src/UnitInfo/ui/windows/UnitDisplay.java b/src/UnitInfo/ui/windows/UnitDisplay.java index 42b0012..d551570 100644 --- a/src/UnitInfo/ui/windows/UnitDisplay.java +++ b/src/UnitInfo/ui/windows/UnitDisplay.java @@ -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),