Quantcast
kgPanels Button - WoWInterface
Thread Tools Display Modes
10-13-14, 05:13 PM   #1
MalachiDraven
A Deviate Faerie Dragon
Join Date: Oct 2014
Posts: 10
kgPanels Button

Hiya. I'm trying to make a button using kgPanels. I want it to open/close my bags. I also want it to show/hide a different kgPanel when I click it and also when I press the "B" key to open/close my bags.
  Reply With Quote
10-14-14, 07:58 AM   #2
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Originally Posted by MalachiDraven View Post
Hiya. I'm trying to make a button using kgPanels. I want it to open/close my bags. I also want it to show/hide a different kgPanel when I click it and also when I press the "B" key to open/close my bags.
In your button panel, use these scripts:

OnLoad
lua Code:
  1. local ToggleAllBags = ToggleAllBags -- Create a local reference to the original ToggleAllBags function before we hook it
  2. hooksecurefunc("ToggleAllBags", function() -- Hook the global ToggleAllBags to call the OnClick method of this panel
  3.     self:OnClick()
  4. end)
  5.  
  6. function self:OnClick()
  7.     ToggleAllBags() -- Call the local reference to ToggleAllBags
  8.     OtherPanel:SetShown(not OtherPanel:IsShown()) -- Change OtherPanel to the name of the other panel
  9. end

OnClick
lua Code:
  1. self:OnClick()

In your other panel, add this to the OnLoad script:
lua Code:
  1. OtherPanel = self -- Change OtherPanel to the desired name of this panel

In both OnLoad scripts, change OtherPanel to some unique name for your panel.
  Reply With Quote
10-14-14, 10:10 AM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Rather than setting that global "OtherPanel" in the second panel's OnLoad script, you should just use the method kgPanels provides for accessing other panels:

Code:
function self:OnClick()
    ToggleAllBags() -- Call the local reference to ToggleAllBags
    local OtherPanel = kgPanels:FetchFrame("Name of the second panel")
    OtherPanel:SetShown(not OtherPanel:IsShown())
end
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, 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!
  Reply With Quote
10-14-14, 11:52 AM   #4
Choonstertwo
A Chromatic Dragonspawn
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 194
Originally Posted by Phanx View Post
Rather than setting that global "OtherPanel" in the second panel's OnLoad script, you should just use the method kgPanels provides for accessing other panels:

Code:
function self:OnClick()
    ToggleAllBags() -- Call the local reference to ToggleAllBags
    local OtherPanel = kgPanels:FetchFrame("Name of the second panel")
    OtherPanel:SetShown(not OtherPanel:IsShown())
end
Indeed, that's a nicer solution. I forgot kgPanels had that.
  Reply With Quote
10-14-14, 07:07 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,746
Or, to make the other panel show/hide when your bags are opened/closed you can do an even *simpler* solution. Set the backpack to your panel's parent.
__________________
"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
10-15-14, 01:43 PM   #6
MalachiDraven
A Deviate Faerie Dragon
Join Date: Oct 2014
Posts: 10
Originally Posted by Seerah View Post
Or, to make the other panel show/hide when your bags are opened/closed you can do an even *simpler* solution. Set the backpack to your panel's parent.
That worked perfectly
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » kgPanels Button

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