Thread Tools Display Modes
07-18-14, 03:03 AM   #1
philipe24
A Deviate Faerie Dragon
Join Date: Jan 2014
Posts: 10
PetFrame Texture

Hello again!
I've been trying to change the texture of my PetFrame but because the whole frame reloads every time you call it its not done this simple:
Lua Code:
  1. PetFrameTexture:SetTexture("xxxxx");


So what I've tried is to take a look at the PetFrame.lua from blizzard and copied the following code into my addon:
Lua Code:
  1. function PetFrame_Update (self, override)
  2.     if ( (not PlayerFrame.animating) or (override) ) then
  3.         if ( UnitIsVisible(self.unit) and PetUsesPetFrame() and not PlayerFrame.vehicleHidesPet ) then
  4.             if ( self:IsShown() ) then
  5.                 UnitFrame_Update(self);
  6.             else
  7.                 self:Show();
  8.             end
  9.             --self.flashState = 1;
  10.             --self.flashTimer = PET_FLASH_ON_TIME;
  11.             if ( UnitPowerMax(self.unit) == 0 ) then
  12.                 PetFrameTexture:SetTexture("xxxxxx");
  13.                 PetFrameManaBarText:Hide();
  14.             else
  15.                 PetFrameTexture:SetTexture("xxxxxx");
  16.             end
  17.             PetAttackModeTexture:Hide();
  18.  
  19.             RefreshDebuffs(self, self.unit, nil, nil, true);
  20.         else
  21.             self:Hide();
  22.         end
  23.     end
  24. end
It works but I get the following error sometimes and the ToT Frame vanishs.
Lua Code:
  1. 240x [ADDON_ACTION_BLOCKED] AddOn "GhettoFrames" tried to call the protected function "TargetFrameToT:Show()".!BugGrabber-r198-release\BugGrabber.lua:552: in function FrameXML\TargetFrame.lua:924: in function "TargetofTarget_Update"FrameXML\TargetFrame.lua:109: in function "TargetFrame_Update"FrameXML\TargetFrame.lua:154: in function "OnEvent"FrameXML\UnitFrame.lua:673: in function :"TARGETNEARESTFRIEND":1: in function :"TARGETNEARESTFRIEND":1Locals:nil
Anyone who got an idea to fix this? thanks alot!greetings
  Reply With Quote
07-18-14, 04:31 AM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Replacing default functions in any way related to unit frames is gonna break stuff, as you've witnessed, but you can use a secure hook.
Code:
hooksecurefunc("PetFrame_Update", function(self, override)
	PetFrameTexture:SetTexture("xxxxxx")
end)
__________________
Grab your sword and fight the Horde!
  Reply With Quote
07-18-14, 05:45 AM   #3
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
You can set the hook directly on the SetTexture call if you want. Thus it will only fire on a SetTexture call.
Lua Code:
  1. hooksecurefunc(PetFrameTexture, "SetTexture", function(self, texture)
  2.   local mytexture = "xxx"
  3.   if texture ~= mytexture then
  4.     print("reseting texture: "..texture)
  5.     self:SetTexture(mytexture)
  6.   end
  7. end)
__________________
| 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
07-18-14, 10:59 AM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I'm pretty sure that would cause an infinite loop.
__________________
"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
07-18-14, 12:04 PM   #5
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Originally Posted by Seerah View Post
I'm pretty sure that would cause an infinite loop.
It'll only run if SetTexture is called with a texture path other than the one defined because of the if statement.

I think you can avoid that by making a local reference to PetFrameTexture.SetTexture outside the function and calling that instead of self:SetTexture in the hook.

For example, this shouldn't call the hooked function..
Lua Code:
  1. local PetFrameSetTexture = PetFrameTexture.SetTexture
  2. hooksecurefunc(PetFrameTexture, 'SetTexture', function(self, texture)
  3.     PetFrameSetTexture(self, 'mytexture')
  4. end)

Last edited by semlar : 07-18-14 at 12:13 PM.
  Reply With Quote
07-18-14, 03:10 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Whoops - missed that.

And yeah, what semlar put is what I usually do in these cases.
__________________
"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

WoWInterface » Developer Discussions » Lua/XML Help » PetFrame Texture


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