Logic hint tooltips

This commit is contained in:
Anuken
2021-02-09 14:52:23 -05:00
parent ce8b32f022
commit e22fccf5b1
12 changed files with 152 additions and 24 deletions

View File

@@ -108,7 +108,7 @@ public class UI implements ApplicationListener, Loadable{
Dialog.setHideAction(() -> sequence(fadeOut(0.1f)));
Tooltips.getInstance().animations = false;
Tooltips.getInstance().textProvider = text -> new Tooltip(t -> t.background(Styles.black5).margin(4f).add(text));
Tooltips.getInstance().textProvider = text -> new Tooltip(t -> t.background(Styles.black6).margin(4f).add(text));
Core.settings.setErrorHandler(e -> {
Log.err(e);

View File

@@ -7,6 +7,7 @@ public enum ConditionOp{
lessThanEq("<=", (a, b) -> a <= b),
greaterThan(">", (a, b) -> a > b),
greaterThanEq(">=", (a, b) -> a >= b),
strictEqual("===", (a, b) -> false),
always("always", (a, b) -> true);
public static final ConditionOp[] all = values();

View File

@@ -41,6 +41,13 @@ public class LCanvas extends Table{
return Core.graphics.getWidth() < Scl.scl(900f) * 1.2f;
}
public static void tooltip(Cell<?> cell, String key){
String lkey = key.toLowerCase().replace(" ", "");
if(Core.settings.getBool("logichints", true) && Core.bundle.has(lkey)){
cell.get().addListener(new Tooltip(t -> t.background(Styles.black8).margin(4f).add("[lightgray]" + Core.bundle.get(lkey)).style(Styles.outlineLabel)));
}
}
public void rebuild(){
targetWidth = useRows() ? 400f : 900f;
float s = pane != null ? pane.getScrollPercentY() : 0f;

View File

@@ -966,7 +966,9 @@ public class LExecutor{
Var vb = exec.var(compare);
boolean cmp;
if(op.objFunction != null && va.isobj && vb.isobj){
if(op == ConditionOp.strictEqual){
cmp = va.isobj == vb.isobj && ((va.isobj && va.objval == vb.objval) || (!va.isobj && va.numval == vb.numval));
}else if(op.objFunction != null && va.isobj && vb.isobj){
//use object function if both are objects
cmp = op.objFunction.get(exec.obj(value), exec.obj(compare));
}else{

View File

@@ -15,6 +15,8 @@ import mindustry.logic.LCanvas.*;
import mindustry.logic.LExecutor.*;
import mindustry.ui.*;
import static mindustry.logic.LCanvas.*;
/**
* A statement is an intermediate representation of an instruction, to be used mostly in UI.
* Contains all relevant variable information. */
@@ -38,13 +40,18 @@ public abstract class LStatement{
//protected methods are only for internal UI layout utilities
protected void param(Cell<Label> label){
String text = name() + "." + label.get().getText().toString().trim();
tooltip(label, text);
}
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).maxTextLength(LAssembler.maxTokenLength).addInputDialog();
}
protected Cell<TextField> fields(Table table, String desc, String value, Cons<String> setter){
table.add(desc).padLeft(10).left();
table.add(desc).padLeft(10).left().self(this::param);;
return field(table, value, setter).width(85f).padRight(10).left();
}
@@ -58,7 +65,7 @@ public abstract class LStatement{
}
}
protected <T> void showSelect(Button b, T[] values, T current, Cons<T> getter, int cols, Cons<Cell> sizer){
protected <T extends Enum<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<>();
int i = 0;
@@ -68,14 +75,14 @@ public abstract class LStatement{
sizer.get(t.button(p.toString(), Styles.logicTogglet, () -> {
getter.get(p);
hide.run();
}).checked(current == p).group(group));
}).self(c -> tooltip(c, "lenum." + p.name())).checked(current == p).group(group));
if(++i % cols == 0) t.row();
}
});
}
protected <T> void showSelect(Button b, T[] values, T current, Cons<T> getter){
protected <T extends Enum<T>> void showSelect(Button b, T[] values, T current, Cons<T> getter){
showSelect(b, values, current, getter, 4, c -> {});
}
@@ -151,4 +158,5 @@ public abstract class LStatement{
public String name(){
return Strings.insertSpaces(getClass().getSimpleName().replace("Statement", ""));
}
}

View File

@@ -15,6 +15,7 @@ import mindustry.type.*;
import mindustry.ui.*;
import mindustry.world.meta.*;
import static mindustry.logic.LCanvas.*;
import static mindustry.world.blocks.logic.LogicDisplay.*;
public class LStatements{
@@ -355,7 +356,7 @@ public class LStatements{
}, 2, cell -> cell.size(100, 50)));
}, Styles.logict, () -> {}).size(90, 40).color(table.color).left().padLeft(2);
table.add(" of ");
table.add(" of ").self(this::param);
field(table, target, v -> target = v);
@@ -394,7 +395,7 @@ public class LStatements{
table.defaults().left();
if(buildFrom()){
table.add(" from ");
table.add(" from ").self(this::param);
fields(table, radar, v -> radar = v);
@@ -405,7 +406,7 @@ public class LStatements{
int fi = i;
Prov<RadarTarget> get = () -> (fi == 0 ? target1 : fi == 1 ? target2 : target3);
table.add(i == 0 ? " target " : " and ");
table.add(i == 0 ? " target " : " and ").self(this::param);
table.button(b -> {
b.label(() -> get.get().name());
@@ -419,13 +420,13 @@ public class LStatements{
}
}
table.add(" order ");
table.add(" order ").self(this::param);
fields(table, sortOrder, v -> sortOrder = v);
table.row();
table.add(" sort ");
table.add(" sort ").self(this::param);
table.button(b -> {
b.label(() -> sort.name());
@@ -434,7 +435,7 @@ public class LStatements{
}, 2, cell -> cell.size(100, 50)));
}, Styles.logict, () -> {}).size(90, 40).color(table.color).left().padLeft(2);
table.add(" output ");
table.add(" output ").self(this::param);
fields(table, output, v -> output = v);
}
@@ -511,7 +512,7 @@ public class LStatements{
i.button(sensor.name(), Styles.cleart, () -> {
stype("@" + sensor.name());
hide.run();
}).size(240f, 40f).row();
}).size(240f, 40f).self(c -> tooltip(c, "lenum." + sensor.name())).row();
}
})
};
@@ -538,7 +539,7 @@ public class LStatements{
}));
}, Styles.logict, () -> {}).size(40f).padLeft(-1).color(table.color);
table.add(" in ");
table.add(" in ").self(this::param);
field(table, from, str -> from = str);
}
@@ -900,7 +901,7 @@ public class LStatements{
void rebuild(Table table){
table.clearChildren();
table.add(" find ").left();
table.add(" find ").left().self(this::param);;
table.button(b -> {
b.label(() -> locate.name());
@@ -913,14 +914,14 @@ public class LStatements{
switch(locate){
case building -> {
row(table);
table.add(" type ").left();
table.add(" group ").left().self(this::param);;
table.button(b -> {
b.label(() -> flag.name());
b.clicked(() -> showSelect(b, BlockFlag.all, flag, t -> flag = t, 2, cell -> cell.size(110, 50)));
}, Styles.logict, () -> {}).size(110, 40).color(table.color).left().padLeft(2);
row(table);
table.add(" enemy ").left();
table.add(" enemy ").left().self(this::param);;
fields(table, enemy, str -> enemy = str);
@@ -928,7 +929,7 @@ public class LStatements{
}
case ore -> {
table.add(" ore ").left();
table.add(" ore ").left().self(this::param);
table.table(ts -> {
ts.color.set(table.color);
@@ -965,19 +966,19 @@ public class LStatements{
}
}
table.add(" outX ").left();
table.add(" outX ").left().self(this::param);
fields(table, outX, str -> outX = str);
table.add(" outY ").left();
table.add(" outY ").left().self(this::param);
fields(table, outY, str -> outY = str);
row(table);
table.add(" found ").left();
table.add(" found ").left().self(this::param);
fields(table, outFound, str -> outFound = str);
if(locate != LLocate.ore){
table.add(" building ").left();
table.add(" building ").left().self(this::param);
fields(table, outBuild, str -> outBuild = str);
}

View File

@@ -10,6 +10,7 @@ import mindustry.ui.*;
import mindustry.ui.dialogs.*;
import static mindustry.Vars.*;
import static mindustry.logic.LCanvas.*;
public class LogicDialog extends BaseDialog{
public LCanvas canvas;
@@ -72,7 +73,7 @@ public class LogicDialog extends BaseDialog{
t.button(example.name(), style, () -> {
canvas.add(prov.get());
dialog.hide();
}).size(140f, 50f);
}).size(140f, 50f).self(c -> tooltip(c, "lst." + example.name()));
if(++i % 2 == 0) t.row();
}
});

View File

@@ -320,6 +320,7 @@ public class SettingsMenuDialog extends SettingsDialog{
game.checkPref("blockreplace", true);
game.checkPref("conveyorpathfinding", true);
game.checkPref("hints", true);
game.checkPref("logichints", true);
if(!mobile){
game.checkPref("backgroundpause", true);