Thread Tools Display Modes
11-05-14, 03:00 PM   #1
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Nameplates

Hey everyone i just returned to WoW!

Im trying to fix my UI currently.

It seems i have an issue with my nameplates, and i really can't figure what the problem is!

If anyone could give me a hand to fix it would be really helpful!

Thanks!


Code:
if AftermathhUI.nameplates.nameplates == false then return end

local AfterNamePlates = CreateFrame('Frame', nil, UIParent)
AfterNamePlates:RegisterEvent('PLAYER_ENTERING_WORLD')
AfterNamePlates:SetScript('OnEvent', function(self, event)
    if event == ('PLAYER_ENTERING_WORLD') then
        SetCVar("bloatthreat", 0)
        SetCVar("bloattest", 0)
        SetCVar("bloatnameplates", 0)
		SetCVar("threatWarning", 3)
        SetCVar("nameplateMotion", 0)
	    SetCVar('ShowClassColorInNameplate', 1)
	end	
end)

local OVERLAY = [[Interface\TargetingFrame\UI-TargetingFrame-Flash]]
local numChildren = -1
local frames = {}

local function QueueObject(parent, object)
	parent.queue = parent.queue or {}
	parent.queue[object] = true
end

local function HideObjects(parent)
	for object in pairs(parent.queue) do
		if(object:GetObjectType() == 'Texture') then
			object:SetTexture(nil)
			object.SetTexture = function() end 
		elseif (object:GetObjectType() == 'FontString') then
			object.ClearAllPoints = function() end
			object.SetFont = function() end
			object.SetPoint = function() end
			object:Hide()
			object.Show = function() end
			object.SetText = function() end
			object.SetShadowOffset = function() end		
		else
			object:Hide()
			object.Show = function() end
		end
	end
end

function round(num, idp)
    if idp and idp > 0 then
        local mult = 10^idp
        return math.floor(num*mult + 0.5) / mult
    end
    return math.floor(num + 0.5)
end

function CoolNumber(num)
	if(num >= 1e6) then
		return round(num/1e6,1).."m"
	elseif(num >= 1e3) then
		return round(num/1e3,1).."k"
	else
		return num
	end
end

local function UpdateFrame(frame)
	if(frame.region:IsShown()) then
		local _, val = frame.region:GetVertexColor()		
		if(val > 0.7) then
			ColorBorder(frame.hp, 1, 1, 0)
		else
			ColorBorder(frame.hp, 1, 0, 0)
		end
	else
		ColorBorder(frame.hp, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor)
	end
	
    local minHealth, maxHealth = frame.healthOriginal:GetMinMaxValues()
    local valueHealth = frame.healthOriginal:GetValue()
	local d =(valueHealth/maxHealth)*100
	if (d < 100) and valueHealth > 1 then
		frame.hp.value:SetText(CoolNumber(valueHealth))
	else
	    frame.hp.value:SetText("")
    end
	
	if(d <= 90 and d >= 50) then
		frame.hp.value:SetTextColor(0, 1, 0)
	elseif(d < 50 and d >= 20) then
		frame.hp.value:SetTextColor(1, 1, 0)
	elseif(d < 20) then
		frame.hp.value:SetTextColor(1, 0, 0)
	else
		frame.hp.value:SetTextColor(1, 1, 1)
	end
end

local function UpdateObjects(frame)
	frame = frame:GetParent()
	frame.hp:SetSize(180, 16)
	frame.hp:ClearAllPoints()
	frame.hp:SetPoint('CENTER', frame)
	
	CreateBorderLight(frame.hp, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 2)

	local r, g, b = frame.hp:GetStatusBarColor()
	local newr, newg, newb
	if g + b == 0 then
	    newr, newg, newb = .25, .25, .25
		frame.hp:SetStatusBarColor(newr, newg, newb)
	elseif r + b == 0 then
	    newr, newg, newb = 0.33, 0.59, 0.33
		frame.hp:SetStatusBarColor(newr, newg, newb)
	elseif r + g == 0 then
	    newr, newg, newb = 0.33, 0.43, 0.63
		frame.hp:SetStatusBarColor(newr, newg, newb)
	elseif 2 - (r + g) < 0.05 and b == 0 then
	    newr, newg, newb = 0.76, 0.73, 0.35
		frame.hp:SetStatusBarColor(newr, newg, newb)
	else
	    newr, newg, newb = r, g, b
		frame.hp:SetStatusBarColor(newr, newg, newb)
	end
	frame.hp:SetStatusBarColor(newr, newg, newb)
	
	local name = frame.oldname:GetText()
	local rn, gn, bn = frame.level:GetTextColor()
	if(frame.boss:IsShown()) then
		frame.name:SetText('|cffff0000??B|r '..frame.oldname:GetText())
	else
		frame.name:SetText(format('|cff%02x%02x%02x', rn*255, gn*255, bn*255)..tonumber(frame.level:GetText())..(frame.elite:IsShown() and '+' or '')..'|r '..frame.oldname:GetText())
	end
 
	HideObjects(frame)
end

