Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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); }
}
73 changes: 64 additions & 9 deletions src/main/java/mindurka/rules/Castle.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,21 @@
import mindustry.content.Items;
import mindustry.game.Rules;
import mindustry.game.Team;
import mindustry.gen.Icon;
import mindustry.type.Item;
import mindustry.type.ItemStack;
import mindustry.type.StatusEffect;
import mindustry.type.UnitType;
import mindustry.ui.Fonts;
import mindustry.world.Block;
import mindustry.world.blocks.environment.Floor;
import mindustry.world.blocks.environment.Prop;
import mindustry.world.blocks.environment.SpawnBlock;
import mindustry.world.meta.Env;

import java.util.Iterator;

import static mindustry.Vars.state;
import static mindustry.Vars.*;

public class Castle extends Gamemode {

Expand Down Expand Up @@ -191,7 +195,7 @@ public void writeGamemodeRules(RulesWrite write) {
write.b("rules.mindurka.castle.mirrored", this::mirrored, this::mirrored);
write.b("rules.mindurka.castle.noPlatform", this::noPlatform, this::noPlatform);
write.b("rules.mindurka.castle.betterGroundValid", this::betterGroundValid, this::betterGroundValid);
write.block("rules.mindurka.castle.shopFloor", this::shopFloor, this::shopFloor);
write.block("rules.mindurka.castle.shopFloor", this::shopFloor, this::shopFloor).filter(block -> block instanceof Prop || block instanceof Floor);
}

@Override
Expand Down Expand Up @@ -220,6 +224,10 @@ public void drawEditorGuides() {
if (region != null && region.found()) {
Draw.rect(region, (sx + v2.x) / 2, (sy + v2.y) / 2, v2.x - sx, v2.y - sy);
}
Draw.reset();
Draw.color(Color.white);
Lines.rect(sx, sy, v2.x - sx, v2.y - sy);
Draw.reset();

GlyphLayout layout = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
Fonts.outline.getData().setScale(0.5f * Scl.scl(15) / (128 / MVars.mapView.zoom()));
Expand All @@ -237,10 +245,6 @@ public void drawEditorGuides() {
Pools.free(layout);
Fonts.outline.getData().setScale(1f);
Fonts.outline.setColor(Color.white);

Draw.reset();
Draw.color(Color.white);
Lines.rect(sx, sy, v2.x - sx, v2.y - sy);
}
for (int i = 0; i < miners.size; i++) {
Castle.CastleMiner miner = miners.items[i];
Expand All @@ -256,14 +260,18 @@ public void drawEditorGuides() {
if (region != null && region.found()) {
Draw.rect(region, (sx + v2.x) / 2, (sy + v2.y) / 2, v2.x - sx, v2.y - sy);
}
Draw.reset();
Draw.color(Color.white);
Lines.rect(sx, sy, v2.x - sx, v2.y - sy);
Draw.reset();

GlyphLayout layout = Pools.obtain(GlyphLayout.class, GlyphLayout::new);
Fonts.outline.getData().setScale(0.5f * Scl.scl(15) / (128 / MVars.mapView.zoom()));
String label =
Core.bundle.get("rules.mindurka.castle.item.cost")+": "+miner.cost+"\n"+
Core.bundle.get("rules.mindurka.castle.item.cost")+": "+miner.cost+"\n"+
Core.bundle.get("rules.mindurka.castle.item.interval")+": "+miner.interval+"\n"+
Core.bundle.get("rules.mindurka.castle.item.amount")+": "+miner.amount+"\n"+
Core.bundle.get("rules.mindurka.castle.item")+": "+miner.item;
Core.bundle.get("rules.mindurka.castle.item")+": "+miner.item.emoji()+"("+miner.item+")";
layout.setText(Fonts.outline, label);

float cx = (sx + v2.x) / 2;
Expand All @@ -277,11 +285,57 @@ public void drawEditorGuides() {
Fonts.outline.getData().setScale(1f);
Fonts.outline.setColor(Color.white);

}
TextureRegion groundUnitIcon = content.units().find(unit -> !unit.flying && !unit.naval && !unit.isHidden() && !unit.isBanned()).uiIcon;
TextureRegion flyingUnitIcon = content.units().find(unit -> unit.flying && !unit.canBoost && !unit.isHidden() && !unit.isBanned()).uiIcon;
TextureRegion navalUnit = content.units().find(unit -> unit.naval && !unit.isHidden() && !unit.isBanned()).uiIcon;
drawDefenseSpawn(groundSpawn,groundUnitIcon);
drawDefenseSpawn(airSpawn,flyingUnitIcon);
drawDefenseSpawn(navalSpawn,navalUnit);
drawDropZones(Icon.units.getRegion());
}
private void drawDefenseSpawn(Seq<Point2> spawns, TextureRegion icon){
float lineScale = Core.settings.getInt("mindurka.guideslinewidth", 1);
for(Point2 spawn : spawns){
float borderX = (float) spawn.x;
float borderY = (float) spawn.y-6;
float borderX2 = (float) 1+borderX;
float borderY2 = 12f+borderY;
Vec2 border = new Vec2(MVars.mapView.unproject(borderX,borderY));
Vec2 borderParam = MVars.mapView.unproject(borderX2,borderY2);
Vec2 borderParamNew = new Vec2(borderParam.x - border.x,borderParam.y-border.y);
Draw.reset();
Draw.color(Color.blue);
Lines.stroke(lineScale);
Lines.rect(border.x,border.y,borderParamNew.x,borderParamNew.y);
Draw.reset();
Draw.color(Color.white);
Lines.rect(sx, sy, v2.x - sx, v2.y - sy);
Vec2 newSpawn = new Vec2(MVars.mapView.unproject(spawn.x+0.5f,spawn.y+0.5f));
Vec2 v1 = MVars.mapView.unproject((float)spawn.x+1.5f,(float)spawn.y+1.5f);
Draw.rect(icon,newSpawn.x,newSpawn.y,v1.x-newSpawn.x,v1.y-newSpawn.y,-90);
Draw.reset();
}
}
private void drawDropZones(TextureRegion icon){
float lineScale = Core.settings.getInt("mindurka.guideslinewidth", 1);
world.tiles.eachTile(tile -> {
if(tile.overlay() instanceof SpawnBlock){
Draw.reset();
Draw.color(Color.scarlet);
Lines.stroke(lineScale);
Vec2 spawn = new Vec2(MVars.mapView.unproject((float)tile.x+0.5f,(float)tile.y+0.5f));
Vec2 v3 = new Vec2(MVars.mapView.unproject(tile.x,tile.y - rc.rules.dropZoneRadius / tilesize));
Lines.circle(spawn.x,spawn.y,(spawn.y - v3.y) / tilesize);
Draw.reset();
Draw.color(Color.white);
Vec2 corner1 = new Vec2(MVars.mapView.unproject(tile.x-1.5f,tile.y-1.25f));
Vec2 corner2 = MVars.mapView.unproject(tile.x+1.5f,tile.y+1.25f);
float w = corner2.x - corner1.x;
float h = corner2.y - corner1.y;
Draw.rect(icon, spawn.x, spawn.y, w, h);
}
});
}

private final ObjectIntMap<Block> blockCostMap = new ObjectIntMap<>();

Expand Down Expand Up @@ -507,6 +561,7 @@ protected void _setRules() {
rules.coreIncinerates = true;
rules.buildCostMultiplier = 1f;
rules.buildSpeedMultiplier = 0.5f;
rules.dropZoneRadius = tilesize*6f;
rules.deconstructRefundMultiplier = 0.5f;
rules.blockHealthMultiplier = 1f;
rules.unitDamageMultiplier = 1f;
Expand Down
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
17 changes: 13 additions & 4 deletions src/main/java/mindurka/rules/SchematicEditorAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import arc.math.geom.Point2;
import arc.math.geom.Vec2;
import arc.scene.ui.layout.Scl;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import mindurka.ui.OMapView;
import mindurka.ui.SpecialEditorAction;
Expand All @@ -16,12 +17,20 @@

@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;

@Getter
private final Schematic.Options options;

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

@Override
public boolean clicked(OMapView view, float mouseX, float mouseY) {
Point2 p = view.project(mouseX, mouseY);
Expand All @@ -30,7 +39,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
28 changes: 15 additions & 13 deletions src/main/java/mindurka/ui/EditorTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import mindurka.rules.*;
import mindustry.Vars;
import mindustry.content.Blocks;
import mindustry.game.Team;
import mindustry.type.Item;
import mindustry.ui.Styles;
import mindustry.world.Block;
Expand Down Expand Up @@ -140,12 +141,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;
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 +159,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 Expand Up @@ -324,11 +330,11 @@ public void toolOptions(Table table) {

table.label(() -> "@rules.mindurka.castle.block.cost").left().pad(6).row();
table.field(String.valueOf(MVars.toolOptions.blockCostFor(MVars.toolOptions.current.selectedBlock)), text -> {
MVars.toolOptions.blockCost = Integer.parseInt(text);
if(!text.isEmpty())MVars.toolOptions.blockCost = Integer.parseInt(text);
}).growX().left().row();
table.label(() -> "@rules.status.invincible").left().pad(6).row();
table.field(String.valueOf(MVars.toolOptions.invincible || MVars.toolOptions.current.selectedBlock instanceof Turret), text -> {
MVars.toolOptions.invincible = Boolean.parseBoolean(text);
if(!text.isEmpty())MVars.toolOptions.invincible = Boolean.parseBoolean(text);
}).growX().left().row();
}

Expand Down Expand Up @@ -402,10 +408,6 @@ public void toolOptions(Table table) {
table.field(String.valueOf(MVars.toolOptions.minerCostFor(MVars.toolOptions.selectedItemCastle)), text -> {
MVars.toolOptions.minerCost = Integer.parseInt(text);
}).growX().left().row();
table.label(() -> "@rules.mindurka.castle.drill").left().pad(6).row();
table.field(String.valueOf(MVars.toolOptions.current.selectedBlock), text -> {
MVars.toolOptions.minerDrill = MVars.toolOptions.current.selectedBlock;
}).growX().left().row();
table.label(() -> "@rules.mindurka.castle.item").left().pad(6).row();
table.table(t -> {
int i = 0;
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
21 changes: 20 additions & 1 deletion src/main/java/mindurka/ui/OEditorDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,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("schematic.skipEmpty", "Skip empty floors"), opts.skipEmpty, v -> opts.skipEmpty = v).row();
optionsTable.check(Core.bundle.get("schematic.skipAir", "Skip air blocks"), opts.skipAir, v -> opts.skipAir = v).row();
optionsTable.check(Core.bundle.get("schematic.skipBuildings", "Skip buildings"), opts.skipBuildings, v -> opts.skipBuildings = v).row();
optionsTable.check(Core.bundle.get("schematic.skipNoOverlay", "Skip air overlays"), opts.skipNoOverlay, v -> opts.skipNoOverlay = v).row();
// 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
Loading
Loading