Thread Tools Display Modes
04-02-11, 08:48 AM   #1
Monolit
A Black Drake
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 81
reverse status bars (again)

I know this topic came out a couple of times already in the past, but uhm, I've ran search few times and have yet to find a solution to my problem regarding reverse status bars.

So I want my health status bar to fill in reverse, i.e. the bigger amount of health missing - the bigger health status bar is (starting from right to left).

If I understand correctly neither default wow API or oUF allows us to do that with some simple method, so I need to make a PostUpdateHealth hook and change this by my own, but I struggle with that one ...

Setting the new value is easy, but I can't reanchor the texture itself
my PostUpdateHealth function looks like this:
lua Code:
  1. lib.PostUpdateHealth = function(s, unit, min, max)
  2.     if unit=='player' or unit=='target' then
  3.         s:SetValue(max-min)
  4.         s.t = s:GetStatusBarTexture()
  5.         s.t:SetPoint('TOPRIGHT', s, 'TOPLEFT', 0, 0)
  6.     end
  7. end

and hp bar function:
lua Code:
  1. lib.gen_hpbar = function(f)
  2.     local s = CreateFrame("StatusBar", nil, f)
  3.     s:SetStatusBarTexture(cfg.statusbar_texture)
  4.     fixStatusbar(s)
  5.     s:SetHeight(f.height)
  6.     s:SetWidth(f.width)
  7.     s:SetPoint("TOPLEFT",0,0)
  8.     s:SetAlpha(0.65)
  9.     s:SetOrientation("HORIZONTAL")
  10.     local h = CreateFrame("Frame", nil, s)
  11.     h:SetFrameLevel(0)
  12.     h:SetPoint("TOPLEFT",-4,4)
  13.     h:SetPoint("BOTTOMRIGHT",4,-4)
  14.     lib.gen_backdrop(h)
  15.     local b = s:CreateTexture(nil, "BACKGROUND")
  16.     b:SetTexture(cfg.statusbar_texture)
  17.     b:SetAllPoints(s)
  18.     s.PostUpdate = lib.PostUpdateHealth
  19.     f.Health = s
  20.     f.Health.bg = b
  21.   end

So basically I get bar with the right value, but it's placed at default position, i.e. anchored to right and filling up towards left. Any help or some kind of clues would be appreciated!

Last edited by Monolit : 04-02-11 at 02:05 PM.
  Reply With Quote
04-02-11, 12:36 PM   #2
Saiket
A Chromatic Dragonspawn
 
Saiket's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 154
I think that StatusBars delay re-anchoring their textures until just before the next OnUpdate, so you'll have to use an OnUpdate handler to re-position the texture. Here's the function I use to create a reverse status bar in my UI:
http://code.google.com/p/wow-saiket/...lua?r=1574#313

Last edited by Saiket : 04-03-11 at 07:47 PM.
  Reply With Quote
04-03-11, 05:44 AM   #3
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Couldn't you just switch colors. (dark foreground, light background). That way if the bar depletes the bright color will become more and more visible.
__________________
| 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
04-03-11, 07:30 AM   #4
Monolit
A Black Drake
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 81
Originally Posted by Saiket View Post
I think that StatusBars delay re-anchoring their textures until just before the next OnUpdate, so you'll have to use an OnUpdate handler to re-position the texture. Here's the function I use to create a reverse status bar in my UI:
http://code.google.com/p/wow-saiket/...ts.oUF.lua#313
hm, that definitely helps although I thought it was possible to avoid using OnUpdate scripts

Originally Posted by zork View Post
Couldn't you just switch colors. (dark foreground, light background). That way if the bar depletes the bright color will become more and more visible.
I thought about that too, but the problem is that I want to have 3d portrait in the background and you can't really do that with portraits :/
i.e. I want this bar to overlay the background with the portrait

Last edited by Monolit : 04-03-11 at 08:08 AM.
  Reply With Quote
04-03-11, 12:28 PM   #5
Saiket
A Chromatic Dragonspawn
 
Saiket's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 154
Originally Posted by Monolit View Post
hm, that definitely helps although I thought it was possible to avoid using OnUpdate scripts
Those OnUpdate scripts don't run all the time; They run once right after the bar value changes, and then they shut themselves off. The CPU usage for that kind of throttle is insignificant.
  Reply With Quote
04-03-11, 03:33 PM   #6
Monolit
A Black Drake
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 81
Originally Posted by Saiket View Post
Those OnUpdate scripts don't run all the time; They run once right after the bar value changes, and then they shut themselves off. The CPU usage for that kind of throttle is insignificant.
Oh well, you're right and this method worked, got exactly what I was looking for, thank you.

P.S.
Just out of curiosity why do you wrap your OnUpdate functions in 'do ... end' loop? I've read something about this a while ago... something about optimizing lua code, but can't really find it right now, so could you please enlighten me?

Last edited by Monolit : 04-03-11 at 03:44 PM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » reverse status bars (again)


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