File daybreak.lua changed (mode: 100644) (index b0c3294..d105517) |
|
1 |
|
--[[-- |
|
2 |
|
Add paladin player aura indicator. |
|
3 |
|
@script daybreak |
|
4 |
|
]] |
|
5 |
|
|
|
6 |
|
--[[-- |
|
7 |
|
Access constant default indicator size pixels. |
|
8 |
|
@function getDefaultButtonSize |
|
9 |
|
@treturn number positive integer |
|
10 |
|
]] |
1 |
11 |
local function getDefaultButtonSize() |
local function getDefaultButtonSize() |
2 |
12 |
return 32 |
return 32 |
3 |
13 |
end |
end |
4 |
14 |
|
|
|
15 |
|
--[[-- |
|
16 |
|
Access constant maximum quantity of holy power points. |
|
17 |
|
@function getMaxHolyPower |
|
18 |
|
@treturn number positive integer |
|
19 |
|
]] |
|
20 |
|
local function getMaxHolyPower() |
|
21 |
|
return 3 |
|
22 |
|
end |
|
23 |
|
|
|
24 |
|
--[[-- |
|
25 |
|
Process reaction to UNIT_AURA event for aura indicator. |
|
26 |
|
When aura disappears from the unit associated with this button, |
|
27 |
|
hide the button. Show it otherwise. |
|
28 |
|
@function acceptUnitAura |
|
29 |
|
@tparam button frame this button frame to update |
|
30 |
|
@tparam string eventCategory given event category designation |
|
31 |
|
@return nothing |
|
32 |
|
]] |
5 |
33 |
local function acceptUnitAura(button, eventCategory) |
local function acceptUnitAura(button, eventCategory) |
6 |
34 |
assert (button ~= nil) |
assert (button ~= nil) |
7 |
35 |
assert (eventCategory ~= nil) |
assert (eventCategory ~= nil) |
|
36 |
|
assert ('string' == type(eventCategory)) |
|
37 |
|
assert (string.len(eventCategory) >= 2) |
|
38 |
|
assert (string.len(eventCategory) <= 256) |
8 |
39 |
|
|
9 |
40 |
local auraName = button.spell |
local auraName = button.spell |
10 |
41 |
assert (auraName ~= nil) |
assert (auraName ~= nil) |
|
42 |
|
assert ('string' == type(auraName)) |
|
43 |
|
assert (string.len(auraName) >= 2) |
|
44 |
|
assert (string.len(auraName) <= 256) |
11 |
45 |
|
|
12 |
46 |
local unitDesignation = button.unit |
local unitDesignation = button.unit |
13 |
47 |
assert (unitDesignation ~= nil) |
assert (unitDesignation ~= nil) |
|
48 |
|
assert ('string' == type(unitDesignation)) |
|
49 |
|
assert (string.len(unitDesignation) >= 2) |
|
50 |
|
assert (string.len(unitDesignation) <= 256) |
14 |
51 |
|
|
15 |
52 |
local name, _, icon = UnitBuff(unitDesignation, auraName) |
local name, _, icon = UnitBuff(unitDesignation, auraName) |
16 |
53 |
if name then |
if name then |
|
... |
... |
local function acceptUnitAura(button, eventCategory) |
22 |
59 |
end |
end |
23 |
60 |
end |
end |
24 |
61 |
|
|
25 |
|
local function applyUpdate(button, updateDuration) |
|
|
62 |
|
--[[-- |
|
63 |
|
Process timer tick to update remaining aura duration. |
|
64 |
|
@function applyUpdate |
|
65 |
|
@tparam frame button to update |
|
66 |
|
@return nothing |
|
67 |
|
]] |
|
68 |
|
local function applyUpdate(button) |
26 |
69 |
assert (button ~= nil) |
assert (button ~= nil) |
27 |
70 |
|
|
28 |
71 |
local auraName = button.spell |
local auraName = button.spell |
29 |
72 |
assert (auraName ~= nil) |
assert (auraName ~= nil) |
|
73 |
|
assert ('string' == type(auraName)) |
|
74 |
|
assert (string.len(auraName) >= 2) |
|
75 |
|
assert (string.len(auraName) <= 256) |
30 |
76 |
|
|
31 |
77 |
local unitDesignation = button.unit |
local unitDesignation = button.unit |
32 |
78 |
assert (unitDesignation ~= nil) |
assert (unitDesignation ~= nil) |
|
79 |
|
assert ('string' == type(unitDesignation)) |
|
80 |
|
assert (string.len(unitDesignation) >= 2) |
|
81 |
|
assert (string.len(unitDesignation) <= 256) |
33 |
82 |
|
|
34 |
|
local name, _, _, _, _, duration, expirationInstance = UnitBuff(unitDesignation, auraName) |
|
35 |
|
local now = GetTime() |
|
|
83 |
|
local _, _, _, _, _, _, expirationInstance = UnitBuff(unitDesignation, auraName) |
36 |
84 |
if nil == expirationInstance then |
if nil == expirationInstance then |
37 |
85 |
return |
return |
38 |
86 |
end |
end |
|
87 |
|
local now = GetTime() |
39 |
88 |
local remainingDuration = math.ceil(expirationInstance - now) |
local remainingDuration = math.ceil(expirationInstance - now) |
40 |
89 |
button:SetText(remainingDuration) |
button:SetText(remainingDuration) |
41 |
90 |
end |
end |
42 |
91 |
|
|
|
92 |
|
--[[-- |
|
93 |
|
Produce frame that tracks and displays given unit holy power. |
|
94 |
|
The new frame possesses custom attribute "unit". |
|
95 |
|
@function createHolyPowerIndicator |
|
96 |
|
@tparam string frameName conventionally unique frame desgination |
|
97 |
|
@tparam frame parentFrame parent frame |
|
98 |
|
@tparam string unitDesignation associated unit designation |
|
99 |
|
@treturn frame newly allocated frame |
|
100 |
|
]] |
43 |
101 |
local function createHolyPowerIndicator(frameName, parentFrame, unitDesignation) |
local function createHolyPowerIndicator(frameName, parentFrame, unitDesignation) |
44 |
102 |
assert (parentFrame ~= nil) |
assert (parentFrame ~= nil) |
45 |
|
assert (unitDesignation ~= nil) |
|
46 |
103 |
|
|
|
104 |
|
assert (unitDesignation ~= nil) |
|
105 |
|
assert ('string' == type(unitDesignation)) |
|
106 |
|
assert (string.len(unitDesignation) >= 2) |
|
107 |
|
assert (string.len(unitDesignation) <= 256) |
47 |
108 |
|
|
48 |
109 |
local f = CreateFrame('FRAME', frameName, parentFrame) |
local f = CreateFrame('FRAME', frameName, parentFrame) |
49 |
110 |
f.unit = unitDesignation |
f.unit = unitDesignation |
|
... |
... |
local function createHolyPowerIndicator(frameName, parentFrame, unitDesignation) |
51 |
112 |
local t = {} |
local t = {} |
52 |
113 |
local q = 0 |
local q = 0 |
53 |
114 |
local x = 0 |
local x = 0 |
54 |
|
local y = 0 |
|
55 |
|
local margin = 0 |
|
56 |
|
while (q < 5) do |
|
|
115 |
|
local maxQuantity = getMaxHolyPower() |
|
116 |
|
while (q < maxQuantity) do |
57 |
117 |
q = q + 1 |
q = q + 1 |
58 |
118 |
local p = f:CreateTexture(frameName .. tostring(q), 'OVERLAY') |
local p = f:CreateTexture(frameName .. tostring(q), 'OVERLAY') |
59 |
119 |
p:SetTexture(255 / 255, 204 / 255, 0 / 255, 1) |
p:SetTexture(255 / 255, 204 / 255, 0 / 255, 1) |
60 |
120 |
p:SetSize(24, 24) |
p:SetSize(24, 24) |
61 |
|
p:SetPoint('BOTTOMLEFT', margin + x * 28, y * 28) |
|
|
121 |
|
p:SetPoint('BOTTOMLEFT', x * 28, 0) |
62 |
122 |
p:Hide() |
p:Hide() |
63 |
123 |
x = x + 1 |
x = x + 1 |
64 |
|
if x >= 3 then |
|
65 |
|
x = 0 |
|
66 |
|
y = y + 1 |
|
67 |
|
margin = margin + 14 |
|
68 |
|
end |
|
69 |
124 |
t[q] = p |
t[q] = p |
70 |
125 |
end |
end |
71 |
126 |
f.children = t |
f.children = t |
72 |
127 |
|
|
73 |
128 |
f:RegisterEvent('UNIT_POWER_FREQUENT') |
f:RegisterEvent('UNIT_POWER_FREQUENT') |
74 |
|
f:SetScript('OnEvent', function(self) |
|
75 |
|
local t = self.children |
|
|
129 |
|
f:SetScript('OnEvent', function() |
76 |
130 |
local i = 0 |
local i = 0 |
77 |
|
local hppq = UnitPower(self.unit, SPELL_POWER_HOLY_POWER) |
|
78 |
|
while (i < 5) do |
|
|
131 |
|
local hppq = UnitPower(unitDesignation, SPELL_POWER_HOLY_POWER) |
|
132 |
|
while (i < maxQuantity) do |
79 |
133 |
i = i + 1 |
i = i + 1 |
80 |
134 |
local p = t[i] |
local p = t[i] |
81 |
135 |
if i <= hppq then |
if i <= hppq then |
|
... |
... |
local function createHolyPowerIndicator(frameName, parentFrame, unitDesignation) |
89 |
143 |
end |
end |
90 |
144 |
|
|
91 |
145 |
--[[-- |
--[[-- |
|
146 |
|
Allocate button frame that represents a single aura |
|
147 |
|
New button has two custom fields: unit and spell. |
|
148 |
|
that is potentially applied to the player character. |
92 |
149 |
@function createButton |
@function createButton |
93 |
|
@param buttonName string |
|
94 |
|
@param parentFrame |
|
95 |
|
@param localizedSpellName string |
|
96 |
|
@return button frame |
|
97 |
|
@treturn spell string |
|
98 |
|
@treturn unit string |
|
|
150 |
|
@tparam string buttonName |
|
151 |
|
@tparam frame parentFrame |
|
152 |
|
@tparam string localizedSpellName aura name to track |
|
153 |
|
@treturn frame newly allocated button frame instance |
99 |
154 |
]] |
]] |
100 |
155 |
local function createButton(buttonName, parentFrame, localizedSpellName) |
local function createButton(buttonName, parentFrame, localizedSpellName) |
101 |
156 |
assert (buttonName ~= nil) |
assert (buttonName ~= nil) |
|
... |
... |
local function createButton(buttonName, parentFrame, localizedSpellName) |
133 |
188 |
return button |
return button |
134 |
189 |
end |
end |
135 |
190 |
|
|
|
191 |
|
--[[-- |
|
192 |
|
When variables loaded then create and configure all required frames. |
|
193 |
|
Must only be executed once per script lifetime. |
|
194 |
|
@function init |
|
195 |
|
@tparam frame rootFrame |
|
196 |
|
@treturn frame updated given root frame |
|
197 |
|
]] |
136 |
198 |
local function init(rootFrame) |
local function init(rootFrame) |
137 |
199 |
assert (rootFrame ~= nil) |
assert (rootFrame ~= nil) |
138 |
200 |
|
|
|
... |
... |
local function init(rootFrame) |
141 |
203 |
'CENTER', 0, 0) |
'CENTER', 0, 0) |
142 |
204 |
|
|
143 |
205 |
local hpf = createHolyPowerIndicator('DaybreakHolyPowerPlayerFrame', rootFrame, 'player') |
local hpf = createHolyPowerIndicator('DaybreakHolyPowerPlayerFrame', rootFrame, 'player') |
144 |
|
hpf:SetPoint('CENTER', 0, -128) |
|
|
206 |
|
hpf:SetPoint('CENTER', 0, 0) |
|
207 |
|
hpf:SetPoint('BOTTOM', 0, 0) |
145 |
208 |
|
|
146 |
209 |
local padding = 8 |
local padding = 8 |
147 |
210 |
local size = getDefaultButtonSize() + padding |
local size = getDefaultButtonSize() + padding |
|
... |
... |
local function init(rootFrame) |
189 |
252 |
return rootFrame |
return rootFrame |
190 |
253 |
end |
end |
191 |
254 |
|
|
|
255 |
|
--[[-- |
|
256 |
|
Daybreak script entry point. |
|
257 |
|
Must only be executed once per script life time. |
|
258 |
|
@function main |
|
259 |
|
]] |
192 |
260 |
local function main() |
local function main() |
193 |
261 |
local rootFrame = CreateFrame('FRAME', 'DaybreakFrame', UIParent) |
local rootFrame = CreateFrame('FRAME', 'DaybreakFrame', UIParent) |
194 |
262 |
rootFrame:SetScript('OnEvent', init) |
rootFrame:SetScript('OnEvent', init) |