diff --git a/src/UnitInfo/SUtils.java b/src/UnitInfo/SUtils.java index bc40e79..fc9fccb 100644 --- a/src/UnitInfo/SUtils.java +++ b/src/UnitInfo/SUtils.java @@ -22,4 +22,11 @@ public class SUtils { if(String.valueOf(number).split("[.]")[1].matches("0")) return String.valueOf(number).split("[.]")[0]; return Strings.fixed(number, 1); } + + + public static Object invoke(Object ut, String fieldName) throws IllegalAccessException, NoSuchFieldException { + Field field = ut.getClass().getDeclaredField(fieldName); + field.setAccessible(true); + return field.get(ut); + } } diff --git a/src/UnitInfo/SVars.java b/src/UnitInfo/SVars.java index feb546a..62f359e 100644 --- a/src/UnitInfo/SVars.java +++ b/src/UnitInfo/SVars.java @@ -20,7 +20,6 @@ public class SVars { public static TextureRegion clear = atlas.find("clear"); public static TextureRegion error = atlas.find("error"); public static float modUiScale = settings.getInt("infoUiScale") / 100f == 0 ? 1 : settings.getInt("infoUiScale") / 100f; - public static float scaledScale = Scl.scl(Math.min(modUiScale, 1)); public static Seq pathTiles = new Seq<>(); } diff --git a/src/UnitInfo/core/HudUi.java b/src/UnitInfo/core/HudUi.java index d9931cc..a6dc903 100644 --- a/src/UnitInfo/core/HudUi.java +++ b/src/UnitInfo/core/HudUi.java @@ -269,7 +269,7 @@ public class HudUi { }); Events.run(EventType.Trigger.update, ()->{ - if(modUiScale != settings.getInt("infoUiScale") / 100f){ + if(Scl.scl(modUiScale) != settings.getInt("infoUiScale") / 100f){ modUiScale = settings.getInt("infoUiScale") / 100f; mainTable.clearChildren(); addTable(); @@ -368,7 +368,7 @@ public class HudUi { 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(modUiScale * 12f); + ttt.add(image).size(Scl.scl(modUiScale) * 12f); ttt.pack(); })); }}).pad(6); @@ -376,6 +376,7 @@ public class HudUi { }); }); t.row(); + i[0] = 0; content.units().each(type -> Groups.unit.contains(u -> u.type == type && u.team == state.rules.waveTeam && !u.isBoss()), type -> { t.table(tt -> { tt.add(new Stack() {{ @@ -677,10 +678,10 @@ public class HudUi { }) , new Table(h -> { h.defaults().growX().height(Scl.scl(modUiScale) * 9f).width(Scl.scl(modUiScale) * iconLarge).padTop(Scl.scl(modUiScale) * 18f); - h.add(new Bar( + h.add(new SBar( () -> "", () -> Pal.accent.cpy().lerp(Color.orange, mount.reload / weapon.reload), - () -> mount.reload / weapon.reload)); + () -> mount.reload / weapon.reload).rect().init()); h.pack(); }) ); @@ -748,7 +749,7 @@ public class HudUi { public void addUnitTable(){ if(uiIndex != 0) return; unitTable = new Table(table -> { - table.left().defaults().width(modUiScale * 27 * 8f).maxHeight(modUiScale * 35 * 8f); + table.left().defaults().width(Scl.scl(modUiScale) * 27 * 8f).maxHeight(Scl.scl(modUiScale) * 35 * 8f); addBars(); Table table1 = new Table(Tex.button, t -> { t.left(); @@ -804,9 +805,8 @@ public class HudUi { } }); button.visibility = () -> getTarget() != null; - button.update(()->{ - lockButton.getStyle().imageUp = Icon.lock.tint(locked ? Pal.accent : Color.white); - }); + button.update(()->lockButton.getStyle().imageUp = Icon.lock.tint(locked ? Pal.accent : Color.white)); + button.getLabel().setFontScale(Scl.scl(modUiScale)); lockButton = Elem.newImageButton(Styles.clearPartiali, Icon.lock.tint(locked ? Pal.accent : Color.white), 3 * 8f * Scl.scl(modUiScale), () -> { locked = !locked; @@ -935,14 +935,14 @@ public class HudUi { tt.stack( new Table(ttt -> { ttt.center(); - ttt.add(image).size(iconMed * modUiScale); + ttt.add(image).size(iconMed * Scl.scl(modUiScale)); ttt.pack(); }), new Table(ttt -> { ttt.bottom().left(); Label label = new Label(() -> amount + ""); - label.setFontScale(modUiScale * 0.85f); + label.setFontScale(Scl.scl(modUiScale) * 0.85f); ttt.add(label); ttt.pack(); }), @@ -951,7 +951,7 @@ public class HudUi { ttt.top().right(); Image image1 = new Image(Icon.warning.getRegion()).setScaling(Scaling.fit); image1.update(() -> image1.setColor(Tmp.c2.set(Color.orange).lerp(Color.scarlet, Mathf.absin(Time.time, 2f, 1f)))); - ttt.add(image1).size(modUiScale * 12f); + ttt.add(image1).size(Scl.scl(modUiScale) * 12f); ttt.visible(() -> group.effect == StatusEffects.boss); ttt.pack(); }) @@ -1043,14 +1043,14 @@ public class HudUi { wavePane.setWidget(new Table(tx -> tx.table(this::setWave).left())); waveTable = new Table(table -> { - table.left().defaults().width(modUiScale * 32 * 8f).maxHeight(modUiScale * 32 * 8f).align(Align.left); + table.left().defaults().width(Scl.scl(modUiScale) * 35 * 8f).maxHeight(Scl.scl(modUiScale) * 32 * 8f).align(Align.left); table.add(new Table(Tex.button, t -> { t.add(wavePane); t.update(() -> { NinePatchDrawable patch = (NinePatchDrawable)Tex.button; t.setBackground(patch.tint(Tmp.c1.set(patch.getPatch().getColor()).a(settings.getInt("uiopacity") / 100f))); }); - })).padRight(modUiScale * 39 * 8f); + })).padRight(Scl.scl(modUiScale) * 39 * 8f); table.fillParent = true; table.visibility = () -> uiIndex == 1; @@ -1093,14 +1093,14 @@ public class HudUi { }); itemTable = new Table(table -> { - table.left().defaults().width(modUiScale * 54 * 8f).height(modUiScale * 32 * 8f).align(Align.left); + table.left().defaults().width(Scl.scl(modUiScale) * 54 * 8f).height(Scl.scl(modUiScale) * 32 * 8f).align(Align.left); table.table(Tex.button, t -> { t.add(itemPane); t.update(() -> { NinePatchDrawable patch = (NinePatchDrawable)Tex.button; t.setBackground(patch.tint(Tmp.c1.set(patch.getPatch().getColor()).a(settings.getInt("uiopacity") / 100f))); }); - }).padRight(modUiScale * 39 * 8f); + }).padRight(Scl.scl(modUiScale) * 39 * 8f); table.fillParent = true; table.visibility = () -> uiIndex == 2; diff --git a/src/UnitInfo/core/Main.java b/src/UnitInfo/core/Main.java index 76ac47c..e8a4bf9 100644 --- a/src/UnitInfo/core/Main.java +++ b/src/UnitInfo/core/Main.java @@ -10,10 +10,11 @@ import arc.scene.ui.layout.*; import arc.util.*; import mindustry.*; import mindustry.ai.Pathfinder; -import mindustry.ai.types.BuilderAI; -import mindustry.ai.types.MinerAI; +import mindustry.ai.types.*; import mindustry.content.*; import mindustry.entities.units.AIController; +import mindustry.entities.units.UnitCommand; +import mindustry.entities.units.UnitController; import mindustry.game.EventType.*; import mindustry.game.*; import mindustry.gen.*; @@ -33,17 +34,14 @@ public class Main extends Mod { int otherCores; boolean groundValid = false, legValid = false, navalValid = false; - public Tile getNextTile(Tile tile, int finder){ - Team team = state.rules.waveTeam; - Pathfinder.Flowfield field = pathfinder.getField(team, finder, Pathfinder.fieldCore); + public Tile getNextTile(Tile tile, int cost, Team team, int finder) { + Pathfinder.Flowfield field = pathfinder.getField(team, cost, finder); Tile tile1 = pathfinder.getTargetTile(tile, field); pathTiles.add(tile1); if(otherCores != Groups.build.count(b -> b instanceof CoreBlock.CoreBuild && b.team != team) - || tile1 == tile || tile1 == null || - tile1.build instanceof CoreBlock.CoreBuild || - !Groups.build.contains(b -> b instanceof CoreBlock.CoreBuild && b.team != team)) //so many ififififififif. + || tile1 == tile || tile1 == null || tile1.build instanceof CoreBlock.CoreBuild) //so many ififififififif. return tile1; - return getNextTile(tile1, finder); + return getNextTile(tile1, cost, team, finder); } @Override @@ -86,27 +84,57 @@ public class Main extends Mod { if(input.keyTap(KeyCode.num3)) navalValid = !navalValid; } - if(settings.getBool("spathfinder") || (input.keyDown(KeyCode.shiftRight) || input.keyDown(KeyCode.shiftLeft)) && input.keyTap(KeyCode.q)) { + if(settings.getBool("spathfinder")) { + Groups.unit.each(u -> { + Team enemyTeam = u.team; + otherCores = Groups.build.count(b -> b instanceof CoreBlock.CoreBuild && b.team != enemyTeam); + if(otherCores == 0) return; //must have target core + + UnitController c = u.controller(); + UnitCommand com = enemyTeam.data().command; + if(u.type.flying || //not flying + c instanceof MinerAI || //not mono + c instanceof BuilderAI || //not poly + c instanceof RepairAI || //not mega + c instanceof DefenderAI || //not oct + c instanceof FormationAI || //not commanded unit by player + c instanceof LogicAI || //not controlled unit by logic + c instanceof FlyingAI || + com == UnitCommand.idle) return; + + getNextTile(u.tileOn(), u.pathType(), enemyTeam, com == UnitCommand.attack ? Pathfinder.fieldCore : Pathfinder.fieldRally); + pathTiles.filter(Objects::nonNull); + for(int i = 1; i < pathTiles.size; i++) { + if(i + 1 >= pathTiles.size) continue; //prevent IndexOutException + Tile tile1 = pathTiles.get(i); + Tile tile2 = pathTiles.get(i + 1); + Draw.z(Layer.overlayUI); + Lines.stroke(1, enemyTeam.color); + Lines.line(tile1.worldx(), tile1.worldy(), tile2.worldx(), tile2.worldy()); + } + pathTiles.clear(); + }); + spawner.getSpawns().each(t -> { Team enemyTeam = state.rules.waveTeam; - for (int p = 0; p < 3; p++) { - if(p == 0 && !groundValid && !mobile) continue; - if(p == 1 && !legValid && !mobile) continue; - if(p == 2 && !navalValid && !mobile) continue; - + for(int p = 0; p < 3; p++) { otherCores = Groups.build.count(b -> b instanceof CoreBlock.CoreBuild && b.team != enemyTeam); - getNextTile(t, p); + if(otherCores == 0) return; //must have target core + + getNextTile(t, p, enemyTeam, Pathfinder.fieldCore); pathTiles.filter(Objects::nonNull); - for (int i = 1; i < pathTiles.size; i++) { - if (i + 1 >= pathTiles.size) continue; //prevent IndexOutException + for(int i = 1; i < pathTiles.size; i++) { + if(i + 1 >= pathTiles.size) continue; //prevent IndexOutException Tile tile1 = pathTiles.get(i); Tile tile2 = pathTiles.get(i + 1); + Draw.z(Layer.overlayUI); Lines.stroke(1, enemyTeam.color); Lines.line(tile1.worldx(), tile1.worldy(), tile2.worldx(), tile2.worldy()); } pathTiles.clear(); } }); + Draw.reset(); } if(settings.getBool("blockstatus")) Groups.build.each(build -> { @@ -126,6 +154,7 @@ public class Main extends Mod { Draw.color(); } }); + if(Core.settings.getBool("unithealthui")) Groups.unit.each(unit -> new FreeBar().draw(unit)); diff --git a/src/UnitInfo/ui/CoresItemsDisplay.java b/src/UnitInfo/ui/CoresItemsDisplay.java index 65b1c33..e67c1e0 100644 --- a/src/UnitInfo/ui/CoresItemsDisplay.java +++ b/src/UnitInfo/ui/CoresItemsDisplay.java @@ -113,7 +113,7 @@ public class CoresItemsDisplay { } image.addListener(new Tooltip(tttt -> { Label label = new Label(() -> "([#" + Tmp.c1.set(Color.green).lerp(Color.red, 1 - core.healthf()).toString() + "]" + Strings.fixed(core.health, 2) + "[]/" + Strings.fixed(core.block.health, 2) + ")"); - if (modUiScale < 1) label.setFontScale(Scl.scl(modUiScale)); + label.setFontScale(Scl.scl(modUiScale)); tttt.background(Tex.button).add(label); })); s.add(image).size(iconLarge * modUiScale); @@ -126,9 +126,9 @@ public class CoresItemsDisplay { ); tt.row(); Label label = new Label(() -> "(" + (int) core.x / 8 + ", " + (int) core.y / 8 + ")"); - label.setFontScale(modUiScale * 0.75f); + label.setFontScale(Scl.scl(modUiScale) * 0.75f); tt.add(label); - }).padTop(modUiScale * 2).padLeft(modUiScale * 4).padRight(modUiScale * 4); + }).padTop(Scl.scl(modUiScale) * 2).padLeft(Scl.scl(modUiScale) * 4).padRight(Scl.scl(modUiScale) * 4); if(++i[0] % 5 == 0) coretable.row(); } });