On nUI for the tooltip I have this ( plus a few others ) which seems to be similar to what you were trying to display.
Code:
GameTooltip:SetText(
AZERITE_POWER_TOOLTIP_TITLE:format(level, xpToNextLevel),
HIGHLIGHT_FONT_COLOR:GetRGB()
)
For the rest of the code nUI has its own statusbar functionality but it is similar to yours, this is the main block, it only gets executed if the itemLocation is valid.
Code:
local xp, totalXP = C_AzeriteItem.GetAzeriteItemXPInfo(azeriteItemLocation);
local currentLevel = C_AzeriteItem.GetPowerLevel(azeriteItemLocation);
local xpToNextLevel = totalXP - xp;
local pct = xp / totalXP
I also have this hefty block of code that identifies which azerite items you have and if they have powers not applied and creates the tooltip.
Code:
frame:SetScript( "OnEnter",
function()
local azeriteItemLocation = C_AzeriteItem.FindActiveAzeriteItem()
local azeriteItem = azeriteItemLocation and Item:CreateFromItemLocation(azeriteItemLocation) or nil
local azeriteItemName = azeriteItem and azeriteItem:GetItemName() or nil
local neckItemLocation = ItemLocation:CreateFromEquipmentSlot(Enum.InventoryType.IndexNeckType)
local headItemLocation = ItemLocation:CreateFromEquipmentSlot(Enum.InventoryType.IndexHeadType)
local shoulderItemLocation = ItemLocation:CreateFromEquipmentSlot(Enum.InventoryType.IndexShoulderType)
local chestItemLocation = ItemLocation:CreateFromEquipmentSlot(Enum.InventoryType.IndexChestType)
local hasNeckItem = C_Item.DoesItemExist(neckItemLocation)
local hasHeadItem = C_Item.DoesItemExist(headItemLocation)
local hasShoulderItem = C_Item.DoesItemExist(shoulderItemLocation)
local hasChestItem = C_Item.DoesItemExist(chestItemLocation)
local headIsAzeriteEmpowered = hasHeadItem and C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItem(headItemLocation)
local shoulderIsAzeriteEmpowered = hasShoulderItem and C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItem(shoulderItemLocation)
local chestIsAzeriteEmpowered = hasChestItem and C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItem(chestItemLocation)
local headItem = headItemLocation and headIsAzeriteEmpowered and Item:CreateFromItemLocation(headItemLocation) or nil
local shoulderItem = shoulderItemLocation and shoulderIsAzeriteEmpowered and Item:CreateFromItemLocation(shoulderItemLocation) or nil
local chestItem = chestItemLocation and chestIsAzeriteEmpowered and Item:CreateFromItemLocation(chestItemLocation) or nil
local headItemName = headItem and headItem:GetItemName() or ""
local shoulderItemName = shoulderItem and shoulderItem:GetItemName() or ""
local chestItemName = chestItem and chestItem:GetItemName() or ""
local azeritePowerAvailable = " (" .. AZERITE_ITEM_LEVELED_UP_TOAST_UNLOCKED_MULTIPLE .. ")"
local headHasPowers = headItem and C_AzeriteEmpoweredItem.HasAnyUnselectedPowers(headItemLocation) and azeritePowerAvailable or ""
local shoulderHasPowers = shoulderItem and C_AzeriteEmpoweredItem.HasAnyUnselectedPowers(shoulderItemLocation) and azeritePowerAvailable or ""
local chestHasPowers = chestItem and C_AzeriteEmpoweredItem.HasAnyUnselectedPowers(chestItemLocation) and azeritePowerAvailable or ""
local isEquippedAzeriteItem = hasNeckItem and (C_Item.GetItemInventoryType(azeriteItemLocation) == Enum.InventoryType.IndexNeckType)
local mustEquip = (not hasNeckItem or not isEquippedAzeriteItem) and ERR_MUST_EQUIP_ARTIFACT or ""
GameTooltip:SetOwner( frame );
GameTooltip:ClearLines()
GameTooltip:SetText(AZERITE_POWER_TOOLTIP_TITLE:format(frame.level, frame.xpToNextLevel), HIGHLIGHT_FONT_COLOR:GetRGB());
GameTooltip:AddLine(AZERITE_POWER_TOOLTIP_BODY:format(azeriteItemName));
GameTooltip:AddLine(mustEquip,HIGHLIGHT_FONT_COLOR:GetRGB())
GameTooltip:AddLine(headItemName .. headHasPowers ,HIGHLIGHT_FONT_COLOR:GetRGB())
GameTooltip:AddLine(shoulderItemName .. shoulderHasPowers ,HIGHLIGHT_FONT_COLOR:GetRGB())
GameTooltip:AddLine(chestItemName .. chestHasPowers ,HIGHLIGHT_FONT_COLOR:GetRGB())
GameTooltip:Show();
end
);