Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- SilkBoard: Re-work
- */
- if ( SERVER ) then
- AddCSLuaFile( "cl_silkconfig.lua" )
- AddCSLuaFile()
- return
- end
- // Include the configuration file
- include( "cl_silkconfig.lua" )
- /*
- Fonts
- */
- surface.CreateFont( "SilkBoardFont",
- {
- font = "coolvetica",
- size = 21,
- weight = 100,
- underline = 1
- }
- )
- surface.CreateFont( "SilkTitle",
- {
- font = "coolvetica",
- size = 58,
- weight = 100,
- underline = 1
- }
- )
- // Materials
- local blurMat = Material( "pp/blurscreen" )
- local cornerMat = surface.GetTextureID( "gui/corner8" )
- /*
- Has ULX access?
- */
- local function hasULXAccess( cmd )
- return ( ulx && ULib.ucl.query( LocalPlayer(), "ulx " .. cmd, true ) )
- end
- local SILKBOARD_TAB = {
- SortRows = function( self, name, desc )
- for _, item in pairs( self.player_list.Items ) do
- item:SetColumnmInfo()
- end
- self.player_list:SortByMember( name, desc )
- local items = self.player_list.Items
- --
- self.player_list:Clear()
- --
- for k, v in pairs( items ) do
- self.player_list:AddItem( v )
- end
- end,
- UpdateBoard = function( self )
- local t = player.GetAll()
- for i = 1, #t do
- local ply = t[ i ]
- if ( IsValid( ply ) && self.row[ ply ] == nil ) then
- local pan = vgui.Create( "DPanel" )
- pan.ply = ply
- pan:SetSize( self.player_list:GetWide(), 50 )
- pan.Paint = function( self, w, h )
- if ( !IsValid( self.ply ) ) then
- return
- end
- local col = team.GetColor( self.ply:Team() )
- -- Rounded box
- draw.RoundedBox( 8, 0, 0, w, h, Color( col.r, col.g, col.b, 150 ) )
- end
- pan.m_expireTime = CurTime()
- pan.tab = {}
- pan.SetColumnmInfo = function( self )
- if ( !IsValid( self.ply ) ) then
- return
- end
- self.tab[ "Name" ] = self.ply:Nick()
- for k, v in pairs( SILKBOARD.config.tabs ) do
- self.tab[ v.title ] = v.func( self.ply )
- end
- end
- pan.Think = function( self )
- if ( CurTime() > self.m_expireTime ) then
- if ( !IsValid( self.ply ) ) then
- self:Remove()
- if ( self.player_list != nil && self.player_list.VBar != nil && self.player_list.VBar:IsVisible() ) then
- self.player_list.VBar:SetScroll( self.player_list.VBar:GetScroll() - 50 )
- end
- return
- end
- self.m_expireTime = CurTime() + 1
- end
- end
- local avatar = pan:Add( "AvatarImage" )
- avatar:Dock( LEFT )
- avatar:SetContentAlignment( 4 )
- avatar:SetPlayer( ply, 40 )
- avatar:DockMargin( 5, 5, 5, 5 )
- avatar:SetSize( 40, 40 )
- // Name and rank
- local nameSpace = ( self:GetWide() - 2 ) * 0.2
- local ply_col = {}
- local tab = pan:Add( "DPanel" )
- tab:SetDrawBackground( false )
- tab:Dock( LEFT )
- tab:SetSize( nameSpace, 50 )
- tab:DockMargin( 6, 0, 0, 0 )
- tab:SetContentAlignment( 4 )
- local lab = tab:Add( "DLabel" )
- lab:SetFont( "SilkBoardFont" )
- lab:SetTextColor( color_white )
- lab:Dock( TOP )
- lab:SetHeight( 50 )
- lab:SetContentAlignment( 4 )
- lab:DockMargin( 0, 0, 0, 0 )
- lab:SetText( "" )
- lab.m_expireTime = CurTime()
- lab.Think = function( self_lab )
- if ( CurTime() > self_lab.m_expireTime ) then
- self_lab.m_expireTime = CurTime() + 2
- if ( IsValid( ply ) ) then
- local str
- if ( SILKBOARD.config.showRankUnderName && ply.GetUserGroup ) then
- str = ply:Nick() .. "\n" .. ( SILKBOARD.config.rankNames[ ply:GetUserGroup() ] or ply:GetUserGroup() )
- else
- str = ply:Nick()
- end
- if ( self_lab.m_Nick != str ) then
- self_lab:SetText( str )
- self_lab.m_Nick = str
- if ( SILKBOARD.config.enableTabAutoSort && SILKBOARD.config.tabToAutoSort == "Name" ) then
- self:SortRows( "Name", true )
- end
- end
- end
- end
- end
- for k = 1, #SILKBOARD.config.tabs do
- local v = SILKBOARD.config.tabs[ k ]
- ply_col[ k ] = pan:Add( "DPanel" )
- local width = math.floor( ( self:GetWide() - ( 82 + nameSpace ) ) * v.size )
- local tab = ply_col[ k ]
- tab:SetDrawBackground( false )
- tab:Dock( LEFT )
- tab:SetSize( width, 50 )
- tab:SetContentAlignment( 4 )
- tab.label = tab:Add( "DLabel" )
- tab.label:SetFont( "SilkBoardFont" )
- tab.label:SetTextColor( color_white )
- tab.label:Dock( FILL )
- tab.label:SetHeight( 50 )
- tab.label:SetContentAlignment( 5 )
- tab.label:DockMargin( 0, 0, 0, 0 )
- tab.label:SetText( v.title )
- tab.label.m_expireTime = CurTime()
- tab.label.Think = function( self_lab )
- if ( CurTime() > self_lab.m_expireTime ) then
- self_lab.m_expireTime = CurTime() + 2
- if ( IsValid( ply ) ) then
- local str = v.func( ply )
- if ( str != self_lab.m_text ) then
- self_lab.m_text = str
- self_lab:SetText( str )
- if ( SILKBOARD.config.enableTabAutoSort && SILKBOARD.config.tabToAutoSort == v.title ) then
- self:SortRows( v.title, true )
- end
- end
- end
- end
- end
- end
- local muteB = pan:Add( "DImageButton" )
- if ( ply:IsMuted() ) then
- muteB:SetImage( "icon16/sound_mute.png" )
- muteB.muted = true
- else
- muteB:SetImage( "icon16/sound_low.png" )
- muteB.muted = false
- end
- muteB.DoClick = function()
- if ( ply:IsMuted() ) then
- ply:SetMuted( false )
- muteB:SetImage( "icon16/sound_low.png" )
- muteB.muted = false
- else
- ply:SetMuted( true )
- muteB:SetImage( "icon16/sound_mute.png" )
- muteB.muted = true
- end
- end
- muteB.m_expireTime = CurTime()
- muteB.Think = function( self )
- if ( CurTime() > muteB.m_expireTime ) then
- muteB.m_expireTime = CurTime() + 5
- if ( !IsValid( ply ) ) then return end
- --
- if ( ply:IsMuted() && !self.muted ) then
- self:SetImage( "icon16/sound_mute.png" )
- self.muted = true
- elseif ( !ply:IsMuted() && self.muted ) then
- self:SetImage( "icon16/sound_low.png" )
- self.muted = false
- end
- end
- end
- local clickB = pan:Add( "DImageButton" )
- clickB.DoClick = function()
- local menu = DermaMenu()
- local cat = {}
- for k = 1, #SILKBOARD.config.commands do
- local v = SILKBOARD.config.commands[ k ]
- if ( v.ulxCMD && v.ulxCMD != "" && ( ( not SILKBOARD.config.enableULXOptions ) || not hasULXAccess( v.ulxCMD ) ) ) then continue end
- if ( pan.ply == LocalPlayer() && ( v.ulxCMD == "goto" || v.ulxCMD == "bring" ) ) then continue end
- local opt
- if ( v.category != nil ) then
- if ( cat[ v.category ] == nil ) then
- local menuOpt
- cat[ v.category ], menuOpt = menu:AddSubMenu( v.category )
- local icon = SILKBOARD.config.category_icons[ v.category ]
- if ( icon != nil ) then
- menuOpt:SetIcon( icon )
- end
- end
- opt = cat[ v.category ]:AddOption( v.name )
- if ( v.spacer ) then
- cat[ v.category ]:AddSpacer()
- end
- else
- opt = menu:AddOption( v.name )
- if ( v.spacer ) then
- menu:AddSpacer()
- end
- end
- opt:SetIcon( v.icon )
- if ( v.q ) then
- opt.DoClick = function() Derma_StringRequest( v.name, v.q, "", function( a ) if ( type( tonumber( a ) ) == "number" ) then RunConsoleCommand( "ulx", v.ulxCMD, pan.ply:Nick(), tonumber( a ) ) end end ) end
- else
- opt.DoClick = function() if ( v.func ) then v.func( pan.ply ) else RunConsoleCommand( "ulx", v.ulxCMD, pan.ply:Nick() ) end end
- end
- end
- menu:Open()
- menu.Think = function()
- if ( !SILKBOARD.frame:IsVisible() || !pan.ply:IsValid() ) then
- menu:Remove()
- end
- end
- --
- menu:AddSpacer()
- --
- menu:Open()
- menu.Think = function()
- if ( !self:IsVisible() || !pan.ply:IsValid() ) then
- menu:Remove()
- end
- end
- end
- pan.PerformLayout = function( self_panel )
- clickB:SetSize( self_panel:GetWide() - 84, 50 )
- clickB:SetPos( 50, 0 )
- muteB:SetSize( 16, 16 )
- muteB:SetPos( self_panel:GetWide() - 24, pan:GetTall()/2 - 8 )
- local nameSpace = ( self:GetWide() - 2 ) * 0.2
- tab:SetSize( nameSpace, 50 )
- for k = 1, #SILKBOARD.config.tabs do
- local v = SILKBOARD.config.tabs[ k ]
- local width = math.floor( ( self:GetWide() - ( 82 + nameSpace ) ) * v.size )
- ply_col[ k ]:SetSize( width, 50 )
- end
- end
- self.player_list:AddItem( pan )
- self.row[ pan.ply ] = pan
- end
- end
- end,
- Init = function( self )
- // For the player rows
- self.row = {}
- self.Header = self:Add( "DPanel" )
- self.Header:Dock( TOP )
- self.Header:SetHeight( 100 )
- self.Header:SetDrawBackground( false )
- self.Name = self.Header:Add( "DLabel" )
- self.Name:SetFont( "SilkTitle" )
- self.Name:SetTextColor( SILKBOARD.config.titleColor )
- self.Name:Dock( TOP )
- self.Name:SetHeight( 100 )
- self.Name:SetContentAlignment( 5 )
- self.Name:SetExpensiveShadow( 3, Color( 0, 0, 0, 200 ) )
- self.Name:DockMargin( 0, 0, 0, 0 )
- self.topPanel = self:Add( "DPanel" )
- self.topPanel:Dock( TOP )
- self.topPanel:DockMargin( 0, 2, 0, 0 )
- self.topPanel:SetHeight( 25 )
- self.topPanel:SetDrawBackground( false )
- self.nameButton = vgui.Create( "DImageButton", self.topPanel )
- self.nameButton:Dock( LEFT )
- self.nameButton:SetHeight( 25 )
- self.nameButton:SetContentAlignment( 4 )
- self.nameButton:DockMargin( 58, 0, 0, 0 )
- self.nameButton:SetDrawBackground( false )
- self.nameButton.click = true
- self.nameButton.DoClick = function( b_me )
- self:SortRows( "Name", !b_me.click )
- end
- self.nameLabel = self.nameButton:Add( "DLabel" )
- self.nameLabel:SetFont( "SilkBoardFont" )
- self.nameLabel:SetTextColor( color_white )
- self.nameLabel:Dock( FILL )
- self.nameLabel:SetHeight( 25 )
- self.nameLabel:SetContentAlignment( 4 )
- self.nameLabel:DockMargin( 0, 0, 0, 0 )
- self.button_tabs = {}
- for k, v in pairs( SILKBOARD.config.tabs ) do
- self.button_tabs[ k ] = self.topPanel:Add( "DImageButton" )
- local tab = self.button_tabs[ k ]
- tab:Dock( LEFT )
- tab:SetHeight( 25 )
- tab:SetContentAlignment( 4 )
- tab:SetDrawBackground( false )
- tab.click = true
- tab.DoClick = function( self_button )
- self:SortRows( v.title, !self_button.click )
- end
- tab.label = tab:Add( "DLabel" )
- tab.label:SetFont( "SilkBoardFont" )
- tab.label:SetTextColor( color_white )
- tab.label:Dock( FILL )
- tab.label:SetHeight( 25 )
- tab.label:SetContentAlignment( 5 )
- tab.label:DockMargin( 0, 0, 0, 0 )
- end
- self.player_list = self:Add( "DPanelList" )
- self.player_list:SetSpacing( 2 )
- self.player_list:EnableHorizontal( false )
- self.player_list:EnableVerticalScrollbar( false )
- self.player_list:Dock( TOP )
- self.player_list:DockMargin( 2, 2, 2, 2 )
- self.player_list.SortByMember = function( self_plist, key, desc )
- table.sort( self_plist.Items, function( a, b )
- if ( a == nil || b == nil ) then return end
- if ( a.tab[ key ] == nil ) then return false end
- if ( b.tab[ key ] == nil ) then return true end
- if ( key == "Name" ) then
- self.nameButton.click = desc
- else
- for k = 1, #SILKBOARD.config.tabs do
- local v = SILKBOARD.config.tabs[ k ]
- if ( v.title == key ) then
- self.button_tabs[ k ].click = desc
- break
- end
- end
- end
- if ( desc ) then
- return ( b.tab[ key ] > a.tab[ key ] )
- end
- return ( a.tab[ key ] > b.tab[ key ] )
- end )
- end
- self.player_list.VBar.Paint = function() return true end
- self.player_list.VBar.btnUp.Paint = function() return true end
- self.player_list.VBar.btnDown.Paint = function() return true end
- self.player_list.VBar.btnGrip.Paint = function() return true end
- function self.player_list.VBar.btnGrip:OnMousePressed() return true end
- function self.player_list.VBar:OnScrollbarAppear() return true end
- function self.player_list.VBar:OnMousePressed() return true end
- function self.player_list.VBar:OnMouseReleased() return true end
- self.footer = self:Add( "DPanel" )
- self.footer:SetDrawBackground( false )
- self.footer:Dock( TOP )
- self.footer:SetHeight( 25 )
- self.footer:DockMargin( 0, 2, 0, 0 )
- local count_lab = self.footer:Add( "DLabel" )
- count_lab:SetFont( "SilkBoardFont" )
- count_lab:SetTextColor( SILKBOARD.config.footerTextColor )
- count_lab:SetText( "" )
- count_lab:SizeToContents()
- count_lab:Dock( LEFT )
- count_lab:SetHeight( 25 )
- count_lab:SetContentAlignment( 5 )
- count_lab:DockMargin( 4, 0, 0, 0 )
- count_lab.m_expireTime = CurTime()
- count_lab.Think = function( self )
- if ( CurTime() > self.m_expireTime ) then
- self.m_expireTime = CurTime() + 2
- local str = ( #player.GetAll() .. "/" .. game.MaxPlayers() )
- if ( self.m_text != str ) then
- self.m_text = str
- count_lab:SetText( str )
- count_lab:SizeToContents()
- end
- end
- end
- local lab = self.footer:Add( "DLabel" )
- lab:SetFont( "SilkBoardFont" )
- lab:SetTextColor( SILKBOARD.config.footerTextColor )
- lab:SetText( SILKBOARD.config.footerText )
- lab:SizeToContents()
- lab:Dock( RIGHT )
- lab:SetHeight( 25 )
- lab:SetContentAlignment( 5 )
- lab:DockMargin( 0, 0, 4, 0 )
- end,
- PerformLayout = function( self )
- self:SetSize( ScrW() * 0.70, ScrH() * 0.95 )
- self:Center()
- // Set the scoreboard title
- self.Name:SetText( SILKBOARD.config.title )
- local nameSpace = ( self:GetWide() - 2 ) * 0.2
- self.nameButton:SetWidth( nameSpace )
- // Set the column titles
- for k = 1, #SILKBOARD.config.tabs do
- local v = SILKBOARD.config.tabs[ k ]
- local width = math.floor( ( self:GetWide() - ( 82 + nameSpace ) ) * v.size )
- self.button_tabs[ k ]:SetWidth( width )
- self.button_tabs[ k ].label:SetText( v.title )
- end
- if ( SILKBOARD.config.showRankUnderName ) then
- self.nameLabel:SetText( "Name/Rank" )
- else
- self.nameLabel:SetText( "Name" )
- end
- self.player_list:SetHeight( self:GetTall() - 158 )
- self.player_list.pnlCanvas.GetWide = function()
- return self.player_list:GetWide()
- end
- end,
- Paint = function( self, w, h )
- // Background
- local x, y = self:LocalToScreen( 0, 0 )
- surface.SetMaterial( blurMat )
- surface.SetDrawColor( 255, 255, 255, 255 )
- for i = 0, 4 do
- blurMat:SetFloat( "$blur", 1.5 )
- blurMat:Recompute()
- render.UpdateScreenEffectTexture()
- surface.DrawTexturedRect( -x, -y, ScrW(), ScrH() )
- end
- draw.RoundedBox( 0, 0, 129, w, h - ( 100 + 29 + 25 ), Color( 10, 10, 10, 150 ) )
- // Header
- draw.RoundedBox( 0, 4, 0, w - 8, 4, Color( 35, 35, 35, 240 ) )
- draw.RoundedBox( 0, 0, 4, w, 100 - 4, Color( 35, 35, 35, 240 ) )
- draw.RoundedBox( 0, 0, 102, w, 25, Color( 35, 35, 35, 240 ) )
- surface.SetDrawColor( 35, 35, 35, 240 )
- surface.SetTexture( cornerMat )
- surface.DrawTexturedRectUV( 0, 0, 4, 4, 0, 0, 1, 1 )
- surface.DrawTexturedRectUV( w - 4, 0, 4, 4, 1, 0, 0, 1 )
- // Footer
- draw.RoundedBox( 0, 0, h - 25, w, 21, Color( 35, 35, 35, 245 ) )
- draw.RoundedBox( 0, 4, h - 4, w - 8, 4, Color( 35, 35, 35, 245 ) )
- --
- surface.SetDrawColor( 35, 35, 35, 245 )
- surface.SetTexture( cornerMat )
- surface.DrawTexturedRectUV( 0, h - 4, 4, 4, 0, 1, 1, 0 )
- surface.DrawTexturedRectUV( w - 4, h - 4, 4, 4, 1, 1, 0, 0 )
- end,
- }
- local SILK_BOARD = vgui.RegisterTable( SILKBOARD_TAB, "EditablePanel" )
- local silkboard = nil
- /*
- Hide the default scoreboard
- */
- hook.Add( "InitPostEntity", "initSilkBoard", function()
- // For DarkRP
- hook.Remove( "ScoreboardShow", "FAdmin_scoreboard" )
- hook.Remove( "ScoreboardHide", "FAdmin_scoreboard" )
- function GAMEMODE:ScoreboardShow()
- if ( !IsValid( silkboard ) ) then
- silkboard = vgui.CreateFromTable( SILK_BOARD )
- silkboard:SetSize( ScrW() * 0.70, ScrH() * 0.95 )
- silkboard:MakePopup()
- silkboard:SetKeyboardInputEnabled( false )
- // Force update the board
- silkboard:UpdateBoard()
- // Destroy the timer if it already exists
- timer.Destroy( "SILKBOARD_UPDATE_INFO" )
- // Update the scoreboard every second
- timer.Create( "SILKBOARD_UPDATE_INFO", 1, 0, function()
- if ( IsValid( silkboard ) ) then
- silkboard:UpdateBoard()
- else
- timer.Destroy( "SILKBOARD_UPDATE_INFO" )
- end
- end )
- else
- silkboard:Show()
- RestoreCursorPosition()
- --
- if ( SILKBOARD.config.glideAnimation ) then
- silkboard:SetPos( 0, ScrH() / 2 - ( ( ScrH() * 0.95 ) / 2 ) )
- silkboard:MoveTo( ScrW() / 2 - ( ( ScrW() * 0.7 ) / 2 ), ScrH() / 2 - ( ScrH() * 0.95 ) / 2, 0.2, 0, 1 )
- end
- end
- end
- function GAMEMODE:ScoreboardHide()
- if ( IsValid( silkboard ) ) then
- RememberCursorPosition()
- silkboard:Hide()
- end
- end
- end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement