Skip to content

Commit

Permalink
Given DAdjustableModelPanel an example
Browse files Browse the repository at this point in the history
It had one inherited from DModelPanel, and it was wrong displaying just
nothing initially.

Also improved the example for DModelPanel to not show an error, and gave
the model a skin as an example.
  • Loading branch information
robotboy655 committed May 13, 2016
1 parent 893d84e commit 4cd4f3b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
21 changes: 17 additions & 4 deletions garrysmod/lua/vgui/dadjustablemodelpanel.lua
Expand Up @@ -58,13 +58,13 @@ function PANEL:FirstPersonControls()
y = y * 0.5 * scale

if ( self.MouseKey == MOUSE_LEFT ) then

if ( input.IsShiftDown() ) then y = 0 end

self.aLookAngle = self.aLookAngle + Angle( y * 4, x * 4, 0 )

self.vCamPos = self.Entity:OBBCenter() - self.aLookAngle:Forward() * self.vCamPos:Length()

return
end

Expand Down Expand Up @@ -102,4 +102,17 @@ function PANEL:OnMouseReleased( mousecode )

end

function PANEL:GenerateExample( ClassName, PropertySheet, Width, Height )

local ctrl = vgui.Create( ClassName )
ctrl:SetSize( 300, 300 )
ctrl:SetModel( "models/props_junk/PlasticCrate01a.mdl" )
ctrl:GetEntity():SetSkin( 2 )
ctrl:SetLookAng( Angle( 45, 0, 0 ) )
ctrl:SetCamPos( Vector( -20, 0, 20 ) )

PropertySheet:AddSheet( ClassName, ctrl, nil, true, true )

end

derma.DefineControl( "DAdjustableModelPanel", "A panel containing a model", PANEL, "DModelPanel" )
19 changes: 10 additions & 9 deletions garrysmod/lua/vgui/dmodelpanel.lua
Expand Up @@ -50,7 +50,7 @@ end
-----------------------------------------------------------]]
function PANEL:SetModel( strModelName )
-- Note - there's no real need to delete the old
-- Note - there's no real need to delete the old
-- entity, it will get garbage collected, but this is nicer.
if ( IsValid( self.Entity ) ) then
self.Entity:Remove()
Expand Down Expand Up @@ -90,7 +90,7 @@ end
Name: DrawModel
-----------------------------------------------------------]]
function PANEL:DrawModel()
local curparent = self
local rightx = self:GetWide()
local leftx = 0
Expand All @@ -109,7 +109,7 @@ function PANEL:DrawModel()
render.SetScissorRect( leftx, topy, rightx, bottomy, true )
local ret = self:PreDrawModel( self.Entity )
if ( ret != false ) then
if ( ret != false ) then
self.Entity:DrawModel()
self:PostDrawModel( self.Entity )
end
Expand All @@ -129,7 +129,7 @@ end
Name: PostDrawModel
-----------------------------------------------------------]]
function PANEL:PostDrawModel( ent )
end
--[[---------------------------------------------------------
Expand All @@ -145,16 +145,16 @@ function PANEL:Paint( w, h )
local ang = self.aLookAngle
if ( !ang ) then
ang = (self.vLookatPos-self.vCamPos):Angle()
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( self.Entity:GetPos() )
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) )
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 ) )
for i=0, 6 do
local col = self.DirectionalLight[ i ]
Expand Down Expand Up @@ -222,7 +222,8 @@ function PANEL:GenerateExample( ClassName, PropertySheet, Width, Height )
local ctrl = vgui.Create( ClassName )
ctrl:SetSize( 300, 300 )
ctrl:SetModel( "models/error.mdl" )
ctrl:SetModel( "models/props_junk/PlasticCrate01a.mdl" )
ctrl:GetEntity():SetSkin( 2 )
PropertySheet:AddSheet( ClassName, ctrl, nil, true, true )
Expand Down

0 comments on commit 4cd4f3b

Please sign in to comment.