Garry's Mod Wiki

ContentIcon

Description

The spawn icon used for SWEPs and other SENTs, commonly featured as part of the spawn menu. Do note that at least one of your ContentIcon's parents must either be an EditablePanel or derived from it (like a DFrame, for example), else it won't be able to focus and thus be unclickable.

This control only exists in Sandbox derived gamemodes.

View source

Parent

Derives methods, etc not listed on this page from DButton.

Methods

table ContentIcon:GetColor()
An AccessorFunc that returns the color set by ContentIcon:SetColor
string ContentIcon:GetContentType()
An AccessorFunc that returns the content type used to save and restore the content icon in a spawnlist.
table ContentIcon:GetNPCWeapon()
An AccessorFunc that returns a table of weapon classes for the content icon with "NPC" content type to be randomly chosen from when user tries to spawn the NPC.
string ContentIcon:GetSpawnName()
An AccessorFunc that returns the internal "name" for the content icon, usually a class name for an entity.
ContentIcon:OpenMenu()
A hook for override, by default does nothing. Called when user right clicks on the content icon, you are supposed to open a DermaMenu here with additional options.
ContentIcon:SetAdminOnly( boolean adminOnly )
An AccessorFunc that sets whether the content item is admin only. This makes the icon to display a admin icon in the top left corner of the icon.
ContentIcon:SetColor( table clr )
An AccessorFunc that sets the color for the content icon. Currently is not used by the content icon panel.
ContentIcon:SetContentType( string type )
An AccessorFunc that sets the content type used to save and restore the content icon in a spawnlist.
ContentIcon:SetMaterial( string path )
Sets the material to be displayed as the content icon.
ContentIcon:SetName( string name )
Sets the tool tip and the "nice" name to be displayed by the content icon.
ContentIcon:SetNPCWeapon( table weapons )
An AccessorFunc that sets a table of weapon classes for the content icon with "NPC" content type to be randomly chosen from when user tries to spawn the NPC.
ContentIcon:SetSpawnName( string name )
An AccessorFunc that sets the internal "name" for the content icon, usually a class name for an entity.

Example

Creates a button to spawn one or multiple pistols on top of a custom DFrame.

local frame = vgui.Create( "DFrame" ) frame:SetSize( 400, 200 ) frame:Center() frame:SetTitle( "Secret SWEP Spawn Menu" ) frame:MakePopup() local icon = vgui.Create( "ContentIcon", frame ) icon:Center() icon:SetMaterial( "entities/weapon_pistol.png" ) icon:SetName( "Pistol" ) icon.DoClick = function() RunConsoleCommand( "gm_spawnswep", "weapon_pistol" ) end icon.OpenMenu = function() local menu = DermaMenu() menu:AddOption( "Copy to clipboard", function() SetClipboardText( "weapon_pistol" ) end ) menu:AddOption( "Spawn 5", function() for i=1,5 do RunConsoleCommand( "gm_spawnswep", "weapon_pistol" ) end end ) menu:AddOption( "Spawn 10", function() for i=1,10 do RunConsoleCommand( "gm_spawnswep", "weapon_pistol" ) end end ) menu:Open() end
Output: