Thread Tools Display Modes
11-23-14, 10:00 PM   #1
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
Simple How to Hide and Show Window Help?

I'm simply trying to understand how to show and hide a from with a right mouse click. Here is the code where I think I don't have it correct. I'm remembering how I did this with Elder Scrolls Online so I was trying it this way and mixed it with a way to do it in wow that I've found online. However it's not working.

The Code for Hidding and showing the frame with right mouse click to my button.

Lua Code:
  1. local frame = CreateFrame("Button", ZBarOptionFrame, UIParent)
  2.  
  3. ZBarOptionFrame:RegisterForClicks("AnyUp")
  4. ZBarOptionFrame:SetScrpit("OnClick", function(self, button, ...)
  5.     if (button == "RightButton") then
  6.         if ZBarOptionFrame:IsShown() then
  7.             ZBarOptionFrame:SetHidden(false)
  8.         else
  9.             ZBarOptionFrame:SetHidden(true)
  10.         end
  11.     end
  12. end)

Here is the entire lua code I have so far remember I'm still working on this so it's not finished at all yet.

Lua Code:
  1. --Want to add Show Hide function for each window. ( barQWindow, barAWindow, barMWindow, barCWindow )
  2. --With the Show Hide I want to add this in an addon options window.
  3. --Want to add a lock frame for each window.
  4. --With lock frame I want to add this in an addon options window.
  5.  
  6. --Create a button using lua that pulls up a window for ZBar Options.
  7.  
  8. -- creates a generic button in the middle of the screen --
  9. ZBarButton = CreateFrame("Button","ZBarButton",UIParent,"UIPanelButtonTemplate")
  10. ZBarButton:SetPoint("CENTER",0,0)
  11. ZBarButton:SetWidth(30)
  12. ZBarButton:SetHeight(30)
  13. ZBarButton:SetText("ZB")
  14. ZBarButton:SetMovable(true)
  15. ZBarButton:RegisterForDrag("LeftButton")
  16. ZBarButton:SetScript("OnDragStart",ZBarButton.StartMoving)
  17. ZBarButton:SetScript("OnDragStop",ZBarButton.StopMovingOrSizing)
  18.  
  19. ZBarOptionFrame = CreateFrame("Frame")
  20. ZBarOptionFrame:ClearAllPoints()
  21. ZBarOptionFrame:SetBackdrop(StaticPopup1:GetBackdrop())
  22. ZBarOptionFrame:SetHeight(300)
  23. ZBarOptionFrame:SetWidth(300)
  24. ZBarOptionFrame:SetHidden(true)
  25.  
  26. ZBarOptionFrame.text = ZBarOptionFrame:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
  27. ZBarOptionFrame.text:SetAllPoints()
  28. ZBarOptionFrame.text:SetText("ZBar Options Verison 1.0")
  29. ZBarOptionFrame:SetPoint("CENTER", 0, 0)
  30.  
  31. local frame = CreateFrame("Button", ZBarOptionFrame, UIParent)
  32.  
  33. ZBarOptionFrame:RegisterForClicks("AnyUp")
  34. ZBarOptionFrame:SetScrpit("OnClick", function(self, button, ...)
  35.     if (button == "RightButton") then
  36.         if ZBarOptionFrame:IsShown() then
  37.             ZBarOptionFrame:SetHidden(false)
  38.         else
  39.             ZBarOptionFrame:SetHidden(true)
  40.         end
  41.     end
  42. end)

Please if you write code back to me show it completely with all information and deep examples. I'm still very new to coding.
  Reply With Quote
11-23-14, 11:22 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You should be getting an error. Make sure that you have Lua errors shown in your Interface Options. Also, install an error catching addons (BugSack is an example) to catch errors that happen early in the loading process.

frame:SetHidden(false) is API from ESO. You'll need to use the frame API provided by WoW.

frame:Hide()
frame:Show()

