Search in sources :

Example 1 with Map

use of io.anuke.mindustry.world.Map in project Mindustry by Anuken.

the class MapEditorDialog method build.

public void build() {
    new table() {

        {
            float isize = 16 * 2f;
            aleft();
            new table() {

                {
                    defaults().growY().width(130f).padBottom(-6);
                    new imagebutton("icon-terrain", isize, () -> dialog.show()).text("$text.editor.generate");
                    row();
                    new imagebutton("icon-resize", isize, () -> resizeDialog.show()).text("$text.editor.resize").padTop(4f);
                    row();
                    new imagebutton("icon-load-map", isize, () -> loadDialog.show()).text("$text.editor.loadmap");
                    row();
                    new imagebutton("icon-save-map", isize, () -> saveDialog.show()).text("$text.editor.savemap");
                    row();
                    new imagebutton("icon-load-image", isize, () -> openFile.show()).text("$text.editor.loadimage");
                    row();
                    new imagebutton("icon-save-image", isize, () -> saveFile.show()).text("$text.editor.saveimage");
                    row();
                    new imagebutton("icon-back", isize, () -> {
                        if (!saved) {
                            ui.showConfirm("$text.confirm", "$text.editor.unsaved", MapEditorDialog.this::hide);
                        } else {
                            hide();
                        }
                    }).padBottom(0).text("$text.back");
                }
            }.left().growY().end();
            new table("button") {

                {
                    add(view).grow();
                }
            }.grow().end();
            new table() {

                {
                    Table tools = new Table("button");
                    tools.top();
                    tools.marginTop(0).marginBottom(6);
                    ButtonGroup<ImageButton> group = new ButtonGroup<>();
                    int i = 1;
                    tools.defaults().size(53f, 58f).padBottom(-6);
                    ImageButton undo = tools.addImageButton("icon-undo", 16 * 2f, () -> view.undo()).get();
                    ImageButton redo = tools.addImageButton("icon-redo", 16 * 2f, () -> view.redo()).get();
                    ImageButton grid = tools.addImageButton("icon-grid", "toggle", 16 * 2f, () -> view.setGrid(!view.isGrid())).get();
                    undo.setDisabled(() -> !view.getStack().canUndo());
                    redo.setDisabled(() -> !view.getStack().canRedo());
                    undo.update(() -> undo.getImage().setColor(undo.isDisabled() ? Color.GRAY : Color.WHITE));
                    redo.update(() -> redo.getImage().setColor(redo.isDisabled() ? Color.GRAY : Color.WHITE));
                    grid.update(() -> grid.setChecked(view.isGrid()));
                    for (EditorTool tool : EditorTool.values()) {
                        ImageButton button = new ImageButton("icon-" + tool.name(), "toggle");
                        button.clicked(() -> view.setTool(tool));
                        button.resizeImage(16 * 2f);
                        button.update(() -> button.setChecked(view.getTool() == tool));
                        group.add(button);
                        if (tool == EditorTool.pencil)
                            button.setChecked(true);
                        tools.add(button).padBottom(-6f);
                        if (i++ % 4 == 1)
                            tools.row();
                    }
                    add(tools).width(53 * 4).padBottom(-6);
                    row();
                    new table("button") {

                        {
                            margin(10f);
                            Slider slider = new Slider(0, MapEditor.brushSizes.length - 1, 1, false);
                            slider.moved(f -> editor.setBrushSize(MapEditor.brushSizes[(int) (float) f]));
                            new label(() -> Bundles.format("text.editor.brushsize", MapEditor.brushSizes[(int) slider.getValue()])).left();
                            row();
                            add(slider).growX().padTop(4f);
                        }
                    }.growX().padBottom(-6).end();
                    row();
                    new table("button") {

                        {
                            get().addCheck("$text.oregen", b -> editor.getMap().oreGen = b).update(c -> c.setChecked(editor.getMap().oreGen)).padTop(3).padBottom(3);
                        }
                    }.growX().padBottom(-6).end();
                    row();
                    addBlockSelection(get());
                    row();
                }
            }.right().growY().end();
        }
    }.grow().end();
}
Also used : Block(io.anuke.mindustry.world.Block) io.anuke.ucore.scene.builders.table(io.anuke.ucore.scene.builders.table) FileHandle(com.badlogic.gdx.files.FileHandle) Map(io.anuke.mindustry.world.Map) Strings(io.anuke.ucore.util.Strings) Arrays(java.util.Arrays) Bundles(io.anuke.ucore.util.Bundles) io.anuke.ucore.scene.builders.imagebutton(io.anuke.ucore.scene.builders.imagebutton) Blocks(io.anuke.mindustry.world.blocks.Blocks) Texture(com.badlogic.gdx.graphics.Texture) FileChooser(io.anuke.mindustry.ui.dialogs.FileChooser) Graphics(io.anuke.ucore.core.Graphics) BlockPair(io.anuke.mindustry.world.ColorMapper.BlockPair) Table(io.anuke.ucore.scene.ui.layout.Table) Log(io.anuke.ucore.util.Log) Vars(io.anuke.mindustry.Vars) Inputs(io.anuke.ucore.core.Inputs) Core(io.anuke.ucore.core.Core) Pixmap(com.badlogic.gdx.graphics.Pixmap) Platform(io.anuke.mindustry.io.Platform) Pixmaps(io.anuke.ucore.graphics.Pixmaps) Color(com.badlogic.gdx.graphics.Color) ColorMapper(io.anuke.mindustry.world.ColorMapper) Draw(io.anuke.ucore.graphics.Draw) Element(io.anuke.ucore.scene.Element) io.anuke.ucore.scene.ui(io.anuke.ucore.scene.ui) io.anuke.ucore.scene.builders.label(io.anuke.ucore.scene.builders.label) Keys(com.badlogic.gdx.Input.Keys) io.anuke.ucore.scene.builders.build(io.anuke.ucore.scene.builders.build) SpecialBlocks(io.anuke.mindustry.world.blocks.SpecialBlocks) Timers(io.anuke.ucore.core.Timers) Table(io.anuke.ucore.scene.ui.layout.Table) io.anuke.ucore.scene.builders.label(io.anuke.ucore.scene.builders.label) io.anuke.ucore.scene.builders.imagebutton(io.anuke.ucore.scene.builders.imagebutton) io.anuke.ucore.scene.builders.table(io.anuke.ucore.scene.builders.table)

