mirror of
https://github.com/teverse/teverse
synced 2025-12-23 17:34:47 +01:00
Compare commits
3 Commits
9e722ea708
...
b688f4a49d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b688f4a49d | ||
|
|
3d956cf8df | ||
|
|
23868e9ed1 |
@ -12,6 +12,7 @@ local boundingBox = engine.construct("block", workspace, {
|
|||||||
})
|
})
|
||||||
|
|
||||||
controller.selection = {}
|
controller.selection = {}
|
||||||
|
controller.destroyingListeners = {}
|
||||||
|
|
||||||
controller.callbacks = {}
|
controller.callbacks = {}
|
||||||
|
|
||||||
@ -27,14 +28,34 @@ end
|
|||||||
|
|
||||||
controller.setSelection = function(obj)
|
controller.setSelection = function(obj)
|
||||||
controller.selection = {}
|
controller.selection = {}
|
||||||
|
|
||||||
|
for _,v in pairs(controller.destroyingListeners) do
|
||||||
|
v:disconnect()
|
||||||
|
end
|
||||||
|
controller.destroyingListeners = {}
|
||||||
|
|
||||||
controller.addSelection(obj)
|
controller.addSelection(obj)
|
||||||
end
|
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)
|
controller.addSelection = function(obj)
|
||||||
if type(obj) == "table" then
|
if type(obj) == "table" then
|
||||||
for _,v in pairs(obj) do
|
for _,v in pairs(obj) do
|
||||||
if v.isA and v:isA("baseClass") then
|
if v.isA and v:isA("baseClass") then
|
||||||
table.insert(controller.selection, v)
|
table.insert(controller.selection, v)
|
||||||
|
controller.destroyingListeners[v] = v:once("destroying", destroyListener)
|
||||||
else
|
else
|
||||||
warn("selecting unknown object")
|
warn("selecting unknown object")
|
||||||
end
|
end
|
||||||
@ -42,6 +63,7 @@ controller.addSelection = function(obj)
|
|||||||
else
|
else
|
||||||
if obj.isA and obj:isA("baseClass") then
|
if obj.isA and obj:isA("baseClass") then
|
||||||
table.insert(controller.selection, obj)
|
table.insert(controller.selection, obj)
|
||||||
|
controller.destroyingListeners[obj] = obj:once("destroying", destroyListener)
|
||||||
else
|
else
|
||||||
warn("selecting unknown object")
|
warn("selecting unknown object")
|
||||||
end
|
end
|
||||||
@ -64,17 +86,19 @@ end
|
|||||||
local boundingEvents = {}
|
local boundingEvents = {}
|
||||||
|
|
||||||
local function boundUpdate()
|
local function boundUpdate()
|
||||||
|
if not boundingBox or not boundingBox.alive then return end
|
||||||
|
|
||||||
--inefficient, is called for each change
|
--inefficient, is called for each change
|
||||||
local bounds = aabb()
|
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.min = controller.selection[1].position
|
||||||
bounds.max = controller.selection[1].position
|
bounds.max = controller.selection[1].position
|
||||||
end
|
|
||||||
|
|
||||||
for _,v in pairs(controller.selection) do
|
for _,v in pairs(controller.selection) do
|
||||||
bounds:expand(v.position + (v.size/2))
|
bounds:expand(v.position + (v.size/2))
|
||||||
bounds:expand(v.position - (v.size/2))
|
bounds:expand(v.position - (v.size/2))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
boundingBox.position = bounds:getCentre()
|
boundingBox.position = bounds:getCentre()
|
||||||
@ -87,17 +111,21 @@ controller.registerCallback(function()
|
|||||||
end
|
end
|
||||||
boundingEvents = {}
|
boundingEvents = {}
|
||||||
|
|
||||||
|
if not boundingBox or not boundingBox.alive then return end
|
||||||
|
|
||||||
local bounds = aabb()
|
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.min = controller.selection[1].position
|
||||||
bounds.max = controller.selection[1].position
|
bounds.max = controller.selection[1].position
|
||||||
end
|
|
||||||
|
|
||||||
for _,v in pairs(controller.selection) do
|
for _,v in pairs(controller.selection) do
|
||||||
bounds:expand(v.position + (v.size/2))
|
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))
|
bounds:expand(v.position - (v.size/2))
|
||||||
|
table.insert(boundingEvents, v:changed(boundUpdate))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
boundingBox.position = bounds:getCentre()
|
boundingBox.position = bounds:getCentre()
|
||||||
|
|||||||
@ -2,6 +2,7 @@ local controller = {}
|
|||||||
|
|
||||||
local shared = require("tevgit:workshop/controllers/shared.lua")
|
local shared = require("tevgit:workshop/controllers/shared.lua")
|
||||||
local selection = require("tevgit:workshop/controllers/core/selection.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")
|
local ui = require("tevgit:workshop/controllers/ui/core/ui.lua")
|
||||||
|
|
||||||
-- store icons for each class type
|
-- store icons for each class type
|
||||||
@ -189,7 +190,7 @@ local function createHierarchyButton(object, guiParent)
|
|||||||
|
|
||||||
if object:isA("luaSharedFolder") or object:isA("luaServerFolder") or
|
if object:isA("luaSharedFolder") or object:isA("luaServerFolder") or
|
||||||
object:isA("luaClientFolder") then
|
object:isA("luaClientFolder") then
|
||||||
contextMenu.bind(btn, luaFolderContextOptions)
|
context.bind(btn, context.exampleOptions)
|
||||||
else
|
else
|
||||||
-- selectionController.applyContext(btn)
|
-- selectionController.applyContext(btn)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -88,4 +88,14 @@ controller.generateMenu = function(options, position)
|
|||||||
menu.size = guiCoord(0, 160, 0, yPos)
|
menu.size = guiCoord(0, 160, 0, yPos)
|
||||||
end
|
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
|
return controller
|
||||||
Loading…
x
Reference in New Issue
Block a user