From e8305d12451aa9be85469c6d30f84467ff5a93b4 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 19 May 2018 11:53:01 -0700 Subject: [PATCH] Updated map editor with better placement preview --- .../build/libs/annotations-release.jar | Bin 9921 -> 9921 bytes .../io/anuke/mindustry/editor/MapEditor.java | 6 +-- .../io/anuke/mindustry/editor/MapView.java | 51 ++++++++++++++---- .../io/anuke/mindustry/entities/Player.java | 2 +- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/annotations/build/libs/annotations-release.jar b/annotations/build/libs/annotations-release.jar index 683e153024f80a3df474b9386236433f9d1f862c..861d9e586549c4fff0ac74d62a1ba5bbfc2622dc 100644 GIT binary patch delta 236 zcmX@;d(f9Rz?+$ci-CcIgW*Nk=83#&%pl6lOASc*FaQA)hyVg+AkNI!XJ$avuneN% zyb(y>W)?;@CNM*nIY<)BXp#wJ1T(J5#zGio@^KKxbcG}cR8)04@Ag#sB~S delta 236 zcmX@;d(f9Rz?+$ci-CcIgCV(V(?ni1=4Bn5CYpJv0Vy8_AYcL!K)?*dnfdz63Nf5>#MM*GYvV^h; z$ok3t%JyJ-qOu;CJ_Hm88bA4`vICg5QHciAvs5C%^f#4oFdd*82c|bdX(6>hFh5N# F8UWalPn-Y% diff --git a/core/src/io/anuke/mindustry/editor/MapEditor.java b/core/src/io/anuke/mindustry/editor/MapEditor.java index 6d476d9f07..11a55e73ba 100644 --- a/core/src/io/anuke/mindustry/editor/MapEditor.java +++ b/core/src/io/anuke/mindustry/editor/MapEditor.java @@ -74,9 +74,9 @@ public class MapEditor{ writer.team = (byte)drawTeam.ordinal(); } - for(int rx = -brushSize + 1; rx <= brushSize - 1; rx ++){ - for(int ry = -brushSize + 1; ry <= brushSize - 1; ry ++){ - if(Mathf.dst(rx, ry) <= brushSize){ + for(int rx = -brushSize; rx <= brushSize; rx ++){ + for(int ry = -brushSize; ry <= brushSize; ry ++){ + if(Mathf.dst(rx, ry) <= brushSize - 0.5f){ if(dx + rx < 0 || dy + ry < 0 || dx + rx >= map.width() || dy + ry >= map.height()){ continue; } diff --git a/core/src/io/anuke/mindustry/editor/MapView.java b/core/src/io/anuke/mindustry/editor/MapView.java index 874588e11e..c25c9fc610 100644 --- a/core/src/io/anuke/mindustry/editor/MapView.java +++ b/core/src/io/anuke/mindustry/editor/MapView.java @@ -1,5 +1,6 @@ package io.anuke.mindustry.editor; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Colors; import com.badlogic.gdx.graphics.g2d.Batch; @@ -24,10 +25,11 @@ import io.anuke.ucore.scene.event.InputListener; import io.anuke.ucore.scene.event.Touchable; import io.anuke.ucore.scene.ui.TextField; import io.anuke.ucore.scene.ui.layout.Unit; -import io.anuke.ucore.input.Input; +import io.anuke.ucore.util.Geometry; import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Tmp; +import static io.anuke.mindustry.Vars.mobile; import static io.anuke.mindustry.Vars.ui; public class MapView extends Element implements GestureListener{ @@ -43,10 +45,12 @@ public class MapView extends Element implements GestureListener{ private GridImage image = new GridImage(0, 0); private Vector2 vec = new Vector2(); private Rectangle rect = new Rectangle(); + private Vector2[][] brushPolygons = new Vector2[MapEditor.brushSizes.length][0]; private boolean drawing; private int lastx, lasty; private int startx, starty; + private float mousex, mousey; public void setTool(EditorTool tool){ this.tool = tool; @@ -87,11 +91,24 @@ public class MapView extends Element implements GestureListener{ public MapView(MapEditor editor){ this.editor = editor; + + for(int i = 0; i < MapEditor.brushSizes.length; i ++){ + float size = MapEditor.brushSizes[i]; + brushPolygons[i] = Geometry.pixelCircle(size, (index, x, y) -> Vector2.dst(x, y, index, index) <= index - 0.5f); + } Inputs.addProcessor(0, new GestureDetector(20, 0.5f, 2, 0.15f, this)); setTouchable(Touchable.enabled); addListener(new InputListener(){ + + @Override + public boolean mouseMoved (InputEvent event, float x, float y) { + mousex = x; + mousey = y; + + return false; + } @Override public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { @@ -135,6 +152,9 @@ public class MapView extends Element implements GestureListener{ @Override public void touchDragged (InputEvent event, float x, float y, int pointer) { + mousex = x; + mousey = y; + GridPoint2 p = project(x, y); if(drawing && tool == EditorTool.pencil){ @@ -156,7 +176,7 @@ public class MapView extends Element implements GestureListener{ super.act(delta); if(Core.scene.getKeyboardFocus() == null || !(Core.scene.getKeyboardFocus() instanceof TextField) && - !Inputs.keyDown(Input.CONTROL_LEFT)) { + !Inputs.keyDown(io.anuke.ucore.input.Input.CONTROL_LEFT)) { float ax = Inputs.getAxis("move_x"); float ay = Inputs.getAxis("move_y"); offsetx -= ax * 15f / zoom; @@ -223,20 +243,33 @@ public class MapView extends Element implements GestureListener{ Draw.color(); } + int index = 0; + for(int i = 0; i < MapEditor.brushSizes.length; i ++){ + if(editor.getBrushSize() == MapEditor.brushSizes[i]){ + index = i; + break; + } + } + if(tool == EditorTool.line && drawing){ Vector2 v1 = unproject(startx, starty).add(x, y); float sx = v1.x, sy = v1.y; Vector2 v2 = unproject(lastx, lasty).add(x, y); - Draw.color(Tmp.c1.set(ColorMapper.getColor(editor.getDrawBlock()))); - Lines.stroke(Unit.dp.scl(3f * zoom)); - Lines.line(sx, sy, v2.x, v2.y); - - Lines.poly(sx, sy, 40, editor.getBrushSize() * zoom * 3); - - Lines.poly(v2.x, v2.y, 40, editor.getBrushSize() * zoom * 3); + Draw.color("accent"); + Lines.stroke(Unit.dp.scl(1f * zoom)); + Lines.poly(brushPolygons[index], sx, sy, 3f*zoom); + Lines.poly(brushPolygons[index], v2.x, v2.y, 3f*zoom); } + if(tool.edit && (!mobile || drawing)){ + GridPoint2 p = project(mousex, mousey); + Vector2 v = unproject(p.x, p.y).add(x, y); + Draw.color("accent"); + Lines.stroke(Unit.dp.scl(1f * zoom)); + Lines.poly(brushPolygons[index], v.x, v.y, 3f*zoom); + } + batch.flush(); if(pop) ScissorStack.popScissors(); diff --git a/core/src/io/anuke/mindustry/entities/Player.java b/core/src/io/anuke/mindustry/entities/Player.java index 2eabb63762..49e10769f6 100644 --- a/core/src/io/anuke/mindustry/entities/Player.java +++ b/core/src/io/anuke/mindustry/entities/Player.java @@ -316,7 +316,7 @@ public class Player extends Unit implements BlockPlacer{ return control.input(playerIndex).canShoot() && control.input(playerIndex).isShooting() && inventory.hasAmmo(); } - public Iterable getPlaceQueue(){ + public Queue getPlaceQueue(){ return placeQueue; }