forked from tullamods/Dominos_Cast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbar.lua
More file actions
executable file
·313 lines (244 loc) · 6.79 KB
/
bar.lua
File metadata and controls
executable file
·313 lines (244 loc) · 6.79 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
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
local AddonName = ...
local Addon = LibStub('AceAddon-3.0'):GetAddon(GetAddOnDependencies(AddonName))
local LSM = LibStub('LibSharedMedia-3.0', true)
local CastBar = Addon:CreateClass('Frame', Addon.Frame)
--[[ frame creation ]]--
function CastBar:New()
return CastBar.proto.New(self, 'cast')
end
local function check(source, target)
--you may now add new defaults at will. ~Goranaws
if (not target) or (type(target) ~= 'table') then
target = {}
end
for key, value in pairs(source) do
if type(value) == 'table' then
target[key] =check(value, target[key])
else
if (type(value) == 'boolean') then
if target[key] == nil then
target[key] = value
end
else
target[key] = target[key] or value
end
end
end
return target
end
function CastBar:Create(...)
local bar = CastBar.proto.Create(self, ...)
bar.cast = CreateFrame('StatusBar', bar:GetName()..'Bar', bar.header, 'CastingBarFrameTemplate')
bar.cast:Hide()
bar.cast:SetPoint('CENTER')
bar.cast.unit = 'player'
bar.cast:SetAttribute('unit', 'player')
CastingBarFrame_SetLook(bar.cast, 'UNITFRAME')
bar.cast:HookScript('OnUpdate', bar.SetTime)
bar.cast.time = bar.cast:CreateFontString(nil, 'OVERLAY', 'TextStatusBarText')
bar.cast.time:SetTextColor(1, 1, 1)
bar.skin = CreateFrame('Frame', bar:GetName() .. 'Skin', bar.cast)
bar.skin:SetFrameLevel(bar:GetFrameLevel() - 1)
bar.skin:SetPoint('CENTER', bar)
bar.cast.border:SetParent(MainMenuBarArtFrame)
bar.cast.borderShield:SetParent(MainMenuBarArtFrame)
bar.cast.barFlash:SetTexture([[Interface\Cooldown\star4]])
bar.cast.barFlash:SetVertexColor(0, 1, 0, 1)
bar.cast.barFlash:SetBlendMode('ADD')
bar.cast.barFlash:SetAllPoints(bar.skin)
bar:LoadSettings()
bar:Layout()
return bar
end
function CastBar:GetDefaults()
return {
point = 'CENTER',
x = 0,
y = 30,
height = 19,
width = 200,
padding = 3,
hideText = false,
showIcon = true,
inset = 3,
color = { r = 0, g = 0, b = 0, a = 1 },
bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
timeFormat = 'Default',
alignText = 'LEFT',
alignTime = 'RIGHT',
texture = [[Interface\TargetingFrame\UI-StatusBar]],
font = 'Friz Quadrata TT',
textcolor = { r = 1,g = 1,b = 1,a = 1 },
hideDefault = true,
}
end
--[[ update functions ]]--
function CastBar:Layout()
self:UpdateIcon()
self:UpdateSize()
self:UpdateTextures()
self:UpdateBlizzard()
self:UpdateText()
end
function CastBar:UpdateSize()
local pw, ph = self:GetPadding()
local w, h = self.sets.width, self.sets.height
self:SetSize(w + pw, h + ph)
self.skin:SetSize(w, h)
local offset = 0
if self.sets.showIcon then
offset = 19
end
self.cast:SetSize(w-offset, h)
local point = 'RIGHT'
if self.sets.isRightToLeft then
point = 'LEFT'
end
self.cast:ClearAllPoints()
self.cast:SetPoint(point, self.skin)
end
function CastBar:UpdateIcon()
if self.sets.showIcon then
self.cast.icon:Show()
local point = 'LEFT'
if self.sets.isRightToLeft then
point = 'RIGHT'
end
self.cast.icon:ClearAllPoints()
self.cast.icon:SetPoint(point, self.skin)
else
self.cast.icon:Hide()
end
end
function CastBar:UpdateBlizzard()
if self.sets.hideDefault then
CastingBarFrame:SetParent(MainMenuBarArtFrame)
else
CastingBarFrame:SetParent(UIParent)
end
end
function CastBar:UpdateTextures()
self.skin:SetBackdrop({
bgFile = LSM and LSM:Fetch('background', self.sets.bgFile),
insets = {left = -self.sets.inset, right = -self.sets.inset, top = -self.sets.inset, bottom = -self.sets.inset},
tile = false,
})
self.skin:SetBackdropColor(self.sets.color.r, self.sets.color.g, self.sets.color.b, self.sets.color.a)
local castTexture = (LSM and LSM:Fetch('statusbar', self.sets.texture)) or DEFAULT_STATUSBAR_TEXTURE
self.cast:SetStatusBarTexture(castTexture)
end
function CastBar:UpdateText()
local time, text = self.cast.time, self.cast.text
local isLeftToRight = self:GetLeftToRight()
time:ClearAllPoints()
text:ClearAllPoints()
local textAlign = self.sets.alignText
local timeAlign = self.sets.alignTime
if isLeftToRight then
time:SetPoint('RIGHT', self.cast, -2, 0)
text:SetPoint('LEFT', self.cast, 2, 0)
text:SetPoint('RIGHT', time, 'LEFT')
else
time:SetPoint('LEFT', self.cast, 2, 0)
text:SetPoint('RIGHT', self.cast, -2, 0)
text:SetPoint('LEFT', time, 'RIGHT')
if textAlign == 'LEFT' then
textAlign = 'RIGHT'
elseif textAlign == 'RIGHT' then
textAlign = 'LEFT'
end
if timeAlign == 'LEFT' then
timeAlign = 'RIGHT'
elseif timeAlign == 'RIGHT' then
timeAlign = 'LEFT'
end
end
text:SetJustifyH(textAlign)
time:SetJustifyH(timeAlign)
local font = LSM:Fetch('font', self.sets.font)
text:SetFont(font, 12)
time:SetFont(font, 12)
local c = self.sets.textcolor
text:SetTextColor(c.r, c.g, c.b, c.a )
time:SetTextColor(c.r, c.g, c.b, c.a )
if self.sets.hideText then
text:SetAlpha(0)
else
text:SetAlpha(1)
text:Show()
end
if (self.sets.hideTime == true) then
time:SetAlpha(0)
time.hidden = true
else
time:SetAlpha(1)
time.hidden = nil
end
end
function CastBar:SetTime()
self.icon:SetTexCoord(.15,.85,.15,.85)
if self.time.hidden == true then
return
end
local sets = self:GetParent():GetParent().sets
local startTime, endTime = self:GetParent():GetParent():GetSpellcastStartAndEndTimes()
if endTime and (endTime > 0) then
local style = sets.timeFormat
local text
local time = GetTime()
if style == 'Default' then
text = string.format('%.1f', (endTime / 1000) - time)
elseif style == 'Percent' then
text = string.format('%.0f', ((time - (startTime / 1000)) / ((endTime- startTime)/1000))*100)..'%'
elseif style == 'Fraction' then
text = string.format('%.1f', time - (startTime / 1000) )..'/'..string.format('%.1f', (endTime- startTime)/1000)
end
self.time:SetText(text or '')
end
end
function CastBar:GetSpellcastStartAndEndTimes()
if self.cast.casting then
return select(5, UnitCastingInfo('player'))
end
if self.cast.channeling then
return select(5, UnitChannelInfo('player'))
end
end
--[[ bar settings ]]--
function CastBar:SetLeftToRight(isLeftToRight)
local isRightToLeft = not isLeftToRight
self.sets.isRightToLeft = isRightToLeft and true or nil
self:Layout()
end
function CastBar:GetLeftToRight()
return not self.sets.isRightToLeft
end
function CastBar:SetTexture(texture)
self.sets.texture = texture
self:UpdateTextures()
end
function CastBar:GetBarTexture()
return self.sets.texture
end
function CastBar:SetBackground(texture)
self.sets.bgFile = texture
self:UpdateTextures()
end
function CastBar:GetBackground()
return self.sets.bgFile
end
function CastBar:GetFont()
return self.sets.font
end
function CastBar:SetFont(font)
self.sets.font = font
self:Layout()
end
--[[ menu hooks ]]
function CastBar:CreateMenu()
self.menu = Addon:CreateMenu(self)
end
--[[ exports ]]--
Addon.NewCastBar = function(self)
return CastBar:New()
end