local PANEL = {}
AccessorFunc( PANEL,
"ItemWidth",
"ItemWidth", FORCE_NUMBER
)
AccessorFunc( PANEL,
"ItemHeight",
"ItemHeight", FORCE_NUMBER
)
AccessorFunc( PANEL,
"m_bSizeToContent",
"AutoHeight", FORCE_BOOL
)
/*---------------------------------------------------------
Name: This function is used as the paint function for
selected buttons.
---------------------------------------------------------*/
local function HighlightedButtonPaint( self )
for i=2, 3 do
end
end
/*---------------------------------------------------------
Name: Init
---------------------------------------------------------*/
function PANEL:Init()
// A panellist is a panel that you shove other panels
// into and it makes a nice organised frame.
self.List:EnableHorizontal( true )
self.List:EnableVerticalScrollbar()
self.List:SetSpacing( 0 )
self.List:SetPadding( 5 )
self.Controls = {}
self.Height = 2
self:SetItemWidth( 128 )
self:SetItemHeight( 128 )
end
/*---------------------------------------------------------
Name: SetAutoHeight
---------------------------------------------------------*/
function PANEL:SetAutoHeight( bAutoHeight )
self.m_bSizeToContent = bAutoHeight
self.List:SetAutoSize( bAutoHeight )
end
/*---------------------------------------------------------
Name: AddMaterial
---------------------------------------------------------*/
function PANEL:AddMaterial( label, value )
// Creeate a spawnicon and set the model
Mat:SetOnViewMaterial( value, "models/wireframe" )
Mat.AutoSize = false
Mat.Value = value
Mat:
SetSize( self.ItemWidth, self.ItemHeight
)
// Run a console command when the Icon is clicked
Mat.DoClick = function ( button )
end
// Add the Icon us
self.List:AddItem( Mat )
end
/*---------------------------------------------------------
Name: SetItemSize
---------------------------------------------------------*/
function PANEL:SetItemSize( pnl )
local w = self.ItemWidth
if ( w
< 1 ) then w
= ( self:
GetWide() - self.List:GetPadding
()*2 ) * w
end
local h = self.ItemHeight
if ( h
< 1 ) then h
= ( self:
GetWide() - self.List:GetPadding
()*2 ) * h
end
end
/*---------------------------------------------------------
Name: AddMaterialEx
---------------------------------------------------------*/
function PANEL:AddMaterialEx( label, material, value, convars )
// Creeate a spawnicon and set the model
Mat:SetImage( material )
Mat.AutoSize = false
Mat.Value = value
Mat.ConVars = convars
self:SetItemSize( Mat )
// Run a console command when the Icon is clicked
Mat.DoClick = function ( button )
end
// Add the Icon us
self.List:AddItem( Mat )
end
/*---------------------------------------------------------
Name: ControlValues
---------------------------------------------------------*/
function PANEL:ControlValues( kv )
self.BaseClass.ControlValues( self, kv )
self.Height = kv.height or 2
// Load the list of models from our keyvalues file
if (kv.options) then
for k, v
in pairs( kv.options
) do
self:AddMaterial( k, v )
end
end
self.ItemWidth = kv.itemwidth or 32
self.ItemHeight = kv.itemheight or 32
for k, v
in pairs( self.Controls
) do
v:
SetSize( self.ItemWidth, self.ItemHeight
)
end
end
/*---------------------------------------------------------
Name: PerformLayout
---------------------------------------------------------*/
function PANEL:PerformLayout()
for k, v
in pairs( self.List:GetItems
() ) do
self:SetItemSize( v )
end
if ( self.m_bSizeToContent ) then
return end
local h = self.ItemHeight
if ( h
< 1 ) then h
= ( self:
GetWide() - self.List:GetPadding
()*2 ) * h
end
local Height = (h * self.Height) + (self.List:GetPadding() * 2) + 1
end
/*---------------------------------------------------------
Name: FindAndSelectMaterial
---------------------------------------------------------*/
function PANEL:FindAndSelectMaterial( Value )
self.CurrentValue = Value
for k, Mat
in pairs( self.Controls
) do
if ( Mat.Value == Value ) then
// Remove the old overlay
if ( self.SelectedMaterial ) then
self.SelectedMaterial.PaintOver = nil
end
// Add the overlay to this button
Mat.PaintOver = HighlightedButtonPaint;
self.SelectedMaterial = Mat
end
end
end
/*---------------------------------------------------------
Name: TestForChanges
---------------------------------------------------------*/
function PANEL:TestForChanges()
local cvar = self:ConVar()
if (!cvar) then return end
if ( Value == self.CurrentValue ) then return end
self:FindAndSelectMaterial( Value )
end