DERMA: SpawnIcon In DPanel In DCollapsibleCategory In DPanelList

Hey, I’m trying to put SpawnIcon’s inside a DPanel inside a few DCollapsibleCategorys which are organized in a DPanelList but there are some issues :confused:

The DCollapsibleCategorys will collapse but never expand again.
The DPanelList has a scroll bar but it doesn’t actuall scroll anything.

Any suggestions as to what might be happening?


local BaseClassEntityList = vgui.Create( "DPanelList", DX_Panel_Sheets )
BaseClassEntityList:SetPos( 5,5 )
BaseClassEntityList:SetSize( 765, 540 )
BaseClassEntityList:SetAutoSize( true )
BaseClassEntityList:SetSpacing( 5 )
BaseClassEntityList:EnableHorizontal( false )
BaseClassEntityList:EnableVerticalScrollbar( true )

local DX_LeaderCategory = vgui.Create("DCollapsibleCategory")
DX_LeaderCategory:SetSize( 765, 100 )
DX_LeaderCategory:SetExpanded( 1 )
DX_LeaderCategory:SetLabel( "Resistance Leader" )
BaseClassEntityList:AddItem( DX_LeaderCategory )

local DX_LeaderCategoryFrame = vgui.Create( "DPanel" )
DX_LeaderCategoryFrame:SetPos( 5, 5 )
DX_LeaderCategoryFrame:SetSize( 755, 90 )
DX_LeaderCategory:SetContents( DX_LeaderCategoryFrame )

local SpawnA001 = vgui.Create( "SpawnIcon", DX_LeaderCategoryFrame )
SpawnA001:SetPos(5,5)
SpawnA001:SetModel( "models/Madman07/destiny_emmiter/destiny_emmiter.mdl" )
SpawnA001:SetToolTip( "Command Point (CP)" )
SpawnA001.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_command_main")
end

local DX_EngineerCategory = vgui.Create("DCollapsibleCategory")
DX_EngineerCategory:SetSize( 765, 230 )
DX_EngineerCategory:SetExpanded( 1 )
DX_EngineerCategory:SetLabel( "Civil Engineer" )
BaseClassEntityList:AddItem( DX_EngineerCategory )

local DX_EngineerCategoryFrame = vgui.Create( "DPanel" )
DX_EngineerCategoryFrame:SetPos( 5, 5 )
DX_EngineerCategoryFrame:SetSize( 765, 220 )
DX_EngineerCategory:SetContents( DX_EngineerCategoryFrame )

local SpawnB001 = vgui.Create( "SpawnIcon", DX_EngineerCategoryFrame )
SpawnB001:SetPos(5,5)
SpawnB001:SetModel( "models/buildables/sentry1.mdl" )
SpawnB001:SetToolTip( "Sentinel Defence Turret" )
SpawnB001.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_defence_sturret")
end

local SpawnB006 = vgui.Create( "SpawnIcon", DX_EngineerCategoryFrame )
SpawnB006:SetPos(70,5)
SpawnB006:SetModel( "models/props_c17/pottery03a.mdl" )
SpawnB006:SetToolTip( "Mobile Spawn Point" )
SpawnB006.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_spawn_player")
end

local SpawnB002 = vgui.Create( "SpawnIcon", DX_EngineerCategoryFrame )
SpawnB002:SetPos(5,70)
SpawnB002:SetModel( "models/props/de_nuke/equipment3a.mdl" )
SpawnB002:SetToolTip( "Tier-1 Power Generator - $5,000" )
SpawnB002.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_power_t1")
end

local SpawnB003 = vgui.Create( "SpawnIcon", DX_EngineerCategoryFrame )
SpawnB003:SetPos(70,70)
SpawnB003:SetModel( "models/props/de_nuke/equipment2.mdl" )
SpawnB003:SetToolTip( "Tier-2 Power Generator - $10,000" )
SpawnB003.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_power_t2")
end

local SpawnB004 = vgui.Create( "SpawnIcon", DX_EngineerCategoryFrame )
SpawnB004:SetPos(5,135)
SpawnB004:SetModel( "models/props/cs_assault/ACUnit02.mdl" )
SpawnB004:SetToolTip( "Tier-1 Coolant Generator - $5,000" )
SpawnB004.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_coolant_t1")
end

