Map objective editor fixes

This commit is contained in:
Anuken 2022-06-26 14:07:58 -04:00
parent 02e46a9909
commit 3f6ab92fcb
3 changed files with 63 additions and 40 deletions

View File

@ -192,7 +192,7 @@ public class SectorPresets{
), ),
new DestroyBlockObjective(Blocks.largeShieldProjector, 210, 278, Team.malis).withMarkers( new DestroyBlockObjective(Blocks.largeShieldProjector, 210, 278, Team.malis).withMarkers(
new TextMarker("The enemy is protected by shields.\nAn experimental shield breaker module has been detected in this sector.\nFind and activate it using tungsten.", 276f * 8f, 164f * 8f), new TextMarker("The enemy is protected by shields.\nAn experimental shield breaker module has been detected in this sector.\nFind and activate it using tungsten.", 276f * 8f, 164f * 8f),
new MinimapMarker(23f, 137f, Pal.accent) new MinimapMarker(23, 137, Pal.accent)
) )
); );
}; };

View File

@ -16,6 +16,7 @@ import mindustry.game.MapObjectives.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
import mindustry.io.*; import mindustry.io.*;
import mindustry.type.*;
import mindustry.ui.*; import mindustry.ui.*;
import mindustry.ui.dialogs.*; import mindustry.ui.dialogs.*;
import mindustry.world.*; import mindustry.world.*;
@ -25,6 +26,8 @@ import java.lang.reflect.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
public class MapObjectivesDialog extends BaseDialog{ public class MapObjectivesDialog extends BaseDialog{
private static final Seq<String> worldFields = Seq.with("x", "y");
private Seq<MapObjective> objectives = new Seq<>(); private Seq<MapObjective> objectives = new Seq<>();
private Table list = new Table(); private Table list = new Table();
@ -183,9 +186,9 @@ public class MapObjectivesDialog extends BaseDialog{
var type = field.getType(); var type = field.getType();
if(type == String.class){ if(type == String.class){
f.field(Reflect.get(objective, field), text -> { f.area(Reflect.get(objective, field), text -> {
Reflect.set(objective, field, text); Reflect.set(objective, field, text);
}); }).height(60f);
}else if(type == boolean.class){ }else if(type == boolean.class){
f.check("", Reflect.get(objective, field), val -> Reflect.set(objective, field, val)); f.check("", Reflect.get(objective, field), val -> Reflect.set(objective, field, val));
}else if(type == int.class){ }else if(type == int.class){
@ -195,9 +198,11 @@ public class MapObjectivesDialog extends BaseDialog{
} }
}).valid(Strings::canParseInt); }).valid(Strings::canParseInt);
}else if(type == float.class){ }else if(type == float.class){
f.field(Reflect.<Float>get(objective, field) + "", text -> { float multiplier = worldFields.contains(field.getName()) ? tilesize : 1f;
f.field((Reflect.<Float>get(objective, field) / multiplier) + "", text -> {
if(Strings.canParsePositiveFloat(text)){ if(Strings.canParsePositiveFloat(text)){
Reflect.set(objective, field, Strings.parseFloat(text)); Reflect.set(objective, field, Strings.parseFloat(text) * multiplier);
} }
}).valid(Strings::canParseFloat); }).valid(Strings::canParseFloat);
}else if(type == UnlockableContent.class){ }else if(type == UnlockableContent.class){
@ -216,6 +221,13 @@ public class MapObjectivesDialog extends BaseDialog{
setup(); setup();
}, b -> ((Block)b).synthetic()); }, b -> ((Block)b).synthetic());
}).pad(4); }).pad(4);
}else if(type == Item.class){
f.button(b -> b.image(Reflect.<Item>get(objective, field).uiIcon).size(iconSmall), () -> {
showContentSelect(ContentType.item, result -> {
Reflect.set(objective, field, result);
setup();
}, b -> true);
}).pad(4);
}else if(type == Team.class){ }else if(type == Team.class){
f.button(b -> b.image(Tex.whiteui).color(Reflect.<Team>get(objective, field).color).size(iconSmall), () -> { f.button(b -> b.image(Tex.whiteui).color(Reflect.<Team>get(objective, field).color).size(iconSmall), () -> {
showTeamSelect(result -> { showTeamSelect(result -> {
@ -274,7 +286,6 @@ public class MapObjectivesDialog extends BaseDialog{
f.row(); f.row();
f.add(strings).colspan(2).fill(); f.add(strings).colspan(2).fill();
}else if(type == ObjectiveMarker[].class){ }else if(type == ObjectiveMarker[].class){
Runnable[] rebuild = {null}; Runnable[] rebuild = {null};
@ -290,7 +301,6 @@ public class MapObjectivesDialog extends BaseDialog{
ObjectiveMarker[] array = Reflect.get(objective, field); ObjectiveMarker[] array = Reflect.get(objective, field);
//TODO very very broken
for(var marker : array){ for(var marker : array){
t.button(b -> { t.button(b -> {
b.left(); b.left();
@ -326,7 +336,7 @@ public class MapObjectivesDialog extends BaseDialog{
selectedMarker = marker; selectedMarker = marker;
rebuild[0].run(); rebuild[0].run();
} }
}).width(310f).growX().height(46f).pad(-6f).padBottom(12f).row(); }).width(280f).growX().height(46f).pad(-6f).padBottom(12f).row();
if(selectedMarker == marker){ if(selectedMarker == marker){
t.table(b -> { t.table(b -> {
@ -346,13 +356,8 @@ public class MapObjectivesDialog extends BaseDialog{
}).padTop(-12f).grow().row(); }).padTop(-12f).grow().row();
} }
} }
};
rebuild[0].run(); t.button("+ Add", () -> {
}).width(310f).pad(8f).colspan(2).row();
f.button("+ Add", () -> {
var selection = new BaseDialog("@add"); var selection = new BaseDialog("@add");
selection.cont.pane(p -> { selection.cont.pane(p -> {
p.background(Tex.button); p.background(Tex.button);
@ -374,8 +379,23 @@ public class MapObjectivesDialog extends BaseDialog{
selection.addCloseButton(); selection.addCloseButton();
selection.show(); selection.show();
}).height(40f).width(140f).left().row(); }).height(40f).width(140f).left().padLeft(-18f).padTop(-6f).row();
};
rebuild[0].run();
}).width(280f).pad(8f).colspan(2).row();
}else if(type == byte.class){
f.table(t -> {
byte value = Reflect.get(objective, field);
t.left().defaults().left();
t.check("background", (value & WorldLabel.flagBackground) != 0, val ->
Reflect.set(objective, field, (byte)(val ? value | WorldLabel.flagBackground : value & ~WorldLabel.flagBackground))).padTop(4f).padBottom(4f);
t.row();
t.check("outline", (value & WorldLabel.flagOutline) != 0, val ->
Reflect.set(objective, field, (byte)(val ? value | WorldLabel.flagOutline : value & ~WorldLabel.flagOutline)));
});
}else{ }else{
f.add("[red]UNFINISHED"); f.add("[red]UNFINISHED");
} }

View File

@ -489,22 +489,22 @@ public class MapObjectives{
/** Displays a circle on the minimap. */ /** Displays a circle on the minimap. */
public static class MinimapMarker extends ObjectiveMarker{ public static class MinimapMarker extends ObjectiveMarker{
//in tiles. public int x, y;
public float x, y, radius = 5f, stroke = 11f; public float radius = 5f, stroke = 11f;
public Color color = Color.valueOf("f25555"); public Color color = Color.valueOf("f25555");
public MinimapMarker(float x, float y){ public MinimapMarker(int x, int y){
this.x = x; this.x = x;
this.y = y; this.y = y;
} }
public MinimapMarker(float x, float y, Color color){ public MinimapMarker(int x, int y, Color color){
this.x = x; this.x = x;
this.y = y; this.y = y;
this.color = color; this.color = color;
} }
public MinimapMarker(float x, float y, float radius, float stroke, Color color){ public MinimapMarker(int x, int y, float radius, float stroke, Color color){
this.x = x; this.x = x;
this.y = y; this.y = y;
this.stroke = stroke; this.stroke = stroke;
@ -530,7 +530,7 @@ public class MapObjectives{
/** Displays a shape with an outline and color. */ /** Displays a shape with an outline and color. */
public static class ShapeMarker extends ObjectiveMarker{ public static class ShapeMarker extends ObjectiveMarker{
public float x, y, radius = 6f, rotation = 0f, stroke = 1f; public float x, y, radius = 8f, rotation = 0f, stroke = 1f;
public boolean fill = false, outline = true; public boolean fill = false, outline = true;
public int sides = 4; public int sides = 4;
public Color color = Color.valueOf("ffd37f"); public Color color = Color.valueOf("ffd37f");
@ -552,6 +552,9 @@ public class MapObjectives{
@Override @Override
public void draw(){ public void draw(){
//in case some idiot decides to make 9999999 sides and freeze the game
int sides = Math.min(this.sides, 200);
if(!fill){ if(!fill){
if(outline){ if(outline){
Lines.stroke(stroke + 2f, Pal.gray); Lines.stroke(stroke + 2f, Pal.gray);
@ -611,7 +614,7 @@ public class MapObjectives{
//TODO localize //TODO localize
public String typeName(){ public String typeName(){
return getClass().getSimpleName().replace("Objective", ""); return getClass().getSimpleName().replace("Marker", "");
} }
/** Called in the overlay draw layer.*/ /** Called in the overlay draw layer.*/