Logic tooltips on mobile devices w/ long-press

This commit is contained in:
Anuken
2021-02-19 17:18:17 -05:00
parent fa7697fc40
commit f043a5f340
4 changed files with 42 additions and 1 deletions

View File

@@ -1312,6 +1312,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
return switch(sensor){
case x -> World.conv(x);
case y -> World.conv(y);
//case dead -> !isValid(); //TODO 126
case team -> team.id;
case health -> health;
case maxHealth -> maxHealth;

View File

@@ -128,6 +128,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
case ammoCapacity -> type.ammoCapacity;
case x -> World.conv(x);
case y -> World.conv(y);
//case dead -> dead || !isAdded(); //TODO 126
case team -> team.id;
case shooting -> isShooting() ? 1 : 0;
case range -> range() / tilesize;

View File

@@ -27,6 +27,7 @@ public enum LAccess{
y,
shootX,
shootY,
//dead, //TODO 126
range,
shooting,
mineX,

View File

@@ -13,6 +13,7 @@ import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import mindustry.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.ui.*;
@@ -29,10 +30,26 @@ public class LCanvas extends Table{
StatementElem hovered;
float targetWidth;
int jumpCount = 0;
Seq<Tooltip> tooltips = new Seq<>();
public LCanvas(){
canvas = this;
Core.scene.addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCode button){
//hide tooltips on tap
for(var t : tooltips){
t.container.toFront();
}
Core.app.post(() -> {
tooltips.each(Tooltip::hide);
tooltips.clear();
});
return super.touchDown(event, x, y, pointer, button);
}
});
rebuild();
}
@@ -44,7 +61,28 @@ public class LCanvas extends Table{
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)));
var tip = new Tooltip(t -> t.background(Styles.black8).margin(4f).add("[lightgray]" + Core.bundle.get(lkey)).style(Styles.outlineLabel));
//mobile devices need long-press tooltips
if(Vars.mobile){
cell.get().addListener(new ElementGestureListener(20, 0.4f, 0.43f, 0.15f){
@Override
public boolean longPress(Element element, float x, float y){
tip.show(element, x, y);
canvas.tooltips.add(tip);
//prevent touch down for other listeners
for(var list : cell.get().getListeners()){
if(list instanceof ClickListener cl){
cl.cancel();
}
}
return true;
}
});
}else{
cell.get().addListener(tip);
}
}
}