View Single Post
07-11-15, 12:59 PM   #7
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
I actually started to make this some time ago. I think it should work, but I never really bothered finishing it. Not sure if it's of any use to you. I never implemented hiding the default frame it seems. Most of it is copied from the UI source.

Code:
local items = {
	[19183] = true, -- Hourglass Sand
	[24494] = true, -- Tears of the Goddess
	[46029] = true, -- Magnetic Core
}

local bar = ExtraActionBarFrame

local button = CreateFrame("CheckButton", "ExtraExtraActionButton", ExtraActionBarFrame, "ExtraActionButtonTemplate")
button:SetPoint("CENTER")
button:SetAttribute("type", "item")
button.style:SetTexture("Interface\\ExtraButton\\Default")

function button:SetItem(itemID)
	bar:Show()
	bar.outro:Stop()
	bar.intro:Play()
	
	self:SetAttribute("item", "item:"..itemID)
	self.item = itemID
	self.icon:SetTexture(GetItemIcon(itemID))
end

button:RegisterEvent("BAG_UPDATE_COOLDOWN")
button:RegisterEvent("BAG_UPDATE")
button:RegisterEvent("SPELL_UPDATE_USABLE")
button:RegisterEvent("SPELL_UPDATE_COOLDOWN")
button:RegisterEvent("CURRENT_SPELL_CAST_CHANGED")

button:SetScript("OnAttributeChanged", function(self, name, value)
	-- if name == "item" then
		-- self.item = value
	-- end
end)

button:SetScript("OnEvent", function(self)
	local item = self.item
	if not item then return end
	local start, duration, enable = GetItemCooldown(item)
	CooldownFrame_SetTimer(self.cooldown, start, duration, enable)
	if (not item or duration > 0 and enable == 0) then
		self.icon:SetVertexColor(0.4, 0.4, 0.4)
	else
		self.icon:SetVertexColor(1, 1, 1)
	end
	
	self.icon:SetDesaturated(false)
	
	if (GameTooltip:GetOwner() == self) then
		GameTooltip:SetInventoryItemByID(self.item)
	end
end)

button:SetScript("OnEnter", function(self)
	if GetCVar("UberTooltips") == "1" then
		GameTooltip_SetDefaultAnchor(GameTooltip, self)
	else
		local parent = self:GetParent()
		if parent == MultiBarBottomRight or parent == MultiBarRight or parent == MultiBarLeft then
			GameTooltip:SetOwner(self, "ANCHOR_LEFT")
		else
			GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
		end
	end
	if GameTooltip:SetInventoryItemByID(self.item) then
		-- self.UpdateTooltip = ActionButton_SetTooltip
	-- else
		-- self.UpdateTooltip = nil
	end
end)

button:SetScript("OnUpdate", function(self, elapsed)
	if ( ActionButton_IsFlashing(self) ) then
		local flashtime = self.flashtime;
		flashtime = flashtime - elapsed;
		
		if ( flashtime <= 0 ) then
			local overtime = -flashtime;
			if ( overtime >= ATTACK_BUTTON_FLASH_TIME ) then
				overtime = 0;
			end
			flashtime = ATTACK_BUTTON_FLASH_TIME - overtime;

			local flashTexture = _G[self:GetName().."Flash"];
			if ( flashTexture:IsShown() ) then
				flashTexture:Hide();
			else
				flashTexture:Show();
			end
		end
		
		self.flashtime = flashtime;
	end
	
	-- Handle range indicator
	local rangeTimer = self.rangeTimer
	if rangeTimer then
		rangeTimer = rangeTimer - elapsed

		if rangeTimer <= 0 then
			local count = _G[self:GetName().."HotKey"]
			local valid = IsItemInRange(self.item)
			if count:GetText() == RANGE_INDICATOR then
				if valid == 0 then
					count:Show()
					count:SetVertexColor(1.0, 0.1, 0.1)
				elseif valid == 1 then
					count:Show()
					count:SetVertexColor(0.6, 0.6, 0.6)
				else
					count:Hide()
				end
			else
				if valid == 0 then
					count:SetVertexColor(1.0, 0.1, 0.1)
				else
					count:SetVertexColor(0.6, 0.6, 0.6)
				end
			end
			rangeTimer = TOOLTIP_UPDATE_TIME
		end
		
		self.rangeTimer = rangeTimer
	end
end)
__________________
Grab your sword and fight the Horde!
  Reply With Quote