1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-10-06 21:07:25 +03:00

WIP map info dialog changes

This commit is contained in:
Anuken 2022-06-23 16:32:37 -04:00
parent 342a7abf9b
commit a39fe2cb37
3 changed files with 125 additions and 28 deletions

View File

@ -1,10 +1,10 @@
package mindustry.editor;
import arc.*;
import arc.scene.ui.*;
import arc.struct.*;
import mindustry.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.io.*;
import mindustry.maps.filters.*;
import mindustry.ui.*;
@ -16,6 +16,7 @@ public class MapInfoDialog extends BaseDialog{
private final WaveInfoDialog waveInfo;
private final MapGenerateDialog generate;
private final CustomRulesDialog ruleInfo = new CustomRulesDialog();
private final MapObjectivesDialog objectives = new MapObjectivesDialog();
public MapInfoDialog(){
super("@editor.mapinfo");
@ -51,41 +52,49 @@ public class MapInfoDialog extends BaseDialog{
t.row();
t.add("@editor.author").padRight(8).left();
TextField author = t.field(tags.get("author", Core.settings.getString("mapAuthor", "")), text -> {
TextField author = t.field(tags.get("author", ""), text -> {
tags.put("author", text);
Core.settings.put("mapAuthor", text);
}).size(400, 55f).maxTextLength(50).get();
author.setMessageText("@unknown");
t.row();
t.add("@editor.rules").padRight(8).left();
t.button("@edit", () -> {
ruleInfo.show(Vars.state.rules, () -> Vars.state.rules = new Rules());
hide();
}).left().width(200f);
t.row();
t.add("@editor.waves").padRight(8).left();
t.button("@edit", () -> {
waveInfo.show();
hide();
}).left().width(200f);
t.table(Tex.button, r -> {
r.defaults().width(230f).height(60f);
t.row();
t.add("@editor.generation").padRight(8).left();
t.button("@edit", () -> {
//randomize so they're not all the same seed
var res = maps.readFilters(editor.tags.get("genfilters", ""));
res.each(GenerateFilter::randomize);
var style = Styles.flatt;
generate.show(res,
filters -> {
//reset seed to 0 so it is not written
filters.each(f -> f.seed = 0);
editor.tags.put("genfilters", JsonIO.write(filters));
});
hide();
}).left().width(200f);
r.button("@editor.rules", Icon.list, style, () -> {
ruleInfo.show(Vars.state.rules, () -> Vars.state.rules = new Rules());
hide();
}).marginLeft(10f);
r.button("@editor.waves", Icon.units, style, () -> {
waveInfo.show();
hide();
}).marginLeft(10f);
r.row();
r.button("@editor.objectives", Icon.info, style, () -> {
objectives.show(state.rules.objectives);
hide();
}).marginLeft(10f);
r.button("@editor.generation", Icon.terrain, style, () -> {
//randomize so they're not all the same seed
var res = maps.readFilters(editor.tags.get("genfilters", ""));
res.each(GenerateFilter::randomize);
generate.show(res,
filters -> {
//reset seed to 0 so it is not written
filters.each(f -> f.seed = 0);
editor.tags.put("genfilters", JsonIO.write(filters));
});
hide();
}).marginLeft(10f);
}).colspan(2).center();
name.change();
description.change();

View File

@ -0,0 +1,70 @@
package mindustry.editor;
import arc.*;
import arc.struct.*;
import mindustry.game.MapObjectives.*;
import mindustry.gen.*;
import mindustry.io.*;
import mindustry.ui.*;
import mindustry.ui.dialogs.*;
import static mindustry.Vars.*;
public class MapObjectivesDialog extends BaseDialog{
private Seq<MapObjective> objectives = new Seq<>();
public MapObjectivesDialog(){
super("@editor.objectives");
buttons.defaults().size(180f, 64f).pad(2f);
buttons.button("@back", Icon.left, this::hide);
buttons.button("@edit", Icon.edit, () -> {
BaseDialog dialog = new BaseDialog("@editor.export");
dialog.cont.pane(p -> {
p.margin(10f);
p.table(Tex.button, in -> {
var style = Styles.flatt;
in.defaults().size(280f, 60f).left();
in.button("@waves.copy", Icon.copy, style, () -> {
dialog.hide();
Core.app.setClipboardText(JsonIO.write(objectives));
}).marginLeft(12f).row();
in.button("@waves.load", Icon.download, style, () -> {
dialog.hide();
try{
objectives.set(JsonIO.read(Seq.class, Core.app.getClipboardText()));
setup();
}catch(Throwable e){
ui.showException(e);
}
}).marginLeft(12f).disabled(b -> Core.app.getClipboardText() == null).row();
in.button("@clear", Icon.none, style, () -> {
dialog.hide();
objectives.clear();
setup();
}).marginLeft(12f).row();
});
});
dialog.addCloseButton();
dialog.show();
});
}
public void show(Seq<MapObjective> objectives){
super.show();
this.objectives = objectives;
setup();
}
void setup(){
cont.clear();
cont.add("This editor doesn't work yet. Come back later.");
}
}

View File

@ -1,5 +1,6 @@
package mindustry.io;
import arc.graphics.*;
import arc.util.*;
import arc.util.serialization.*;
import arc.util.serialization.Json.*;
@ -72,6 +73,23 @@ public class JsonIO{
json.setElementType(Rules.class, "spawns", SpawnGroup.class);
json.setElementType(Rules.class, "loadout", ItemStack.class);
json.setSerializer(Color.class, new Serializer<>(){
@Override
public void write(Json json, Color object, Class knownType){
json.writeValue(object.toString());
}
@Override
public Color read(Json json, JsonValue jsonData, Class type){
if(jsonData.isString()){
return Color.valueOf(jsonData.asString());
}
Color out = new Color();
json.readFields(out, jsonData);
return out;
}
});
json.setSerializer(Sector.class, new Serializer<>(){
@Override
public void write(Json json, Sector object, Class knownType){