WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   kgPanels Button (https://www.wowinterface.com/forums/showthread.php?t=50045)

MalachiDraven 10-13-14 05:13 PM

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.

Choonstertwo 10-14-14 07:58 AM

Quote:

Originally Posted by MalachiDraven (Post 297718)
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.

Phanx 10-14-14 10:10 AM

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


Choonstertwo 10-14-14 11:52 AM

Quote:

Originally Posted by Phanx (Post 297746)
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.

Seerah 10-14-14 07:07 PM

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.

MalachiDraven 10-15-14 01:43 PM

Quote:

Originally Posted by Seerah (Post 297788)
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 :)


All times are GMT -6. The time now is 03:57 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI