From 82246dc0c689d012fea49d1590e9fd4736500996 Mon Sep 17 00:00:00 2001 From: binarycat Date: Sat, 12 Mar 2022 13:16:39 -0500 Subject: [PATCH] multiselect region can be drawn with the right mouse button --- code/camera.lua | 13 +++++++++++++ code/editor.lua | 40 +++++++++++++++++++++++++++++++++++++++- code/rect.lua | 9 +++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/code/camera.lua b/code/camera.lua index 35f3a2d..b67e4dc 100644 --- a/code/camera.lua +++ b/code/camera.lua @@ -77,3 +77,16 @@ function Camera:positionAt(x,y) self.pos.y = math.floor((y/self.height)*self.height) end +-- translate screen coordinates to game coordinates +function Camera:ptScreenToGame(pt) + return self.pos + pt +end + +function Camera:mouseScreenPos() + return Point:new(love.mouse.getX(),love.mouse.getY()) / game.scale +end + +-- return the mouse position as game coordinates +function Camera:mouseGamePos() + return self:ptScreenToGame(self:mouseScreenPos()) +end diff --git a/code/editor.lua b/code/editor.lua index 8103be0..fc066de 100644 --- a/code/editor.lua +++ b/code/editor.lua @@ -8,6 +8,7 @@ editor = { }, multiselect = { active = false, + sweeping = false, box = nil, }, pan = { fixed = false, speed = 3 }, @@ -16,6 +17,20 @@ editor = { function stepEditor() animateTiles() + local osweep = editor.multiselect.sweeping + editor.multiselect.sweeping = love.mouse.isDown(2) + frameDebug("sweeping: "..tostring(editor.multiselect.sweeping)) + if editor.multiselect.sweeping and not editor.multiselect.active then + print("multiselect enabled") + editor.multiselect.active = true + end + if not osweep and osweep ~= editor.multiselect.sweeping then + editor.multiselect.box = nil + end + if editor.multiselect.active then + doEditorMultiselect() + end + if Keybind:checkPressed(Keybind.editor.room_mode) then if love.keyboard.isDown("lshift") then editor.room_mode = "delete" @@ -125,6 +140,10 @@ function drawEditor() if editor.palette.active then doEditorPalette() end + if editor.multiselect.box ~= nil then + frameDebug("drawing multiselect "..tostring(editor.multiselect.box)) + drawEditorMultiselect() + end end function doEditorEdit() @@ -351,6 +370,25 @@ end function drawEditorRooms() for _, room in pairs(LoadedObjects.Rooms) do love.graphics.setColor(0,0,100,1) - love.graphics.rectangle("line",room.from.x-Camera.pos.x, room.from.y-Camera.pos.y, room.width, room.height) + room:asRect():draw("line") + --love.graphics.rectangle("line",room.from.x-Camera.pos.x, room.from.y-Camera.pos.y, room.width, room.height) end end + +function drawEditorMultiselect() + love.graphics.setColor(100,100,50,1) + editor.multiselect.box:draw("line") +end + +function doEditorMultiselect() + local mousept = Camera:mouseGamePos() + if editor.multiselect.box == nil then + print("sweep started") + editor.multiselect.box = Rect:fromPoints(mousept, mousept) + print("box: "..tostring(editor.multiselect.box)) + elseif editor.multiselect.sweeping then + editor.multiselect.box.max = mousept + frameDebug("swept to "..tostring(mousept)) + end +end + diff --git a/code/rect.lua b/code/rect.lua index c67c9a6..55e84a8 100644 --- a/code/rect.lua +++ b/code/rect.lua @@ -6,6 +6,7 @@ Rect.__index = Rect function Rect:fromPoints(pt1, pt2) local o = { min = pt1, max = pt2 } setmetatable(o, self) + return o end function Rect:fromCoords(x1, y1, x2, y2) @@ -64,3 +65,11 @@ function Rect:overlapsRect(other) return self.min.x