WIP command order system
This commit is contained in:
@@ -11,6 +11,8 @@ import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ai.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.entities.*;
|
||||
@@ -422,6 +424,8 @@ public class PlacementFragment{
|
||||
commandTable.table(u -> {
|
||||
u.left();
|
||||
int[] curCount = {0};
|
||||
UnitCommand[] currentCommand = {null};
|
||||
var commands = new Seq<UnitCommand>();
|
||||
|
||||
Runnable rebuildCommand = () -> {
|
||||
u.clearChildren();
|
||||
@@ -431,12 +435,17 @@ public class PlacementFragment{
|
||||
for(var unit : units){
|
||||
counts[unit.type.id] ++;
|
||||
}
|
||||
commands.clear();
|
||||
boolean firstCommand = false;
|
||||
Table unitlist = u.table().growX().left().get();
|
||||
unitlist.left();
|
||||
|
||||
int col = 0;
|
||||
for(int i = 0; i < counts.length; i++){
|
||||
if(counts[i] > 0){
|
||||
var type = content.unit(i);
|
||||
u.add(new ItemImage(type.uiIcon, counts[i])).tooltip(type.localizedName).pad(4).with(b -> {
|
||||
ClickListener listener = new ClickListener();
|
||||
unitlist.add(new ItemImage(type.uiIcon, counts[i])).tooltip(type.localizedName).pad(4).with(b -> {
|
||||
var listener = new ClickListener();
|
||||
|
||||
//left click -> select
|
||||
b.clicked(KeyCode.mouseLeft, () -> control.input.selectedUnits.removeAll(unit -> unit.type != type));
|
||||
@@ -450,16 +459,62 @@ public class PlacementFragment{
|
||||
});
|
||||
|
||||
if(++col % 7 == 0){
|
||||
u.row();
|
||||
unitlist.row();
|
||||
}
|
||||
|
||||
if(!firstCommand){
|
||||
commands.add(type.commands);
|
||||
firstCommand = true;
|
||||
}else{
|
||||
//remove commands that this next unit type doesn't have
|
||||
commands.removeAll(com -> !Structs.contains(type.commands, com));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(commands.size > 1){
|
||||
u.row();
|
||||
|
||||
u.table(coms -> {
|
||||
for(var command : commands){
|
||||
coms.button(Icon.icons.get(command.icon, Icon.cancel), Styles.clearNoneTogglei, () -> {
|
||||
IntSeq ids = new IntSeq();
|
||||
for(var unit : units){
|
||||
ids.add(unit.id);
|
||||
}
|
||||
|
||||
Call.setUnitCommand(Vars.player, ids.toArray(), command);
|
||||
}).checked(i -> currentCommand[0] == command).size(50f).tooltip(command.localized());
|
||||
}
|
||||
}).fillX().padTop(4f).left();
|
||||
}
|
||||
}else{
|
||||
u.add("[no units]").color(Color.lightGray).growX().center().labelAlign(Align.center).pad(6);
|
||||
}
|
||||
};
|
||||
|
||||
u.update(() -> {
|
||||
boolean hadCommand = false;
|
||||
UnitCommand shareCommand = null;
|
||||
|
||||
//find the command that all units have, or null if they do not share one
|
||||
for(var unit : control.input.selectedUnits){
|
||||
if(unit.isCommandable()){
|
||||
var nextCommand = unit.command().currentCommand();
|
||||
|
||||
if(hadCommand){
|
||||
if(shareCommand != nextCommand){
|
||||
shareCommand = null;
|
||||
}
|
||||
}else{
|
||||
shareCommand = nextCommand;
|
||||
hadCommand = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentCommand[0] = shareCommand;
|
||||
|
||||
int size = control.input.selectedUnits.size;
|
||||
if(curCount[0] != size){
|
||||
curCount[0] = size;
|
||||
|
||||
Reference in New Issue
Block a user