Benny/gamemodes/benny/gamemode/debugmenu.lua

260 lines
7.6 KiB
Lua
Raw Normal View History

2024-03-08 20:10:47 -05:00
---------------------
-- 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:Spawn()
local TRACE = ply:GetEyeTrace()
local thespawnpos = TRACE.HitPos
thespawnpos:Add( TRACE.HitNormal * 16 )
local WORLDAA, WORLDBB = ent:GetCollisionBounds()
local tr = util.TraceHull( {
start = thespawnpos,
endpos = thespawnpos - (vector_up*32),
mins = WORLDAA,
maxs = WORLDBB,
collisiongroup = COLLISION_GROUP_WEAPON,
})
thespawnpos:Set( tr.HitPos )
ent:SetPos( thespawnpos )
--[[local WORLDAA, WORLDBB = ent:GetCollisionBounds()
local WORLDC = ent:WorldSpaceCenter()
local TRACE = ply:GetEyeTrace()
local thespawnpos = TRACE.HitPos
thespawnpos:Add( WORLDC/2 )
thespawnpos:Add( ((WORLDBB * TRACE.HitNormal) - (WORLDAA * TRACE.HitNormal)) )
ent:SetPos( thespawnpos )]]
debugoverlay.Box( thespawnpos, WORLDAA, WORLDBB, 4, Color( 255, 255, 255, 0) )
2024-03-08 20:10:47 -05:00
end)
return
end
local function dospawn( self )
net.Start( "Benny_DebugMenuSpawn" )
net.WriteString( self.iName )
net.SendToServer()
2024-04-06 09:30:09 -04:00
DebugMenu:Remove()
return
2024-03-08 20:10:47 -05:00
end
local function OpenDebugMenu()
if IsValid(DebugMenu) then DebugMenu:Remove() end
DebugMenu = vgui.Create("DFrame")
DebugMenu:SetSize( 600, 500 )
2024-03-08 20:10:47 -05:00
DebugMenu:Center()
DebugMenu:MakePopup()
2024-03-25 00:48:36 -04:00
DebugMenu:SetKeyboardInputEnabled( false )
DebugMenu:SetSizable(true)
local splitter = DebugMenu:Add("DHorizontalDivider")
splitter:Dock( FILL )
splitter:SetLeftWidth(200)
2024-03-08 20:10:47 -05:00
2024-04-06 09:30:09 -04:00
local opt = DebugMenu:Add("DScrollPanel")
--opt:Dock( FILL )
splitter:SetLeft( opt )
local vsplit = DebugMenu:Add("DVerticalDivider")
splitter:SetRight( vsplit )
vsplit:SetTopHeight( 500/2 )
local texter = DebugMenu:Add("DTextEntry")
texter:SetFont( "HUD_24" )
texter:SetMultiline( true )
vsplit:SetBottom( texter )
local matColor = Material( "models/debug/debugwhite" )
local modeller = DebugMenu:Add("DModelPanel")
do
vsplit:SetTop( modeller )
modeller:SetModel( "models/weapons/w_pistol.mdl" )
modeller:SetFOV( 5 )
local original = Vector( 0, 50, 0 )
modeller:SetCamPos( original )
modeller:SetLookAt( vector_origin )
function modeller:LayoutEntity( ent )
ent:SetPos( Vector( 0, 0, 0 ) )
ent:SetAngles( Angle( 0, 0 * RealTime() * 10 % 360, 0 ) )
return
end
modeller:SetAmbientLight( HSLToColor( 0, 0, 1.00 ) )
modeller:SetDirectionalLight(BOX_TOP, HSLToColor( 0, 0, 1.00 ) )
modeller:SetDirectionalLight(BOX_FRONT, HSLToColor( 0, 0, 1.00 ) )
modeller:SetDirectionalLight(BOX_RIGHT, HSLToColor( 0, 0, 1.00 ) )
function modeller:Update( mdl )
if self.Entity:GetModel() == mdl then return end
self.Entity:SetModel( mdl )
local worked = self.Entity:PhysicsInit( SOLID_VPHYSICS )
if worked then
-- Factors the USP's bodygroup suppressor for some reason. Great
local mins, maxs = self.Entity:GetCollisionBounds()
local wsc = Vector()
wsc:Add( mins )
wsc:Add( maxs )
wsc:Div( 2 )
self:SetLookAt( wsc )
self:SetCamPos( wsc+original )
-- local HFOV = 45-5
-- local hfovRad = HFOV * math.pi / 180
-- local vfovRad = 2*math.atan(math.tan(hfovRad/2)*(self:GetTall()/self:GetWide()))
-- local VFOV = math.ceil(vfovRad* 180 / math.pi)
local directionAngCos = math.cos( math.rad(5/2) )
-- scale test
if true then for i=1, 50 do
local S1, S2 = false, false
local aimVector = (self:GetLookAt() - self:GetCamPos()):GetNormalized()
do -- test 1, mins
local entVector = mins - self:GetCamPos()
local angCos = aimVector:Dot(entVector) / entVector:Length()
S1 = (angCos >= directionAngCos)
end
do -- test 2: maxs
local entVector = maxs - self:GetCamPos()
local angCos = aimVector:Dot(entVector) / entVector:Length()
S2 = (angCos >= directionAngCos)
end
if S1 and S2 then
self.indicate = "took " .. i
self.vCamPos:Add( Vector( 0, 20, 0 ) )
--self.vLookatPos:Add( Vector( 0, 0, 0 ) )
--self.vLookatPos:Set( (mins+maxs)/2 )
break
else
self.indicate = "failed"
self.vCamPos:Sub( (aimVector*20) )
end
end end
else
self.indicate = false
self:SetLookAt( vector_origin )
self:SetCamPos( original )
end
self.Failed = !worked
end
local material = Material( "sprites/splodesprite" )
function modeller:Paint1( w, h )
if ( !IsValid( self.Entity ) ) then return end
local x, y = self:LocalToScreen( 0, 0 )
self:LayoutEntity( self.Entity )
local ang = self.aLookAngle
if ( !ang ) then
ang = ( self.vLookatPos - self.vCamPos ):Angle()
end
cam.Start3D( self.vCamPos, ang, self.fFOV, x, y, w, h, 5, self.FarZ )
render.SuppressEngineLighting( true )
render.SetLightingOrigin( vector_origin )
render.ResetModelLighting( self.colAmbientLight.r / 255, self.colAmbientLight.g / 255, self.colAmbientLight.b / 255 )
render.SetColorModulation( self.colColor.r / 255, self.colColor.g / 255, self.colColor.b / 255 )
render.SetBlend( ( self:GetAlpha() / 255 ) * ( self.colColor.a / 255 ) ) -- * surface.GetAlphaMultiplier()
for i = 0, 6 do
local col = self.DirectionalLight[ i ]
if ( col ) then
render.SetModelLighting( i, col.r / 255, col.g / 255, col.b / 255 )
end
end
render.MaterialOverride(matColor)
self:DrawModel()
render.MaterialOverride()
local mins, maxs = self.Entity:GetCollisionBounds()
-- render.SetColorMaterial()
-- render.DrawSphere( mins, .5, 30, 30, Color( 255, 0, 0 ) )
-- render.DrawSphere( maxs, .5, 30, 30, Color( 0, 0, 255 ) )
-- render.DrawWireframeBox( vector_origin, angle_zero, mins, maxs, Color( 0, 0, 0, 127 ))
render.SuppressEngineLighting( false )
cam.End3D()
self.LastPaint = RealTime()
end
function modeller:Paint( w, h )
surface.SetDrawColor( color_black )
surface.DrawRect( 0, 0, w, h )
self:Paint1( w, h )
if self.Failed then
draw.SimpleText("Failed physinit, not cached?", "HUD_36", w/2, h/2, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end
-- if self.indicate then
-- draw.SimpleText(self.indicate, "HUD_36", w/2, h/2 + 48, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
-- end
end
end
2024-03-08 20:10:47 -05:00
2024-08-30 18:30:03 -04:00
local categories = {}
2024-03-08 20:10:47 -05:00
for iname, idata in SortedPairs( ITEMS ) do
if idata.Category == "base" then continue end
2024-08-30 18:30:03 -04:00
if !categories[idata.Category] then
local cate = opt:Add("DCollapsibleCategory")
cate:Dock(TOP)
cate:SetLabel(idata.Category)
local plist = vgui.Create("DPanelList")
cate:SetContents(plist)
categories[idata.Category] = plist
end
local plist = categories[idata.Category]
local button = plist:Add("DButton")
2024-03-08 20:10:47 -05:00
button:Dock( TOP )
2024-08-30 18:30:03 -04:00
button:DockMargin( 0, 0, 0, 0 )
2024-03-08 20:10:47 -05:00
button:SetText( l8( idata.PrintName ) )
button:SetTall(32)
2024-03-08 20:10:47 -05:00
button.iName = iname
button.iData = idata
button.DoClick = dospawn
function button:Think()
if self:IsHovered() then
texter:SetText( l8(idata.Description) .. "\n\nClipsize: " .. (idata.ClipSize or "?") )
modeller:Update( idata.Model )
end
end
2024-03-08 20:10:47 -05:00
end
2024-03-25 00:48:36 -04:00
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
2024-03-08 20:10:47 -05:00
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)