Fixed #11646
This commit is contained in:
@@ -9,6 +9,7 @@ import arc.scene.event.*;
|
|||||||
import arc.scene.style.*;
|
import arc.scene.style.*;
|
||||||
import arc.scene.ui.*;
|
import arc.scene.ui.*;
|
||||||
import arc.scene.ui.Tooltip.*;
|
import arc.scene.ui.Tooltip.*;
|
||||||
|
import arc.scene.ui.layout.Stack;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
@@ -29,6 +30,8 @@ import mindustry.world.*;
|
|||||||
import mindustry.world.blocks.ConstructBlock.*;
|
import mindustry.world.blocks.ConstructBlock.*;
|
||||||
import mindustry.world.meta.*;
|
import mindustry.world.meta.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class PlacementFragment{
|
public class PlacementFragment{
|
||||||
@@ -474,9 +477,9 @@ public class PlacementFragment{
|
|||||||
|
|
||||||
Bits availableCommands = new Bits(content.unitCommands().size);
|
Bits availableCommands = new Bits(content.unitCommands().size);
|
||||||
Bits availableStances = new Bits(content.unitStances().size);
|
Bits availableStances = new Bits(content.unitStances().size);
|
||||||
|
Bits activeTypes = new Bits(content.units().size), prevActiveTypes = new Bits(content.units().size);
|
||||||
|
|
||||||
u.left();
|
u.left();
|
||||||
int[] curCount = {0};
|
|
||||||
Bits usedCommands = new Bits(content.unitCommands().size);
|
Bits usedCommands = new Bits(content.unitCommands().size);
|
||||||
var commands = new Seq<UnitCommand>();
|
var commands = new Seq<UnitCommand>();
|
||||||
|
|
||||||
@@ -484,6 +487,8 @@ public class PlacementFragment{
|
|||||||
var stances = new Seq<UnitStance>();
|
var stances = new Seq<UnitStance>();
|
||||||
var stancesOut = new Seq<UnitStance>();
|
var stancesOut = new Seq<UnitStance>();
|
||||||
|
|
||||||
|
int[] counts = new int[content.units().size];
|
||||||
|
|
||||||
rebuildCommand = () -> {
|
rebuildCommand = () -> {
|
||||||
u.clearChildren();
|
u.clearChildren();
|
||||||
var units = control.input.selectedUnits;
|
var units = control.input.selectedUnits;
|
||||||
@@ -493,7 +498,7 @@ public class PlacementFragment{
|
|||||||
commands.clear();
|
commands.clear();
|
||||||
stances.clear();
|
stances.clear();
|
||||||
|
|
||||||
int[] counts = new int[content.units().size];
|
Arrays.fill(counts, 0);
|
||||||
|
|
||||||
for(var unit : units){
|
for(var unit : units){
|
||||||
counts[unit.type.id] ++;
|
counts[unit.type.id] ++;
|
||||||
@@ -514,12 +519,18 @@ public class PlacementFragment{
|
|||||||
|
|
||||||
int col = 0;
|
int col = 0;
|
||||||
for(int i = 0; i < counts.length; i++){
|
for(int i = 0; i < counts.length; i++){
|
||||||
|
int fi = i;
|
||||||
if(counts[i] > 0){
|
if(counts[i] > 0){
|
||||||
var type = content.unit(i);
|
var type = content.unit(i);
|
||||||
unitlist.add(StatValues.stack(type, counts[i])).pad(4).with(b -> {
|
unitlist.add(StatValues.stack(type, counts[i])).pad(4).with(b -> {
|
||||||
b.clearListeners();
|
b.clearListeners();
|
||||||
b.addListener(Tooltips.getInstance().create(type.localizedName, false));
|
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();
|
var listener = new ClickListener();
|
||||||
|
|
||||||
//left click -> select
|
//left click -> select
|
||||||
@@ -602,6 +613,9 @@ public class PlacementFragment{
|
|||||||
activeStances.clear();
|
activeStances.clear();
|
||||||
availableCommands.clear();
|
availableCommands.clear();
|
||||||
availableStances.clear();
|
availableStances.clear();
|
||||||
|
activeTypes.clear();
|
||||||
|
|
||||||
|
Arrays.fill(counts, 0);
|
||||||
|
|
||||||
//find the command that all units have, or null if they do not share one
|
//find the command that all units have, or null if they do not share one
|
||||||
for(var unit : control.input.selectedUnits){
|
for(var unit : control.input.selectedUnits){
|
||||||
@@ -610,6 +624,10 @@ public class PlacementFragment{
|
|||||||
activeStances.set(cmd.stances);
|
activeStances.set(cmd.stances);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
counts[unit.type.id] ++;
|
||||||
|
|
||||||
|
activeTypes.set(unit.type.id);
|
||||||
|
|
||||||
stancesOut.clear();
|
stancesOut.clear();
|
||||||
unit.type.getUnitStances(unit, stancesOut);
|
unit.type.getUnitStances(unit, stancesOut);
|
||||||
|
|
||||||
@@ -622,12 +640,9 @@ public class PlacementFragment{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = control.input.selectedUnits.size;
|
if(!usedCommands.equals(availableCommands) || !usedStances.equals(availableStances) || !prevActiveTypes.equals(activeTypes)){
|
||||||
if(curCount[0] != size || !usedCommands.equals(availableCommands) || !usedStances.equals(availableStances)){
|
rebuildCommand.run();
|
||||||
if(!(curCount[0] + size == 0)){
|
prevActiveTypes.set(activeTypes);
|
||||||
rebuildCommand.run();
|
|
||||||
}
|
|
||||||
curCount[0] = size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//not a huge fan of running input logic here, but it's convenient as the stance arrays are all here...
|
//not a huge fan of running input logic here, but it's convenient as the stance arrays are all here...
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ public class StatValues{
|
|||||||
if(amount != 0){
|
if(amount != 0){
|
||||||
stack.add(new Table(t -> {
|
stack.add(new Table(t -> {
|
||||||
t.left().bottom();
|
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();
|
t.pack();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user