Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*---------------------------------------------------
- SlimHUD by Szymekk
- Steam: http://steamcommunity.com/id/szymski
- -----------------------------------------------------*/
- if SERVER then
- AddCSLuaFile()
- AddCSLuaFile("shud_config.lua")
- return
- end
- /*--------------------------------
- Clientside
- ----------------------------------*/
- if !SHUDConfig then include("shud_config.lua") end
- local Config = SHUDConfig
- local PANEL = {}
- local PlayerVoicePanels = {}
- local MatGradientUp = Material("vgui/gradient-u")
- local MatGradientDown = Material("vgui/gradient-d")
- function PANEL:Init()
- self.LabelName = vgui.Create( "DLabel", self )
- self.LabelName:SetFont( "GModNotify" )
- self.LabelName:Dock( FILL )
- self.LabelName:DockMargin( 8, 0, 0, 0 )
- self.LabelName:SetTextColor( Color( 255, 255, 255, 255 ) )
- self.Avatar = vgui.Create( "AvatarImage", self )
- self.Avatar:Dock( LEFT )
- self.Avatar:SetSize( 32, 32 )
- self.Avatar.PaintOver = function(av, w, h)
- if IsValid(self.ply) && self.ply.Alive then
- surface.SetDrawColor(self.ply:Alive() == false and Config.DeadVoiceColor or (self.ply:Team() == TEAM_DEATH and Config.DVoiceColor or Config.RVoiceColor))
- surface.DrawOutlinedRect(0, 0, w, h)
- end
- end
- self.Color = color_transparent
- self:SetSize( 250, 32 + 8 )
- self:DockPadding( 4, 4, 4, 4 )
- self:DockMargin( 2, 2, 2, 2 )
- self:Dock( BOTTOM )
- end
- function PANEL:Setup( ply )
- self.ply = ply
- self.LabelName:SetText( ply:Nick() )
- self.Avatar:SetPlayer( ply )
- self.Color = team.GetColor( ply:Team() )
- self:InvalidateLayout()
- end
- function PANEL:Paint( w, h )
- if IsValid(self.ply) && self.ply.Alive then
- surface.SetDrawColor(self.ply:Alive() == false and Config.DeadVoiceColor or (self.ply:Team() == TEAM_DEATH and Config.DVoiceColor or Config.RVoiceColor))
- surface.DrawRect(0, 0, w, h)
- surface.SetDrawColor(255, 255, 255, 50)
- surface.DrawLine(1, 1, w-2, 1)
- surface.SetDrawColor(255, 255, 255, 20)
- surface.DrawLine(w-2, 1, w-2, h-1)
- surface.SetDrawColor(0, 0, 0, 150)
- surface.DrawOutlinedRect(0, 0, w, h)
- surface.SetDrawColor(0, 0, 0, 80)
- surface.SetMaterial(MatGradientDown)
- surface.DrawTexturedRect(0, h*0.7, w, h*0.3)
- if Config.VoiceAnim then
- self.smoothv = ((self.smoothv or 0)*6 + self.ply:VoiceVolume() * 150) / 7
- local c = math.Clamp(self.smoothv, 0, 50)
- surface.SetDrawColor(255, 255, 255, c)
- surface.DrawRect(0, 0, w, h)
- end
- end
- end
- function PANEL:Think()
- if ( IsValid( self.ply ) ) then
- self.LabelName:SetText( self.ply:Nick() )
- end
- if ( self.fadeAnim ) then
- self.fadeAnim:Run()
- end
- end
- function PANEL:FadeOut( anim, delta, data )
- if ( anim.Finished ) then
- if ( IsValid( PlayerVoicePanels[ self.ply ] ) ) then
- PlayerVoicePanels[ self.ply ]:Remove()
- PlayerVoicePanels[ self.ply ] = nil
- return
- end
- return end
- self:SetAlpha( 255 - ( 255 * delta ) )
- end
- derma.DefineControl( "SHUDVoiceNotify", "", PANEL, "DPanel" )
- local function VoiceClean()
- for k, v in pairs( PlayerVoicePanels ) do
- if ( !IsValid( k ) ) then
- GAMEMODE:PlayerEndVoice( k )
- end
- end
- end
- timer.Create( "VoiceClean", 10, 0, VoiceClean )
- local function CreateVoiceVGUI()
- if g_VoicePanelList then g_VoicePanelList:Remove() end
- g_VoicePanelList = vgui.Create( "DPanel" )
- g_VoicePanelList:ParentToHUD()
- g_VoicePanelList:SetPos( ScrW() - 300, 100 )
- g_VoicePanelList:SetSize( 250, ScrH() - 200 )
- g_VoicePanelList:SetPaintBackground( false )
- end
- hook.Add("InitPostEntity", "SHUDVoice_Init", function()
- if !Config.VoiceEnabled then return end
- function GAMEMODE:PlayerStartVoice( ply )
- if ( !IsValid( g_VoicePanelList ) ) then return end
- -- There'd be an exta one if voice_loopback is on, so remove it.
- GAMEMODE:PlayerEndVoice( ply )
- if ( IsValid( PlayerVoicePanels[ ply ] ) ) then
- if ( PlayerVoicePanels[ ply ].fadeAnim ) then
- PlayerVoicePanels[ ply ].fadeAnim:Stop()
- PlayerVoicePanels[ ply ].fadeAnim = nil
- end
- PlayerVoicePanels[ ply ]:SetAlpha( 255 )
- return
- end
- if ( !IsValid( ply ) ) then return end
- local pnl = g_VoicePanelList:Add( "SHUDVoiceNotify" )
- pnl:Setup( ply )
- PlayerVoicePanels[ ply ] = pnl
- end
- function GAMEMODE:PlayerEndVoice( ply )
- if ( IsValid( PlayerVoicePanels[ ply ] ) ) then
- if ( PlayerVoicePanels[ ply ].fadeAnim ) then return end
- PlayerVoicePanels[ ply ].fadeAnim = Derma_Anim( "FadeOut", PlayerVoicePanels[ ply ], PlayerVoicePanels[ ply ].FadeOut )
- PlayerVoicePanels[ ply ].fadeAnim:Start( 0.4 )
- end
- end
- CreateVoiceVGUI()
- end)
- if GAMEMODE && Config.VoiceEnabled then
- function GAMEMODE:PlayerStartVoice( ply )
- if ( !IsValid( g_VoicePanelList ) ) then return end
- -- There'd be an exta one if voice_loopback is on, so remove it.
- GAMEMODE:PlayerEndVoice( ply )
- if ( IsValid( PlayerVoicePanels[ ply ] ) ) then
- if ( PlayerVoicePanels[ ply ].fadeAnim ) then
- PlayerVoicePanels[ ply ].fadeAnim:Stop()
- PlayerVoicePanels[ ply ].fadeAnim = nil
- end
- PlayerVoicePanels[ ply ]:SetAlpha( 255 )
- return
- end
- if ( !IsValid( ply ) ) then return end
- local pnl = g_VoicePanelList:Add( "SHUDVoiceNotify" )
- pnl:Setup( ply )
- PlayerVoicePanels[ ply ] = pnl
- end
- function GAMEMODE:PlayerEndVoice( ply )
- if ( IsValid( PlayerVoicePanels[ ply ] ) ) then
- if ( PlayerVoicePanels[ ply ].fadeAnim ) then return end
- PlayerVoicePanels[ ply ].fadeAnim = Derma_Anim( "FadeOut", PlayerVoicePanels[ ply ], PlayerVoicePanels[ ply ].FadeOut )
- PlayerVoicePanels[ ply ].fadeAnim:Start( 0.4 )
- end
- end
- CreateVoiceVGUI()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement