From 142e93f3e9a25c9997c3fddbc8f83114318bec81 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 18 Oct 2019 17:18:29 -0400 Subject: [PATCH] Schematic search button --- core/assets/bundles/bundle.properties | 2 + .../anuke/mindustry/input/DesktopInput.java | 3 + .../anuke/mindustry/input/InputHandler.java | 2 +- .../ui/dialogs/SchematicsDialog.java | 94 ++++++++++++++----- gradle.properties | 2 +- 5 files changed, 78 insertions(+), 25 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index bf023cb2e3..2791a512c7 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -223,6 +223,7 @@ loading = [accent]Loading... reloading = [accent]Reloading Mods... saving = [accent]Saving... cancelbuilding = [accent][[{0}][] to clear plan +selectschematic = [accent][[{0}][] to select+copy pausebuilding = [accent][[{0}][] to pause building resumebuilding = [scarlet][[{0}][] to resume building wave = [accent]Wave {0} @@ -632,6 +633,7 @@ keybind.press.axis = Press an axis or key... keybind.screenshot.name = Map Screenshot keybind.move_x.name = Move x keybind.move_y.name = Move y +keybind.schematic.name = Select Region keybind.schematic_flip_x.name = Flip Schematic X keybind.schematic_flip_y.name = Flip Schematic Y keybind.fullscreen.name = Toggle Fullscreen diff --git a/core/src/io/anuke/mindustry/input/DesktopInput.java b/core/src/io/anuke/mindustry/input/DesktopInput.java index f9135f8475..f76a3e199a 100644 --- a/core/src/io/anuke/mindustry/input/DesktopInput.java +++ b/core/src/io/anuke/mindustry/input/DesktopInput.java @@ -50,6 +50,8 @@ public class DesktopInput extends InputHandler{ b.label(() -> Core.bundle.format(!player.isBuilding ? "resumebuilding" : "pausebuilding", Core.keybinds.get(Binding.pause_building).key.name())).style(Styles.outlineLabel); b.row(); b.add(Core.bundle.format("cancelbuilding", Core.keybinds.get(Binding.clear_building).key.name())).style(Styles.outlineLabel); + b.row(); + b.add(Core.bundle.format("selectschematic", Core.keybinds.get(Binding.schematic).key.name())).style(Styles.outlineLabel); }).margin(10f); }); @@ -69,6 +71,7 @@ public class DesktopInput extends InputHandler{ lastSchematic.tags.put("name", text); schematics.add(lastSchematic); ui.showInfoFade("$schematic.saved"); + ui.schematics.showInfo(lastSchematic); }); }).colspan(2).size(250f, 50f); }); diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index 94e06a9328..cfdafc57fd 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -210,7 +210,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ if(request.breaking){ drawBreaking(request.x, request.y); }else{ - drawSelected(request.x, request.y, request.tile().block(), Pal.remove); + drawSelected(request.x, request.y, request.block, Pal.remove); } } diff --git a/core/src/io/anuke/mindustry/ui/dialogs/SchematicsDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/SchematicsDialog.java index 338176e1c5..eb1f7e32d2 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/SchematicsDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/SchematicsDialog.java @@ -5,12 +5,15 @@ import io.anuke.arc.scene.ui.*; import io.anuke.arc.util.*; import io.anuke.mindustry.game.*; import io.anuke.mindustry.game.Schematics.*; +import io.anuke.mindustry.gen.*; import io.anuke.mindustry.graphics.*; import io.anuke.mindustry.ui.*; import static io.anuke.mindustry.Vars.*; public class SchematicsDialog extends FloatingDialog{ + private SchematicInfoDialog info = new SchematicInfoDialog(); + private String search = ""; public SchematicsDialog(){ super("$schematics"); @@ -20,37 +23,82 @@ public class SchematicsDialog extends FloatingDialog{ } void setup(){ + search = ""; + Runnable[] rebuildPane = {null}; + + cont.top(); cont.clear(); + cont.table(s -> { + s.left(); + s.addImage(Icon.zoom).color(Pal.gray); + s.addField(search, res -> { + search = res; + rebuildPane[0].run(); + }).growX(); + }).fillX().padBottom(4); + + cont.row(); + cont.pane(t -> { t.top(); t.margin(20f); - int i = 0; - for(Schematic s : schematics.all()){ - Button sel = t.addButton(b -> { - Texture tex = schematics.getPreview(s, PreviewRes.high); - b.add(s.name()).center().color(Color.lightGray).fillY().get().setEllipsis(true); - b.row(); - b.add(new BorderImage(tex){ - @Override - public void draw(){ - //Draw.blend(Blending.disabled); - super.draw(); - //Draw.blend(); - } - }.setScaling(Scaling.fit).setName("border")); - }, () -> { - control.input.useSchematic(s); - hide(); - }).size(200f, 230f).pad(2).style(Styles.clearPartiali).get(); + rebuildPane[0] = () -> { + t.clear(); + int i = 0; + for(Schematic s : schematics.all()){ + if(!search.isEmpty() && !s.name().contains(search)) continue; - BorderImage image = sel.find("border"); - image.update(() -> image.borderColor = (sel.isOver() ? Pal.accent : Pal.gray)); + Button sel = t.addButton(b -> { + Texture tex = schematics.getPreview(s, PreviewRes.high); + b.add(s.name()).center().color(Color.lightGray).fillY().get().setEllipsis(true); + b.row(); + b.add(new BorderImage(tex){ + @Override + public void draw(){ + //Draw.blend(Blending.disabled); + super.draw(); + //Draw.blend(); + } + }.setScaling(Scaling.fit).setName("border")); + }, () -> { + control.input.useSchematic(s); + hide(); + }).size(200f, 230f).pad(2).style(Styles.clearPartiali).get(); - if(++i % 4 == 0){ - t.row(); + BorderImage image = sel.find("border"); + image.update(() -> image.borderColor = (sel.isOver() ? Pal.accent : Pal.gray)); + + if(++i % 4 == 0){ + t.row(); + } } - } + }; + + rebuildPane[0].run(); }).get().setScrollingDisabled(true, false); } + + public void showInfo(Schematic schematic){ + info.show(schematic); + } + + public static class SchematicInfoDialog extends FloatingDialog{ + + SchematicInfoDialog(){ + super(""); + setFillParent(false); + addCloseButton(); + } + + public void show(Schematic schem){ + cont.clear(); + title.setText(schem.name()); + + cont.add(new BorderImage(schematics.getPreview(schem, PreviewRes.high))).maxSize(400f); + cont.row(); + + show(); + } + } } diff --git a/gradle.properties b/gradle.properties index 4626fe4261..f8dffac1ba 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=795ded7ccae9aeb15ee480e3b9f6d6af57148ea0 +archash=3bd01eb4c67d11e36be2bd56f71e6928bf291345