-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvoicehud_standalone.lua
More file actions
280 lines (220 loc) · 6.02 KB
/
Copy pathvoicehud_standalone.lua
File metadata and controls
280 lines (220 loc) · 6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
--[[
Voice chat HUD replacement
Reskinned from QBox (Metastruct)
--]]
if SERVER then
include'sh_voice.lua'
AddCSLuaFile'sh_voice.lua'
return
end
local GM = GAMEMODE and GAMEMODE or gmod.GetGamemode()
-- Client pref cvar
-- 1: on
-- 0: server pref
-- -1: off
CreateClientConVar("cl_voicedistance","0",true,true)
local function nodraw()
if hook.Call("HUDShouldDraw",gmod.GetGamemode(),"CHudVoiceStatus")==false then
--print"nodraw"
return true
else
--print"draw"
end
end
local PANEL={}
function PANEL:Init()
self:SetSize(200,32)
self:SizeTo(200,32,1,0,4)
self.ava=vgui.Create('AvatarImage',self)
self.ava:Dock(RIGHT)
self.ava:SetSize(32,32)
self.alpha=0
end
function PANEL:PerformLayout()
end
function PANEL:PerformLayoutEx(k,maxh)
if not self._y then
self._y=maxh-self:GetTall()-(k-1)*(32+2)
end
if self._y!=y then self:GetParent():InvalidateLayout() end
local t = maxh-self:GetTall()-(k)*(32+2)
self._y=math.Approach(self._y,t,FrameTime()*300)
self:SetPos(0,self._y)
end
local cola,colb=
Color(30,30,30,255),
Color(60,60,60,255)
function PANEL:Paint()
local pl = self.pl
local vol = IsValid(pl) and pl:VoiceVolume()
if vol then
vol=vol+0.5
vol=vol>1 and 1 or vol<0 and 0 or vol
vol=vol*90
end
local c=vol or 90
colb.r=c
colb.g=c
colb.b=c
draw.RoundedBoxEx(16,0,0,self:GetWide()-32,self:GetTall(),
self.die and cola or colb,true,false,false,false
)
local txt=tostring(IsValid(self.pl) and pl:Name() or self.plname)
surface.SetTextColor(128,128,128,255)
surface.SetFont "Default"
local w,h=surface.GetTextSize(txt)
surface.SetTextPos(12,self:GetTall()*0.3-h*0.5)
surface.DrawText(txt)
local dist = IsValid(pl) and LocalPlayer():GetPos():Distance(pl:GetPos())
if dist then
local vari=130
if not self.die then
self.starttime=self.starttime or CurTime()
vari=80 - 15 - math.cos((CurTime()-self.starttime)*5)*15
end
local frac = dist/4200
frac = frac <0 and 0 or frac > 1 and 1 or frac
frac=1-frac
surface.SetDrawColor(0,0,0,vari)
surface.DrawRect(0,self:GetTall()-8,self:GetWide(),8)
surface.SetDrawColor(0,0,0,vari)
surface.DrawRect(0,self:GetTall()-8,(self:GetWide()-16)*frac,8)
end
end
function PANEL:SetPlayer(pl)
self.plname=pl:Name()
self.pl=pl
self.ava:SetPlayer(pl,32)
end
function PANEL:Think()
local pl = self.pl
if IsValid(pl) and pl:IsSpeaking() then
self.die = false
else
self.die = true
end
self.alpha=self.alpha>1300 and 1300 or self.alpha<0 and 0 or self.alpha
self:SetAlpha(self.alpha>255 and 255 or self.alpha)
if self.die then
self.alpha = self.alpha - FrameTime()*800
if self.alpha>0 then
return
end
self:GetParent():InvalidateLayout()
self:Remove()
else
self.alpha = self.alpha+FrameTime()*1800
end
end
local voiceinfo = vgui.RegisterTable(PANEL,"DPanel")
local PANEL={}
function PANEL:Init()
self:ParentToHUD()
self:SetMouseInputEnabled(true)
self.players={}
end
function PANEL:Think()
local nodraw=nodraw()
if nodraw and not self.nodrawed then
self:SetAlpha(0)
self.nodrawed=true
elseif not nodraw and self.nodrawed then
self:SetAlpha(255)
self.nodrawed=false
end
end
function PANEL:PerformLayout()
local w,h=ScrW(),ScrH()
self:SetSize(200,h)
self:SetPos(w-self:GetWide()-32,0)
for k,v in pairs(self.players) do
if ValidPanel(v) then
v:PerformLayoutEx(k,self:GetTall())
else
self.players[k]=nil
end
end
end
function PANEL:AddPlayer(pl)
local pnl=self:GetPnl(pl)
if ValidPanel(pnl) then
if pnl.die==true then
pnl.die=false
else
pnl.lastadd=RealTime()
end
else
pnl = self:GetPnl(pl,true)
end
end
function PANEL:GetPnl(pl,create)
for k,v in pairs(self.players) do
if pl==v.pl then return v end
end
if create then
local pnl = vgui.CreateFromTable(voiceinfo,self)
pnl:SetPlayer(pl)
self:InvalidateLayout()
table.insert(self.players,pnl)
end
end
local voicepanel = vgui.RegisterTable(PANEL,"EditablePanel")
if ValidPanel(g_VoicePnl) then
g_VoicePnl:Remove()
end
g_VoicePnl=nil
local function DoInit()
g_VoicePnl=g_VoicePnl or vgui.CreateFromTable(voicepanel,vgui.GetWorldPanel(),"CHudVoiceStatus")
return g_VoicePnl
end
-- Old vgui
hook.Remove( "InitPostEntity", "CreateVoiceVGUI")
-- VOICE RING THING --
local mic_speaking={}
local CircleMat = Material( "SGM/playercircle" )
local function DrawVoiceRing( pl )
if mic_speaking[pl]and pl.IsValid and pl:IsValid()
and pl:Alive() then
local trace = {}
trace.start = pl:GetPos() + Vector(0,0,50)
trace.endpos = trace.start + Vector(0,0,-300)
trace.filter = pl
local tr = util.TraceLine( trace )
if not tr.HitWorld then
tr.HitPos = pl:GetPos()
end
local color = team.GetColor( pl:Team() )
color.a=120 * pl:VoiceVolume()
render.SetMaterial( CircleMat )
render.DrawQuadEasy( pl:GetPos()+Vector(0,0,1), Vector(0,0,1), 128, 128, color )
end
end
hook.Add( "PrePlayerDraw", "VoiceRing", DrawVoiceRing )
local createtimers={}
function GM:PlayerStartVoice( pl )
if not IsValid( pl ) then return end
mic_speaking[ pl ] = true
-- new voice panel
local pnl = DoInit()
local tid=pl:UserID()..'_voice'
createtimers[pl]=tid
if timer.Exists(tid) then return end
timer.Create(tid,1/66,1,function() -- distance voice delay is about this long (tickrate?), thankfully mostly unnoticeable. In fact it's always just one frame, so now this requires full recoding.. At least we have a solid way of detecting when voice distance is used.
if pl:IsValid() then
pnl:AddPlayer(pl)
end
end)
end
function GM:PlayerEndVoice( pl )
local tid=createtimers[pl]
if tid then
timer.Remove(tid)
end
mic_speaking[ pl ] = nil
end
timer.Simple(0,function()
local icntlk_pl=Material("voice/icntlk_pl")
if icntlk_pl then
icntlk_pl:SetFloat("$alpha", 0)
end
end)