Menu to copy/load objectives from clipboard
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package mindustry.editor;
|
package mindustry.editor;
|
||||||
|
|
||||||
|
import arc.*;
|
||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
import arc.graphics.*;
|
import arc.graphics.*;
|
||||||
import arc.math.geom.*;
|
import arc.math.geom.*;
|
||||||
@@ -465,10 +466,42 @@ public class MapObjectivesDialog extends BaseDialog{
|
|||||||
buttons.defaults().size(160f, 64f).pad(2f);
|
buttons.defaults().size(160f, 64f).pad(2f);
|
||||||
buttons.button("@back", Icon.left, MapObjectivesDialog.this::hide);
|
buttons.button("@back", Icon.left, MapObjectivesDialog.this::hide);
|
||||||
buttons.button("@add", Icon.add, () -> getProvider(MapObjective.class).get(new TypeInfo(MapObjective.class), canvas::query));
|
buttons.button("@add", Icon.add, () -> getProvider(MapObjective.class).get(new TypeInfo(MapObjective.class), canvas::query));
|
||||||
|
buttons.button("@waves.edit", Icon.edit, () -> {
|
||||||
|
BaseDialog dialog = new BaseDialog("@waves.edit");
|
||||||
|
dialog.addCloseButton();
|
||||||
|
dialog.setFillParent(false);
|
||||||
|
dialog.cont.table(Tex.button, t -> {
|
||||||
|
var style = Styles.cleart;
|
||||||
|
t.defaults().size(280f, 64f).pad(2f);
|
||||||
|
|
||||||
|
t.button("@waves.copy", Icon.copy, style, () -> {
|
||||||
|
ui.showInfoFade("@copied");
|
||||||
|
Core.app.setClipboardText(JsonIO.write(new MapObjectives(canvas.objectives)));
|
||||||
|
dialog.hide();
|
||||||
|
}).disabled(b -> canvas.objectives.isEmpty()).marginLeft(12f).row();
|
||||||
|
|
||||||
|
t.button("@waves.load", Icon.download, style, () -> {
|
||||||
|
try{
|
||||||
|
rebuildObjectives(new Seq<>(JsonIO.read(MapObjectives.class, Core.app.getClipboardText()).all));
|
||||||
|
}catch(Exception e){
|
||||||
|
Log.err(e);
|
||||||
|
ui.showErrorMessage("@waves.invalid");
|
||||||
|
}
|
||||||
|
dialog.hide();
|
||||||
|
}).disabled(Core.app.getClipboardText() == null || !Core.app.getClipboardText().startsWith("[")).marginLeft(12f).row();
|
||||||
|
|
||||||
|
t.button("@clear", Icon.none, style, () -> ui.showConfirm("@confirm", "@settings.clear.confirm", () -> {
|
||||||
|
rebuildObjectives(new Seq<>());
|
||||||
|
dialog.hide();
|
||||||
|
})).marginLeft(12f).row();
|
||||||
|
});
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
});
|
||||||
|
|
||||||
if(mobile){
|
if(mobile){
|
||||||
buttons.button("@cancel", Icon.cancel, canvas::stopQuery).disabled(b -> !canvas.isQuerying());
|
buttons.button("@cancel", Icon.cancel, canvas::stopQuery).visible(() -> canvas.isQuerying());
|
||||||
buttons.button("@ok", Icon.ok, canvas::placeQuery).disabled(b -> !canvas.isQuerying());
|
buttons.button("@ok", Icon.ok, canvas::placeQuery).visible(() -> canvas.isQuerying());
|
||||||
}
|
}
|
||||||
|
|
||||||
setFillParent(true);
|
setFillParent(true);
|
||||||
@@ -490,22 +523,27 @@ public class MapObjectivesDialog extends BaseDialog{
|
|||||||
public void show(Seq<MapObjective> objectives, Cons<Seq<MapObjective>> out){
|
public void show(Seq<MapObjective> objectives, Cons<Seq<MapObjective>> out){
|
||||||
this.out = out;
|
this.out = out;
|
||||||
|
|
||||||
|
rebuildObjectives(objectives);
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rebuildObjectives(Seq<MapObjective> objectives){
|
||||||
canvas.clearObjectives();
|
canvas.clearObjectives();
|
||||||
if(
|
if(
|
||||||
objectives.any() && (
|
objectives.any() && (
|
||||||
// If the objectives were previously programmatically made...
|
// If the objectives were previously programmatically made...
|
||||||
objectives.contains(obj -> obj.editorX == -1 || obj.editorY == -1) ||
|
objectives.contains(obj -> obj.editorX == -1 || obj.editorY == -1) ||
|
||||||
// ... or some idiot somehow made it not work...
|
// ... or some idiot somehow made it not work...
|
||||||
objectives.contains(obj -> !canvas.tilemap.createTile(obj))
|
objectives.contains(obj -> !canvas.tilemap.createTile(obj))
|
||||||
)){
|
)){
|
||||||
// ... then rebuild the structure.
|
// ... then rebuild the structure.
|
||||||
canvas.clearObjectives();
|
canvas.clearObjectives();
|
||||||
|
|
||||||
// This is definitely NOT a good way to do it, but only insane people or people from the distant past would actually encounter this anyway.
|
// This is definitely NOT a good way to do it, but only insane people or people from the distant past would actually encounter this anyway.
|
||||||
int w = objWidth + 2,
|
int w = objWidth + 2,
|
||||||
len = objectives.size * w,
|
len = objectives.size * w,
|
||||||
columns = objectives.size,
|
columns = objectives.size,
|
||||||
rows = 1;
|
rows = 1;
|
||||||
|
|
||||||
if(len > bounds){
|
if(len > bounds){
|
||||||
rows = len / bounds;
|
rows = len / bounds;
|
||||||
@@ -525,7 +563,6 @@ public class MapObjectivesDialog extends BaseDialog{
|
|||||||
}
|
}
|
||||||
|
|
||||||
canvas.objectives.set(objectives);
|
canvas.objectives.set(objectives);
|
||||||
show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends UnlockableContent> void showContentSelect(@Nullable ContentType type, Cons<T> cons, Boolf<T> check){
|
public static <T extends UnlockableContent> void showContentSelect(@Nullable ContentType type, Cons<T> cons, Boolf<T> check){
|
||||||
|
|||||||
@@ -106,6 +106,13 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
|||||||
JsonIO.classTag(name, type);
|
JsonIO.classTag(name, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MapObjectives(Seq<MapObjective> all){
|
||||||
|
this.all.addAll(all);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapObjectives(){
|
||||||
|
}
|
||||||
|
|
||||||
/** Adds all given objectives to the executor as root objectives. */
|
/** Adds all given objectives to the executor as root objectives. */
|
||||||
public void add(MapObjective... objectives){
|
public void add(MapObjective... objectives){
|
||||||
for(var objective : objectives) flatten(objective);
|
for(var objective : objectives) flatten(objective);
|
||||||
|
|||||||
Reference in New Issue
Block a user