Compare commits

...

3 Commits

Author SHA1 Message Date
teverse b688f4a49d fixes 2019-11-16 20:25:46 +00:00
teverse 3d956cf8df add destroy listener to selection controller 2019-11-16 20:04:28 +00:00
teverse 23868e9ed1 is this ok checks 2019-11-16 19:47:37 +00:00
3 changed files with 51 additions and 12 deletions

View File

@ -12,6 +12,7 @@ local boundingBox = engine.construct("block", workspace, {
})
controller.selection = {}
controller.destroyingListeners = {}
controller.callbacks = {}
@ -27,14 +28,34 @@ end
controller.setSelection = function(obj)
controller.selection = {}
for _,v in pairs(controller.destroyingListeners) do
v:disconnect()
end
controller.destroyingListeners = {}
controller.addSelection(obj)
end
local function destroyListener()
for i,v in pairs(controller.selection) do
if v == self.object then
table.remove(controller.selection, i)
break
end
end
controller.destroyingListeners[self.object] = nil
self:disconnect()
end
controller.addSelection = function(obj)
if type(obj) == "table" then
for _,v in pairs(obj) do
if v.isA and v:isA("baseClass") then
table.insert(controller.selection, v)
controller.destroyingListeners[v] = v:once("destroying", destroyListener)
else
warn("selecting unknown object")
end
@ -42,6 +63,7 @@ controller.addSelection = function(obj)
else
if obj.isA and obj:isA("baseClass") then
table.insert(controller.selection, obj)
controller.destroyingListeners[obj] = obj:once("destroying", destroyListener)
else
warn("selecting unknown object")
end
@ -64,17 +86,19 @@ end
local boundingEvents = {}
local function boundUpdate()
if not boundingBox or not boundingBox.alive then return end
--inefficient, is called for each change
local bounds = aabb()
if #controller.selection > 0 then
if #controller.selection > 0 and controller.selection[1].position then
bounds.min = controller.selection[1].position
bounds.max = controller.selection[1].position
end
for _,v in pairs(controller.selection) do
bounds:expand(v.position + (v.size/2))
bounds:expand(v.position - (v.size/2))
for _,v in pairs(controller.selection) do
bounds:expand(v.position + (v.size/2))
bounds:expand(v.position - (v.size/2))
end
end
boundingBox.position = bounds:getCentre()
@ -87,17 +111,21 @@ controller.registerCallback(function()
end
boundingEvents = {}
if not boundingBox or not boundingBox.alive then return end
local bounds = aabb()
if #controller.selection > 0 then
if #controller.selection > 0 and type(controller.selection[1].position) == "vector3" then
bounds.min = controller.selection[1].position
bounds.max = controller.selection[1].position
end
for _,v in pairs(controller.selection) do
bounds:expand(v.position + (v.size/2))
bounds:expand(v.position - (v.size/2))
table.insert(boundingEvents, v:changed(boundUpdate))
for _,v in pairs(controller.selection) do
if type(v.position) == "vector3" then
bounds:expand(v.position + (v.size/2))
bounds:expand(v.position - (v.size/2))
table.insert(boundingEvents, v:changed(boundUpdate))
end
end
end
boundingBox.position = bounds:getCentre()

View File

@ -2,6 +2,7 @@ local controller = {}
local shared = require("tevgit:workshop/controllers/shared.lua")
local selection = require("tevgit:workshop/controllers/core/selection.lua")
local context = require("tevgit:workshop/controllers/ui/core/contextMenu.lua")
local ui = require("tevgit:workshop/controllers/ui/core/ui.lua")
-- store icons for each class type
@ -189,7 +190,7 @@ local function createHierarchyButton(object, guiParent)
if object:isA("luaSharedFolder") or object:isA("luaServerFolder") or
object:isA("luaClientFolder") then
contextMenu.bind(btn, luaFolderContextOptions)
context.bind(btn, context.exampleOptions)
else
-- selectionController.applyContext(btn)
end

View File

@ -88,4 +88,14 @@ controller.generateMenu = function(options, position)
menu.size = guiCoord(0, 160, 0, yPos)
end
controller.bind = function(object, options)
if not object.mouseRightReleased then
return warn("Could not hook onto mouse event?!")
end
object:on("mouseRightReleased", function()
controller.generateMenu(options)
end)
end
return controller