File daybreak.lua added (mode: 100644) (index 0000000..e99adab) |
|
1 |
|
local function getDefaultButtonSize() |
|
2 |
|
return 32 |
|
3 |
|
end |
|
4 |
|
|
|
5 |
|
local function acceptUnitAura(button, eventCategory) |
|
6 |
|
assert (button ~= nil) |
|
7 |
|
assert (eventCategory ~= nil) |
|
8 |
|
|
|
9 |
|
local auraName = button:GetAttribute('spell') |
|
10 |
|
assert (auraName ~= nil) |
|
11 |
|
|
|
12 |
|
local unitDesignation = button:GetAttribute('unit') |
|
13 |
|
assert (unitDesignation ~= nil) |
|
14 |
|
|
|
15 |
|
local name, rank, icon, count, debuffType, duration, expirationInstance, |
|
16 |
|
unitCaster, isStealable, shouldConsolidate, |
|
17 |
|
spellId = UnitBuff(unitDesignation, auraName) |
|
18 |
|
if nil == expirationInstance then |
|
19 |
|
expirationInstance = 0 |
|
20 |
|
end |
|
21 |
|
local now = GetTime() |
|
22 |
|
if not name or not expirationInstance then |
|
23 |
|
button:Hide() |
|
24 |
|
elseif name and expirationInstance > now then |
|
25 |
|
local elapsedDuration = expirationInstance - now |
|
26 |
|
local durationRemaining = duration - elapsedDuration |
|
27 |
|
button:SetText(durationRemaining) |
|
28 |
|
--[[ FIXME Apply graphics only once instead of every aura update ]]-- |
|
29 |
|
button:SetNormalTexture(icon) |
|
30 |
|
button:Show() |
|
31 |
|
else |
|
32 |
|
button:Hide() |
|
33 |
|
end |
|
34 |
|
end |
|
35 |
|
|
|
36 |
|
local function applyUpdate(button, updateDuration) |
|
37 |
|
assert (button ~= nil) |
|
38 |
|
|
|
39 |
|
local auraName = button:GetAttribute('spell') |
|
40 |
|
assert (auraName ~= nil) |
|
41 |
|
|
|
42 |
|
local unitDesignation = button:GetAttribute('unit') |
|
43 |
|
assert (unitDesignation ~= nil) |
|
44 |
|
|
|
45 |
|
local name, _, _, _, _, duration, expirationInstance = UnitBuff(unitDesignation, auraName) |
|
46 |
|
local now = GetTime() |
|
47 |
|
if nil == expirationInstance then |
|
48 |
|
return |
|
49 |
|
end |
|
50 |
|
local remainingDuration = math.ceil(expirationInstance - now) |
|
51 |
|
button:SetText(remainingDuration) |
|
52 |
|
end |
|
53 |
|
|
|
54 |
|
local function createHolyPowerIndicator(frameName, parentFrame, unitDesignation) |
|
55 |
|
assert (parentFrame ~= nil) |
|
56 |
|
assert (unitDesignation ~= nil) |
|
57 |
|
|
|
58 |
|
|
|
59 |
|
local f = CreateFrame('FRAME', frameName, parentFrame) |
|
60 |
|
f.unit = unitDesignation |
|
61 |
|
f:SetSize(64, 64) |
|
62 |
|
local t = {} |
|
63 |
|
local q = 0 |
|
64 |
|
local x = 0 |
|
65 |
|
local y = 0 |
|
66 |
|
local margin = 0 |
|
67 |
|
while (q < 5) do |
|
68 |
|
q = q + 1 |
|
69 |
|
local p = f:CreateTexture(frameName .. tostring(q), 'OVERLAY') |
|
70 |
|
p:SetTexture(255 / 255, 204 / 255, 0 / 255, 1) |
|
71 |
|
p:SetSize(24, 24) |
|
72 |
|
p:SetPoint('BOTTOMLEFT', margin + x * 28, y * 28) |
|
73 |
|
p:Hide() |
|
74 |
|
x = x + 1 |
|
75 |
|
if x >= 3 then |
|
76 |
|
x = 0 |
|
77 |
|
y = y + 1 |
|
78 |
|
margin = margin + 14 |
|
79 |
|
end |
|
80 |
|
t[q] = p |
|
81 |
|
end |
|
82 |
|
f.children = t |
|
83 |
|
|
|
84 |
|
f:RegisterEvent('UNIT_POWER_FREQUENT') |
|
85 |
|
f:SetScript('OnEvent', function(self) |
|
86 |
|
local t = self.children |
|
87 |
|
local i = 0 |
|
88 |
|
local hppq = UnitPower(self.unit, SPELL_POWER_HOLY_POWER) |
|
89 |
|
while (i < 5) do |
|
90 |
|
i = i + 1 |
|
91 |
|
local p = t[i] |
|
92 |
|
if i <= hppq then |
|
93 |
|
p:Show() |
|
94 |
|
else |
|
95 |
|
p:Hide() |
|
96 |
|
end |
|
97 |
|
end |
|
98 |
|
end) |
|
99 |
|
return f |
|
100 |
|
end |
|
101 |
|
|
|
102 |
|
local function createButton(buttonName, parentFrame, auraName) |
|
103 |
|
assert (buttonName ~= nil) |
|
104 |
|
assert (parentFrame ~= nil) |
|
105 |
|
assert (auraName ~= nil) |
|
106 |
|
|
|
107 |
|
local button = CreateFrame('BUTTON', buttonName, parentFrame, 'SecureActionButtonTemplate') |
|
108 |
|
local size = getDefaultButtonSize() |
|
109 |
|
button:SetSize(size, size) |
|
110 |
|
|
|
111 |
|
local text = button:CreateFontString(button:GetName() .. 'Text', 'OVERLAY') |
|
112 |
|
text:SetFontObject(DaybreakFont) |
|
113 |
|
text:SetAllPoints() |
|
114 |
|
|
|
115 |
|
button:SetFontString(text) |
|
116 |
|
button:SetText('?') |
|
117 |
|
|
|
118 |
|
button:SetAttribute('type', 'cancelaura') |
|
119 |
|
button:SetAttribute('spell', auraName) |
|
120 |
|
button:SetAttribute('unit', 'player') |
|
121 |
|
|
|
122 |
|
button:RegisterEvent('UNIT_AURA') |
|
123 |
|
button:SetScript('OnEvent', acceptUnitAura) |
|
124 |
|
button:SetScript('OnUpdate', applyUpdate) |
|
125 |
|
|
|
126 |
|
button:Hide() |
|
127 |
|
|
|
128 |
|
return button |
|
129 |
|
end |
|
130 |
|
|
|
131 |
|
local function init(rootFrame) |
|
132 |
|
assert (rootFrame ~= nil) |
|
133 |
|
|
|
134 |
|
rootFrame:SetSize(384, 384) |
|
135 |
|
rootFrame:SetPoint('CENTER', UIParent, |
|
136 |
|
'CENTER', 0, 0) |
|
137 |
|
|
|
138 |
|
local hpf = createHolyPowerIndicator('DaybreakHolyPowerPlayerFrame', rootFrame, 'player') |
|
139 |
|
hpf:SetPoint('CENTER', 0, -128) |
|
140 |
|
|
|
141 |
|
local padding = 8 |
|
142 |
|
local size = getDefaultButtonSize() + padding |
|
143 |
|
|
|
144 |
|
--[[ General ]]-- |
|
145 |
|
local wings = createButton('DaybreakButton01', rootFrame, 'Avenging Wrath') |
|
146 |
|
wings:SetPoint('BOTTOMLEFT', 0 * size, 2 * size) |
|
147 |
|
|
|
148 |
|
local protection = createButton('DaybreakButton02', rootFrame, 'Divine Protection') |
|
149 |
|
protection:SetPoint('BOTTOMLEFT', 0 * size, 2 * size) |
|
150 |
|
|
|
151 |
|
local bubble = createButton('DaybreakButton03', rootFrame, 'Divine Shield') |
|
152 |
|
bubble:SetPoint('BOTTOMLEFT', 0 * size, 2 * size) |
|
153 |
|
|
|
154 |
|
local plea = createButton('DaybreakButton04', rootFrame, 'Divine Plea') |
|
155 |
|
plea:SetPoint('BOTTOMLEFT', 0 * size, 1 * size) |
|
156 |
|
|
|
157 |
|
local hop = createButton('DaybreakButton05', rootFrame, 'Hand of Protection') |
|
158 |
|
hop:SetPoint('BOTTOMLEFT', 0 * size, 0 * size) |
|
159 |
|
|
|
160 |
|
local freedom = createButton('DaybreakButton06', rootFrame, 'Hand of Freedom') |
|
161 |
|
freedom:SetPoint('BOTTOMLEFT', 0 * size, 0 * size) |
|
162 |
|
|
|
163 |
|
--[[ Holy ]]-- |
|
164 |
|
local daybreak = createButton('DaybreakButton07', rootFrame, 'Daybreak') |
|
165 |
|
daybreak:SetPoint('BOTTOMLEFT', 1 * size, 1 * size) |
|
166 |
|
|
|
167 |
|
local infusion = createButton('DaybreakButton08', rootFrame, 'Infusion of Light') |
|
168 |
|
infusion:SetPoint('BOTTOMLEFT', 1 * size, 2 * size) |
|
169 |
|
|
|
170 |
|
local judgement = createButton('DaybreakButton08', rootFrame, 'Judgements of the Pure') |
|
171 |
|
judgement:SetPoint('BOTTOMLEFT', 1 * size, 0 * size) |
|
172 |
|
|
|
173 |
|
--[[ Protection ]]-- |
|
174 |
|
local grandCrusader = createButton('DaybreakButton09', rootFrame, 'Grand Crusader') |
|
175 |
|
grandCrusader:SetPoint('BOTTOMLEFT', 1 * size, 0 * size) |
|
176 |
|
|
|
177 |
|
local shield = createButton('DaybreakButton10', rootFrame, 'Holy Shield') |
|
178 |
|
shield:SetPoint('BOTTOMLEFT', 1 * size, 1 * size) |
|
179 |
|
|
|
180 |
|
--[[ Retribution ]]-- |
|
181 |
|
|
|
182 |
|
print('[Daybreak]: addon loaded') |
|
183 |
|
|
|
184 |
|
return rootFrame |
|
185 |
|
end |
|
186 |
|
|
|
187 |
|
local function main() |
|
188 |
|
local rootFrame = CreateFrame('FRAME', 'DaybreakFrame', UIParent) |
|
189 |
|
rootFrame:SetScript('OnEvent', init) |
|
190 |
|
rootFrame:RegisterEvent('VARIABLES_LOADED') |
|
191 |
|
end |
|
192 |
|
main() |