Search in sources :

Example 1 with SaveSlot

use of io.anuke.mindustry.io.Saves.SaveSlot in project Mindustry by Anuken.

the class LoadDialog method setup.

protected void setup() {
    content().clear();
    slots = new Table();
    pane = new ScrollPane(slots, "clear-black");
    pane.setFadeScrollBars(false);
    pane.setScrollingDisabled(true, false);
    slots.marginRight(24);
    Timers.runTask(2f, () -> Core.scene.setScrollFocus(pane));
    Array<SaveSlot> array = control.getSaves().getSaveSlots();
    for (SaveSlot slot : array) {
        TextButton button = new TextButton("[accent]" + slot.getName(), "clear");
        button.getLabelCell().growX().left();
        button.getLabelCell().padBottom(8f);
        button.getLabelCell().top().left().growX();
        button.defaults().left();
        button.table(t -> {
            t.right();
            t.addImageButton("icon-floppy", "emptytoggle", 14 * 3, () -> {
                slot.setAutosave(!slot.isAutosave());
            }).checked(slot.isAutosave()).right();
            t.addImageButton("icon-trash", "empty", 14 * 3, () -> {
                ui.showConfirm("$text.confirm", "$text.save.delete.confirm", () -> {
                    slot.delete();
                    setup();
                });
            }).size(14 * 3).right();
            t.addImageButton("icon-pencil-small", "empty", 14 * 3, () -> {
                ui.showTextInput("$text.save.rename", "$text.save.rename.text", slot.getName(), text -> {
                    slot.setName(text);
                    setup();
                });
            }).size(14 * 3).right();
            if (!gwt) {
                t.addImageButton("icon-save", "empty", 14 * 3, () -> {
                    new FileChooser("$text.save.export", false, file -> {
                        try {
                            slot.exportFile(file);
                            setup();
                        } catch (IOException e) {
                            ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
                        }
                    }).show();
                }).size(14 * 3).right();
            }
        }).padRight(-10).growX();
        String color = "[lightgray]";
        button.defaults().padBottom(3);
        button.row();
        button.add(Bundles.format("text.save.map", color + slot.getMap().localized()));
        button.row();
        button.add(Bundles.get("text.level.mode") + " " + color + slot.getMode());
        button.row();
        button.add(Bundles.format("text.save.wave", color + slot.getWave()));
        button.row();
        button.add(Bundles.format("text.save.difficulty", color + slot.getDifficulty()));
        button.row();
        button.label(() -> Bundles.format("text.save.autosave", color + Bundles.get(slot.isAutosave() ? "text.on" : "text.off")));
        button.row();
        button.add();
        button.add(Bundles.format("text.save.date", color + slot.getDate()));
        button.row();
        modifyButton(button, slot);
        slots.add(button).uniformX().fillX().pad(4).padRight(-4).margin(10f).marginLeft(20f).marginRight(20f);
        slots.row();
    }
    content().add(pane);
    addSetup();
}
Also used : TextButton(io.anuke.ucore.scene.ui.TextButton) Strings(io.anuke.ucore.util.Strings) SaveIO(io.anuke.mindustry.io.SaveIO) Core(io.anuke.ucore.core.Core) Array(com.badlogic.gdx.utils.Array) Bundles(io.anuke.ucore.util.Bundles) IOException(java.io.IOException) TextButton(io.anuke.ucore.scene.ui.TextButton) Table(io.anuke.ucore.scene.ui.layout.Table) Timers(io.anuke.ucore.core.Timers) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane) Log(io.anuke.ucore.util.Log) SaveSlot(io.anuke.mindustry.io.Saves.SaveSlot) Vars(io.anuke.mindustry.Vars) State(io.anuke.mindustry.core.GameState.State) Table(io.anuke.ucore.scene.ui.layout.Table) ScrollPane(io.anuke.ucore.scene.ui.ScrollPane) SaveSlot(io.anuke.mindustry.io.Saves.SaveSlot) IOException(java.io.IOException)

Aggregations

Array (com.badlogic.gdx.utils.Array)1 Vars (io.anuke.mindustry.Vars)1 State (io.anuke.mindustry.core.GameState.State)1 SaveIO (io.anuke.mindustry.io.SaveIO)1 SaveSlot (io.anuke.mindustry.io.Saves.SaveSlot)1 Core (io.anuke.ucore.core.Core)1 Timers (io.anuke.ucore.core.Timers)1 ScrollPane (io.anuke.ucore.scene.ui.ScrollPane)1 TextButton (io.anuke.ucore.scene.ui.TextButton)1 Table (io.anuke.ucore.scene.ui.layout.Table)1 Bundles (io.anuke.ucore.util.Bundles)1 Log (io.anuke.ucore.util.Log)1 Strings (io.anuke.ucore.util.Strings)1 IOException (java.io.IOException)1