Advertisement
szymski

Untitled

May 23rd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.66 KB | None | 0 0
  1. /*---------------------------------------------------
  2. SlimHUD by Szymekk
  3. Steam: http://steamcommunity.com/id/szymski
  4. -----------------------------------------------------*/
  5.  
  6. if SERVER then
  7. AddCSLuaFile()
  8. AddCSLuaFile("shud_config.lua")
  9. return
  10. end
  11.  
  12. /*--------------------------------
  13. Clientside
  14. ----------------------------------*/
  15.  
  16. if !SHUDConfig then include("shud_config.lua") end
  17. local Config = SHUDConfig
  18.  
  19. local PANEL = {}
  20. local PlayerVoicePanels = {}
  21.  
  22. local MatGradientUp = Material("vgui/gradient-u")
  23. local MatGradientDown = Material("vgui/gradient-d")
  24.  
  25. function PANEL:Init()
  26.  
  27. self.LabelName = vgui.Create( "DLabel", self )
  28. self.LabelName:SetFont( "GModNotify" )
  29. self.LabelName:Dock( FILL )
  30. self.LabelName:DockMargin( 8, 0, 0, 0 )
  31. self.LabelName:SetTextColor( Color( 255, 255, 255, 255 ) )
  32.  
  33. self.Avatar = vgui.Create( "AvatarImage", self )
  34. self.Avatar:Dock( LEFT )
  35. self.Avatar:SetSize( 32, 32 )
  36. self.Avatar.PaintOver = function(av, w, h)
  37. if IsValid(self.ply) && self.ply.Alive then
  38. surface.SetDrawColor(self.ply:Alive() == false and Config.DeadVoiceColor or (self.ply:Team() == TEAM_DEATH and Config.DVoiceColor or Config.RVoiceColor))
  39. surface.DrawOutlinedRect(0, 0, w, h)
  40. end
  41. end
  42.  
  43. self.Color = color_transparent
  44.  
  45. self:SetSize( 250, 32 + 8 )
  46. self:DockPadding( 4, 4, 4, 4 )
  47. self:DockMargin( 2, 2, 2, 2 )
  48. self:Dock( BOTTOM )
  49.  
  50. end
  51.  
  52. function PANEL:Setup( ply )
  53.  
  54. self.ply = ply
  55. self.LabelName:SetText( ply:Nick() )
  56. self.Avatar:SetPlayer( ply )
  57.  
  58. self.Color = team.GetColor( ply:Team() )
  59.  
  60. self:InvalidateLayout()
  61.  
  62. end
  63.  
  64. function PANEL:Paint( w, h )
  65.  
  66. if IsValid(self.ply) && self.ply.Alive then
  67.  
  68. surface.SetDrawColor(self.ply:Alive() == false and Config.DeadVoiceColor or (self.ply:Team() == TEAM_DEATH and Config.DVoiceColor or Config.RVoiceColor))
  69. surface.DrawRect(0, 0, w, h)
  70.  
  71. surface.SetDrawColor(255, 255, 255, 50)
  72. surface.DrawLine(1, 1, w-2, 1)
  73. surface.SetDrawColor(255, 255, 255, 20)
  74. surface.DrawLine(w-2, 1, w-2, h-1)
  75.  
  76. surface.SetDrawColor(0, 0, 0, 150)
  77. surface.DrawOutlinedRect(0, 0, w, h)
  78.  
  79. surface.SetDrawColor(0, 0, 0, 80)
  80. surface.SetMaterial(MatGradientDown)
  81. surface.DrawTexturedRect(0, h*0.7, w, h*0.3)
  82.  
  83. if Config.VoiceAnim then
  84. self.smoothv = ((self.smoothv or 0)*6 + self.ply:VoiceVolume() * 150) / 7
  85. local c = math.Clamp(self.smoothv, 0, 50)
  86. surface.SetDrawColor(255, 255, 255, c)
  87. surface.DrawRect(0, 0, w, h)
  88. end
  89.  
  90. end
  91. end
  92.  
  93. function PANEL:Think()
  94.  
  95. if ( IsValid( self.ply ) ) then
  96. self.LabelName:SetText( self.ply:Nick() )
  97. end
  98.  
  99. if ( self.fadeAnim ) then
  100. self.fadeAnim:Run()
  101. end
  102.  
  103. end
  104.  
  105. function PANEL:FadeOut( anim, delta, data )
  106.  
  107. if ( anim.Finished ) then
  108.  
  109. if ( IsValid( PlayerVoicePanels[ self.ply ] ) ) then
  110. PlayerVoicePanels[ self.ply ]:Remove()
  111. PlayerVoicePanels[ self.ply ] = nil
  112. return
  113. end
  114.  
  115. return end
  116.  
  117. self:SetAlpha( 255 - ( 255 * delta ) )
  118.  
  119. end
  120.  
  121. derma.DefineControl( "SHUDVoiceNotify", "", PANEL, "DPanel" )
  122.  
  123.  
  124. local function VoiceClean()
  125.  
  126. for k, v in pairs( PlayerVoicePanels ) do
  127.  
  128. if ( !IsValid( k ) ) then
  129. GAMEMODE:PlayerEndVoice( k )
  130. end
  131.  
  132. end
  133.  
  134. end
  135. timer.Create( "VoiceClean", 10, 0, VoiceClean )
  136.  
  137. local function CreateVoiceVGUI()
  138.  
  139. if g_VoicePanelList then g_VoicePanelList:Remove() end
  140.  
  141. g_VoicePanelList = vgui.Create( "DPanel" )
  142.  
  143. g_VoicePanelList:ParentToHUD()
  144. g_VoicePanelList:SetPos( ScrW() - 300, 100 )
  145. g_VoicePanelList:SetSize( 250, ScrH() - 200 )
  146. g_VoicePanelList:SetPaintBackground( false )
  147.  
  148.  
  149. end
  150.  
  151. hook.Add("InitPostEntity", "SHUDVoice_Init", function()
  152. if !Config.VoiceEnabled then return end
  153.  
  154. function GAMEMODE:PlayerStartVoice( ply )
  155. if ( !IsValid( g_VoicePanelList ) ) then return end
  156.  
  157. -- There'd be an exta one if voice_loopback is on, so remove it.
  158. GAMEMODE:PlayerEndVoice( ply )
  159.  
  160.  
  161. if ( IsValid( PlayerVoicePanels[ ply ] ) ) then
  162.  
  163. if ( PlayerVoicePanels[ ply ].fadeAnim ) then
  164. PlayerVoicePanels[ ply ].fadeAnim:Stop()
  165. PlayerVoicePanels[ ply ].fadeAnim = nil
  166. end
  167.  
  168. PlayerVoicePanels[ ply ]:SetAlpha( 255 )
  169.  
  170. return
  171.  
  172. end
  173.  
  174. if ( !IsValid( ply ) ) then return end
  175.  
  176. local pnl = g_VoicePanelList:Add( "SHUDVoiceNotify" )
  177. pnl:Setup( ply )
  178.  
  179. PlayerVoicePanels[ ply ] = pnl
  180. end
  181.  
  182. function GAMEMODE:PlayerEndVoice( ply )
  183. if ( IsValid( PlayerVoicePanels[ ply ] ) ) then
  184.  
  185. if ( PlayerVoicePanels[ ply ].fadeAnim ) then return end
  186.  
  187. PlayerVoicePanels[ ply ].fadeAnim = Derma_Anim( "FadeOut", PlayerVoicePanels[ ply ], PlayerVoicePanels[ ply ].FadeOut )
  188. PlayerVoicePanels[ ply ].fadeAnim:Start( 0.4 )
  189.  
  190. end
  191. end
  192.  
  193. CreateVoiceVGUI()
  194. end)
  195.  
  196. if GAMEMODE && Config.VoiceEnabled then
  197. function GAMEMODE:PlayerStartVoice( ply )
  198. if ( !IsValid( g_VoicePanelList ) ) then return end
  199.  
  200. -- There'd be an exta one if voice_loopback is on, so remove it.
  201. GAMEMODE:PlayerEndVoice( ply )
  202.  
  203.  
  204. if ( IsValid( PlayerVoicePanels[ ply ] ) ) then
  205.  
  206. if ( PlayerVoicePanels[ ply ].fadeAnim ) then
  207. PlayerVoicePanels[ ply ].fadeAnim:Stop()
  208. PlayerVoicePanels[ ply ].fadeAnim = nil
  209. end
  210.  
  211. PlayerVoicePanels[ ply ]:SetAlpha( 255 )
  212.  
  213. return
  214.  
  215. end
  216.  
  217. if ( !IsValid( ply ) ) then return end
  218.  
  219. local pnl = g_VoicePanelList:Add( "SHUDVoiceNotify" )
  220. pnl:Setup( ply )
  221.  
  222. PlayerVoicePanels[ ply ] = pnl
  223. end
  224.  
  225. function GAMEMODE:PlayerEndVoice( ply )
  226. if ( IsValid( PlayerVoicePanels[ ply ] ) ) then
  227.  
  228. if ( PlayerVoicePanels[ ply ].fadeAnim ) then return end
  229.  
  230. PlayerVoicePanels[ ply ].fadeAnim = Derma_Anim( "FadeOut", PlayerVoicePanels[ ply ], PlayerVoicePanels[ ply ].FadeOut )
  231. PlayerVoicePanels[ ply ].fadeAnim:Start( 0.4 )
  232.  
  233. end
  234. end
  235. CreateVoiceVGUI()
  236. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement