-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclassic.lua
315 lines (251 loc) · 8.01 KB
/
classic.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
--[[-------------------------------------------------------------------------
Trond A Ekseth grants anyone the right to use this work for any purpose,
without any conditions, unless such conditions are required by law.
---------------------------------------------------------------------------]]
local _TEXTURE = [[Interface\AddOns\oUF_Classic\textures\statusbar]]
local colors = setmetatable({
health = {.45, .73, .27},
power = setmetatable({
['MANA'] = {.27, .53, .73},
['RAGE'] = {.73, .27, .27},
}, {__index = oUF.colors.power}),
}, {__index = oUF.colors})
local siValue = function(val)
if(val >= 1e6) then
return ('%.1f'):format(val / 1e6):gsub('%.', 'm')
elseif(val >= 1e4) then
return ("%.1f"):format(val / 1e3):gsub('%.', 'k')
else
return val
end
end
oUF.Tags.Methods['classic:health'] = function(unit)
if(not UnitIsConnected(unit) or UnitIsDead(unit) or UnitIsGhost(unit)) then return end
return siValue(UnitHealth(unit)) .. '/' .. siValue(UnitHealthMax(unit))
end
oUF.Tags.Events['classic:health'] = oUF.Tags.Events.missinghp
oUF.Tags.Methods['classic:power'] = function(unit)
local min, max = UnitPower(unit), UnitPowerMax(unit)
if(min == 0 or max == 0 or not UnitIsConnected(unit) or UnitIsDead(unit) or UnitIsGhost(unit)) then return end
return siValue(min) .. '/' .. siValue(max)
end
oUF.Tags.Events['classic:power'] = oUF.Tags.Events.missingpp
local PostUpdateHealth = function(health, unit, min, max)
local self = health:GetParent()
if(UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) or not UnitIsConnected(unit)) then
self:SetBackdropBorderColor(.3, .3, .3)
else
local r, g, b = UnitSelectionColor(unit)
self:SetBackdropBorderColor(r, g, b)
end
if(UnitIsDead(unit)) then
health:SetValue(0)
elseif(UnitIsGhost(unit)) then
health:SetValue(0)
end
end
local PostUpdatePower = function(power, unit,min, max)
if(UnitIsDead(unit) or UnitIsGhost(unit)) then
power:SetValue(0)
end
end
local backdrop = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16,
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16,
insets = {left = 4, right = 4, top = 4, bottom = 4},
}
local Shared = function(self, unit, isSingle)
self:SetScript("OnEnter", UnitFrame_OnEnter)
self:SetScript("OnLeave", UnitFrame_OnLeave)
self:RegisterForClicks"AnyUp"
self:SetBackdrop(backdrop)
self:SetBackdropColor(0, 0, 0, 1)
self:SetBackdropBorderColor(.3, .3, .3, 1)
-- Health bar
local Health = CreateFrame("StatusBar", nil, self)
Health:SetHeight(14)
Health:SetStatusBarTexture(_TEXTURE)
Health:SetPoint("TOP", 0, -8)
Health:SetPoint("LEFT", 8, 0)
Health:SetPoint('RIGHT', -90, 0)
Health.frequentUpdates = true
Health.colorDisconnected = true
Health.colorTapping = true
Health.colorSmooth = true
Health.PostUpdate = PostUpdateHealth
self.Health = Health
local HealthPoints = Health:CreateFontString(nil, "OVERLAY", "GameFontNormal")
HealthPoints:SetPoint("LEFT", Health, "RIGHT", 2, -1)
HealthPoints:SetPoint("RIGHT", self, -6, -1)
HealthPoints:SetJustifyH"CENTER"
HealthPoints:SetFont(GameFontNormal:GetFont(), 10)
HealthPoints:SetTextColor(1, 1, 1)
self:Tag(HealthPoints, '[dead][offline][classic:health]')
Health.value = HealthPoints
-- Health bar background
local HealthBackground = Health:CreateTexture(nil, "BORDER")
HealthBackground:SetAllPoints(Health)
HealthBackground:SetAlpha(.5)
HealthBackground:SetTexture(_TEXTURE)
Health.bg = HealthBackground
local Castbar = CreateFrame("StatusBar", nil, self)
Castbar:SetStatusBarTexture(_TEXTURE)
Castbar:SetStatusBarColor(.73, 0, .27, .8)
Castbar:SetAllPoints(Health)
Castbar:SetToplevel(true)
self.Castbar = Castbar
-- Unit name
local Name = Health:CreateFontString(nil, "OVERLAY", "GameFontNormal")
Name:SetPoint("LEFT", 2, -1)
Name:SetPoint("RIGHT", -2, -1)
Name:SetJustifyH"LEFT"
Name:SetFont(GameFontNormal:GetFont(), 11)
Name:SetTextColor(1, 1, 1)
self:Tag(Name, '[name]')
self.Name = Name
local Leader = self:CreateTexture(nil, "OVERLAY")
Leader:SetSize(16, 16)
Leader:SetPoint("BOTTOM", self, "TOP", 0, -7)
self.Leader = Leader
-- enable our colors
self.colors = colors
if(isSingle) then
self:SetSize(260, 48)
end
end
local DoAuras = function(self)
-- Buffs
local Buffs = CreateFrame("Frame", nil, self)
Buffs:SetPoint("BOTTOM", self, "TOP")
Buffs:SetPoint'LEFT'
Buffs:SetPoint'RIGHT'
Buffs:SetHeight(17)
Buffs.size = 17
Buffs.num = math.floor(self:GetWidth() / Buffs.size + .5)
self.Buffs = Buffs
-- Debuffs
local Debuffs = CreateFrame("Frame", nil, self)
Debuffs:SetPoint("TOP", self, "BOTTOM")
Debuffs:SetPoint'LEFT'
Debuffs:SetPoint'RIGHT'
Debuffs:SetHeight(20)
Debuffs.initialAnchor = "TOPLEFT"
Debuffs.size = 20
Debuffs.showDebuffType = true
Debuffs.num = math.floor(self:GetWidth() / Debuffs.size + .5)
self.Debuffs = Debuffs
end
local DoPower = function(self)
-- Power bar
local Power = CreateFrame("StatusBar", nil, self)
Power:SetHeight(14)
Power:SetStatusBarTexture(_TEXTURE)
Power:SetPoint("BOTTOM", 0, 8)
Power:SetPoint("LEFT", 8, 0)
Power:SetPoint('RIGHT', -90, 0)
Power.colorPower = true
Power.frequentUpdates = true
self.Power = Power
-- Power bar background
local PowerBackground = Power:CreateTexture(nil, "BORDER")
PowerBackground:SetAllPoints(Power)
PowerBackground:SetAlpha(.5)
PowerBackground:SetTexture(_TEXTURE)
Power.bg = PowerBackground
local PowerPoints = Power:CreateFontString(nil, "OVERLAY", "GameFontNormal")
PowerPoints:SetPoint("LEFT", Power, "RIGHT", 2, -1)
PowerPoints:SetPoint("RIGHT", self, -6, -1)
PowerPoints:SetJustifyH"CENTER"
PowerPoints:SetFont(GameFontNormal:GetFont(), 10)
PowerPoints:SetTextColor(1, 1, 1)
self:Tag(PowerPoints, '[classic:power]')
Power.value = PowerPoints
Power.PostUpdate = PostUpdatePower
-- Info string
local Info = Power:CreateFontString(nil, "OVERLAY", "GameFontNormal")
Info:SetPoint("LEFT", 2, -1)
Info:SetPoint("RIGHT", -2, -1)
Info:SetJustifyH"LEFT"
Info:SetFont(GameFontNormal:GetFont(), 11)
Info:SetTextColor(1, 1, 1)
self:Tag(Info, 'L[level][shortclassification] [raidcolor][smartclass]')
self.Info = Info
end
local UnitSpecific = {
target = function(self, ...)
Shared(self, ...)
DoAuras(self)
DoPower(self)
end,
targettarget = function(self, unit, isSingle)
Shared(self, unit, isSingle)
DoAuras(self)
if(isSingle) then
self:SetHeight(32)
end
end,
}
do
local PLAYER_UPDATE_RESTING = function(self)
if(IsResting()) then
self:SetBackdropBorderColor(.3, .3, .8)
else
local r, g, b = UnitSelectionColor(self.unit)
self:SetBackdropBorderColor(r, g, b)
end
end
UnitSpecific.player = function(self, ...)
Shared(self, ...)
DoPower(self)
self:RegisterEvent("PLAYER_UPDATE_RESTING", PLAYER_UPDATE_RESTING)
end
end
do
local range = {
insideAlpha = 1,
outsideAlpha = .5,
}
UnitSpecific.party = function(self, ...)
Shared(self, ...)
DoAuras(self)
DoPower(self)
self.Range = range
end
end
oUF:RegisterStyle("Classic", Shared)
for unit,layout in next, UnitSpecific do
-- Capitalize the unit name, so it looks better.
oUF:RegisterStyle('Classic - ' .. unit:gsub("^%l", string.upper), layout)
end
-- A small helper to change the style into a unit specific, if it exists.
local spawnHelper = function(self, unit, ...)
if(UnitSpecific[unit]) then
self:SetActiveStyle('Classic - ' .. unit:gsub("^%l", string.upper))
else
self:SetActiveStyle'Classic'
end
local object = self:Spawn(unit)
object:SetPoint(...)
return object
end
oUF:Factory(function(self)
local player = spawnHelper(self, 'player', "CENTER", -200, -380)
spawnHelper(self, 'pet', 'TOP', player, 'BOTTOM', 0, -16)
spawnHelper(self, 'target', "CENTER", 200, -380)
spawnHelper(self, 'targettarget', "CENTER", 0, -250)
self:SetActiveStyle'Classic - Party'
local party = self:SpawnHeader(nil, nil, 'raid,party',
'showParty', true,
'yOffset', -40,
'xOffset', -40,
'maxColumns', 2,
'unitsPerColumn', 2,
'columnAnchorPoint', 'LEFT',
'columnSpacing', 15,
'oUF-initialConfigFunction', [[
self:SetWidth(260)
self:SetHeight(48)
]]
)
party:SetPoint("TOPLEFT", 30, -30)
end)