local SpawnB005 = vgui.Create( "SpawnIcon", DX_EngineerCategoryFrame )
SpawnB005:SetPos(70,135)
SpawnB005:SetModel( "models/props/cs_assault/ACUnit01.mdl" )
SpawnB005:SetToolTip( "Tier-2 Coolant Generator - $10,000" )
SpawnB005.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_coolant_t2")
end

local DX_EconomistCategory = vgui.Create("DCollapsibleCategory")
DX_EconomistCategory:SetSize( 765, 100 )
DX_EconomistCategory:SetExpanded( 1 )
DX_EconomistCategory:SetLabel( "Economist" )
BaseClassEntityList:AddItem( DX_EconomistCategory )

local DX_EconomistCategoryFrame = vgui.Create( "DPanel" )
DX_EconomistCategoryFrame:SetPos( 5, 5 )
DX_EconomistCategoryFrame:SetSize( 765, 90 )
DX_EconomistCategory:SetContents( DX_EconomistCategoryFrame )

local SpawnD001 = vgui.Create( "SpawnIcon", DX_EconomistCategoryFrame )
SpawnD001:SetPos(5,5)
SpawnD001:SetModel( "models/props/de_train/de_train_signalbox_01.mdl" )
SpawnD001:SetToolTip( "Bank Vault" )
SpawnD001.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_bank_vault")
end

local DX_CivilServicesCategory = vgui.Create("DCollapsibleCategory")
DX_CivilServicesCategory:SetSize( 765, 100 )
DX_CivilServicesCategory:SetExpanded( 1 )
DX_CivilServicesCategory:SetLabel( "Civil Services" )
BaseClassEntityList:AddItem( DX_CivilServicesCategory )

local DX_CivilServicesCategoryFrame = vgui.Create( "DPanel" )
DX_CivilServicesCategoryFrame:SetPos( 5, 5 )
DX_CivilServicesCategoryFrame:SetSize( 765, 90 )
DX_CivilServicesCategory:SetContents( DX_CivilServicesCategoryFrame )

local SpawnE001 = vgui.Create( "SpawnIcon", DX_CivilServicesCategoryFrame )
SpawnE001:SetPos(5,5)
SpawnE001:SetModel( "models/props_spytech/control_room_console02.mdl" )
SpawnE001:SetToolTip( "Terminal Weaponry" )
SpawnE001.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_terminal_weaponry")
end

local SpawnE002 = vgui.Create( "SpawnIcon", DX_CivilServicesCategoryFrame )
SpawnE002:SetPos(70,5)
SpawnE002:SetModel( "models/props/cs_militia/gun_cabinet.mdl" )
SpawnE002:SetToolTip( "Terminal Weaponry Exchange" )
SpawnE002.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_terminal_weaponry_exchange")
end

local DX_IllegalCategory = vgui.Create("DCollapsibleCategory")
DX_IllegalCategory:SetSize( 765, 100 )
DX_IllegalCategory:SetExpanded( 1 )
DX_IllegalCategory:SetLabel( "Illegals" )
BaseClassEntityList:AddItem( DX_IllegalCategory )

local DX_IllegalCategoryFrame = vgui.Create( "DPanel" )
DX_IllegalCategoryFrame:SetPos( 5, 5 )
DX_IllegalCategoryFrame:SetSize( 765, 90 )
DX_IllegalCategory:SetContents( DX_IllegalCategoryFrame )

local SpawnC001 = vgui.Create( "SpawnIcon", DX_IllegalCategoryFrame )
SpawnC001:SetPos(5,5)
SpawnC001:SetModel( "models/props_lab/reciever01d.mdl" )
SpawnC001:SetToolTip( "Tier-1 Money Printer $1,000" )
SpawnC001.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_money_t1")
end

local SpawnC002 = vgui.Create( "SpawnIcon", DX_IllegalCategoryFrame )
SpawnC002:SetPos(70,5)
SpawnC002:SetModel( "models/props_lab/reciever01b.mdl" )
SpawnC002:SetToolTip( "Tier-2 Money Printer $2,000" )
SpawnC002.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_money_t2")
end

local SpawnC003 = vgui.Create( "SpawnIcon", DX_IllegalCategoryFrame )
SpawnC003:SetPos(135,5)
SpawnC003:SetModel( "models/props_lab/reciever01a.mdl" )
SpawnC003:SetToolTip( "Tier-3 Money Printer $4,000" )
SpawnC003.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_money_t3")
end

