Permalink
Browse files

Addon spawnlists are now separated

  • Loading branch information...
robotboy655 committed Nov 28, 2016
1 parent 4f651b5 commit 4965849af3f70331f050536a11583899dca4227f
@@ -7,14 +7,11 @@ local matOverlay_Normal = Material( "gui/ContentIcon-normal.png" )
local matOverlay_Hovered = Material( "gui/ContentIcon-hovered.png" )
local matOverlay_AdminOnly = Material( "icon16/shield.png" )
AccessorFunc( PANEL, "m_Color", "Color" )
AccessorFunc( PANEL, "m_Type", "ContentType" )
AccessorFunc( PANEL, "m_SpawnName", "SpawnName" )
AccessorFunc( PANEL, "m_NPCWeapon", "NPCWeapon" )
--[[---------------------------------------------------------
Name: Paint
-----------------------------------------------------------]]
AccessorFunc( PANEL, "m_Color", "Color" )
AccessorFunc( PANEL, "m_Type", "ContentType" )
AccessorFunc( PANEL, "m_SpawnName", "SpawnName" )
AccessorFunc( PANEL, "m_NPCWeapon", "NPCWeapon" )
function PANEL:Init()
self:SetPaintBackground( false )
@@ -112,10 +109,10 @@ function PANEL:Paint( w, h )
render.PushFilterMag( TEXFILTER.ANISOTROPIC )
render.PushFilterMin( TEXFILTER.ANISOTROPIC )
self.Image:PaintAt( 3 + self.Border, 3 + self.Border, 128-8-self.Border*2, 128-8-self.Border*2 )
self.Image:PaintAt( 3 + self.Border, 3 + self.Border, 128 - 8 - self.Border * 2, 128 - 8 - self.Border * 2 )
render.PopFilterMag()
render.PopFilterMin()
render.PopFilterMag()
surface.SetDrawColor( 255, 255, 255, 255 )
@@ -137,6 +134,7 @@ function PANEL:Paint( w, h )
surface.SetMaterial( matOverlay_AdminOnly )
surface.DrawTexturedRect( self.Border + 8, self.Border + 8, 16, 16 )
end
end
function PANEL:PaintOver( w, h )
@@ -186,7 +184,7 @@ spawnmenu.AddContentType( "entity", function( container, obj )
if ( !obj.nicename ) then return end
if ( !obj.spawnname ) then return end
local icon = vgui.Create( "ContentIcon", container )
local icon = vgui.Create( "ContentIcon", container )
icon:SetContentType( "entity" )
icon:SetSpawnName( obj.spawnname )
icon:SetName( obj.nicename )
@@ -3,23 +3,18 @@ local AddCustomizableNode = nil
local function SetupCustomNode( node, pnlContent, needsapp )
node.CustomSpawnlist = true -- Used to determine which nodes ContentSidebarToolBox can edit
node.CustomSpawnlist = !node.AddonSpawnlist -- Used to determine which nodes ContentSidebarToolBox can edit
--
-- This spawnlist needs a certain app mounted before it will show up.
--
if ( needsapp && needsapp != "" ) then
node:SetVisible( IsMounted( needsapp ) )
node.NeedsApp = needsapp
end
node.OnModified = function()
hook.Run( "SpawnlistContentChanged" )
end
node.SetupCopy = function( self, copy )
SetupCustomNode( copy, pnlContent )
SetupCustomNode( copy, pnlContent, needsapp )
self:DoPopulate()
@@ -32,26 +27,30 @@ local function SetupCustomNode( node, pnlContent, needsapp )
end
node.DoRightClick = function( self )
if ( !node.AddonSpawnlist ) then
node.OnModified = function()
hook.Run( "SpawnlistContentChanged" )
end
local menu = DermaMenu()
menu:AddOption( "Edit", function() self:InternalDoClick() hook.Run( "OpenToolbox" ) end )
menu:AddOption( "New Category", function() AddCustomizableNode( pnlContent, "New Category", "", self ) self:SetExpanded( true ) hook.Run( "SpawnlistContentChanged" ) end )
menu:AddOption( "Delete", function() node:Remove() hook.Run( "SpawnlistContentChanged" ) end )
node.DoRightClick = function( self )
menu:Open()
local menu = DermaMenu()
menu:AddOption( "Edit", function() self:InternalDoClick() hook.Run( "OpenToolbox" ) end )
menu:AddOption( "New Category", function() AddCustomizableNode( pnlContent, "New Category", "", self ) self:SetExpanded( true ) hook.Run( "SpawnlistContentChanged" ) end )
menu:AddOption( "Delete", function() node:Remove() hook.Run( "SpawnlistContentChanged" ) end )
menu:Open()
end
end
node.DoPopulate = function( self )
if ( !self.PropPanel ) then
if ( IsValid( self.PropPanel ) ) then return end
self.PropPanel = vgui.Create( "ContentContainer", pnlContent )
self.PropPanel:SetVisible( false )
self.PropPanel:SetTriggerSpawnlistChange( true )
end
self.PropPanel = vgui.Create( "ContentContainer", pnlContent )
self.PropPanel:SetVisible( false )
self.PropPanel:SetTriggerSpawnlistChange( true )
end
@@ -67,6 +66,7 @@ end
AddCustomizableNode = function( pnlContent, name, icon, parent, needsapp )
local node = parent:AddNode( name, icon )
node.AddonSpawnlist = parent.AddonSpawnlist
SetupCustomNode( node, pnlContent, needsapp )
@@ -123,22 +123,22 @@ local function ConstructSpawnlist( node )
end
function AddPropsOfParent( pnlContent, node, parentid )
function AddPropsOfParent( pnlContent, node, parentid, customProps )
local Props = spawnmenu.GetPropTable()
local Props = customProps or spawnmenu.GetPropTable()
for FileName, Info in SortedPairs( Props ) do
if ( parentid != Info.parentid ) then continue end
local pnlnode = AddCustomizableNode( pnlContent, Info.name, Info.icon, node, Info.needsapp )
pnlnode:SetExpanded( true )
pnlnode.CustomSpawnlist = true -- Used to determine which nodes ContentSidebarToolBox can edit
pnlnode.DoPopulate = function( self )
if ( self.PropPanel ) then return end
self.PropPanel = vgui.Create( "ContentContainer", pnlContent )
self.PropPanel:SetVisible( false )
self.PropPanel:SetTriggerSpawnlistChange( true )
for i, object in SortedPairs( Info.contents ) do
@@ -147,8 +147,6 @@ function AddPropsOfParent( pnlContent, node, parentid )
end
self.PropPanel:SetTriggerSpawnlistChange( true )
end
AddPropsOfParent( pnlContent, pnlnode, Info.id )
@@ -161,6 +159,8 @@ hook.Add( "PopulateContent", "AddCustomContent", function( pnlContent, tree, nod
local node = AddCustomizableNode( pnlContent, "#spawnmenu.category.your_spawnlists", "", tree )
node:SetDraggableName( "CustomContent" )
node:SetExpanded( true )
node.CustomSpawnlist = nil
node.DoRightClick = function( self )
@@ -170,16 +170,13 @@ hook.Add( "PopulateContent", "AddCustomContent", function( pnlContent, tree, nod
end
--
-- Save the spawnlist when children drag and dropped
--
node.OnModified = function()
hook.Run( "SpawnlistContentChanged" )
end
AddPropsOfParent( pnlContent, node, 0 )
node:SetExpanded( true )
node:MoveToBack()
CustomizableSpawnlistNode = node
@@ -190,6 +187,20 @@ hook.Add( "PopulateContent", "AddCustomContent", function( pnlContent, tree, nod
FirstNode:InternalDoClick()
end
-- Custom stuff from addons
local CustomProps = spawnmenu.GetCustomPropTable()
if ( table.Count( CustomProps ) > 0 ) then
local node = AddCustomizableNode( pnlContent, "#spawnmenu.category.addon_spawnlists", "", tree )
node:SetExpanded( true )
--node:SetDraggableName( "CustomContent" )
node.DoRightClick = function() end
node.OnModified = function() end
node.AddonSpawnlist = true
node.CustomSpawnlist = nil
AddPropsOfParent( pnlContent, node, 0, CustomProps )
end
end )
hook.Add( "OnSaveSpawnlist", "DoSaveSpawnlist", function()
@@ -6,8 +6,10 @@ module( "spawnmenu", package.seeall )
local g_ToolMenu = {}
local CreationMenus = {}
local PropTable = {}
local PropTableCustom = {}
local ActiveToolPanel = nil
local ActiveSpawnlistID = 1000
function SetActiveControlPanel( pnl )
ActiveToolPanel = pnl
@@ -143,24 +145,30 @@ function GetPropTable()
end
--[[---------------------------------------------------------
GetPropTable
GetCustomPropTable
-----------------------------------------------------------]]
function AddPropCategory( strFilename, strName, tabContents, icon, id, parentid, needsapp )
function GetCustomPropTable()
return PropTableCustom
id = id or math.random( 1000, 9999 )
parentid = parentid or 0
end
PropTable[ strFilename ] = {
--[[---------------------------------------------------------
AddPropCategory
-----------------------------------------------------------]]
function AddPropCategory( strFilename, strName, tabContents, icon, id, parentid, needsapp )
PropTableCustom[ strFilename ] = {
name = strName,
icon = icon,
id = id,
parentid = parentid,
contents = tabContents,
icon = icon,
id = id or ActiveSpawnlistID,
parentid = parentid or 0,
needsapp = needsapp
}
if ( !id ) then ActiveSpawnlistID = ActiveSpawnlistID + 1 end
end
--[[---------------------------------------------------------
@@ -170,9 +178,18 @@ function PopulateFromEngineTextFiles()
-- Reset the already loaded prop list before loading them again.
-- This caused the spawnlists to duplicate into crazy trees when spawnmenu_reload'ing after saving edited spawnlists
-- PropTable = {} -- Disabled for now, it breaks addons doing shitty things
spawnmenu_engine.PopulateFromTextFiles( AddPropCategory )
PropTable = {}
spawnmenu_engine.PopulateFromTextFiles( function( strFilename, strName, tabContents, icon, id, parentid, needsapp )
PropTable[ strFilename ] = {
name = strName,
contents = tabContents,
icon = icon,
id = id,
parentid = parentid or 0,
needsapp = needsapp
}
end )
end

0 comments on commit 4965849

Please sign in to comment.