mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-12-22 23:34:00 +07:00
Menu to copy/load objectives from clipboard
This commit is contained in:
parent
7b0d0ba10f
commit
13c0e95e6b
@ -1,5 +1,6 @@
|
||||
package mindustry.editor;
|
||||
|
||||
import arc.*;
|
||||
import arc.func.*;
|
||||
import arc.graphics.*;
|
||||
import arc.math.geom.*;
|
||||
@ -465,10 +466,42 @@ public class MapObjectivesDialog extends BaseDialog{
|
||||
buttons.defaults().size(160f, 64f).pad(2f);
|
||||
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("@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){
|
||||
buttons.button("@cancel", Icon.cancel, canvas::stopQuery).disabled(b -> !canvas.isQuerying());
|
||||
buttons.button("@ok", Icon.ok, canvas::placeQuery).disabled(b -> !canvas.isQuerying());
|
||||
buttons.button("@cancel", Icon.cancel, canvas::stopQuery).visible(() -> canvas.isQuerying());
|
||||
buttons.button("@ok", Icon.ok, canvas::placeQuery).visible(() -> canvas.isQuerying());
|
||||
}
|
||||
|
||||
setFillParent(true);
|
||||
@ -490,22 +523,27 @@ public class MapObjectivesDialog extends BaseDialog{
|
||||
public void show(Seq<MapObjective> objectives, Cons<Seq<MapObjective>> out){
|
||||
this.out = out;
|
||||
|
||||
rebuildObjectives(objectives);
|
||||
show();
|
||||
}
|
||||
|
||||
public void rebuildObjectives(Seq<MapObjective> objectives){
|
||||
canvas.clearObjectives();
|
||||
if(
|
||||
objectives.any() && (
|
||||
// If the objectives were previously programmatically made...
|
||||
objectives.contains(obj -> obj.editorX == -1 || obj.editorY == -1) ||
|
||||
// ... or some idiot somehow made it not work...
|
||||
objectives.contains(obj -> !canvas.tilemap.createTile(obj))
|
||||
objectives.any() && (
|
||||
// If the objectives were previously programmatically made...
|
||||
objectives.contains(obj -> obj.editorX == -1 || obj.editorY == -1) ||
|
||||
// ... or some idiot somehow made it not work...
|
||||
objectives.contains(obj -> !canvas.tilemap.createTile(obj))
|
||||
)){
|
||||
// ... then rebuild the structure.
|
||||
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.
|
||||
int w = objWidth + 2,
|
||||
len = objectives.size * w,
|
||||
columns = objectives.size,
|
||||
rows = 1;
|
||||
len = objectives.size * w,
|
||||
columns = objectives.size,
|
||||
rows = 1;
|
||||
|
||||
if(len > bounds){
|
||||
rows = len / bounds;
|
||||
@ -525,7 +563,6 @@ public class MapObjectivesDialog extends BaseDialog{
|
||||
}
|
||||
|
||||
canvas.objectives.set(objectives);
|
||||
show();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public MapObjectives(Seq<MapObjective> all){
|
||||
this.all.addAll(all);
|
||||
}
|
||||
|
||||
public MapObjectives(){
|
||||
}
|
||||
|
||||
/** Adds all given objectives to the executor as root objectives. */
|
||||
public void add(MapObjective... objectives){
|
||||
for(var objective : objectives) flatten(objective);
|
||||
|
Loading…
Reference in New Issue
Block a user