Permalink
Browse files

Merge pull request #623 from robotboy655/tools

Fixed tools in spawnlists not opening contentmenu
  • Loading branch information...
2 parents f2d19b2 + 729146b commit 7ec4b2a69a941fa1fa61e43eec43af4e908946fe @UnderscoreKilburn UnderscoreKilburn committed Mar 3, 2014
@@ -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
+end
@@ -1,8 +1,8 @@
+
include( 'controlpanel.lua' )
local PANEL = {}
-
AccessorFunc( PANEL, "m_TabID", "TabID" )
--[[---------------------------------------------------------
@@ -62,34 +62,25 @@ 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
for k, v in pairs( tItems ) do
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" )
+vgui.Register( "ToolPanel", PANEL, "Panel" )
@@ -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
+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

0 comments on commit 7ec4b2a

Please sign in to comment.