File src/ChorusAuraButtonTemplate.lua changed (mode: 100644) (index 591de11..f8a7e8e) |
... |
... |
local function formatDuration(durationSec) |
86 |
86 |
assert('number' == type(durationSec)) |
assert('number' == type(durationSec)) |
87 |
87 |
|
|
88 |
88 |
local t |
local t |
89 |
|
if durationSec < 60 then |
|
|
89 |
|
local durationSecAbs = math.abs(durationSec) |
|
90 |
|
if durationSecAbs < 60 then |
90 |
91 |
t = string.format("%.0f", durationSec) |
t = string.format("%.0f", durationSec) |
91 |
|
elseif durationSec < 3600 then |
|
|
92 |
|
elseif durationSecAbs < 3600 then |
92 |
93 |
t = string.format("%.0f m", durationSec / 60) |
t = string.format("%.0f m", durationSec / 60) |
93 |
|
elseif durationSec < 3600 * 24 then |
|
|
94 |
|
elseif durationSecAbs < 3600 * 24 then |
94 |
95 |
t = string.format("%.0f h", durationSec / 60 / 60) |
t = string.format("%.0f h", durationSec / 60 / 60) |
95 |
96 |
else |
else |
96 |
97 |
t = string.format("%.0f d", durationSec / 60 / 60 / 24) |
t = string.format("%.0f d", durationSec / 60 / 60 / 24) |
|
... |
... |
local function applyDuration(auraButton, now, totalDurationSec, expirationInstan |
121 |
122 |
durationRemainingSec = expirationInstance - now |
durationRemainingSec = expirationInstance - now |
122 |
123 |
end |
end |
123 |
124 |
|
|
124 |
|
local t = nil |
|
|
125 |
|
local t |
125 |
126 |
if durationRemainingSec then |
if durationRemainingSec then |
126 |
127 |
t = formatDuration(durationRemainingSec) |
t = formatDuration(durationRemainingSec) |
|
128 |
|
else |
|
129 |
|
--[[ The aura button text is color coded to report if the owner |
|
130 |
|
of the aura is the user or another player. Therefore, the |
|
131 |
|
label should never be empty. ]]-- |
|
132 |
|
t = '∞' |
127 |
133 |
end |
end |
128 |
134 |
|
|
129 |
135 |
label:SetText(t) |
label:SetText(t) |
|
... |
... |
local function applyDuration(auraButton, now, totalDurationSec, expirationInstan |
136 |
142 |
end |
end |
137 |
143 |
end |
end |
138 |
144 |
|
|
|
145 |
|
local function applyChargeQuantity(auraButton, chargeQuantity) |
|
146 |
|
auraButtonValidate(auraButton) |
|
147 |
|
|
|
148 |
|
local label = auraButton.label2 |
|
149 |
|
assert (label ~= nil) |
|
150 |
|
|
|
151 |
|
local t = nil |
|
152 |
|
if chargeQuantity then |
|
153 |
|
assert(chargeQuantity ~= nil) |
|
154 |
|
assert('number' == type(chargeQuantity)) |
|
155 |
|
chargeQuantity = math.abs(math.floor(chargeQuantity)) |
|
156 |
|
if chargeQuantity < 2 then |
|
157 |
|
t = nil |
|
158 |
|
elseif chargeQuantity < 100 then |
|
159 |
|
t = string.format('%d', chargeQuantity) |
|
160 |
|
else |
|
161 |
|
t = '>99' |
|
162 |
|
end |
|
163 |
|
end |
|
164 |
|
label:SetText(t) |
|
165 |
|
end |
|
166 |
|
|
139 |
167 |
local function auraButtonUpdateProcessor(self) |
local function auraButtonUpdateProcessor(self) |
140 |
168 |
local unitDesignation = SecureButton_GetUnit(self) |
local unitDesignation = SecureButton_GetUnit(self) |
141 |
169 |
local index = self.index |
local index = self.index |
|
... |
... |
local function auraButtonUpdateProcessor(self) |
143 |
171 |
if not unitDesignation or not index then |
if not unitDesignation or not index then |
144 |
172 |
return |
return |
145 |
173 |
end |
end |
146 |
|
local name, _, _, _, _, durationSec, expirationInstance = UnitAura(unitDesignation, index, filter) |
|
|
174 |
|
local name, _, _, chargeQuantity, _, durationSec, expirationInstance = UnitAura(unitDesignation, index, filter) |
147 |
175 |
if not name then |
if not name then |
148 |
176 |
return |
return |
149 |
177 |
end |
end |
150 |
178 |
applyDuration(self, GetTime(), durationSec, expirationInstance) |
applyDuration(self, GetTime(), durationSec, expirationInstance) |
|
179 |
|
applyChargeQuantity(self, chargeQuantity) |
151 |
180 |
end |
end |
152 |
181 |
|
|
153 |
182 |
local function apply(auraButton, unitDesignation, auraIndex, filter) |
local function apply(auraButton, unitDesignation, auraIndex, filter) |
|
... |
... |
local function apply(auraButton, unitDesignation, auraIndex, filter) |
176 |
205 |
return |
return |
177 |
206 |
end |
end |
178 |
207 |
|
|
179 |
|
local name, _, artworkFile, _, category, durationSec, expirationInstance, |
|
|
208 |
|
local name, _, artworkFile, chargeQuantity, category, durationSec, expirationInstance, |
180 |
209 |
owner = UnitAura(unitDesignation, auraIndex, filter) |
owner = UnitAura(unitDesignation, auraIndex, filter) |
181 |
210 |
if name then |
if name then |
182 |
211 |
auraButton:Show() |
auraButton:Show() |
|
... |
... |
local function apply(auraButton, unitDesignation, auraIndex, filter) |
190 |
219 |
applyArtwork(auraButton, artworkFile) |
applyArtwork(auraButton, artworkFile) |
191 |
220 |
applyDuration(auraButton, GetTime(), durationSec, expirationInstance) |
applyDuration(auraButton, GetTime(), durationSec, expirationInstance) |
192 |
221 |
applyOverlay(auraButton, category, owner) |
applyOverlay(auraButton, category, owner) |
|
222 |
|
applyChargeQuantity(auraButton, chargeQuantity) |
193 |
223 |
end |
end |
194 |
224 |
|
|
195 |
225 |
local function auraButtonEventProcessor(self, eventCategory, ...) |
local function auraButtonEventProcessor(self, eventCategory, ...) |
|
... |
... |
function Chorus.auraButtonMain(self) |
257 |
287 |
local n = self:GetName() |
local n = self:GetName() |
258 |
288 |
if n then |
if n then |
259 |
289 |
self.artwork = _G[n .. 'Artwork'] |
self.artwork = _G[n .. 'Artwork'] |
260 |
|
self.label = _G[n .. 'Text'] |
|
|
290 |
|
self.label = _G[n .. 'Text1'] |
|
291 |
|
self.label2 = _G[n .. 'Text2'] |
261 |
292 |
self.overlay = _G[n .. 'Overlay'] |
self.overlay = _G[n .. 'Overlay'] |
262 |
293 |
end |
end |
263 |
294 |
self:SetScript('OnEvent', auraButtonEventProcessor) |
self:SetScript('OnEvent', auraButtonEventProcessor) |