derma.DefineControl( "EPlayerList", "Stylish player list", PANEL, "DComboBox" )
PlayerList = vgui.Create( "EPlayerList", pnl )
PlayerList:SetPos( 0, 0 )
PlayerList:SetSize( self.Width, pnl:GetParent():GetTall() - 58 )
function PANEL:Populate()
local selectedPlayers = {}
if ( #PlayerList:GetSelectedItems() > 0 ) then
for _, item in ipairs( PlayerList:GetSelectedItems() ) do
if ( IsValid( item.Player ) ) then table.insert( selectedPlayers, item.Player ) end
end
end
PlayerList:Clear()
local players = {}
for _, pl in ipairs( player.GetAll() ) do table.insert( players, { Name = pl:Nick(), Ply = pl } ) end
table.SortByMember( players, "Name", function( a, b ) return a > b end )
for _, pl in ipairs( players ) do
local item = PlayerList:AddPlayer( pl.Ply )
item.DoClick= function( mc )
if ( item.LastClick and os.clock() < item.LastClick + 0.3 and item.LastX == gui.MouseX() and item.LastY == gui.MouseY() ) then
item:MoveTo( -PlayerList.Parent.Width, 0, 0.1 )
item.Parent.PluginList:MoveTo( 0, 0, 0.1 )
item.Parent.ButPlugins:SetButtonText( "Players" )
end
item.LastClick = os.clock()
item.LastX, item.LastY = gui.MousePos()
end
if ( table.HasValue( selectedPlayers, pl.Ply ) ) then
PlayerList:SelectItem( item )
end
end
if ( #PlayerList:GetSelectedItems() == 0 ) then
PlayerList:SelectFirstItem()
end
end