local function UpdateCastbar(frame)
	frame:ClearAllPoints()
	frame:SetSize(180, 16)
	frame:SetPoint('TOP', frame:GetParent().hp, 'BOTTOM', 0, -8)
	
	CreateBorderLight(frame, AftermathhUI.media.bordersize, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor, 2)

	if(frame.shield:IsShown()) then
		frame:SetStatusBarColor(1, 0, 1)
		ColorBorder(frame, 1, 0, 1)
	else
	    ColorBorder(frame, AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor)
	end
end	

local function UpdateCastText(frame, curValue)
	local minValue, maxValue = frame:GetMinMaxValues()
	if UnitChannelInfo("target") then
		frame.time:SetFormattedText("%.1fs", curValue)
		frame.name:SetText(select(1, (UnitChannelInfo("target"))))
	end
	if UnitCastingInfo("target") then
		frame.time:SetFormattedText("%.1fs", maxValue - curValue)
		frame.name:SetText(select(1, (UnitCastingInfo("target"))))
	end
end

local function OnValueChanged(self, curValue)
    UpdateCastText(self, curValue)
	if self.needFix then
		UpdateCastbar(self)
		self.needFix = nil
	end
end

local function OnSizeChanged(self)
	self.needFix = true
end

local function SkinObjects(frame)
	local hp, cb = frame:GetChildren()
	local threat, hpborder, overlay, oldname, level, bossicon, raidicon, elite = frame:GetRegions()
	local _, cbborder, cbshield, cbicon = cb:GetRegions()
    local offset = UIParent:GetScale() / hp:GetEffectiveScale()
	
	hp.value = hp:CreateFontString(nil, "OVERLAY")	
	hp.value:SetFont(AftermathhUI.media.font, 14, AftermathhUI.media.fontflag)
	hp.value:SetPoint("LEFT", hp, "RIGHT", 7, 0)
	if AftermathhUI.media.shadowoffset == true then
	    hp.value:SetShadowOffset(1, -1)
	    hp.value:SetShadowColor(0, 0, 0)
	end
	hp:HookScript('OnShow', UpdateObjects)
	hp:HookScript('OnSizeChanged', UpdateObjects)
	hp:SetSatusBarTexture(AftermathhUI.media.texture)
	
	local hpbg = hp:CreateTexture(nil, 'BACKGROUND')
	hpbg:SetPoint('BOTTOMRIGHT', offset, -offset)
	hpbg:SetPoint('TOPLEFT', -offset, offset)
	hpbg:SetTexture(unpack(AftermathhUI.media.backdropcolor))
	
	cb:HookScript('OnShow', UpdateCastbar)
	cb:HookScript('OnSizeChanged', UpdateCastbar)
	cb:HookScript('OnSizeChanged', OnSizeChanged)
	cb:HookScript('OnValueChanged', OnValueChanged)	
	--cb:RegisterEvent('UNIT_SPELLCAST_INTERRUPTIBLE')
	--cb:RegisterEvent('UNIT_SPELLCAST_NOT_INTERRUPTIBLE')
	cb:SetSatusBarTexture(AftermathhUI.media.texture)
	
	local cbbg = cb:CreateTexture(nil, 'BACKGROUND')
	cbbg:SetPoint('BOTTOMRIGHT', offset, -offset)
	cbbg:SetPoint('TOPLEFT', -offset, offset)
    cbbg:SetTexture(unpack(AftermathhUI.media.backdropcolor))
	
	cb.time = cb:CreateFontString(nil, "OVERLAY")
	cb.time:SetPoint('RIGHT', cb, 'RIGHT', -1, 0)
	cb.time:SetFont(AftermathhUI.media.font, 14, AftermathhUI.media.fontflag)
	cb.time:SetTextColor(1, 1, 1)
	if AftermathhUI.media.shadowoffset == true then
	    cb.time:SetShadowOffset(1, -1)
	    cb.time:SetShadowColor(0, 0, 0)
	end	
	cb.name = cb:CreateFontString(nil, "OVERLAY")
	cb.name:SetPoint('LEFT', cb, 3, 0)
    cb.name:SetPoint('RIGHT', cb.time, 'LEFT', -6, 0)
	cb.name:SetJustifyH('LEFT')
	cb.name:SetFont(AftermathhUI.media.font, 12, AftermathhUI.media.fontflag)
	cb.name:SetTextColor(1, 1, 1)
	if AftermathhUI.media.shadowoffset == true then 
	    cb.name:SetShadowOffset(1, -1)
     	cb.name:SetShadowColor(0, 0, 0)
	end
	cbicon:SetDrawLayer("ARTWORK") -- just so we can get my beauty texture over the icon.
	cbicon:ClearAllPoints()
	cbicon:SetPoint('TOPRIGHT', hp, 'TOPLEFT', -8, -4)		
	cbicon:SetSize(30, 30)
	cbicon:SetTexCoord(.07, .93, .07, .93)
	
    local IconOverlay = cb:CreateTexture(nil, 'OVERLAY')
    IconOverlay:SetPoint('TOPLEFT', cbicon, 'TOPLEFT', -3, 3)
    IconOverlay:SetPoint('BOTTOMRIGHT', cbicon, 'BOTTOMRIGHT', 3, -3)
    IconOverlay:SetTexture(AftermathhUI.media.borderlight)
	IconOverlay:SetSize(offset, offset)
	IconOverlay:SetVertexColor(AftermathhUI.bordercolor, AftermathhUI.bordercolor, AftermathhUI.bordercolor)

	local CastbarIconBg = cb:CreateTexture(nil, 'BACKGROUND')
	CastbarIconBg:SetPoint('TOPLEFT', cbicon, 'TOPLEFT',-4, 4)
    CastbarIconBg:SetPoint('BOTTOMRIGHT', cbicon, 'BOTTOMRIGHT', 4, -4)
	CastbarIconBg:SetTexture(AftermathhUI.media.shadow)
	CastbarIconBg:SetVertexColor(0, 0, 0, 1)

	local name = hp:CreateFontString(nil, 'OVERLAY')
	name:SetPoint('BOTTOMLEFT', hp, 'TOPLEFT', 0, 10)
	name:SetPoint('BOTTOMRIGHT', hp, 'TOPRIGHT', 0, -5)
	name:SetFont(AftermathhUI.media.font, 15, AftermathhUI.media.fontflag)
	if AftermathhUI.media.shadowoffset == true then
		name:SetShadowOffset(1, -1)
     	name:SetShadowColor(0, 0, 0)
	end
	
	raidicon:ClearAllPoints()
	raidicon:SetPoint('CENTER', hp, 0, 44)
	raidicon:SetSize(30, 30)
	
	frame.healthOriginal = hp 
	frame.hp = hp
	cb.icon = cbicon
	cb.shield = cbshield
	frame.cb = cb
	frame.name = name
	frame.level = level
	frame.elite = elite
	frame.boss = bossicon
    frame.oldname = oldname	

	QueueObject(frame, threat)
	QueueObject(frame, hpborder)
	QueueObject(frame, cbshield)
	QueueObject(frame, cbborder)
	QueueObject(frame, overlay)
	QueueObject(frame, oldname)
	QueueObject(frame, level)
	QueueObject(frame, bossicon)
	QueueObject(frame, elite)
	
	UpdateObjects(hp)
	UpdateCastbar(cb)
	
	frames[frame] = true
