Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Spawn Menu Customization #2142

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,32 @@ end
function PANEL:DoRightClick()

local pCanvas = self:GetSelectionCanvas()

if ( IsValid( pCanvas ) && pCanvas:NumSelectedChildren() > 0 && self:IsSelected() ) then
return hook.Run( "SpawnlistOpenGenericMenu", pCanvas )
end

local oldMenuCount = #GetOpenDermaMenus()

self:OpenMenu()

local openedMenus = GetOpenDermaMenus()

local menuIndex = #openedMenus == oldMenuCount and oldMenuCount or oldMenuCount + 1
local menu = openedMenus[ menuIndex ]

if ( !IsValid( menu ) ) then return end

local parent = menu.ParentMenu

if ( IsValid( parent ) ) then

menu = parent

end

hook.Run( "OnContentIconOpenMenu", self, menu )

end

function PANEL:DoClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,61 @@ list.Set( "ContentCategoryIcons", "Half-Life: Source", "games/16/hl1.png" )
list.Set( "ContentCategoryIcons", "Half-Life 2", "games/16/hl2.png" )
list.Set( "ContentCategoryIcons", "Portal", "games/16/portal.png" )

local function BuildContentList( tab, propPanel )

local orderedList = {}

for k, ent in SortedPairsByMemberValue( tab, "PrintName" ) do

local order = isnumber( ent.SpawnListOrder ) and ent.SpawnListOrder

if ( order ) then

table.insert( orderedList, order, ent )

else

table.insert( orderedList, ent )

end

end

for k, ent in SortedPairs( orderedList ) do

spawnmenu.CreateContentIcon( ent.ScriptedEntityType or "entity", propPanel, {
nicename = ent.PrintName or ent.ClassName,
spawnname = ent.SpawnName,
material = ent.IconOverride or ( "entities/" .. ent.SpawnName .. ".png" ),
admin = ent.AdminOnly
} )

end

end

