Thread Tools Display Modes
09-01-17, 10:16 AM   #1
Terenna
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
Close Frame if you escape/click outside of it

Hey all,

I'm coding an addon that shows a frame with secure buttons on it that let you cast poisons on those weapons. The idea is you right click the respective weapon in the player frame and the frame appears. Currently the frame will open when I right click the weapon as expected, however, I can't figure out how to hide it when I click outside of the frame or hit escape.

Any suggestions would be much appreciated.
  Reply With Quote
09-01-17, 10:21 AM   #2
Terenna
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
Close Frame if you escape/click outside of it

Hey all,

I'm coding an addon that shows a frame with secure buttons on it that let you cast poisons on those weapons. The idea is you right click the respective weapon in the player frame and the frame appears. Currently the frame will open when I right click the weapon as expected, however, I can't figure out how to hide it when I click outside of the frame.

I found table.insert(UISpecialFrames, yourframehere) to allow escape, but still wanted to find a way to close when you clicked outside of the frame if at all possible.

Any suggestions would be much appreciated.
  Reply With Quote
09-01-17, 10:55 AM   #3
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
Lua Code:
  1. -- The form should use SecureHandlerShowHideTemplate
  2. -- so we can handle the key binding when it's shown
  3. MyForm = CreateFrame("Frame", "MyForm", UIParent, "SecureHandlerShowHideTemplate")
  4. MyForm:Hide()
  5. MyForm:SetPoint("CENTER")
  6. MyForm:SetSize(100, 100)
  7. MyForm:SetBackdrop{
  8.     edgeFile = "Interface\\Buttons\\WHITE8x8",
  9.     edgeSize = 1,
  10. }
  11.  
  12. -- Create a secure button for key binding
  13. MyToggle = CreateFrame("CheckButton", "MyFormToggle", MyForm, "SecureActionButtonTemplate")
  14. MyToggle:Hide()
  15.  
  16. SecureHandlerSetFrameRef(MyForm, "toggle", MyToggle)
  17. SecureHandlerExecute(MyForm, [[toggle = self:GetFrameRef("toggle")]])
  18.  
  19. SecureHandlerSetFrameRef(MyToggle, "form", MyForm)
  20. SecureHandlerExecute(MyToggle, [[form = self:GetFrameRef("form")]])
  21.  
  22. -- Bind the BUTTON1(left-mouse) to the button when form is shown
  23. MyForm:SetAttribute("_onshow", [[
  24.     toggle:SetBindingClick(true, "BUTTON1", "MyFormToggle", "LeftButton")
  25. ]])
  26.  
  27. -- Left-click trigger the toggle to hide the form and clear the binding
  28. MyToggle:SetAttribute("type", "toggle")
  29. MyToggle:SetAttribute("_toggle", [[print(123) form:Hide() self:ClearBinding("BUTTON1")]])
  30.  
  31. -- Test
  32. MyForm:Show()
  Reply With Quote
09-01-17, 11:12 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
To close with the escape key

Code:
tinsert(UISpecialFrames, "Name of your frame")
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
09-01-17, 11:33 AM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I merged your threads together.
__________________
"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
09-01-17, 12:58 PM   #6
Terenna
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
I'm sorry about that. I think I clicked back after submitting, got tied up in something, and then thought I didn't submit the first time.
  Reply With Quote
09-01-17, 02:59 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
No worries. They both had replies, so I merged instead of deleting the first one.
__________________
"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

WoWInterface » Developer Discussions » General Authoring Discussion » Close Frame if you escape/click outside of it

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