-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPerfectRaid_ReadyCheck.lua
More file actions
141 lines (98 loc) · 3.51 KB
/
PerfectRaid_ReadyCheck.lua
File metadata and controls
141 lines (98 loc) · 3.51 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
--[[-------------------------------------------------------------------------
*
* ReadyCheck module for PerfectRaid addon.
*
* Written by: Panoramix
* Version: 1.0
*
---------------------------------------------------------------------------]]
local ReadyCheck = PerfectRaid:NewModule("PerfectRaid-ReadyCheck")
local frames
-- the duration to fade the ready check status
ReadyCheck.fadeDuration = 4
function ReadyCheck:Initialize()
frames = PerfectRaid.frames
self:RegisterEvent("READY_CHECK", "UpdateReadyCheck")
self:RegisterEvent("READY_CHECK_CONFIRM", "UpdateReadyCheck")
self:RegisterEvent("READY_CHECK_FINISHED", "UpdateReadyCheck")
self.started = false
end
function ReadyCheck:ConfigureButton( button )
button.readycheck = CreateFrame("Frame", nil, button.leftbox)
button.readycheck.indicator = button.readycheck:CreateTexture(nil, "OVERLAY")
end
function ReadyCheck:UpdateButtonLayout( button )
button.readycheck:ClearAllPoints()
button.readycheck:SetWidth(button:GetHeight( ))
button.readycheck:SetHeight(button:GetHeight( ))
button.readycheck:SetFrameLevel(button.leftbox:GetFrameLevel()+1)
button.readycheck.indicator:SetAllPoints()
button.readycheck.indicator:SetTexture(READY_CHECK_READY_TEXTURE)
button.readycheck:SetPoint("RIGHT", button.name, "RIGHT", 0, 0)
button.readycheck:Hide()
end
--[[
event = READY_CHECK | READY_CHECK_CONFIRM(unit)| READY_CHECK_FINISHED
status = GetReadyCheckStatus( unit )
= "ready" | "notready" | "waiting"
]]--
function ReadyCheck:UpdateReadyCheck( event, target )
-- a ready check is initiated, update all frames
if event == "READY_CHECK" then
for unit, tbl in pairs(frames) do
local status = GetReadyCheckStatus( unit )
for frame in pairs(frames[unit]) do
ReadyCheck:SetReadyCheckStatus( frame, status )
end
end
-- a ready check is confirmed or declined, update frames of the unit
elseif event == "READY_CHECK_CONFIRM" then
for unit, tbl in pairs(frames) do
if UnitIsUnit( target, unit ) then
local status = GetReadyCheckStatus( unit )
for frame in pairs(frames[unit]) do
ReadyCheck:SetReadyCheckStatus( frame, status )
end
break
end
end
-- the ready check has finished, wrap it up
elseif event == "READY_CHECK_FINISHED" then
-- update any ~ready status
for unit, tbl in pairs(frames) do
for frame in pairs(frames[unit]) do
if frame.readycheck.status then
-- update status to not ready
if frame.readycheck.status ~= "ready" then
ReadyCheck:SetReadyCheckStatus( frame, "notready" )
end
-- start fade timer
frame.readycheck.elapsed = ReadyCheck.fadeDuration
frame.readycheck:SetScript("OnUpdate", function(self, elapsed)
self.elapsed = self.elapsed - elapsed
self:SetAlpha( self.elapsed / ReadyCheck.fadeDuration )
if self.elapsed <= 0 then
self:Hide()
self:SetScript("OnUpdate", nil)
end
end)
end
end
end
end
end
function ReadyCheck:SetReadyCheckStatus( frame, status )
frame.readycheck.status = status
if not status then
return
end
if( status == "ready" ) then
frame.readycheck.indicator:SetTexture(READY_CHECK_READY_TEXTURE)
elseif( status == "notready" ) then
frame.readycheck.indicator:SetTexture(READY_CHECK_NOT_READY_TEXTURE)
elseif( status == "waiting" ) then
frame.readycheck.indicator:SetTexture(READY_CHECK_WAITING_TEXTURE)
end
frame.readycheck:SetAlpha( 1.0 )
frame.readycheck:Show()
end