Spawnmenu -> Toolmenu

Is there a way to completely hide the default toolmenu and rewrite your own only showing specific tools? Can functions or sections of code be suggested please. If possible write a short explanation a long with your function/codesnippet.

You could try overriding the register,

[LUA]
local PANEL = {}

function PANEL:Init()

end

function PANEL:LoadTools()
self:AddToolPanel(Name, ToolTable) //Here is where you would add each tool you want, You’ll have to figure out what a tooltable is.
end

function PANEL:AddToolPanel( Name, ToolTable )
local Panel = vgui.Create( “ToolPanel” )
Panel:LoadToolsFromTable( ToolTable.Items )

self:AddSheet( ToolTable.Label, Panel, ToolTable.Icon )

self.ToolPanels[ Name ] = Panel

end

function PANEL:Paint()
DPropertySheet.Paint( self )
end

function PANEL:PerformLayout()
DPropertySheet.PerformLayout( self )
self:SizeToContentWidth()
end

vgui.Register( “ToolMenu2”, PANEL, “DPropertySheet” )
[/LUA]

Edit* okay you need to do abit more then that. Change the vgui.Register to a new name like “ToolMenu2”

You’ll need to create a client side autorun file to do this next part.

[LUA]
spawnmenu.ClearToolMenus()

spawnmenu.ToolMenu = vgui.Create( "ToolMenu2", spawnmenu)
spawnmenu.ToolMenu:Dock( RIGHT );
spawnmenu.ToolMenu:DockMargin( 0, 20, 3, 10 )
spawnmenu.ToolMenu:LoadTools()
spawnmenu.ToolMenu:SetVisible( !spawnmenu.ToolMenu:IsVisible() );
spawnmenu:InvalidateLayout()

[/LUA]

I shall try that and afterwards ill edit something in here to tell you of the results.

*edit, The spawnmenu no longer opens close to what i wanted, but may need to be more specific to the tools panel…

*edit, sent a steam friend request an IM may make this easier if you do not mind?

That with the edited code?

and if you can’t figure out what a tooltable is you can do this.

[LUA]
function PANEL:LoadTools()
local ToolNames = {Weld=true, Rope=true} //add the tool names you want here
for k,v in pairs(spawnmenu.GetTools())do
if(!ToolNames[k])then continue end
self:AddToolPanel(k, v)
end
end
[/LUA]

Can you accept my steam friends request so I can maybe contact you another day, I will need to continue this later as i have to go.

I just did this for my game I’ll post the code so you can look at it.
– this is a shared table so it’s on both client and server this is our list of tools
– Name first then the actual tool mode name which is the file name without the .lua
[lua]
tools = {}
table.insert(tools, { “Axis” , “axis” } )
table.insert(tools, { “Weld” , “weld” } )
table.insert(tools, { “EZ Weld” , “weld_ez” } )
table.insert(tools, { “Smart Weld”, “smartwelder” } )
table.insert(tools, { “Rope” , “rope” } )
table.insert(tools, { “Elastic” , “elastic” } )
table.insert(tools, { “Hydraulic”, “hydraulic” } )
table.insert(tools, { “Winch” , “winch” } )
table.insert(tools, { “No Collide” , “nocollide” } )
table.insert(tools, { “Ballsocket” , “ballsocket” } )
table.insert(tools, { “EZ Ballsocket” , “ballsocket_ez” } )
table.insert(tools, { “Physical Properties” , “physprop” } )
table.insert(tools, { “Color” , “colour” } )
table.insert(tools, { “Material” , “material” } )
table.insert(tools, { “Camera” , “camera” } )
table.insert(tools, { “RT Camera” , “rtcamera” } )
table.insert(tools, { “Light”, “light”})
[/lua]

– Next in a client side file you need to disable the regular spawn menu like this

[lua]
function GM:SpawnMenuEnabled()
return false
end

function GM:SpawnMenuOpen()
return false
end
[/lua]

– then in either the same client file or another I used two files one for functions one for the meun
– Anyway I show the menu based on a key think hook.
[lua]
– Variables to hold the menus
cInside = “amd”
MeteorMenu = “bah”
– Variables to see if things are open and such
showCMenu = false
showQMenu = false
allowMenu = true
allowTime = CurTime()
keyNextThink = CurTime()

