Permalink
Browse files

Fix gmod_tool(mode) to bring up the context menu.

  • Loading branch information...
1 parent cd2f8ce commit 155284a81d4e8209e52e6e22d34533b4368255bd @robotboy655 robotboy655 committed Jul 15, 2014
@@ -2,6 +2,11 @@
local gmod_drawhelp = CreateClientConVar( "gmod_drawhelp", "1", true, false )
local gmod_toolmode = CreateClientConVar( "gmod_toolmode", "rope", true, true )
+cvars.AddChangeCallback( "gmod_toolmode", function( name, old, new )
+ if ( old == new ) then return end
+ spawnmenu.ActivateTool( new )
+end, "gmod_toolmode_panel" )
+
include('shared.lua')
include('cl_viewscreen.lua')
@@ -261,9 +261,9 @@ function ActivateToolPanel( id, cp )
local Tab = g_SpawnMenu:GetToolMenu():GetToolPanel( id )
if ( !IsValid( Tab ) ) then return end
-
+
spawnmenu.SetActiveControlPanel( cp )
-
+
if ( cp ) then
Tab:SetActive( cp )
end
@@ -275,30 +275,30 @@ 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
+ -- I really don't like this triple loop
+ 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
+
+ if ( item.Command ) then
+ RunConsoleCommand( unpack( string.Explode( " ", item.Command ) ) )
+ end
+
+ local cp = controlpanel.Get( strName )
+ if ( !cp:GetInitialized() ) then
+ cp:FillViaTable( { Text = item.Text, ControlPanelBuildFunction = item.CPanelFunction, Controls = item.Controls } )
+ end
+
+ ActivateToolPanel( tab, cp )
+
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 155284a

Please sign in to comment.