Example 2 with Map

use of io.anuke.mindustry.world.Map in project Mindustry by Anuken.

the class LevelDialog method setup.

void setup() {
    Table maps = new Table();
    pane = new ScrollPane(maps);
    pane.setFadeScrollBars(false);
    int maxwidth = 4;
    Table selmode = new Table();
    ButtonGroup<TextButton> group = new ButtonGroup<>();
    selmode.add("$text.level.mode").padRight(15f);
    for (GameMode mode : GameMode.values()) {
        TextButton[] b = { null };
        b[0] = Elements.newButton("$mode." + mode.name() + ".name", "toggle", () -> state.mode = mode);
        b[0].update(() -> b[0].setChecked(state.mode == mode));
        group.add(b[0]);
        selmode.add(b[0]).size(130f, 54f);
    }
    selmode.addButton("?", this::displayGameModeHelp).size(50f, 54f).padLeft(18f);
    content().add(selmode);
    content().row();
    Difficulty[] ds = Difficulty.values();
    float s = 50f;
    Table sdif = new Table();
    sdif.add("$setting.difficulty.name").padRight(15f);
    sdif.defaults().height(s + 4);
    sdif.addImageButton("icon-arrow-left", 10 * 3, () -> {
        state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() - 1, ds.length)]);
    }).width(s);
    sdif.addButton("", () -> {
    }).update(t -> {
        t.setText(state.difficulty.toString());
        t.setTouchable(Touchable.disabled);
    }).width(180f);
    sdif.addImageButton("icon-arrow-right", 10 * 3, () -> {
        state.difficulty = (ds[Mathf.mod(state.difficulty.ordinal() + 1, ds.length)]);
    }).width(s);
    content().add(sdif);
    content().row();
    int i = 0;
    for (Map map : world.maps().list()) {
        if (!map.visible && !debug)
            continue;
        if (i % maxwidth == 0) {
            maps.row();
        }
        Table inset = new Table("pane-button");
        inset.add("[accent]" + Bundles.get("map." + map.name + ".name", map.name)).pad(3f);
        inset.row();
        inset.label((() -> {
            try {
                return Bundles.format("text.level.highscore", Settings.getInt("hiscore" + map.name));
            } catch (Exception e) {
                Settings.defaults("hiscore" + map.name, 1);
                return Bundles.format("text.level.highscore", 0);
            }
        })).pad(3f);
        inset.pack();
        float images = 154f;
        Stack stack = new Stack();
        Image back = new Image("white");
        back.setColor(map.backgroundColor);
        ImageButton image = new ImageButton(new TextureRegion(map.texture), "togglemap");
        image.row();
        image.add(inset).width(images + 6);
        TextButton[] delete = new TextButton[1];
        if (map.custom) {
            image.row();
            delete[0] = image.addButton("Delete", () -> {
                Timers.run(1f, () -> {
                    ui.showConfirm("$text.level.delete.title", Bundles.format("text.level.delete", Bundles.get("map." + map.name + ".name", map.name)), () -> {
                        world.maps().removeMap(map);
                        reload();
                        Core.scene.setScrollFocus(pane);
                    });
                });
            }).width(images + 16).padBottom(-10f).grow().get();
        }
        Vector2 hit = new Vector2();
        image.addListener(new ClickListener() {

            public void clicked(InputEvent event, float x, float y) {
                image.localToStageCoordinates(hit.set(x, y));
                if (delete[0] != null && (delete[0].getClickListener().isOver() || delete[0].getClickListener().isPressed() || (Core.scene.hit(hit.x, hit.y, true) != null && Core.scene.hit(hit.x, hit.y, true).isDescendantOf(delete[0])))) {
                    return;
                }
                selectedMap = map;
                hide();
                control.playMap(selectedMap);
            }
        });
        image.getImageCell().size(images);
        stack.add(back);
        stack.add(image);
        maps.add(stack).width(170).top().pad(4f);
        maps.marginRight(26);
        i++;
    }
    content().add(pane).uniformX();
    shown(() -> {
        // this is necessary for some reason?
        Timers.run(2f, () -> {
            Core.scene.setScrollFocus(pane);
        });
    });
}
Also used : Map(io.anuke.mindustry.world.Map) Core(io.anuke.ucore.core.Core) Bundles(io.anuke.ucore.util.Bundles) Settings(io.anuke.ucore.core.Settings) Stack(io.anuke.ucore.scene.ui.layout.Stack) Elements(io.anuke.ucore.scene.utils.Elements) InputEvent(io.anuke.ucore.scene.event.InputEvent) ClickListener(io.anuke.ucore.scene.event.ClickListener) io.anuke.ucore.scene.ui(io.anuke.ucore.scene.ui) Vector2(com.badlogic.gdx.math.Vector2) GameMode(io.anuke.mindustry.game.GameMode) Table(io.anuke.ucore.scene.ui.layout.Table) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Difficulty(io.anuke.mindustry.game.Difficulty) Mathf(io.anuke.ucore.util.Mathf) Timers(io.anuke.ucore.core.Timers) Vars(io.anuke.mindustry.Vars) Touchable(io.anuke.ucore.scene.event.Touchable) Table(io.anuke.ucore.scene.ui.layout.Table) Difficulty(io.anuke.mindustry.game.Difficulty) Stack(io.anuke.ucore.scene.ui.layout.Stack) GameMode(io.anuke.mindustry.game.GameMode) TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Vector2(com.badlogic.gdx.math.Vector2) InputEvent(io.anuke.ucore.scene.event.InputEvent) Map(io.anuke.mindustry.world.Map) ClickListener(io.anuke.ucore.scene.event.ClickListener)

