WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Hide frame when pet leaves (https://www.wowinterface.com/forums/showthread.php?t=46534)

10leej 05-24-13 11:26 AM

Hide frame when pet leaves
 
So I know how to show/update a frame when the player's pet exists/enters, but how do I hide the frame when the pet leaves?

I figured I could call the same event for enter and leaves and run UnitExists("pet") but that did no good.

source code

Dridzt 05-24-13 11:40 AM

You inherit from "SecureHandlerStateTemplate" in addition to whatever it is you're inheriting from now (didn't check code) and then
RegisterStateDriver(yourframe, "visibility", "[nopet]hide;show")

Seerah 05-24-13 11:42 AM

Your if and elseif logic is exactly the same.

/edit: plus what Dridzt said ;)

10leej 05-24-13 02:01 PM

Quote:

Originally Posted by Dridzt (Post 278573)
You inherit from "SecureHandlerStateTemplate" in addition to whatever it is you're inheriting from now (didn't check code) and then
RegisterStateDriver(yourframe, "visibility", "[nopet]hide;show")

All I find for SecureHandlerStateTemplate are xml examples, but yeah i'll look into that

Dridzt 05-24-13 05:27 PM

Hmm, I took a look at your code.

You're over-complicating things :)

There's no reason to have a frame to parent your unitframe to, that does nothing.

You should just create your Button from 'SecureUnitButtonTemplate' as you've done, set your attributes and then use RegisterUnitWatch(yourframe)
It will take care of showing / hiding of itself (look at how the default target frame is done for example)

You don't need that 'w' frame you have at all.

Here for an example:
http://www.wowpedia.org/API_RegisterUnitWatch

Phanx 05-24-13 08:15 PM

Also, since your button is created as a secure frame, you can't use :Show() and :Hide() on it while you're in combat. If you want a unit frame, create a secure unit button (as you're already doing) and use RegisterUnitWatch on it like Dridzt said; you don't even need to use a state driver to hide/show it, as the UI will do that automatically based on the existence of the unit it's registered to watch.

The example code on Wowpedia is really messy, so here is a cleaner one:

Code:

local f = CreateFrame("Button", "MyPetButton", UIParent, "SecureUnitButtonTemplate")
f:SetAttribute("unit", "pet")
RegisterUnitWatch(f)


10leej 05-25-13 03:22 PM

Awesome I was about to rage about how terrible that example code was, lmao.

Anyways seems to be working fine now, now to look into making target/focus huds, those work with just a copy paste of the pet code.

Probably gonna have to call an even to get health/power update when targetted. (apparently people want an icehud really replacement or something I guess) Anyways this thread b resolved.


All times are GMT -6. The time now is 12:34 AM.

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