View difference between Paste ID: TRZjiDuc and 4Rpn2S0u
SHOW: | | - or go back to the newest paste.
1
--[[
2
3
  Adrian L Lange grants anyone the right to use this work for any purpose,
4
  without any conditions, unless such conditions are required by law.
5
6
--]]
7
8
local _, ns = ...
9
local oUF = ns.oUF
10
11
local FONT = [=[Interface\AddOns\oUF_P3lim\semplice.ttf]=]
12
local TEXTURE = [=[Interface\ChatFrame\ChatFrameBackground]=]
13
local BACKDROP = {
14
	bgFile = TEXTURE, insets = {top = -1, bottom = -1, left = -1, right = -1}
15
}
16
17
local UpdateComboPoints
18
do
19
	local spells = {
20
		[1822] = true, -- Rake
21
		[5221] = true, -- Shred
22
		[6785] = true, -- Ravage
23
		[33876] = true, -- Mangle
24
		[102545] = true, -- Ravage!
25
		[114236] = true, -- Shred!
26
	}
27
28
	local min = math.min
29
	local count, form = 0
30
	local playerGUID
31
32
	function UpdateCombo(self, event, ...)
33
		if(event == 'COMBAT_LOG_EVENT_UNFILTERED') then
34
			local _, param, _, source, _, _, _, destination, _, _, _, spell, _, _, _, _, _, _, _, _, crit = ...
35
			if(form and param == 'SPELL_DAMAGE' and source == playerGUID and destination == UnitGUID('target')) then
36
				if(spells[spell] and crit) then
37
					count = min(count + 1, 5)
38
				end
39
			end
40
		elseif(event == 'UPDATE_SHAPESHIFT_FORM') then
41
			if(not playerGUID) then
42
				playerGUID = UnitGUID('player')
43
			end
44
45
			form = GetShapeshiftForm() == 3
46
		else
47
			if(UnitHasVehicleUI('player')) then
48
				count = GetComboPoints('vehicle', 'target')
49
			else
50
				count = GetComboPoints('player', 'target')
51
			end
52
		end
53
54
		local element = self.ComboPoints
55
		if(count > 0) then
56
			element:SetText(count)
57
		else
58
			element:SetText()
59
		end
60
	end
61
end
62
63
local function PostUpdatePower(element, unit, min, max)
64
	element:GetParent().Health:SetHeight(max ~= 0 and 20 or 22)
65
end
66
67
local function PostUpdateCast(element, unit)
68
	local Spark = element.Spark
69
	if(not element.interrupt and UnitCanAttack('player', unit)) then
70
		Spark:SetTexture(1, 0, 0)
71
	else
72
		Spark:SetTexture(1, 1, 1)
73
	end
74
end
75
76
local function UpdateRuneState(self)
77
	local opacity
78
	if(UnitHasVehicleUI('player') or UnitIsDeadOrGhost('player')) then
79
		opacity = 0
80
	elseif(UnitAffectingCombat('player')) then
81
		opacity = 1
82
	elseif(UnitExists('target') and UnitCanAttack('player', 'target')) then
83
		opacity = 0.8
84
	else
85
		opacity = 0
86
87
		for index = 1, 6 do
88
			local _, _, ready = GetRuneCooldown(index)
89
			if(not ready) then
90
				opacity = 0.5
91
				break
92
			end
93
		end
94
	end
95
96
	local current = self:GetAlpha()
97
	if(opacity > current) then
98
		UIFrameFadeIn(self, 1/4, current, opacity)
99
	elseif(opacity < current) then
100
		UIFrameFadeOut(self, 1/4, current, opacity)
101
	end
102
end
103
104
local function UpdateRunes(self, elapsed)
105
	local duration = self.duration + elapsed
106
	if(duration >= 1) then
107
		self:SetScript('OnUpdate', nil)
108
	else
109
		self.duration = duration
110
		self:SetValue(math.max(duration, 0))
111
	end
112
113
	local Background = self.Background
114
	if(Background:GetHeight() <= 2.1) then
115
		Background:Hide()
116
	else
117
		Background:Show()
118
	end
