multiselect region can be drawn with the right mouse button
This commit is contained in:
parent
f091fba9f7
commit
82246dc0c6
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<other.max.x and self.min.x<other.max.x and
|
||||
self.min.y<other.max.y and self.min.y<other.max.y
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user