multiselect region can be drawn with the right mouse button

This commit is contained in:
binarycat 2022-03-12 13:16:39 -05:00
parent f091fba9f7
commit 82246dc0c6
3 changed files with 61 additions and 1 deletions

View File

@ -77,3 +77,16 @@ function Camera:positionAt(x,y)
self.pos.y = math.floor((y/self.height)*self.height) self.pos.y = math.floor((y/self.height)*self.height)
end 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

View File

@ -8,6 +8,7 @@ editor = {
}, },
multiselect = { multiselect = {
active = false, active = false,
sweeping = false,
box = nil, box = nil,
}, },
pan = { fixed = false, speed = 3 }, pan = { fixed = false, speed = 3 },
@ -16,6 +17,20 @@ editor = {
function stepEditor() function stepEditor()
animateTiles() 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 Keybind:checkPressed(Keybind.editor.room_mode) then
if love.keyboard.isDown("lshift") then if love.keyboard.isDown("lshift") then
editor.room_mode = "delete" editor.room_mode = "delete"
@ -125,6 +140,10 @@ function drawEditor()
if editor.palette.active then if editor.palette.active then
doEditorPalette() doEditorPalette()
end end
if editor.multiselect.box ~= nil then
frameDebug("drawing multiselect "..tostring(editor.multiselect.box))
drawEditorMultiselect()
end
end end
function doEditorEdit() function doEditorEdit()
@ -351,6 +370,25 @@ end
function drawEditorRooms() function drawEditorRooms()
for _, room in pairs(LoadedObjects.Rooms) do for _, room in pairs(LoadedObjects.Rooms) do
love.graphics.setColor(0,0,100,1) 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
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

View File

@ -6,6 +6,7 @@ Rect.__index = Rect
function Rect:fromPoints(pt1, pt2) function Rect:fromPoints(pt1, pt2)
local o = { min = pt1, max = pt2 } local o = { min = pt1, max = pt2 }
setmetatable(o, self) setmetatable(o, self)
return o
end end
function Rect:fromCoords(x1, y1, x2, y2) function Rect:fromCoords(x1, y1, x2, y2)
@ -64,3 +65,11 @@ function Rect:overlapsRect(other)
return self.min.x<other.max.x and self.min.x<other.max.x and return self.min.x<other.max.x and self.min.x<other.max.x and
self.min.y<other.max.y and self.min.y<other.max.y self.min.y<other.max.y and self.min.y<other.max.y
end end
function Rect:draw(style)
love.graphics.rectangle(style, self.min.x - Camera.pos.x, self.min.y - Camera.pos.y, self:width(), self:height())
end
function Rect:__tostring()
return "Rect["..tostring(self.min).." "..tostring(self.max).."]"
end