– these keep the c and q keys from working when chat is open
– don’t know about detecting when the console is open though
function GM:StartChat(TeamSay)
allowMenu = false
end

function GM:FinishChat(TeamSay)
allowMenu = true
end

– the brains of it this runs using the keyNextThink to check for key presses / key holding
function fanKeyPressed()

if allowMenu and (CurTime() > keyNextThink) then
	if input.IsKeyDown(KEY_C) and
		!showCMenu and 
		!inRound then 
		if LocalPlayer():GetActiveWeapon():IsValid() then
			if LocalPlayer():GetActiveWeapon():GetClass() == "gmod_tool" then
				--print("Context Menu Open")

				local curMode = LocalPlayer():GetActiveWeapon().current_mode
				if curMode == nil then return end
				spawnmenu.AddContext("Options", "ToolsOptions_" .. curMode, "Tools Options", "Tools Options Menu")
				cInside = GetControlPanel("ToolsOptions_" .. curMode)
				cInside:ClearControls()
				cInside.VertPos = 5
				
				cInside:SetSize(275, 800)
				cInside:SetPos(ScrW() - 290, 0)
				
				--print(tostring(LocalPlayer():GetActiveWeapon().Tool[curMode].BuildCPanel))
				
				if !(LocalPlayer():GetActiveWeapon():GetTable()['Tool'][curMode].BuildCPanel == nil) then
					LocalPlayer():GetActiveWeapon():GetTable()['Tool'][curMode].BuildCPanel(cInside)
				else
					--print("curMode: " .. tostring(curMode))
					toolContextFromFile(curMode, cInside)
				end
				cInside:SetText(curMode)
				cInside:PerformLayout()				
				cInside:SetVisible(true)
				if cInside.once == nil then
					cInside.once = true
					cInside:MakePopup()
				end
				showCMenu = true
			end
		end
	elseif showCMenu and
		!input.IsKeyDown(KEY_C) then
		--print("Context Menu Closed")
		--print(cInside)
		cInside:SetVisible(false)
		--cInside:Close()
		showCMenu = false
	end
	
	if allowMenu and (CurTime() > keyNextThink) and
	   input.IsKeyDown(KEY_Q) and
		!showQMenu and
		!inRound then 
					
			if MeteorMenu == "bah" then createSpawnMenu() end
			MeteorMenu:SetVisible(true)
			if MeteorMenu.once == nil then
				MeteorMenu.once = true
				MeteorMenu:MakePopup()
			end
			showQMenu = true

		
	elseif showQMenu and
		!input.IsKeyDown(KEY_Q) then
		--print("Spawn Menu Closed")
		RememberCursorPosition()
		MeteorMenu:SetVisible(false)
		MeteorMenu:Close()
		showQMenu = false
	end
keyNextThink = CurTime() + 0.25
end

end
hook.Add( “Think”, “fanKeyPressed”, fanKeyPressed )

– And this is the most important function if the tool doesn’t have a buildCpanel function this will read it from the text file. There is a build in function to do this but it didn’t work for me. Pretty much copied off the panel object in the code bin.
function toolContextFromFile( strName, cp )

local file = file.Read( "settings/controls/"..strName..".txt", true )
if (!file) then return end
local Tab = KeyValuesToTablePreserveOrder( file )
if (!Tab) then return end

for k, data in pairs( Tab ) do
    if ( type( data.Value ) == "table" ) then
        local kv = table.CollapseKeyValue( data.Value )
        local ctrl = cp:AddControl( data.Key, kv )
        if ( ctrl && kv.description ) then
            ctrl:SetTooltip( kv.description );
        end
    end
    
end

end