119
end
120
121
local function PostUpdateRune(element, Rune, id, start, duration, ready)
122
	local Overlay = Rune.Overlay
123
	if(ready) then
124
		Overlay:SetValue(1)
125
		Overlay:SetScript('OnUpdate', nil)
126
		Overlay.Background:Show()
127
	else
128
		Overlay.duration = GetTime() - (start + duration - 1)
129
		Overlay:SetScript('OnUpdate', UpdateRunes)
130
	end
131
end
132
133
local function PostUpdateRuneType(element, Rune)
134
	local r, g, b = Rune:GetStatusBarColor()
135
	Rune:SetStatusBarColor(r * 0.7, g * 0.7, b * 0.7)
136
	Rune.Overlay:SetStatusBarColor(r, g, b)
137
end
138
139
local function UpdateAura(self, elapsed)
140
	if(self.expiration) then
141
		if(self.expiration < 60) then
142
			self.remaining:SetFormattedText('%d', self.expiration)
143
		else
144
			self.remaining:SetText()
145
		end
146
147
		self.expiration = self.expiration - elapsed
148
	end
149
end
150
151
local function PostCreateAura(element, button)
152
	button:SetBackdrop(BACKDROP)
153
	button:SetBackdropColor(0, 0, 0)
154
	button.cd:SetReverse()
155
	button.icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
156
	button.icon:SetDrawLayer('ARTWORK')
157
158
	button.count:SetPoint('BOTTOMRIGHT', 2, 1)
159
	button.count:SetFont(FONT, 8, 'OUTLINEMONOCHROME')
160
161
	local remaining = button:CreateFontString(nil, 'OVERLAY')
162
	remaining:SetPoint('TOPLEFT', 0, -1)
163
	remaining:SetFont(FONT, 8, 'OUTLINEMONOCROME')
164
	button.remaining = remaining
165
166
	button:HookScript('OnUpdate', UpdateAura)
167
end
168
169
local function PostUpdateBuff(element, unit, button, index)
170
	local _, _, _, _, _, duration, expiration = UnitAura(unit, index, button.filter)
171
172
	if(duration and duration > 0) then
173
		button.expiration = expiration - GetTime()
174
	else
175
		button.expiration = math.huge
176
	end
177
end
178
179
local function PostUpdateDebuff(element, unit, button, index)
180
	local _, _, _, _, type, _, _, owner = UnitAura(unit, index, button.filter)
181
182
	if(owner == 'player') then
183
		local color = DebuffTypeColor[type or 'none']
184
		button:SetBackdropColor(color.r * 3/5, color.g * 3/5, color.b * 3/5)
185
		button.icon:SetDesaturated(false)
186
	else
187
		button:SetBackdropColor(0, 0, 0)
188
		button.icon:SetDesaturated(true)
189
	end
190
191
	PostUpdateBuff(element, unit, button, index)
192
end
193
194
local FilterPlayerBuffs
195
do
196
	local spells = {
197
		-- Druid
198
		[5217] = true, -- Tiger's Fury
199
		[52610] = true, -- Savage Roar
200
		[106951] = true, -- Berserk
201
		[127538] = true, -- Savage Roar (glyphed)
202
		[124974] = true, -- Nature's Vigil
203
		[132158] = true, -- Nature's Swiftness
204
		[132402] = true, -- Savage Defense
205
206
		-- Rogue
207
		[5171] = true, -- Slice and Dice
208
		[31224] = true, -- Cloak of Shadows
209
		[32645] = true, -- Envenom
210
		[73651] = true, -- Recuperate
211
		[121471] = true, -- Shadow Blades
212
		[115189] = true, -- Anticipation
213
214
		-- Death Knight
215
		[48707] = true, -- Anti-Magic Shell
216
		[51271] = true, -- Pillar of Frost
217
		[53365] = true, -- Rune of the Fallen Crusader
218
219
		-- Shared
220
		[32182] = true, -- Heroism
221
		[57933] = true, -- Tricks of the Trade
222
		[80353] = true, -- Time Warp
223
	}
224
225
	if(select(2, UnitClass('player')) == 'DEATHKNIGHT') then
226
		spells[57330] = true -- Horn of Winter
227
	end
