fix brush offset

This commit is contained in:
sharlottes
2022-04-23 14:02:33 +09:00
parent e98712d350
commit 0d7733f5f7

View File

@@ -3,7 +3,12 @@ package unitinfo.ui.windows;
import arc.Events; import arc.Events;
import arc.graphics.g2d.Draw; import arc.graphics.g2d.Draw;
import arc.graphics.g2d.Lines; import arc.graphics.g2d.Lines;
import arc.math.geom.Bresenham2;
import arc.math.geom.Geometry; import arc.math.geom.Geometry;
import arc.math.geom.Point2;
import arc.scene.Element;
import arc.scene.event.InputEvent;
import arc.scene.event.InputListener;
import mindustry.editor.MapEditor; import mindustry.editor.MapEditor;
import mindustry.game.EventType; import mindustry.game.EventType;
import mindustry.graphics.Layer; import mindustry.graphics.Layer;
@@ -39,8 +44,9 @@ public class MapEditorDisplay extends Window implements Updatable {
final Vec2[][] brushPolygons = new Vec2[MapEditor.brushSizes.length][0]; final Vec2[][] brushPolygons = new Vec2[MapEditor.brushSizes.length][0];
float heat; float heat;
float brushSize = -1; float brushSize = -1;
boolean hold = false;
int pastX, pastY; boolean drawing;
int lastx, lasty;
public static Team drawTeam = Team.sharded; public static Team drawTeam = Team.sharded;
public static Block drawBlock = Blocks.router; public static Block drawBlock = Blocks.router;
@@ -71,8 +77,9 @@ public class MapEditorDisplay extends Window implements Updatable {
Draw.reset(); Draw.reset();
} }
Tile tile = world.tileWorld(Core.input.mouseWorldX(), Core.input.mouseWorldY());
if(tile == null || tool == null || brushSize < 1) return;
if(tool==null) return;
int index = 0; int index = 0;
for(int i = 0; i < MapEditor.brushSizes.length; i++){ for(int i = 0; i < MapEditor.brushSizes.length; i++){
if(brushSize == MapEditor.brushSizes[i]){ if(brushSize == MapEditor.brushSizes[i]){
@@ -83,31 +90,24 @@ public class MapEditorDisplay extends Window implements Updatable {
Lines.stroke(Scl.scl(2f), Pal.accent); Lines.stroke(Scl.scl(2f), Pal.accent);
if((!drawBlock.isMultiblock() || tool == EditorTool.eraser) && tool != EditorTool.fill){ if((!drawBlock.isMultiblock() || tool == EditorTool.eraser) && tool != EditorTool.fill){
if(tool == EditorTool.line && hold){ if(tool == EditorTool.line && drawing){
Vec2 v = Core.input.mouseWorld(); Lines.poly(brushPolygons[index], lastx, lasty, scaling);
Lines.poly(brushPolygons[index], pastX, pastY, scaling); Lines.poly(brushPolygons[index], tile.x*8, tile.y*8, scaling);
float vx = Mathf.floor(v.x/8)*8-4, vy = Mathf.floor(v.y/8)*8-4;
Lines.poly(brushPolygons[index], vx, vy, scaling);
} }
if((tool.edit || (tool == EditorTool.line && !hold)) && (!mobile || hold)){ if((tool.edit || (tool == EditorTool.line && !drawing)) && (!mobile || drawing)){
//pencil square outline
Vec2 v = Core.input.mouseWorld();
float vx = Mathf.floor(v.x/8)*8-4, vy = Mathf.floor(v.y/8)*8-4;
if(tool == EditorTool.pencil && tool.mode == 1){ if(tool == EditorTool.pencil && tool.mode == 1){
Lines.square(vx, vy, scaling * (brushSize + 0.5f)); Lines.square(tile.x*8, tile.y*8, scaling * (brushSize + 0.5f));
}else{ }else{
Lines.poly(brushPolygons[index], vx, vy, scaling); Lines.poly(brushPolygons[index], tile.x*8-4, tile.y*8-4, scaling);
} }
} }
}else{ }else{
if((tool.edit || tool == EditorTool.line) && (!mobile || hold)){ if((tool.edit || tool == EditorTool.line) && (!mobile || drawing)){
Vec2 v = Core.input.mouseWorld();
float vx = Mathf.floor(v.x/8)*8-4, vy = Mathf.floor(v.y/8)*8-4;
float offset = (drawBlock.size % 2 == 0 ? scaling / 2f : 0f); float offset = (drawBlock.size % 2 == 0 ? scaling / 2f : 0f);
Lines.square( Lines.square(
vx + scaling / 2f + offset, tile.x*8 + scaling / 2f + offset,
vy + scaling / 2f + offset, tile.y*8 + scaling / 2f + offset,
scaling * drawBlock.size / 2f); scaling * drawBlock.size / 2f);
} }
} }
@@ -137,29 +137,21 @@ public class MapEditorDisplay extends Window implements Updatable {
heat = 0f; heat = 0f;
resetPane(); resetPane();
} }
if(tool != null && drawBlock != null && !hasMouse()) {
if(Core.input.isTouched()) {
if(!(!mobile&&Core.input.keyDown(KeyCode.mouseLeft))) return;
if(tool== EditorTool.line) {
if(!hold) {
pastX = Mathf.round(Core.input.mouseWorldX() / 8);
pastY = Mathf.round(Core.input.mouseWorldY() / 8);
}
hold = true;
}
else {
pastX = Mathf.round(Core.input.mouseWorldX() / 8);
pastY = Mathf.round(Core.input.mouseWorldY() / 8);
}
tool.touched(pastX, pastY); Tile tile = world.tileWorld(Core.input.mouseWorldX(), Core.input.mouseWorldY());
} if(tile == null || tool == null || brushSize < 1 || drawBlock == null || hasMouse()) return;
else if(tool== EditorTool.line) { if(Core.input.isTouched()) {
if(hold&&pastX>=0&&pastY>=0) tool.touchedLine(pastX, pastY, Mathf.round(Core.input.mouseWorldX() / 8), Mathf.round(Core.input.mouseWorldY() / 8)); if((tool == EditorTool.line && drawing) || (!mobile && !Core.input.keyDown(KeyCode.mouseLeft))) return;
hold = false; drawing = true;
pastX = -1; lastx = tile.x;
pastY = -1; lasty = tile.y;
} tool.touched(lastx, lasty);
}
else {
if(tool == EditorTool.line && drawing) tool.touchedLine(lastx, lasty, tile.x, tile.y);
drawing = false;
lastx = -1;
lasty = -1;
} }
} }