forked from AdiAddons/AdiButtonAuras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplay.lua
243 lines (213 loc) · 6.76 KB
/
Display.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
--[[
AdiButtonAuras - Display auras on action buttons.
Copyright 2013 Adirelle ([email protected])
All rights reserved.
This file is part of AdiButtonAuras.
AdiButtonAuras is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
AdiButtonAuras is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with AdiButtonAuras. If not, see <http://www.gnu.org/licenses/>.
--]]
local addonName, addon = ...
local AceTimer = LibStub('AceTimer-3.0')
local _G = _G
local CreateFrame = _G.CreateFrame
local floor = _G.floor
local GetTime = _G.GetTime
local next = _G.next
local pairs = _G.pairs
local tonumber = _G.tonumber
local fontFile, fontSize, fontFlag = [[Fonts\ARIALN.TTF]], 13, "OUTLINE"
local overlayPrototype = addon.overlayPrototype
local function Timer_Update(self)
local timeLeft = (self.expiration or 0) - GetTime()
local r, g, b, delay = 1, 1, 1
if timeLeft >= 3600 then
self:SetFormattedText("%dh", floor(timeLeft/3600))
delay = timeLeft % 3600
elseif timeLeft >= 600 then
self:SetFormattedText("%dm", floor(timeLeft/60))
delay = timeLeft % 60
elseif timeLeft >= 60 then
self:SetFormattedText("%d:%02d", floor(timeLeft/60), floor(timeLeft%60))
delay = timeLeft % 1
elseif timeLeft >= 3 then
self:SetFormattedText("%d", floor(timeLeft))
delay = timeLeft % 1
if timeLeft <= 10 then
r, g, b = 1, 1, (timeLeft - 3) / 7
end
elseif timeLeft > 0 then
self:SetFormattedText("%.1f", floor(timeLeft*10)/10)
delay = timeLeft % 0.1
r, g, b = 1, 0.5 + timeLeft / 6, 0
else
if self.timerId then
AceTimer:CancelTimer(self.timerId)
self.timerId = nil
end
self:Hide()
return
end
self:SetTextColor(r, g, b, 1)
self.timerId = AceTimer.ScheduleTimer(self, "Update", delay)
self:Show()
end
local function Text_OnShowHide(text)
text:GetParent():LayoutTexts()
end
function overlayPrototype:InitializeDisplay()
self:SetFrameLevel(self.button.cooldown:GetFrameLevel()+1)
self.parentCount = _G[self.button:GetName().."Count"]
local border = self:CreateTexture(self:GetName().."Border", "BACKGROUND", NumberFontNormalSmall)
border:Hide()
self.Border = border
local timer = self:CreateFontString(self:GetName().."Timer", "OVERLAY")
timer:SetFont(fontFile, fontSize, fontFlag)
timer:SetPoint("BOTTOMLEFT", 2, 2)
timer:SetPoint("BOTTOMRIGHT", -2, 2)
timer:SetJustifyV("BOTTOM")
timer.Update = Timer_Update
timer:Hide()
hooksecurefunc(timer, "Show", Text_OnShowHide)
hooksecurefunc(timer, "Hide", Text_OnShowHide)
self.Timer = timer
local count = self:CreateFontString(self:GetName().."Count", "OVERLAY")
count:SetFont(fontFile, fontSize, fontFlag)
count:SetPoint("BOTTOMLEFT", 2, 2)
count:SetPoint("BOTTOMRIGHT", -2, 2)
count:SetJustifyV("BOTTOM")
count:Hide()
hooksecurefunc(count, "Show", Text_OnShowHide)
hooksecurefunc(count, "Hide", Text_OnShowHide)
self.Count = count
end
function overlayPrototype:LayoutTexts()
local count, timer = self.Count, self.Timer
local parentCount = self.parentCount
local parentCountIsShown = parentCount:IsShown() and strtrim(parentCount:GetText() or "") ~= ""
timer:SetJustifyH((count:IsShown() or parentCountIsShown) and "LEFT" or "CENTER")
count:SetJustifyH(timer:IsShown() and "RIGHT" or "CENTER")
end
function overlayPrototype:SetExpiration(expiration)
if type(expiration) ~= "number" or expiration <= GetTime() then
expiration = nil
end
if self.expiration ~= expiration then
self.expiration = expiration
self.Timer.expiration = expiration
self.Timer:Update()
end
end
function overlayPrototype:SetCount(count)
count = tonumber(count)
if count == 0 then count = nil end
if self.count == count then return end
self.count = count
self.Count:SetShown(count)
if count then
self.Count:SetFormattedText("%d", count)
end
end
function overlayPrototype:SetHighlight(highlight)
if self.highlight == highlight then return end
self.highlight = highlight
if highlight == "flash" then
self:ShowOverlayGlow()
else
self:HideOverlayGlow()
end
local border = self.Border
if highlight == "darken" or highlight == "lighten" then
if border:GetTexture() ~= "Color-666666ff" then
border:SetAllPoints(self)
border:SetTexture(0.4, 0.4, 0.4, 1)
border:SetVertexColor(1, 1, 1, 1)
end
border:SetBlendMode(highlight == "darken" and "MOD" or "ADD")
border:Show()
elseif highlight == "good" or highlight == "bad" then
if border:GetTexture() ~= [[Interface\Buttons\UI-ActionButton-Border]] then
border:ClearAllPoints()
border:SetPoint("CENTER", self)
border:SetSize(62, 62)
border:SetTexture([[Interface\Buttons\UI-ActionButton-Border]])
border:SetBlendMode("ADD")
end
if highlight == "good" then
border:SetVertexColor(0, 1, 0, 1)
else
border:SetVertexColor(1, 0, 0, 1)
end
border:Show()
else
border:Hide()
end
end
do
local serial = 1
local heap = {}
local OnHide, AnimOutFinished
local function CreateOverlayGlow()
serial = serial + 1
local overlay = CreateFrame("Frame", addonName.."ButtonOverlay"..serial, UIParent, "ActionBarButtonSpellActivationAlert")
overlay.animOut:SetScript("OnFinished", AnimOutFinished)
overlay:SetScript("OnHide", OnHide)
return overlay
end
function AnimOutFinished(animGroup)
local overlay = animGroup:GetParent()
overlay:Hide()
overlay:ClearAllPoints()
overlay:SetParent(nil)
overlay.state.overlay = nil
overlay.state = nil
tinsert(heap, overlay)
end
function OnHide(button)
if button.animOut:IsPlaying() then
button.animOut:Stop()
return AnimOutFinished(button.animOut)
end
end
function overlayPrototype:ShowOverlayGlow()
local overlay = self.overlay
if overlay then
if overlay.animOut:IsPlaying() then
overlay.animOut:Stop()
overlay.animIn:Play()
end
else
overlay = tremove(heap) or CreateOverlayGlow()
local button = self.button
local width, height = button:GetSize()
overlay:SetParent(button)
overlay:ClearAllPoints()
overlay:SetSize(width * 1.4, height * 1.4)
overlay:SetPoint("TOPLEFT", button, "TOPLEFT", -width * 0.2, height * 0.2)
overlay:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", width * 0.2, -height * 0.2)
overlay:Show()
overlay.animIn:Play()
overlay.state, self.overlay = self, overlay
end
end
function overlayPrototype:HideOverlayGlow()
local overlay = self.overlay
if overlay then
if overlay.animIn:IsPlaying() then
overlay.animIn:Stop()
end
if overlay:IsVisible() then
overlay.animOut:Play()
else
AnimOutFinished(overlay.animOut)
end
end
end
end