This commit is contained in:
Anuken
2026-02-09 20:25:02 -05:00
parent de3c2430c0
commit 51a2588c4e
2 changed files with 24 additions and 9 deletions

View File

@@ -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<UnitCommand>();
@@ -484,6 +487,8 @@ public class PlacementFragment{
var stances = new Seq<UnitStance>();
var stancesOut = new Seq<UnitStance>();
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)){
if(!usedCommands.equals(availableCommands) || !usedStances.equals(availableStances) || !prevActiveTypes.equals(activeTypes)){
rebuildCommand.run();
}
curCount[0] = size;
prevActiveTypes.set(activeTypes);
}
//not a huge fan of running input logic here, but it's convenient as the stance arrays are all here...

View File

@@ -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();
}));
}