Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions src/main/java/mindurka/MVars.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,16 @@ private MVars() {}

public static boolean patchEditorLoaded = false;

// FIXME: This is bullshit.
private static final BitMap[] mapbitsPool = new BitMap[2];

private static BitMap mapbits = null;
public static BitMap mapbits() {
if (mapbits == null || mapbits.width != Vars.world.width() || mapbits.height != Vars.world.height()) {
mapbits = BitMap.of(Vars.world.tiles);
private static BitMap mapbits(int index) {
BitMap b = mapbitsPool[index];
if (b == null || b.width != Vars.world.width() || b.height != Vars.world.height()) {
mapbitsPool[index] = b = BitMap.of(Vars.world.tiles);
}
return mapbits;
}
private static BitMap mapbits2 = null;
public static BitMap mapbits2() {
if (mapbits2 == null || mapbits2.width != Vars.world.width() || mapbits2.height != Vars.world.height()) {
mapbits2 = BitMap.of(Vars.world.tiles);
}
return mapbits2;
return b;
}

public static BitMap mapbits() { return mapbits(0); }
public static BitMap mapbits2() { return mapbits(1); }
}
6 changes: 3 additions & 3 deletions src/main/java/mindurka/rules/FortsPlotKindSquare.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ public void writeRules(RulesWrite write) {
public void writeTeamRules(Team team, RulesWrite write) {
write.button("rules.mindurka.forts.plot.schematic", () -> {
MVars.mapView.editorAction = new SchematicEditorAction(
wallsSize() * 2 + size, wallsSize() * 2 + size, scheme -> {
plotSchematic(team, scheme);
});
wallsSize() * 2 + size, wallsSize() * 2 + size,
scheme -> plotSchematic(team, scheme)
);
MVars.customRulesDialog.hide();
});
}
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/mindurka/rules/SchematicEditorAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,39 @@
import arc.math.geom.Point2;
import arc.math.geom.Vec2;
import arc.scene.ui.layout.Scl;
import lombok.RequiredArgsConstructor;
import mindurka.ui.OMapView;
import mindurka.ui.SpecialEditorAction;
import mindurka.util.FormatException;
import mindurka.util.Schematic;
import mindustry.Vars;
import mindustry.graphics.Pal;

@RequiredArgsConstructor
public class SchematicEditorAction implements SpecialEditorAction {
// TODO: Make it configurable.
private static final Schematic.Options OPTIONS = new Schematic.Options().skipEmpty().skipAir().skipBuildings();

private final int width, height;
private final Cons<Schematic> accepted;
private final Schematic.Options options;

public SchematicEditorAction(int width, int height, Cons<Schematic> accepted) {
Schematic.Options opts = new Schematic.Options();
opts.skipEmpty = true;
opts.skipAir = true;
opts.skipBuildings = true;
this.width = width;
this.height = height;
this.accepted = accepted;
this.options = opts;
}

public SchematicEditorAction(int width, int height, Cons<Schematic> accepted, Schematic.Options options) {
this.width = width;
this.height = height;
this.accepted = accepted;
this.options = options;
}
Comment thread
RE-AST marked this conversation as resolved.
Resolved
Comment thread
RE-AST marked this conversation as resolved.
Resolved

public Schematic.Options getOptions() {
return options;
}

@Override
public boolean clicked(OMapView view, float mouseX, float mouseY) {
Expand All @@ -30,7 +48,7 @@ public boolean clicked(OMapView view, float mouseX, float mouseY) {
|| p.y >= Vars.world.height() - height) return false;
Schematic scheme;
try {
scheme = Schematic.of(Vars.world.tiles, p.x, p.y, width, height, OPTIONS);
scheme = Schematic.of(Vars.world.tiles, p.x, p.y, width, height, options);
} catch (FormatException e) {
throw new RuntimeException("Unreachable!", e);
}
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/mindurka/ui/EditorTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,15 @@ public void touched(ToolContext ctx, int x1, int y1, int x2, int y2) {

EditorTool.line(x1, y1, x2, y2, (x, y) -> {
if (x < 0 || y < 0 || x >= ctx.width() || y >= ctx.height()) return;
Block target = MVars.toolOptions.selectedBlock().isOverlay()
Block selected = MVars.toolOptions.selectedBlock();
boolean isBlock = !selected.isOverlay() && !selected.isFloor();
Block target = selected.isOverlay()
? ctx.overlay(x, y)
: MVars.toolOptions.selectedBlock().isFloor()
: selected.isFloor()
? ctx.floor(x, y)
: ctx.block(x, y);
if (ctx.block(x, y) == MVars.toolOptions.selectedBlock()) return;
mindustry.game.Team targetTeam = isBlock ? ctx.team(x, y) : null;
if (ctx.block(x, y) == selected && (!isBlock || ctx.team(x, y) == MVars.toolOptions.team())) return;

points.add(Util.packxy(x2, y2));

Expand All @@ -155,12 +158,14 @@ public void touched(ToolContext ctx, int x1, int y1, int x2, int y2) {
int py = Util.unpacky(point);
if (bits.toggled(px, py)) continue;
if (px < 0 || py < 0 || px >= ctx.width() || py >= ctx.height()) continue;
if ((MVars.toolOptions.selectedBlock().isOverlay()
Block at = selected.isOverlay()
? ctx.overlay(px, py)
: MVars.toolOptions.selectedBlock().isFloor()
: selected.isFloor()
? ctx.floor(px, py)
: ctx.block(px, py)) != target) continue;
ctx.setAny(px, py, MVars.toolOptions.selectedBlock());
: ctx.block(px, py);
if (at != target) continue;
if (isBlock && ctx.team(px, py) != targetTeam) continue;
ctx.setAny(px, py, selected);
bits.enable(px, py);

points.add(Util.packxy(px + 1, py));
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/mindurka/ui/EraseToolContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ public Block overlay(int x, int y) {
return tile.overlay();
}

@Override
public Team team(int x, int y) {
Tile tile = Vars.world.tiles.get(x, y);
if (tile == null) return Team.derelict;
return tile.team();
}

@Override
public int width() {
return Vars.world.width();
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/mindurka/ui/LayerToolContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ public Block overlay(int x, int y) {
return tile.overlay();
}

@Override
public Team team(int x, int y) {
Tile tile = Vars.world.tiles.get(x, y);
if (tile == null) return Team.derelict;
return tile.team();
}

@Override
public int width() {
return Vars.world.width();
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/mindurka/ui/OEditorDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ public void build() {
grid.update(() -> grid.setChecked(view.isGrid()));

addMode.get(EditorMode.zoom);
addMode.get(EditorMode.eraser);
Comment thread
RE-AST marked this conversation as resolved.
Resolved
tools.row();
addTool.get(EditorTool.pencil);
addTool.get(EditorTool.line);
Expand Down Expand Up @@ -420,7 +419,26 @@ public void build() {
button.setChecked(true);
});
button.setChecked(true);
t.add(button).size(size, size).left().top();
t.add(button).size(size, size).left().top().row();

Table optionsTable = new Table();
t.add(optionsTable).left().top().row();
t.update(() -> {
if (view.editorAction instanceof mindurka.rules.SchematicEditorAction) {
mindurka.util.Schematic.Options opts =
((mindurka.rules.SchematicEditorAction) view.editorAction).getOptions();
if (optionsTable.getChildren().isEmpty()) {
optionsTable.defaults().left().pad(2f);
optionsTable.check(Core.bundle.get("rules.schematic.skipEmpty", "Skip empty floors"), opts.skipEmpty, v -> opts.skipEmpty = v).row();
optionsTable.check(Core.bundle.get("rules.schematic.skipAir", "Skip air blocks"), opts.skipAir, v -> opts.skipAir = v).row();
optionsTable.check(Core.bundle.get("rules.schematic.skipBuildings", "Skip buildings"), opts.skipBuildings, v -> opts.skipBuildings = v).row();
optionsTable.check(Core.bundle.get("rules.schematic.skipNoOverlay", "Skip air overlays"), opts.skipNoOverlay, v -> opts.skipNoOverlay = v).row();
Comment thread
RE-AST marked this conversation as resolved.
Resolved
// TODO: Add team option.
}
} else {
optionsTable.clear();
}
});
}).grow();
Comment thread
RE-AST marked this conversation as resolved.
Resolved
midOverlay.background(Tex.whiteui);
midOverlay.setColor(Color.black);
Expand Down
52 changes: 51 additions & 1 deletion src/main/java/mindurka/ui/OMapEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,57 @@ private void createTiles(int width, int height) {

@Override
public void resize(int width, int height, int shiftX, int shiftY) {
super.resize(width, height, shiftX, shiftY);
clearOp();

Tiles previous = Vars.world.tiles;
int offsetX = (width() - width) / 2 - shiftX, offsetY = (height() - height) / 2 - shiftY;
loading = true;

Vars.world.clearBuildings();

Tiles tiles = Vars.world.tiles = new Tiles(width, height);

for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int px = offsetX + x, py = offsetY + y;
if (previous.in(px, py)) {
tiles.set(x, y, previous.getn(px, py));
Tile tile = tiles.getn(x, y);

Object config = null;
if (tile.build != null && tile.isCenter()) {
config = tile.build.config();
}

tile.x = (short) x;
tile.y = (short) y;

if (tile.build != null && tile.isCenter()) {
tile.build.x = x * Vars.tilesize + tile.block().offset;
tile.build.y = y * Vars.tilesize + tile.block().offset;

if (config != null) {
Object out = mindustry.entities.units.BuildPlan.pointConfig(tile.block(), config, p -> {
if (!tile.build.block.ignoreResizeConfig) {
p.sub(offsetX, offsetY);
}
});
if (out != config) {
boolean prev = Vars.state.rules.editor;
Vars.state.rules.editor = true;
tile.build.configureAny(out);
Vars.state.rules.editor = prev;
}
}
}
} else {
tiles.set(x, y, new EditorTile(x, y, Blocks.stone.id, 0, 0));
}
}
}

renderer.resize(width, height);
loading = false;
MVars.rules = new MRules(Vars.state.rules, Vars.world.width(), Vars.world.height());
}

Expand Down
66 changes: 51 additions & 15 deletions src/main/java/mindurka/ui/OMapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,11 @@ public boolean touchDown(InputEvent event, float x, float y, int pointer, KeyCod
// Krita/Voidsprite/iBIS/AnyImageEdtiorInExistence-like binds cuz they are infinitely better than
// whatever the fuck Anuke cooked, and you're obligated to agree.
if (Vars.mobile || button == KeyCode.mouseLeft) {
// To be entirely fair, if your tool is zoom this is the same as zoom action.
if (editorAction != null) {
mousea = MouseAction.Draw.Cancelled.begin();
SpecialEditorAction prev = editorAction;
editorAction = null;
dragging = false;
prev.clicked(OMapView.this, x, y);
redrawPreview = true;
mousex = x;
mousey = y;
dragging = true;
return true;
} else mousea = MVars.toolOptions.mode.drawAction(x, y);
} else if (button == KeyCode.mouseRight) {
Expand Down Expand Up @@ -228,6 +225,16 @@ public void touchUp(InputEvent event, float x, float y, int pointer, KeyCode but
boolean isMain = activeTouches[0] != null && activeTouches[0].pointer == pointer;
removeTouch(pointer, button);

if (editorAction != null && dragging && isMain) {
SpecialEditorAction prev = editorAction;
editorAction = null;
mousea = null;
dragging = false;
prev.clicked(OMapView.this, x, y);
redrawPreview = true;
return;
}

if (mousea != null) {
if (mousea instanceof MouseAction.TouchDrag) {
if (activeTouches() == 0) mousea = null;
Expand Down Expand Up @@ -418,25 +425,54 @@ public void draw() {
} else MVars.toolOptions.tool.touched(previewMap, s.x, s.y, s.x, s.y);
}

// FIXME: Potential performance penalty for drawing a ton of one-length lines
if (previewMap.hasRegion) {
Draw.color(Pal.accent);
Lines.stroke(Scl.scl(2f));
for (int x = previewMap.startx; x <= previewMap.endx + 1; x++) for (int y = previewMap.starty; y <= previewMap.endy + 1; y++) {
boolean enabled = previewMap.bitmap.toggled(x, y);
if (enabled != previewMap.bitmap.toggled(x - 1, y)) {
Vec2 s = unproject(x, y);

for (int x = previewMap.startx; x <= previewMap.endx + 1; x++) {
int runStart = -1;
for (int y = previewMap.starty; y <= previewMap.endy + 1; y++) {
boolean border = previewMap.bitmap.toggled(x, y) != previewMap.bitmap.toggled(x - 1, y);
if (border && runStart == -1) {
runStart = y;
} else if (!border && runStart != -1) {
Vec2 s = unproject(x, runStart);
float sx = s.x, sy = s.y;
s = unproject(x, y);
Lines.line(sx, sy, s.x, s.y);
runStart = -1;
}
}
if (runStart != -1) {
Vec2 s = unproject(x, runStart);
float sx = s.x, sy = s.y;
s = unproject(x, y + 1);
s = unproject(x, previewMap.endy + 2);
Lines.line(sx, sy, s.x, s.y);
}
if (enabled != previewMap.bitmap.toggled(x, y - 1)) {
Vec2 s = unproject(x + 1, y);
}

for (int y = previewMap.starty; y <= previewMap.endy + 1; y++) {
int runStart = -1;
for (int x = previewMap.startx; x <= previewMap.endx + 1; x++) {
boolean border = previewMap.bitmap.toggled(x, y) != previewMap.bitmap.toggled(x, y - 1);
if (border && runStart == -1) {
runStart = x;
} else if (!border && runStart != -1) {
Vec2 s = unproject(runStart, y);
float sx = s.x, sy = s.y;
s = unproject(x, y);
Lines.line(sx, sy, s.x, s.y);
runStart = -1;
}
}
if (runStart != -1) {
Vec2 s = unproject(runStart, y);
float sx = s.x, sy = s.y;
s = unproject(x, y);
s = unproject(previewMap.endx + 2, y);
Lines.line(sx, sy, s.x, s.y);
}
}

Draw.reset();
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/mindurka/ui/PreviewToolContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ public Block overlay(int x, int y) {
return tile.overlay();
}

@Override
public Team team(int x, int y) {
Tile tile = Vars.world.tile(x, y);
if (tile == null) return Team.derelict;
return tile.team();
}

Comment thread
RE-AST marked this conversation as resolved.
Resolved
@Override
public int width() {
return Vars.world.width();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mindurka/ui/ToolContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface ToolContext {
Block block(int x, int y);
Floor floor(int x, int y);
Block overlay(int x, int y);
Team team(int x, int y);

int width();
int height();
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/bundles/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ rules.mindurka.forts.plot.shiftX = Grid X Shift
rules.mindurka.forts.plot.shiftY = Grid Y Shift
rules.mindurka.forts.plot.schematic = Set Plot Schematic

rules.schematic.options = Schematic Options
rules.schematic.skipEmpty = Skip empty floors
rules.schematic.skipAir = Skip air blocks
rules.schematic.skipBuildings = Skip buildings
rules.schematic.skipNoOverlay = Skip air overlays
rules.schematic.select = Select Area

rules.mindurka.forts.apply_damage_effects = Apply Damage Effects
rules.mindurka.forts.min_health = Minimum Total Block Health

Expand Down
Loading