– This function creates the spawn menu the first time you open it
function createSpawnMenu()

			RestoreCursorPosition( )			
			local claimPropButton
			local sellPropertyButton
			local buyPropertyButton
			local sellPropButton
			local actionPanel
			local DButton1
			local toolLabel
			local actionLabel
			local toolPanel
			local propLabel
			local propPanel
			
			
			MeteorMenu = vgui.Create('DFrame')
			MeteorMenu:SetSize(513, 408)
			MeteorMenu:Center()
			MeteorMenu:SetTitle('Meteor Defense Menu')
			MeteorMenu:SetDeleteOnClose(false)
			
	
			--Panel's	
			propPanel = vgui.Create('DPanel')
			propPanel:SetSize(208, 335)
			
			entityPanel = vgui.Create('DPanel')
			entityPanel:SetSize(208,335)
			
			toolPanel = vgui.Create('DPanel')
			toolPanel:SetParent(MeteorMenu)
			toolPanel:SetSize(135, 335)
			toolPanel:SetPos(223, 55)

			actionPanel = vgui.Create('DPanel')
			actionPanel:SetParent(MeteorMenu)
			actionPanel:SetSize(140, 335)
			actionPanel:SetPos(363, 55)

			iconSheet = vgui.Create('DPropertySheet', MeteorMenu)
			iconSheet:SetPos(10,34)
			iconSheet:SetSize(210,356)
			
			--Labels
			toolLabel = vgui.Create('DLabel')
			toolLabel:SetParent(MeteorMenu)
			toolLabel:SetPos(223, 38)
			toolLabel:SetText('Tools')
			toolLabel:SizeToContents()

			actionLabel = vgui.Create('DLabel')
			actionLabel:SetParent(MeteorMenu)
			actionLabel:SetPos(363, 38)
			actionLabel:SetText('Actions')
			actionLabel:SizeToContents()
			
			-- Spawn Icons
			local rowCount = 0
			local rowOffset = 10
			local perCol = 3
			local colCount = 0
			local colOffset = 10
			local spawnIconWidth = 62
			local spawnIconHeight = 62
			
			for k,v in pairs(props) do
			
				local spawnIcon = vgui.Create('SpawnIcon')
				spawnIcon:SetModel(v[2])
				spawnIcon:SetParent(propPanel)
				spawnIcon:SetPos((colOffset + ( colCount * spawnIconWidth)), (rowOffset + ( rowCount * spawnIconHeight)))
				local toolTip = v[1] .. " 

" … "Cost: " … tostring(v[3])
spawnIcon:SetToolTip( toolTip )
spawnIcon.OnMousePressed = function() RunConsoleCommand(“fan_buy”, k) end
spawnIcon.OnMouseReleased = function() RememberCursorPosition( ) MeteorMenu:Close() end

				colCount = colCount + 1
				if colCount == perCol then
					colCount = 0
					rowCount = rowCount +1
				end
				
			end	
			
			rowCount = 0
			colCount = 0
			
			for k,v in pairs(entities) do
			
				local spawnIcon = vgui.Create('SpawnIcon')
				spawnIcon:SetModel(v[2])
				spawnIcon:SetParent(entityPanel)
				spawnIcon:SetPos((colOffset + ( colCount * spawnIconWidth)), (rowOffset + ( rowCount * spawnIconHeight)))
				local toolTip = "OMFG!!! It's BROKE!!"
				if v[4] > 0 then 
					toolTip = v[1] .. "

