include( 'controlpanel.lua' ) include( 'ToolMenuButton.lua' ) g_ActiveControlPanel = nil g_ToolPanel = nil local PANEL = {} /*--------------------------------------------------------- Name: Paint ---------------------------------------------------------*/ function PANEL:Init() self.List = vgui.Create( "DPanelList", self ) self.List:EnableVerticalScrollbar( true ) self.List:Dock( LEFT ) self.List:SetWidth( 150 ) self.List:SetSpacing( 2 ) self.List:SetPadding( 2 ) self.Content = vgui.Create( "DPanelList", self ) self.Content:EnableVerticalScrollbar( true ) self.Content:Dock( FILL ) self.Content:SetSpacing( 3 ) self.Content:SetPadding( 3 ) self.Content:DockMargin( 3, 0, 0, 0 ) self:SetWide( 460 ) end /*--------------------------------------------------------- Name: LoadToolsFromTable ---------------------------------------------------------*/ function PANEL:LoadToolsFromTable( inTable ) local inTable = table.Copy( inTable ) for k, v in pairs( inTable ) do if ( type( v ) == "table" ) then // Remove these from the table so we can // send the rest of the table to the other // function local Name = v.ItemName local Label = v.Text v.ItemName = nil v.Text = nil self:AddCategory( Name, Label, v ) end end end /*--------------------------------------------------------- Name: AddCategory ---------------------------------------------------------*/ function PANEL:AddCategory( Name, Label, tItems ) local Category = vgui.Create( "DCollapsibleCategory", self ) self.List:AddItem( Category ) Category:SetLabel( Label ) Category:SetCookieName( "ToolMenu."..tostring(Name) ) local CategoryContent = vgui.Create( "DPanelList" ) CategoryContent:SetAutoSize( true ) CategoryContent:SetDrawBackground( false ) CategoryContent:SetSpacing( 0 ) CategoryContent:SetPadding( 0 ) Category:SetContents( CategoryContent ) local bAlt = true for k, v in pairs( tItems ) do local item = vgui.Create( "ToolMenuButton", self ) item:SetText( v.Text ) item.OnSelect = function( button ) self:EnableControlPanel( button ) end concommand.Add( Format( "tool_%s", v.ItemName ), function() item:OnSelect() end ) if ( v.SwitchConVar ) then item:AddCheckBox( v.SwitchConVar ) end item.ControlPanelBuildFunction = v.CPanelFunction item.Command = v.Command item.Name = v.ItemName item.Controls = v.Controls item.Text = v.Text item:SetAlt( bAlt ) bAlt = !bAlt CategoryContent:AddItem( item ) end self:InvalidateLayout() end /*--------------------------------------------------------- Name: EnableControlPanel ---------------------------------------------------------*/ function PANEL:EnableControlPanel( button ) if ( self.LastSelected ) then self.LastSelected:SetSelected( false ) end button:SetSelected( true ) self.LastSelected = button local cp = controlpanel.Get( button.Name ) if ( !cp:GetInitialized() ) then cp:FillViaTable( button ) end self.Content:Clear() self.Content:AddItem( cp ) self.Content:Rebuild() g_ActiveControlPanel = cp if ( button.Command ) then LocalPlayer():ConCommand( button.Command ) end end vgui.Register( "ToolPanel", PANEL, "Panel" )