diff --git a/core/src/mindustry/ui/fragments/PlacementFragment.java b/core/src/mindustry/ui/fragments/PlacementFragment.java index 7df456cb0c..dcfcba3a67 100644 --- a/core/src/mindustry/ui/fragments/PlacementFragment.java +++ b/core/src/mindustry/ui/fragments/PlacementFragment.java @@ -9,6 +9,7 @@ import arc.scene.event.*; import arc.scene.style.*; import arc.scene.ui.*; import arc.scene.ui.Tooltip.*; +import arc.scene.ui.layout.Stack; import arc.scene.ui.layout.*; import arc.struct.*; import arc.util.*; @@ -29,6 +30,8 @@ import mindustry.world.*; import mindustry.world.blocks.ConstructBlock.*; import mindustry.world.meta.*; +import java.util.*; + import static mindustry.Vars.*; public class PlacementFragment{ @@ -474,9 +477,9 @@ public class PlacementFragment{ Bits availableCommands = new Bits(content.unitCommands().size); Bits availableStances = new Bits(content.unitStances().size); + Bits activeTypes = new Bits(content.units().size), prevActiveTypes = new Bits(content.units().size); u.left(); - int[] curCount = {0}; Bits usedCommands = new Bits(content.unitCommands().size); var commands = new Seq(); @@ -484,6 +487,8 @@ public class PlacementFragment{ var stances = new Seq(); var stancesOut = new Seq(); + int[] counts = new int[content.units().size]; + rebuildCommand = () -> { u.clearChildren(); var units = control.input.selectedUnits; @@ -493,7 +498,7 @@ public class PlacementFragment{ commands.clear(); stances.clear(); - int[] counts = new int[content.units().size]; + Arrays.fill(counts, 0); for(var unit : units){ counts[unit.type.id] ++; @@ -514,12 +519,18 @@ public class PlacementFragment{ int col = 0; for(int i = 0; i < counts.length; i++){ + int fi = i; if(counts[i] > 0){ var type = content.unit(i); unitlist.add(StatValues.stack(type, counts[i])).pad(4).with(b -> { b.clearListeners(); b.addListener(Tooltips.getInstance().create(type.localizedName, false)); + Label amountLabel = b.find("stack amount"); + if(amountLabel != null){ + amountLabel.setText(() -> counts[fi] + ""); + } + var listener = new ClickListener(); //left click -> select @@ -602,6 +613,9 @@ public class PlacementFragment{ activeStances.clear(); availableCommands.clear(); availableStances.clear(); + activeTypes.clear(); + + Arrays.fill(counts, 0); //find the command that all units have, or null if they do not share one for(var unit : control.input.selectedUnits){ @@ -610,6 +624,10 @@ public class PlacementFragment{ activeStances.set(cmd.stances); } + counts[unit.type.id] ++; + + activeTypes.set(unit.type.id); + stancesOut.clear(); unit.type.getUnitStances(unit, stancesOut); @@ -622,12 +640,9 @@ public class PlacementFragment{ } } - int size = control.input.selectedUnits.size; - if(curCount[0] != size || !usedCommands.equals(availableCommands) || !usedStances.equals(availableStances)){ - if(!(curCount[0] + size == 0)){ - rebuildCommand.run(); - } - curCount[0] = size; + if(!usedCommands.equals(availableCommands) || !usedStances.equals(availableStances) || !prevActiveTypes.equals(activeTypes)){ + rebuildCommand.run(); + prevActiveTypes.set(activeTypes); } //not a huge fan of running input logic here, but it's convenient as the stance arrays are all here... diff --git a/core/src/mindustry/world/meta/StatValues.java b/core/src/mindustry/world/meta/StatValues.java index 8556ef3adc..2dcc47bb38 100644 --- a/core/src/mindustry/world/meta/StatValues.java +++ b/core/src/mindustry/world/meta/StatValues.java @@ -236,7 +236,7 @@ public class StatValues{ if(amount != 0){ stack.add(new Table(t -> { t.left().bottom(); - t.add(amount >= 1000 ? UI.formatAmount(amount) : amount + "").style(Styles.outlineLabel); + t.add(amount >= 1000 ? UI.formatAmount(amount) : amount + "").name("stack amount").style(Styles.outlineLabel); t.pack(); })); }