View Single Post
07-29-13, 12:13 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I'd guess your problem is that the alpha of the micro button is getting changed when it's enabled or disabled, and that state is getting updated after your code runs.

To solve this, you should hook the OnEnable and OnDisable methods for each button as well. When a button is enabled or disabled, check for mouseover, and re-set the alpha accordingly.

On a side note, there's no reason to ever use ipairs, as it is significantly slower than a simpler i = 1, #t loop, and since the contents of the MICRO_BUTTONS table never changes, you can save yourself some table lookups by keeping a local table that contains the button objects themselves, rather than their global names. Also, you may want to distinguish between enabled and disabled micro buttons in your code.

Code:
local MicroButtons = {}

local function resetAlpha(self)
	for i = 1, #MicroButtons do
		if MicroButtons[i]:IsMouseOver() then
			return self:SetAlpha(self:IsEnabled() and 1 or 0.5)
		end
	end
	self:SetAlpha(0)
end	

local function showFoo(self)
	for i = 1, #MicroButtons do
		local v = MicroButtons[i]
		v:SetAlpha(v:IsEnabled() and 1 or 0.5)
	end
end

local function hideFoo(self)
	for i = 1, #MicroButtons do
		MicroButtons[i]:SetAlpha(0)
	end
end

for i = 1, #MICRO_BUTTONS do
	local v = _G[MICRO_BUTTONS[i]]
	v:HookScript("OnEnable", resetAlpha)
	v:HookScript("OnDisable", resetAlpha)
	v:HookScript("OnEnter", showFoo)
	v:HookScript("OnLeave", hideFoo)
	MicroButtons[i] = v
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 07-29-13 at 12:50 AM.
  Reply With Quote