Add drawing layers to markers
This commit is contained in:
@@ -2460,5 +2460,5 @@ lenum.within = Check if unit is near a position.
|
|||||||
lenum.boost = Start/stop boosting.
|
lenum.boost = Start/stop boosting.
|
||||||
|
|
||||||
lenum.texture = Texture name straight from game's texture atlas (using kebab-case naming style).\nSecond and third arguments are additional suffixes added using "-" separator.\nIf additional arguments are not strings, nothing is added to first string.
|
lenum.texture = Texture name straight from game's texture atlas (using kebab-case naming style).\nSecond and third arguments are additional suffixes added using "-" separator.\nIf additional arguments are not strings, nothing is added to first string.
|
||||||
lenum.textureWidth = Width of texture in tiles. Zero value scales marker width to original texture's size.
|
lenum.texturewidth = Width of texture in tiles. Zero value scales marker width to original texture's size.
|
||||||
lenum.textureHeight = Height of texture in tiles. Zero value scales marker height to original texture's size.
|
lenum.textureheight = Height of texture in tiles. Zero value scales marker height to original texture's size.
|
||||||
|
|||||||
@@ -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);
|
Draw.draw(Layer.overlayUI, overlays::drawTop);
|
||||||
if(state.rules.fog) Draw.draw(Layer.fogOfWar, fog::drawFog);
|
if(state.rules.fog) Draw.draw(Layer.fogOfWar, fog::drawFog);
|
||||||
Draw.draw(Layer.space, this::drawLanding);
|
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{
|
public static abstract class ObjectiveMarker{
|
||||||
/** Makes sure markers are only added once. */
|
/** Makes sure markers are only added once. */
|
||||||
public transient boolean wasAdded;
|
public transient boolean wasAdded;
|
||||||
/** Hides the marker, used by world processors */
|
/** Hides the marker, used by world processors. */
|
||||||
public boolean hidden = false;
|
protected boolean hidden = false;
|
||||||
|
/** On which z-sorting layer is marker drawn. */
|
||||||
|
protected float drawLayer = Layer.overlayUI;
|
||||||
|
|
||||||
/** Called in the overlay draw layer.*/
|
/** Called in the overlay draw layer.*/
|
||||||
public void draw(){}
|
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){
|
public void control(LMarkerControl type, double p1, double p2, double p3){
|
||||||
switch(type){
|
switch(type){
|
||||||
case toggleVisibility -> hidden = !hidden;
|
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){}
|
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
|
//in case some idiot decides to make 9999999 sides and freeze the game
|
||||||
int sides = Math.min(this.sides, 200);
|
int sides = Math.min(this.sides, 200);
|
||||||
|
|
||||||
|
Draw.z(drawLayer);
|
||||||
Lines.stroke(3f, Pal.gray);
|
Lines.stroke(3f, Pal.gray);
|
||||||
Lines.poly(pos.x, pos.y, sides, radius + 1f, rotation);
|
Lines.poly(pos.x, pos.y, sides, radius + 1f, rotation);
|
||||||
Lines.stroke(1f, color);
|
Lines.stroke(1f, color);
|
||||||
Lines.poly(pos.x, pos.y, sides, radius + 1f, rotation);
|
Lines.poly(pos.x, pos.y, sides, radius + 1f, rotation);
|
||||||
|
Draw.z(Layer.overlayUI);
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
|
|
||||||
if(fetchedText == null){
|
if(fetchedText == null){
|
||||||
@@ -713,7 +718,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
|||||||
// font size cannot be 0
|
// font size cannot be 0
|
||||||
if(Math.abs(fontSize) < 1e-5) return;
|
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
|
@Override
|
||||||
@@ -794,8 +799,11 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
|||||||
float rad = minimap.scale(radius * tilesize);
|
float rad = minimap.scale(radius * tilesize);
|
||||||
float fin = Interp.pow2Out.apply((Time.globalTime / 100f) % 1f);
|
float fin = Interp.pow2Out.apply((Time.globalTime / 100f) % 1f);
|
||||||
|
|
||||||
|
Draw.z(drawLayer);
|
||||||
Lines.stroke(Scl.scl((1f - fin) * stroke + 0.1f), color);
|
Lines.stroke(Scl.scl((1f - fin) * stroke + 0.1f), color);
|
||||||
Lines.circle(Tmp.v1.x, Tmp.v1.y, rad * fin);
|
Lines.circle(Tmp.v1.x, Tmp.v1.y, rad * fin);
|
||||||
|
|
||||||
|
Draw.z(Layer.overlayUI);
|
||||||
Draw.reset();
|
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
|
//in case some idiot decides to make 9999999 sides and freeze the game
|
||||||
int sides = Math.min(this.sides, 200);
|
int sides = Math.min(this.sides, 200);
|
||||||
|
|
||||||
|
Draw.z(drawLayer);
|
||||||
if(!fill){
|
if(!fill){
|
||||||
if(outline){
|
if(outline){
|
||||||
Lines.stroke(stroke + 2f, Pal.gray);
|
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);
|
Fill.poly(pos.x, pos.y, sides, radius, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Draw.z(Layer.overlayUI);
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -868,7 +878,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
|||||||
case shapeSides -> sides = (int)p1;
|
case shapeSides -> sides = (int)p1;
|
||||||
case shapeFill -> fill = (Math.abs(p1) >= 1e-5);
|
case shapeFill -> fill = (Math.abs(p1) >= 1e-5);
|
||||||
case shapeOutline -> outline = (Math.abs(p1) >= 1e-5);
|
case shapeOutline -> outline = (Math.abs(p1) >= 1e-5);
|
||||||
case setShape -> {
|
case shape -> {
|
||||||
sides = (int)p1;
|
sides = (int)p1;
|
||||||
fill = (Math.abs(p2) >= 1e-5);
|
fill = (Math.abs(p2) >= 1e-5);
|
||||||
outline = (Math.abs(p3) >= 1e-5);
|
outline = (Math.abs(p3) >= 1e-5);
|
||||||
@@ -911,7 +921,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
|||||||
fetchedText = fetchText(text);
|
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
|
@Override
|
||||||
@@ -994,6 +1004,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
|||||||
public void draw(){
|
public void draw(){
|
||||||
if(hidden) return;
|
if(hidden) return;
|
||||||
|
|
||||||
|
Draw.z(drawLayer);
|
||||||
if(outline){
|
if(outline){
|
||||||
Lines.stroke(stroke + 2f, Pal.gray);
|
Lines.stroke(stroke + 2f, Pal.gray);
|
||||||
Lines.line(pos1.x, pos1.y, pos2.x, pos2.y);
|
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(width < 1e-5) width = fetchedRegion.width * fetchedRegion.scl() * Draw.xscl;
|
||||||
if(height < 1e-5) height = fetchedRegion.height * fetchedRegion.scl() * Draw.yscl;
|
if(height < 1e-5) height = fetchedRegion.height * fetchedRegion.scl() * Draw.yscl;
|
||||||
|
|
||||||
|
Draw.z(drawLayer);
|
||||||
if(fetchedRegion.found()){
|
if(fetchedRegion.found()){
|
||||||
Draw.color(color);
|
Draw.color(color);
|
||||||
Draw.rect(fetchedRegion, pos.x, pos.y, width, height, rotation);
|
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.color(Color.white);
|
||||||
Draw.rect("error", pos.x, pos.y, width, height, rotation);
|
Draw.rect("error", pos.x, pos.y, width, height, rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Draw.z(Layer.overlayUI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
if(player.dead()) return; //dead players don't draw
|
||||||
|
|
||||||
InputHandler input = control.input;
|
InputHandler input = control.input;
|
||||||
|
|||||||
@@ -2,29 +2,30 @@ package mindustry.logic;
|
|||||||
|
|
||||||
public enum LMarkerControl{
|
public enum LMarkerControl{
|
||||||
remove,
|
remove,
|
||||||
setVisibility("true/false"),
|
visibility("true/false"),
|
||||||
toggleVisibility,
|
toggleVisibility,
|
||||||
text("text"),
|
|
||||||
flushText,
|
|
||||||
x("x"),
|
x("x"),
|
||||||
y("y"),
|
y("y"),
|
||||||
pos("x", "y"),
|
pos("x", "y"),
|
||||||
endX("x"),
|
endX("x"),
|
||||||
endY("y"),
|
endY("y"),
|
||||||
endPos("x", "y"),
|
endPos("x", "y"),
|
||||||
fontSize("size"),
|
drawLayer("layer"),
|
||||||
textHeight("height"),
|
color("color"),
|
||||||
labelBackground("true/false"),
|
|
||||||
labelOutline("true/false"),
|
|
||||||
labelFlags("background", "outline"),
|
|
||||||
radius("radius"),
|
radius("radius"),
|
||||||
stroke("stroke"),
|
stroke("stroke"),
|
||||||
rotation("rotation"),
|
rotation("rotation"),
|
||||||
shapeSides("sides"),
|
shapeSides("sides"),
|
||||||
shapeFill("true/false"),
|
shapeFill("true/false"),
|
||||||
shapeOutline("true/false"),
|
shapeOutline("true/false"),
|
||||||
setShape("sides", "fill", "outline"),
|
shape("sides", "fill", "outline"),
|
||||||
color("color"),
|
text("text"),
|
||||||
|
flushText,
|
||||||
|
fontSize("size"),
|
||||||
|
textHeight("height"),
|
||||||
|
labelBackground("true/false"),
|
||||||
|
labelOutline("true/false"),
|
||||||
|
labelFlags("background", "outline"),
|
||||||
texture("name", "-", "-"),
|
texture("name", "-", "-"),
|
||||||
textureWidth("width"),
|
textureWidth("width"),
|
||||||
textureHeight("height");
|
textureHeight("height");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package mindustry.logic;
|
|||||||
|
|
||||||
import arc.*;
|
import arc.*;
|
||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
|
import arc.graphics.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.scene.*;
|
import arc.scene.*;
|
||||||
import arc.scene.actions.*;
|
import arc.scene.actions.*;
|
||||||
@@ -10,10 +11,12 @@ import arc.scene.ui.layout.*;
|
|||||||
import arc.struct.*;
|
import arc.struct.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
|
import mindustry.graphics.*;
|
||||||
import mindustry.logic.LCanvas.*;
|
import mindustry.logic.LCanvas.*;
|
||||||
import mindustry.logic.LExecutor.*;
|
import mindustry.logic.LExecutor.*;
|
||||||
import mindustry.ui.*;
|
import mindustry.ui.*;
|
||||||
|
|
||||||
|
import static mindustry.Vars.ui;
|
||||||
import static mindustry.logic.LCanvas.*;
|
import static mindustry.logic.LCanvas.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,6 +123,23 @@ public abstract class LStatement{
|
|||||||
return result[0];
|
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){
|
protected Cell<TextField> fields(Table table, String value, Cons<String> setter){
|
||||||
return field(table, value, setter).width(85f);
|
return field(table, value, setter).width(85f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,6 +174,10 @@ public class LStatements{
|
|||||||
}
|
}
|
||||||
case col -> {
|
case col -> {
|
||||||
fields(s, "color", x, v -> x = v).width(144f);
|
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 -> {
|
case stroke -> {
|
||||||
s.add().width(4);
|
s.add().width(4);
|
||||||
@@ -1554,22 +1558,10 @@ public class LStatements{
|
|||||||
if(entry.color){
|
if(entry.color){
|
||||||
fields(table, "color", color, str -> color = str).width(120f);
|
fields(table, "color", color, str -> color = str).width(120f);
|
||||||
|
|
||||||
table.button(b -> {
|
col(table, color, res -> {
|
||||||
b.image(Icon.pencilSmall);
|
color = "%" + res.toString().substring(0, res.a >= 1f ? 6 : 8);
|
||||||
b.clicked(() -> {
|
build(table);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
row(table);
|
row(table);
|
||||||
@@ -1959,6 +1951,30 @@ public class LStatements{
|
|||||||
t.setColor(table.color);
|
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);
|
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);
|
if(i == 0) row(table);
|
||||||
|
|||||||
Reference in New Issue
Block a user