Thread Tools Display Modes
08-27-12, 01:29 PM   #1
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
How do you handle petbattle hiding?

I'm thinking of sth. like
Lua Code:
  1. local unit = CreateFrame("Frame")
  2.   unit:Hide()
  3.   unit:RegisterEvent("PET_BATTLE_OPENING_START")
  4.   unit:RegisterEvent("PET_BATTLE_CLOSE")
  5.   --event
  6.   unit:SetScript("OnEvent", function(...)
  7.     local self, event, arg1 = ...
  8.     if event == "PET_BATTLE_OPENING_START" then
  9.       for _, v in pairs(oUF_Diablo_Units) do
  10.         local f = _G[v]
  11.         if f then f:SetParent(unit) end
  12.       end
  13.     elseif event == "PET_BATTLE_CLOSE" then
  14.       for _, v in pairs(oUF_Diablo_Units) do
  15.         local f = _G[v]
  16.         if f then f:SetParent(UIParent) end
  17.       end
  18.     end
  19.   end)

Petbattle can only be enganged out of combat.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 08-27-12 at 01:42 PM.
  Reply With Quote
08-27-12, 01:54 PM   #2
Maul
Ion Engines, Engage!
 
Maul's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 401
You could use the [petbattle] macro conditional that others of us requested for just this sort of thing -

Code:
local frame = CreateFrame("Frame", nil, UIParent, "SecureHandlerStateTemplate")

RegisterStateDriver(frame, "petbattle", "[petbattle] dostuff1; [nopetbattle] dostuff2")

frame:SetAttribute("_onstate-petbattle", [[
         if (self:GetAttribute("state-petbattle") == "dostuff1") then
              --do stuff
         elseif (self:GetAttribute("state-petbattle") == "dostuff2") then
              -- do stuff
         end
]])
__________________

Twitter: @IonMaul | Windows Live: [email protected] | Google Talk: [email protected]

Last edited by Maul : 08-27-12 at 01:58 PM.
  Reply With Quote
08-27-12, 01:57 PM   #3
Talyrius
An Onyxian Warder
 
Talyrius's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 363
Why not just use the new [petbattle] macro conditional with the SecureStateDriver to be on the safe side?

EDIT:
I took forever to hit reply.
  Reply With Quote
08-27-12, 02:12 PM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Yes I'm using that for my actionbars already. Just checking the options.

The thing is ... you can't just show the frame because it may have been hidden. Not sure if oUF will hide the frame by itself if you get out of petbattle and show it.

Code:
RegisterStateDriver(frame, "visibility", "[petbattle] hide; [vehicleui] hide; show")
Using the statedriver and calling :Show() in dostuff seems to be unsecure aswell. Or is it allowed to call :Show() / :Hide() inside of the statedriver functions that you define manually?

What I like about SetParent is that you don't have to care about the show/hide status of the frame.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
08-27-12, 06:40 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by zork View Post
Using the statedriver and calling :Show() in dostuff seems to be unsecure aswell. Or is it allowed to call :Show() / :Hide() inside of the statedriver functions that you define manually?
SetParent is in the same category of protected functions as Show, Hide, SetPoint, SetWidth, SetHeight, etc. -- you cannot call any of them insecurely in combat. At any time, if you can use SetParent, you can also use Show or Hide. If you can't use Show or Hide at a particular time, you can't use SetParent either.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
08-31-12, 05:48 PM   #6
tukz
A Fallenroot Satyr
 
tukz's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 20
im using:

Code:
-- Hider Secure (mostly used to hide stuff while in pet battle)
local PetBattleHider = CreateFrame("Frame", "TukuiPetBattleHider", UIParent, "SecureHandlerStateTemplate");
PetBattleHider:SetAllPoints(UIParent)
RegisterStateDriver(PetBattleHider, "visibility", "[petbattle] hide; show")
And I parent everything on My UI that I want to hide while in pet battle to it when the addon load, except for my action bars which I use [petbattle] macro.
  Reply With Quote
08-31-12, 06:27 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by zork View Post
Code:
RegisterStateDriver(frame, "visibility", "[petbattle] hide; [vehicleui] hide; show")
You can actually condense that:

Code:
RegisterStateDriver(frame, "visibility", "[petbattle] [vehicleui] hide; show")
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » How do you handle petbattle hiding?

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