Thread Tools Display Modes
07-28-13, 06:08 AM   #1
laukond
A Black Drake
Join Date: Dec 2011
Posts: 87
Hide MicroBars Mouseover / Achievement Button

I use this script to hide the micromenu when now mouseovered:

Code:
local function showFoo(self)
	for _, v in ipairs(MICRO_BUTTONS) do
		_G[v]:SetAlpha(1)
	end
end

local function hideFoo(self)
	for _, v in ipairs(MICRO_BUTTONS) do
		_G[v]:SetAlpha(0)
	end
end

for _, v in ipairs(MICRO_BUTTONS) do
	v = _G[v]
	v:HookScript("OnEnter", showFoo)
	v:HookScript("OnLeave", hideFoo)
	v:SetAlpha(0)
end
My problem is that the achievement button doesn't hide on login, I need to hover it once for it to fade:
http://i.imgur.com/h18nkpF.jpg

How do I make the achievement button fade on login like the rest of the micromenu buttons?
  Reply With Quote
07-28-13, 09:46 PM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Just a hunch, and I admit this could be very wrong, but look at your third function. To me, that reads like this, in psuedo-code:
Code:
loop
    get local variable 'v'
    ignore local variable 'v' and set it to global 'v' instead
    etc
end loop
Try this and see if it works:
Code:
for _, v in ipairs(MICRO_BUTTONS) do
	_G[v] = v -- is this line even necessary?
	v:HookScript("OnEnter", showFoo)
	v:HookScript("OnLeave", hideFoo)
	v:Hide() -- see this change too? replace in your other functions as well
end
  Reply With Quote
07-28-13, 09:50 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
No, say v = "MyFrame" - this is a string with the text of a frame name.

v = _G[v] looks up "MyFrame" (the string) in the global table and sees that it is the global name of a frame object. The variable v is then set to the actual frame object. In other words, whatever the right side evaluates to, the left side will be set to.

You can then do v:SetAlpha() because v is referencing the frame itself, not the frame name.


/edit: You think the above works backwards from how it actually does. You're replacing the entry in the global table with a string. You're breaking the whole UI.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
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
07-29-13, 06:15 AM   #5
laukond
A Black Drake
Join Date: Dec 2011
Posts: 87
http://i.imgur.com/DKFeQUg.jpg

Well my original problem is solved but now I have 11 more problems

Last edited by laukond : 07-29-13 at 06:57 AM.
  Reply With Quote
07-29-13, 05:03 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You're gonna have to be more specific than "I have problems" if you want any help solving them...
__________________
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.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Hide MicroBars Mouseover / Achievement Button


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