mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-10 10:47:13 +07:00
Sensor selection
This commit is contained in:
parent
4dc90d4074
commit
1b7159647e
@ -1,35 +0,0 @@
|
||||
package mindustry.entities.units;
|
||||
|
||||
public class StateMachine{
|
||||
private UnitState state;
|
||||
|
||||
public void update(){
|
||||
if(state != null) state.update();
|
||||
}
|
||||
|
||||
public void set(UnitState next){
|
||||
if(next == state) return;
|
||||
if(state != null) state.exited();
|
||||
this.state = next;
|
||||
if(next != null) next.entered();
|
||||
}
|
||||
|
||||
public UnitState current(){
|
||||
return state;
|
||||
}
|
||||
|
||||
public boolean is(UnitState state){
|
||||
return this.state == state;
|
||||
}
|
||||
|
||||
public interface UnitState{
|
||||
default void entered(){
|
||||
}
|
||||
|
||||
default void exited(){
|
||||
}
|
||||
|
||||
default void update(){
|
||||
}
|
||||
}
|
||||
}
|
@ -24,12 +24,29 @@ public abstract class LStatement{
|
||||
public abstract LCategory category();
|
||||
public abstract LInstruction build(LAssembler builder);
|
||||
|
||||
protected void field(Table table, String value, Cons<String> setter){
|
||||
table.field(value, Styles.nodeField, setter)
|
||||
.size(130f, 40f).pad(2f).color(table.color);
|
||||
protected Cell<TextField> field(Table table, String value, Cons<String> setter){
|
||||
return table.field(value, Styles.nodeField, setter)
|
||||
.size(144f, 40f).pad(2f).color(table.color).addInputDialog();
|
||||
}
|
||||
|
||||
protected <T> void showSelect(Button b, T[] values, T current, Cons<T> getter){
|
||||
showSelectTable(b, (t, hide) -> {
|
||||
ButtonGroup<Button> group = new ButtonGroup<>();
|
||||
int i = 0;
|
||||
t.defaults().size(56f, 40f);
|
||||
|
||||
for(T p : values){
|
||||
t.button(p.toString(), Styles.clearTogglet, () -> {
|
||||
getter.get(p);
|
||||
hide.run();
|
||||
}).checked(current == p).group(group);
|
||||
|
||||
if(++i % 4 == 0) t.row();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void showSelectTable(Button b, Cons2<Table, Runnable> hideCons){
|
||||
Table t = new Table(Tex.button);
|
||||
|
||||
//triggers events behind the element to simulate deselection
|
||||
@ -48,23 +65,12 @@ public abstract class LStatement{
|
||||
|
||||
t.update(() -> {
|
||||
b.localToStageCoordinates(Tmp.v1.set(b.getWidth()/2f, b.getHeight()/2f));
|
||||
Tmp.v1.clamp(0, 0, Core.graphics.getWidth() - b.getWidth(), Core.graphics.getHeight() - b.getHeight());
|
||||
t.setPosition(Tmp.v1.x, Tmp.v1.y, Align.center);
|
||||
t.keepInStage();
|
||||
});
|
||||
t.actions(Actions.alpha(0), Actions.fadeIn(0.3f, Interp.fade));
|
||||
|
||||
ButtonGroup<Button> group = new ButtonGroup<>();
|
||||
int i = 0;
|
||||
t.defaults().size(56f, 40f);
|
||||
|
||||
for(T p : values){
|
||||
t.button(p.toString(), Styles.clearTogglet, () -> {
|
||||
getter.get(p);
|
||||
hide.run();
|
||||
}).checked(current == p).group(group);
|
||||
|
||||
if(++i % 4 == 0) t.row();
|
||||
}
|
||||
hideCons.get(t, hide);
|
||||
|
||||
t.pack();
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
package mindustry.logic;
|
||||
|
||||
import arc.graphics.*;
|
||||
import arc.scene.style.*;
|
||||
import arc.scene.ui.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import mindustry.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.logic.LCanvas.*;
|
||||
import mindustry.logic.LExecutor.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
public class LStatements{
|
||||
@ -64,6 +69,9 @@ public class LStatements{
|
||||
public String to = "result";
|
||||
public String from = "@0", type = "@copper";
|
||||
|
||||
private transient int selected = 0;
|
||||
private transient TextField tfield;
|
||||
|
||||
@Override
|
||||
public void build(Table table){
|
||||
field(table, to, str -> to = str);
|
||||
@ -72,13 +80,78 @@ public class LStatements{
|
||||
|
||||
table.row();
|
||||
|
||||
field(table, type, str -> type = str);
|
||||
tfield = field(table, type, str -> type = str).padRight(0f).get();
|
||||
|
||||
table.button(b -> {
|
||||
b.image(Icon.pencilSmall);
|
||||
//240
|
||||
b.clicked(() -> showSelectTable(b, (t, hide) -> {
|
||||
Table[] tables = {
|
||||
//items
|
||||
new Table(i -> {
|
||||
int c = 0;
|
||||
for(Item item : Vars.content.items()){
|
||||
i.button(new TextureRegionDrawable(item.icon(Cicon.small)), Styles.cleari, () -> {
|
||||
stype("@" + item.name);
|
||||
hide.run();
|
||||
}).size(40f);
|
||||
|
||||
if(++c % 6 == 0) i.row();
|
||||
}
|
||||
}),
|
||||
//liquids
|
||||
new Table(i -> {
|
||||
int c = 0;
|
||||
for(Liquid item : Vars.content.liquids()){
|
||||
i.button(new TextureRegionDrawable(item.icon(Cicon.small)), Styles.cleari, () -> {
|
||||
stype("@" + item.name);
|
||||
hide.run();
|
||||
}).size(40f);
|
||||
|
||||
if(++c % 6 == 0) i.row();
|
||||
}
|
||||
}),
|
||||
//sensors
|
||||
new Table(i -> {
|
||||
for(LSensor sensor : LSensor.all){
|
||||
i.button(sensor.name(), Styles.cleart, () -> {
|
||||
stype("@" + sensor.name());
|
||||
hide.run();
|
||||
}).size(240f, 40f).row();
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
Drawable[] icons = {Icon.box, Icon.liquid, Icon.tree};
|
||||
Stack stack = new Stack(tables[selected]);
|
||||
ButtonGroup<Button> group = new ButtonGroup<>();
|
||||
|
||||
for(int i = 0; i < tables.length; i++){
|
||||
int fi = i;
|
||||
|
||||
t.button(icons[i], Styles.clearTogglei, () -> {
|
||||
selected = fi;
|
||||
|
||||
stack.clearChildren();
|
||||
stack.addChild(tables[selected]);
|
||||
t.pack();
|
||||
}).size(80f, 50f).checked(selected == fi).group(group);
|
||||
}
|
||||
t.row();
|
||||
t.add(stack).colspan(3);
|
||||
}));
|
||||
}, Styles.cleart, () -> {}).size(40f).padLeft(-1);
|
||||
|
||||
table.add(" in ");
|
||||
|
||||
field(table, from, str -> from = str);
|
||||
}
|
||||
|
||||
private void stype(String text){
|
||||
tfield.setText(text);
|
||||
this.type = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LCategory category(){
|
||||
return LCategory.operations;
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=93182a28a728438ae456919ec0265afdb77d5090
|
||||
archash=cbfa2828a465909e9bb74e3dde211a3f59ffbbb1
|
||||
|
Loading…
Reference in New Issue
Block a user