mirror of
https://github.com/yawaflua/Informatis.git
synced 2025-12-10 12:09:27 +02:00
fix brush offset
This commit is contained in:
@@ -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()) {
|
|
||||||
|
Tile tile = world.tileWorld(Core.input.mouseWorldX(), Core.input.mouseWorldY());
|
||||||
|
if(tile == null || tool == null || brushSize < 1 || drawBlock == null || hasMouse()) return;
|
||||||
if(Core.input.isTouched()) {
|
if(Core.input.isTouched()) {
|
||||||
if(!(!mobile&&Core.input.keyDown(KeyCode.mouseLeft))) return;
|
if((tool == EditorTool.line && drawing) || (!mobile && !Core.input.keyDown(KeyCode.mouseLeft))) return;
|
||||||
if(tool== EditorTool.line) {
|
drawing = true;
|
||||||
if(!hold) {
|
lastx = tile.x;
|
||||||
pastX = Mathf.round(Core.input.mouseWorldX() / 8);
|
lasty = tile.y;
|
||||||
pastY = Mathf.round(Core.input.mouseWorldY() / 8);
|
tool.touched(lastx, lasty);
|
||||||
}
|
|
||||||
hold = true;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pastX = Mathf.round(Core.input.mouseWorldX() / 8);
|
if(tool == EditorTool.line && drawing) tool.touchedLine(lastx, lasty, tile.x, tile.y);
|
||||||
pastY = Mathf.round(Core.input.mouseWorldY() / 8);
|
drawing = false;
|
||||||
}
|
lastx = -1;
|
||||||
|
lasty = -1;
|
||||||
tool.touched(pastX, pastY);
|
|
||||||
}
|
|
||||||
else if(tool== EditorTool.line) {
|
|
||||||
if(hold&&pastX>=0&&pastY>=0) tool.touchedLine(pastX, pastY, Mathf.round(Core.input.mouseWorldX() / 8), Mathf.round(Core.input.mouseWorldY() / 8));
|
|
||||||
hold = false;
|
|
||||||
pastX = -1;
|
|
||||||
pastY = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user