Marker autoscale now works outside of minimap mode, another yet lmarkercontrol instructions cleanup, fix renderer's draw color breaking after drawing markers

This commit is contained in:
ApsZoldat
2023-11-28 22:00:08 +03:00
parent 6ea2188bee
commit 02a53daa58
4 changed files with 81 additions and 99 deletions

View File

@@ -2462,4 +2462,4 @@ 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.
lenum.minimapautoscale = Whether to scale marker in minimap mode corresponding to player's zoom level. lenum.autoscale = Whether to scale marker corresponding to player's zoom level.

View File

@@ -380,6 +380,8 @@ public class Renderer implements ApplicationListener{
if(marker != null) marker.draw(); if(marker != null) marker.draw();
} }
Draw.reset();
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);

View File

@@ -615,8 +615,8 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public transient boolean wasAdded; public transient boolean wasAdded;
/** Whether to display marker on minimap instead of world. {@link MinimapMarker} ignores this value. */ /** Whether to display marker on minimap instead of world. {@link MinimapMarker} ignores this value. */
public boolean minimap = false; public boolean minimap = false;
/** Whether to scale marker in minimap mode corresponding to player's zoom level. {@link MinimapMarker} ignores this value. */ /** Whether to scale marker corresponding to player's zoom level. {@link MinimapMarker} ignores this value. */
public boolean minimapAutoscale = false; public boolean autoscale = false;
/** Hides the marker, used by world processors. */ /** Hides the marker, used by world processors. */
protected boolean hidden = false; protected boolean hidden = false;
/** On which z-sorting layer is marker drawn. */ /** On which z-sorting layer is marker drawn. */
@@ -633,10 +633,10 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
/** Control marker with world processor code*/ /** Control marker with world processor code*/
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 visibility -> hidden = (Math.abs(p1) < 1e-5); case visibility -> hidden = Mathf.equal((float)p1, 0f);
case drawLayer -> drawLayer = (float)p1; case drawLayer -> drawLayer = (float)p1;
case minimap -> minimap = (Math.abs(p1) >= 1e-5); case minimap -> minimap = !Mathf.equal((float)p1, 0f);
case minimapAutoscale -> minimapAutoscale = (Math.abs(p1) >= 1e-5); case autoscale -> autoscale = !Mathf.equal((float)p1, 0f);
} }
} }
public void setText(String text, boolean fetch){} public void setText(String text, boolean fetch){}
@@ -708,11 +708,13 @@ 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);
float scl = autoscale ? 4f / renderer.getDisplayScale() : 1f;
Draw.z(drawLayer); Draw.z(drawLayer);
Lines.stroke(3f, Pal.gray); Lines.stroke(3f * scl, Pal.gray);
Lines.poly(pos.x, pos.y, sides, radius + 1f, rotation); Lines.poly(pos.x, pos.y, sides, (radius + 1f) * scl, rotation);
Lines.stroke(1f, color); Lines.stroke(scl, color);
Lines.poly(pos.x, pos.y, sides, radius + 1f, rotation); Lines.poly(pos.x, pos.y, sides, (radius + 1f) * scl, rotation);
Draw.reset(); Draw.reset();
if(fetchedText == null){ if(fetchedText == null){
@@ -720,9 +722,9 @@ 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(Mathf.equal(fontSize, 0f)) return;
WorldLabel.drawAt(fetchedText, pos.x, pos.y + radius + textHeight, drawLayer, flags, fontSize); WorldLabel.drawAt(fetchedText, pos.x, pos.y + radius * scl + textHeight * scl, drawLayer, flags, fontSize * scl);
} }
@Override @Override
@@ -734,12 +736,12 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f)); minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f));
float rad = minimap.scale(radius, minimapAutoscale); float rad = minimap.scale(radius, autoscale);
Draw.z(drawLayer); Draw.z(drawLayer);
Lines.stroke(minimap.scale(3f, minimapAutoscale), Pal.gray); Lines.stroke(minimap.scale(3f, autoscale), Pal.gray);
Lines.poly(Tmp.v1.x, Tmp.v1.y, sides, rad + 1f, rotation); Lines.poly(Tmp.v1.x, Tmp.v1.y, sides, rad + 1f, rotation);
Lines.stroke(minimap.scale(1f, minimapAutoscale), color); Lines.stroke(minimap.scale(1f, autoscale), color);
Lines.poly(Tmp.v1.x, Tmp.v1.y, sides, rad + 1f, rotation); Lines.poly(Tmp.v1.x, Tmp.v1.y, sides, rad + 1f, rotation);
Draw.reset(); Draw.reset();
@@ -748,9 +750,9 @@ 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(Mathf.equal(fontSize, 0f)) return;
WorldLabel.drawAt(fetchedText, Tmp.v1.x, Tmp.v1.y + rad + minimap.scale(textHeight, minimapAutoscale), drawLayer, flags, minimap.scale(fontSize, minimapAutoscale)); WorldLabel.drawAt(fetchedText, Tmp.v1.x, Tmp.v1.y + rad + minimap.scale(textHeight, autoscale), drawLayer, flags, minimap.scale(fontSize, autoscale));
} }
@Override @Override
@@ -761,23 +763,9 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize); case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize);
case fontSize -> fontSize = (float)p1; case fontSize -> fontSize = (float)p1;
case textHeight -> textHeight = (float)p1; case textHeight -> textHeight = (float)p1;
case labelBackground -> {
if((Math.abs(p1) >= 1e-5)){
flags |= WorldLabel.flagBackground;
}else{
flags &= ~WorldLabel.flagBackground;
}
}
case labelOutline -> {
if((Math.abs(p1) >= 1e-5)){
flags |= WorldLabel.flagOutline;
}else{
flags &= ~WorldLabel.flagOutline;
}
}
case labelFlags -> { case labelFlags -> {
flags = ((Math.abs(p1) >= 1e-5) ? WorldLabel.flagBackground : 0); flags = (!Mathf.equal((float)p1, 0f) ? WorldLabel.flagBackground : 0);
if((Math.abs(p2) >= 1e-5)) flags |= WorldLabel.flagOutline; if(!Mathf.equal((float)p2, 0f)) flags |= WorldLabel.flagOutline;
} }
case radius -> radius = (float)p1; case radius -> radius = (float)p1;
case rotation -> rotation = (float)p1; case rotation -> rotation = (float)p1;
@@ -828,7 +816,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
minimap.transform(Tmp.v1.set(pos.x * tilesize, pos.y * tilesize)); minimap.transform(Tmp.v1.set(pos.x * tilesize, pos.y * tilesize));
float rad = minimap.scale(radius * tilesize); float rad = minimap.scale(radius * tilesize, autoscale);
float fin = Interp.pow2Out.apply((Time.globalTime / 100f) % 1f); float fin = Interp.pow2Out.apply((Time.globalTime / 100f) % 1f);
Draw.z(drawLayer); Draw.z(drawLayer);
@@ -879,18 +867,20 @@ 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);
float scl = autoscale ? 4f / renderer.getDisplayScale() : 1f;
Draw.z(drawLayer); Draw.z(drawLayer);
if(!fill){ if(!fill){
if(outline){ if(outline){
Lines.stroke(stroke + 2f, Pal.gray); Lines.stroke((stroke + 2f) * scl, Pal.gray);
Lines.poly(pos.x, pos.y, sides, radius + 1f, rotation); Lines.poly(pos.x, pos.y, sides, (radius + 1f) * scl, rotation);
} }
Lines.stroke(stroke, color); Lines.stroke(stroke * scl, color);
Lines.poly(pos.x, pos.y, sides, radius + 1f, rotation); Lines.poly(pos.x, pos.y, sides, (radius + 1f) * scl, rotation);
}else{ }else{
Draw.color(color); Draw.color(color);
Fill.poly(pos.x, pos.y, sides, radius, rotation); Fill.poly(pos.x, pos.y, sides, radius * scl, rotation);
} }
Draw.reset(); Draw.reset();
@@ -905,20 +895,20 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f)); minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f));
float rad = minimap.scale(radius, minimapAutoscale); float rad = minimap.scale(radius, autoscale);
Draw.z(drawLayer); Draw.z(drawLayer);
if(!fill){ if(!fill){
if(outline){ if(outline){
Lines.stroke(minimap.scale(stroke + 2f, minimapAutoscale), Pal.gray); Lines.stroke(minimap.scale(stroke + 2f, autoscale), Pal.gray);
Lines.poly(Tmp.v1.x, Tmp.v1.y, sides, minimap.scale(radius + 1f, minimapAutoscale), rotation); Lines.poly(Tmp.v1.x, Tmp.v1.y, sides, minimap.scale(radius + 1f, autoscale), rotation);
} }
Lines.stroke(stroke, color); Lines.stroke(stroke, color);
Lines.poly(Tmp.v1.x, Tmp.v1.y, sides, minimap.scale(radius + 1f, minimapAutoscale), rotation); Lines.poly(Tmp.v1.x, Tmp.v1.y, sides, minimap.scale(radius + 1f, autoscale), rotation);
}else{ }else{
Draw.color(color); Draw.color(color);
Fill.poly(Tmp.v1.x, Tmp.v1.y, sides, minimap.scale(radius, minimapAutoscale), rotation); Fill.poly(Tmp.v1.x, Tmp.v1.y, sides, minimap.scale(radius, autoscale), rotation);
} }
Draw.reset(); Draw.reset();
@@ -934,12 +924,12 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
case rotation -> rotation = (float)p1; case rotation -> rotation = (float)p1;
case stroke -> stroke = (float)p1; case stroke -> stroke = (float)p1;
case shapeSides -> sides = (int)p1; case shapeSides -> sides = (int)p1;
case shapeFill -> fill = (Math.abs(p1) >= 1e-5); case shapeFill -> fill = !Mathf.equal((float)p1, 0f);
case shapeOutline -> outline = (Math.abs(p1) >= 1e-5); case shapeOutline -> outline = !Mathf.equal((float)p1, 0f);
case shape -> { case shape -> {
sides = (int)p1; sides = (int)p1;
fill = (Math.abs(p2) >= 1e-5); fill = !Mathf.equal((float)p2, 0f);
outline = (Math.abs(p3) >= 1e-5); outline = !Mathf.equal((float)p3, 0f);
} }
case color -> color.set(Tmp.c1.fromDouble(p1)); case color -> color.set(Tmp.c1.fromDouble(p1));
default -> super.control(type, p1, p2, p3); default -> super.control(type, p1, p2, p3);
@@ -973,23 +963,25 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
@Override @Override
public void draw(){ public void draw(){
// font size cannot be 0 // font size cannot be 0
if(hidden || Math.abs(fontSize) < 1e-5 || minimap) return; if(hidden || Mathf.equal(fontSize, 0f) || minimap) return;
if(fetchedText == null){ if(fetchedText == null){
fetchedText = fetchText(text); fetchedText = fetchText(text);
} }
WorldLabel.drawAt(fetchedText, pos.x, pos.y, drawLayer, flags, fontSize); float scl = autoscale ? 4f / renderer.getScale() : 1f;
WorldLabel.drawAt(fetchedText, pos.x, pos.y, drawLayer, flags, fontSize * scl);
} }
@Override @Override
public void drawMinimap(MinimapRenderer minimap){ public void drawMinimap(MinimapRenderer minimap){
if(hidden || !this.minimap) return; if(hidden || !this.minimap) return;
float size = minimap.scale(fontSize, minimapAutoscale); float size = minimap.scale(fontSize, autoscale);
// font size cannot be 0 // font size cannot be 0
if(Math.abs(fontSize) < 1e-5) return; if(Mathf.equal(fontSize, 0f)) return;
minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f)); minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f));
@@ -1007,23 +999,9 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
case y -> pos.y = (float)p1 * tilesize; case y -> pos.y = (float)p1 * tilesize;
case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize); case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize);
case fontSize -> fontSize = (float)p1; case fontSize -> fontSize = (float)p1;
case labelBackground -> {
if((Math.abs(p1) >= 1e-5)){
flags |= WorldLabel.flagBackground;
}else{
flags &= ~WorldLabel.flagBackground;
}
}
case labelOutline -> {
if((Math.abs(p1) >= 1e-5)){
flags |= WorldLabel.flagOutline;
}else{
flags &= ~WorldLabel.flagOutline;
}
}
case labelFlags -> { case labelFlags -> {
flags = ((Math.abs(p1) >= 1e-5) ? WorldLabel.flagBackground : 0); flags = (!Mathf.equal((float)p1, 0f) ? WorldLabel.flagBackground : 0);
if((Math.abs(p2) >= 1e-5)) flags |= WorldLabel.flagOutline; if(!Mathf.equal((float)p2, 0f)) flags |= WorldLabel.flagOutline;
} }
default -> super.control(type, p1, p2, p3); default -> super.control(type, p1, p2, p3);
} }
@@ -1060,33 +1038,19 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public LineMarker(){} public LineMarker(){}
@Override
public void control(LMarkerControl type, double p1, double p2, double p3){
switch(type){
case x -> pos1.x = (float)p1 * tilesize;
case y -> pos1.y = (float)p1 * tilesize;
case pos -> pos1.set((float)p1 * tilesize, (float)p2 * tilesize);
case endX -> pos2.x = (float)p1 * tilesize;
case endY -> pos2.y = (float)p1 * tilesize;
case endPos -> pos2.set((float)p1 * tilesize, (float)p2 * tilesize);
case stroke -> stroke = (float)p1;
case shapeOutline -> outline = ((Math.abs(p1) >= 1e-5));
case color -> color.set(Tmp.c1.fromDouble(p1));
default -> super.control(type, p1, p2, p3);
}
}
@Override @Override
public void draw(){ public void draw(){
if(hidden || minimap) return; if(hidden || minimap) return;
float scl = autoscale ? 4f / renderer.getDisplayScale() : 1f;
Draw.z(drawLayer); Draw.z(drawLayer);
if(outline){ if(outline){
Lines.stroke(stroke + 2f, Pal.gray); Lines.stroke((stroke + 2f) * scl, Pal.gray);
Lines.line(pos1.x, pos1.y, pos2.x, pos2.y); Lines.line(pos1.x, pos1.y, pos2.x, pos2.y);
} }
Lines.stroke(stroke, color); Lines.stroke(stroke * scl, color);
Lines.line(pos1.x, pos1.y, pos2.x, pos2.y); Lines.line(pos1.x, pos1.y, pos2.x, pos2.y);
} }
@@ -1099,13 +1063,29 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
Draw.z(drawLayer); Draw.z(drawLayer);
if(outline){ if(outline){
Lines.stroke(minimap.scale(stroke + 2f, minimapAutoscale), Pal.gray); Lines.stroke(minimap.scale(stroke + 2f, autoscale), Pal.gray);
Lines.line(Tmp.v1.x, Tmp.v1.y, Tmp.v2.x, Tmp.v2.y); Lines.line(Tmp.v1.x, Tmp.v1.y, Tmp.v2.x, Tmp.v2.y);
} }
Lines.stroke(minimap.scale(stroke, minimapAutoscale), color); Lines.stroke(minimap.scale(stroke, autoscale), color);
Lines.line(Tmp.v1.x, Tmp.v1.y, Tmp.v2.x, Tmp.v2.y); Lines.line(Tmp.v1.x, Tmp.v1.y, Tmp.v2.x, Tmp.v2.y);
} }
@Override
public void control(LMarkerControl type, double p1, double p2, double p3){
switch(type){
case x -> pos1.x = (float)p1 * tilesize;
case y -> pos1.y = (float)p1 * tilesize;
case pos -> pos1.set((float)p1 * tilesize, (float)p2 * tilesize);
case endX -> pos2.x = (float)p1 * tilesize;
case endY -> pos2.y = (float)p1 * tilesize;
case endPos -> pos2.set((float)p1 * tilesize, (float)p2 * tilesize);
case stroke -> stroke = (float)p1;
case shapeOutline -> outline = !Mathf.equal((float)p1, 0f);
case color -> color.set(Tmp.c1.fromDouble(p1));
default -> super.control(type, p1, p2, p3);
}
}
} }
/** Displays a texture with specified name. */ /** Displays a texture with specified name. */
@@ -1149,16 +1129,18 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
if(fetchedRegion == null) fetchedRegion = Core.atlas.find(textureName); if(fetchedRegion == null) fetchedRegion = Core.atlas.find(textureName);
// Zero width/height scales marker to original texture's size // Zero width/height scales marker to original texture's size
if(width < 1e-5) width = fetchedRegion.width * fetchedRegion.scl() * Draw.xscl; if(Mathf.equal(width, 0f)) width = fetchedRegion.width * fetchedRegion.scl() * Draw.xscl;
if(height < 1e-5) height = fetchedRegion.height * fetchedRegion.scl() * Draw.yscl; if(Mathf.equal(height, 0f)) height = fetchedRegion.height * fetchedRegion.scl() * Draw.yscl;
float scl = autoscale ? 4f / renderer.getDisplayScale() : 1f;
Draw.z(drawLayer); 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 * scl, height * scl, rotation);
}else{ }else{
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 * scl, height * scl, rotation);
} }
} }
@@ -1169,18 +1151,18 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
if(fetchedRegion == null) fetchedRegion = Core.atlas.find(textureName); if(fetchedRegion == null) fetchedRegion = Core.atlas.find(textureName);
// Zero width/height scales marker to original texture's size // Zero width/height scales marker to original texture's size
if(width < 1e-5) width = fetchedRegion.width * fetchedRegion.scl() * Draw.xscl; if(Mathf.equal(width, 0f)) width = fetchedRegion.width * fetchedRegion.scl() * Draw.xscl;
if(height < 1e-5) height = fetchedRegion.height * fetchedRegion.scl() * Draw.yscl; if(Mathf.equal(height, 0f)) height = fetchedRegion.height * fetchedRegion.scl() * Draw.yscl;
minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f)); minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f));
Draw.z(drawLayer); Draw.z(drawLayer);
if(fetchedRegion.found()){ if(fetchedRegion.found()){
Draw.color(color); Draw.color(color);
Draw.rect(fetchedRegion, Tmp.v1.x, Tmp.v1.y, minimap.scale(width, minimapAutoscale), minimap.scale(height, minimapAutoscale), rotation); Draw.rect(fetchedRegion, Tmp.v1.x, Tmp.v1.y, minimap.scale(width, autoscale), minimap.scale(height, autoscale), rotation);
}else{ }else{
Draw.color(Color.white); Draw.color(Color.white);
Draw.rect("error", Tmp.v1.x, Tmp.v1.y, minimap.scale(width, minimapAutoscale), minimap.scale(height, minimapAutoscale), rotation); Draw.rect("error", Tmp.v1.x, Tmp.v1.y, minimap.scale(width, autoscale), minimap.scale(height, autoscale), rotation);
} }
} }

View File

@@ -4,7 +4,7 @@ public enum LMarkerControl{
remove, remove,
visibility("true/false"), visibility("true/false"),
minimap("true/false"), minimap("true/false"),
minimapAutoscale("true/false"), autoscale("true/false"),
x("x"), x("x"),
y("y"), y("y"),
pos("x", "y"), pos("x", "y"),
@@ -24,8 +24,6 @@ public enum LMarkerControl{
flushText, flushText,
fontSize("size"), fontSize("size"),
textHeight("height"), textHeight("height"),
labelBackground("true/false"),
labelOutline("true/false"),
labelFlags("background", "outline"), labelFlags("background", "outline"),
texture("name", "-", "-"), texture("name", "-", "-"),
textureWidth("width"), textureWidth("width"),