forked from Resike/Z-Perl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZPerl_Voice.lua
175 lines (150 loc) · 4.3 KB
/
ZPerl_Voice.lua
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
-- X-Perl UnitFrames
-- Author: Resike
-- License: GNU GPL v3, 29 June 2007 (see LICENSE.txt)
CreateFrame("Frame", "XPerl_Voice", BackdropTemplateMixin and "BackdropTemplate")
local voice = XPerl_Voice
local conf
XPerl_RequestConfig(function(new)
conf = new
voice:RepositionAll()
end, "$Revision: @file-revision@ $")
voice.frames = {}
voice.permenantUnits = {}
function voice:ClearCache()
self.cachedUnits = setmetatable({}, {
__index = function(self, unit)
for frame in pairs(XPerl_Voice.frames) do
--if (not frame.permenantVoiceID) then -- Shouldn't ever happen
if (frame.partyid == unit) then
self[unit] = frame
return self[unit]
end
--end
end
end
})
end
voice:ClearCache()
-- if (IsVoiceChatEnabled()) then
-- voice:Create
function voice:Create(frame)
if not frame.voiceButton then
frame.voiceButton = CreateFrame("Button", self:GetName().."Speaker", frame, BackdropTemplateMixin and "BackdropTemplate", "VoiceChatSpeakerTemplate")
frame.voiceButton:EnableMouse(false)
end
XPerl_SetChildMembers(frame.voiceButton)
self:Position(frame)
end
-- voice:Position
function voice:Position(frame)
if (frame.nameFrame and frame.nameFrame:IsShown()) then
frame.voiceButton:SetParent(frame.nameFrame)
frame.voiceButton:SetPoint("LEFT", frame.nameFrame, "LEFT", 5, 0)
frame.voiceButton:SetFrameLevel(frame.nameFrame:GetFrameLevel() + 1)
elseif (frame.portraitFrame and frame.portraitFrame:IsShown()) then
frame.voiceButton:SetParent(frame.portraitFrame)
frame.voiceButton:SetPoint("TOPLEFT", frame.portraitFrame, "TOPLEFT", 5, -5)
frame.voiceButton:SetFrameLevel(frame.portraitFrame:GetFrameLevel() + 1)
elseif (frame.statsFrame and frame.statsFrame:IsShown()) then
frame.voiceButton:SetParent(frame.statsFrame)
frame.voiceButton:SetPoint("CENTER", frame.statsFrame, "CENTER", 0, 0)
frame.voiceButton:SetFrameLevel(frame.statsFrame:GetFrameLevel() + 1)
else
frame.voiceButton:SetParent(frame)
frame.voiceButton:SetPoint("TOPLEFT", 5, -5)
frame.voiceButton:SetFrameLevel(frame:GetFrameLevel() + 1)
end
frame.voiceButton:SetWidth(16)
frame.voiceButton:SetHeight(16)
end
-- voice:RepositionAll
function voice:RepositionAll()
for frame in pairs(self.frames) do
self:Position(frame)
end
end
-- voice:Register
function voice:Register(frame, variableUnitID)
self:Create(frame)
self.frames[frame] = true
if (not variableUnitID) then
self.permenantUnits[frame.partyid] = frame
frame.permenantVoiceID = true
end
self:UpdateVoice(frame)
end
-- voice:Unregister
function voice:Unregister(frame)
self.frames[frame] = nil
end
-- voice:OnEvent(event, a, b, c)
function voice:OnEvent(event, a, b, c)
self[event](self, a, b, c)
end
-- voice:Updatevoice
function voice:UpdateVoice(frame, onoff)
--[[if (IsVoiceChatEnabled()) then
if (onoff == nil) then
if (frame.partyid and GetVoiceStatus(frame.partyid)) then
onoff = UnitIsTalking(frame.partyid)
end
end
else
onoff = nil
end]]
if (onoff) then
frame.voiceButton.On:Show()
frame.voiceButton.Flash:Hide()
XPerl_FrameFlash(frame.voiceButton.Flash)
else
if frame.voiceButton then
frame.voiceButton.On:Hide()
XPerl_FrameFlashStop(frame.voiceButton.Flash)
end
end
--local muted = frame.partyid and GetMuteStatus(frame.partyid)
--if (muted) then
-- frame.voiceButton.Muted:Show()
--else
-- frame.voiceButton.Muted:Hide()
--end
end
-- voice:UpdateAllVoice
function voice:UpdateAllVoice()
for frame in pairs(self.frames) do
self:UpdateVoice(frame)
end
end
-- VOICE_STATUS_UPDATE
function voice:VOICE_STATUS_UPDATE(a, b, c)
self:UpdateAllVoice()
end
-- MUTELIST_UPDATE
function voice:MUTELIST_UPDATE()
self:UpdateAllVoice()
end
-- voice:UpdateByUnit
function voice:UpdateByUnit(unit, onoff)
local frame = self.permenantUnits[unit] or self.cachedUnits[unit]
if (frame) then
self:UpdateVoice(frame, onoff)
end
end
-- voice:VOICE_START
function voice:VOICE_START(unit)
self:UpdateByUnit(unit, true)
end
-- voice:VOICE_STOP
function voice:VOICE_STOP(unit)
self:UpdateByUnit(unit, false)
end
-- voice:GROUP_ROSTER_UPDATE
function voice:GROUP_ROSTER_UPDATE()
self:ClearCache()
end
voice:RegisterEvent("VOICE_STATUS_UPDATE")
voice:RegisterEvent("MUTELIST_UPDATE")
voice:RegisterEvent("VOICE_START")
voice:RegisterEvent("VOICE_STOP")
voice:RegisterEvent("GROUP_ROSTER_UPDATE")
voice:SetScript("OnEvent", voice.OnEvent)