diff --git a/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/stool.lua b/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/stool.lua index a734f2aac1..9042e14bb7 100644 --- a/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/stool.lua +++ b/garrysmod/gamemodes/sandbox/entities/weapons/gmod_tool/stool.lua @@ -63,6 +63,17 @@ function ToolObj:GetServerInfo( property ) end +function ToolObj:BuildConVarList() + + local mode = self:GetMode() + local convars = {} + + for k, v in pairs( self.ClientConVar ) do convars[ mode .. "_" .. k ] = v end + + return convars + +end + function ToolObj:GetClientInfo( property ) local mode = self:GetMode() @@ -180,10 +191,12 @@ if ( CLIENT ) then if ( !k:find( str ) ) then continue end - local entry = - { - text = v.Name or "#"..k, - icon = spawnmenu.CreateContentIcon( "tool", nil, { type = k } ), + local entry = { + text = v.Name or "#" .. k, + icon = spawnmenu.CreateContentIcon( "tool", nil, { + spawnname = k, + nicename = v.Name or "#" .. k + } ), words = { k } } @@ -195,40 +208,43 @@ if ( CLIENT ) then return list - end ); + end ) -- -- Tool spawnmenu icon -- spawnmenu.AddContentType( "tool", function( container, obj ) - if ( !obj.type ) then return end - + if ( !obj.spawnname ) then return end + local icon = vgui.Create( "ContentIcon", container ) - icon:SetContentType( "tool" ) - icon:SetSpawnName( obj.type ) - icon:SetName( obj.type ) - icon:SetMaterial( "gui/tool.png" ) + icon:SetContentType( "tool" ) + icon:SetSpawnName( obj.spawnname ) + icon:SetName( obj.nicename or "#tool." .. obj.spawnname .. ".name" ) + icon:SetMaterial( "gui/tool.png" ) + + icon.DoClick = function() + + spawnmenu.ActivateTool( obj.spawnname ) - icon.DoClick = function() - RunConsoleCommand( "gmod_tool", obj.type ); - surface.PlaySound( "ui/buttonclickrelease.wav" ) - end + surface.PlaySound( "ui/buttonclickrelease.wav" ) + + end - icon.OpenMenu = function( icon ) + icon.OpenMenu = function( icon ) - local menu = DermaMenu() - menu:AddOption( "Delete", function() icon:Remove(); hook.Run( "SpawnlistContentChanged", icon ) end ) - menu:Open() + local menu = DermaMenu() + menu:AddOption( "Delete", function() icon:Remove() hook.Run( "SpawnlistContentChanged", icon ) end ) + menu:Open() - end + end if ( IsValid( container ) ) then container:Add( icon ) end - return icon; + return icon end ) -end \ No newline at end of file +end diff --git a/garrysmod/gamemodes/sandbox/gamemode/spawnmenu/toolpanel.lua b/garrysmod/gamemodes/sandbox/gamemode/spawnmenu/toolpanel.lua index 01e616841b..6b6e41b4f2 100644 --- a/garrysmod/gamemodes/sandbox/gamemode/spawnmenu/toolpanel.lua +++ b/garrysmod/gamemodes/sandbox/gamemode/spawnmenu/toolpanel.lua @@ -1,8 +1,8 @@ + include( 'controlpanel.lua' ) local PANEL = {} - AccessorFunc( PANEL, "m_TabID", "TabID" ) --[[--------------------------------------------------------- @@ -62,7 +62,7 @@ function PANEL:AddCategory( Name, Label, tItems ) local Category = self.List:Add( Label ) - Category:SetCookieName( "ToolMenu."..tostring(Name) ) + Category:SetCookieName( "ToolMenu." .. tostring( Name ) ) local bAlt = true @@ -70,26 +70,17 @@ function PANEL:AddCategory( Name, Label, tItems ) local item = Category:Add( v.Text ) - item.DoClick = function( button ) - - local cp = controlpanel.Get( button.Name ) - if ( !cp:GetInitialized() ) then - cp:FillViaTable( button ) - end - - spawnmenu.ActivateToolPanel( self:GetTabID(), cp ) - - if ( button.Command ) then - LocalPlayer():ConCommand( button.Command ) - end - + item.DoClick = function( button ) + + spawnmenu.ActivateTool( button.Name ) + end - item.ControlPanelBuildFunction = v.CPanelFunction - item.Command = v.Command - item.Name = v.ItemName - item.Controls = v.Controls - item.Text = v.Text + item.ControlPanelBuildFunction = v.CPanelFunction + item.Command = v.Command + item.Name = v.ItemName + item.Controls = v.Controls + item.Text = v.Text end @@ -110,4 +101,4 @@ function PANEL:SetActive( cp ) end -vgui.Register( "ToolPanel", PANEL, "Panel" ) \ No newline at end of file +vgui.Register( "ToolPanel", PANEL, "Panel" ) diff --git a/garrysmod/lua/includes/modules/spawnmenu.lua b/garrysmod/lua/includes/modules/spawnmenu.lua index 06e531cfd6..e19416f8ba 100644 --- a/garrysmod/lua/includes/modules/spawnmenu.lua +++ b/garrysmod/lua/includes/modules/spawnmenu.lua @@ -1,5 +1,5 @@ -local spawnmenu_engine = spawnmenu +local spawnmenu_engine = spawnmenu --[[--------------------------------------------------------- @@ -79,6 +79,7 @@ function AddToolTab( strName, strLabel, Icon ) end + --[[--------------------------------------------------------- -----------------------------------------------------------]] @@ -233,7 +234,7 @@ function GetContentType( name, func ) if ( !cp[ name ] ) then cp[ name ] = function() end - Msg( "spawnmenu.GetContentType( ", name, " ) - not found!\n" ); + Msg( "spawnmenu.GetContentType( ", name, " ) - not found!\n" ) end @@ -242,7 +243,7 @@ end function CreateContentIcon( type, parent, tbl ) - local cp = GetContentType( type ); + local cp = GetContentType( type ) if ( cp ) then return cp( parent, tbl ) end end @@ -264,9 +265,40 @@ function ActivateToolPanel( id, cp ) spawnmenu.SetActiveControlPanel( cp ) if ( cp ) then - Tab:SetActive( cp ); + Tab:SetActive( cp ) end SwitchToolTab( id ) -end \ No newline at end of file +end + +-- While technically tool class names CAN be duplicate, it normally should never happen. +function ActivateTool( strName ) + + -- Hacky code to get table of a tool and its tab + local tool = {} + local tab = 1 + for Tab, v in ipairs( g_ToolMenu ) do + for _, items in pairs( v.Items ) do + for _, item in pairs( items ) do + if ( istable( item ) && item.ItemName && item.ItemName == strName ) then + tool = item + tab = Tab + break + end + end + end + + end + + RunConsoleCommand( unpack( string.Explode( " ", tool.Command ) ) ) + + local cp = controlpanel.Get( strName ) + if ( !cp:GetInitialized() ) then + cp:FillViaTable( { Text = tool.Text, ControlPanelBuildFunction = tool.CPanelFunction, Controls = tool.Controls } ) + end + + ActivateToolPanel( tab, cp ) + SwitchToolTab( tab ) + +end