Allow markers to be used as light sources (#9733)

* Allow markers to be used as light sources

* Better light source markers

* Move PointMarker drawLight to LightMarker

* Add a rule for unit lights

* Optimize marker rendering

* Update core/assets/bundles/bundle.properties

---------

Co-authored-by: Anuken <arnukren@gmail.com>
This commit is contained in:
Redstonneur1256
2025-02-09 18:10:45 +01:00
committed by GitHub
parent 3378475f6a
commit 8626082068
12 changed files with 196 additions and 68 deletions

View File

@@ -65,7 +65,8 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
TextMarker::new,
LineMarker::new,
TextureMarker::new,
QuadMarker::new
QuadMarker::new,
LightMarker::new
);
registerLegacyMarker("Minimap", PointMarker::new);
@@ -620,13 +621,12 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
/** Marker used for drawing various content to indicate something along with an objective. Mostly used as UI overlay. */
public static abstract class ObjectiveMarker{
/** Internal use only! Do not access. */
public transient int arrayIndex;
/** Whether to display marker in the world. */
public boolean world = true;
/** Whether to display marker on minimap. */
public boolean minimap = false;
/** Whether to display marker in the world. Do not modify directly if added, use control() instead. */
public @IndexBool int world = 1;
/** Whether to display marker on the minimap. Do not modify directly if added, use control() instead. */
public @IndexBool int minimap = -1;
/** Whether to use the marker as light. Do not modify directly if added, use control() instead. */
public @IndexBool int light = -1;
/** Whether to scale marker corresponding to player's zoom level. */
public boolean autoscale = false;
/** On which z-sorting layer is marker drawn. */
@@ -634,13 +634,18 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public void draw(float scaleFactor){}
public void drawLight(float scaleFactor){
draw(scaleFactor);
}
/** Control marker with world processor code. Ignores NaN (null) values. */
public void control(LMarkerControl type, double p1, double p2, double p3){
if(Double.isNaN(p1)) return;
switch(type){
case world -> world = !Mathf.equal((float)p1, 0f);
case minimap -> minimap = !Mathf.equal((float)p1, 0f);
case world -> state.markers.updateMarker(state.markers.worldMarkers, this, !Mathf.equal((float)p1, 0f), m -> m.world, (m, i) -> m.world = i);
case minimap -> state.markers.updateMarker(state.markers.mapMarkers, this, !Mathf.equal((float)p1, 0f), m -> m.minimap, (m, i) -> m.minimap = i);
case light -> state.markers.updateMarker(state.markers.lightMarkers, this, !Mathf.equal((float)p1, 0f), m -> m.light, (m, i) -> m.light = i);
case autoscale -> autoscale = !Mathf.equal((float)p1, 0f);
case drawLayer -> drawLayer = (float)p1;
}
@@ -842,8 +847,13 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
Draw.z(drawLayer);
Lines.stroke(Scl.scl((1f - fin) * stroke + 0.1f), color);
Lines.circle(pos.x, pos.y, rad * fin);
}
Draw.reset();
@Override
public void drawLight(float scaleFactor){
float rad = radius * tilesize * scaleFactor;
renderer.lights.add(pos.x, pos.y, radius, color, color.a);
}
@Override
@@ -901,8 +911,6 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
Fill.arc(pos.x, pos.y, radius * scaleFactor, (startAngle - endAngle) / 360f, rotation + endAngle, sides);
}
}
Draw.reset();
}
@Override
@@ -1043,6 +1051,11 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
Lines.line(pos.x, pos.y, color1, endPos.x, endPos.y, color2);
}
@Override
public void drawLight(float scaleFactor){
renderer.lights.line(pos.x, pos.y, endPos.x, endPos.y, stroke, color1, color1.a);
}
@Override
public void control(LMarkerControl type, double p1, double p2, double p3){
super.control(type, p1, p2, p3);
@@ -1247,6 +1260,48 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
}
/** Displays a single point light. */
public static class LightMarker extends PosMarker{
public float radius = 5f;
public Color color = Color.valueOf("ffd37f");
public LightMarker(int x, int y){
this.pos.set(x, y);
}
public LightMarker(int x, int y, Color color){
this.pos.set(x, y);
this.color = color;
}
public LightMarker(int x, int y, float radius, Color color){
this.pos.set(x, y);
this.radius = radius;
this.color = color;
}
public LightMarker(){}
@Override
public void drawLight(float scaleFactor){
float rad = radius * tilesize * scaleFactor;
renderer.lights.add(pos.x, pos.y, radius, color, color.a);
}
@Override
public void control(LMarkerControl type, double p1, double p2, double p3){
super.control(type, p1, p2, p3);
if(!Double.isNaN(p1)){
switch(type){
case radius -> radius = (float)p1;
case color -> color.fromDouble(p1);
}
}
}
}
private static void lookupRegion(String name, TextureRegion out){
TextureRegion region = Core.atlas.find(name);
if(region.found()){
@@ -1275,6 +1330,11 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
@Retention(RUNTIME)
public @interface Vertices{}
/** For {@code int}; treats it as a boolean with -1 for false and any other value for true (defaulting to 1) */
@Target(FIELD)
@Retention(RUNTIME)
public @interface IndexBool{}
/** For {@code byte}; treats it as a world label flag. */
@Target(FIELD)
@Retention(RUNTIME)