mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-10 10:47:13 +07:00
Better logic UI
This commit is contained in:
parent
73dd7ba21a
commit
ffb2d6eeaa
@ -40,7 +40,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
|
||||
public void update(){
|
||||
Building core = closestCore();
|
||||
|
||||
if(core != null && mineTile != null && mineTile.drop() != null && !acceptsItem(mineTile.drop()) && within(core, mineTransferRange)){
|
||||
if(core != null && mineTile != null && mineTile.drop() != null && !acceptsItem(mineTile.drop()) && within(core, mineTransferRange) && !offloadImmediately()){
|
||||
int accepted = core.acceptStack(item(), stack().amount, this);
|
||||
if(accepted > 0){
|
||||
Call.transferItemTo(item(), accepted,
|
||||
@ -52,7 +52,7 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
|
||||
|
||||
if(mineTile == null || core == null || mineTile.block() != Blocks.air || dst(mineTile.worldx(), mineTile.worldy()) > miningRange
|
||||
|| (((Object)this) instanceof Builderc && ((Builderc)(Object)this).activelyBuilding())
|
||||
|| mineTile.drop() == null || !acceptsItem(mineTile.drop()) || !canMine(mineTile.drop())){
|
||||
|| mineTile.drop() == null || !canMine(mineTile.drop())){
|
||||
mineTile = null;
|
||||
mineTimer = 0f;
|
||||
}else{
|
||||
@ -60,6 +60,10 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
|
||||
rotation(Mathf.slerpDelta(rotation(), angleTo(mineTile.worldx(), mineTile.worldy()), 0.4f));
|
||||
mineTimer += Time.delta *type.mineSpeed;
|
||||
|
||||
if(Mathf.chance(0.06 * Time.delta)){
|
||||
Fx.pulverizeSmall.at(mineTile.worldx() + Mathf.range(tilesize / 2f), mineTile.worldy() + Mathf.range(tilesize / 2f), 0f, item.color);
|
||||
}
|
||||
|
||||
if(mineTimer >= 50f + item.hardness*10f){
|
||||
mineTimer = 0;
|
||||
|
||||
@ -73,12 +77,13 @@ abstract class MinerComp implements Itemsc, Posc, Teamc, Rotc, Drawc, Unitc{
|
||||
mineTile.worldx() + Mathf.range(tilesize / 2f),
|
||||
mineTile.worldy() + Mathf.range(tilesize / 2f),
|
||||
this);
|
||||
}else{
|
||||
mineTile = null;
|
||||
mineTimer = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
if(Mathf.chance(0.06 * Time.delta)){
|
||||
Fx.pulverizeSmall.at(mineTile.worldx() + Mathf.range(tilesize / 2f), mineTile.worldy() + Mathf.range(tilesize / 2f), 0f, item.color);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ public class DesktopInput extends InputHandler{
|
||||
Core.camera.position.lerpDelta(player, Core.settings.getBool("smoothcamera") ? 0.08f : 1f);
|
||||
}
|
||||
|
||||
shouldShoot = true;
|
||||
shouldShoot = !scene.hasMouse();
|
||||
|
||||
if(!scene.hasMouse()){
|
||||
if(Core.input.keyDown(Binding.control) && Core.input.keyTap(Binding.select)){
|
||||
|
@ -903,7 +903,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
}
|
||||
|
||||
public boolean canShoot(){
|
||||
return block == null && !Core.scene.hasMouse() && !onConfigurable() && !isDroppingItem() && !(player.builder().updateBuilding() && player.builder().isBuilding());
|
||||
return block == null && !onConfigurable() && !isDroppingItem() && !(player.builder().updateBuilding() && player.builder().isBuilding());
|
||||
}
|
||||
|
||||
public boolean onConfigurable(){
|
||||
|
@ -16,9 +16,7 @@ import arc.util.*;
|
||||
import arc.util.ArcAnnotate.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.logic.LStatements.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.dialogs.*;
|
||||
import mindustry.world.blocks.logic.*;
|
||||
|
||||
public class LCanvas extends Table{
|
||||
@ -26,38 +24,46 @@ public class LCanvas extends Table{
|
||||
private static Seq<Runnable> postDraw = new Seq<>();
|
||||
private Vec2 offset = new Vec2();
|
||||
|
||||
private DragLayout statements;
|
||||
private StatementElem dragging;
|
||||
DragLayout statements;
|
||||
StatementElem dragging;
|
||||
ScrollPane pane;
|
||||
float targetWidth;
|
||||
|
||||
public LCanvas(){
|
||||
//left();
|
||||
rebuild();
|
||||
}
|
||||
|
||||
/** @return if statement elements should have rows. */
|
||||
public static boolean useRows(){
|
||||
return Core.graphics.getWidth() < Scl.scl(900f) * 1.2f;
|
||||
}
|
||||
|
||||
public void rebuild(){
|
||||
targetWidth = useRows() ? 400f : 900f;
|
||||
float s = pane != null ? pane.getScrollPercentY() : 0f;
|
||||
String toLoad = statements != null ? save() : null;
|
||||
|
||||
clear();
|
||||
|
||||
statements = new DragLayout();
|
||||
|
||||
ScrollPane pane = pane(statements).grow().get();
|
||||
pane = pane(t -> {
|
||||
t.center();
|
||||
t.add(statements).pad(2f).center().width(targetWidth);
|
||||
}).grow().get();
|
||||
pane.setClip(false);
|
||||
pane.setFlickScroll(false);
|
||||
|
||||
row();
|
||||
//load old scroll percent
|
||||
Core.app.post(() -> {
|
||||
pane.setScrollPercentY(s);
|
||||
pane.updateVisualScroll();
|
||||
pane.requestScroll();
|
||||
});
|
||||
|
||||
button("@add", Icon.add, Styles.cleart, () -> {
|
||||
BaseDialog dialog = new BaseDialog("@add");
|
||||
dialog.cont.pane(t -> {
|
||||
t.background(Tex.button);
|
||||
int i = 0;
|
||||
for(Prov<LStatement> prov : LogicIO.allStatements){
|
||||
LStatement example = prov.get();
|
||||
if(example instanceof InvalidStatement) continue;
|
||||
t.button(example.name(), Styles.cleart, () -> {
|
||||
add(prov.get());
|
||||
dialog.hide();
|
||||
}).size(140f, 50f);
|
||||
if(++i % 2 == 0) t.row();
|
||||
}
|
||||
});
|
||||
dialog.addCloseButton();
|
||||
dialog.show();
|
||||
}).height(50f).left().width(400f).marginLeft(10f).disabled(t -> statements.getChildren().size >= LogicBlock.maxInstructions);
|
||||
if(toLoad != null){
|
||||
load(toLoad);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawGrid(){
|
||||
@ -120,7 +126,6 @@ public class LCanvas extends Table{
|
||||
}
|
||||
|
||||
public class DragLayout extends WidgetGroup{
|
||||
float margin = Scl.scl(4f);
|
||||
float space = Scl.scl(10f), prefWidth, prefHeight;
|
||||
Seq<Element> seq = new Seq<>();
|
||||
int insertPosition = 0;
|
||||
@ -134,10 +139,10 @@ public class LCanvas extends Table{
|
||||
float cy = 0;
|
||||
seq.clear();
|
||||
|
||||
float totalHeight = getChildren().sumf(e -> e.getHeight() + space) + margin*2f;
|
||||
float totalHeight = getChildren().sumf(e -> e.getHeight() + space);
|
||||
|
||||
height = prefHeight = totalHeight;
|
||||
width = prefWidth = Scl.scl(400f);
|
||||
width = prefWidth = Scl.scl(targetWidth);
|
||||
|
||||
//layout everything normally
|
||||
for(int i = 0; i < getChildren().size; i++){
|
||||
@ -146,8 +151,8 @@ public class LCanvas extends Table{
|
||||
//ignore the dragged element
|
||||
if(dragging == e) continue;
|
||||
|
||||
e.setSize(width - margin * 2f, e.getPrefHeight());
|
||||
e.setPosition(x + margin, height- margin - cy, Align.topLeft);
|
||||
e.setSize(width, e.getPrefHeight());
|
||||
e.setPosition(0, height - cy, Align.topLeft);
|
||||
|
||||
cy += e.getPrefHeight() + space;
|
||||
seq.add(e);
|
||||
@ -197,10 +202,10 @@ public class LCanvas extends Table{
|
||||
//draw selection box indicating placement position
|
||||
if(dragging != null && insertPosition <= seq.size){
|
||||
float shiftAmount = dragging.getHeight();
|
||||
float lastX = x + margin;
|
||||
float lastY = insertPosition == 0 ? height + y - margin : seq.get(insertPosition - 1).y + y - space;
|
||||
float lastX = x;
|
||||
float lastY = insertPosition == 0 ? height + y : seq.get(insertPosition - 1).y + y - space;
|
||||
|
||||
Tex.pane.draw(lastX, lastY - shiftAmount, width - margin*2f, dragging.getHeight());
|
||||
Tex.pane.draw(lastX, lastY - shiftAmount, width, dragging.getHeight());
|
||||
}
|
||||
|
||||
super.draw();
|
||||
@ -253,6 +258,10 @@ public class LCanvas extends Table{
|
||||
|
||||
t.add(st.name()).style(Styles.outlineLabel).color(color).padRight(8);
|
||||
t.add().growX();
|
||||
|
||||
t.button(Icon.copy, Styles.logici, () -> {
|
||||
}).padRight(6).get().tapped(() -> copy());
|
||||
|
||||
t.button(Icon.cancel, Styles.logici, () -> {
|
||||
remove();
|
||||
dragging = null;
|
||||
@ -266,15 +275,7 @@ public class LCanvas extends Table{
|
||||
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){
|
||||
|
||||
if(button == KeyCode.mouseMiddle){
|
||||
LStatement copy = st.copy();
|
||||
if(copy != null){
|
||||
StatementElem s = new StatementElem(copy);
|
||||
|
||||
statements.addChildAfter(StatementElem.this,s);
|
||||
statements.layout();
|
||||
copy.elem = s;
|
||||
copy.setupUI();
|
||||
}
|
||||
copy();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -317,6 +318,18 @@ public class LCanvas extends Table{
|
||||
marginBottom(7);
|
||||
}
|
||||
|
||||
void copy(){
|
||||
LStatement copy = st.copy();
|
||||
if(copy != null){
|
||||
StatementElem s = new StatementElem(copy);
|
||||
|
||||
statements.addChildAfter(StatementElem.this,s);
|
||||
statements.layout();
|
||||
copy.elem = s;
|
||||
copy.setupUI();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
float pad = 5f;
|
||||
|
@ -48,6 +48,12 @@ public abstract class LStatement{
|
||||
field(table, value, setter).width(85f);
|
||||
}
|
||||
|
||||
protected void row(Table table){
|
||||
if(LCanvas.useRows()){
|
||||
table.row();
|
||||
}
|
||||
}
|
||||
|
||||
protected <T> void showSelect(Button b, T[] values, T current, Cons<T> getter, int cols, Cons<Cell> sizer){
|
||||
showSelectTable(b, (t, hide) -> {
|
||||
ButtonGroup<Button> group = new ButtonGroup<>();
|
||||
|
@ -94,7 +94,7 @@ public class LStatements{
|
||||
|
||||
fields(table, target, str -> target = str);
|
||||
|
||||
table.row();
|
||||
row(table);
|
||||
|
||||
table.add(" at ");
|
||||
|
||||
@ -126,7 +126,7 @@ public class LStatements{
|
||||
|
||||
fields(table, target, str -> target = str);
|
||||
|
||||
table.row();
|
||||
row(table);
|
||||
|
||||
table.add(" at ");
|
||||
|
||||
@ -168,7 +168,7 @@ public class LStatements{
|
||||
}, Styles.logict, () -> {}).size(90, 40).color(table.color).left().padLeft(2);
|
||||
|
||||
if(type != GraphicsType.stroke){
|
||||
table.row();
|
||||
row(table);
|
||||
}
|
||||
|
||||
table.table(s -> {
|
||||
@ -189,7 +189,7 @@ public class LStatements{
|
||||
case line:
|
||||
fields(s, "x", x, v -> x = v);
|
||||
fields(s, "y", y, v -> y = v);
|
||||
s.row();
|
||||
row(s);
|
||||
fields(s, "x2", p1, v -> p1 = v);
|
||||
fields(s, "y2", p2, v -> p2 = v);
|
||||
break;
|
||||
@ -197,7 +197,7 @@ public class LStatements{
|
||||
case lineRect:
|
||||
fields(s, "x", x, v -> x = v);
|
||||
fields(s, "y", y, v -> y = v);
|
||||
s.row();
|
||||
row(s);
|
||||
fields(s, "width", p1, v -> p1 = v);
|
||||
fields(s, "height", p2, v -> p2 = v);
|
||||
break;
|
||||
@ -205,19 +205,19 @@ public class LStatements{
|
||||
case linePoly:
|
||||
fields(s, "x", x, v -> x = v);
|
||||
fields(s, "y", y, v -> y = v);
|
||||
s.row();
|
||||
row(s);
|
||||
fields(s, "sides", p1, v -> p1 = v);
|
||||
fields(s, "radius", p2, v -> p2 = v);
|
||||
s.row();
|
||||
row(s);
|
||||
fields(s, "rotation", p3, v -> p3 = v);
|
||||
break;
|
||||
case triangle:
|
||||
fields(s, "x", x, v -> x = v);
|
||||
fields(s, "y", y, v -> y = v);
|
||||
s.row();
|
||||
row(s);
|
||||
fields(s, "x2", p1, v -> p1 = v);
|
||||
fields(s, "y2", p2, v -> p2 = v);
|
||||
s.row();
|
||||
row(s);
|
||||
fields(s, "x3", p3, v -> p3 = v);
|
||||
fields(s, "y3", p4, v -> p4 = v);
|
||||
break;
|
||||
@ -328,7 +328,7 @@ public class LStatements{
|
||||
|
||||
field(table, target, v -> target = v);
|
||||
|
||||
table.row();
|
||||
row(table);
|
||||
|
||||
//Q: why don't you just use arrays for this?
|
||||
//A: arrays aren't as easy to serialize so the code generator doesn't handle them
|
||||
@ -337,7 +337,7 @@ public class LStatements{
|
||||
|
||||
fields(table, type.parameters[i], i == 0 ? p1 : i == 1 ? p2 : i == 2 ? p3 : p4, i == 0 ? v -> p1 = v : i == 1 ? v -> p2 = v : i == 2 ? v -> p3 = v : v -> p4 = v);
|
||||
|
||||
if(++c % 2 == 0) table.row();
|
||||
if(++c % 2 == 0) row(table);
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,7 +366,7 @@ public class LStatements{
|
||||
|
||||
fields(table, radar, v -> radar = v);
|
||||
|
||||
table.row();
|
||||
row(table);
|
||||
|
||||
for(int i = 0; i < 3; i++){
|
||||
int fi = i;
|
||||
@ -382,7 +382,7 @@ public class LStatements{
|
||||
}, Styles.logict, () -> {}).size(90, 40).color(table.color).left().padLeft(2);
|
||||
|
||||
if(i == 1){
|
||||
table.row();
|
||||
row(table);
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,7 +390,7 @@ public class LStatements{
|
||||
|
||||
fields(table, sortOrder, v -> sortOrder = v);
|
||||
|
||||
table.row();
|
||||
row(table);
|
||||
|
||||
table.add(" output ");
|
||||
|
||||
@ -422,7 +422,7 @@ public class LStatements{
|
||||
|
||||
table.add(" = ");
|
||||
|
||||
table.row();
|
||||
row(table);
|
||||
|
||||
tfield = field(table, type, str -> type = str).padRight(0f).get();
|
||||
|
||||
@ -547,7 +547,7 @@ public class LStatements{
|
||||
|
||||
table.add(" = ");
|
||||
|
||||
table.row();
|
||||
row(table);
|
||||
|
||||
field(table, a, str -> a = str);
|
||||
|
||||
|
@ -3,11 +3,12 @@ package mindustry.logic;
|
||||
import arc.*;
|
||||
import arc.func.*;
|
||||
import arc.scene.ui.TextButton.*;
|
||||
import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.logic.LStatements.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.dialogs.*;
|
||||
import mindustry.world.blocks.logic.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
@ -23,6 +24,8 @@ public class LogicDialog extends BaseDialog{
|
||||
canvas = new LCanvas();
|
||||
addCloseButton();
|
||||
|
||||
buttons.getCells().first().width(170f);
|
||||
|
||||
buttons.button("@edit", Icon.edit, () -> {
|
||||
BaseDialog dialog = new BaseDialog("@editor.export");
|
||||
dialog.cont.pane(p -> {
|
||||
@ -49,14 +52,36 @@ public class LogicDialog extends BaseDialog{
|
||||
|
||||
dialog.addCloseButton();
|
||||
dialog.show();
|
||||
});
|
||||
}).width(170f);
|
||||
|
||||
stack(canvas, new Table(t -> {
|
||||
t.bottom();
|
||||
t.add(buttons);
|
||||
})).grow();
|
||||
buttons.button("@add", Icon.add, () -> {
|
||||
BaseDialog dialog = new BaseDialog("@add");
|
||||
dialog.cont.pane(t -> {
|
||||
t.background(Tex.button);
|
||||
int i = 0;
|
||||
for(Prov<LStatement> prov : LogicIO.allStatements){
|
||||
LStatement example = prov.get();
|
||||
if(example instanceof InvalidStatement) continue;
|
||||
t.button(example.name(), Styles.cleart, () -> {
|
||||
canvas.add(prov.get());
|
||||
dialog.hide();
|
||||
}).size(140f, 50f);
|
||||
if(++i % 2 == 0) t.row();
|
||||
}
|
||||
});
|
||||
dialog.addCloseButton();
|
||||
dialog.show();
|
||||
}).width(170f).disabled(t -> canvas.statements.getChildren().size >= LogicBlock.maxInstructions);
|
||||
|
||||
add(canvas).grow();
|
||||
|
||||
row();
|
||||
|
||||
add(buttons).growX();
|
||||
|
||||
hidden(() -> consumer.get(canvas.save()));
|
||||
|
||||
onResize(() -> canvas.rebuild());
|
||||
}
|
||||
|
||||
public void show(String code, Cons<String> consumer){
|
||||
|
@ -44,7 +44,9 @@ public abstract class GenerateFilter{
|
||||
|
||||
/** localized display name */
|
||||
public String name(){
|
||||
return Core.bundle.get("filter." + getClass().getSimpleName().toLowerCase().replace("filter", ""), getClass().getSimpleName().replace("Filter", ""));
|
||||
Class c = getClass();
|
||||
if(c.isAnonymousClass()) c = c.getSuperclass();
|
||||
return Core.bundle.get("filter." + c.getSimpleName().toLowerCase().replace("filter", ""), c.getSimpleName().replace("Filter", ""));
|
||||
}
|
||||
|
||||
/** set the seed to a random number */
|
||||
|
@ -203,7 +203,7 @@ public class Styles{
|
||||
}};
|
||||
geni = new ImageButtonStyle(){{
|
||||
imageDownColor = Pal.accent;
|
||||
imageUpColor = Color.white;
|
||||
imageUpColor = Color.black;
|
||||
}};
|
||||
colori = new ImageButtonStyle(){{
|
||||
//imageDownColor = Pal.accent;
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=a5c0934b3894e9f2fe793800a2adb39606f32cee
|
||||
archash=7fbbbc6eb77b8f868c962504586e8c4b67c709ec
|
||||
|
Loading…
Reference in New Issue
Block a user