PageRenderTime 771ms CodeModel.GetById 122ms app.highlight 459ms RepoModel.GetById 96ms app.codeStats 2ms

/Tukui/modules/nameplates/nameplates.lua

http://github.com/Asphyxia/Tukui
Lua | 699 lines | 558 code | 89 blank | 52 comment | 114 complexity | 432dd9ac7db903b35af6d28b13de6ff6 MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import Functions/Constants/Variables, Config, Locales
  2
  3--Base code by Dawn (dNameplates), Rewritten by Elv22
  4if not C["nameplate"].enable == true then return end
  5
  6local TEXTURE = C["media"].normTex
  7local FONT = C["media"].pixelfont
  8local FONTSIZE = 10
  9local FONTFLAG = "MONOCHROMEOUTLINE"
 10local hpHeight = 12
 11local hpWidth = 110
 12local iconSize = 25		--Size of all Icons, RaidIcon/ClassIcon/Castbar Icon
 13local cbHeight = 5
 14local cbWidth = 110
 15local blankTex = C["media"].blank
 16local OVERLAY = [=[Interface\TargetingFrame\UI-TargetingFrame-Flash]=]
 17local numChildren = -1
 18local frames = {}
 19local noscalemult = T.mult * C["general"].uiscale
 20
 21--Change defaults if we are showing health text or not
 22if C["nameplate"].showhealth ~= true then
 23	hpHeight = 7
 24	iconSize = 20
 25end
 26
 27local NamePlates = CreateFrame("Frame", nil, UIParent)
 28NamePlates:SetScript("OnEvent", function(self, event, ...) self[event](self, ...) end)
 29if C["nameplate"].trackdebuffs == true or C["nameplate"].trackcc == true then
 30	NamePlates:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
 31end
 32
 33local function QueueObject(parent, object)
 34	parent.queue = parent.queue or {}
 35	parent.queue[object] = true
 36end
 37
 38local function HideObjects(parent)
 39	for object in pairs(parent.queue) do
 40		if(object:GetObjectType() == 'Texture') then
 41			object:SetTexture(nil)
 42			object.SetTexture = T.dummy
 43		elseif (object:GetObjectType() == 'FontString') then
 44			object.ClearAllPoints = T.dummy
 45			object.SetFont = T.dummy
 46			object.SetPoint = T.dummy
 47			object:Hide()
 48			object.Show = T.dummy
 49			object.SetText = T.dummy
 50			object.SetShadowOffset = T.dummy
 51		else
 52			object:Hide()
 53			object.Show = T.dummy
 54		end
 55	end
 56end
 57
 58--Create a fake backdrop frame using textures
 59local function CreateVirtualFrame(parent, point)
 60	if point == nil then point = parent end
 61	
 62	if point.backdrop then return end
 63	parent.backdrop = parent:CreateTexture(nil, "BORDER")
 64	parent.backdrop:SetDrawLayer("BORDER", -8)
 65	parent.backdrop:SetPoint("TOPLEFT", point, "TOPLEFT", -noscalemult*3, noscalemult*3)
 66	parent.backdrop:SetPoint("BOTTOMRIGHT", point, "BOTTOMRIGHT", noscalemult*3, -noscalemult*3)
 67	parent.backdrop:SetTexture(0, 0, 0, 1)
 68	
 69	parent.backdrop2 = parent:CreateTexture(nil, "BORDER")
 70	parent.backdrop2:SetDrawLayer("BORDER", -7)
 71	parent.backdrop2:SetAllPoints(point)
 72	parent.backdrop2:SetTexture(unpack(C["media"].backdropcolor)) 
 73
 74	parent.bordertop = parent:CreateTexture(nil, "BORDER")
 75	parent.bordertop:SetPoint("TOPLEFT", point, "TOPLEFT", -noscalemult*2, noscalemult*2)
 76	parent.bordertop:SetPoint("TOPRIGHT", point, "TOPRIGHT", noscalemult*2, noscalemult*2)
 77	parent.bordertop:SetHeight(noscalemult)
 78	parent.bordertop:SetTexture(unpack(C["media"].bordercolor))	
 79	parent.bordertop:SetDrawLayer("BORDER", -7)
 80	
 81	parent.borderbottom = parent:CreateTexture(nil, "BORDER")
 82	parent.borderbottom:SetPoint("BOTTOMLEFT", point, "BOTTOMLEFT", -noscalemult*2, -noscalemult*2)
 83	parent.borderbottom:SetPoint("BOTTOMRIGHT", point, "BOTTOMRIGHT", noscalemult*2, -noscalemult*2)
 84	parent.borderbottom:SetHeight(noscalemult)
 85	parent.borderbottom:SetTexture(unpack(C["media"].bordercolor))	
 86	parent.borderbottom:SetDrawLayer("BORDER", -7)
 87	
 88	parent.borderleft = parent:CreateTexture(nil, "BORDER")
 89	parent.borderleft:SetPoint("TOPLEFT", point, "TOPLEFT", -noscalemult*2, noscalemult*2)
 90	parent.borderleft:SetPoint("BOTTOMLEFT", point, "BOTTOMLEFT", noscalemult*2, -noscalemult*2)
 91	parent.borderleft:SetWidth(noscalemult)
 92	parent.borderleft:SetTexture(unpack(C["media"].bordercolor))	
 93	parent.borderleft:SetDrawLayer("BORDER", -7)
 94	
 95	parent.borderright = parent:CreateTexture(nil, "BORDER")
 96	parent.borderright:SetPoint("TOPRIGHT", point, "TOPRIGHT", noscalemult*2, noscalemult*2)
 97	parent.borderright:SetPoint("BOTTOMRIGHT", point, "BOTTOMRIGHT", -noscalemult*2, -noscalemult*2)
 98	parent.borderright:SetWidth(noscalemult)
 99	parent.borderright:SetTexture(unpack(C["media"].bordercolor))	