228
229
	function FilterPlayerBuffs(...)
230
		local _, _, _, _, _, _, _, _, _, _, _, _, _, id = ...
231
		return spells[id]
232
	end
233
end
234
235
local FilterTargetDebuffs
236
do
237
	local show = {
238
		[1490] = true, -- Curse of Elements (Magic Vulnerability)
239
		[58410] = true, -- Master Poisoner (Magic Vulnerability)
240
		[81326] = true, -- Physical Vulnerability (Shared)
241
		[113746] = true, -- Weakened Armor (Shared)
242
	}
243
244
	local hide = {
245
		[770] = true, -- Faerie Fire
246
		[58180] = true, -- Infected Wounds
247
		[115798] = true, -- Weakened Blows
248
	}
249
250
	function FilterTargetDebuffs(...)
251
		local _, unit, _, _, _, _, _, _, _, _, owner, _, _, id = ...
252
253
		if(owner == 'player' and hide[id]) then
254
			return false
255
		elseif(owner == 'player' or owner == 'vehicle' or UnitIsFriend('player', unit) or show[id] or not owner) then
256
			return true
257
		end
258
	end
259
end
260
261
local UnitSpecific = {
262
	player = function(self)
263
		local PowerValue = self.Health:CreateFontString(nil, 'OVERLAY')
264
		PowerValue:SetPoint('LEFT', 2, 0)
265
		PowerValue:SetPoint('RIGHT', self.HealthValue, 'LEFT', -3)
266
		PowerValue:SetFont(FONT, 8, 'OUTLINEMONOCHROME')
267
		PowerValue:SetJustifyH('LEFT')
268
		PowerValue.frequentUpdates = 0.1
269
		self:Tag(PowerValue, '[|cffffff00>holypower<|r ][p3lim:power][ >p3lim:druid][ | >p3lim:spell]')
270
271
		local Experience = CreateFrame('StatusBar', nil, self)
272
		Experience:SetPoint('BOTTOM', 0, -20)
273
		Experience:SetSize(230, 6)
274
		Experience:SetStatusBarTexture(TEXTURE)
275
		Experience:SetStatusBarColor(0.15, 0.7, 0.1)
276
		self.Experience = Experience
277
278
		local Rested = CreateFrame('StatusBar', nil, Experience)
279
		Rested:SetAllPoints()
280
		Rested:SetStatusBarTexture(TEXTURE)
281
		Rested:SetStatusBarColor(0, 0.4, 1, 0.6)
282
		Rested:SetBackdrop(BACKDROP)
283
		Rested:SetBackdropColor(0, 0, 0)
284
		Experience.Rested = Rested
285
286
		local ExperienceBG = Rested:CreateTexture(nil, 'BORDER')
287
		ExperienceBG:SetAllPoints()
288
		ExperienceBG:SetTexture(1/3, 1/3, 1/3)
289
290
		local AltPower = CreateFrame('StatusBar', nil, self)
291
		AltPower:SetPoint('BOTTOM', 0, -10)
292
		AltPower:SetSize(230, 6)
293
		AltPower:SetStatusBarTexture(TEXTURE)
294
		AltPower:SetStatusBarColor(0.15, 0.7, 0.1)
295
		AltPower:SetBackdrop(BACKDROP)
296
		AltPower:SetBackdropColor(0, 0, 0)
297
		AltPower:EnableMouse(true)
298
		AltPower.colorTexture = true
299
		self.AltPowerBar = AltPower
300
301
		local AltPowerBG = AltPower:CreateTexture(nil, 'BORDER')
302
		AltPowerBG:SetAllPoints()
303
		AltPowerBG:SetTexture(1/3, 1/3, 1/3)
304
305
		local playerClass = select(3, UnitClass('player'))
306
		if(playerClass == 6) then
307
			local Parent = CreateFrame('Frame', nil, UIParent)
308
			Parent:SetPoint('CENTER', 0, -230)
309
			Parent:SetSize(82, 40)
310
311
			Parent:RegisterEvent('UNIT_EXITED_VEHICLE')
312
			Parent:RegisterEvent('UNIT_ENTERED_VEHICLE')
313
			Parent:RegisterEvent('PLAYER_ENTERING_WORLD')
314
			Parent:RegisterEvent('PLAYER_TARGET_CHANGED')
315
			Parent:RegisterEvent('PLAYER_REGEN_DISABLED')
316
			Parent:RegisterEvent('PLAYER_REGEN_ENABLED')
317
			Parent:RegisterEvent('RUNE_POWER_UPDATE')
318
			Parent:SetScript('OnEvent', UpdateRuneState)
319
320
			local Runes = {}
321
			for index = 1, 6 do
322
				local Rune = CreateFrame('StatusBar', nil, Parent)
323
				Rune:SetPoint('BOTTOMLEFT', 3 + (index - 1) * 13, 0)
324
				Rune:SetSize(10, 38)
325
				Rune:SetOrientation('VERTICAL')
326
				Rune:SetStatusBarTexture(TEXTURE)
327
				Rune:SetAlpha(0.7)
328
329
				local Overlay = CreateFrame('StatusBar', nil, Parent)
330
				Overlay:SetAllPoints(Rune)
331
				Overlay:SetOrientation('VERTICAL')
332
				Overlay:SetStatusBarTexture(TEXTURE)
333
				Overlay:SetMinMaxValues(0, 1)
334
				Overlay:SetFrameLevel(3)
335
				Rune.Overlay = Overlay
336
337
				local RuneBG = Parent:CreateTexture(nil, 'BORDER')
338
				RuneBG:SetPoint('BOTTOM', Rune, 0, -1)
339
				RuneBG:SetPoint('TOP', Rune:GetStatusBarTexture(), 0, 1)
340
				RuneBG:SetSize(12, 40)
341
				RuneBG:SetTexture(0, 0, 0)
342
				Overlay.Background = RuneBG
343
344
				Runes[index] = Rune
345
			end
346
347
			Runes.PostUpdateRune = PostUpdateRune
348
			Runes.PostUpdateType = PostUpdateRuneType
349
350
			self.Runes = Runes
351
352
			self.colors.runes[1] = {0.9, 0.15, 0.15}
353
			self.colors.runes[2] = {0.4, 0.9, 0.3}
354
			self.colors.runes[3] = {0, 0.7, 0.9}
355
			self.colors.runes[4] = {0.5, 0.27, 0.68}
356
		end
357
358
		self.Debuffs.size = 22
359
		self.Debuffs:SetSize(230, 22)
360
		self.Debuffs.PostUpdateIcon = PostUpdateBuff
361
		self.Buffs.PostUpdateIcon = PostUpdateBuff
362
		self.Buffs.CustomFilter = FilterPlayerBuffs
363
364
		self:Tag(self.HealthValue, '[p3lim:status][p3lim:player]')
365
		self:SetWidth(230)
366
	end,
367
	target = function(self)
368
		local ComboPoints = self:CreateFontString(nil, 'OVERLAY', 'SubZoneTextFont')
369
		ComboPoints:SetPoint('RIGHT', self, 'LEFT', -9, 0)
370
		ComboPoints:SetJustifyH('RIGHT')
371
		ComboPoints:SetTextColor(1, 1, 1)
372
373
		if(select(3, UnitClass('player')) == 11) then
374
			self.ComboPoints = ComboPoints
375
376
			self:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED', UpdateCombo, true)
377
			self:RegisterEvent('UPDATE_SHAPESHIFT_FORM', UpdateCombo, true)
378
			self:RegisterEvent('PLAYER_TARGET_CHANGED', UpdateCombo, true)
379
			self:RegisterEvent('UNIT_COMBO_POINTS', UpdateCombo, true)
380
381
			table.insert(self.__elements, UpdateCombo)
382
		else
383
			self:Tag(ComboPoints, '[cpoints]')
384
		end
385
386
		self.Castbar.PostCastStart = PostUpdateCast
387
		self.Castbar.PostCastInterruptible = PostUpdateCast
388
		self.Castbar.PostCastNotInterruptible = PostUpdateCast
389
		self.Castbar.PostChannelStart = PostUpdateCast
390
391
		self.Debuffs.size = 19.4
392
		self.Debuffs['growth-y'] = 'DOWN'
393
		self.Debuffs:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -4)
