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();
}
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);
});
});
}
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;
}
}
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"));
}
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"));
}
Aggregations