Quantcast WoWInterface - View Single Post - Azerite bar not showing
View Single Post
09-23-18, 08:15 PM   #1
superfula
A Deviate Faerie Dragon
Join Date: Mar 2006
Posts: 14
Azerite tooltip throwing error when mousing over azerite bar

I'm working on a bar addon that is supposed to place an xp/rep bar below the minimap and then an azerite bar just below that. I am able to get both bars to show, however I'm down to one last issue. The azerite tooltip that should show when you mouseover the azerite bar gives this error:

Code:
30x modules/exp.lua:255: bad argument #1 to 'format' (string expected, got nil)
[C]: in function `format'
modules/exp.lua:255: in function <modules/exp.lua:248>
modules/exp.lua:280: in function <modules/exp.lua:280>

Locals:
(*temporary) = "Level %s (%s Artifact Power to next level)"
(*temporary) = nil
(*temporary) = nil
(*temporary) = "string expected, got nil"
Full addon code.

Code:
local SCALE			= 1
--local WIDTH 			= 348
local WIDTH 		= 236
local HEIGHT 		= 4
local _, CLASS 		= UnitClass('player')
local COLOR			= CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[CLASS] or RAID_CLASS_COLORS[CLASS]
--local POSITION		= {'CENTER', UIParent, 'BOTTOM', 0, 4}
local POSITION		= {'TOP', Minimap, 'BOTTOM', 0, 17}
local OFFSET		= -13
--local TIP				= {'TOPRIGHT', UIParent, -275, -235}
local TIP			= {'TOPRIGHT', UIParent, -275, -235}
local TEXTURE 		= [[Interface\AddOns\LynExperience\assets\statusbar]]
local CLASSCOLOR 	= CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[CLASS] or RAID_CLASS_COLORS[CLASS]

f = CreateFrame('Frame', nil, UIParent)
f:SetPoint(POSITION[1], POSITION[2], POSITION[3], POSITION[4], POSITION[5])
f:SetWidth(WIDTH)
f:SetHeight(HEIGHT)
f:SetScale(SCALE)

-- SETUP BARS
local setBar = function(frame)
	frame:SetStatusBarTexture(TEXTURE)
	frame:SetWidth(WIDTH)
	frame:SetHeight(HEIGHT)
	frame:SetScale(SCALE)
end

local setBackdrop = function(frame)
	frame.bg = CreateFrame('Frame', nil, frame)
	frame.bg:SetBackdrop({
		bgFile = [[Interface/Buttons/WHITE8X8]],
		tiled = false,
		insets = {left = 0, right = 0, top = 0, bottom = 0}
	})
	frame.bg:SetPoint('TOPLEFT', frame, 0, 0)
	frame.bg:SetPoint('BOTTOMRIGHT', frame, 0, 0)
	frame.bg:SetFrameLevel(1)
	frame.bg:SetBackdropColor(0, 0, 0, 0.2)

	frame.shadow = CreateFrame('Frame', nil, frame)
	frame.shadow:SetBackdrop({
		bgFile = [[Interface\Tooltips\UI-Tooltip-Background]],
		tiled = false,
		insets = {left = 0, right = 0, top = 0, bottom = 0}
	})
	frame.shadow:SetPoint('TOPLEFT', frame, -3, 3)
	frame.shadow:SetPoint('BOTTOMRIGHT', frame, 3, -3)
	frame.shadow:SetFrameLevel(0)
	frame.shadow:SetBackdropColor(0, 0, 0, 0)
end

local exp = CreateFrame('StatusBar', nil, f, 'AnimatedStatusBarTemplate')
setBar(exp)
exp:SetFrameLevel(4)
exp:SetStatusBarColor(.4, .1, .6)
exp:SetAnimatedTextureColors(.4, .1, .6)
exp:SetPoint(POSITION[1], POSITION[2], POSITION[3], POSITION[4], POSITION[5])
setBackdrop(exp)

local rest = CreateFrame('StatusBar', nil, xp)
setBar(rest)
rest:SetFrameLevel(3)
rest:EnableMouse(false)
rest:SetStatusBarColor(.2, .4, .8)
rest:SetAllPoints(exp)

local azerite = CreateFrame('StatusBar', nil, f, 'AnimatedStatusBarTemplate')
setBar(azerite)
azerite:SetFrameLevel(4)
azerite:SetStatusBarColor(.9, .8, .6)
azerite:SetAnimatedTextureColors(.9, .8, .6)
azerite:SetPoint(POSITION[1], POSITION[2], POSITION[3], POSITION[4], POSITION[5] + OFFSET)
setBackdrop(azerite)

-- DATA METHODS
local factionStanding = {
	[1] = { name = 'Hated' },
	[2] = { name = 'Hostile' },
	[3] = { name = 'Unfriendly' },
	[4] = { name = 'Neutral' },
	[5] = { name = 'Friendly' },
	[6] = { name = 'Honored' },
	[7] = { name = 'Revered' },
	[8] = { name = 'Exalted' },
};

local numberize = function(v)
    if v <= 9999 then return v end
    if v >= 1000000 then
        local value = string.format('%.1fm', v/1000000)
        return value
    elseif v >= 10000 then
        local value = string.format('%.1fk', v/1000)
        return value
    end
end


local exp_update = function()
	if UnitLevel('player') == MAX_PLAYER_LEVEL then
		local name, standing, min, max, cur = GetWatchedFactionInfo()
		if name then
			local faction = FACTION_BAR_COLORS[standing]
			exp:SetStatusBarColor(faction.r, faction.g, faction.b)
			exp:SetAnimatedTextureColors(faction.r, faction.g, faction.b)
			--print(cur, min, max, cur-min, 0, max-min)
			exp:SetAnimatedValues(cur - min, 0, max - min, standing)
			-- xp:SetMinMaxValues(min, max)
			-- xp:SetValue(cur)

			rest:SetMinMaxValues(0, 1)
			rest:SetValue(0)

			exp:Show()
			rest:Show()
			return
		end

		--xp:SetAnimatedValues(0, 0, 1, 1)
		exp:Hide()
		rest:Hide()
		--rest:SetMinMaxValues(0, 1)
		--rest:SetValue(0)
	else
		local c, m, l	= UnitXP('player'), UnitXPMax('player'), UnitLevel('player')
		local p 			= math.ceil(c/m*100)
		local r			= GetXPExhaustion()

		exp:SetAnimatedValues(c, 0, m, l)
		-- xp:SetMinMaxValues(min(0, c), m)
		-- xp:SetValue(c)
		rest:SetMinMaxValues(min(0, c), m)
		rest:SetValue(r and (c + r) or 0)

		exp:Show()
		rest:Show()
	end
end

local showExperienceTooltip = function(self)
	if UnitLevel('player') == MAX_PLAYER_LEVEL then
		local name, standing, min, max, cur = GetWatchedFactionInfo()
		if name then
			local faction = FACTION_BAR_COLORS[standing]

			GameTooltip:SetOwner(self, 'ANCHOR_NONE')
			GameTooltip:SetPoint(TIP[1], TIP[2], TIP[3], TIP[4], TIP[5])

			GameTooltip:AddLine(name, faction.r, faction.g, faction.b)
			GameTooltip:AddLine(factionStanding[standing].name, 1, 1, 1)
			GameTooltip:AddLine(cur-min.."/"..max-min, 1, 1, 1)

			GameTooltip:Show()
		end
	else
		local xpc, xpm, xpr = UnitXP('player'), UnitXPMax('player'), GetXPExhaustion('player')

		GameTooltip:SetOwner(self, 'ANCHOR_NONE')
		GameTooltip:SetPoint(TIP[1], TIP[2], TIP[3], TIP[4], TIP[5])

		GameTooltip:AddLine('Level '..UnitLevel('player'), COLOR.r, COLOR.g, COLOR.b)
		GameTooltip:AddLine((numberize(xpc)..'/'..numberize(xpm)..' ('..floor((xpc/xpm)*100) ..'%)'), 1, 1, 1)
		if xpr then
			GameTooltip:AddLine(numberize(xpr)..' ('..floor((xpr/xpm)*100) ..'%)', .2, .4, .8)
		end

		GameTooltip:Show()
	end
end

local azerite_update = function(self)
local azeriteItemLocation = C_AzeriteItem.FindActiveAzeriteItem()
--if C_AzeriteItem.HasActiveAzeriteItem() then

	if azeriteItemLocation then
		--local azeriteItem = Item:CreateFromItemLocation(azeriteItemLocation);
		--local azeriteItemName = azeriteItem:GetItemName()

		local xp, totalLevelXP = C_AzeriteItem.GetAzeriteItemXPInfo(azeriteItemLocation)
		local currentLevel = C_AzeriteItem.GetPowerLevel(azeriteItemLocation)
		local xpToNextLevel = totalLevelXP - xp
		
		if not azerite:IsShown() then
			azerite:Show()
		end

		azerite:SetAnimatedValues(xp, 0, totalLevelXP)
--		azerite:SetMinMaxValues(0, totalLevelXP)
--		azerite:SetValue(xp)
--		azerite:Show()

--		local y
--		if UnitLevel'player' < MAX_PLAYER_LEVEL or faction then
--			y = POSITION[5] + OFFSET
--		else
--			y = POSITION[5]
--		end
--		
--		azerite:SetPoint(POSITION[1], POSITION[2], POSITION[3], POSITION[4], y)
	else
		if azerite:IsShown() then
			azerite:Hide()
		end
	end
	if event == 'AZERITE_ITEM_EXPERIENCE_CHANGED' or event == 'PLAYER_ENTERING_WORLD' then
		if not azerite:IsShown() then
			azerite:Show()
		end
	end
end
		


local showAzeriteTooltip = function(self)
	local azeriteItemLocation = C_AzeriteItem.FindActiveAzeriteItem();
	local azeriteItem = Item:CreateFromItemLocation(azeriteItemLocation);
    local azeriteItemName = azeriteItem:GetItemName();
	
	GameTooltip:SetOwner(self, 'ANCHOR_NONE')
	GameTooltip:SetPoint(TIP[1], TIP[2], TIP[3], TIP[4], TIP[5])
	GameTooltip:SetText(AZERITE_POWER_TOOLTIP_TITLE:format(currentLevel, xpToNextLevel), HIGHLIGHT_FONT_COLOR:GetRGB());
    GameTooltip:AddLine(AZERITE_POWER_TOOLTIP_BODY:format(azeriteItemName));

	GameTooltip:Show()
end

-- events
exp:RegisterEvent('PLAYER_LEVEL_UP')
exp:RegisterEvent('PLAYER_XP_UPDATE')
exp:RegisterEvent('UPDATE_EXHAUSTION')
exp:RegisterEvent('PLAYER_ENTERING_WORLD')
exp:RegisterEvent('MODIFIER_STATE_CHANGED')
exp:RegisterEvent('UPDATE_FACTION')
exp:RegisterEvent('ADDON_LOADED')
exp:SetScript('OnEvent', exp_update)
exp:SetScript('OnEnter', function() showExperienceTooltip(exp) end)
exp:SetScript('OnLeave', function() GameTooltip:Hide() end)

azerite:RegisterEvent('PLAYER_ENTERING_WORLD')
azerite:RegisterEvent('AZERITE_ITEM_EXPERIENCE_CHANGED')
azerite:RegisterEvent('PLAYER_EQUIPMENT_CHANGED')
azerite:RegisterEvent('PLAYER_LEVEL_UP')
azerite:RegisterEvent('UPDATE_FACTION')
azerite:RegisterEvent('ADDON_LOADED')
azerite:SetScript('OnEvent', azerite_update)
azerite:SetScript('OnEnter', function() showAzeriteTooltip(azerite) end)
azerite:SetScript('OnLeave', function() GameTooltip:Hide() end)

hooksecurefunc("SetWatchedFactionIndex", function(self)
	exp_update()
    azerite_update()
end)

Last edited by superfula : 09-27-18 at 03:20 PM.
  Reply With Quote