Example 3 with Map

use of io.anuke.mindustry.world.Map in project Mindustry by Anuken.

the class Maps method loadMapFile.

private boolean loadMapFile(FileHandle file, boolean logException) {
    try {
        Array<Map> arr = json.fromJson(ArrayContainer.class, file).maps;
        if (arr != null) {
            // can be an empty map file
            for (Map map : arr) {
                map.pixmap = new Pixmap(file.sibling(map.name + ".png"));
                if (!headless)
                    map.texture = new Texture(map.pixmap);
                maps.put(map.id, map);
                mapNames.put(map.name, map);
                lastID = Math.max(lastID, map.id);
                if (!map.custom) {
                    defaultMaps.add(map);
                }
            }
        }
        return true;
    } catch (GdxRuntimeException e) {
        Log.err(e);
        return true;
    } catch (Exception e) {
        if (logException) {
            Log.err(e);
            Log.err("Failed loading map file: {0}", file);
        }
        return false;
    }
}
Also used : Map(io.anuke.mindustry.world.Map) Texture(com.badlogic.gdx.graphics.Texture) Pixmap(com.badlogic.gdx.graphics.Pixmap)

Example 4 with Map

use of io.anuke.mindustry.world.Map in project Mindustry by Anuken.

the class Maps method removeMap.