394
		self.Debuffs:SetSize(230, 19.4)
395
		self.Debuffs.CustomFilter = FilterTargetDebuffs
396
		self.Debuffs.PostUpdateIcon = PostUpdateDebuff
397
398
		self.Power.PostUpdate = PostUpdatePower
399
		self:Tag(self.HealthValue, '[p3lim:status][p3lim:hostile][p3lim:friendly]')
400
		self:SetWidth(230)
401
	end,
402-
	party = function(self)
402+
403-
		local Name = self.Health:CreateFontString(nil, 'OVERLAY')
403+
404-
		Name:SetPoint('LEFT', 3, 0)
404+
405-
		Name:SetPoint('RIGHT', self.HealthValue, 'LEFT')
405+
406
	end
407
}
408-
		self:Tag(Name, '[p3lim:unbuffed< ][p3lim:leader][raidcolor][name]')
408+
409
local function Shared(self, unit)
410-
		local RoleIcon = self:CreateTexture(nil, 'ARTWORK')
410+
411-
		RoleIcon:SetPoint('LEFT', self, 'RIGHT', 3, 0)
411+
412-
		RoleIcon:SetSize(14, 14)
412+
413-
		RoleIcon:SetAlpha(0)
413+
414-
		self.LFDRole = RoleIcon
