Partial 7.0 merge - API preview

This commit is contained in:
Anuken
2021-06-02 11:08:08 -04:00
parent ea75a357ca
commit 28b235ef07
531 changed files with 12356 additions and 6286 deletions

View File

@@ -10,13 +10,8 @@ import mindustry.world.blocks.environment.*;
import static mindustry.Vars.*;
public class DrawOperation{
private MapEditor editor;
private LongSeq array = new LongSeq();
public DrawOperation(MapEditor editor){
this.editor = editor;
}
public boolean isEmpty(){
return array.isEmpty();
}

View File

@@ -77,7 +77,7 @@ public class EditorTile extends Tile{
op(OpType.team, (byte)getTeamID());
super.setTeam(team);
getLinkedTiles(t -> ui.editor.editor.renderer.updatePoint(t.x, t.y));
getLinkedTiles(t -> editor.renderer.updatePoint(t.x, t.y));
}
@Override
@@ -140,14 +140,14 @@ public class EditorTile extends Tile{
}
private void update(){
ui.editor.editor.renderer.updatePoint(x, y);
editor.renderer.updatePoint(x, y);
}
private boolean skip(){
return state.isGame() || ui.editor.editor.isLoading();
return state.isGame() || editor.isLoading();
}
private void op(OpType type, short value){
ui.editor.editor.addTileOp(TileOp.get(x, y, (byte)type.ordinal(), value));
editor.addTileOp(TileOp.get(x, y, (byte)type.ordinal(), value));
}
}

View File