local SpawnC004 = vgui.Create( "SpawnIcon", DX_IllegalCategoryFrame )
SpawnC004:SetPos(200,5)
SpawnC004:SetModel( "models/props_c17/consolebox05a.mdl" )
SpawnC004:SetToolTip( "Tier-4 Money Printer $8,000" )
SpawnC004.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_money_t4")
end

local SpawnC005 = vgui.Create( "SpawnIcon", DX_IllegalCategoryFrame )
SpawnC005:SetPos(265,5)
SpawnC005:SetModel( "models/props_c17/consolebox03a.mdl" )
SpawnC005:SetToolTip( "Tier-5 Money Printer $16,000" )
SpawnC005.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_money_t5")
end

local SpawnC006 = vgui.Create( "SpawnIcon", DX_IllegalCategoryFrame )
SpawnC006:SetPos(330,5)
SpawnC006:SetModel( "models/props_c17/consolebox01a.mdl" )
SpawnC006:SetToolTip( "Tier-6 Money Printer $32,000" )
SpawnC006.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_money_t6")
end

local SpawnC007 = vgui.Create( "SpawnIcon", DX_IllegalCategoryFrame )
SpawnC007:SetPos(395,5)
SpawnC007:SetModel( "models/props/de_prodigy/desk_console3.mdl" )
SpawnC007:SetToolTip( "Tier-7 Money Printer $64,000" )
SpawnC007.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_money_t7")
end

local SpawnC008 = vgui.Create( "SpawnIcon", DX_IllegalCategoryFrame )
SpawnC008:SetPos(460,5)
SpawnC008:SetModel( "models/props/de_nuke/nucleartestcabinet.mdl" )
SpawnC008:SetToolTip( "Tier-8 Money Printer $128,000" )
SpawnC008.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_money_t8")
end

local SpawnC009 = vgui.Create( "SpawnIcon", DX_IllegalCategoryFrame )
SpawnC009:SetPos(525,5)
SpawnC009:SetModel( "models/props_lab/servers.mdl" )
SpawnC009:SetToolTip( "Tier-9 Money Printer $256,000" )
SpawnC009.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_money_t9")
end

local SpawnC010 = vgui.Create( "SpawnIcon", DX_IllegalCategoryFrame )
SpawnC010:SetPos(590,5)
SpawnC010:SetModel( "models/props_spytech/computer_low.mdl" )
SpawnC010:SetToolTip( "Tier-10 Money Printer $512,000" )
SpawnC010.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_generator_money_t10")
end

I know there’s a lot of code there >.<

I make a list


local BaseClassEntityList = vgui.Create( "DPanelList", DX_Panel_Sheets )
BaseClassEntityList:SetPos( 5,5 )
BaseClassEntityList:SetSize( 765, 540 )
BaseClassEntityList:SetAutoSize( true )
BaseClassEntityList:SetSpacing( 5 )
BaseClassEntityList:EnableHorizontal( false )
BaseClassEntityList:EnableVerticalScrollbar( true )

Add a category


local DX_LeaderCategory = vgui.Create("DCollapsibleCategory")
DX_LeaderCategory:SetSize( 765, 100 )
DX_LeaderCategory:SetExpanded( 1 )
DX_LeaderCategory:SetLabel( "Resistance Leader" )
BaseClassEntityList:AddItem( DX_LeaderCategory )

Put a frame in it


local DX_LeaderCategoryFrame = vgui.Create( "DPanel" )
DX_LeaderCategoryFrame:SetPos( 5, 5 )
DX_LeaderCategoryFrame:SetSize( 755, 90 )
DX_LeaderCategory:SetContents( DX_LeaderCategoryFrame )

Add some spawn icons to the frame


local SpawnA001 = vgui.Create( "SpawnIcon", DX_LeaderCategoryFrame )
SpawnA001:SetPos(5,5)
SpawnA001:SetModel( "models/Madman07/destiny_emmiter/destiny_emmiter.mdl" )
SpawnA001:SetToolTip( "Command Point (CP)" )
SpawnA001.DoClick = function( button )
	surface.PlaySound( "ui/buttonclickrelease.wav" )
	RunConsoleCommand("gm_spawnsent", "dx_command_main")
end

Then repeat adding more categories to the list, a frame to each category, and spawn icons to each frame.

I suggest you make a custom function for all those SpawnIcons and you will save a lot of lines.

Okay, will do, any ideas on the scrolling & expanding/contracting?

Instead of DPanel use DPanelList or DScrollPanel.