414+
415
	self:SetScript('OnEnter', UnitFrame_OnEnter)
416-
		local ReadyCheck = self:CreateTexture(nil, 'OVERLAY')
416+
417-
		ReadyCheck:SetPoint('LEFT', self, 'RIGHT', 3, 0)
417+
418-
		ReadyCheck:SetSize(14, 14)
418+
419-
		self.ReadyCheck = ReadyCheck
419+
420
421-
		self:HookScript('OnEnter', function() RoleIcon:SetAlpha(1) end)
421+
422-
		self:HookScript('OnLeave', function() RoleIcon:SetAlpha(0) end)
422+
423
	Health:SetStatusBarColor(1/6, 1/6, 2/7)
424
	Health.frequentUpdates = true
425-
		self:Tag(self.HealthValue, '[p3lim:status][p3lim:percent]')
425+
426
427
	local HealthBG = Health:CreateTexture(nil, 'BORDER')
428
	HealthBG:SetAllPoints()
429
	HealthBG:SetTexture(1/3, 1/3, 1/3)
430
431
	local HealthValue = Health:CreateFontString(nil, 'OVERLAY')
432
	HealthValue:SetPoint('RIGHT', -2, 0)
433-
UnitSpecific.raid = UnitSpecific.party
433+
434
	HealthValue:SetJustifyH('RIGHT')
435
	HealthValue.frequentUpdates = 1/4
436
	self.HealthValue = HealthValue
437
438
	if(unit == 'player' or unit == 'target') then
439
		local Power = CreateFrame('StatusBar', nil, self)
440
		Power:SetPoint('BOTTOMRIGHT')
441
		Power:SetPoint('BOTTOMLEFT')
442
		Power:SetPoint('TOP', Health, 'BOTTOM', 0, -1)
443
		Power:SetStatusBarTexture(TEXTURE)
444
		Power.frequentUpdates = true
445
		self.Power = Power
446
447
		Power.colorClass = true
448
		Power.colorTapping = true
449
		Power.colorDisconnected = true
450
		Power.colorReaction = true
451
452
		local PowerBG = Power:CreateTexture(nil, 'BORDER')
453
		PowerBG:SetAllPoints()
454
		PowerBG:SetTexture(TEXTURE)
455
		PowerBG.multiplier = 1/3
456
		Power.bg = PowerBG
457
458
		local Buffs = CreateFrame('Frame', nil, self)
459
		Buffs:SetPoint('TOPLEFT', self, 'TOPRIGHT', 4, 0)
460
		Buffs:SetSize(236, 44)
461
		Buffs.num = 20
462
		Buffs.size = 22
463
		Buffs.spacing = 4
464
		Buffs.initialAnchor = 'TOPLEFT'
465
		Buffs['growth-y'] = 'DOWN'
466
		Buffs.PostCreateIcon = PostCreateAura
