update markers (#9506)

* update markers

* update markers & minimap rendering
This commit is contained in:
Redstonneur1256
2024-01-31 01:35:39 +01:00
committed by GitHub
parent 994ed5a872
commit 6a429184aa
7 changed files with 290 additions and 180 deletions

View File

@@ -372,18 +372,20 @@ public class Renderer implements ApplicationListener{
});
}
float scaleFactor = 4f / renderer.getDisplayScale();
//draw objective markers
state.rules.objectives.eachRunning(obj -> {
for(var marker : obj.markers){
if(!marker.minimap){
marker.drawWorld();
if(marker.world){
marker.draw(marker.autoscale ? scaleFactor : 1);
}
}
});
for(var marker : state.markers){
if(!marker.isHidden() && !marker.minimap){
marker.drawWorld();
if(marker.world){
marker.draw(marker.autoscale ? scaleFactor : 1);
}
}

View File

@@ -246,6 +246,38 @@ public class MapObjectivesDialog extends BaseDialog{
show();
}});
setInterpreter(Vertices.class, float[].class, (cont, name, type, field, remover, indexer, get, set) -> cont.table(main -> {
float[] data = get.get();
name(cont, name, remover, indexer);
cont.table(t -> {
t.left().defaults().left();
String[] names = {"x", "y", "color", "u", "v"};
int stride = 6;
int vertices = data.length / stride;
for(int i = 0; i < vertices; i++){
int offset = i * stride;
t.table(row -> {
for(int j = 0; j < names.length; j++){
int index = offset + j;
if("color".equals(names[j])) {
getInterpreter(Color.class).build(row, names[j], new TypeInfo(Color.class), null, null, null, () -> new Color().abgr8888(data[index]), value -> data[index] = value.toFloatBits());
}else{
float scale = j <= 1 ? tilesize : 1;
getInterpreter(float.class).build(row, names[j], new TypeInfo(float.class), null, null, null, () -> data[index] / scale, value -> data[index] = value * scale);
}
row.add().pad(4);
}
}).row();
}
});
}));
// Types that use the default interpreter. It would be nice if all types could use it, but I don't know how to reliably prevent classes like [? extends Content] from using it.
for(var obj : MapObjectives.allObjectiveTypes) setInterpreter(obj.get().getClass(), defaultInterpreter());
for(var mark : MapObjectives.allMarkerTypes) setInterpreter(mark.get().getClass(), defaultInterpreter());
@@ -290,10 +322,12 @@ public class MapObjectivesDialog extends BaseDialog{
t.button(Icon.downOpen, Styles.emptyi, () -> indexer.get(false)).fill().padRight(4f);
}
t.button(Icon.add, Styles.emptyi, () -> getProvider(type.element.raw).get(type.element, res -> {
arr.add(res);
rebuild[0].run();
})).fill();
if(!field.isAnnotationPresent(Immutable.class)) {
t.button(Icon.add, Styles.emptyi, () -> getProvider(type.element.raw).get(type.element, res -> {
arr.add(res);
rebuild[0].run();
})).fill();
}
}).growX().height(46f).pad(0f, -10f, 0f, -10f).get();
main.row().table(Tex.button, t -> rebuild[0] = () -> {
@@ -312,10 +346,10 @@ public class MapObjectivesDialog extends BaseDialog{
getInterpreter((Class<Object>)arr.get(index).getClass()).build(
t, "", new TypeInfo(arr.get(index).getClass()),
field, () -> {
field, field == null || !field.isAnnotationPresent(Immutable.class) ? () -> {
arr.remove(index);
rebuild[0].run();
}, field == null || !field.isAnnotationPresent(Unordered.class) ? in -> {
} : null, field == null || !field.isAnnotationPresent(Unordered.class) ? in -> {
if(in && index > 0){
arr.swap(index, index - 1);
rebuild[0].run();

View File

@@ -61,12 +61,15 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
registerMarker(
ShapeTextMarker::new,
MinimapMarker::new,
PointMarker::new,
ShapeMarker::new,
TextMarker::new,
LineMarker::new,
TextureMarker::new
TextureMarker::new,
QuadMarker::new
);
registerLegacyMarker("Minimap", PointMarker::new);
}
@SafeVarargs
@@ -96,6 +99,15 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
}
}
public static void registerLegacyMarker(String name, Prov<? extends ObjectiveMarker> prov) {
Class<?> type = prov.get().getClass();
markerNameToType.put(name, prov);
markerNameToType.put(Strings.camelize(name), prov);
JsonIO.classTag(Strings.camelize(name), type);
JsonIO.classTag(name, type);
}
/** Adds all given objectives to the executor as root objectives. */
public void add(MapObjective... objectives){
for(var objective : objectives) flatten(objective);
@@ -617,38 +629,26 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
/** Internal use only! Do not access. */
public transient int arrayIndex;
/** Whether to display marker on minimap instead of world. {@link MinimapMarker} ignores this value. */
/** Whether to display marker in the world. */
public boolean world = true;
/** Whether to display marker on minimap. */
public boolean minimap = false;
/** Whether to scale marker corresponding to player's zoom level. {@link MinimapMarker} ignores this value. */
/** Whether to scale marker corresponding to player's zoom level. */
public boolean autoscale = false;
/** Hides the marker, used by world processors. */
protected boolean hidden = false;
/** On which z-sorting layer is marker drawn. */
protected float drawLayer = Layer.overlayUI;
/** Draws the marker. Actual marker position and scale are calculated in {@link #drawWorld()} and {@link #drawMinimap(MinimapRenderer)}. */
public void baseDraw(float x, float y, float scaleFactor){}
/** Called in the main renderer. */
public void drawWorld(){}
/** Called in the small and large map. */
public void drawMinimap(MinimapRenderer minimap){}
/** Whether the marker is hidden */
public boolean isHidden(){
return hidden;
}
public void draw(float 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 visibility -> hidden = Mathf.equal((float)p1, 0f);
case drawLayer -> drawLayer = (float)p1;
case world -> world = !Mathf.equal((float)p1, 0f);
case minimap -> minimap = !Mathf.equal((float)p1, 0f);
case autoscale -> autoscale = !Mathf.equal((float)p1, 0f);
case drawLayer -> drawLayer = (float)p1;
}
}
@@ -688,19 +688,6 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
/** Position of marker, in world coordinates */
public @TilePos Vec2 pos = new Vec2();
/** Called in the main renderer. */
@Override
public void drawWorld(){
baseDraw(pos.x, pos.y, autoscale ? 4f / renderer.getDisplayScale() : 1f);
}
/** Called in the small and large map. */
@Override
public void drawMinimap(MinimapRenderer minimap){
minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f));
baseDraw(Tmp.v1.x, Tmp.v1.y, minimap.getScaleFactor(autoscale));
}
@Override
public void control(LMarkerControl type, double p1, double p2, double p3){
super.control(type, p1, p2, p3);
@@ -761,15 +748,15 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public ShapeTextMarker(){}
@Override
public void baseDraw(float x, float y, float scaleFactor){
public void draw(float scaleFactor){
//in case some idiot decides to make 9999999 sides and freeze the game
int sides = Math.min(this.sides, 300);
Draw.z(drawLayer);
Lines.stroke(3f * scaleFactor, Pal.gray);
Lines.poly(x, y, sides, (radius + 1f) * scaleFactor, rotation);
Lines.poly(pos.x, pos.y, sides, (radius + 1f) * scaleFactor, rotation);
Lines.stroke(scaleFactor, color);
Lines.poly(x, y, sides, (radius + 1f) * scaleFactor, rotation);
Lines.poly(pos.x, pos.y, sides, (radius + 1f) * scaleFactor, rotation);
Draw.reset();
if(fetchedText == null){
@@ -779,7 +766,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
// font size cannot be 0
if(Mathf.equal(fontSize, 0f)) return;
WorldLabel.drawAt(fetchedText, x, y + radius * scaleFactor + textHeight * scaleFactor, drawLayer, flags, fontSize * scaleFactor);
WorldLabel.drawAt(fetchedText, pos.x, pos.y + radius * scaleFactor + textHeight * scaleFactor, drawLayer, flags, fontSize * scaleFactor);
}
@Override
@@ -799,7 +786,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
}
case radius -> radius = (float)p1;
case rotation -> rotation = (float)p1;
case color -> color.set(Tmp.c1.fromDouble(p1));
case color -> color.fromDouble(p1);
case shape -> sides = (int)p1;
}
}
@@ -828,72 +815,50 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
}
}
/** Displays a circle on the minimap. */
public static class MinimapMarker extends ObjectiveMarker{
public Point2 pos = new Point2();
/** Displays a circle in the world. */
public static class PointMarker extends PosMarker{
public float radius = 5f, stroke = 11f;
public Color color = Color.valueOf("f25555");
public MinimapMarker(int x, int y){
public PointMarker(int x, int y){
this.pos.set(x, y);
}
public MinimapMarker(int x, int y, Color color){
public PointMarker(int x, int y, Color color){
this.pos.set(x, y);
this.color = color;
minimap = true;
}
public MinimapMarker(int x, int y, float radius, float stroke, Color color){
public PointMarker(int x, int y, float radius, float stroke, Color color){
this.pos.set(x, y);
this.stroke = stroke;
this.radius = radius;
this.color = color;
minimap = true;
}
public MinimapMarker(){}
public PointMarker(){}
@Override
public void baseDraw(float x, float y, float scaleFactor){
public void draw(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);
Lines.circle(pos.x, pos.y, rad * fin);
Draw.reset();
}
@Override
public void drawWorld(){
minimap = true;
}
@Override
public void drawMinimap(MinimapRenderer minimap){
minimap.transform(Tmp.v1.set(pos.x * tilesize, pos.y * tilesize));
baseDraw(Tmp.v1.x, Tmp.v1.y, minimap.getScaleFactor(autoscale));
}
@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 pos -> pos.x = (int)p1;
case radius -> radius = (float)p1;
case stroke -> stroke = (float)p1;
case color -> color.set(Tmp.c1.fromDouble(p1));
case minimap -> minimap = true;
}
}
if(!Double.isNaN(p2)){
if(type == LMarkerControl.pos){
pos.y = (int)p2;
case color -> color.fromDouble(p1);
}
}
}
@@ -919,7 +884,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public ShapeMarker(){}
@Override
public void baseDraw(float x, float y, float scaleFactor){
public void draw(float scaleFactor){
//in case some idiot decides to make 9999999 sides and freeze the game
int sides = Math.min(this.sides, 200);
@@ -927,14 +892,14 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
if(!fill){
if(outline){
Lines.stroke((stroke + 2f) * scaleFactor, Pal.gray);
Lines.poly(x, y, sides, (radius + 1f) * scaleFactor, rotation);
Lines.poly(pos.x, pos.y, sides, (radius + 1f) * scaleFactor, rotation);
}
Lines.stroke(stroke * scaleFactor, color);
Lines.poly(x, y, sides, (radius + 1f) * scaleFactor, rotation);
Lines.poly(pos.x, pos.y, sides, (radius + 1f) * scaleFactor, rotation);
}else{
Draw.color(color);
Fill.poly(x, y, sides, radius * scaleFactor, rotation);
Fill.poly(pos.x, pos.y, sides, radius * scaleFactor, rotation);
}
Draw.reset();
@@ -949,7 +914,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
case radius -> radius = (float)p1;
case stroke -> stroke = (float)p1;
case rotation -> rotation = (float)p1;
case color -> color.set(Tmp.c1.fromDouble(p1));
case color -> color.fromDouble(p1);
case shape -> sides = (int)p1;
}
}
@@ -991,7 +956,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public TextMarker(){}
@Override
public void baseDraw(float x, float y, float scaleFactor){
public void draw(float scaleFactor){
// font size cannot be 0
if(Mathf.equal(fontSize, 0f)) return;
@@ -999,7 +964,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
fetchedText = fetchText(text);
}
WorldLabel.drawAt(fetchedText, x, y, drawLayer, flags, fontSize * scaleFactor);
WorldLabel.drawAt(fetchedText, pos.x, pos.y, drawLayer, flags, fontSize * scaleFactor);
}
@Override
@@ -1048,7 +1013,8 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public @TilePos Vec2 endPos = new Vec2();
public float stroke = 1f;
public boolean outline = true;
public Color color = Color.valueOf("ffd37f");
public Color color1 = Color.valueOf("ffd37f");
public Color color2 = Color.valueOf("ffd37f");
public LineMarker(float x1, float y1, float x2, float y2, float stroke){
this.stroke = stroke;
@@ -1063,27 +1029,16 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public LineMarker(){}
public void baseLineDraw(float x1, float y1, float x2, float y2, float scaleFactor){
@Override
public void draw(float scaleFactor){
Draw.z(drawLayer);
if(outline){
Lines.stroke((stroke + 2f) * scaleFactor, Pal.gray);
Lines.line(x1, y1, x2, y2);
Lines.line(pos.x, pos.y, endPos.x, endPos.y);
}
Lines.stroke(stroke * scaleFactor, color);
Lines.line(x1, y1, x2, y2);
}
@Override
public void drawWorld(){
baseLineDraw(pos.x, pos.y, endPos.x, endPos.y, autoscale ? 4f / renderer.getDisplayScale() : 1f);
}
@Override
public void drawMinimap(MinimapRenderer minimap){
minimap.transform(Tmp.v1.set(pos.x + 4f, pos.y + 4f));
minimap.transform(Tmp.v2.set(endPos.x + 4f, endPos.y + 4f));
baseLineDraw(Tmp.v1.x, Tmp.v1.y, Tmp.v2.x, Tmp.v2.y, minimap.getScaleFactor(autoscale));
Lines.stroke(stroke * scaleFactor, Color.white);
Lines.line(pos.x, pos.y, color1, endPos.x, endPos.y, color2);
}
@Override
@@ -1094,7 +1049,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
switch(type){
case endPos -> endPos.x = (float)p1 * tilesize;
case stroke -> stroke = (float)p1;
case color -> color.set(Tmp.c1.fromDouble(p1));
case color -> color1.set(color2.fromDouble(p1));
}
}
@@ -1103,6 +1058,19 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
case endPos -> endPos.y = (float)p2 * tilesize;
}
}
if(!Double.isNaN(p1) && !Double.isNaN(p2)){
switch (type){
case posi -> ((int)p1 == 0 ? pos : (int)p1 == 1 ? endPos : Tmp.v1).x = (float)p2 * tilesize;
case colori -> ((int)p1 == 0 ? color1 : (int)p1 == 1 ? color2 : Tmp.c1).fromDouble(p2);
}
}
if(!Double.isNaN(p1) && !Double.isNaN(p3)){
switch(type){
case posi -> ((int)p1 == 0 ? pos : (int)p1 == 1 ? endPos : Tmp.v1).y = (float)p3 * tilesize;
}
}
}
}
@@ -1136,7 +1104,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
switch(type){
case rotation -> rotation = (float)p1;
case textureSize -> width = (float)p1 * tilesize;
case color -> color.set(Tmp.c1.fromDouble(p1));
case color -> color.fromDouble(p1);
}
}
@@ -1148,7 +1116,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
}
@Override
public void baseDraw(float x, float y, float scaleFactor){
public void draw(float scaleFactor){
if(textureName.isEmpty()) return;
if(fetchedRegion == null) setTexture(textureName);
@@ -1159,7 +1127,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
Draw.z(drawLayer);
Draw.color(color);
Draw.rect(fetchedRegion, x, y, width * scaleFactor, height * scaleFactor, rotation);
Draw.rect(fetchedRegion, pos.x, pos.y, width * scaleFactor, height * scaleFactor, rotation);
}
@Override
@@ -1167,19 +1135,119 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
this.textureName = textureName;
if(fetchedRegion == null) fetchedRegion = new TextureRegion();
lookupRegion(textureName, fetchedRegion);
}
TextureRegion region = Core.atlas.find(textureName);
if(region.found()){
fetchedRegion.set(region);
}else{
if(Core.assets.isLoaded(textureName, Texture.class)){
fetchedRegion.set(Core.assets.get(textureName, Texture.class));
}else{
fetchedRegion.set(Core.atlas.find("error"));
}
public static class QuadMarker extends ObjectiveMarker{
public String textureName = "white";
public @Vertices float[] vertices = new float[24];
private transient TextureRegion fetchedRegion;
public QuadMarker() {
for(int i = 0; i < 4; i++){
vertices[i * 6 + 2] = Color.white.toFloatBits();
vertices[i * 6 + 5] = Color.clearFloatBits;
}
}
@Override
public void draw(float scaleFactor){
if(fetchedRegion == null) setTexture(textureName);
Draw.z(drawLayer);
Draw.vert(fetchedRegion.texture, vertices, 0, vertices.length);
}
@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 color -> {
float col = Tmp.c1.fromDouble(p1).toFloatBits();
for(int i = 0; i < 4; i++) vertices[i * 6 + 2] = col;
}
case pos -> vertices[0] = (float)p1 * tilesize;
case posi -> setPos((int)p1, p2, p3);
case uvi -> setUv((int)p1, p2, p3);
}
}
if(!Double.isNaN(p2)){
switch(type){
case pos -> vertices[1] = (float)p1 * tilesize;
}
}
if(!Double.isNaN(p1) && !Double.isNaN(p2)){
switch(type){
case colori -> setColor((int)p1, p2);
}
}
}
@Override
public void setTexture(String textureName){
this.textureName = textureName;
boolean firstUpdate = fetchedRegion == null;
if(fetchedRegion == null) fetchedRegion = new TextureRegion();
Tmp.tr1.set(fetchedRegion);
lookupRegion(textureName, fetchedRegion);
if(firstUpdate) {
// possibly from the editor, we need to clamp the values
for(int i = 0; i < 4; i++){
vertices[i * 6 + 3] = Mathf.map(Mathf.clamp(vertices[i * 6 + 3]), fetchedRegion.u, fetchedRegion.u2);
vertices[i * 6 + 4] = Mathf.map(1 - Mathf.clamp(vertices[i * 6 + 4]), fetchedRegion.v, fetchedRegion.v2);
}
}else{
for(int i = 0; i < 4; i++){
vertices[i * 6 + 3] = Mathf.map(vertices[i * 6 + 3], Tmp.tr1.u, Tmp.tr1.u2, fetchedRegion.u, fetchedRegion.u2);
vertices[i * 6 + 4] = Mathf.map(vertices[i * 6 + 4], Tmp.tr1.v, Tmp.tr1.v2, fetchedRegion.v, fetchedRegion.v2);
}
}
}
private void setPos(int i, double x, double y){
if(i >= 0 && i < 4){
if(!Double.isNaN(x)) vertices[i * 6] = (float)x * tilesize;
if(!Double.isNaN(y)) vertices[i * 6 + 1] = (float)y * tilesize;
}
}
private void setColor(int i, double c){
if(i >= 0 && i < 4){
vertices[i * 6 + 2] = Tmp.c1.fromDouble(c).toFloatBits();
}
}
private void setUv(int i, double u, double v){
if(i >= 0 && i < 4){
if(!Double.isNaN(u)) vertices[i * 6 + 3] = Mathf.map(Mathf.clamp((float)u), fetchedRegion.u, fetchedRegion.u2);
if(!Double.isNaN(v)) vertices[i * 6 + 4] = Mathf.map(1 - Mathf.clamp((float)v), fetchedRegion.v, fetchedRegion.v2);
}
}
}
private static void lookupRegion(String name, TextureRegion out){
TextureRegion region = Core.atlas.find(name);
if(region.found()){
out.set(region);
}else{
if(Core.assets.isLoaded(name, Texture.class)){
out.set(Core.assets.get(name, Texture.class));
}else{
out.set(Core.atlas.find("error"));
}
}
}
/** For arrays or {@link Seq}s; does not create element rearrangement buttons. */
@@ -1187,6 +1255,16 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
@Retention(RUNTIME)
public @interface Unordered{}
/** For arrays or {@link Seq}s; does not add the new and delete buttons */
@Target(FIELD)
@Retention(RUNTIME)
public @interface Immutable{}
/** For {@code float[]}; treats it as an array of vertices. */
@Target(FIELD)
@Retention(RUNTIME)
public @interface Vertices{}
/** For {@code byte}; treats it as a world label flag. */
@Target(FIELD)
@Retention(RUNTIME)

