• Spawnmenu -> Toolmenu
    7 replies, posted
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]
[QUOTE=-TB-;28706225]You could try overriding the register, [LUA] local PANEL = {} function PANEL:Init() end function PANEL:LoadTools() end function PANEL:AddToolPanel( Name, ToolTable ) end function PANEL:Paint() end function PANEL:PerformLayout() end vgui.Register( "ToolMenu", PANEL, "DPropertySheet" ) [/LUA][/QUOTE] 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?
[QUOTE=scoie;28706323] *edit, The spawnmenu no longer opens close to what i wanted, but may need to be more specific to the tools panel..[/QUOTE] 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] .. " \n " .. "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] .. "\n" .. "Radius: " .. tostring(v[4]) .. "\n" .. "Energy: " .. tostring(v[5]) .. "\n" .. "Cost: " .. tostring(v[6]) .. "\n" else toolT
[QUOTE=Fantym420;28709186] [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] [/QUOTE] :psyboom:
[QUOTE=King Fagless;28709972]:psyboom:[/QUOTE] 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.
Sorry, you need to Log In to post a reply to this thread.