Markers draw code refactor, minor text marker control changes

This commit is contained in:
ApsZoldat
2023-12-12 22:40:33 +03:00
parent 4802076bf8
commit 5830259e41
6 changed files with 81 additions and 154 deletions
+1 -1
View File
@@ -2480,7 +2480,7 @@ lenum.getblock = Fetch a building, floor and type at coordinates.\nUnit must be
lenum.within = Check if unit is near a position. lenum.within = Check if unit is near a position.
lenum.boost = Start/stop boosting. lenum.boost = Start/stop boosting.
lenum.text = Set marker text, if applicable to marker's type.\nIf printFlush is set to true, consumes text buffer content as text argument.\nIf fetch is set to true, tries to fetch properties from map locale bundle or game's bundle. lenum.flushtext = Flush print buffer's content to marker, if applicable.\nIf fetch is set to true, tries to fetch properties from map locale bundle or game's bundle.
lenum.texture = Texture name straight from game's texture atlas (using kebab-case naming style).\nIf printFlush is set to true, consumes text buffer content as text argument. lenum.texture = Texture name straight from game's texture atlas (using kebab-case naming style).\nIf printFlush is set to true, consumes text buffer content as text argument.
lenum.texturesize = Size of texture in tiles. Zero value scales marker width to original texture's size. lenum.texturesize = Size of texture in tiles. Zero value scales marker width to original texture's size.
lenum.autoscale = Whether to scale marker corresponding to player's zoom level. lenum.autoscale = Whether to scale marker corresponding to player's zoom level.
+69 -140
View File
@@ -637,8 +637,9 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
protected boolean hidden = false; protected boolean hidden = false;
/** On which z-sorting layer is marker drawn. */ /** On which z-sorting layer is marker drawn. */
protected float drawLayer = Layer.overlayUI; protected float drawLayer = Layer.overlayUI;
/** Draws the marker. Actual marker position and scale are calculated in {@link #drawWorld()} and {@link #drawMinimap(MinimapRenderer)}. */
/** Called in the main renderer */ public void baseDraw(float x, float y, float scaleFactor){}
/** Called in the main renderer. */
public void drawWorld(){} public void drawWorld(){}
/** Called in the small and large map. */ /** Called in the small and large map. */
public void drawMinimap(MinimapRenderer minimap){} public void drawMinimap(MinimapRenderer minimap){}
@@ -734,19 +735,15 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public ShapeTextMarker(){} public ShapeTextMarker(){}
@Override @Override
public void drawWorld(){ public void baseDraw(float x, float y, float scaleFactor){
if(hidden || minimap) return;
//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 * scl, Pal.gray); Lines.stroke(3f * scaleFactor, Pal.gray);
Lines.poly(pos.x, pos.y, sides, (radius + 1f) * scl, rotation); Lines.poly(x, y, sides, (radius + 1f) * scaleFactor, rotation);
Lines.stroke(scl, color); Lines.stroke(scaleFactor, color);
Lines.poly(pos.x, pos.y, sides, (radius + 1f) * scl, rotation); Lines.poly(x, y, sides, (radius + 1f) * scaleFactor, rotation);
Draw.reset(); Draw.reset();
if(fetchedText == null){ if(fetchedText == null){
@@ -756,35 +753,18 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
// font size cannot be 0 // font size cannot be 0
if(Mathf.equal(fontSize, 0f)) return; if(Mathf.equal(fontSize, 0f)) return;
WorldLabel.drawAt(fetchedText, pos.x, pos.y + radius * scl + textHeight * scl, drawLayer, flags, fontSize * scl); WorldLabel.drawAt(fetchedText, x, y + radius * scaleFactor + textHeight * scaleFactor, drawLayer, flags, fontSize * scaleFactor);
}
@Override
public void drawWorld(){
baseDraw(pos.x, pos.y, autoscale ? 4f / renderer.getDisplayScale() : 1f);
} }
@Override @Override
public void drawMinimap(MinimapRenderer minimap){ public void drawMinimap(MinimapRenderer minimap){
if(hidden || !this.minimap) return;
//in case some idiot decides to make 9999999 sides and freeze the game
int sides = Math.min(this.sides, 200);
minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f)); minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f));
baseDraw(Tmp.v1.x, Tmp.v1.y, minimap.getScaleFactor(autoscale));
float rad = minimap.scale(radius, autoscale);
Draw.z(drawLayer);
Lines.stroke(minimap.scale(3f, autoscale), Pal.gray);
Lines.poly(Tmp.v1.x, Tmp.v1.y, sides, rad + 1f, rotation);
Lines.stroke(minimap.scale(1f, autoscale), color);
Lines.poly(Tmp.v1.x, Tmp.v1.y, sides, rad + 1f, rotation);
Draw.reset();
if(fetchedText == null){
fetchedText = fetchText(text);
}
// font size cannot be 0
if(Mathf.equal(fontSize, 0f)) return;
WorldLabel.drawAt(fetchedText, Tmp.v1.x, Tmp.v1.y + rad + minimap.scale(textHeight, autoscale), drawLayer, flags, minimap.scale(fontSize, autoscale));
} }
@Override @Override
@@ -861,6 +841,18 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public MinimapMarker(){} public MinimapMarker(){}
@Override
public void baseDraw(float x, float y, float scaleFactor){
float rad = radius * tilesize * scaleFactor;
float fin = Interp.pow2Out.apply((Time.globalTime / 100f) % 1f);
Draw.z(drawLayer);
Lines.stroke(Scl.scl((1f - fin) * stroke + 0.1f), color);
Lines.circle(x, y, rad * fin);
Draw.reset();
}
@Override @Override
public void drawWorld(){ public void drawWorld(){
minimap = true; minimap = true;
@@ -868,18 +860,8 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
@Override @Override
public void drawMinimap(MinimapRenderer minimap){ public void drawMinimap(MinimapRenderer minimap){
if(hidden) return;
minimap.transform(Tmp.v1.set(pos.x * tilesize, pos.y * tilesize)); minimap.transform(Tmp.v1.set(pos.x * tilesize, pos.y * tilesize));
baseDraw(Tmp.v1.x, Tmp.v1.y, minimap.getScaleFactor(autoscale));
float rad = minimap.scale(radius * tilesize, autoscale);
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.reset();
} }
@Override @Override
@@ -926,57 +908,36 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public ShapeMarker(){} public ShapeMarker(){}
@Override @Override
public void drawWorld(){ public void baseDraw(float x, float y, float scaleFactor){
if(hidden || minimap) return;
//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) * scl, Pal.gray); Lines.stroke((stroke + 2f) * scaleFactor, Pal.gray);
Lines.poly(pos.x, pos.y, sides, (radius + 1f) * scl, rotation); Lines.poly(x, y, sides, (radius + 1f) * scaleFactor, rotation);
} }
Lines.stroke(stroke * scl, color); Lines.stroke(stroke * scaleFactor, color);
Lines.poly(pos.x, pos.y, sides, (radius + 1f) * scl, rotation); Lines.poly(x, y, sides, (radius + 1f) * scaleFactor, rotation);
}else{ }else{
Draw.color(color); Draw.color(color);
Fill.poly(pos.x, pos.y, sides, radius * scl, rotation); Fill.poly(x, y, sides, radius * scaleFactor, rotation);
} }
Draw.reset(); Draw.reset();
} }
@Override
public void drawWorld(){
baseDraw(pos.x, pos.y, autoscale ? 4f / renderer.getDisplayScale() : 1f);
}
@Override @Override
public void drawMinimap(MinimapRenderer minimap){ public void drawMinimap(MinimapRenderer minimap){
if(hidden || !this.minimap) return;
//in case some idiot decides to make 9999999 sides and freeze the game
int sides = Math.min(this.sides, 200);
minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f)); minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f));
baseDraw(Tmp.v1.x, Tmp.v1.y, minimap.getScaleFactor(autoscale));
float rad = minimap.scale(radius, autoscale);
Draw.z(drawLayer);
if(!fill){
if(outline){
Lines.stroke(minimap.scale(stroke + 2f, autoscale), Pal.gray);
Lines.poly(Tmp.v1.x, Tmp.v1.y, sides, minimap.scale(radius + 1f, autoscale), rotation);
}
Lines.stroke(stroke, color);
Lines.poly(Tmp.v1.x, Tmp.v1.y, sides, minimap.scale(radius + 1f, autoscale), rotation);
}else{
Draw.color(color);
Fill.poly(Tmp.v1.x, Tmp.v1.y, sides, minimap.scale(radius, autoscale), rotation);
}
Draw.reset();
} }
@Override @Override
@@ -1035,35 +996,26 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public TextMarker(){} public TextMarker(){}
@Override @Override
public void drawWorld(){ public void baseDraw(float x, float y, float scaleFactor){
// font size cannot be 0 // font size cannot be 0
if(hidden || Mathf.equal(fontSize, 0f) || minimap) return; if(Mathf.equal(fontSize, 0f)) return;
if(fetchedText == null){ if(fetchedText == null){
fetchedText = fetchText(text); fetchedText = fetchText(text);
} }
float scl = autoscale ? 4f / renderer.getDisplayScale() : 1f; WorldLabel.drawAt(fetchedText, x, y, drawLayer, flags, fontSize * scaleFactor);
}
WorldLabel.drawAt(fetchedText, pos.x, pos.y, drawLayer, flags, fontSize * scl); @Override
public void drawWorld(){
baseDraw(pos.x, pos.y, autoscale ? 4f / renderer.getDisplayScale() : 1f);
} }
@Override @Override
public void drawMinimap(MinimapRenderer minimap){ public void drawMinimap(MinimapRenderer minimap){
if(hidden || !this.minimap) return;
float size = minimap.scale(fontSize, autoscale);
// font size cannot be 0
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));
baseDraw(Tmp.v1.x, Tmp.v1.y, minimap.getScaleFactor(autoscale));
if(fetchedText == null){
fetchedText = fetchText(text);
}
WorldLabel.drawAt(fetchedText, Tmp.v1.x, Tmp.v1.y, drawLayer, flags, size);
} }
@Override @Override
@@ -1129,37 +1081,27 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public LineMarker(){} public LineMarker(){}
@Override public void baseLineDraw(float x1, float y1, float x2, float y2, float scaleFactor){
public void drawWorld(){
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) * scl, Pal.gray); Lines.stroke((stroke + 2f) * scaleFactor, Pal.gray);
Lines.line(pos1.x, pos1.y, pos2.x, pos2.y); Lines.line(x1, y1, x2, y2);
} }
Lines.stroke(stroke * scl, color); Lines.stroke(stroke * scaleFactor, color);
Lines.line(pos1.x, pos1.y, pos2.x, pos2.y); Lines.line(x1, y1, x2, y2);
}
@Override
public void drawWorld(){
baseLineDraw(pos1.x, pos1.y, pos1.x, pos2.y, autoscale ? 4f / renderer.getDisplayScale() : 1f);
} }
@Override @Override
public void drawMinimap(MinimapRenderer minimap){ public void drawMinimap(MinimapRenderer minimap){
if(hidden || !this.minimap) return;
minimap.transform(Tmp.v1.set(pos1.x + 4f, pos1.y + 4f)); minimap.transform(Tmp.v1.set(pos1.x + 4f, pos1.y + 4f));
minimap.transform(Tmp.v2.set(pos2.x + 4f, pos2.y + 4f)); minimap.transform(Tmp.v2.set(pos2.x + 4f, pos2.y + 4f));
baseLineDraw(Tmp.v1.x, Tmp.v1.y, Tmp.v2.x, Tmp.v2.y, minimap.getScaleFactor(autoscale));
Draw.z(drawLayer);
if(outline){
Lines.stroke(minimap.scale(stroke + 2f, autoscale), Pal.gray);
Lines.line(Tmp.v1.x, Tmp.v1.y, Tmp.v2.x, Tmp.v2.y);
}
Lines.stroke(minimap.scale(stroke, autoscale), color);
Lines.line(Tmp.v1.x, Tmp.v1.y, Tmp.v2.x, Tmp.v2.y);
} }
@Override @Override
@@ -1222,8 +1164,8 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
} }
@Override @Override
public void drawWorld(){ public void baseDraw(float x, float y, float scaleFactor){
if(hidden || textureName.isEmpty() || minimap) return; if(textureName.isEmpty()) return;
if(fetchedRegion == null) fetchedRegion = Core.atlas.find(textureName); if(fetchedRegion == null) fetchedRegion = Core.atlas.find(textureName);
@@ -1231,38 +1173,25 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
if(Mathf.equal(width, 0f)) width = fetchedRegion.width * fetchedRegion.scl() * Draw.xscl; if(Mathf.equal(width, 0f)) width = fetchedRegion.width * fetchedRegion.scl() * Draw.xscl;
if(Mathf.equal(height, 0f)) 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 * scl, height * scl, rotation); Draw.rect(fetchedRegion, x, y, width * scaleFactor, height * scaleFactor, rotation);
}else{ }else{
Draw.color(Color.white); Draw.color(Color.white);
Draw.rect("error", pos.x, pos.y, width * scl, height * scl, rotation); Draw.rect("error", x, y, width * scaleFactor, height * scaleFactor, rotation);
} }
} }
@Override
public void drawWorld(){
baseDraw(pos.x, pos.y, autoscale ? 4f / renderer.getDisplayScale() : 1f);
}
@Override @Override
public void drawMinimap(MinimapRenderer minimap){ public void drawMinimap(MinimapRenderer minimap){
if(hidden || textureName.isEmpty() || !this.minimap) return;
if(fetchedRegion == null) fetchedRegion = Core.atlas.find(textureName);
// Zero width/height scales marker to original texture's size
if(Mathf.equal(width, 0f)) width = fetchedRegion.width * fetchedRegion.scl() * Draw.xscl;
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));
baseDraw(Tmp.v1.x, Tmp.v1.y, minimap.getScaleFactor(autoscale));
Draw.z(drawLayer);
if(fetchedRegion.found()){
Draw.color(color);
Draw.rect(fetchedRegion, Tmp.v1.x, Tmp.v1.y, minimap.scale(width, autoscale), minimap.scale(height, autoscale), rotation);
}else{
Draw.color(Color.white);
Draw.rect("error", Tmp.v1.x, Tmp.v1.y, minimap.scale(width, autoscale), minimap.scale(height, autoscale), rotation);
}
} }
@Override @Override
@@ -302,13 +302,14 @@ public class MinimapRenderer{
} }
public float scale(float radius){ public float scale(float radius){
return scale(radius, false); return worldSpace ? (radius / (baseSize / 2f)) * 5f * lastScl : lastW / rect.width * radius;
} }
public float scale(float radius, boolean zoomAutoScale){
public float getScaleFactor(boolean zoomAutoScale){
if(!zoomAutoScale){ if(!zoomAutoScale){
return worldSpace ? (radius / (baseSize / 2f)) * 5f * lastScl : lastW / rect.width * radius; return worldSpace ? (1 / (baseSize / 2f)) * 5f * lastScl : lastW / rect.width;
}else{ }else{
return worldSpace ? (radius / (baseSize / 2f)) * 5f : lastW / 256f * radius; return worldSpace ? (1 / (baseSize / 2f)) * 5f : lastW / 256f;
} }
} }
+4 -8
View File
@@ -1987,13 +1987,9 @@ public class LExecutor{
var marker = state.markers.get(exec.numi(id)); var marker = state.markers.get(exec.numi(id));
if(marker == null) return; if(marker == null) return;
if(type == LMarkerControl.text){ if(type == LMarkerControl.flushText){
if(exec.bool(p1)){ marker.setText(exec.textBuffer.toString(), exec.bool(p1));
marker.setText(exec.textBuffer.toString(), exec.bool(p3)); exec.textBuffer.setLength(0);
exec.textBuffer.setLength(0);
}else{
marker.setText((exec.obj(p2) != null ? exec.obj(p2).toString() : "null"), exec.bool(p3));
}
}else if(type == LMarkerControl.texture){ }else if(type == LMarkerControl.texture){
if(exec.bool(p1)){ if(exec.bool(p1)){
marker.setTexture(exec.textBuffer.toString()); marker.setTexture(exec.textBuffer.toString());
@@ -2058,7 +2054,7 @@ public class LExecutor{
public static void updateMarkerText(int id, LMarkerControl type, boolean fetch, String text){ public static void updateMarkerText(int id, LMarkerControl type, boolean fetch, String text){
var marker = state.markers.get(id); var marker = state.markers.get(id);
if(marker != null){ if(marker != null){
if(type == LMarkerControl.text){ if(type == LMarkerControl.flushText){
marker.setText(text, fetch); marker.setText(text, fetch);
} }
} }
+1 -1
View File
@@ -13,7 +13,7 @@ public enum LMarkerControl{
stroke("stroke"), stroke("stroke"),
rotation("rotation"), rotation("rotation"),
shape("sides", "fill", "outline"), shape("sides", "fill", "outline"),
text("printFlush", "text", "fetch"), flushText("fetch"),
fontSize("size"), fontSize("size"),
textHeight("height"), textHeight("height"),
labelFlags("background", "outline"), labelFlags("background", "outline"),
@@ -2000,6 +2000,7 @@ 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){ if(type == LMarkerControl.color){
col(t, p1, res -> { col(t, p1, res -> {
p1 = "%" + res.toString().substring(0, res.a >= 1f ? 6 : 8); p1 = "%" + res.toString().substring(0, res.a >= 1f ? 6 : 8);