WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Help with textures on frames update (https://www.wowinterface.com/forums/showthread.php?t=54223)

mich125 08-17-16 07:03 AM

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)

mich125 08-17-16 09:06 AM

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)

Vlad 08-17-16 09:54 AM

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

mich125 08-17-16 10:47 AM

Damn, guess i found simpler solution

I created folder \Interface\TargetingFrame and copied my texture there with name UI-StatusBar ....:banana:

Phanx 08-17-16 05:58 PM

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)

Phanx 08-17-16 06:06 PM

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

mich125 08-18-16 12:32 AM

Quote:

Originally Posted by Phanx (Post 317998)
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.

mich125 08-19-16 02:21 PM

Any idea why your solution doesnt work?
There is no lua errors so i dnno what to do.

zork 08-22-16 02:13 AM

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.

Phanx 08-22-16 08:42 AM

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.

Usoltsev 02-28-17 03:46 PM

@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.

Usoltsev 03-01-17 04:10 PM

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)


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

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