Add drawing layers to markers
This commit is contained in:
@@ -371,6 +371,15 @@ public class Renderer implements ApplicationListener{
|
||||
});
|
||||
}
|
||||
|
||||
//draw objective markers
|
||||
state.rules.objectives.eachRunning(obj -> {
|
||||
for(var marker : obj.markers) marker.draw();
|
||||
});
|
||||
|
||||
for(var marker : state.markers.values()){
|
||||
if(marker != null) marker.draw();
|
||||
}
|
||||
|
||||
Draw.draw(Layer.overlayUI, overlays::drawTop);
|
||||
if(state.rules.fog) Draw.draw(Layer.fogOfWar, fog::drawFog);
|
||||
Draw.draw(Layer.space, this::drawLanding);
|
||||
|
||||
@@ -609,12 +609,14 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
}
|
||||
}
|
||||
|
||||
/** Marker used for drawing UI to indicate something along with an objective. */
|
||||
/** Marker used for drawing various content to indicate something along with an objective. Mostly used as UI overlay. */
|
||||
public static abstract class ObjectiveMarker{
|
||||
/** Makes sure markers are only added once. */
|
||||
public transient boolean wasAdded;
|
||||
/** Hides the marker, used by world processors */
|
||||
public boolean hidden = false;
|
||||
/** Hides the marker, used by world processors. */
|
||||
protected boolean hidden = false;
|
||||
/** On which z-sorting layer is marker drawn. */
|
||||
protected float drawLayer = Layer.overlayUI;
|
||||
|
||||
/** Called in the overlay draw layer.*/
|
||||
public void draw(){}
|
||||
@@ -628,7 +630,8 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
public void control(LMarkerControl type, double p1, double p2, double p3){
|
||||
switch(type){
|
||||
case toggleVisibility -> hidden = !hidden;
|
||||
case setVisibility -> hidden = ((Math.abs(p1) < 1e-5));
|
||||
case visibility -> hidden = ((Math.abs(p1) < 1e-5));
|
||||
case drawLayer -> drawLayer = (float)p1;
|
||||
}
|
||||
}
|
||||
public void setText(String text, boolean fetch){}
|
||||
@@ -700,10 +703,12 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
//in case some idiot decides to make 9999999 sides and freeze the game
|
||||
int sides = Math.min(this.sides, 200);
|
||||
|
||||
Draw.z(drawLayer);
|
||||
Lines.stroke(3f, Pal.gray);
|
||||
Lines.poly(pos.x, pos.y, sides, radius + 1f, rotation);
|
||||
Lines.stroke(1f, color);
|
||||
Lines.poly(pos.x, pos.y, sides, radius + 1f, rotation);
|
||||
Draw.z(Layer.overlayUI);
|
||||
Draw.reset();
|
||||
|
||||
if(fetchedText == null){
|
||||
@@ -713,7 +718,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
// font size cannot be 0
|
||||
if(Math.abs(fontSize) < 1e-5) return;
|
||||
|
||||
WorldLabel.drawAt(fetchedText, pos.x, pos.y + radius + textHeight, Draw.z(), flags, fontSize);
|
||||
WorldLabel.drawAt(fetchedText, pos.x, pos.y + radius + textHeight, drawLayer, flags, fontSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -794,8 +799,11 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
float rad = minimap.scale(radius * tilesize);
|
||||
float fin = Interp.pow2Out.apply((Time.globalTime / 100f) % 1f);
|
||||
|
||||
Draw.z(drawLayer);
|
||||
Lines.stroke(Scl.scl((1f - fin) * stroke + 0.1f), color);
|
||||
Lines.circle(Tmp.v1.x, Tmp.v1.y, rad * fin);
|
||||
|
||||
Draw.z(Layer.overlayUI);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@@ -840,6 +848,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
//in case some idiot decides to make 9999999 sides and freeze the game
|
||||
int sides = Math.min(this.sides, 200);
|
||||
|
||||
Draw.z(drawLayer);
|
||||
if(!fill){
|
||||
if(outline){
|
||||
Lines.stroke(stroke + 2f, Pal.gray);
|
||||
@@ -853,6 +862,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
Fill.poly(pos.x, pos.y, sides, radius, rotation);
|
||||
}
|
||||
|
||||
Draw.z(Layer.overlayUI);
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@@ -868,7 +878,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
case shapeSides -> sides = (int)p1;
|
||||
case shapeFill -> fill = (Math.abs(p1) >= 1e-5);
|
||||
case shapeOutline -> outline = (Math.abs(p1) >= 1e-5);
|
||||
case setShape -> {
|
||||
case shape -> {
|
||||
sides = (int)p1;
|
||||
fill = (Math.abs(p2) >= 1e-5);
|
||||
outline = (Math.abs(p3) >= 1e-5);
|
||||
@@ -911,7 +921,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
fetchedText = fetchText(text);
|
||||
}
|
||||
|
||||
WorldLabel.drawAt(fetchedText, pos.x, pos.y, Draw.z(), flags, fontSize);
|
||||
WorldLabel.drawAt(fetchedText, pos.x, pos.y, drawLayer, flags, fontSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -994,6 +1004,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
public void draw(){
|
||||
if(hidden) return;
|
||||
|
||||
Draw.z(drawLayer);
|
||||
if(outline){
|
||||
Lines.stroke(stroke + 2f, Pal.gray);
|
||||
Lines.line(pos1.x, pos1.y, pos2.x, pos2.y);
|
||||
@@ -1047,6 +1058,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
if(width < 1e-5) width = fetchedRegion.width * fetchedRegion.scl() * Draw.xscl;
|
||||
if(height < 1e-5) height = fetchedRegion.height * fetchedRegion.scl() * Draw.yscl;
|
||||
|
||||
Draw.z(drawLayer);
|
||||
if(fetchedRegion.found()){
|
||||
Draw.color(color);
|
||||
Draw.rect(fetchedRegion, pos.x, pos.y, width, height, rotation);
|
||||
@@ -1054,6 +1066,8 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
Draw.color(Color.white);
|
||||
Draw.rect("error", pos.x, pos.y, width, height, rotation);
|
||||
}
|
||||
|
||||
Draw.z(Layer.overlayUI);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -113,15 +113,6 @@ public class OverlayRenderer{
|
||||
}
|
||||
}
|
||||
|
||||
//draw objective markers
|
||||
state.rules.objectives.eachRunning(obj -> {
|
||||
for(var marker : obj.markers) marker.draw();
|
||||
});
|
||||
|
||||
for(var marker : state.markers.values()){
|
||||
if(marker != null) marker.draw();
|
||||
}
|
||||
|
||||
if(player.dead()) return; //dead players don't draw
|
||||
|
||||
InputHandler input = control.input;
|
||||
|
||||
@@ -2,29 +2,30 @@ package mindustry.logic;
|
||||
|
||||
public enum LMarkerControl{
|
||||
remove,
|
||||
setVisibility("true/false"),
|
||||
visibility("true/false"),
|
||||
toggleVisibility,
|
||||
text("text"),
|
||||
flushText,
|
||||
x("x"),
|
||||
y("y"),
|
||||
pos("x", "y"),
|
||||
endX("x"),
|
||||
endY("y"),
|
||||
endPos("x", "y"),
|
||||
fontSize("size"),
|
||||
textHeight("height"),
|
||||
labelBackground("true/false"),
|
||||
labelOutline("true/false"),
|
||||
labelFlags("background", "outline"),
|
||||
drawLayer("layer"),
|
||||
color("color"),
|
||||
radius("radius"),
|
||||
stroke("stroke"),
|
||||
rotation("rotation"),
|
||||
shapeSides("sides"),
|
||||
shapeFill("true/false"),
|
||||
shapeOutline("true/false"),
|
||||
setShape("sides", "fill", "outline"),
|
||||
color("color"),
|
||||
shape("sides", "fill", "outline"),
|
||||
text("text"),
|
||||
flushText,
|
||||
fontSize("size"),
|
||||
textHeight("height"),
|
||||
labelBackground("true/false"),
|
||||
labelOutline("true/false"),
|
||||
labelFlags("background", "outline"),
|
||||
texture("name", "-", "-"),
|
||||
textureWidth("width"),
|
||||
textureHeight("height");
|
||||
|
||||
@@ -2,6 +2,7 @@ package mindustry.logic;
|
||||
|
||||
import arc.*;
|
||||
import arc.func.*;
|
||||
import arc.graphics.*;
|
||||
import arc.math.*;
|
||||
import arc.scene.*;
|
||||
import arc.scene.actions.*;
|
||||
@@ -10,10 +11,12 @@ import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.logic.LCanvas.*;
|
||||
import mindustry.logic.LExecutor.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
import static mindustry.Vars.ui;
|
||||
import static mindustry.logic.LCanvas.*;
|
||||
|
||||
/**
|
||||
@@ -120,6 +123,23 @@ public abstract class LStatement{
|
||||
return result[0];
|
||||
}
|
||||
|
||||
/** Adds color edit button */
|
||||
protected Cell<Button> col(Table table, String value, Cons<Color> setter){
|
||||
return table.button(b -> {
|
||||
b.image(Icon.pencilSmall);
|
||||
b.clicked(() -> {
|
||||
Color current = Pal.accent.cpy();
|
||||
if(value.startsWith("%")){
|
||||
try{
|
||||
current = Color.valueOf(value.substring(1));
|
||||
}catch(Exception ignored){}
|
||||
}
|
||||
|
||||
ui.picker.show(current, setter);
|
||||
});
|
||||
}, Styles.logict, () -> {}).size(40f).padLeft(-11).color(table.color);
|
||||
}
|
||||
|
||||
protected Cell<TextField> fields(Table table, String value, Cons<String> setter){
|
||||
return field(table, value, setter).width(85f);
|
||||
}
|
||||
|
||||
@@ -174,6 +174,10 @@ public class LStatements{
|
||||
}
|
||||
case col -> {
|
||||
fields(s, "color", x, v -> x = v).width(144f);
|
||||
col(s, x, res -> {
|
||||
x = "%" + res.toString().substring(0, res.a >= 1f ? 6 : 8);
|
||||
build(table);
|
||||
});
|
||||
}
|
||||
case stroke -> {
|
||||
s.add().width(4);
|
||||
@@ -1554,22 +1558,10 @@ public class LStatements{
|
||||
if(entry.color){
|
||||
fields(table, "color", color, str -> color = str).width(120f);
|
||||
|
||||
table.button(b -> {
|
||||
b.image(Icon.pencilSmall);
|
||||
b.clicked(() -> {
|
||||
Color current = Pal.accent.cpy();
|
||||
if(color.startsWith("%")){
|
||||
try{
|
||||
current = Color.valueOf(color.substring(1));
|
||||
}catch(Exception ignored){}
|
||||
}
|
||||
|
||||
ui.picker.show(current, result -> {
|
||||
color = "%" + result.toString().substring(0, result.a >= 1f ? 6 : 8);
|
||||
build(table);
|
||||
});
|
||||
});
|
||||
}, Styles.logict, () -> {}).size(40f).padLeft(-11).color(table.color);
|
||||
col(table, color, res -> {
|
||||
color = "%" + res.toString().substring(0, res.a >= 1f ? 6 : 8);
|
||||
build(table);
|
||||
});
|
||||
}
|
||||
|
||||
row(table);
|
||||
@@ -1959,6 +1951,30 @@ public class LStatements{
|
||||
t.setColor(table.color);
|
||||
|
||||
fields(t, type.params[i], i == 0 ? p1 : i == 1 ? p2 : p3, i == 0 ? v -> p1 = v : i == 1 ? v -> p2 = v : v -> p3 = v).width(100f);
|
||||
if(type == LMarkerControl.color){
|
||||
col(t, p1, res -> {
|
||||
p1 = "%" + res.toString().substring(0, res.a >= 1f ? 6 : 8);
|
||||
build(table);
|
||||
});
|
||||
}else if(type == LMarkerControl.drawLayer){
|
||||
t.button(b -> {
|
||||
b.image(Icon.pencilSmall);
|
||||
b.clicked(() -> showSelectTable(b, (o, hide) -> {
|
||||
o.row();
|
||||
o.table(s -> {
|
||||
s.left();
|
||||
for(var layer : Layer.class.getFields()){
|
||||
float value = Reflect.get(Layer.class, layer.getName());
|
||||
s.button(layer.getName() + " = " + value, Styles.logicTogglet, () -> {
|
||||
p1 = Float.toString(value);
|
||||
rebuild(table);
|
||||
hide.run();
|
||||
}).size(240f, 40f).row();
|
||||
}
|
||||
}).width(240f).left();
|
||||
}));
|
||||
}, Styles.logict, () -> {}).size(40f).padLeft(-2).color(table.color);
|
||||
}
|
||||
});
|
||||
|
||||
if(i == 0) row(table);
|
||||
|
||||
Reference in New Issue
Block a user