public void removeMap(Map map) {
    maps.remove(map.id);
    mapNames.remove(map.name);
    Array<Map> out = new Array<>();
    for (Map m : maps.values()) {
        if (m.custom) {
            out.add(m);
        }
    }
    saveMaps(out, customMapDirectory.child("maps.json"));
}
Also used : Map(io.anuke.mindustry.world.Map)

Example 5 with Map

use of io.anuke.mindustry.world.Map in project Mindustry by Anuken.

the class Maps method saveCustomMap.

public void saveCustomMap(Map toSave) {
    toSave.custom = true;
    Array<Map> out = new Array<>();
    boolean added = false;
    for (Map map : maps.values()) {
        if (map.custom) {
            if (map.name.equals(toSave.name)) {
                out.add(toSave);
                toSave.id = map.id;
                added = true;
            } else {
                out.add(map);
            }
        }
    }
    if (!added) {
        out.add(toSave);
    }
    maps.remove(toSave.id);
    mapNames.remove(toSave.name);
    maps.put(toSave.id, toSave);
    mapNames.put(toSave.name, toSave);
    Pixmaps.write(toSave.pixmap, customMapDirectory.child(toSave.name + ".png"));
    saveMaps(out, customMapDirectory.child("maps.json"));
}
Also used : Map(io.anuke.mindustry.world.Map)

Aggregations

Map (io.anuke.mindustry.world.Map)8 Table (io.anuke.ucore.scene.ui.layout.Table)3 Pixmap (com.badlogic.gdx.graphics.Pixmap)2 Texture (com.badlogic.gdx.graphics.Texture)2 Vars (io.anuke.mindustry.Vars)2 Difficulty (io.anuke.mindustry.game.Difficulty)2 GameMode (io.anuke.mindustry.game.GameMode)2 Core (io.anuke.ucore.core.Core)2 Timers (io.anuke.ucore.core.Timers)2 io.anuke.ucore.scene.ui (io.anuke.ucore.scene.ui)2 Bundles (io.anuke.ucore.util.Bundles)2 Keys (com.badlogic.gdx.Input.Keys)1 FileHandle (com.badlogic.gdx.files.FileHandle)1 Color (com.badlogic.gdx.graphics.Color)1 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)1 Vector2 (com.badlogic.gdx.math.Vector2)1 Player (io.anuke.mindustry.entities.Player)1 Platform (io.anuke.mindustry.io.Platform)1 PlayerInfo (io.anuke.mindustry.net.Administration.PlayerInfo)1 TraceInfo (io.anuke.mindustry.net.TraceInfo)1