Benny/gamemodes/benny/gamemode/debugmenu.lua

373 lines
11 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 doteamselect( self )
LocalPlayer():ConCommand( "b-cheat_setteam " .. self.iIndex )
self:GetParent():Remove()
end
local function painterly( self, w, h )
surface.SetDrawColor( self.iFaction.COLOR_DARK )
surface.DrawRect( 0, 0, w, h )
surface.SetDrawColor( self.iFaction.COLOR_MAIN )
surface.DrawOutlinedRect( 1, 1, w-2, h-2, 1 )
draw.SimpleText( l8(self.iData.name), "HUD_24", w/2, 4, self.iFaction.COLOR_MAIN, TEXT_ALIGN_CENTER )
return true
end
local preferredcategoryorder = { "pistol", "smg", "assaultrifle", "machinegun", "shotgun", "utility" }
2024-03-08 20:10:47 -05:00
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 )
modeller:SetCamPos( original )
modeller:SetLookAt( vector_origin )
modeller:SetPos( vector_origin )
modeller.Entity:SetAngles( angle_zero )
modeller.Standard = Vector( 0, 100, 0 )
modeller.Finalized = Vector()
function modeller:LayoutEntity( ent )
local the = Vector(modeller.Finalized)
the:Rotate( Angle( 0, (360/4) * RealTime() % 360, 0 ) )
modeller:SetCamPos( the )
-- ent:SetPos( Vector( 0, 0, 0 ) )
--ent:SetAngles( Angle( 0, 10 * RealTime() * 10 % 360, 0 ) )
return
end
modeller:SetAmbientLight( HSLToColor( 0, 0, 0.00 ) )
modeller:SetDirectionalLight(BOX_TOP, HSLToColor( 0, 0, 0.50 ) )
modeller:SetDirectionalLight(BOX_BOTTOM, HSLToColor( 0, 0, 0.50 ) )
modeller:SetDirectionalLight(BOX_FRONT, HSLToColor( 0, 0, 0.50 ) )
modeller:SetDirectionalLight(BOX_BACK, HSLToColor( 0, 0, 0.50 ) )
modeller:SetDirectionalLight(BOX_LEFT, HSLToColor( 0, 0, 1.00 ) )
modeller:SetDirectionalLight(BOX_RIGHT, HSLToColor( 0, 0, 1.00 ) )
function modeller:Update( idata )
if self.Entity:GetModel() == idata.Model then return end
self.Entity:SetModel( idata.Model )
for i=0, self.Entity:GetNumBodyGroups()-1 do
self.Entity:SetBodygroup( i, 0 )
end
for k, v in ipairs(idata.DefaultBodygroups) do
if v then
self.Entity:SetBodygroup( k-1, v )
end
end
local worked = self.Entity:PhysicsInit( SOLID_VPHYSICS )
if worked then
-- Factors the USP's bodygroup suppressor for some reason. Great -- Not anymore, changed it to Physics Object AABB
local mins, maxs = self.Entity:GetPhysicsObject():GetAABB()
local wsc = Vector()
wsc:Add( mins )
wsc:Add( maxs )
wsc:Div( 2 )
self.Entity:SetPos( -wsc )
self:SetLookAt( vector_origin )
modeller.Finalized:Set(modeller.Standard)
--self:SetCamPos( modeller.Standard )
-- 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() - modeller.Finalized):GetNormalized()
do -- test 1, mins
local entVector = mins - modeller.Finalized
local angCos = aimVector:Dot(entVector) / entVector:Length()
S1 = (angCos >= directionAngCos)
end
do -- test 2: maxs
local entVector = maxs - modeller.Finalized
local angCos = aimVector:Dot(entVector) / entVector:Length()
S2 = (angCos >= directionAngCos)
end
if S1 and S2 then
self.indicate = i
--modeller.Finalized:Add( Vector( 0, 20, 0 ) )
--self.vLookatPos:Add( Vector( 0, 0, 0 ) )
--self.vLookatPos:Set( (mins+maxs)/2 )
break
else
self.indicate = "failed"
modeller.Finalized: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()
if false and self.Entity:GetPhysicsObject():IsValid() then
local pos = self.Entity:GetPos()
local mins, maxs = self.Entity:GetPhysicsObject():GetAABB()
render.SetColorMaterial()
render.DrawSphere( pos+mins, .5, 30, 30, Color( 255, 0, 0 ) )
render.DrawSphere( pos+maxs, .5, 30, 30, Color( 0, 0, 255 ) )
render.DrawWireframeBox( pos, angle_zero, mins, maxs, Color( 0, 0, 0, 127 ))
end
render.SuppressEngineLighting( false )
cam.End3D()
self.LastPaint = RealTime()
end
function modeller:Paint( w, h )
surface.SetDrawColor( HSLToColor( 0.9, 0.2, 0 ) )
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_16", 4, 4, color_white)
end
end
end
2024-03-08 20:10:47 -05:00
2024-08-30 18:30:03 -04:00
local categories = {}
-- preferred order
for index, category in SortedPairs( preferredcategoryorder ) do
if category == "base" then continue end
if !categories[category] then
local cate = opt:Add("DCollapsibleCategory")
cate:Dock(TOP)
cate:SetLabel( l8( "#ItemCategory." .. category .. ".Name" ) )
local plist = vgui.Create("DPanelList")
cate:SetContents(plist)
categories[category] = plist
end
end
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( l8( "#ItemCategory." .. idata.Category .. ".Name" ) )
2024-08-30 18:30:03 -04:00
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 )
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
2024-09-21 16:53:57 -04:00
function OpenMyTeamMenu()
if IsValid(DebugMenu) then DebugMenu:Remove() end
DebugMenu = vgui.Create("DFrame")
DebugMenu:SetSize( 200, 300 )
DebugMenu:MakePopup()
DebugMenu:SetKeyboardInputEnabled( false )
DebugMenu:SetSizable(false)
for index, data in ipairs( TEAMS ) do
local faction = FACTIONS[ data.factionid ]
if !faction then continue end
local button = DebugMenu:Add("DButton")
button:Dock( TOP )
button:DockMargin( 0, 0, 0, 5 )
button:SetText( l8( data.name ) )
button.iIndex = index
button.iData = data
button.iFaction = faction
button:SetTall(28)
button.DoClick = doteamselect
button.Paint = painterly
end
DebugMenu:InvalidateLayout( true )
DebugMenu:SizeToChildren( false, true )
DebugMenu:Center()
end
hook.Add("PlayerButtonDown", "Benny_PlayerButtonDown_DebugMenu", function( ply, button )
if CLIENT and IsFirstTimePredicted() then
if button == KEY_F1 then
OpenDebugMenu()
elseif button == KEY_F2 then
OpenMyTeamMenu()
end
2024-03-08 20:10:47 -05:00
end
end)
local c_id = Color( 255, 200, 200 )
local c_name = Color( 200, 255, 255 )
local c_white = Color( 255, 255, 255 )
local function recursebones( ent, O_id, level )
local gap = ""
for i=1, level do gap = gap .. " " end
for index, id in ipairs( ent:GetChildBones( O_id ) ) do
MsgC( gap, c_id, tostring(id), c_white, " - ", c_name, ent:GetBoneName(id) .. "\n" )
recursebones( ent, id, level+1 )
2024-03-08 20:10:47 -05:00
end
end
function printallbones( ent )
if !ent:IsValid() then print("invalid ent") return end
for id=0, ent:GetBoneCount()-1 do
if ent:GetBoneName(id) == "__INVALIDBONE__" then continue end
if ent:GetBoneParent(id) != -1 then continue end
MsgC( c_id, tostring(id), c_white, " - ", c_name, ent:GetBoneName(id) .. "\n" )
recursebones( ent, id, 1 )
end
end
2024-10-08 20:46:36 -04:00
concommand.Add("b-debug_listbones", function( ply, cmd, args )
printallbones( args[1] and Entity(args[1]) or ply )
2024-03-08 20:10:47 -05:00
end)