Thread Tools Display Modes
05-24-13, 11:26 AM   #1
10leej
A Molten Giant
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 583
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
__________________
Tweets YouTube Website
  Reply With Quote
05-24-13, 11:40 AM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
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")
  Reply With Quote
05-24-13, 11:42 AM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Your if and elseif logic is exactly the same.

/edit: plus what Dridzt said
__________________
"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
05-24-13, 02:01 PM   #4
10leej
A Molten Giant
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 583
Originally Posted by Dridzt View Post
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
__________________
Tweets YouTube Website
  Reply With Quote
05-24-13, 05:27 PM   #5
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,359
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
  Reply With Quote
05-24-13, 08:15 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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)
__________________
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
05-25-13, 03:22 PM   #7
10leej
A Molten Giant
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 583
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.
__________________
Tweets YouTube Website

Last edited by 10leej : 05-25-13 at 03:37 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Hide frame when pet leaves

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