Thread Tools Display Modes
03-04-16, 07:31 PM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Texture:SetTexCoord() is not working for texture of Health StatusBar created via oUF

So, I've been posting this on "Graphics Help" forum and came back here as I'm guessing that my issue is related to oUF.

First of all, here's lines of code that I wrote to create Health bar:
Lua Code:
  1. local LSM = LibStub("LibSharedMedia-3.0");
  2.  
  3. local HEALTH_BAR = LSM:Fetch("statusbar", "fer10");
  4.  
  5. A.CreateHealthBar = function(f, unit)
  6.     local Health = CreateFrame("StatusBar", f:GetName() .. "HealthBar", f);
  7.     Health:SetFrameStrata("LOW");
  8.     Health:SetStatusBarTexture(HEALTH_BAR);
  9.     Health:SetStatusBarColor(0.69, 0.69, 0.69, 1);
  10.  
  11.     if (unit == "player" or unit == "target") then
  12.         Health:SetSize(f:GetWidth() - 82, f:GetHeight() - 38);
  13.  
  14.         if (unit == "player") then
  15.             Health:SetPoint("TOPRIGHT", f, "TOPRIGHT", -1, -1);
  16.         elseif (unit == "target") then
  17.             Health:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
  18.             Health:SetReverseFill(true);
  19.             Health:GetStatusBarTexture():SetTexCoord(1, 0, 0, 1);
  20.         end
  21.     end
  22.    
  23.     ...
  24. end

So, I utilized Texture:SetTexCoord() to simply flip the status bar along the axis if the unit is a "target" and "Health:GetStatusBarTexture():SetTexCoord(1, 0, 0, 1);" did not work at all...

Well... it could be working but something inside oUF module must be updating it again after its initialization, so that it actually goes back to its original state.

The reason that I made this assumption is because the following lines of code worked perfectly outside oUF:
Lua Code:
  1. local LSM = LibStub("LibSharedMedia-3.0");
  2.  
  3. local BAR = LSM:Fetch("statusbar", "fer10");
  4.  
  5. local testbar = CreateFrame("StatusBar", nil, UIParent);
  6. testbar:SetSize(248, 40);
  7. testbar:SetPoint("CENTER");
  8. testbar:SetStatusBarTexture(BAR);
  9. testbar:GetStatusBarTexture():SetTexCoord(1, 0, 0, 1);

So for the testing, inside "health.lua" module, I actually added "health:GetStatusBarTexture():SetTexCoord(1, 0, 0, 1);" before/after "health.PostUpdate" (inside Update function) is called and it performed some kind of ugly animation ...

Could anyone please tell me how I could achieve my object without destroying the things.

Last edited by Layback_ : 03-04-16 at 09:38 PM.
  Reply With Quote
03-05-16, 06:45 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Ok I tried my best to explain it to you in the other thread but I seem to have failed.

I created an addon for you: oUF_Doom.

https://github.com/zorker/rothui/tre...ow6.0/oUF_Doom

Screenshots: http://imgur.com/a/BHfcs

It does exactly what I described in the other thread. Create a fake statusbar for value updates.
Create a texture and apply the value changes via SetTexCoord to that texture.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 03-05-16 at 06:52 AM.
  Reply With Quote
03-05-16, 06:19 PM   #3
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by zork View Post
Ok I tried my best to explain it to you in the other thread but I seem to have failed.

I created an addon for you: oUF_Doom.

https://github.com/zorker/rothui/tre...ow6.0/oUF_Doom

Screenshots: http://imgur.com/a/BHfcs

It does exactly what I described in the other thread. Create a fake statusbar for value updates.
Create a texture and apply the value changes via SetTexCoord to that texture.
Mmmmmmmmm.....

I don't know why that is not working for me..............

Like I mentioned it works fine outside oUF, but not working within functions that I created for oUF D:.........

Maybe I should give it an another try.



P.S: I know you tried your best to explain as much as you know, and I really and really appreciate your help.
  Reply With Quote
03-07-16, 05:39 PM   #4
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by zork View Post
Ok I tried my best to explain it to you in the other thread but I seem to have failed.

I created an addon for you: oUF_Doom.

https://github.com/zorker/rothui/tre...ow6.0/oUF_Doom

Screenshots: http://imgur.com/a/BHfcs

It does exactly what I described in the other thread. Create a fake statusbar for value updates.
Create a texture and apply the value changes via SetTexCoord to that texture.
Hi zork,

before I go further, I guess I need some clarifications regarding PreUpdate and PostUpdate.

Could I get some explanations regarding them?

Last edited by Layback_ : 03-07-16 at 05:57 PM.
  Reply With Quote
