Texture marker implementation
This commit is contained in:
@@ -2458,3 +2458,7 @@ lenum.build = Build a structure.
|
|||||||
lenum.getblock = Fetch a building, floor and type at coordinates.\nUnit must be in range of position.\nSolid non-buildings will have the type [accent]@solid[].
|
lenum.getblock = Fetch a building, floor and type at coordinates.\nUnit must be in range of position.\nSolid non-buildings will have the type [accent]@solid[].
|
||||||
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.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.textureHeight = Height of texture in tiles. Zero value scales marker height to original texture's size.
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
|||||||
MinimapMarker::new,
|
MinimapMarker::new,
|
||||||
ShapeMarker::new,
|
ShapeMarker::new,
|
||||||
TextMarker::new,
|
TextMarker::new,
|
||||||
LineMarker::new
|
LineMarker::new,
|
||||||
|
TextureMarker::new
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,7 +613,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
|||||||
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;
|
public boolean hidden = false;
|
||||||
|
|
||||||
/** Called in the overlay draw layer.*/
|
/** Called in the overlay draw layer.*/
|
||||||
@@ -632,6 +633,8 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
|||||||
}
|
}
|
||||||
public void setText(String text, boolean fetch){}
|
public void setText(String text, boolean fetch){}
|
||||||
|
|
||||||
|
public void setTexture(String textureName){}
|
||||||
|
|
||||||
/** @return The localized type-name of this objective, defaulting to the class simple name without the "Marker" prefix. */
|
/** @return The localized type-name of this objective, defaulting to the class simple name without the "Marker" prefix. */
|
||||||
public String typeName(){
|
public String typeName(){
|
||||||
String className = getClass().getSimpleName().replace("Marker", "");
|
String className = getClass().getSimpleName().replace("Marker", "");
|
||||||
@@ -1001,6 +1004,65 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Displays a texture with specified name. */
|
||||||
|
public static class TextureMarker extends ObjectiveMarker{
|
||||||
|
public @TilePos Vec2 pos = new Vec2();
|
||||||
|
public float rotation = 0f, width = 0f, height = 0f; // Zero width/height scales marker to original texture's size
|
||||||
|
public String textureName = "";
|
||||||
|
public Color color = Color.white.cpy();
|
||||||
|
|
||||||
|
private transient TextureRegion fetchedRegion;
|
||||||
|
|
||||||
|
public TextureMarker(String textureName, float x, float y){
|
||||||
|
this.textureName = textureName;
|
||||||
|
this.pos.set(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextureMarker(){}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void control(LMarkerControl type, double p1, double p2, double p3){
|
||||||
|
switch(type){
|
||||||
|
case x -> pos.x = (float)p1 * tilesize;
|
||||||
|
case y -> pos.y = (float)p1 * tilesize;
|
||||||
|
case pos -> pos.set((float)p1 * tilesize, (float)p2 * tilesize);
|
||||||
|
case rotation -> rotation = (float)p1;
|
||||||
|
case textureWidth -> width = (float)p1 * tilesize;
|
||||||
|
case textureHeight -> height = (float)p1 * tilesize;
|
||||||
|
case color -> {
|
||||||
|
Log.info("test");
|
||||||
|
color.set(Tmp.c1.fromDouble(p1));
|
||||||
|
}
|
||||||
|
default -> super.control(type, p1, p2, p3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(){
|
||||||
|
if(hidden || textureName.isEmpty()) return;
|
||||||
|
|
||||||
|
if(fetchedRegion == null) fetchedRegion = Core.atlas.find(textureName);
|
||||||
|
|
||||||
|
// Zero width/height scales marker to original texture's size
|
||||||
|
if(width < 1e-5) width = fetchedRegion.width * fetchedRegion.scl() * Draw.xscl;
|
||||||
|
if(height < 1e-5) height = fetchedRegion.height * fetchedRegion.scl() * Draw.yscl;
|
||||||
|
|
||||||
|
if(fetchedRegion.found()){
|
||||||
|
Draw.color(color);
|
||||||
|
Draw.rect(fetchedRegion, pos.x, pos.y, width, height, rotation);
|
||||||
|
}else{
|
||||||
|
Draw.color(Color.white);
|
||||||
|
Draw.rect("error", pos.x, pos.y, width, height, rotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTexture(String textureName){
|
||||||
|
this.textureName = textureName;
|
||||||
|
fetchedRegion = Core.atlas.find(textureName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** For arrays or {@link Seq}s; does not create element rearrangement buttons. */
|
/** For arrays or {@link Seq}s; does not create element rearrangement buttons. */
|
||||||
@Target(FIELD)
|
@Target(FIELD)
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
|
|||||||
@@ -1555,7 +1555,7 @@ public class LExecutor{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(LExecutor exec){
|
public void run(LExecutor exec){
|
||||||
//set default to succes
|
//set default to success
|
||||||
exec.setnum(outSuccess, 1);
|
exec.setnum(outSuccess, 1);
|
||||||
if(headless && type != MessageType.mission) {
|
if(headless && type != MessageType.mission) {
|
||||||
exec.textBuffer.setLength(0);
|
exec.textBuffer.setLength(0);
|
||||||
@@ -1879,6 +1879,13 @@ public class LExecutor{
|
|||||||
}else if(type == LMarkerControl.flushText){
|
}else if(type == LMarkerControl.flushText){
|
||||||
marker.setText(exec.textBuffer.toString(), true);
|
marker.setText(exec.textBuffer.toString(), true);
|
||||||
exec.textBuffer.setLength(0);
|
exec.textBuffer.setLength(0);
|
||||||
|
}else if(type == LMarkerControl.texture){
|
||||||
|
if(exec.obj(p1) != null){
|
||||||
|
StringBuilder res = new StringBuilder(exec.obj(p1).toString());
|
||||||
|
if(exec.obj(p2) != null) res.append("-").append(exec.obj(p2).toString());
|
||||||
|
if(exec.obj(p3) != null) res.append("-").append(exec.obj(p3).toString());
|
||||||
|
marker.setTexture(res.toString());
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
marker.control(type, exec.num(p1), exec.num(p2), exec.num(p3));
|
marker.control(type, exec.num(p1), exec.num(p2), exec.num(p3));
|
||||||
}
|
}
|
||||||
@@ -1944,5 +1951,13 @@ public class LExecutor{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Remote(called = Loc.server, variants = Variant.both, unreliable = true)
|
||||||
|
public static void updateMarkerTexture(int id, String textureName){
|
||||||
|
var marker = state.markers.get(id);
|
||||||
|
if(marker != null){
|
||||||
|
marker.setTexture(textureName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ public enum LMarkerControl{
|
|||||||
shapeFill("true/false"),
|
shapeFill("true/false"),
|
||||||
shapeOutline("true/false"),
|
shapeOutline("true/false"),
|
||||||
setShape("sides", "fill", "outline"),
|
setShape("sides", "fill", "outline"),
|
||||||
color("color");
|
color("color"),
|
||||||
|
texture("name", "-", "-"),
|
||||||
|
textureWidth("width"),
|
||||||
|
textureHeight("height");
|
||||||
|
|
||||||
public final String[] params;
|
public final String[] params;
|
||||||
|
|
||||||
|
|||||||
@@ -1943,7 +1943,7 @@ public class LStatements{
|
|||||||
b.clicked(() -> showSelect(b, LMarkerControl.all, type, t -> {
|
b.clicked(() -> showSelect(b, LMarkerControl.all, type, t -> {
|
||||||
type = t;
|
type = t;
|
||||||
rebuild(table);
|
rebuild(table);
|
||||||
}, 2, cell -> cell.size(140, 50)));
|
}, 3, cell -> cell.size(140, 50)));
|
||||||
}, Styles.logict, () -> {}).size(190, 40).color(table.color).left().padLeft(2);
|
}, Styles.logict, () -> {}).size(190, 40).color(table.color).left().padLeft(2);
|
||||||
|
|
||||||
row(table);
|
row(table);
|
||||||
|
|||||||
Reference in New Issue
Block a user