-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.lua
326 lines (266 loc) · 7.41 KB
/
lib.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
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
314
315
316
317
318
319
320
321
322
323
324
325
326
local ADDON_NAME, ns = ...
if(freebDebug) then
ns.Debug = function(...)
freebDebug:Stuff(ADDON_NAME, ...)
end
else
ns.Debug = function() end
end
ns.mediapath = 'Interface\\AddOns\\'..ADDON_NAME..'\\media\\'
ns.statusbar = ns.mediapath..'statusbar'
ns.font = ns.mediapath..'font.ttf'
--ns.font = [[Interface\Addons\SharedMedia\fonts\deja_vu\DejaVuLGCSans.ttf]]
ns.FreebFont = CreateFont'FreebFont'
ns.FreebFont:SetFont(ns.font, 12, 'THINOUTLINE')
ns.FreebFont:SetShadowOffset(1, -1)
ns.FreebFont:SetTextColor(1, 1, 1)
ns.FreebFontSmall = CreateFont'FreebFontSmall'
ns.FreebFontSmall:SetFont(ns.font, 10, 'THINOUTLINE')
ns.FreebFontSmall:SetShadowOffset(1, -1)
ns.FreebFontSmall:SetTextColor(1, 1, 1)
ns.FreebFontLarge = CreateFont'FreebFontLarge'
ns.FreebFontLarge:SetFont(ns.font, 16, 'THINOUTLINE')
ns.FreebFontLarge:SetShadowOffset(1, -1)
ns.FreebFontLarge:SetTextColor(1, 1, 1)
ns.colors = setmetatable({
power = setmetatable({
['MANA'] = {.41, .55, .73}
}, {__index = oUF.colors.power}),
}, {__index = oUF.colors})
function ns.numberize(val)
if(val >= 1e6) then
return ('%.1fm'):format(val / 1e6)
elseif(val >= 1e3) then
return ('%.0fk'):format(val / 1e3)
else
return ('%d'):format(val)
end
end
function ns.formatTime(val)
if(val > 3600) then
return ('%dh'):format((val / 3600) + 0.5)
elseif(val > 60) then
return ('%dm'):format((val / 60) + 0.5)
else
return ('%.0f'):format(val)
end
end
function ns.multiCheck(check, ...)
for i=1, select('#', ...) do
if(check == select(i, ...)) then return true end
end
return false
end
function ns.unitColor(unit)
local colors
if(UnitPlayerControlled(unit)) then
local _, class = UnitClass(unit)
if(class and UnitIsPlayer(unit)) then
-- Players have color
colors = ns.colors.class[class]
elseif(UnitCanAttack(unit, 'player')) then
-- Hostiles are red
colors = ns.colors.reaction[2]
elseif(UnitCanAttack('player', unit)) then
-- Units we can attack but which are not hostile are yellow
colors = ns.colors.reaction[4]
elseif(UnitIsPVP(unit)) then
-- Units we can assist but are PvP flagged are green
colors = ns.colors.reaction[6]
end
elseif(UnitIsTapDenied(unit, 'player')) then
colors = ns.colors.tapped
end
if(not colors) then
local reaction = UnitReaction(unit, 'player')
colors = reaction and ns.colors.reaction[reaction] or {1,1,1}
end
return colors[1], colors[2], colors[3]
end
do
local glowBorder = {
bgFile = 'Interface\\ChatFrame\\ChatFrameBackground',
edgeFile = ns.mediapath..'glowTex', edgeSize = 3,
insets = {left = 3, right = 3, top = 3, bottom = 3}
}
function ns.createBackdrop(parent, anchor)
local frame = CreateFrame('Frame', nil, parent)
frame:SetFrameStrata('BACKGROUND')
frame:SetPoint('TOPLEFT', anchor or parent, 'TOPLEFT', -3, 3)
frame:SetPoint('BOTTOMRIGHT', anchor or parent, 'BOTTOMRIGHT', 3, -3)
frame:SetBackdrop(glowBorder)
frame:SetBackdropColor(.05, .05, .05, 1)
--frame:SetBackdropColor(.5, .5, .5, 1)
frame:SetBackdropBorderColor(0, 0, 0, 1)
return frame
end
end
do
local bnot, band = bit.bnot, bit.band
local flags = {}
for i=0, 7 do
flags[i] = bit.lshift(1, i)
end
local methods = {
Hide = function(self)
if(not self.__visible) then return end
for i=1,8 do
self[i]:Hide()
end
self.__visible = nil
end,
Show = function(self)
if(self.__visible) then return end
for i=1,8 do
self[i]:Show()
end
self.__visible = true
end,
SetColor = function(self, r, g, b, a)
if(not a) then a = 1 end
if(r == self.__r and g == self.__g and b == self.__b and a == self.__a) then
return
end
for i=1,8 do
self[i]:SetVertexColor(r, g, b, a)
end
self.__r, self.__g, self.__b, self.__a = r, g, b, a
end,
SetParent = function(self, parent)
self.__parent = parent
end,
SetVisible = function(self, left, right, top, bottom)
local mask = 0xff
if(not left) then
mask = mask - flags[0]
mask = band(mask, bnot(flags[1]))
mask = band(mask, bnot(flags[7]))
end
if(not right) then
mask = mask - flags[4]
mask = band(mask, bnot(flags[3]))
mask = band(mask, bnot(flags[5]))
end
if(not top) then
mask = mask - flags[2]
mask = band(mask, bnot(flags[1]))
mask = band(mask, bnot(flags[3]))
end
if(not bottom) then
mask = mask - flags[6]
mask = band(mask, bnot(flags[7]))
mask = band(mask, bnot(flags[5]))
end
for i=0, 7 do
if(band(mask, flags[i]) ~= 0) then
self[i + 1]:Show()
else
self[i + 1]:Hide()
end
end
end,
SetPoint = function(self, point)
point = point or self.__parent
for i=1, 8 do
self[i]:ClearAllPoints()
end
local Left = self[1]
Left:SetPoint('RIGHT', point, 'LEFT')
Left:SetPoint('TOP')
Left:SetPoint('BOTTOM')
Left:SetWidth(16)
local TopLeft = self[2]
TopLeft:SetPoint('BOTTOMRIGHT', point, 'TOPLEFT')
TopLeft:SetSize(16, 16)
local Top = self[3]
Top:SetPoint('BOTTOM', point, 'TOP')
Top:SetPoint('LEFT')
Top:SetPoint('RIGHT')
Top:SetHeight(16)
local TopRight = self[4]
TopRight:SetPoint('BOTTOMLEFT', point, 'TOPRIGHT')
TopRight:SetSize(16, 16)
local Right = self[5]
Right:SetPoint('LEFT', point, 'RIGHT')
Right:SetPoint('TOP')
Right:SetPoint('BOTTOM')
Right:SetWidth(16)
local BottomRight = self[6]
BottomRight:SetPoint('TOPLEFT', point, 'BOTTOMRIGHT')
BottomRight:SetSize(16, 16)
local Bottom = self[7]
Bottom:SetPoint('TOP', point, 'BOTTOM')
Bottom:SetPoint('LEFT')
Bottom:SetPoint('RIGHT')
Bottom:SetHeight(16)
local BottomLeft = self[8]
BottomLeft:SetPoint('TOPRIGHT', point, 'BOTTOMLEFT')
BottomLeft:SetSize(16, 16)
end
}
methods.__index = methods
function ns.createBorder(self, texture)
local Border = setmetatable({
__visible = true,
}, methods)
for i=1,8 do
local T = self:CreateTexture(nil, 'BACKGROUND')
T:SetTexture(texture)
Border[i] = T
end
local Left = Border[1]
Left:SetTexCoord(0/8, 1/8, 0/8, 8/8)
local TopLeft = Border[2]
TopLeft:SetTexCoord(6/8, 7/8, 8/8, 0/8)
local Top = Border[3]
Top:SetTexCoord(.5, -.75, .375, -.75, .5, -.625, .375, -.625)
local TopRight = Border[4]
TopRight:SetTexCoord(7/8, 6/8, 8/8, 0/8)
local Right = Border[5]
Right:SetTexCoord(1/8, 0/8, 0/8, 8/8)
local BottomRight = Border[6]
BottomRight:SetTexCoord(5/8, 6/8, 8/8, 0/8)
local Bottom = Border[7]
Bottom:SetTexCoord(.375, 1, .5, 1, .375, 0, .5, 0)
local BottomLeft = Border[8]
BottomLeft:SetTexCoord(6/8, 5/8, 8/8, 0/8)
Border:SetParent(self)
Border:SetPoint()
Border:SetColor(0, 0, 0, 0)
self.Border = Border
return Border
end
end
do
local function Smooth(self, value)
if(value == 0) then value = 0.01 end
if(value == self:GetValue()) then
self.smoothing = nil
else
self.smoothing = value
end
end
local GetFramerate = GetFramerate
local min, max, abs = math.min, math.max, abs
local function SmoothUpdate(self)
local value = self.smoothing
if(not value) then return end
local limit = 30/GetFramerate()
local cur = self:GetValue()
local new = cur + min((value-cur)/3, max(value-cur, limit))
if(new ~= new) then
new = value
end
self:SetValue_(new)
if(cur == value or abs(new - value) < 2) then
self:SetValue_(value)
self.smoothing = nil
end
end
local SetValue = CreateFrame('StatusBar').SetValue
function ns.sbSmooth(statusbar)
statusbar.SetValue_ = SetValue
statusbar.SetValue = Smooth
statusbar:SetScript('OnUpdate', SmoothUpdate)
end
end