Thread Tools Display Modes
11-07-22, 03:14 PM   #1
Elanthis
A Murloc Raider
Join Date: Nov 2022
Posts: 6
Problem with setting the tex-coords of a statusbar's texture

Pretext:
I am trying to change the health- and manabar textures of the default ui's personal resource display to match the new bar textures of the new Blizzard ui's player and target frames.
For that I use SetAtlas() on the textures used by the status bars of the personal resource display. That works fine, but...
...All variations of those new bar textures (that I can find in the atlas) have at least partially rounded corners. I want to get rid of those by cropping the bar textures at the left and right ends.

The problem:
When using SetTexCoord() on my newly changed health and mana bar textures of the personal resource display, nothing happens - the bar textures aren't cropped.

To elaborate:
The changing of the bar texture takes place after the NAME_PLATE_UNIT_ADDED event fires if the added nameplate's unit is the player (as the personal resource display is just called into existence as another nameplate).
This is when SetTexCoord() is called. When I tell the game to print() the status bar texture's tex-coords in the same function - just after calling SetTexCoord() - I get the newly set tex-coords, just like I want.
But it seems to be overwritten (or something - this is where I need your help) immediately, because I see no visual change in the game and when I manually tell the game to print() the status bar texture's tex-coords at any point in time, I get the un-cropped default coordinates.

Here's a minimal implementation of my code:
Lua Code:
  1. local handleNamePlateAddedFrame = CreateFrame("Frame")
  2. handleNamePlateAddedFrame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
  3. handleNamePlateAddedFrame:SetScript("OnEvent", function(self, event, ...)
  4.     local unitToken = ...
  5.     if not UnitIsPlayer(unitToken) then return end
  6.  
  7.     local namePlate = C_NamePlate.GetNamePlateForUnit(unitToken)
  8.     local healthBar = namePlate.UnitFrame.healthBar
  9.     local healthBarTexture = healthBar:GetStatusBarTexture()
  10.  
  11.     healthBarTexture:SetAtlas("UI-HUD-UnitFrame-Player-PortraitOff-Bar-Health-Status")
  12.     healthBarTexture:SetTexCoord(0.1, 0.9, 0, 1)
  13.  
  14.     -- print(healthBar:GetStatusBarTexture():GetTexCoord())
  15. end)

Some thoughts:
I tried several things to (try to) rule out trivial mistakes/misunderstanding (as I'm not very experienced with all this). I won't post them here now, hoping that the problem is not something trivial and some of you can just instantly spot what's going on here.
If that is not the case and you want to rule out trivial mistakes, tell me and I'll follow up with a list of everything I tried so far.
Else I can just half-guess what's the problem here. One of my tests was to replicate the whole scenario but with just a simple status bar that I created and that I "ran the same code through" as I did with the pre-existing personal resource display status bars. And with my own, simple status bar it worked as expected.
So I figure there's something that the personal resource display structure does under the hood that I don't know of that's messing with my tex-coords.

Final words:
I'm not a very experienced wow programmer, it might be that I am missing something generic here. But I did try to search through the widget api doc and other forum posts regarding this matter and don't seem to be able to solve this one on my own. Help is much appreciated.
  Reply With Quote
11-07-22, 06:14 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Appears texture:SetTexCoord() doesn't work on StatusBars as they keep overwriting it on render.

Generally, texture:SetTexCoord() doesn't work on atlases either, but using C_Texture.GetAtlasInfo() to set by texture file and trimming the supplied texcoord isn't yielding useful results either as it normally would.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 11-07-22 at 07:18 PM.
  Reply With Quote
11-07-22, 07:08 PM   #3
Elanthis
A Murloc Raider
Join Date: Nov 2022
Posts: 6
Thank you for your reply.

Originally Posted by SDPhantom View Post
Appears texture:SetTexCoord() doesn't work on StatusBars as they keep overwriting it on render.
I can confirm this (maybe I should have had my simple test bar actually track something when I first tested with it). Even when putting SetTexCoord() inside the same function that updates the status bar value, it barely works (only when the value's stopped changing for a few seconds).

Lua Code:
  1. local f = CreateFrame("Frame")
  2. f:RegisterEvent("PLAYER_LOGIN")
  3. f:SetScript("OnEvent", function(self, event, ...)
  4.     local tex = f:CreateTexture()
  5.     tex:SetAtlas("UI-HUD-UnitFrame-Player-PortraitOff-Bar-Health-Status")
  6.     tex:SetTexCoord(0.1, 0.9, 0, 1)
  7.     ElanthisStatusBar = CreateFrame("StatusBar")
  8.     ElanthisStatusBar:SetPoint("CENTER", UIParent, "CENTER", 0, -30)
  9.     ElanthisStatusBar:SetSize(126, 12)
  10.     ElanthisStatusBar:SetStatusBarTexture(tex)
  11.  
  12.     ElanthisStatusBar:RegisterEvent("UNIT_POWER_FREQUENT")
  13.     ElanthisStatusBar:SetScript("OnEvent", function(self, event, ...)
  14.         local unitID = ...
  15.         if not UnitIsPlayer(unitID) then return end
  16.         local maxPower = UnitPowerMax(unitID)
  17.         local currentPower = UnitPower(unitID)
  18.         self:SetMinMaxValues(0, maxPower)
  19.         self:SetValue(currentPower)
  20.         -- tex:SetTexCoord(0.1, 0.9, 0, 1)
  21.     end)
  22. end)

Originally Posted by SDPhantom View Post
Generally, texture:SetTexCoord() doesn't work on atlas' either, but using C_Texture.GetAtlasInfo() to set by texture file and trimming the supplied texcoord isn't yielding useful results either as it normally would.
I tried that earlier (sorry, I should have said so) and yea, it seems to be specific to the SetTexCoord() method as a whole.


Do you by chance know if it's possible to define new atlas members from Blizzards atlas' (so I can crop the bar textures "right at the source")?

Else it is probably easier to make up my own texture file with the desired bar texture.
  Reply With Quote
11-07-22, 07:19 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
There's no way to create atlases either.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
11-07-22, 07:24 PM   #5
Elanthis
A Murloc Raider
Join Date: Nov 2022
Posts: 6
Originally Posted by Elanthis View Post
Else it is probably easier to make up my own texture file with the desired bar texture.
I've looked it up and it seems to be surprisingly easy to extract the atlas files from the game. I'll give that a try now. If that works, I'll probably just modify the desired atlas file and load it from my AddOn's directory.
  Reply With Quote
11-07-22, 08:29 PM   #6
Elanthis
A Murloc Raider
Join Date: Nov 2022
Posts: 6
Originally Posted by Elanthis View Post
If that works, I'll probably just modify the desired atlas file and load it from my AddOn's directory.
This is pretty much what I did now. I've taken the textures from the atlas file one by one, put them each in a single file and cropped them the way I wanted. It's more of a work-a-round than a solution, but it works just fine.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Problem with setting the tex-coords of a statusbar's texture

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