"
… "Radius: " … tostring(v[4]) … "
"
… "Energy: " … tostring(v[5]) … "
"
… "Cost: " … tostring(v[6]) … "
"
else
toolTip = v[1] … "
"
… "Cost: " … tostring(v[6]) … "
"
end
spawnIcon:SetToolTip( toolTip )
spawnIcon.OnMousePressed = function() RunConsoleCommand(“fan_buy”, v[3], k ) end
spawnIcon.OnMouseReleased = function() RememberCursorPosition( ) MeteorMenu:Close() end

				colCount = colCount + 1
				if colCount == perCol then
					colCount = 0
					rowCount = rowCount +1
				end
				
			end	
			
			iconSheet:AddSheet("Props", propPanel, "gui/silkicons/toybox", false, false, "Things to build with.")
			iconSheet:AddSheet("Entities", entityPanel, "gui/silkicons/shield", false, false, "Things to help defend.")
			
			-- Tools
			local toolCount = 0
			local sidePad = 5
			local topPad = 5
			
			for k, v in pairs(tools) do
			
				local toolButton = vgui.Create('DButton')
				toolButton:SetParent(toolPanel)
				toolButton:SetSize(125, 19)
				toolButton:SetPos(sidePad, topPad + (toolCount * 19))
				toolButton:SetText(v[1])
				toolButton.DoClick = function() RunConsoleCommand("gmod_tool", v[2]) RememberCursorPosition( ) MeteorMenu:Close() end
				toolCount = toolCount + 1
			
			end

			-- Action Buttons
			buyPropertyButton = vgui.Create('DButton')
			buyPropertyButton:SetParent(actionPanel)
			buyPropertyButton:SetSize(130, 25)
			buyPropertyButton:SetPos(5, 5)
			buyPropertyButton:SetText('Buy Property')
			buyPropertyButton.DoClick = function() RunConsoleCommand("fan_buy", "property") RememberCursorPosition( ) MeteorMenu:Close() end

			sellPropertyButton = vgui.Create('DButton')
			sellPropertyButton:SetParent(actionPanel)
			sellPropertyButton:SetSize(130, 25)
			sellPropertyButton:SetPos(5, 35)
			sellPropertyButton:SetText('Sell Property')
			sellPropertyButton.DoClick = function() RunConsoleCommand("fan_sell", "property") RememberCursorPosition( ) MeteorMenu:Close() end

			claimPropButton = vgui.Create('DButton')
			claimPropButton:SetParent(actionPanel)
			claimPropButton:SetSize(130, 25)
			claimPropButton:SetPos(5, 65)
			claimPropButton:SetText('Claim Un-Owned Prop')
			claimPropButton.DoClick = function() RememberCursorPosition( ) MeteorMenu:Close() RunConsoleCommand("claim_prop") end
			
			unClaimPropButton = vgui.Create('DButton')
			unClaimPropButton:SetParent(actionPanel)
			unClaimPropButton:SetSize(130, 25)
			unClaimPropButton:SetPos(5, 95)
			unClaimPropButton:SetText('Un-own Prop')
			unClaimPropButton.DoClick = function() RememberCursorPosition( ) MeteorMenu:Close() RunConsoleCommand("unclaim_prop") end
			
			sellPropButton = vgui.Create('DButton')
			sellPropButton:SetParent(actionPanel)
			sellPropButton:SetSize(130, 25)
			sellPropButton:SetPos(5, 125)
			sellPropButton:SetText('Sell Prop')
			sellPropButton.DoClick = function() RememberCursorPosition( ) MeteorMenu:Close() RunConsoleCommand("fan_sell", "prop") end
			
			healAmmoButton = vgui.Create('DButton')
			healAmmoButton:SetParent(actionPanel)
			healAmmoButton:SetSize(130, 25)
			healAmmoButton:SetPos(5, 155)
			healAmmoButton:SetToolTip("200 Heal Ammo for 300 Credits")
			healAmmoButton:SetText('Buy Heal Ammo')
			healAmmoButton.DoClick = function() RememberCursorPosition( ) MeteorMenu:Close() RunConsoleCommand("fan_buy", "ha") end
			
			sellAllButton = vgui.Create('DButton')
			sellAllButton:SetParent(actionPanel)
			sellAllButton:SetSize(130, 25)
			sellAllButton:SetPos(5, 185)
			sellAllButton:SetToolTip("Careful! This sells *ALL* your props")
			sellAllButton:SetText('Sell All Props')
			sellAllButton.DoClick = function() RememberCursorPosition( ) MeteorMenu:Close() RunConsoleCommand("fan_sell", "allprops") end
			
			transCreditsButton = vgui.Create('DButton')
			transCreditsButton:SetParent(actionPanel)
			transCreditsButton:SetSize(130, 25)
			transCreditsButton:SetPos(5, 215)
			transCreditsButton:SetToolTip("Transfer Credits to Aimed at player")
			transCreditsButton:SetText('Transfer Credits')
			transCreditsButton.DoClick = function() RememberCursorPosition( ) MeteorMenu:Close() RunConsoleCommand("fan_cred", "trans", transCreditsSlider:GetValue() ) end
			
			transCreditsSlider = vgui.Create('DNumSlider')
			transCreditsSlider:SetParent(actionPanel)
			transCreditsSlider:SetPos(5,260)
			transCreditsSlider:SetSize(130,35)
			transCreditsSlider:SetMin(1)
			transCreditsSlider:SetMax(credits)
			transCreditsSlider:SetDecimals(0)
			transCreditsSlider:SetText('Trans. Amt.')

end
[/lua]

Well hope that helps, if you have any questions about what I did where post and i’ll try to answer them.

:psyboom:

and your point? it’s run once and it’s easy to read. Why does everyone assume their way is better, if it runs it counts.