From 11fc54622be897599a98a98bbcd27814cf1c8789 Mon Sep 17 00:00:00 2001 From: Sharlotte Date: Sun, 25 Jul 2021 22:39:40 +0900 Subject: [PATCH] added forceProjector bar, clean up --- src/UnitInfo/core/BarInfo.java | 23 +++++------- src/UnitInfo/core/HudUi.java | 67 ++++++++++++++++++---------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/UnitInfo/core/BarInfo.java b/src/UnitInfo/core/BarInfo.java index 8e24146..93cfd6e 100644 --- a/src/UnitInfo/core/BarInfo.java +++ b/src/UnitInfo/core/BarInfo.java @@ -17,6 +17,7 @@ import mindustry.gen.*; import mindustry.graphics.Pal; import mindustry.ui.Fonts; import mindustry.world.blocks.ConstructBlock; +import mindustry.world.blocks.defense.ForceProjector; import mindustry.world.blocks.defense.turrets.*; import mindustry.world.blocks.storage.*; import mindustry.world.blocks.units.Reconstructor; @@ -33,19 +34,6 @@ public class BarInfo { static Seq numbers = new Seq<>(new Float[]{0f,0f,0f,0f,0f,0f}); static Seq colors = new Seq<>(new Color[]{Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear}); - public static Seq returnStrings(T target){ - getInfo(target); - return strings; - } - public static Seq returnColors(T target){ - getInfo(target); - return colors; - } - public static Seq returnNumbers(T target){ - getInfo(target); - return numbers; - } - public static String format(float number){ if(number >= 10000) return UI.formatAmount((long)number); if(String.valueOf(number).split("[.]")[1].matches("0")) return String.valueOf(number).split("[.]")[0]; @@ -98,6 +86,15 @@ public class BarInfo { colors.set(1, Pal.darkerMetal); numbers.set(1, reconstruct.fraction()); } + else if(target instanceof ForceProjector.ForceBuild){ + ForceProjector.ForceBuild force = (ForceProjector.ForceBuild) target; + ForceProjector forceBlock = (ForceProjector) force.block; + float max = forceBlock.shieldHealth + forceBlock.phaseShieldBoost * force.phaseHeat; + strings.set(1, Core.bundle.format("shar-stat.shield", format(max-force.buildup), max)); + colors.set(1, Pal.shield); + numbers.set(1, (max-force.buildup)/max); + + } if(target instanceof ItemTurret.ItemTurretBuild) { ItemTurret.ItemTurretBuild turretBuild = (ItemTurret.ItemTurretBuild) target; diff --git a/src/UnitInfo/core/HudUi.java b/src/UnitInfo/core/HudUi.java index 41f8e7e..2f15a8c 100644 --- a/src/UnitInfo/core/HudUi.java +++ b/src/UnitInfo/core/HudUi.java @@ -62,22 +62,29 @@ public class HudUi { int waveamount; int coreamount; - Seq strings = new Seq<>(new String[]{"","","","","",""}); - Seq numbers = new Seq<>(new Float[]{0f,0f,0f,0f,0f,0f}); - Seq colors = new Seq<>(new Color[]{Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear}); Seq lastColors = new Seq<>(new Color[]{Color.clear,Color.clear,Color.clear,Color.clear,Color.clear,Color.clear}); CoresItemsDisplay coreItems = new CoresItemsDisplay(Team.baseTeams); - @Nullable Teamc target; @SuppressWarnings("unchecked") public T getTarget(){ - if(locked && lockedTarget != null) return (T) lockedTarget; //if there is locked target, return it first. - Seq units = Groups.unit.intersect(Core.input.mouseWorldX(), Core.input.mouseWorldY(), 4, 4); - 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 && ((BlockUnitUnit)player.unit()).tile() != null) return (T)((BlockUnitUnit)player.unit()).tile(); + if(locked && + (lockedTarget instanceof Unit && ((Unit) lockedTarget).dead) || + (lockedTarget instanceof Building && ((Building) lockedTarget).dead)) { + lockedTarget = null; + locked = false; + } + if(locked && lockedTarget != null) + return (T) lockedTarget; //if there is locked target, return it first. + + Seq units = Groups.unit.intersect(Core.input.mouseWorldX(), Core.input.mouseWorldY(), 4, 4); // well, 0.5tile is enough to search them........ maybe? + 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 && ((BlockUnitUnit)player.unit()).tile() != null) + return (T)((BlockUnitUnit)player.unit()).tile(); return (T) player.unit(); //if there are not unit and not build, return player. } @@ -225,27 +232,27 @@ public class HudUi { public void addBars(){ bars.clear(); - lastColors.set(2, colors.get(2)); + { int i = 0; bars.add(new SBar( - () -> strings.get(i), + () -> BarInfo.strings.get(i), () -> { - if (colors.get(i) != Color.clear) lastColors.set(i, colors.get(i)); + if (BarInfo.colors.get(i) != Color.clear) lastColors.set(i, BarInfo.colors.get(i)); return lastColors.get(i); }, - () -> numbers.get(i) + () -> BarInfo.numbers.get(i) )); } { int i = 1; bars.add(new SBar( - () -> strings.get(i), + () -> BarInfo.strings.get(i), () -> { - if (colors.get(i) != Color.clear) lastColors.set(i, colors.get(i)); + if (BarInfo.colors.get(i) != Color.clear) lastColors.set(i, BarInfo.colors.get(i)); return lastColors.get(i); }, - () -> numbers.get(i) + () -> BarInfo.numbers.get(i) )); } bars.add(new Stack(){{ @@ -253,12 +260,12 @@ public class HudUi { t.top().defaults().width(Scl.scl(23 * 8f)).height(Scl.scl(4f * 8f)); int i = 2; t.add(new SBar( - () -> strings.get(i), + () -> BarInfo.strings.get(i), () -> { - if(colors.get(i) != Color.clear) lastColors.set(i, colors.get(i)); + if(BarInfo.colors.get(i) != Color.clear) lastColors.set(i, BarInfo.colors.get(i)); return lastColors.get(i); }, - () -> numbers.get(i) + () -> BarInfo.numbers.get(i) )).growX().left(); })); add(new Table(){{ @@ -333,12 +340,12 @@ public class HudUi { { int i = 3; bars.add(new SBar( - () -> strings.get(i), + () -> BarInfo.strings.get(i), () -> { - if (colors.get(i) != Color.clear) lastColors.set(i, colors.get(i)); + if (BarInfo.colors.get(i) != Color.clear) lastColors.set(i, BarInfo.colors.get(i)); return lastColors.get(i); }, - () -> numbers.get(i) + () -> BarInfo.numbers.get(i) )); } @@ -346,12 +353,12 @@ public class HudUi { { int i = 4; bars.add(new SBar( - () -> strings.get(i), + () -> BarInfo.strings.get(i), () -> { - if (colors.get(i) != Color.clear) lastColors.set(i, colors.get(i)); + if (BarInfo.colors.get(i) != Color.clear) lastColors.set(i, BarInfo.colors.get(i)); return lastColors.get(i); }, - () -> numbers.get(i) + () -> BarInfo.numbers.get(i) )); } @@ -361,12 +368,12 @@ public class HudUi { int i = 5; t.add(new SBar( - () -> strings.get(i), + () -> BarInfo.strings.get(i), () -> { - if (colors.get(i) != Color.clear) lastColors.set(i, colors.get(i)); + if (BarInfo.colors.get(i) != Color.clear) lastColors.set(i, BarInfo.colors.get(i)); return lastColors.get(i); }, - () -> numbers.get(i) + () -> BarInfo.numbers.get(i) )).growX().left(); })); add(new Table(t -> { @@ -569,9 +576,7 @@ public class HudUi { }).padRight(Scl.scl(24 * 8f)); table.row(); table.update(() -> { - strings = BarInfo.returnStrings(getTarget()); - numbers = BarInfo.returnNumbers(getTarget()); - colors = BarInfo.returnColors(getTarget()); + BarInfo.getInfo(target); if(getTarget() instanceof Turret.TurretBuild){ if(((Turret.TurretBuild) getTarget()).charging) charge += Time.delta; else charge = 0f;