-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
280 lines (255 loc) · 9.45 KB
/
Core.lua
File metadata and controls
280 lines (255 loc) · 9.45 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
local SLDataText = LibStub("AceAddon-3.0"):NewAddon("SLDataText", "AceEvent-3.0", "AceTimer-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("SLDataText")
local media = LibStub("LibSharedMedia-3.0")
local broker = LibStub("LibDataBroker-1.1")
local objects = {}
local db
local debugOn = true
local function Debug(msg)
if ( debugOn ) then
ChatFrame1:AddMessage(msg)
end
end
local function fadeIn(frame)
frame:Show()
if ( frame:GetAlpha() == 0 ) then
local step = 0.05
frame:SetScript("OnUpdate", function(self, elapsed)
if ( frame:GetAlpha() < 1.0 ) then
frame:SetAlpha(frame:GetAlpha()+step)
elseif ( frame:GetAlpha() == 1.0 ) then
frame:SetScript("OnUpdate", nil)
end
end)
end
end
local function fadeOut(frame)
if ( frame:GetAlpha() > 0 ) then
local step = 0.05
frame:SetScript("OnUpdate", function(self, elapsed)
if ( frame:GetAlpha() <= 1.0 and frame:GetAlpha() ~= 0 ) then
frame:SetAlpha(frame:GetAlpha()-step)
elseif ( frame:GetAlpha() == 0 ) then
frame:Hide()
frame:SetScript("OnUpdate", nil)
end
end)
end
end
local function outCombat()
for key, val in SLDataText:IterateModules() do
if ( val:IsEnabled() and db.hideInCombat and not val.db.profile.noCombatHide ) then --( val:IsEnabled() and
fadeIn(val.frame)
end
end
end
local function inCombat()
for key, val in SLDataText:IterateModules() do
if ( val:IsEnabled() and db.hideInCombat and not val.db.profile.noCombatHide ) then
fadeOut(val.frame)
end
end
end
function SLDataText:GetColor()
local color
if ( db.gColorClass ) then
local class = select(2, UnitClass("player"))
local classColors = {
["DEATHKNIGHT"] = "c41f3b",
["DEMONHUNTER"] = "a330c9",
["DRUID"] = "ff7d0a",
["HUNTER"] = "abd473",
["MAGE"] = "69ccf0",
["PALADIN"] = "f58cba",
["PRIEST"] = "ffffff",
["ROGUE"] = "fff569",
["SHAMAN"] = "2459ff",
["WARLOCK"] = "9482ca",
["WARRIOR"] = "c79c6e",
["MONK"] = "00ff96", --// FAN-UPDATE Karaswa (Monk added)
}
color = classColors[class]
else
color = db.gColor
end
return color
end
function SLDataText:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("SLDTDB")
self.db:RegisterDefaults({
profile = {
locked = true,
hideInCombat = false,
classColored = true,
gFont = "Arial Narrow",
gFontSize = 12,
gColor = "ffffff",
gColorClass = false,
modules = {
['*'] = true,
},
},
})
self.db.RegisterCallback(self, "OnProfileChanged", "Refresh")
self.db.RegisterCallback(self, "OnProfileCopied", "Refresh")
self.db.RegisterCallback(self, "OnProfileReset", "Refresh")
db = self.db.profile
self:BuildConfig()
end
function SLDataText:OnEnable()
self:RegisterEvent("PLAYER_REGEN_ENABLED", outCombat)
self:RegisterEvent("PLAYER_REGEN_DISABLED", inCombat)
for key, val in self:IterateModules() do
if ( self:GetModuleEnabled(key) and not val:IsEnabled() ) then
self:EnableModule(key)
end
end
for name, obj in broker:DataObjectIterator() do
tinsert(objects, { name, obj })
self:SetupObjects(name, obj)
end
end
function SLDataText:OnDisable()
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
self:UnregisterEvent("PLAYER_REGEN_DISABLED")
for key, val in self:IterateModules() do
if ( self:GetModuleEnabled(key) and val:IsEnabled() ) then
self:DisableModule(key)
end
end
end
function SLDataText:Refresh()
db = self.db.profile
for key, val in self:IterateModules() do
if ( self:GetModuleEnabled(key) and not val:IsEnabled() ) then
self:EnableModule(key)
elseif ( not self:GetModuleEnabled(key) and val:IsEnabled() ) then
self:DisableModule(key)
end
if ( type(val.Refresh) == "function" and val:IsEnabled() ) then
val:Refresh()
self:RefreshModule(val)
end
end
end
function SLDataText:GetModuleEnabled(module)
return db.modules[module]
end
function SLDataText:SetModuleEnabled(module, value)
local old = db.modules[module]
db.modules[module] = value
if ( old ~= value ) then
if ( value ) then
self:EnableModule(module)
else
self:DisableModule(module)
end
end
end
local function getFontInfo(module)
local modDB = module.db.profile
local font, size
if ( modDB.useGlobalFont ) then font = media:Fetch("font", db.gFont) else font = media:Fetch("font", modDB.fontFace) end
if ( modDB.useGlobalFontSize ) then size = db.gFontSize else size = modDB.fontSize end
return font, size
end
local function TranslateCoords(module, aF, x, y)
local just = module.db.profile.justify
local y1, x1
if ( aF == "TOP" or aF == "TOPLEFT" or aF == "TOPRIGHT" ) then y1 = module.frame:GetHeight()/2; y = y - y1
elseif ( aF == "BOTTOM" or aF == "BOTTOMLEFT" or aF == "BOTTOMRIGHT" ) then y1 = module.frame:GetHeight()/2; y = y + y1 end
if ( just == "RIGHT" and (aF == "TOPRIGHT" or aF == "RIGHT" or aF == "BOTTOMRIGHT") ) then x = x
elseif ( just == "RIGHT" and (aF == "TOPLEFT" or aF == "LEFT" or aF == "BOTTOMLEFT") ) then x1 = module.frame:GetWidth(); x = x + x1
elseif ( just == "RIGHT" and (aF == "CENTER" or aF == "TOP" or aF == "BOTTOM") ) then x1 = module.frame:GetWidth()/2; x = x + x1
elseif ( just == "LEFT" and (aF == "TOPRIGHT" or aF == "RIGHT" or aF == "BOTTOMRIGHT") ) then x1 = module.frame:GetWidth(); x = x - x1
elseif ( just == "LEFT" and (aF == "TOPLEFT" or aF == "LEFT" or aF == "BOTTOMLEFT") ) then x = x
elseif ( just == "LEFT" and (aF == "CENTER" or aF == "TOP" or aF == "BOTTOM") ) then x1 = module.frame:GetWidth()/2; x = x - x1
elseif ( just == "CENTER" and (aF == "TOPLEFT" or aF == "LEFT" or aF == "BOTTOMLEFT") ) then x1 = module.frame:GetWidth()/2; x = x + x1
elseif ( just == "CENTER" and (aF == "TOPRIGHT" or aF == "RIGHT" or aF == "BOTTOMRIGHT") ) then x1 = module.frame:GetWidth()/2; x = x - x1
elseif ( just == "CENTER" and (aF == "CENTER" or aF == "TOP" or aF == "BOTTOM") ) then x = x end
return x, y
end
local function MoveFrame(module)
local modDB = module.db.profile
module.frame:SetPoint(modDB.justify, modDB.anchor, modDB.anchorFrom, modDB.offX, modDB.offY)
module.isMoving = true
if ( not db.locked ) then module.frame:StartMoving() else end
end
local function StopFrame(module)
local modDB = module.db.profile
module.frame:StopMovingOrSizing()
module.isMoving = false
local aP, _, aF, x, y = module.frame:GetPoint()
local anchor = module.frame:GetParent():GetName()
local xoff, yoff = TranslateCoords(module, aF, x, y)
modDB.anchorPoint, modDB.anchor, modDB.anchorFrom, modDB.offX, modDB.offY = modDB.justify, anchor, aF, floor(xoff), floor(yoff)
end
function SLDataText:UpdateModule(module)
local modDB = module.db.profile
local font, size = getFontInfo(module)
if ( db.fontOutline ) then
module.string:SetFont(font, size, "OUTLINE")
else
module.string:SetFont(font, size)
module.string:SetShadowColor(0, 0, 0, 1)
module.string:SetShadowOffset(1.5, -1.5)
end
module.frame:SetWidth(module.string:GetWidth())
module.frame:SetHeight(module.string:GetHeight())
if ( module.icon and modDB.dispStyle == L["Icon"] ) then -- Has icon (ie. Tracking)
module.icon:SetWidth(modDB.iconSize)
module.icon:SetHeight(modDB.iconSize)
-- Readjust frame
module.frame:SetWidth(module.icon:GetWidth())
module.frame:SetHeight(module.icon:GetHeight())
end
if ( module.button ) then module.button:SetAllPoints(module.frame) end
end
function SLDataText:RefreshModule(module)
local modDB = module.db.profile
module.frame:SetBackdrop({ bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = { left = 0, top = 0, right = 0, bottom = 0 }, })
-- Force update of data & set font and frame size
self:UpdateModule(module)
module:Refresh()
module.frame:EnableMouse(true)
module.frame:SetFrameStrata(modDB.strata)
if ( not db.locked ) then
if ( module.button ) then module.button:EnableMouse(false) end
module.frame:SetBackdropColor(0, 0, 0, 1)
module.frame:SetMovable(true)
module.frame:RegisterForDrag("LeftButton")
module.frame:SetScript("OnMouseDown", function()
MoveFrame(module)
end)
module.frame:SetScript("OnMouseUp", function()
StopFrame(module)
end)
else
if ( module.button ) then module.button:EnableMouse(true) end
module.frame:SetBackdropColor(0, 0, 0, 0)
module.frame:SetMovable(false)
module.frame:RegisterForDrag("LeftButton")
module.frame:SetScript("OnMouseDown", nil)
module.frame:SetScript("OnMouseUp", nil)
end
if ( not module.isMoving ) then
module.frame:ClearAllPoints()
module.frame:SetPoint(modDB.justify, modDB.anchor, modDB.anchorFrom, modDB.offX, modDB.offY)
module.string:ClearAllPoints()
module.string:SetPoint(modDB.justify, module.frame, modDB.justify, 0, 0)
if ( module.icon ) then
module.icon:ClearAllPoints()
module.icon:SetPoint(modDB.justify, module.frame, modDB.justify, 0, 0)
end
end
end
-- Common information
SLDataText.just = { ["LEFT"] = L["Left"], ["CENTER"] = L["Center"], ["RIGHT"] = L["Right"], }
SLDataText.strata = { ["PARENT"] = L["Parent"], ["BACKGROUND"] = L["Background"], ["LOW"] = L["Low"],
["MEDIUM"] = L["Medium"], ["HIGH"] = L["High"], ["DIALOG"] = L["Dialog"], }
SLDataText.point = { ["LEFT"] = L["Left"], ["CENTER"] = L["Center"], ["RIGHT"] = L["Right"], ["BOTTOM"] = L["Bottom"], ["BOTTOMLEFT"] = L["Bottom Left"],
["BOTTOMRIGHT"] = L["Bottom Right"], ["TOP"] = L["Top"], ["TOPLEFT"] = L["Top Left"], ["TOPRIGHT"] = L["Top Right"], }
SLDataText.ttColors = { ["HEADER"] = "ffff00", ["LINEHEAD"] = "ffff88", ["LINERED"] = "ff0000", ["LINEGREEN"] = "00ff00", }
-- Databroker handling
function SLDataText:SetupObjects(name, obj)
end