hook.Add( "PopulateEntities", "AddEntityContent", function( pnlContent, tree, browseNode )

local Categorised = {}

-- Add this list into the tormoil
local SpawnableEntities = list.Get( "SpawnableEntities" )

if ( SpawnableEntities ) then
for k, v in pairs( SpawnableEntities ) do

local Category = v.Category or "Other"
if ( !isstring( Category ) ) then Category = tostring( Category ) end
Categorised[ Category ] = Categorised[ Category ] or {}
Category = tostring( Category )

local SubCategory = v.SubCategory or "Other"
SubCategory = tostring( SubCategory )

v.SpawnName = k
table.insert( Categorised[ Category ], v )

Categorised[ Category ] = Categorised[ Category ] or {}
Categorised[ Category ][ SubCategory ] = Categorised[ Category ][ SubCategory ] or {}

table.insert( Categorised[ Category ][ SubCategory ], v )

end
end
Expand All @@ -26,7 +66,7 @@ hook.Add( "PopulateEntities", "AddEntityContent", function( pnlContent, tree, br
-- Add a tree node for each category
--
local CustomIcons = list.Get( "ContentCategoryIcons" )
for CategoryName, v in SortedPairs( Categorised ) do
for CategoryName, subCategories in SortedPairs( Categorised ) do

-- Add a node to the tree
local node = tree:AddNode( CategoryName, CustomIcons[ CategoryName ] or "icon16/bricks.png" )
Expand All @@ -42,14 +82,37 @@ hook.Add( "PopulateEntities", "AddEntityContent", function( pnlContent, tree, br
self.PropPanel:SetVisible( false )
self.PropPanel:SetTriggerSpawnlistChange( false )

for k, ent in SortedPairsByMemberValue( v, "PrintName" ) do
local createOtherHeader = false

for subCategoryName, tab in SortedPairs( subCategories ) do

if ( subCategoryName == "Other" ) then continue end

local label = vgui.Create( "ContentHeader" )

label:SetText( subCategoryName )

self.PropPanel:Add( label )

BuildContentList( tab, self.PropPanel )

createOtherHeader = true

end

if ( subCategories.Other ) then

if ( createOtherHeader ) then

local label = vgui.Create( "ContentHeader" )

label:SetText( "Other" )

self.PropPanel:Add( label )

end

spawnmenu.CreateContentIcon( ent.ScriptedEntityType or "entity", self.PropPanel, {
nicename = ent.PrintName or ent.ClassName,
spawnname = ent.SpawnName,
material = ent.IconOverride or ( "entities/" .. ent.SpawnName .. ".png" ),
admin = ent.AdminOnly
} )
BuildContentList( subCategories.Other, self.PropPanel )

end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,71 @@

local function BuildContentList( tab, propPanel )

local orderedList = {}

for name, ent in SortedPairsByMemberValue( tab, "Name" ) do

local order = isnumber( ent.SpawnListOrder ) and ent.SpawnListOrder
local data = { name = name, ent = ent }

if ( order ) then

table.insert( orderedList, order, data )

else

table.insert( orderedList, data )

end

end

for k, data in SortedPairs( orderedList ) do

local ent = data.ent
local name = data.name

spawnmenu.CreateContentIcon( ent.ScriptedEntityType or "npc", propPanel, {
nicename = ent.Name or name,
spawnname = name,
material = ent.IconOverride or "entities/" .. name .. ".png",
weapon = ent.Weapons,
admin = ent.AdminOnly
} )

end

end

hook.Add( "PopulateNPCs", "AddNPCContent", function( pnlContent, tree, browseNode )

-- Get a list of available NPCs
local NPCList = list.Get( "NPC" )

-- Categorize them
local Categories = {}

for k, v in pairs( NPCList ) do

local Category = v.Category or "Other"
if ( !isstring( Category ) ) then Category = tostring( Category ) end
Category = tostring( Category )

local SubCategory = v.SubCategory or "Other"
SubCategory = tostring( SubCategory )

local Tab = Categories[ Category ] or {}
Tab[ k ] = v
local subCategoryTab = Tab[ SubCategory ] or {}

subCategoryTab[ k ] = v

Tab[ SubCategory ] = subCategoryTab
Categories[ Category ] = Tab

end

-- Create an icon for each one and put them on the panel
local CustomIcons = list.Get( "ContentCategoryIcons" )
for CategoryName, v in SortedPairs( Categories ) do
for CategoryName, subCategories in SortedPairs( Categories ) do

-- Add a node to the tree
local node = tree:AddNode( CategoryName, CustomIcons[ CategoryName ] or "icon16/monkey.png" )
Expand All @@ -35,15 +81,37 @@ hook.Add( "PopulateNPCs", "AddNPCContent", function( pnlContent, tree, browseNod
self.PropPanel:SetVisible( false )
self.PropPanel:SetTriggerSpawnlistChange( false )

for name, ent in SortedPairsByMemberValue( v, "Name" ) do
local createOtherHeader = false

for subCategoryName, tab in SortedPairs( subCategories ) do

if ( subCategoryName == "Other" ) then continue end

local label = vgui.Create( "ContentHeader" )

label:SetText( subCategoryName )

self.PropPanel:Add( label )

BuildContentList( tab, self.PropPanel )

createOtherHeader = true

end

if ( subCategories.Other ) then

if ( createOtherHeader ) then

local label = vgui.Create( "ContentHeader" )

label:SetText( "Other" )

self.PropPanel:Add( label )

end

spawnmenu.CreateContentIcon( ent.ScriptedEntityType or "npc", self.PropPanel, {
nicename = ent.Name or name,
spawnname = name,
material = ent.IconOverride or "entities/" .. name .. ".png",
weapon = ent.Weapons,
admin = ent.AdminOnly
} )
BuildContentList( subCategories.Other, self.PropPanel )

end

Expand Down
Loading