@@ -9,11 +9,12 @@ import arc.util.*;
import mindustry.content.*;
import mindustry.game.*;
import mindustry.world.*;
import static mindustry.Vars.*;
public enum EditorTool{
zoom(KeyCode.v),
pick(KeyCode.i){
public void touched(MapEditor editor, int x, int y){
public void touched(int x, int y){
if(!Structs.inBounds(x, y, editor.width(), editor.height())) return;
Tile tile = editor.tile(x, y);
@@ -23,7 +24,7 @@ public enum EditorTool{
line(KeyCode.l, "replace", "orthogonal"){
@Override
public void touchedLine(MapEditor editor, int x1, int y1, int x2, int y2){
public void touchedLine(int x1, int y1, int x2, int y2){
//straight
if(mode == 1){
if(Math.abs(x2 - x1) > Math.abs(y2 - y1)){
@@ -51,7 +52,7 @@ public enum EditorTool{
}
@Override
public void touched(MapEditor editor, int x, int y){
public void touched(int x, int y){
if(mode == -1){
//normal mode
editor.drawBlocks(x, y);
@@ -75,7 +76,7 @@ public enum EditorTool{
}
@Override
public void touched(MapEditor editor, int x, int y){
public void touched(int x, int y){
editor.drawCircle(x, y, tile -> {
if(mode == -1){
//erase block
@@ -95,13 +96,13 @@ public enum EditorTool{
IntSeq stack = new IntSeq();
@Override
public void touched(MapEditor editor, int x, int y){
public void touched(int x, int y){
if(!Structs.inBounds(x, y, editor.width(), editor.height())) return;
Tile tile = editor.tile(x, y);
if(editor.drawBlock.isMultiblock()){
//don't fill multiblocks, thanks
pencil.touched(editor, x, y);
pencil.touched(x, y);
return;
}
@@ -133,19 +134,19 @@ public enum EditorTool{
}
//replace only when the mode is 0 using the specified functions
fill(editor, x, y, mode == 0, tester, setter);
fill(x, y, mode == 0, tester, setter);
}else if(mode == 1){ //mode 1 is team fill
//only fill synthetic blocks, it's meaningless otherwise
if(tile.synthetic()){
Team dest = tile.team();
if(dest == editor.drawTeam) return;
fill(editor, x, y, false, t -> t.getTeamID() == dest.id && t.synthetic(), t -> t.setTeam(editor.drawTeam));
fill(x, y, false, t -> t.getTeamID() == dest.id && t.synthetic(), t -> t.setTeam(editor.drawTeam));
}
}
}
void fill(MapEditor editor, int x, int y, boolean replace, Boolf<Tile> tester, Cons<Tile> filler){
void fill(int x, int y, boolean replace, Boolf<Tile> tester, Cons<Tile> filler){
int width = editor.width(), height = editor.height();
if(replace){
@@ -215,7 +216,7 @@ public enum EditorTool{
}
@Override
public void touched(MapEditor editor, int x, int y){
public void touched(int x, int y){
//floor spray
if(editor.drawBlock.isFloor()){
@@ -263,7 +264,7 @@ public enum EditorTool{
this.key = code;
}
public void touched(MapEditor editor, int x, int y){}
public void touched(int x, int y){}
public void touchedLine(MapEditor editor, int x1, int y1, int x2, int y2){}
public void touchedLine(int x1, int y1, int x2, int y2){}
}

View File

@@ -21,7 +21,7 @@ public class MapEditor{
public static final int[] brushSizes = {1, 2, 3, 4, 5, 9, 15, 20};
public StringMap tags = new StringMap();
public MapRenderer renderer = new MapRenderer(this);
public MapRenderer renderer = new MapRenderer();
private final Context context = new Context();
private OperationStack stack = new OperationStack();
@@ -62,7 +62,7 @@ public class MapEditor{
public void beginEdit(Pixmap pixmap){
reset();
createTiles(pixmap.getWidth(), pixmap.getHeight());
createTiles(pixmap.width, pixmap.height);
load(() -> MapIO.readImage(pixmap, tiles()));
renderer.resize(width(), height());
}
@@ -330,7 +330,7 @@ public class MapEditor{
public void addTileOp(long data){
if(loading) return;
if(currentOp == null) currentOp = new DrawOperation(this);
if(currentOp == null) currentOp = new DrawOperation();
currentOp.addOperation(data);
renderer.updatePoint(TileOp.x(data), TileOp.y(data));

View File

@@ -33,8 +33,6 @@ import mindustry.world.meta.*;
import static mindustry.Vars.*;
public class MapEditorDialog extends Dialog implements Disposable{
public final MapEditor editor;
private MapView view;
private MapInfoDialog infoDialog;
private MapLoadDialog loadDialog;
@@ -53,10 +51,9 @@ public class MapEditorDialog extends Dialog implements Disposable{
background(Styles.black);
editor = new MapEditor();
view = new MapView(editor);
infoDialog = new MapInfoDialog(editor);
generateDialog = new MapGenerateDialog(editor, true);
view = new MapView();
infoDialog = new MapInfoDialog();
generateDialog = new MapGenerateDialog(true);
menu = new BaseDialog("@menu");
menu.addCloseButton();
@@ -120,7 +117,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
"@editor.exportimage", "@editor.exportimage.description", Icon.fileImage,
(Runnable)() -> platform.export(editor.tags.get("name", "unknown"), "png", file -> {
Pixmap out = MapIO.writeImage(editor.tiles());
file.writePNG(out);
file.writePng(out);
out.dispose();
})));
});
@@ -173,7 +170,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
menu.hide();
}).size(swidth * 2f + 10, 60f);
resizeDialog = new MapResizeDialog(editor, (x, y) -> {
resizeDialog = new MapResizeDialog((x, y) -> {
if(!(editor.width() == x && editor.height() == y)){
ui.loadAnd(() -> {
editor.resize(x, y);
@@ -639,7 +636,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
for(int x = 0; x < editor.width(); x++){
for(int y = 0; y < editor.height(); y++){
Tile tile = editor.tile(x, y);
if(tile.block().breakable && tile.block() instanceof Boulder){
if(tile.block().breakable && tile.block() instanceof Prop){
tile.setBlock(Blocks.air);
editor.renderer.updatePoint(x, y);
}
@@ -714,7 +711,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
int i = 0;
for(Block block : blocksOut){
TextureRegion region = block.icon(Cicon.medium);
TextureRegion region = block.uiIcon;
if(!Core.atlas.isFound(region) || !block.inEditor
|| block.buildVisibility == BuildVisibility.debugOnly

View File

@@ -26,28 +26,27 @@ import static mindustry.Vars.*;
@SuppressWarnings("unchecked")
public class MapGenerateDialog extends BaseDialog{
private final Prov<GenerateFilter>[] filterTypes = new Prov[]{
final Prov<GenerateFilter>[] filterTypes = new Prov[]{
NoiseFilter::new, ScatterFilter::new, TerrainFilter::new, DistortFilter::new,
RiverNoiseFilter::new, OreFilter::new, OreMedianFilter::new, MedianFilter::new,
BlendFilter::new, MirrorFilter::new, ClearFilter::new, CoreSpawnFilter::new,
EnemySpawnFilter::new, SpawnPathFilter::new
};
private final MapEditor editor;
private final boolean applied;
final boolean applied;
private Pixmap pixmap;
private Texture texture;
private GenerateInput input = new GenerateInput();
Pixmap pixmap;
Texture texture;
GenerateInput input = new GenerateInput();
Seq<GenerateFilter> filters = new Seq<>();
private int scaling = mobile ? 3 : 1;
private Table filterTable;
int scaling = mobile ? 3 : 1;
Table filterTable;
private AsyncExecutor executor = new AsyncExecutor(1);
private AsyncResult<Void> result;
AsyncExecutor executor = new AsyncExecutor(1);
AsyncResult<Void> result;
boolean generating;
private long[] buffer1, buffer2;
private Cons<Seq<GenerateFilter>> applier;
long[] buffer1, buffer2;
Cons<Seq<GenerateFilter>> applier;
CachedTile ctile = new CachedTile(){
//nothing.
@Override
@@ -62,35 +61,79 @@ public class MapGenerateDialog extends BaseDialog{
};
/** @param applied whether or not to use the applied in-game mode. */
public MapGenerateDialog(MapEditor editor, boolean applied){
public MapGenerateDialog(boolean applied){
super("@editor.generate");
this.editor = editor;
this.applied = applied;
shown(this::setup);
addCloseButton();
addCloseListener();
var style = Styles.cleart;
buttons.defaults().size(180f, 64f).pad(2f);
buttons.button("@back", Icon.left, this::hide);
if(applied){
buttons.button("@editor.apply", Icon.ok, () -> {
ui.loadAnd(() -> {
apply();
hide();
});
}).size(160f, 64f);
}else{
buttons.button("@settings.reset", () -> {
filters.set(maps.readFilters(""));
rebuildFilters();
update();
}).size(160f, 64f);
});
}
buttons.button("@editor.randomize", Icon.refresh, () -> {
for(GenerateFilter filter : filters){
filter.randomize();
}
update();
}).size(160f, 64f);
});
buttons.button("@add", Icon.add, this::showAdd).height(64f).width(150f);
buttons.button("@edit", Icon.edit, () -> {
BaseDialog dialog = new BaseDialog("@editor.export");
dialog.cont.pane(p -> {
p.margin(10f);
p.table(Tex.button, in -> {
in.defaults().size(280f, 60f).left();
in.button("@waves.copy", Icon.copy, style, () -> {
dialog.hide();
Core.app.setClipboardText(JsonIO.write(filters));
}).marginLeft(12f).row();
in.button("@waves.load", Icon.download, style, () -> {
dialog.hide();
try{
filters.set(JsonIO.read(Seq.class, Core.app.getClipboardText()));
rebuildFilters();
update();
}catch(Throwable e){
ui.showException(e);
}
}).marginLeft(12f).disabled(b -> Core.app.getClipboardText() == null).row();
in.button("@clear", Icon.none, style, () -> {
dialog.hide();
filters.clear();
rebuildFilters();
update();
}).marginLeft(12f).row();
if(!applied){
in.button("@settings.reset", Icon.refresh, style, () -> {
dialog.hide();
filters.set(maps.readFilters(""));
rebuildFilters();
update();
}).marginLeft(12f).row();
}
});
});
dialog.addCloseButton();
dialog.show();
});
buttons.button("@add", Icon.add, this::showAdd);
if(!applied){
hidden(this::apply);
@@ -173,7 +216,7 @@ public class MapGenerateDialog extends BaseDialog{
@Override
public void draw(){
super.draw();
for(GenerateFilter filter : filters){
for(var filter : filters){
filter.draw(this);
}
}
@@ -214,7 +257,7 @@ public class MapGenerateDialog extends BaseDialog{
filterTable.top().left();
int i = 0;
for(GenerateFilter filter : filters){
for(var filter : filters){
//main container
filterTable.table(Tex.pane, c -> {
@@ -284,31 +327,33 @@ public class MapGenerateDialog extends BaseDialog{
}
void showAdd(){
BaseDialog selection = new BaseDialog("@add");
var selection = new BaseDialog("@add");
selection.cont.pane(p -> {
p.background(Tex.button);
p.marginRight(14);
p.defaults().size(210f, 60f);
p.defaults().size(195f, 56f);
int i = 0;
for(Prov<GenerateFilter> gen : filterTypes){
GenerateFilter filter = gen.get();
for(var gen : filterTypes){
var filter = gen.get();
var icon = filter.icon();
if((filter.isPost() && applied)) continue;
if(filter.isPost() && applied) continue;
p.button(filter.name(), () -> {
p.button((icon == '\0' ? "" : icon + " ") + filter.name(), Styles.cleart, () -> {
filters.add(filter);
rebuildFilters();
update();
selection.hide();
});
if(++i % 2 == 0) p.row();
}).with(Table::left).get().getLabelCell().growX().left().padLeft(5).labelAlign(Align.left);
if(++i % 3 == 0) p.row();
}
p.button("@filter.defaultores", () -> {
p.button(Iconc.refresh + " " + Core.bundle.get("filter.defaultores"), Styles.cleart, () -> {
maps.addDefaultOres(filters);
rebuildFilters();
update();
selection.hide();
});
}).with(Table::left).get().getLabelCell().growX().left().padLeft(5).labelAlign(Align.left);
}).get().setScrollingDisabled(true, false);
selection.addCloseButton();
@@ -350,25 +395,25 @@ public class MapGenerateDialog extends BaseDialog{
return;
}
Seq<GenerateFilter> copy = new Seq<>(filters);
var copy = filters.copy();
result = executor.submit(() -> {
try{
int w = pixmap.getWidth();
int w = pixmap.width;
world.setGenerating(true);
generating = true;
if(!filters.isEmpty()){
//write to buffer1 for reading
for(int px = 0; px < pixmap.getWidth(); px++){
for(int py = 0; py < pixmap.getHeight(); py++){
for(int px = 0; px < pixmap.width; px++){
for(int py = 0; py < pixmap.height; py++){
buffer1[px + py*w] = pack(editor.tile(px * scaling, py * scaling));
}
}
}
for(GenerateFilter filter : copy){
input.begin(filter, editor.width(), editor.height(), (x, y) -> unpack(buffer1[Mathf.clamp(x / scaling, 0, pixmap.getWidth()-1) + w* Mathf.clamp(y / scaling, 0, pixmap.getHeight()-1)]));
for(var filter : copy){
input.begin(filter, editor.width(), editor.height(), (x, y) -> unpack(buffer1[Mathf.clamp(x / scaling, 0, pixmap.width -1) + w* Mathf.clamp(y / scaling, 0, pixmap.height -1)]));
//read from buffer1 and write to buffer2
pixmap.each((px, py) -> {
@@ -382,8 +427,8 @@ public class MapGenerateDialog extends BaseDialog{
pixmap.each((px, py) -> buffer1[px + py*w] = buffer2[px + py*w]);
}
for(int px = 0; px < pixmap.getWidth(); px++){
for(int py = 0; py < pixmap.getHeight(); py++){
for(int px = 0; px < pixmap.width; px++){
for(int py = 0; py < pixmap.height; py++){
int color;
//get result from buffer1 if there's filters left, otherwise get from editor directly
if(filters.isEmpty()){
@@ -393,7 +438,7 @@ public class MapGenerateDialog extends BaseDialog{
long tile = buffer1[px + py*w];
color = MapIO.colorFor(content.block(PackTile.block(tile)), content.block(PackTile.floor(tile)), content.block(PackTile.overlay(tile)), Team.derelict);
}
pixmap.draw(px, pixmap.getHeight() - 1 - py, color);
pixmap.set(px, pixmap.height - 1 - py, color);
}
}

View File

@@ -9,17 +9,17 @@ import mindustry.io.*;
import mindustry.ui.*;
import mindustry.ui.dialogs.*;
import static mindustry.Vars.*;
public class MapInfoDialog extends BaseDialog{
private final MapEditor editor;
private final WaveInfoDialog waveInfo;
private final MapGenerateDialog generate;
private final CustomRulesDialog ruleInfo = new CustomRulesDialog();
public MapInfoDialog(MapEditor editor){
public MapInfoDialog(){
super("@editor.mapinfo");
this.editor = editor;
this.waveInfo = new WaveInfoDialog(editor);
this.generate = new MapGenerateDialog(editor, false);
this.waveInfo = new WaveInfoDialog();
this.generate = new MapGenerateDialog(false);
addCloseButton();

View File

@@ -18,14 +18,7 @@ public class MapRenderer implements Disposable{
private IndexedRenderer[][] chunks;
private IntSet updates = new IntSet();
private IntSet delayedUpdates = new IntSet();
private MapEditor editor;
private int width, height;
private Texture texture;
public MapRenderer(MapEditor editor){
this.editor = editor;
this.texture = Core.atlas.find("clear-editor").texture;
}
public void resize(int width, int height){
updates.clear();
@@ -64,6 +57,8 @@ public class MapRenderer implements Disposable{
return;
}
var texture = Core.atlas.find("clear-editor").texture;
for(int x = 0; x < chunks.length; x++){
for(int y = 0; y < chunks[0].length; y++){
IndexedRenderer mesh = chunks[x][y];

View File

@@ -6,13 +6,14 @@ import arc.scene.ui.TextField.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.ui.dialogs.*;
import static mindustry.Vars.*;
public class MapResizeDialog extends BaseDialog{
public static int minSize = 50, maxSize = 500, increment = 50;
int width, height;
public MapResizeDialog(MapEditor editor, Intc2 cons){
public MapResizeDialog(Intc2 cons){
super("@editor.resizemap");
shown(() -> {
cont.clear();

View File

@@ -19,7 +19,6 @@ import mindustry.ui.*;
import static mindustry.Vars.*;
public class MapView extends Element implements GestureListener{
private MapEditor editor;
EditorTool tool = EditorTool.pencil;
private float offsetx, offsety;
private float zoom = 1f;
@@ -35,8 +34,7 @@ public class MapView extends Element implements GestureListener{
float mousex, mousey;
EditorTool lastTool;
public MapView(MapEditor editor){
this.editor = editor;
public MapView(){
for(int i = 0; i < MapEditor.brushSizes.length; i++){
float size = MapEditor.brushSizes[i];
@@ -92,7 +90,7 @@ public class MapView extends Element implements GestureListener{
lasty = p.y;
startx = p.x;
starty = p.y;
tool.touched(editor, p.x, p.y);
tool.touched(p.x, p.y);
firstTouch.set(p);
if(tool.edit){
@@ -115,7 +113,7 @@ public class MapView extends Element implements GestureListener{
if(tool == EditorTool.line){
ui.editor.resetSaved();
tool.touchedLine(editor, startx, starty, p.x, p.y);
tool.touchedLine(startx, starty, p.x, p.y);
}
editor.flushOp();
@@ -136,7 +134,7 @@ public class MapView extends Element implements GestureListener{
if(drawing && tool.draggable && !(p.x == lastx && p.y == lasty)){
ui.editor.resetSaved();
Bresenham2.line(lastx, lasty, p.x, p.y, (cx, cy) -> tool.touched(editor, cx, cy));
Bresenham2.line(lastx, lasty, p.x, p.y, (cx, cy) -> tool.touched(cx, cy));
}
if(tool == EditorTool.line && tool.mode == 1){

View File

@@ -177,7 +177,7 @@ public class WaveGraph extends Table{
t.button(b -> {
Color tcolor = color(type).cpy();
b.image().size(32f).update(i -> i.setColor(b.isChecked() ? Tmp.c1.set(tcolor).mul(0.5f) : tcolor)).get().act(1);
b.image(type.icon(Cicon.medium)).size(32f).padRight(20).update(i -> i.setColor(b.isChecked() ? Color.gray : Color.white)).get().act(1);
b.image(type.uiIcon).size(32f).padRight(20).update(i -> i.setColor(b.isChecked() ? Color.gray : Color.white)).get().act(1);
b.margin(0f);
}, Styles.fullTogglet, () -> {
if(!hidden.add(type)){

View File

@@ -30,7 +30,7 @@ public class WaveInfoDialog extends BaseDialog{
private float updateTimer, updatePeriod = 1f;
private WaveGraph graph = new WaveGraph();
public WaveInfoDialog(MapEditor editor){
public WaveInfoDialog(){
super("@waves.title");
shown(this::setup);
@@ -160,7 +160,7 @@ public class WaveInfoDialog extends BaseDialog{
t.margin(0).defaults().pad(3).padLeft(5f).growX().left();
t.button(b -> {
b.left();
b.image(group.type.icon(Cicon.medium)).size(32f).padRight(3).scaling(Scaling.fit);
b.image(group.type.uiIcon).size(32f).padRight(3).scaling(Scaling.fit);
b.add(group.type.localizedName).color(Pal.accent);
b.add().growX();
@@ -263,7 +263,7 @@ public class WaveInfoDialog extends BaseDialog{
if(type.isHidden()) continue;
p.button(t -> {
t.left();
t.image(type.icon(Cicon.medium)).size(8 * 4).scaling(Scaling.fit).padRight(2f);
t.image(type.uiIcon).size(8 * 4).scaling(Scaling.fit).padRight(2f);
t.add(type.localizedName);
}, () -> {
lastType = type;