Thread Tools Display Modes
08-17-16, 07:03 AM   #1
mich125
A Fallenroot Satyr
Join Date: Jan 2010
Posts: 27
Exclamation Help with textures on frames update

Hi

I have a simple script to change texture on frames, but HP and Mana bars texture gets changed to default when hp/mana value changes.
I assume that I need some sort of "onupdate" script to keep new textures on? Anyone can help me plz?

When i load ui, new textures load fine:



When hp changes, red hp texture is default
When hp/mana changes, mana texture changes to default:



Lua Code:
  1. local main = function()
  2. for _, StatusBarTextures in pairs ({
  3.     PlayerFrameHealthBar,
  4.     PlayerFrameManaBar,
  5. TargetFrameHealthBar,
  6. TargetFrameManaBar,
  7. TargetFrameToTHealthBar,
  8. TargetFrameToTManaBar,
  9.     FocusFrameHealthBar,
  10.     FocusFrameManaBar,
  11.     FocusFrameToTHealthBar,
  12.     FocusFrameToTManaBar,
  13. PartyMemberFrame1HealthBar,
  14. PartyMemberFrame2HealthBar,
  15. PartyMemberFrame3HealthBar,
  16. PartyMemberFrame4HealthBar,
  17.     PartyMemberFrame1ManaBar,
  18.     PartyMemberFrame2ManaBar,
  19.     PartyMemberFrame3ManaBar,
  20.     PartyMemberFrame4ManaBar,
  21. CastingBarFrame,
  22. TargetFrameSpellBar,
  23. FocusFrameSpellBar,
  24.         })  do StatusBarTextures:SetStatusBarTexture("Interface\\AddOns\\EVUI\\FrameBackground") end
  25. for _, BarTextures in pairs ({
  26. TargetFrameNameBackground,
  27. FocusFrameNameBackground,
  28.         })  do BarTextures:SetTexture("Interface\\AddOns\\EVUI\\FrameBackground") end
  29. end
  30.  
  31. local ef = CreateFrame("frame")
  32. ef:RegisterEvent("PLAYER_ENTERING_WORLD")
  33. ef:SetScript("OnEvent", function(self)
  34.  main()
  35.  main = nil
  36.  self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  37.  self:SetScript("OnEvent", nil)
  38. end)

Last edited by mich125 : 08-17-16 at 07:25 AM.
  Reply With Quote
08-17-16, 09:06 AM   #2
mich125
A Fallenroot Satyr
Join Date: Jan 2010
Posts: 27
I found something like this, is that what i need?

Lua Code:
  1. hooksecurefunc(getmetatable(PlayerFrameHealthBar).__index, "Show", function(bar, ...)
  2.         if bar:GetParent().healthbar then
  3.             if bar.styled == nil then
  4.         bar:SetStatusBarTexture("Interface\\AddOns\\EVUI\\FrameBackground")
  5.         bar:GetStatusBarTexture():SetHorizTile(true)
  6.         bar.styled = true
  7.             end
  8.         end
  9. end)

Last edited by mich125 : 08-17-16 at 09:11 AM.
  Reply With Quote
08-17-16, 09:54 AM   #3
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
getmetatable(PlayerFrameHealthBar).__index is the metatable for ALL StatusBar widgets. You are hooking every frame imaginable "Show" call by doing this. You don't want to do that.

Doing hooksecurefunc(PlayerFrameHealthBar, "Show", ...) should be enough or better yet PlayerFrameHealthBar:HookScript("OnShow", ...) but ideally find out when Blizzard run their code, and run your styling after theirs instead of hooking Show related events.
__________________
Profile: Curse | Wowhead
  Reply With Quote
08-17-16, 10:47 AM   #4
mich125
A Fallenroot Satyr
Join Date: Jan 2010
Posts: 27
Damn, guess i found simpler solution

I created folder \Interface\TargetingFrame and copied my texture there with name UI-StatusBar ....
  Reply With Quote
08-17-16, 05:58 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Keep in mind that solution will not work for anyone else using your addon (if you plan to release it).

The health bar texture wasn't getting changed. The red bar in your screenshot is the additional bars for heals and absorbs. To fix that, you just need to set the textures for those:

