Thread Tools Display Modes
04-09-17, 05:02 AM   #1
Kupotek
An Aku'mai Servant
 
Kupotek's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 38
Help with AP Watch addon

This addon was made to show AP count in text, but many AP items of different values share the same name... so I was hoping someone could help me do 2 things with this addon...

#1 - remove the text altogether

#2 - have no fallback icon, instead if no AP items are found, display nothing, so the icon only appears if AP items are found...

~*~

Code:
do
	local addon, namespace = ...
	setfenv(1, setmetatable(namespace, { __index = _G }))
end

--config
local TEXT_FMT = "|TInterface/LevelUp/LevelUpTex:0:0:0:0:512:512:370:400:20:50|t%d"
local SIZE = 30
local FALLBACK_ICON = "Interface/Icons/inv_legendary_sigilofpower"

local btn = CreateFrame("Button", "ArtifactWatcherButton", UIParent, "SecureActionButtonTemplate")
btn:SetPoint("CENTER")
btn:SetHeight(SIZE)
btn:SetWidth(SIZE)
btn:SetAttribute("type", "item")

local tex = btn:CreateTexture()
tex:SetAllPoints()
local cd = CreateFrame("Cooldown", nil, btn, "CooldownFrameTemplate")
cd:SetAllPoints()
local fs = btn:CreateFontString()
fs:SetPoint("TOP", btn, "BOTTOM")
fs:SetFontObject("GameFontGreen")

btn:EnableMouse(true)
btn:SetMovable(true)
btn:RegisterForDrag("LeftButton")
btn:SetScript("OnDragStart", function(self) if IsAltKeyDown() then self:StartMoving() end end)
btn:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)

btn:RegisterEvent("BAG_UPDATE_COOLDOWN")
btn:RegisterEvent("SPELL_UPDATE_COOLDOWN") --because BAG_UPDATE_COOLDOWN doesn't fire for GCDs from item use
btn:RegisterEvent("BAG_UPDATE_DELAYED")
btn:RegisterEvent("PLAYER_REGEN_ENABLED")

local dirty
btn:SetScript("OnEvent", function(_, event)
	if event == "BAG_UPDATE_COOLDOWN" or event == "SPELL_UPDATE_COOLDOWN" then
		if btn.itemID then
			CooldownFrame_Set(cd, GetItemCooldown(btn.itemID))
		end
	else
		if event == "BAG_UPDATE_DELAYED" and InCombatLockdown() then
			dirty = true
		elseif event == "BAG_UPDATE_DELAYED" or dirty then --update button info
			dirty = false

			local id, p
			for bag = 0, 4 do --scan for artifact power items
				for slot = 1, GetContainerNumSlots(bag) do
					id = GetContainerItemID(bag, slot)
					p = power[id]
					if p then break	end
				end
				if p then break end
			end

			if p then --item found
				btn.itemID = id
				btn:SetAttribute("item", "item:"..id)
				tex:SetTexture(GetItemIcon(id))
				fs:SetText(TEXT_FMT:format(p))
			else --fallback
				btn.itemID = nil
				btn:SetAttribute("item", nil)
				tex:SetTexture(FALLBACK_ICON)
				fs:SetText("")
			end
		end

		if GameTooltip:IsShown() and GameTooltip:GetOwner() == btn then
			btn:GetScript("OnEnter")(btn) --update tooltip
		end
	end
end)

btn:SetScript("OnEnter", function(self)
	GameTooltip:SetOwner(self, "ANCHOR_TOP")
	if self.itemID then
		GameTooltip:SetItemByID(self.itemID)
	else
		GameTooltip:ClearLines()
		GameTooltip:AddLine("Artifact Watch")
		GameTooltip:AddLine("|cffffffffNo artifacts found|r")
		GameTooltip:AddLine("Alt+drag to move")
	end
	if dirty then
		GameTooltip:AddLine("|cffff0000(Update Out of Combat)|r")
	end
	GameTooltip:Show()
end)
btn:SetScript("OnLeave", function() GameTooltip:Hide() end)
__________________
Panther UI | My Home on the Web

Last edited by Kupotek : 04-09-17 at 11:35 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Help with AP Watch addon

Thread Tools
Display Modes

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