View File

@@ -146,16 +146,27 @@ public class MinimapRenderer{
rect.set((dx - sz) * tilesize, (dy - sz) * tilesize, sz * 2 * tilesize, sz * 2 * tilesize);
Tmp.m2.set(Draw.trans());
var trans = Tmp.m1.idt();
trans.translate(lastX, lastY);
if(!worldSpace){
trans.scl(Tmp.v1.set(lastW / rect.width, lastH / rect.height));
trans.translate(-rect.x, -rect.y);
}else{
trans.scl(Tmp.v1.set(lastW / world.unitWidth(), lastH / world.unitHeight()));
}
trans.translate(tilesize / 2f, tilesize / 2f);
Draw.trans(trans);
for(Unit unit : units){
if(unit.inFogTo(player.team()) || !unit.type.drawMinimap) continue;
float rx = !fullView ? (unit.x - rect.x) / rect.width * w : unit.x / (world.width() * tilesize) * w;
float ry = !fullView ? (unit.y - rect.y) / rect.width * h : unit.y / (world.height() * tilesize) * h;
float scale = Scl.scl(1f) * tilesize * 3;
var region = unit.icon();
Draw.mixcol(unit.team.color, 1f);
float scale = Scl.scl(1f) / 2f * scaling * 32f;
var region = unit.icon();
Draw.rect(region, x + rx, y + ry, scale, scale * (float)region.height / region.width, unit.rotation() - 90);
Draw.rect(region, unit.x, unit.y, scale, scale * (float)region.height / region.width, unit.rotation() - 90);
Draw.reset();
}
@@ -186,15 +197,14 @@ public class MinimapRenderer{
//crisp pixels
dynamicTex.setFilter(TextureFilter.nearest);
if(worldSpace){
region.set(0f, 0f, 1f, 1f);
}
Tmp.tr1.set(dynamicTex);
Tmp.tr1.set(region.u, 1f - region.v, region.u2, 1f - region.v2);
Tmp.tr1.set(0f, 0f, 1f, 1f);
float wf = world.width() * tilesize;
float hf = world.height() * tilesize;
Draw.color(state.rules.dynamicColor, 0.5f);
Draw.rect(Tmp.tr1, x + w/2f, y + h/2f, w, h);
Draw.rect(Tmp.tr1, wf / 2, hf / 2, wf, hf);
if(state.rules.staticFog){
staticTex.setFilter(TextureFilter.nearest);
@@ -202,7 +212,7 @@ public class MinimapRenderer{
Tmp.tr1.texture = staticTex;
//must be black to fit with borders
Draw.color(0f, 0f, 0f, 1f);
Draw.rect(Tmp.tr1, x + w/2f, y + h/2f, w, h);
Draw.rect(Tmp.tr1, wf / 2, hf / 2, wf, hf);
}
Draw.color();
@@ -211,23 +221,21 @@ public class MinimapRenderer{
//TODO might be useful in the standard minimap too
if(fullView){
drawSpawns(x, y, w, h, scaling);
drawSpawns();
if(!mobile){
//draw bounds for camera - not drawn on mobile because you can't shift it by tapping anyway
Rect r = Core.camera.bounds(Tmp.r1);
Vec2 bot = transform(Tmp.v1.set(r.x, r.y));
Vec2 top = transform(Tmp.v2.set(r.x + r.width, r.y + r.height));
Lines.stroke(Scl.scl(3f));
Draw.color(Pal.accent);
Lines.rect(bot.x,bot.y, top.x - bot.x, top.y - bot.y);
Lines.rect(r.x, r.y, r.width, r.height);
Draw.reset();
}
}
LongSeq indicators = control.indicators.list();
float fin = ((Time.globalTime / 30f) % 1f);
float rad = scale(fin * 5f + tilesize - 2f);
float rad = fin * 5f + tilesize - 2f;
Lines.stroke(Scl.scl((1f - fin) * 4f + 0.5f));
for(int i = 0; i < indicators.size; i++){
@@ -244,31 +252,32 @@ public class MinimapRenderer{
offset = build.block.offset / tilesize;
}
Vec2 v = transform(Tmp.v1.set((ix + 0.5f + offset) * tilesize, (iy + 0.5f + offset) * tilesize));
Draw.color(Color.orange, Color.scarlet, Mathf.clamp(time / 70f));
Lines.square(v.x, v.y, rad);
Lines.square((ix + 0.5f + offset) * tilesize, (iy + 0.5f + offset) * tilesize, rad);
}
Draw.reset();
//TODO autoscale markers
state.rules.objectives.eachRunning(obj -> {
for(var marker : obj.markers){
if(marker.minimap){
marker.drawMinimap(this);
marker.draw(1);
}
}
});
for(var marker : state.markers){
if(!marker.isHidden() && marker.minimap){
marker.drawMinimap(this);
if(marker.minimap){
marker.draw(1);
}
}
Draw.trans(Tmp.m2);
}
public void drawSpawns(float x, float y, float w, float h, float scaling){
public void drawSpawns(){
if(!state.rules.showSpawns || !state.hasSpawns() || !state.rules.waves) return;
TextureRegion icon = Icon.units.getRegion();
@@ -277,44 +286,21 @@ public class MinimapRenderer{
Draw.color(state.rules.waveTeam.color, Tmp.c2.set(state.rules.waveTeam.color).value(1.2f), Mathf.absin(Time.time, 16f, 1f));
float rad = scale(state.rules.dropZoneRadius);
float rad = state.rules.dropZoneRadius;
float curve = Mathf.curve(Time.time % 240f, 120f, 240f);
for(Tile tile : spawner.getSpawns()){
float tx = ((tile.x + 0.5f) / world.width()) * w;
float ty = ((tile.y + 0.5f) / world.height()) * h;
float tx = tile.worldx();
float ty = tile.worldy();
Draw.rect(icon, x + tx, y + ty, icon.width, icon.height);
Lines.circle(x + tx, y + ty, rad);
if(curve > 0f) Lines.circle(x + tx, y + ty, rad * Interp.pow3Out.apply(curve));
Draw.rect(icon, tx, ty, icon.width, icon.height);
Lines.circle(tx, ty, rad);
if(curve > 0f) Lines.circle(tx, ty, rad * Interp.pow3Out.apply(curve));
}
Draw.reset();
}
//TODO horrible code, everywhere.
public Vec2 transform(Vec2 position){
if(!worldSpace){
position.sub(rect.x, rect.y).scl(lastW / rect.width, lastH / rect.height);
}else{
position.scl(lastW / world.unitWidth(), lastH / world.unitHeight());
}
return position.add(lastX, lastY);
}
public float scale(float radius){
return worldSpace ? (radius / (baseSize / 2f)) * 5f * lastScl : lastW / rect.width * radius;
}
public float getScaleFactor(boolean zoomAutoScale){
if(!zoomAutoScale){
return worldSpace ? (1 / (baseSize / 2f)) * 5f * lastScl : lastW / rect.width;
}else{
return worldSpace ? (1 / (baseSize / 2f)) * 5f : lastW / 256f;
}
}
public @Nullable TextureRegion getRegion(){
if(texture == null) return null;

View File

@@ -2,7 +2,7 @@ package mindustry.logic;
public enum LMarkerControl{
remove,
visibility("true/false"),
world("true/false"),
minimap("true/false"),
autoscale("true/false"),
pos("x", "y"),
@@ -18,7 +18,10 @@ public enum LMarkerControl{
textHeight("height"),
labelFlags("background", "outline"),
texture("printFlush", "name"),
textureSize("width", "height");
textureSize("width", "height"),
posi("index", "x", "y"),
uvi("index", "x", "y"),
colori("index", "color");
public final String[] params;

View File

@@ -1999,11 +1999,14 @@ public class LStatements{
table.table(t -> {
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);
String value = i == 0 ? p1 : i == 1 ? p2 : p3;
Cons<String> setter = i == 0 ? v -> p1 = v : i == 1 ? v -> p2 = v : v -> p3 = v;
if(type == LMarkerControl.color){
col(t, p1, res -> {
p1 = "%" + res.toString().substring(0, res.a >= 1f ? 6 : 8);
fields(t, type.params[i], value, setter).width(100f);
if(type == LMarkerControl.color || (type == LMarkerControl.colori && i == 1)){
col(t, value, res -> {
setter.get("%" + res.toString().substring(0, res.a >= 1f ? 6 : 8));
build(table);
});
}else if(type == LMarkerControl.drawLayer){
@@ -2013,10 +2016,10 @@ public class LStatements{
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);
for(var field : Layer.class.getFields()){
float layer = Reflect.get(field);
s.button(field.getName() + " = " + layer, Styles.logicTogglet, () -> {
p1 = Float.toString(layer);
rebuild(table);
hide.run();
}).size(240f, 40f).row();