467
		self.Buffs = Buffs
468
469
		local Castbar = CreateFrame('StatusBar', nil, self)
470
		Castbar:SetAllPoints(Health)
471
		Castbar:SetStatusBarTexture(TEXTURE)
472
		Castbar:SetStatusBarColor(0, 0, 0, 0)
473
		Castbar:SetFrameStrata('HIGH')
474
		self.Castbar = Castbar
475
476
		local Spark = Castbar:CreateTexture(nil, 'OVERLAY')
477
		Spark:SetSize(2, 20)
478
		Spark:SetTexture(1, 1, 1)
479
		Castbar.Spark = Spark
480
481
		local RaidIcon = Health:CreateTexture(nil, 'OVERLAY')
482
		RaidIcon:SetPoint('TOP', self, 0, 8)
483
		RaidIcon:SetSize(16, 16)
484
		self.RaidIcon = RaidIcon
485
486
		Health:SetHeight(20)
487
		Health:SetPoint('TOPRIGHT')
488
		Health:SetPoint('TOPLEFT')
489
490
		self:SetHeight(22)
491
	end
492
493
	if(unit ~= 'player' and unit ~= 'party' and unit ~= 'raid') then
494
		local Name = Health:CreateFontString(nil, 'OVERLAY')
495
		Name:SetPoint('LEFT', 2, 0)
496
		Name:SetPoint('RIGHT', HealthValue, 'LEFT')
497
		Name:SetFont(FONT, 8, 'OUTLINEMONOCHROME')
498
		Name:SetJustifyH('LEFT')
499
		self:Tag(Name, '[p3lim:color][name][ |cff0090ff>rare<|r]')
500
	end
501
502
	if(unit ~= 'boss') then
503
		local Debuffs = CreateFrame('Frame', nil, self)
504
		Debuffs.spacing = 4
505
		Debuffs.initialAnchor = 'TOPLEFT'
506
		Debuffs.PostCreateIcon = PostCreateAura
507
		self.Debuffs = Debuffs
508
509
		if(unit == 'focus') then
510
			Debuffs:SetPoint('TOPLEFT', self, 'TOPRIGHT', 4, 0)
511
			Debuffs.onlyShowPlayer = true
512
		elseif(unit ~= 'target') then
513
			Debuffs:SetPoint('TOPRIGHT', self, 'TOPLEFT', -4, 0)
514
			Debuffs.initialAnchor = 'TOPRIGHT'
515
			Debuffs['growth-x'] = 'LEFT'
516
		end
517
518
		if(unit == 'focus' or unit == 'targettarget') then
519
			Debuffs.num = 3
520
			Debuffs.size = 19
521
			Debuffs:SetSize(230, 19)
522
523
			Health:SetAllPoints()
524
			self:SetSize(161, 19)
525
		end
526
	end
527
528-
	if(unit ~= 'party' and unit ~= 'raid' and unit ~= 'boss') then
528+
529
		return UnitSpecific[unit](self)
530
	end
531
end
532
533
oUF:RegisterStyle('P3lim', Shared)
534
oUF:Factory(function(self)
535
	self:SetActiveStyle('P3lim')
536
	self:Spawn('player'):SetPoint('CENTER', -300, -250)
537
	self:Spawn('focus'):SetPoint('TOPLEFT', oUF_P3limPlayer, 0, 26)
538
	self:Spawn('target'):SetPoint('CENTER', 300, -250)
539
	self:Spawn('targettarget'):SetPoint('TOPRIGHT', oUF_P3limTarget, 0, 26)
540
541
	for index = 1, MAX_BOSS_FRAMES do
542
		local boss = self:Spawn('boss' .. index)
543
		if(index == 1) then
544
			boss:SetPoint('TOP', oUF_P3limRaid or Minimap, 'BOTTOM', 0, -20)
545
		else
546
			boss:SetPoint('TOP', _G['oUF_P3limBoss' .. index - 1], 'BOTTOM', 0, -6)
547
		end
548
549
		local blizz = _G['Boss' .. index .. 'TargetFrame']
550
		blizz:UnregisterAllEvents()
551
		blizz:Hide()
552
	end
553
end)