end

local numFrames = 0
local lastUpdate = 0
local index = 1
AfterNamePlates:SetScript('OnUpdate', function(self, elapsed)
    lastUpdate = lastUpdate + elapsed

    if (lastUpdate > 0.1) then
        local newNumFrames = WorldFrame:GetNumChildren()

        if (newNumFrames ~= numFrames) then
            numFrames = newNumFrames

            for i = index, numFrames do
                local frame = select(i, WorldFrame:GetChildren())
                local frameName = frame:GetName()

                if (frameName and frameName:find('NamePlate') and not frame.NewName) then
                    SkinObjects(frame)
                    index = i
                end
            end
        end

        lastUpdate = 0
    end
end)
  Reply With Quote
11-05-14, 03:24 PM   #2
sirann
A Flamescale Wyrmkin
Join Date: Mar 2007
Posts: 142
Originally Posted by Game92 View Post
Code:
if AftermathhUI.nameplates.nameplates == false then return end

local AfterNamePlates = CreateFrame('Frame', nil, UIParent)
AfterNamePlates:RegisterEvent('PLAYER_ENTERING_WORLD')
AfterNamePlates:SetScript('OnEvent', function(self, event)
    if event == ('PLAYER_ENTERING_WORLD') then
        SetCVar("bloatthreat", 0)
        SetCVar("bloattest", 0)
        SetCVar("bloatnameplates", 0)
	SetCVar("threatWarning", 3)
        SetCVar("nameplateMotion", 0)
	SetCVar('ShowClassColorInNameplate', 1)
    end	
end)
Pointless if check, there can only be one event since the frame is only registered for one event, so it can only fire when player is entering world. But what exactly are you seeing occur? Frames not spawning? LUA errors?
  Reply With Quote
11-05-14, 03:47 PM   #3
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Make sure to read http://www.wowinterface.com/forums/s...ad.php?t=46740
Test your nameplates on a low spec machine. Make sure to build them fps save. And no the Blizzard nameplates are not fps save.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
11-05-14, 05:31 PM   #4
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by sirann View Post
Pointless if check, there can only be one event since the frame is only registered for one event, so it can only fire when player is entering world. But what exactly are you seeing occur? Frames not spawning? LUA errors?
There was a few minor errors.. But i solved but they plates would not show up.
  Reply With Quote
11-05-14, 05:32 PM   #5
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by zork View Post
Make sure to read http://www.wowinterface.com/forums/s...ad.php?t=46740
Test your nameplates on a low spec machine. Make sure to build them fps save. And no the Blizzard nameplates are not fps save.
Thank you Zork! Will use your nameplate base code, and build my own. Thanks again for the help!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Nameplates


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off