Code:
frame.myHealPredictionBar:SetTexture(x)
frame.otherHealPredictionBar:SetTexture(x)
frame.totalAbsorbBar:SetTexture(x)
frame.healAbsorbBar:SetTexture(x)
(Note these aren't StatusBar objects, just Texture, so you use SetTexture instead of SetStatusBarTexture.)

The power bar texture does get reset, because some power types now have unique textures (eg. maelstrom for enhancement shamans). Use a hook to reapply your desired texture every time it gets updated:

Code:
hooksecurefunc("UnitFrameManaBar_UpdateType", function(manaBar)
    manaBar:SetStatusBarTexture(x)
end)
There's also a "mana cost prediction bar" that shows how much mana will be deducted for the spell you're currently casting:

Code:
frame.myManaCostPredictionBar:SetTexture(x)
__________________
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-17-16, 06:06 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Also a better way to catch all these is probably:

lua Code:
  1. local TEXTURE = "Interface\\AddOns\\EVUI\\FrameBackground"
  2. local UnitFrames = {
  3.     PlayerFrame,
  4.     PetFrame,
  5.     TargetFrame,
  6.     TargetFrameToT,
  7.     FocusFrame,
  8.     FocusFrameToT,
  9.     PartyMemberFrame1,
  10.     PartyMemberFrame2,
  11.     PartyMemberFrame3,
  12.     PartyMemberFrame4,
  13. }
  14. local UnitFrameRegions = {
  15.     "healthBar",
  16.     "myHealPredictionBar",
  17.     "otherHealPredictionBar",
  18.     "healAbsorbBar",
  19.     "totalAbsorbBar",
  20.     "manaBar",
  21.     "myManaCostPredictionBar",
  22.     "spellbar",
  23. }
  24. local OtherStatusBars = {
  25.     CastingBarFrame,
  26.     MirrorTimer1StatusBar,
  27.     MirrorTimer2StatusBar,
  28.     MirrorTimer3StatusBar,
  29. }
  30. for _, frame in next, UnitFrames do
  31.     for _, region in next, UnitFrameRegions do
  32.         local bar = frame[region]
  33.         if bar and bar.SetStatusBarTexture then
  34.             bar:SetStatusBarTexture(TEXTURE)
  35.             bar:GetStatusBarTexture():SetHorizTile(true)
  36.         elseif bar and bar.SetTexture then
  37.             bar:SetTexture(TEXTURE)
  38.             bar:SetHorizTile(true)
  39.         end
  40.     end
  41. end
  42. for _, bar in next, OtherStatusBars do
  43.     bar:SetStatusBarTexture(TEXTURE)
  44.     bar:GetStatusBarTexture():SetHorizTile(true)
  45. end
__________________
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-18-16, 12:32 AM   #7
mich125
A Fallenroot Satyr
Join Date: Jan 2010
Posts: 27
Originally Posted by Phanx View Post
Also a better way to catch all these is probably:

lua Code:
  1. local TEXTURE = "Interface\\AddOns\\EVUI\\FrameBackground"
  2. local UnitFrames = {
  3.     PlayerFrame,
  4.     PetFrame,
  5.     TargetFrame,
  6.     TargetFrameToT,
  7.     FocusFrame,
  8.     FocusFrameToT,
  9.     PartyMemberFrame1,
  10.     PartyMemberFrame2,
  11.     PartyMemberFrame3,
  12.     PartyMemberFrame4,
  13. }
  14. local UnitFrameRegions = {
  15.     "healthBar",
  16.     "myHealPredictionBar",
  17.     "otherHealPredictionBar",
  18.     "healAbsorbBar",
  19.     "totalAbsorbBar",
  20.     "manaBar",
  21.     "myManaCostPredictionBar",
  22.     "spellbar",
  23. }
  24. local OtherStatusBars = {
  25.     CastingBarFrame,
  26.     MirrorTimer1StatusBar,
  27.     MirrorTimer2StatusBar,
  28.     MirrorTimer3StatusBar,
  29. }
  30. for _, frame in next, UnitFrames do
  31.     for _, region in next, UnitFrameRegions do
  32.         local bar = frame[region]
  33.         if bar and bar.SetStatusBarTexture then
  34.             bar:SetStatusBarTexture(TEXTURE)
  35.             bar:GetStatusBarTexture():SetHorizTile(true)
  36.         elseif bar and bar.SetTexture then
  37.             bar:SetTexture(TEXTURE)
  38.             bar:SetHorizTile(true)
  39.         end
  40.     end
  41. end
  42. for _, bar in next, OtherStatusBars do
  43.     bar:SetStatusBarTexture(TEXTURE)
  44.     bar:GetStatusBarTexture():SetHorizTile(true)
  45. end
Thanks for reply m8, your code doesn't seem to work for me tho, and about my addon, its just for my use, i am not rly a developer, just using some scripts i find to improve my ui.
  Reply With Quote
08-19-16, 02:21 PM   #8
mich125
A Fallenroot Satyr
Join Date: Jan 2010
Posts: 27
Any idea why your solution doesnt work?
There is no lua errors so i dnno what to do.
  Reply With Quote
08-22-16, 02:13 AM   #9
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
It may not work if the key does not exist for a specific unitframe.

Example for PlayerFrameManaBar
https://github.com/tomrus88/Blizzard...Frame.xml#L345

It has no key for manaBar. PlayerFrame.manaBar does not exist.

You have to use PlayerFrameManaBar.

Phanx posted you a solutions that works for unitframes that have keys referencing specific child objects.
__________________
| 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-22-16, 08:42 AM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Sorry. Change "healthBar" and "manaBar" to "healthbar" and "manabar" (lowercase "b") in the UnitFrameRegions table.

Those keys are set for in UnitFrame_Initialize, which all the unit frames call in their OnLoad scripts:
https://www.townlong-yak.com/framexm...itFrame.lua#51

The other bars/textures should all work, though.
__________________
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
02-28-17, 03:46 PM   #11
Usoltsev
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Feb 2017
Posts: 3
@Phanx, thank you for your solution.

I have a same problem, but only when player gets damage.

Before damage


Then player gets damage


Why this happens?

Thanks.
  Reply With Quote
03-01-17, 04:10 PM   #12
Usoltsev
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Feb 2017
Posts: 3
I think I found a solution.

When you set
PlayerFrameHealthBar:SetStatusBarTexture(texture)

you also need set a same texture to AnimatedLossBar.
PlayerFrameHealthBar.AnimatedLossBar:SetStatusBarTexture(texture)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Help with textures on frames update

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