03-09-16, 06:00 PM   #5
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
oUF handles element events for you (like UNIT_HEALTH, UNIT_POWER etc.). If one fires oUF runs its UpdateHealth or UpdatePower function. That will update any element you created of that type. Sometimes you want to hook that event. This the case in this example since we are using the statusbar for value updates only. The real visible statusbar is a texture.
__________________
| 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
03-10-16, 03:42 PM   #6
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by zork View Post
oUF handles element events for you (like UNIT_HEALTH, UNIT_POWER etc.). If one fires oUF runs its UpdateHealth or UpdatePower function. That will update any element you created of that type. Sometimes you want to hook that event. This the case in this example since we are using the statusbar for value updates only. The real visible statusbar is a texture.
So, do PreUpdate and PostUpdate have a different call time?

I understand that they are called based on events, but...




EDIT: Sorry for keep asking... I'm just way too stupid to understand things at once...

Last edited by Layback_ : 03-11-16 at 05:35 AM.
  Reply With Quote
03-11-16, 06:52 AM   #7
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
PreUpdate and PostUpdate do excactly what you would think they do. The first one is called before the update function runs. The latter runs after the update function is done.

Power PreUpdate call
https://github.com/haste/oUF/blob/ma...power.lua#L130

Power PostUpdate call
https://github.com/haste/oUF/blob/ma...power.lua#L196

Try reading through oUF/elements and to get a better understanding how each element works.
__________________
| 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
03-11-16, 09:59 PM   #8
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by zork View Post
PreUpdate and PostUpdate do excactly what you would think they do. The first one is called before the update function runs. The latter runs after the update function is done.

Power PreUpdate call
https://github.com/haste/oUF/blob/ma...power.lua#L130

Power PostUpdate call
https://github.com/haste/oUF/blob/ma...power.lua#L196

Try reading through oUF/elements and to get a better understanding how each element works.
Yeah, I've seen those structures (PreUpdate - some codes - PostUpdate) from most of oUF elements.

So, where could I find the definition of PreUpdate and PostUpdate function?

I've been searching for their function definition inside oUF and could've not found any (as there were only function calls)...

Also, I have dumped PostUpdate of my power bar (e.g: /dump oUF_PlayerFrame.Power.PostUpdate) and it returned nil.

Do they act as an placeholder until I actually set some functions to them like what you have done on your oUF_Doom (e.g: self.Health.PostUpdate = UpdateHealth)?



Sorry for keep asking things...



EDIT: I have utilized your oUF_Doom codes and tried to create something similar (without making fake health bar actually)
Lua Code:
  1. A.CreateHealthBar = function(f, unit)
  2.     local Health = CreateFrame("StatusBar", f:GetName() .. "HealthBar", f);
  3.     Health:SetFrameStrata("LOW");
  4.     Health:SetStatusBarTexture(HEALTH_BAR);
  5.     Health:SetStatusBarColor(0.69, 0.69, 0.69, 1);
  6.  
  7.     if (unit == "player" or unit == "target") then
  8.         Health:SetSize(f:GetWidth() - 67, f:GetHeight() - 30);
  9.  
  10.         if (unit == "player") then
  11.             Health:SetPoint("TOPRIGHT", f, "TOPRIGHT", -1, -1);
  12.         elseif (unit == "target") then
  13.             Health:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1);
  14.  
  15.             Health.PostUpdate = A.PostUpdateHealth;
  16.         end
  17.     end
  18.  
  19.     local backdrop = CreateFrame("Frame", nil, Health);
  20.     backdrop:SetSize(Health:GetWidth() + 2, Health:GetHeight() + 2);
  21.     backdrop:SetPoint("CENTER");
  22.     backdrop:SetBackdrop({
  23.         bgFile = nil,
  24.         edgeFile = BACKDROP,
  25.         edgeSize = 1,
  26.         insets = {
  27.             left = 1,
  28.             right = 1,
  29.             top = 1,
  30.             bottom = 1,
  31.         },
  32.     });
  33.     backdrop:SetBackdropBorderColor(0, 0, 0, 1);
  34.  
  35.     Health.backdrop = backdrop;
  36.  
  37.     Health.bg = Health:CreateTexture(nil, "BACKGROUND");
  38.     Health.bg:SetAllPoints(true);
  39.     Health.bg:SetTexture(BACKDROP);
  40.     Health.bg:SetVertexColor(0.05, 0.05, 0.05, 1);
  41.  
  42.     f.Health = Health;
  43.     f.Health.bg = Health.bg;
  44. end
  45.  
  46. A.PostUpdateHealth = function(self, unit)
  47.     local hmin,hmax = self:GetMinMaxValues();
  48.     local hcur = self:GetValue();
  49.     local hcurp = hcur / hmax or 0;
  50.  
  51.     local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy = 0, 0, 0, 1, hcurp, 0, hcurp, 1;
  52.  
  53.     self:GetStatusBarTexture():SetTexCoord(URx,URy, LRx,LRy, ULx,ULy, LLx,LLy);
  54. end
  55.  
  56. C.styles["target"] = function(f, unit)
  57.     A.CreateHealthBar(f, unit);
  58. end
  59.  
  60. C.stylemanager = function(f, unit)
  61.     if C.styles[unit] then
  62.         C.styles[unit](f, unit);
  63.     end
  64. end
  65.  
  66. YUF:RegisterStyle("YUF_Style", C.stylemanager);
  67.  
  68. YUF:Spawn("target", "YUI_Target");

