Reply
Thread Tools Display Modes
Unread 11-07-13, 04:53 AM   #1
10leej
A Scalebane Royal Guard
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 428
Show/hide Frame on button/keybind?

So I want to make a frame that shows/hides on a toggle function when a button is clicked or a specific keybind is pressed. How would I go about doing this?
10leej is offline   Reply With Quote
Unread 11-07-13, 07:07 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,343
Not directly related but maybe it can help you out aswell:
http://wowpedia.org/API_IsModifierKeyDown
You could register the MODIFIER_STATE_CHANGED event and check if a modifier key is clicked.
__________________
| Simple is beautiful.
| Roth UI | Roth UI FAQ | GoogleCode | Zork | TDMOG

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
zork is offline   Reply With Quote
Unread 11-07-13, 10:46 AM   #3
10leej
A Scalebane Royal Guard
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 428
I did a bit of fiddling, unfortunately I'm away from the desktop so I can't test it but I think I can do something like this for the key press, I'm probably way off though.

Code:
frame:SetScript("OnMouseDown", function(self, btn)
if btn == "RightButton" then  
  IsShiftKeyDown() then frame:Show() end end)
  else
    frame:Hide()
end
10leej is offline   Reply With Quote
Unread 11-09-13, 04:13 AM   #4
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,135
Haha, that's probably the highest concentration of Lua syntax errors I've ever seen in so little code.

Anyway, I'm not exactly sure what you're trying to do, but even if you fix the syntax errors on your code, I don't think it's going to do it. For one, your code basically says "show the frame on shift-right click, hide it on any other type of click". For another, you're using that script on the frame itself, and you can't click on a frame that's hidden, so you'd never be able to re-show it.

Do you want to show the frame when the button/key is pressed, and hide it again when the button/key is released; or show the frame on the first click/press and hide it on the second click/press?
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Unread 11-09-13, 11:49 AM   #5
10leej
A Scalebane Royal Guard
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 428
I wanna show it when pressed hide when released.
10leej is offline   Reply With Quote
Unread 11-10-13, 12:08 AM   #6
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,135
If you want to use mouse buttons, that's fairly easy, though you'll have to think about what you want to click on to show the frame, since you can't click on it while hidden. You could either use a second frame as a small always-visible area for clicking (eg. a tab or button) or hook the OnMouseDown script for the WorldFrame and show your frame if the cursor was in a particular area.

Code:
WorldFrame:HookScript("OnMouseDown", function(self, button)
   if button == "RightButton" and MyFrame:IsMouseOver() then
      MyFrame:Show()
   end
end)
WorldFrame:HookScript("OnMouseUp", function(self, button)
   MyFrame:Hide()
end)
^ Note that I'm not actually sure that will work, since I don't know that :IsMouseOver() will works for hidden frames. If it doesn't, you'd need to manually determine the boundaries of your frame and check the coordinates of the cursor to make sure it was within those boundaries.

If you want to use keyboard keys, that's only really possible if you want to use Alt, Ctrl, Shift, or some combination thereof. The only way to detect other keys is to keyboard-enable your frame, which basically makes it behave like a focused editbox, intercepting all keyboard input and preventing the use of keybinds for anything else.

Code:
MyFrame:RegisterEvent("MODIFIER_STATE_CHANGED")
MyFrame:SetScript("OnEvent", function(self, event, key, pressed)
   if key == "LALT" or key == "RALT" then
      if pressed == 1 then
         self:Show()
      else
         self:Hide()
      end
   end
end)
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Unread 11-10-13, 09:59 AM   #7
10leej
A Scalebane Royal Guard
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 428
I should be able to just use UIParent for the frame shouldn't I?
10leej is offline   Reply With Quote
Unread 11-11-13, 05:46 PM   #8
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,135
For which frame?

You should absolutely not use SetScript on the UIParent, if that's what you mean, and you really shouldn't be registering new events on it either. Just create your own frame. Takes 1 line of code and avoids all the potential problems.
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » Show/hide Frame on button/keybind?

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