WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   How do you handle petbattle hiding? (https://www.wowinterface.com/forums/showthread.php?t=43977)

zork 08-27-12 01:29 PM

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.

Maul 08-27-12 01:54 PM

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
]])


Talyrius 08-27-12 01:57 PM

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. :p

zork 08-27-12 02:12 PM

Yes I'm using that for my actionbars already. Just checking the options. :p

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.

Phanx 08-27-12 06:40 PM

Quote:

Originally Posted by zork (Post 260459)
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.

tukz 08-31-12 05:48 PM

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.

Phanx 08-31-12 06:27 PM

Quote:

Originally Posted by zork (Post 260459)
Code:

RegisterStateDriver(frame, "visibility", "[petbattle] hide; [vehicleui] hide; show")

You can actually condense that:

Code:

RegisterStateDriver(frame, "visibility", "[petbattle] [vehicleui] hide; show")


All times are GMT -6. The time now is 08:55 AM.

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