where A and C are elements of AddonTable.

So, in my case, SetTexCoord works only when I select target - deselect - select same target again.

And when it gets to update status bar (like when status bar's value changes), the texture goes back to original coordinate points...

(P.S: I just used oUF's default 'health' element)

Last edited by Layback_ : 03-12-16 at 12:38 AM.
  Reply With Quote
03-12-16, 12:23 PM   #9
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
I think you are correct on that. Applying SetTexCoord to a statusbar texture is not working. You need that extra texture.
__________________
| 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
03-12-16, 07:43 PM   #10
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by zork View Post
I think you are correct on that. Applying SetTexCoord to a statusbar texture is not working. You need that extra texture.
damn............................................................

another texture QQ.........................................


Do you reckon that's the problem with WoW API or something wrong with internal siad of oUF?

Last edited by Layback_ : 03-12-16 at 08:06 PM.
  Reply With Quote
03-14-16, 03:29 AM   #11
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Well you could just create a statusbar on your own and test it.
Lua Code:
  1. local p = CreateFrame("StatusBar",nil,UIParent)
  2. p:SetSize(256,32)
  3. p:SetPoint("CENTER")
  4. p:SetStatusBarTexture("myTexture")
  5. p:RegisterUnitEvent("UNIT_POWER","player")
  6.  
  7. local function OnEvent(self,event,unit,...)
  8.   local pc, pm = UnitPower(unit), UnitPowerMax(unit)
  9.   self:SetMinMaxValues(0,pm)
  10.   self:SetValue(pc)
  11.   print(...)
  12. end
  13.  
  14. p:HookScript("OnEvent",OnEvent)
__________________
| 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
03-19-16, 05:29 AM   #12
Folji
A Flamescale Wyrmkin
 
Folji's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 136
Decided to try and test this, see how it'd go.

Lua Code:
  1. lib.CreateHealth = function(frame,frametype,width,height,point,x,y)
  2.  
  3.     local hp = CreateFrame('StatusBar',nil,frame)
  4.     hp:SetSize(width,height)
  5.     hp:SetPoint(point,frame,x,y)
  6.     hp:SetStatusBarTexture('Interface\\AddOns\\TestUI\\media\\playerhp')
  7.     hp:SetStatusBarColor(0,1,0)
  8.     hp:RegisterUnitEvent('UNIT_HEALTH', frametype)
  9.  
  10.     if (frametype == 'target') then
  11.         hp:SetReverseFill(true)
  12.         hp:GetStatusBarTexture():SetTexCoord(1,0,0,1)
  13.         hp:GetStatusBarTexture():SetPoint('RIGHT', hp)
  14.     end
  15.  
  16.     local function HealthUpdate()
  17.         local hpcur, hpmax = UnitHealth(frametype), UnitHealthMax(frametype)
  18.         hp:SetMinMaxValues(0,hpmax)
  19.         hp:SetValue(hpcur)
  20.     end
  21.  
  22.     hp:HookScript("OnEvent",HealthUpdate)
  23.  
  24.     local function CheckCoords()
  25.         print(frametype.." : "..hp:GetStatusBarTexture():GetPoint())
  26.         print(hp:GetStatusBarTexture():GetTexCoord())
  27.  
  28.     end
  29.  
  30.     frame:HookScript('OnMouseUp',CheckCoords)
  31. end

Seems like not being able to use hp:GetStatusBarTexture():SetTexCoord(1,0,0,1) to flip the texture is largely down to how the game handles statusbars? I don't know if I'm writing something wrong here or what, but testing around with it showed me that the statusbars were narrowing by changing the TexCoords directly. So no matter what it was set to before, it'd change back to 0,1,0,1 and then gradually drop down from there.

GetStatusBarTexture():GetPoint() defaulted to TOPLEFT, and trying to SetPoint() did absolutely nothing.
  Reply With Quote
03-20-16, 06:17 PM   #13
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by Folji View Post
Decided to try and test this, see how it'd go.

Lua Code:
  1. lib.CreateHealth = function(frame,frametype,width,height,point,x,y)
  2.  
  3.     local hp = CreateFrame('StatusBar',nil,frame)
  4.     hp:SetSize(width,height)
  5.     hp:SetPoint(point,frame,x,y)
  6.     hp:SetStatusBarTexture('Interface\\AddOns\\TestUI\\media\\playerhp')
  7.     hp:SetStatusBarColor(0,1,0)
  8.     hp:RegisterUnitEvent('UNIT_HEALTH', frametype)
  9.  
  10.     if (frametype == 'target') then
  11.         hp:SetReverseFill(true)
  12.         hp:GetStatusBarTexture():SetTexCoord(1,0,0,1)
  13.         hp:GetStatusBarTexture():SetPoint('RIGHT', hp)
  14.     end
  15.  
  16.     local function HealthUpdate()
  17.         local hpcur, hpmax = UnitHealth(frametype), UnitHealthMax(frametype)
  18.         hp:SetMinMaxValues(0,hpmax)
  19.         hp:SetValue(hpcur)
  20.     end
  21.  
  22.     hp:HookScript("OnEvent",HealthUpdate)
  23.  
  24.     local function CheckCoords()
  25.         print(frametype.." : "..hp:GetStatusBarTexture():GetPoint())
  26.         print(hp:GetStatusBarTexture():GetTexCoord())
  27.  
  28.     end
  29.  
  30.     frame:HookScript('OnMouseUp',CheckCoords)
  31. end

Seems like not being able to use hp:GetStatusBarTexture():SetTexCoord(1,0,0,1) to flip the texture is largely down to how the game handles statusbars? I don't know if I'm writing something wrong here or what, but testing around with it showed me that the statusbars were narrowing by changing the TexCoords directly. So no matter what it was set to before, it'd change back to 0,1,0,1 and then gradually drop down from there.

GetStatusBarTexture():GetPoint() defaulted to TOPLEFT, and trying to SetPoint() did absolutely nothing.
Hi Folji,

That's exactly what I have experienced.

Like you said, no matter what change is made, it changes back to 0, 1, 0, 1
  Reply With Quote
03-20-16, 07:00 PM   #14
Folji
A Flamescale Wyrmkin
 
Folji's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 136
Yeah, seems it basically is just how the game does statusbars. The texture is anchored to the TOPLEFT of the statusbar, and the TexCoords are continually overwritten based on the percentage HP of the unit in question (at least that would be my assumption, as far as the percentage HP). Guess the texture anchoring might be hardcoded into the Blizzard function that updates statusbars?
  Reply With Quote
03-21-16, 07:52 AM   #15
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Not a real issue though. Just create your own statusbar texture.
__________________
| 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
03-21-16, 03:43 PM   #16
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by zork View Post
Not a real issue though. Just create your own statusbar texture.
Like what you have done on your oUF_Doom? (That was awesome btw)

I actually have a question to ask regarding that.

When you create a doomHealth, don't you need to AddElement first (like oUF:AddElement('Health', Path, Enable, Disable))?

I don't really get how AddElement function works as there was no description written on API page
  Reply With Quote
03-21-16, 04:38 PM   #17
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
AddElement enables the element (module) you are looking at for the oUF framework. Basically the health element is like a module that needs to be enabled to work. You sort of register that module to oUF with that function call. Once you have done that you can use self.Health = myHealthStatusBar etc.
__________________
| 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
03-21-16, 11:33 PM   #18
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by zork View Post
AddElement enables the element (module) you are looking at for the oUF framework. Basically the health element is like a module that needs to be enabled to work. You sort of register that module to oUF with that function call. Once you have done that you can use self.Health = myHealthStatusBar etc.
What about the case of your oUF_Doom?

I had gone through your oUF_Doom and It does not seem to have oUF:AddElement("doomHealth", ...) something like this.
  Reply With Quote
03-23-16, 04:07 AM   #19
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
That is because oUF_Doom is using the default health element (module) that oUF is providing and which is available via self.Health = healthBar. I do not need my own element.

For example if you play a warlock and want to create your own soul shards module with oUF you can do it by creating your own element and registering it to oUF.
__________________
| 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
03-25-16, 05:16 PM   #20
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by zork View Post
That is because oUF_Doom is using the default health element (module) that oUF is providing and which is available via self.Health = healthBar. I do not need my own element.

For example if you play a warlock and want to create your own soul shards module with oUF you can do it by creating your own element and registering it to oUF.
Hi again zork,

But, doesn't that mean it has to be self.Health = doomHealth? not self.doomHealth = doomHealth?

I also used default health element, tried self.testHealth = Health and it didn't work since the default health element refers to self.Health as its health bar.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Texture:SetTexCoord() is not working for texture of Health StatusBar created via oUF


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