323 lines
9.5 KiB
Lua
323 lines
9.5 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: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) )
|
|
end)
|
|
return
|
|
end
|
|
|
|
local function dospawn( self )
|
|
net.Start( "Benny_DebugMenuSpawn" )
|
|
net.WriteString( self.iName )
|
|
net.SendToServer()
|
|
DebugMenu:Remove()
|
|
return
|
|
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 function OpenDebugMenu()
|
|
if IsValid(DebugMenu) then DebugMenu:Remove() end
|
|
DebugMenu = vgui.Create("DFrame")
|
|
DebugMenu:SetSize( 600, 500 )
|
|
DebugMenu:Center()
|
|
DebugMenu:MakePopup()
|
|
DebugMenu:SetKeyboardInputEnabled( false )
|
|
DebugMenu:SetSizable(true)
|
|
|
|
local splitter = DebugMenu:Add("DHorizontalDivider")
|
|
splitter:Dock( FILL )
|
|
splitter:SetLeftWidth(200)
|
|
|
|
|
|
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( 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 -- 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
|
|
|
|
local categories = {}
|
|
|
|
for iname, idata in SortedPairs( ITEMS ) do
|
|
if idata.Category == "base" then continue end
|
|
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")
|
|
button:Dock( TOP )
|
|
button:DockMargin( 0, 0, 0, 0 )
|
|
button:SetText( l8( idata.PrintName ) )
|
|
button:SetTall(32)
|
|
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
|
|
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
|
|
|
|
local 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", "PlayerButtonDown_DebugMenu", function( ply, button )
|
|
if button == KEY_F1 then
|
|
OpenDebugMenu()
|
|
elseif button == KEY_F2 then
|
|
OpenMyTeamMenu()
|
|
end
|
|
end)
|
|
|
|
hook.Add("PlayerButtonUp", "PlayerButtonUp_DebugMenu", function( ply, button )
|
|
if button == KEY_F1 then
|
|
--if IsValid(DebugMenu) then DebugMenu:Remove() end
|
|
end
|
|
end) |