This repository has been 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
/
lib.lua
278 lines (239 loc) · 8.04 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
--[[ Buffology is a World of Warcraft-addon by Mischback.
This is lib.lua, where general functions are implemented.
##### FUNCTIONS #####
VOID debugging(STRING text) - prints a message to the chat-frame
VOID TTOnEnter() - updates the tooltip on hover
VOID TTOnLeave() - hides the tooltip on leave
VOID collectAura(INT id, STRING name) - collects the aura
FONTOBJECT CreateFontObject(FRAME parent, INT size, STRING font) - Creates a font-object
STRING TimeFormat(FLOAT left) - Formats a timestring
VOID SetUpFrames(TABLE frames, FRAME parent) - Creates the buff-frames
STRING FindDisplayFrame(BUTTON icon) - Finds the name of the frame, an icon should be attached to
FRAME CreateIcon(INT id) - Creates an aura-icon
VOID UpdateAuraTime(FRAME self, INT elapsed) - Updates the time of an icon
]]
local ADDON_NAME, ns = ... -- get the addons namespace to exchange functions between core and layout
local settings = ns.settings -- get the settings
local strings = ns.strings -- get the localization
local lib = CreateFrame('Frame') -- create the lib
-- *****************************************************
lib.LBF = nil -- ButtonFacade support START
if (IsAddOnLoaded('ButtonFacade')) then -- *
lib.LBF = LibStub("LibButtonFacade") -- *
if ( lib.LBF ) then -- *
lib.facadegroup = lib.LBF:Group('Buffology', 'Buffs/Debuffs')
lib.facadegroup:Skin(settings.facade.groups['Buffs/Debuffs'].skin, settings.facade.groups['Buffs/Debuffs'].gloss, settings.facade.groups['Buffs/Debuffs'].backdrop, settings.facade.groups['Buffs/Debuffs'].colors)
lib.LBF:RegisterSkinCallback('Buffology', function(_, skinID, gloss, backdrop, group, button, colors)
if not group then return end
settings.facade.groups[group].skin = skinID
settings.facade.groups[group].gloss = gloss
settings.facade.groups[group].backdrop = backdrop
settings.facade.groups[group].colors = colors
end, self)
end -- *
end -- *
-- *****************************************************
--[[ Debugging to ChatFrame
VOID debugging(STRING text)
Adds the given 'text' to the ChatFrame1
]]
lib.debugging = function(text)
DEFAULT_CHAT_FRAME:AddMessage('|cffffff00Buffology:|r |cffeeeeee'..text..'|r')
end
--[[
VOID TTOnEnter(BUTTON self)
]]
lib.TTOnEnter = function(self)
if(not self:IsVisible()) then return end
GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
if ( self.isDebuff ) then
GameTooltip:SetUnitAura('player', self:GetID(), 'HARMFUL')
else
GameTooltip:SetUnitAura('player', self:GetID(), 'HELPFUL')
end
end
--[[
VOID TTOnLeave()
]]
lib.TTOnLeave = function()
GameTooltip:Hide()
end
--[[ Collects the aura
VOID CollectAura(INT id, STRING name)
]]
lib.CollectAura = function(id, name)
BuffologyAuraList[id] = name
end
--[[
VOID CancelBuff(BUTTON self)
]]
lib.CancelBuff = function(self)
CancelUnitBuff('player', self:GetID(), nil)
end
--[[ Creates a font-object
FONTOBJECT CreateFontObject(FRAME parent, INT size, STRING font)
]]
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
--[[
]]
lib.TimeFormatDetail = function(left)
local rtime = '00:00'
left = math.floor(left)
if ( left > 59 ) then
local minutes = math.floor(left/60)
local seconds = left-(minutes*60)
if seconds < 10 then seconds = '0'..seconds end
rtime = minutes..':'..seconds
else
local seconds = left
if seconds < 10 then seconds = '0'..seconds end
rtime = '00:'..seconds
end
return rtime
end
--[[
]]
lib.TimeFormatPlain = function(left)
local rtime = ''
left = math.floor(left)
if ( left > 59 ) then
local minutes = math.floor(left/60)
rtime = minutes..'m'
else
rtime = left..'s'
end
return rtime
end
--[[ Formats a float into a time
STRING TimeFormat(FLOAT left)
]]
lib.TimeFormat = function(left)
if ( settings.options.timeFormat == 'plain' ) then
return lib.TimeFormatPlain(left)
else
return lib.TimeFormatDetail(left)
end
end
--[[ Creates the buff-frames
VOID SetUpFrames(TABLE frames, FRAME parent)
]]
lib.SetUpFrames = function(frames, parent)
-- lib.debugging('SetUpFrames()')
for k, v in pairs(frames) do
-- lib.debugging(k)
if ( not parent.framelist[k] ) then
local frame = CreateFrame('Button', k, parent)
frame.icons = 0
frame:SetWidth(settings.static.iconSize+5)
frame:SetHeight(settings.static.iconSize+5)
frame.texture = frame:CreateTexture()
frame.texture:SetAllPoints(frame)
frame.texture:SetTexture(1, 0, 0, 0.7)
frame.caption = lib.CreateFontObject(frame, 12, settings.options.fonts.count)
frame.caption:SetPoint(v['anchorPoint'], frame, v['anchorPoint'], 0, 0)
frame.caption:SetText(k)
frame:SetPoint(v['anchorPoint'], v['relativeTo'], v['relativePoint'], v['xOffset'], v['yOffset'])
frame:Hide()
frame:RegisterForClicks('LeftButtonUp')
parent.framelist[k] = frame
end
end
end
--[[ Finds the name of the frame, an icon should be attached to
STRING FindDisplayFrame(BUTTON icon)
]]
lib.FindDisplayFrame = function(icon)
if ( settings.assignments[tostring(icon.spellID)] ) then
if _G[settings.assignments[tostring(icon.spellID)]] then
return settings.assignments[tostring(icon.spellID)]
elseif (icon.isDebuff) then
return 'Buffology_debuffs'
else
return 'Buffology_buffs'
end
elseif (icon.isDebuff) then
return 'Buffology_debuffs'
else
return 'Buffology_buffs'
end
end
--[[
BOOL SortIcons(FRAME a, FRAME b)
]]
lib.SortIcons = function(a, b)
-- lib.debugging('Sort(): a: '..a.name..', b: '..b.name)
if ( not a ) or ( not b) then return false end
if ( not a.timeleft ) then
if ( not b.timeleft ) then
return a.name < b.name
else
return true
end
else
if ( not b.timeleft ) then
return false
else
return a.timeleft > b.timeleft
end
end
end
--[[ Creates a buff-/debuff-icon. It's a clickable button
FRAME CreateIcon()
TODO: Work on COUNT, perhaps DEBUFF-coloring
]]
lib.CreateIcon = function(id)
-- lib.debugging('CreateIcon()')
local icon = CreateFrame('Button', 'Buffology'..id, UIParent)
icon:EnableMouse(true)
icon:RegisterForClicks('RightButtonUp')
icon:SetScript('OnClick', lib.CancelBuff)
icon:SetWidth(settings.static.iconSize)
icon:SetHeight(settings.static.iconSize)
icon.BuffologyID = id
local cd = CreateFrame('Cooldown', nil, icon)
cd:SetAllPoints(icon)
icon.cd = cd
icon.cd:Hide()
local texture = icon:CreateTexture(nil, "BACKGROUND")
texture:SetAllPoints(icon)
icon.texture = texture
local timestring = lib.CreateFontObject(icon, 11, settings.options.fonts.timestring)
timestring:SetPoint('TOP', icon, 'BOTTOM', 0, 0)
icon.timestring = timestring
icon.timestring:SetText('00:00')
local count = icon:CreateFontString(nil, "OVERLAY")
count:SetFontObject(NumberFontNormal)
count:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", -1, 0)
icon.count = count
-- local overlay = icon:CreateTexture(nil, "OVERLAY")
-- overlay:SetTexture"Interface\\Buttons\\UI-Debuff-Overlays"
-- overlay:SetAllPoints(icon)
-- overlay:SetTexCoord(.296875, .5703125, 0, .515625)
-- icon.overlay = overlay
icon:SetScript("OnEnter", lib.TTOnEnter)
icon:SetScript("OnLeave", lib.TTOnLeave)
icon.lastUpdate = 0
return icon
end
--[[ Updates the duration-time of fading auras
VOID UpdateAuraTime(FRAME self, INT elapsed)
This is an OnUpdate-Eventhandler and is therefore called for every button with a timer.
]]
lib.UpdateAuraTime = function(self, elapsed)
self.lastUpdate = self.lastUpdate + elapsed
if ( self.lastUpdate > settings.static.updateInterval) then
-- lib.debugging('update '..self.name)
self.duration = self.timeleft - GetTime()
self.timestring:SetText(lib.TimeFormat(self.duration))
self.lastUpdate = 0
end
end
-- *****************************************************
ns.lib = lib -- handover of the lib to the namespace