File size: 2,092 Bytes
b6a38d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
DefineClass.XDeleteObjectsTool = {
__parents = { "XEditorBrushTool", "XEditorObjectPalette" },
properties = {
{ id = "buttons", editor = "buttons", default = false, buttons = {{name = "Clear selected objects", func = "ClearSelection"}} },
},
ToolTitle = "Delete objects",
Description = {
"(<style GedHighlight>hold Ctrl</style> to delete objects on a select terrain)",
},
ActionSortKey = "07",
ActionIcon = "CommonAssets/UI/Editor/Tools/DeleteObjects.tga",
ActionShortcut = "D",
deleted_objects = false,
start_terrain = false,
}
function XDeleteObjectsTool:StartDraw(pt)
SuspendPassEdits("XEditorDeleteObjects")
self.deleted_objects = {}
self.start_terrain = terminal.IsKeyPressed(const.vkControl) and terrain.GetTerrainType(pt)
end
function XDeleteObjectsTool:Draw(pt1, pt2)
local classes = self:GetObjectClass()
local radius = self:GetCursorRadius()
local callback = function(o)
if not self.deleted_objects[o] and XEditorFilters:IsVisible(o) and o:GetGameFlags(const.gofPermanent) ~= 0 then
if not self.start_terrain or terrain.GetTerrainType(o:GetPos()) == self.start_terrain then
self.deleted_objects[o] = true
o:ClearEnumFlags(const.efVisible)
end
end
end
if #classes > 0 then
for _, class in ipairs(classes) do
MapForEach(pt1, pt2, radius, class, callback)
end
else
MapForEach(pt1, pt2, radius, callback)
end
end
function XDeleteObjectsTool:EndDraw(pt)
if next(self.deleted_objects) then
local objs = table.validate(table.keys(self.deleted_objects))
for _, obj in ipairs(objs) do obj:SetEnumFlags(const.efVisible) end
XEditorUndo:BeginOp({ objects = objs, name = string.format("Deleted %d objects", #objs) })
Msg("EditorCallback", "EditorCallbackDelete", objs)
for _, obj in ipairs(objs) do obj:delete() end
XEditorUndo:EndOp()
end
ResumePassEdits("XEditorDeleteObjects")
self.deleted_objects = false
end
function XDeleteObjectsTool:GetCursorRadius()
local radius = self:GetSize() / 2
return radius, radius
end
function XDeleteObjectsTool:ClearSelection()
self:SetObjectClass({})
ObjModified(self)
end
|