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
07-29-13, 05:05 PM   #7
laukond
A Black Drake
Join Date: Dec 2011
Posts: 87
Originally Posted by Phanx View Post
You're gonna have to be more specific than "I have problems" if you want any help solving them...
Oh.. I kinda thought it was obvious on the screenshot :-P
The achievement button (the original problem) is now hidden when logging in, problem solved. However the 11 other micro buttons are visible.
  Reply With Quote
07-29-13, 05:10 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Try changing this:
Code:
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
to this:
Code:
local function resetAlpha(self)
	for i = 1, #MicroButtons do
		if MicroButtons[i]:IsMouseOver() then
			return showFoo(self)
		end
	end
	hideFoo(self)
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.
  Reply With Quote
07-29-13, 05:12 PM   #9
laukond
A Black Drake
Join Date: Dec 2011
Posts: 87
Now all, including the achievement button, are visible.
  Reply With Quote
07-29-13, 06:39 PM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Try keeping track of the mouseover state in a variable, and just going off that. Also, I just noticed I forgot to update the alpha on load, so that's probably a related issue.

Code:
local mouseover
local MicroButtons = {}

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

local function OnEnter(self)
	mouseover = true
	UpdateAlpha()
end

local function OnLeave(self)
	mouseover = false
	UpdateAlpha()
end

for i = 1, #MICRO_BUTTONS do
	local v = _G[MICRO_BUTTONS[i]]
	v:HookScript("OnEnable", UpdateAlpha)
	v:HookScript("OnDisable", UpdateAlpha)
	v:HookScript("OnEnter", OnEnter)
	v:HookScript("OnLeave", OnLeave)
	MicroButtons[i] = v
end

UpdateAlpha()
__________________
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 07:59 PM.
  Reply With Quote
07-29-13, 06:45 PM   #11
laukond
A Black Drake
Join Date: Dec 2011
Posts: 87
19x hbitUI\hbitUI.lua:165: attempt to call global "updateAlpha" (a nil value)
hbitUI\hbitUI.lua:165: in function <hbitUI\hbitUI.lua:163>
<in C code>

Locals:
(*temporary) = <func> =[C]:-1
= <func> *:OnLeave:1
= <func> @..\hbitUI.lua:163
The error is in the OnLeave function.
Aside from the error, all the buttons are faded correctly, but when mouseovering only the tooltip shows. Not the actual icons themselves. Here's a screenshot that shows it: http://i.imgur.com/3FDMRq1.jpg

Last edited by laukond : 07-30-13 at 07:47 AM.
  Reply With Quote
07-29-13, 08:00 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Fixed both issues.

Also, for future reference, you don't really need to quote the entire 40-line post when you're replying directly after it.
__________________
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
07-29-13, 08:02 PM   #13
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Change updateAlpha() in both the OnEnter and OnLeave functions to UpdateAlpha() to actually match the name of the function. Case matters in Lua. (Hint: these are the type of errors you can start to learn to correct by yourself. )
__________________
"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, 11:41 PM   #14
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I already fixed the code in my previous post, and also added the missing call to UpdateAlpha() at the end so it correctly sets the alpha at load.
__________________
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
07-30-13, 07:50 AM   #15
laukond
A Black Drake
Join Date: Dec 2011
Posts: 87
You guys are the best!
Thank you.
  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