Benny/gamemodes/benny/gamemode/debugmenu.lua

68 lines
1.6 KiB
Lua

---------------------
-- Your Name is Benny
---------------------
if SERVER then
util.AddNetworkString( "Benny_DebugMenuSpawn" )
net.Receive( "Benny_DebugMenuSpawn", function( len, ply )
if !ply:IsAdmin() then return end
local ent = ents.Create( "b-item_" .. net.ReadString() )
ent:SetPos( ply:GetEyeTrace().HitPos )
ent:Spawn()
end)
return
end
local function dospawn( self )
net.Start( "Benny_DebugMenuSpawn" )
net.WriteString( self.iName )
net.SendToServer()
end
local function OpenDebugMenu()
if IsValid(DebugMenu) then DebugMenu:Remove() end
DebugMenu = vgui.Create("DFrame")
DebugMenu:SetSize( 400, 300 )
DebugMenu:Center()
DebugMenu:MakePopup()
DebugMenu:SetKeyboardInputEnabled( false )
local opt = DebugMenu:Add("DCollapsibleCategory")
opt:Dock( TOP )
local plist = DebugMenu:Add("DScrollPanel")
opt:SetContents( plist )
for iname, idata in SortedPairs( ITEMS ) do
local button = plist:Add("DButton")
button:Dock( TOP )
button:DockMargin( 4, 4, 4, 0 )
button:SetText( l8( idata.PrintName ) )
button.iName = iname
button.iData = idata
button.DoClick = dospawn
end
local button = DebugMenu:Add("DButton")
button:Dock( BOTTOM )
button:DockMargin( 4, 4, 4, 4 )
button:SetText( "CLOSE" )
button:SetTall( 36 )
button.DoClick = function( self )
DebugMenu:Remove()
end
end
hook.Add("PlayerButtonDown", "PlayerButtonDown_DebugMenu", function( ply, button )
if button == KEY_F1 then
OpenDebugMenu()
end
end)
hook.Add("PlayerButtonUp", "PlayerButtonUp_DebugMenu", function( ply, button )
if button == KEY_F1 then
--if IsValid(DebugMenu) then DebugMenu:Remove() end
end
end)