100	parent.borderright:SetDrawLayer("BORDER", -7)	
101end
102
103local function SetVirtualBorder(parent, r, g, b)
104	parent.bordertop:SetTexture(r, g, b)
105	parent.borderbottom:SetTexture(r, g, b)
106	parent.borderleft:SetTexture(r, g, b)
107	parent.borderright:SetTexture(r, g, b)
108end
109
110--OnUpdate function for all nameplates, we use this to update threat, health, and anything else that may require rapid updates.
111local goodR, goodG, goodB = unpack(C["nameplate"].goodcolor)
112local badR, badG, badB = unpack(C["nameplate"].badcolor)
113local transitionR, transitionG, transitionB = unpack(C["nameplate"].transitioncolor)
114local function UpdateThreat(frame, elapsed)
115	frame.hp:Show()
116	if frame.hasClass == true then return end
117	
118	if C["nameplate"].enhancethreat ~= true then
119		if(frame.region:IsShown()) then
120			local _, val = frame.region:GetVertexColor()
121			if(val > 0.7) then
122				SetVirtualBorder(frame.hp, transitionR, transitionG, transitionB)
123			else
124				SetVirtualBorder(frame.hp, badR, badG, badB)
125			end
126		else
127			SetVirtualBorder(frame.hp, unpack(C["media"].bordercolor))
128		end
129	else
130		if not frame.region:IsShown() then
131			if InCombatLockdown() and frame.isFriendly ~= true then
132				--No Threat
133				if T.Role == "Tank" then
134					frame.hp:SetStatusBarColor(badR, badG, badB)
135					frame.hp.hpbg:SetTexture(badR, badG, badB, 0.25)
136				else
137					frame.hp:SetStatusBarColor(goodR, goodG, goodB)
138					frame.hp.hpbg:SetTexture(goodR, goodG, goodB, 0.25)
139				end		
140			else
141				--Set colors to their original, not in combat
142				frame.hp:SetStatusBarColor(frame.hp.rcolor, frame.hp.gcolor, frame.hp.bcolor)
143				frame.hp.hpbg:SetTexture(frame.hp.rcolor, frame.hp.gcolor, frame.hp.bcolor, 0.25)
144			end
145		else
146			--Ok we either have threat or we're losing/gaining it
147			local r, g, b = frame.region:GetVertexColor()
148			if g + b == 0 then
149				--Have Threat
150				if T.Role == "Tank" then
151					frame.hp:SetStatusBarColor(goodR, goodG, goodB)
152					frame.hp.hpbg:SetTexture(goodR, goodG, goodB, 0.25)
153				else
154					frame.hp:SetStatusBarColor(badR, badG, badB)
155					frame.hp.hpbg:SetTexture(badR, badG, badB, 0.25)
156				end
157			else
158				--Losing/Gaining Threat
159				frame.hp:SetStatusBarColor(transitionR, transitionG, transitionB)	
160				frame.hp.hpbg:SetTexture(transitionR, transitionG, transitionB, 0.25)
161			end
162		end
163	end
164end
165
166--Create our Aura Icons
167local function CreateAuraIcon(parent)
168	local button = CreateFrame("Frame",nil,parent)
169	button:SetWidth(20)
170	button:SetHeight(20)
171	
172	button.bg = button:CreateTexture(nil, "BACKGROUND")
173	button.bg:SetTexture(unpack(C["media"].backdropcolor))
174	button.bg:SetAllPoints(button)
175	
176	button.bord = button:CreateTexture(nil, "BORDER")
177	button.bord:SetTexture(unpack(C["media"].bordercolor))
178	button.bord:SetPoint("TOPLEFT",button,"TOPLEFT", noscalemult,-noscalemult)
179	button.bord:SetPoint("BOTTOMRIGHT",button,"BOTTOMRIGHT",-noscalemult,noscalemult)
180	
181	button.bg2 = button:CreateTexture(nil, "ARTWORK")
182	button.bg2:SetTexture(unpack(C["media"].backdropcolor))
183	button.bg2:SetPoint("TOPLEFT",button,"TOPLEFT", noscalemult*2,-noscalemult*2)
184	button.bg2:SetPoint("BOTTOMRIGHT",button,"BOTTOMRIGHT",-noscalemult*2,noscalemult*2)	
185	
186	button.icon = button:CreateTexture(nil, "OVERLAY")
187	button.icon:SetPoint("TOPLEFT",button,"TOPLEFT", noscalemult*3,-noscalemult*3)
188	button.icon:SetPoint("BOTTOMRIGHT",button,"BOTTOMRIGHT",-noscalemult*3,noscalemult*3)
189	button.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
190	button.cd = CreateFrame("Cooldown",nil,button)
191	button.cd:SetAllPoints(button)
192	button.cd:SetReverse(true)
193	button.count = button:CreateFontString(nil,"OVERLAY")
194	button.count:SetFont(FONT, 10, FONTFLAG)
195	button.count:SetShadowColor(0, 0, 0, 0.4)
196	button.count:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", 0, 2)
197	return button
198end
199
200--Update an Aura Icon
201local function UpdateAuraIcon(button, unit, index, filter)
202	local name,_,icon,count,debuffType,duration,expirationTime,_,_,_,spellID = UnitAura(unit,index,filter)
203	
204	button.icon:SetTexture(icon)
205	button.cd:SetCooldown(expirationTime-duration,duration)
206	button.expirationTime = expirationTime
207	button.duration = duration
208	button.spellID = spellID
209	if count > 1 then 
210		button.count:SetText(count)
211	else
212		button.count:SetText("")
213	end
214	button.cd:SetScript("OnUpdate", function(self) if not button.cd.timer then self:SetScript("OnUpdate", nil) return end button.cd.timer.text:SetFont(FONT,10,FONTFLAG) button.cd.timer.text:SetShadowColor(0, 0, 0, 0.4) end)
215	button:Show()
216end
217
218--Filter auras on nameplate, and determine if we need to update them or not.
219local function OnAura(frame, unit)
220	if not frame.icons or not frame.unit then return end
221	local i = 1
222	for index = 1,40 do
223		if i > 5 then return end
224		local match
225		local name,_,_,_,_,duration,_,caster,_,_,spellid = UnitAura(frame.unit,index,"HARMFUL")
226		
227		if C["nameplate"].trackdebuffs == true then
228			if caster == "player" then match = true end
229		end
230		
231		if C["nameplate"].trackcc == true then
232			if T.DebuffWhiteList[name] then match = true end
233		end
234		
235		if duration and match == true then
236			if not frame.icons[i] then frame.icons[i] = CreateAuraIcon(frame) end
237			local icon = frame.icons[i]
238			if i == 1 then icon:SetPoint("RIGHT",frame.icons,"RIGHT") end
239			if i ~= 1 and i <= 5 then icon:SetPoint("RIGHT", frame.icons[i-1], "LEFT", -2, 0) end
240			i = i + 1
241			UpdateAuraIcon(icon, frame.unit, index, "HARMFUL")
242		end
243	end
244	for index = i, #frame.icons do frame.icons[index]:Hide() end
245end
246
247--Color the castbar depending on if we can interrupt or not,
248--also resize it as nameplates somehow manage to resize some frames when they reappear after being hidden
249local function UpdateCastbar(frame)
250	frame:ClearAllPoints()
251	frame:SetSize(cbWidth, cbHeight)
252	frame:SetPoint('TOP', frame:GetParent().hp, 'BOTTOM', 0, -8)
253	frame:GetStatusBarTexture():SetHorizTile(true)
254	if(frame.shield:IsShown()) then
255		frame:SetStatusBarColor(0.78, 0.25, 0.25, 1)
256	end
257end	
258
259--Determine whether or not the cast is Channelled or a Regular cast so we can grab the proper Cast Name
260local function UpdateCastText(frame, curValue)
261	local minValue, maxValue = frame:GetMinMaxValues()
262
263	if UnitChannelInfo("target") then
264		frame.time:SetFormattedText("%.1f ", curValue)
265		frame.name:SetText(select(1, (UnitChannelInfo("target"))))
266	end
267
268	if UnitCastingInfo("target") then
269		frame.time:SetFormattedText("%.1f ", maxValue - curValue)
270		frame.name:SetText(select(1, (UnitCastingInfo("target"))))
271	end
272end
273
274--Sometimes castbar likes to randomly resize
275local OnValueChanged = function(self, curValue)
276	UpdateCastText(self, curValue)
277	if self.needFix then
278		UpdateCastbar(self)
279		self.needFix = nil
280	end
281end
282
283--Sometimes castbar likes to randomly resize
284local OnSizeChanged = function(self)
285	self.needFix = true
286end
287
288--We need to reset everything when a nameplate it hidden, this is so theres no left over data when a nameplate gets reshown for a differant mob.
289local function OnHide(frame)
290	frame.hp:SetStatusBarColor(frame.hp.rcolor, frame.hp.gcolor, frame.hp.bcolor)
291	frame.overlay:Hide()
292	frame.cb:Hide()
293	frame.unit = nil
294	frame.guid = nil
295	frame.hasClass = nil
296	frame.isFriendly = nil
297	frame.hp.rcolor = nil
298	frame.hp.gcolor = nil
299	frame.hp.bcolor = nil
300	if frame.icons then
301		for _,icon in ipairs(frame.icons) do
302			icon:Hide()
303		end
304	end	
305	
306	frame:SetScript("OnUpdate",nil)
307end
308
309--Color the nameplate to 'Our' style instead of using blizzards ugly colors.
310local function Colorize(frame)
311	local r,g,b = frame.healthOriginal:GetStatusBarColor()
312	
313	for class, color in pairs(RAID_CLASS_COLORS) do
314		local r, g, b = floor(r*100+.5)/100, floor(g*100+.5)/100, floor(b*100+.5)/100
315		if RAID_CLASS_COLORS[class].r == r and RAID_CLASS_COLORS[class].g == g and RAID_CLASS_COLORS[class].b == b then
316			frame.hasClass = true
317			frame.isFriendly = false
318			frame.hp:SetStatusBarColor(unpack(T.oUF_colors.class[class]))
319			return
320		end
321	end
322	
323	if g+b == 0 then -- hostile
324		r,g,b = unpack(T.oUF_colors.reaction[1])
325		frame.isFriendly = false
326	elseif r+b == 0 then -- friendly npc
327		r,g,b = unpack(T.oUF_colors.power["MANA"])
328		frame.isFriendly = true
329	elseif r+g > 1.95 then -- neutral
330		r,g,b = unpack(T.oUF_colors.reaction[4])
331		frame.isFriendly = false
332	elseif r+g == 0 then -- friendly player
333		r,g,b = unpack(T.oUF_colors.reaction[5])
334		frame.isFriendly = true
335	else -- enemy player
336		frame.isFriendly = false
337	end
338	frame.hasClass = false
339	
340	frame.hp:SetStatusBarColor(r,g,b)
341end
342
343--HealthBar OnShow, use this to set variables for the nameplate, also size the healthbar here because it likes to lose it's
344--size settings when it gets reshown
345local function UpdateObjects(frame)
346	local frame = frame:GetParent()
347	
348	local r, g, b = frame.hp:GetStatusBarColor()
349
350	--Have to reposition this here so it doesnt resize after being hidden
351	frame.hp:ClearAllPoints()
352	frame.hp:SetSize(hpWidth, hpHeight)	
353	frame.hp:SetPoint('TOP', frame, 'TOP', 0, -15)
354	frame.hp:GetStatusBarTexture():SetHorizTile(true)
355
356	--Match values
357	frame.hp:SetMinMaxValues(frame.healthOriginal:GetMinMaxValues())
358	frame.hp:SetValue(frame.healthOriginal:GetValue())
359	frame.healthOriginal:SetScript("OnValueChanged", function()
360		frame.hp:SetMinMaxValues(frame.healthOriginal:GetMinMaxValues())
361		frame.hp:SetValue(frame.healthOriginal:GetValue())
362	end)
363	
364	--Colorize Plate
365	Colorize(frame)
366	frame.hp.rcolor, frame.hp.gcolor, frame.hp.bcolor = frame.hp:GetStatusBarColor()
367	frame.hp.hpbg:SetTexture(frame.hp.rcolor, frame.hp.gcolor, frame.hp.bcolor, 0.25)
368	SetVirtualBorder(frame.hp, unpack(C["media"].bordercolor))
369	if C["nameplate"].enhancethreat == true then
370		frame.hp.name:SetTextColor(frame.hp.rcolor, frame.hp.gcolor, frame.hp.bcolor)
371	end
372	
373	--Set the name text
374	frame.hp.name:SetText(frame.hp.oldname:GetText())
375	
376	--Setup level text
377	local level, elite, mylevel = tonumber(frame.hp.oldlevel:GetText()), frame.hp.elite:IsShown(), UnitLevel("player")
378	frame.hp.level:ClearAllPoints()
379	if C["nameplate"].showhealth == true then
380		frame.hp.level:SetPoint("RIGHT", frame.hp, "RIGHT", 2, 1)
381	else
382		frame.hp.level:SetPoint("RIGHT", frame.hp, "LEFT", -1, 1)
383	end
384	
385	frame.hp.level:SetTextColor(frame.hp.oldlevel:GetTextColor())
386	if frame.hp.boss:IsShown() then
387		frame.hp.level:SetText("??")
388		frame.hp.level:SetTextColor(0.8, 0.05, 0)
389		frame.hp.level:Show()
390	elseif not elite and level == mylevel then
391		frame.hp.level:Hide()
392	else
393		frame.hp.level:SetText(level..(elite and "+" or ""))
394		frame.hp.level:Show()
395	end
396	
397	frame.overlay:ClearAllPoints()
398	frame.overlay:SetAllPoints(frame.hp)
399	
400	-- Aura tracking
401	if C["nameplate"].trackdebuffs == true or C["nameplate"].trackcc == true then
402		if frame.icons then return end
403		frame.icons = CreateFrame("Frame",nil,frame)
404		frame.icons:SetPoint("BOTTOMRIGHT",frame.hp,"TOPRIGHT", 0, FONTSIZE+5)
405		frame.icons:SetWidth(20 + hpWidth)
406		frame.icons:SetHeight(25)
407		frame.icons:SetFrameLevel(frame.hp:GetFrameLevel()+2)
408		frame:RegisterEvent("UNIT_AURA")
409		frame:HookScript("OnEvent", OnAura)
410	end	
411
412	HideObjects(frame)
413end
414
415--This is where we create most 'Static' objects for the nameplate, it gets fired when a nameplate is first seen.
416local function SkinObjects(frame)
417	local oldhp, cb = frame:GetChildren()
418	local threat, hpborder, overlay, oldname, oldlevel, bossicon, raidicon, elite = frame:GetRegions()
419	local _, cbborder, cbshield, cbicon = cb:GetRegions()
420
421	--Health Bar
422	frame.healthOriginal = oldhp
423	local hp = CreateFrame("Statusbar", nil, frame)
424	hp:SetFrameLevel(oldhp:GetFrameLevel())
425	hp:SetFrameStrata(oldhp:GetFrameStrata())
426	hp:SetStatusBarTexture(TEXTURE)
427	CreateVirtualFrame(hp)
428	
429	--Create Level
430	hp.level = hp:CreateFontString(nil, "OVERLAY")
431	hp.level:SetFont(FONT, FONTSIZE, FONTFLAG)
432	hp.level:SetShadowColor(0, 0, 0, 0.4)
433	hp.level:SetTextColor(1, 1, 1)
434	hp.level:SetShadowOffset(T.mult, -T.mult)	
435	hp.oldlevel = oldlevel
436	hp.boss = bossicon
437	hp.elite = elite
438	
439	--Create Health Text
440	if C["nameplate"].showhealth == true then
441		hp.value = hp:CreateFontString(nil, "OVERLAY")	
442		hp.value:SetFont(FONT, FONTSIZE, FONTFLAG)
443		hp.value:SetShadowColor(0, 0, 0, 0.4)
444		hp.value:SetPoint("CENTER", 0, 1)
445		hp.value:SetTextColor(1,1,1)
446		hp.value:SetShadowOffset(T.mult, -T.mult)
447	end
448	
449	--Create Name Text
450	hp.name = hp:CreateFontString(nil, 'OVERLAY')
451	hp.name:SetPoint('BOTTOMLEFT', hp, 'TOPLEFT', -10, 3)
452	hp.name:SetPoint('BOTTOMRIGHT', hp, 'TOPRIGHT', 10, 3)
453	hp.name:SetFont(FONT, FONTSIZE, FONTFLAG)
454	hp.name:SetShadowColor(0, 0, 0, 0.4)
455	hp.name:SetShadowOffset(T.mult, -T.mult)
456	hp.oldname = oldname
457
458	hp.hpbg = hp:CreateTexture(nil, 'BORDER')
459	hp.hpbg:SetAllPoints(hp)
460	hp.hpbg:SetTexture(1,1,1,0.25) 		
461	
462	hp:HookScript('OnShow', UpdateObjects)
463	frame.hp = hp
464	
465	--Cast Bar
466	cb:SetFrameLevel(1)
467	cb:SetStatusBarTexture(TEXTURE)
468	CreateVirtualFrame(cb)
469	
470	--Create Cast Time Text
471	cb.time = cb:CreateFontString(nil, "ARTWORK")
472	cb.time:SetPoint("RIGHT", cb, "LEFT", -1, 0)
473	cb.time:SetFont(FONT, FONTSIZE, FONTFLAG)
474	cb.time:SetShadowColor(0, 0, 0, 0.4)
475	cb.time:SetTextColor(1, 1, 1)
476	cb.time:SetShadowOffset(T.mult, -T.mult)
477
478	--Create Cast Name Text
479	cb.name = cb:CreateFontString(nil, "ARTWORK")
480	cb.name:SetPoint("TOP", cb, "BOTTOM", 0, -3)
481	cb.name:SetFont(FONT, FONTSIZE, FONTFLAG)
482	cb.name:SetTextColor(1, 1, 1)
483	cb.name:SetShadowColor(0, 0, 0, 0.4)
484	cb.name:SetShadowOffset(T.mult, -T.mult)		
485	
486	--Setup CastBar Icon
487	cbicon:ClearAllPoints()
488	cbicon:SetPoint("TOPLEFT", hp, "TOPRIGHT", 8, 0)		
489	cbicon:SetSize(iconSize, iconSize)
490	cbicon:SetTexCoord(.07, .93, .07, .93)
491	cbicon:SetDrawLayer("OVERLAY")
492	cb.icon = cbicon
493	CreateVirtualFrame(cb, cb.icon)
494	
495	cb.shield = cbshield
496	cbshield:ClearAllPoints()
497	cbshield:SetPoint("TOP", cb, "BOTTOM")
498	cb:HookScript('OnShow', UpdateCastbar)
499	cb:HookScript('OnSizeChanged', OnSizeChanged)
500	cb:HookScript('OnValueChanged', OnValueChanged)			
501	frame.cb = cb
502	
503	--Highlight
504	overlay:SetTexture(1,1,1,0.15)
505	overlay:SetAllPoints(hp)	
506	frame.overlay = overlay
507
508	--Reposition and Resize RaidIcon
509	raidicon:ClearAllPoints()
510	raidicon:SetPoint("BOTTOM", hp, "TOP", 0, 16)
511	raidicon:SetSize(iconSize*1.4, iconSize*1.4)
512	raidicon:SetTexture([[Interface\AddOns\Tukui\medias\textures\raidicons.blp]])
513	frame.raidicon = raidicon
514	
515	--Hide Old Stuff
516	QueueObject(frame, oldhp)
517	QueueObject(frame, oldlevel)
518	QueueObject(frame, threat)
519	QueueObject(frame, hpborder)
520	QueueObject(frame, cbshield)
521	QueueObject(frame, cbborder)
522	QueueObject(frame, oldname)
523	QueueObject(frame, bossicon)
524	QueueObject(frame, elite)
525	
526	UpdateObjects(hp)
527	UpdateCastbar(cb)
528	
529	frame:HookScript('OnHide', OnHide)
530	frames[frame] = true
531end
532
533--Create our blacklist for nameplates, so prevent a certain nameplate from ever showing
534local function CheckBlacklist(frame, ...)
535	if T.PlateBlacklist[frame.hp.name:GetText()] then
536		frame:SetScript("OnUpdate", function() end)
537		frame.hp:Hide()
538		frame.cb:Hide()
539		frame.overlay:Hide()
540		frame.hp.oldlevel:Hide()
541	end
542end
543
544--When becoming intoxicated blizzard likes to re-show the old level text, this should fix that
545local function HideDrunkenText(frame, ...)
546	if frame and frame.hp.oldlevel and frame.hp.oldlevel:IsShown() then
547		frame.hp.oldlevel:Hide()
548	end
549end
550
551--Force the name text of a nameplate to be behind other nameplates unless it is our target
552local function AdjustNameLevel(frame, ...)
553	if UnitName("target") == frame.hp.name:GetText() and frame:GetAlpha() == 1 then
554		frame.hp.name:SetDrawLayer("OVERLAY")
555	else
556		frame.hp.name:SetDrawLayer("BORDER")
557	end
558end
559
560--Health Text, also border coloring for certain plates depending on health
561local function ShowHealth(frame, ...)
562	-- show current health value
563	local minHealth, maxHealth = frame.healthOriginal:GetMinMaxValues()
564	local valueHealth = frame.healthOriginal:GetValue()
565	local d =(valueHealth/maxHealth)*100
566	
567	if C["nameplate"].showhealth == true then
568		frame.hp.value:SetText(T.ShortValue(valueHealth).." - "..(string.format("%d%%", math.floor((valueHealth/maxHealth)*100))))
569	end
570			
571	--Setup frame shadow to change depending on enemy players health, also setup targetted unit to have white shadow
572	if frame.hasClass == true or frame.isFriendly == true then
573		if(d <= 50 and d >= 20) then
574			SetVirtualBorder(frame.hp, 1, 1, 0)
575		elseif(d < 20) then
576			SetVirtualBorder(frame.hp, 1, 0, 0)
577		else
578			SetVirtualBorder(frame.hp, unpack(C["media"].bordercolor))
579		end
580	elseif (frame.hasClass ~= true and frame.isFriendly ~= true) and C["nameplate"].enhancethreat == true then
581		SetVirtualBorder(frame.hp, unpack(C["media"].bordercolor))
582	end
583end
584
585--Scan all visible nameplate for a known unit.
586local function CheckUnit_Guid(frame, ...)
587	--local numParty, numRaid = GetNumPartyMembers(), GetNumRaidMembers()
588	if UnitExists("target") and frame:GetAlpha() == 1 and UnitName("target") == frame.hp.name:GetText() then
589		frame.guid = UnitGUID("target")
590		frame.unit = "target"
591		OnAura(frame, "target")
592	elseif frame.overlay:IsShown() and UnitExists("mouseover") and UnitName("mouseover") == frame.hp.name:GetText() then
593		frame.guid = UnitGUID("mouseover")
594		frame.unit = "mouseover"
595		OnAura(frame, "mouseover")
596	else
597		frame.unit = nil
598	end	
599end
600
601--Attempt to match a nameplate with a GUID from the combat log
602local function MatchGUID(frame, destGUID, spellID)
603	if not frame.guid then return end
604
605	if frame.guid == destGUID then
606		for _,icon in ipairs(frame.icons) do
607			if icon.spellID == spellID then
608				icon:Hide()
609			end
610		end
611	end
612end
613
614--Run a function for all visible nameplates, we use this for the blacklist, to check unitguid, and to hide drunken text
615local function ForEachPlate(functionToRun, ...)
616	for frame in pairs(frames) do
617		if frame:IsShown() then
618			functionToRun(frame, ...)
619		end
620	end
621end
622
623--Check if the frames default overlay texture matches blizzards nameplates default overlay texture
624local select = select
625local function HookFrames(...)
626	for index = 1, select('#', ...) do
627		local frame = select(index, ...)
628		local region = frame:GetRegions()
629		
630		if(not frames[frame] and (frame:GetName() and frame:GetName():find("NamePlate%d")) and region and region:GetObjectType() == 'Texture' and region:GetTexture() == OVERLAY) then
631			SkinObjects(frame)
632			frame.region = region
633		end
634	end
635end
636
637--Core right here, scan for any possible nameplate frames that are Children of the WorldFrame
638CreateFrame('Frame'):SetScript('OnUpdate', function(self, elapsed)
639	if(WorldFrame:GetNumChildren() ~= numChildren) then
640		numChildren = WorldFrame:GetNumChildren()
641		HookFrames(WorldFrame:GetChildren())
642	end
643
644	if(self.elapsed and self.elapsed > 0.2) then
645		ForEachPlate(UpdateThreat, self.elapsed)
646		ForEachPlate(AdjustNameLevel)
647		self.elapsed = 0
648	else
649		self.elapsed = (self.elapsed or 0) + elapsed
650	end
651	
652	ForEachPlate(ShowHealth)
653	ForEachPlate(CheckBlacklist)
654	ForEachPlate(HideDrunkenText)
655	ForEachPlate(CheckUnit_Guid)
656end)
657
658function NamePlates:COMBAT_LOG_EVENT_UNFILTERED(_, event, _, _, sourceName, _, destGUID, _, _, spellID)
659	if event == "SPELL_AURA_REMOVED" then
660		ForEachPlate(MatchGUID, destGUID, spellID)
661	end
662end
663
664--Only show nameplates when in combat
665if C["nameplate"].combat == true then
666	NamePlates:RegisterEvent("PLAYER_REGEN_ENABLED")
667	NamePlates:RegisterEvent("PLAYER_REGEN_DISABLED")
668	
669	function NamePlates:PLAYER_REGEN_ENABLED()
670		SetCVar("nameplateShowEnemies", 0)
671	end
672
673	function NamePlates:PLAYER_REGEN_DISABLED()
674		SetCVar("nameplateShowEnemies", 1)
675	end
676end
677
678NamePlates:RegisterEvent("PLAYER_ENTERING_WORLD")
679function NamePlates:PLAYER_ENTERING_WORLD()
680	if C["nameplate"].combat == true then
681		if InCombatLockdown() then
682			SetCVar("nameplateShowEnemies", 1)
683		else
684			SetCVar("nameplateShowEnemies", 0)
685		end
686	end
687	
688	if C["nameplate"].enable == true and C["nameplate"].enhancethreat == true then
689		SetCVar("threatWarning", 3)
690	end
691	
692	SetCVar("bloatthreat", 0)
693	SetCVar("bloattest", 0)
694	SetCVar("bloatnameplates", 0)
695	if T.eyefinity then
696		SetCVar("nameplateMotion", "0")
697		InterfaceOptionsNamesPanelUnitNameplatesMotionDropDown:Kill()
698	end
699end