/edit: you also have a typo on line 34
__________________
"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
11-23-14, 11:27 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Oh, and another thing. Unless you ABSOLUTELY need your button to have a global name, accessible from outside of your addon, then don't bother giving it a global name. You can just do:
Lua Code:
  1. local frame = CreateFrame("Button", nil, UIParent)

If you DO want it to have a global name, then use the local you are assigning your button to as your reference in the Lua code. Locals are faster than global lookups.
Lua Code:
  1. frame:RegisterForClicks("AnyUp")
  2. frame:SetScript("OnClick", function(self, button, ...)
  3.     if (button == "RightButton") then
  4.         if frame:IsShown() then
  5.             frame:Hide()
  6.         else
  7.             frame:Show()
  8.         end
  9.     end
  10. end)

/edit: heh... just noticed that you had the :SetHidden() call backwards anyway
__________________
"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
11-24-14, 12:06 AM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
You can use frame:SetShown(). In combination with this, you can toggle a frame's visibility with the following line.
Code:
frame:SetShown(not frame:IsShown())
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 11-24-14 at 12:08 AM.
  Reply With Quote
11-24-14, 10:37 AM   #5
Zireko
An Aku'mai Servant
Join Date: Nov 2014
Posts: 38
I have tried everything you've suggested also I've flipped things around re-named my frame and it's still not working. My button that I made in the code isn't working with a right click to show and hide the window. Any way here is the code as of right now. Still don't know what I'm doing wrong yet.

Lua Code:
  1. --Want to add Show Hide function for each window. ( barQWindow, barAWindow, barMWindow, barCWindow )
  2. --With the Show Hide I want to add this in an addon options window.
  3. --Want to add a lock frame for each window.
  4. --With lock frame I want to add this in an addon options window.
  5.  
  6. --Create a button using lua that pulls up a window for ZBar Options.
  7.  
  8. -- creates a generic button in the middle of the screen --
  9. ZBarButton = CreateFrame("Button","ZBarButton",UIParent,"UIPanelButtonTemplate")
  10. ZBarButton:SetPoint("CENTER",0,0)
  11. ZBarButton:SetWidth(30)
  12. ZBarButton:SetHeight(30)
  13. ZBarButton:SetText("ZB")
  14. ZBarButton:SetMovable(true)
  15. ZBarButton:RegisterForDrag("LeftButton")
  16. ZBarButton:SetScript("OnDragStart",ZBarButton.StartMoving)
  17. ZBarButton:SetScript("OnDragStop",ZBarButton.StopMovingOrSizing)
  18.  
  19. ZBarOptionFrame = CreateFrame("Frame")
  20. ZBarOptionFrame:ClearAllPoints()
  21. ZBarOptionFrame:SetBackdrop(StaticPopup1:GetBackdrop())
  22. ZBarOptionFrame:SetHeight(300)
  23. ZBarOptionFrame:SetWidth(300)
  24. ZBarOptionFrame:Hide(true)
  25.  
  26. ZBarOptionFrame.text = ZBarOptionFrame:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
  27. ZBarOptionFrame.text:SetAllPoints()
  28. ZBarOptionFrame.text:SetText("ZBar Options Verison 1.0")
  29. ZBarOptionFrame:SetPoint("CENTER", 0, 0)
  30.  
  31. local frame = CreateFrame("Button", nil, UIParent)
  32.  
  33. frame:RegisterForClicks("AnyUp")
  34. frame:SetScript("OnClick", function(self, button, ...)
  35.     if (button == "RightButton") then
  36.         if frame:IsShown() then
  37.             frame:Hide()
  38.         else
  39.             frame:Show()
  40.         end
  41.     end
  42. end)
  Reply With Quote
11-24-14, 11:22 AM   #6
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
I'm a little confused.
You're creating two buttons and a frame. For the second button you set up OnClick to hide itself but nothing declaring how your button should look like. (Difficult to click again once it is hidden btw)
The first you set up to be dragable.

Which button is supposed to do what when why?
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Simple How to Hide and Show Window Help?


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