From 6a429184aafa2097d8aaa8b5f2e777752f365acd Mon Sep 17 00:00:00 2001 From: Redstonneur1256 <29004178+Redstonneur1256@users.noreply.github.com> Date: Wed, 31 Jan 2024 01:35:39 +0100 Subject: [PATCH] update markers (#9506) * update markers * update markers & minimap rendering --- core/assets/bundles/bundle.properties | 6 +- core/src/mindustry/core/Renderer.java | 10 +- .../mindustry/editor/MapObjectivesDialog.java | 46 ++- core/src/mindustry/game/MapObjectives.java | 290 +++++++++++------- .../mindustry/graphics/MinimapRenderer.java | 92 +++--- core/src/mindustry/logic/LMarkerControl.java | 7 +- core/src/mindustry/logic/LStatements.java | 19 +- 7 files changed, 290 insertions(+), 180 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index a0aea04348..b8a1089fe3 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -682,10 +682,11 @@ objective.commandmode.name = Command Mode objective.flag.name = Flag marker.shapetext.name = Shape Text -marker.minimap.name = Minimap +marker.point.name = Point marker.shape.name = Shape marker.text.name = Text marker.line.name = Line +marker.quad.name = Quad marker.background = Background marker.outline = Outline @@ -2485,3 +2486,6 @@ lenum.flushtext = Flush print buffer's content to marker, if applicable.\nIf fet 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.autoscale = Whether to scale marker corresponding to player's zoom level. +lenum.posi = Indexed position, used for line and quad markers with index zero being the first position. +lenum.uvi = Texture's position ranging from zero to one, used for quad markers. +lenum.colori = Indexed position, used for line and quad markers with index zero being the first color. diff --git a/core/src/mindustry/core/Renderer.java b/core/src/mindustry/core/Renderer.java index 13b1ead08f..7b7d1dc155 100644 --- a/core/src/mindustry/core/Renderer.java +++ b/core/src/mindustry/core/Renderer.java @@ -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); } } diff --git a/core/src/mindustry/editor/MapObjectivesDialog.java b/core/src/mindustry/editor/MapObjectivesDialog.java index 5e354a84ae..ecdc53e01e 100644 --- a/core/src/mindustry/editor/MapObjectivesDialog.java +++ b/core/src/mindustry/editor/MapObjectivesDialog.java @@ -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)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(); diff --git a/core/src/mindustry/game/MapObjectives.java b/core/src/mindustry/game/MapObjectives.java index f88607419a..466068c4eb 100644 --- a/core/src/mindustry/game/MapObjectives.java +++ b/core/src/mindustry/game/MapObjectives.java @@ -61,12 +61,15 @@ public class MapObjectives implements Iterable, Eachable, Eachable 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, Eachable