This repository was archived by the owner on Mar 15, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.lua
More file actions
291 lines (241 loc) · 8.27 KB
/
lib.lua
File metadata and controls
291 lines (241 loc) · 8.27 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
--[[ oUF_PredatorSimple
This is a layout for the incredibly awesome oUF by haste.
PLEASE NOTE that this layout comes with no warranty and "as it is". It was created to fit my very own
needs, so please understand, that I'll not put any effort in "fixing" something for you, "adding" something
for you or make any changes to this.
Anyway, when you read this, you've already downloaded my layout, so please, feel free to modify it to your
own needs.
]]
local ADDON_NAME, ns = ... -- get the addons namespace to exchange functions between core and layout
local lib = CreateFrame('Frame')
local settings = ns.settings -- get the settings
--[[ FUNCTIONS
Now we're starting with our library-functions.
]]
--[[ Updates the Tooltip on Auras
VOID AuraUpdateTooltip(FRAME self)
]]
local AuraUpdateTooltip = function(self)
GameTooltip:SetUnitAura(self.parent:GetParent().unit, self:GetID(), self.filter)
end
--[[ Shows the Toolttip on Auras
VOID AuraTTOnEnter(FRAME self)
]]
local AuraTTOnEnter = function(self)
if(not self:IsVisible()) then return end
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
self:UpdateTooltip()
end
--[[ Hides the Tooltip on Auras
VOID AuraTTOnLeave()
]]
local AuraTTOnLeave = function()
GameTooltip:Hide()
end
--[[ Debugging to ChatFrame
VOID debugging(STRING text)
]]
lib.debugging = function(text)
DEFAULT_CHAT_FRAME:AddMessage('|cffffd700oUF_PredatorSimple:|r |cffeeeeee'..text..'|r')
end
--[[ Shortening the values displayed on the Health- and Power-Bars
STRING Shorten(INT value)
]]
lib.Shorten = function(value)
if value >= 1e7 then
return ('%.1fm'):format(value / 1e6):gsub('%.?0+([km])$', '%1')
elseif value >= 1e6 then
return ('%.2fm'):format(value / 1e6):gsub('%.?0+([km])$', '%1')
elseif value >= 1e5 then
return ('%.0fk'):format(value / 1e3)
elseif value >= 1e3 then
return ('%.1fk'):format(value / 1e3):gsub('%.?0+([km])$', '%1')
else
return value
end
end
--[[ Evaluates the level of our target
STRING EvalLevel(INT level)
]]
lib.EvalLevel = function(level)
if level < 0 then return '|cffff0000??' end
local difference = level - UnitLevel('player')
if (difference >= 5) then return '|cffff0000'..level
elseif (difference >= 3) then return '|cffff0000'..level
elseif (difference >= -2) then return '|cffffff00'..level
elseif -difference <= GetQuestGreenRange() then return '|cff00cc00'..level
else return '|cffaaaaaa'..level
end
end
--[[ Is a value in a table?
BOOL in_array(MIXED e, TABLE t)
]]
lib.in_array = function(e, t)
-- lib.debugging('entering in_array() with spellID='..e)
for _,v in pairs(t) do
if ( v == e ) then
-- lib.debugging('in_array(): v == e: '..v..'/'..e)
return true
end
end
return false
end
--[[ Collects an aura
VOID collectAura(INT id, STRING name)
]]
lib.collectAura = function(id, name)
PredatorSimpleAuraList[id] = name
end
--[[ Creates a font-object
FONTOBJECT CreateFontObject(FRAME parent, INT size, STRING font)
Creates a font-object with the given 'parent' and 'size', using 'font'. Shadow and Outline are constant throughout the layout.
]]
lib.CreateFontObject = function(parent, size, font)
local fo = parent:CreateFontString(nil, 'OVERLAY')
fo:SetFont(font, size, 'OUTLINE')
fo:SetJustifyH('LEFT')
fo:SetShadowColor(0,0,0)
fo:SetShadowOffset(1, -1)
return fo
end
--[[ Provides the standard UF-menu
VOID Menu(FRAME self)
]]
lib.Menu = function(self)
local unit = self.unit:sub(1, -2)
local cunit = self.unit:gsub('(.)', string.upper, 1)
if(unit == 'party' or unit == 'partypet') then
ToggleDropDownMenu(1, nil, _G['PartyMemberFrame'..self.id..'DropDown'], 'cursor', 0, 0)
elseif(_G[cunit..'FrameDropDown']) then
ToggleDropDownMenu(1, nil, _G[cunit..'FrameDropDown'], 'cursor', 0, 0)
end
end
--[[ Apply a color to the border
VOID SetBorderColor(FRAME self, FLOAT r, FLOAT g, FLOAT b)
]]
lib.SetBorderColor = function(self, r, g, b)
if not self or type(self) ~= "table" then return end
local i
if not self.borderTextures then
lib.CreateBorder(self)
end
if not r then
r, g, b = 0.5, 0.5, 0.5
end
for i, tex in ipairs(self.borderTextures) do
tex:SetVertexColor(r, g, b)
end
end
--[[ Creates the borders for our frames
VOID CreateBorder (FRAME frame, INT size)
]]
lib.CreateBorder = function(frame, size)
if not frame or type(frame) ~= "table" or frame.borderTextures then return end
if not size then size = settings.options.bordersize end
local i
frame.borderTextures = { }
-- creating the textures
local tex = frame.borderTextures
for i = 1, 8 do
tex[i] = frame:CreateTexture(nil, 'ARTWORK')
tex[i]:SetTexture(settings.src.textures.bordertexture)
tex[i]:SetWidth(size)
tex[i]:SetHeight(size)
end
local x = size / 2 - 6
tex[1].id = "TOPLEFT"
tex[1]:SetTexCoord(0, 1/3, 0, 1/3)
tex[1]:SetPoint("TOPLEFT", frame, -5 - x, 5 + x)
tex[2].id = "TOPRIGHT"
tex[2]:SetTexCoord(2/3, 1, 0, 1/3)
tex[2]:SetPoint("TOPRIGHT", frame, 5 + x, 5 + x)
tex[3].id = "TOP"
tex[3]:SetTexCoord(1/3, 2/3, 0, 1/3)
tex[3]:SetPoint("TOPLEFT", tex[1], "TOPRIGHT")
tex[3]:SetPoint("TOPRIGHT", tex[2], "TOPLEFT")
tex[4].id = "BOTTOMLEFT"
tex[4]:SetTexCoord(0, 1/3, 2/3, 1)
tex[4]:SetPoint("BOTTOMLEFT", frame, -5 - x, -5 - x)
tex[5].id = "BOTTOMRIGHT"
tex[5]:SetTexCoord(2/3, 1, 2/3, 1)
tex[5]:SetPoint("BOTTOMRIGHT", frame, 5 + x, -5 - x)
tex[6].id = "BOTTOM"
tex[6]:SetTexCoord(1/3, 2/3, 2/3, 1)
tex[6]:SetPoint("BOTTOMLEFT", tex[4], "BOTTOMRIGHT")
tex[6]:SetPoint("BOTTOMRIGHT", tex[5], "BOTTOMLEFT")
tex[7].id = "LEFT"
tex[7]:SetTexCoord(0, 1/3, 1/3, 2/3)
tex[7]:SetPoint("TOPLEFT", tex[1], "BOTTOMLEFT")
tex[7]:SetPoint("BOTTOMLEFT", tex[4], "TOPLEFT")
tex[8].id = "RIGHT"
tex[8]:SetTexCoord(2/3, 1, 1/3, 2/3)
tex[8]:SetPoint("TOPRIGHT", tex[2], "BOTTOMRIGHT")
tex[8]:SetPoint("BOTTOMRIGHT", tex[5], "TOPRIGHT")
lib.SetBorderColor(frame, 0.5, 0.5, 0.5)
frame.SetBorderColor = lib.SetBorderColor
end
--[[ Creates a single buff-/debuff-icon
FRAME CreateAuraIcon(FRAME icons, INT index)
]]
lib.CreateAuraIcon = function(icons, index)
local button = CreateFrame('Frame', nil, icons)
button:SetWidth(icons.size or 16)
button:SetHeight(icons.size or 16)
local icon = button:CreateTexture(nil, 'BACKGROUND')
icon:SetAllPoints(button)
button.icon = icon
local count = button:CreateFontString(nil, 'OVERLAY')
count:SetFontObject(NumberFontNormal)
count:SetPoint('BOTTOMRIGHT', button, 'BOTTOMRIGHT', -1, 0)
button.count = count
local overlay = button:CreateTexture(nil, 'OVERLAY')
button.overlay = overlay
local cd = CreateFrame('Cooldown', nil, button)
cd:SetAllPoints(button)
button.cd = cd
button.UpdateTooltip = AuraUpdateTooltip
button:SetScript("OnEnter", AuraTTOnEnter)
button:SetScript("OnLeave", AuraTTOnLeave)
table.insert(icons, button)
lib.CreateBorder(button, 10)
button.parent = icons
return button
end
--[[ Providing blacklisting. Returns "false" if the ID is found.
BOOL FilterBlacklist(INT spellID, TABLE filterSRC)
]]
lib.FilterBlacklist = function(spellID, list)
if ( #list ~= 0 ) then
if ( lib.in_array(spellID, list) ) then
return false
end
end
return true
end
--[[ Providing whitelisting. Returns "true" if the ID is found.
BOOL FilterWhitelist(INT spellID, TABLE filterSRC)
]]
lib.FilterWhitelist = function(spellID, list)
-- lib.debugging('entering FilterWhitelist() with spellID='..spellID)
if ( #list ~= 0 ) then
if ( lib.in_array(spellID, list) ) then
return true
end
end
return false
end
--[[ Generic filter-function (distinction between blacklist and whitelist)
BOOL FilterGeneric(INT spellID, TABLE filterSRC)
]]
lib.FilterGeneric = function(spellID, name, filterSRC, icon, caster)
-- lib.debugging('entering FilterGeneric() with spellID='..spellID..' ('..name..')')
lib.collectAura(spellID, name)
icon.caster = caster
if (filterSRC.mode == 'blacklist') then
return lib.FilterBlacklist(spellID, filterSRC.list)
else
return lib.FilterWhitelist(spellID, filterSRC.list)
end
end
-- ************************************************************************************************
ns.lib = lib -- handover of the core-functions to the namespace