Thread Tools Display Modes
01-25-12, 02:57 AM   #1
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
Changing statusbar alpha independently of background alpha

Hi! I'm working on a GUI-configurable oUF layout. I think I have most of the bar elements down, but there's one that I can't figure out. I would like the user to be able to change the statusbar alpha while leaving the background alpha intact (to permit the transparent frames some people like to use).

I know this is theoretically possible because it works in Pitbull - I can make a statusbar transparent, and as it depletes, the transparent bar "uncovers" the visible background.

But I can't figure out how to make it work. If I parent the background to the bar and change the bar alpha, the background alpha changes. If I parent the background to the frame, the whole background is visible. Do I need to make the 'background' be a statusbar itself and have it show missing health?

(I've already technically got a way for the user to accomplish transparent frames - they can invert the bar (to show missing health), reverse the direction, and make the background transparent. But that seems a little unintuitive and confusing, and it won't work for partial opacity.)

Also, if the user wants to use the colorDisconnect flag and also use custom bar and background colors, is there a non-ugly way to make the custom color come back when a disconnected player reconnects?
  Reply With Quote
01-25-12, 03:06 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
You only have to adjust the SetStatusBarColor() which is in RGBA. A is for alpha.

If you define bar.bg that will be your background. If your bar.bg has class-color and your statusbar is very dark-greyscale but a tiny bit transparent the class color will shine through a little bit.

Because bar.bg is a child of bar (your statusbar) and you adjust the SetAlpha() of it the bar.bg will follow. So use SetStatusBarColor() if you can. [http://wowprogramming.com/docs/widge...tatusBarColor]
__________________
| 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 : 01-25-12 at 03:10 AM.
  Reply With Quote
01-25-12, 05:32 AM   #3
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
I think maybe a picture would help. I want to make it so that it's possible to do this:

where the statusbar is transparent but the opaque background shows when it depletes.

It's possible to do that by manipulating the statusbar (run a PostUpdate to make it show missing health instead of remaining, reverse the direction, and make the backdrop transparent). But I'd prefer to make it so that that's simply the default behaviour of the statusbar - the background doesn't show under the part it 'covers', even if the bar itself is partly or fully transparent.

I think I know what the solution has to be. The background has to be a second statusbar, and I need to define its behaviour in a PostUpdate() on the main bar.
  Reply With Quote
01-25-12, 08:06 AM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Actually you must have an error. Just define bar.bg it's a known oUF object on statusbars. It will be behind your statusbar at full width. The statusbar itself may deplete but the background does not. If that is not the case for you check your code again.
__________________
| 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
01-25-12, 04:58 PM   #5
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
Nono. It's working properly. The picture I posted is what I want to happen, not what's actually happening.

I think I've *almost* figured out the solution. The problem is that right now it's working properly for the power bar, but not for the health bar, even though the code is identical. See here:

The coloring on the power bar "background" bar (bottom, in blue) is applied properly, but the health bar (middle, in purple) background isn't colored. And if I make the 'foreground' bar transparent, I can also see that the power bar 'background' is updating properly, but the health bar 'background' is not:


Here's my bar constructor. I seriously have no idea why the two bars would behave differently - they're constructed identically.
lua Code:
  1. lib.GenerateBar = function(f, n, b, isgroup)
  2.     local style
  3.     if isgroup then
  4.         style = profile.groupframes[n].bars[b]
  5.     else
  6.         style = profile.unitframes[n].bars[b]
  7.     end
  8.    
  9.     local bg = CreateFrame("StatusBar", nil, f)
  10.     bg:SetStatusBarTexture(LSM:Fetch("statusbar", style.texture))
  11.     bg:SetHeight(f.height * style.heightmult)
  12.     bg:SetWidth(f.width * style.widthmult)
  13.     bg:SetPoint(style.anchor, f, style.anchor,
  14.                 f.width * style.xoffsetmult, f.height * style.yoffsetmult)
  15.     bg:SetFrameLevel(style.level * 2 + 1)
  16.    
  17.     local s = CreateFrame("StatusBar", nil, f)
  18.     s:SetStatusBarTexture(LSM:Fetch("statusbar", style.texture))
  19.     s:SetHeight(f.height * style.heightmult)
  20.     s:SetWidth(f.width * style.widthmult)
  21.     s:SetPoint(style.anchor, f, style.anchor,
  22.                 f.width * style.xoffsetmult, f.height * style.yoffsetmult)
  23.     s:SetFrameLevel(style.level * 2 + 3)
  24.    
  25.     local h = CreateFrame("Frame", nil, s)
  26.     h:SetPoint("TOPLEFT", -style.bginset, style.bginset)
  27.     h:SetPoint("BOTTOMRIGHT", style.bginset, -style.bginset)
  28.     h:SetFrameLevel(style.level * 2)
  29.     lib.GenerateBackdrop(h, style)
  30.    
  31.     if (style.reverse and not style.invert) or (style.invert and not style.reverse) then
  32.         s:SetReverseFill(true)
  33.         bg:SetReverseFill(false)
  34.     else
  35.         s:SetReverseFill(false)
  36.         bg:SetReverseFill(true)
  37.     end
  38.    
  39.     if style.vertical then
  40.         s:SetOrientation("VERTICAL")
  41.         s:SetRotatesTexture(true)
  42.         bg:SetOrientation("VERTICAL")
  43.         bg:SetRotatesTexture(true)
  44.     else
  45.         s:SetOrientation("HORIZONTAL")
  46.         s:SetRotatesTexture(false)
  47.         bg:SetOrientation("HORIZONTAL")
  48.         bg:SetRotatesTexture(false)
  49.     end
  50.    
  51.     s.bar_bg = bg
  52.     s.backdrop = h
  53.     local iscustombg = style.bgcolorCustom
  54.     local mult = style.barbgmultiplier
  55.     if b == 1 then
  56.         f.Health = s
  57.         if style.invert then
  58.             f.Health.PostUpdate = function(self, unit, min, max)
  59.                 self.bar_bg:SetMinMaxValues(0, max)
  60.                 self.bar_bg:SetValue(min)
  61.                 self:SetValue(max - min)
  62.                 if not iscustombg then
  63.                     local r, g, b = self:GetStatusBarColor()
  64.                     self.bar_bg:SetStatusBarColor(r*mult, g*mult, b*mult)
  65.                 end
  66.             end
  67.         else
  68.             f.Health.PostUpdate = function(self, unit, min, max)
  69.                 self.bar_bg:SetMinMaxValues(0, max)
  70.                 self.bar_bg:SetValue(max - min)
  71.                 if not iscustombg then
  72.                     local r, g, b = self:GetStatusBarColor()
  73.                     self.bar_bg:SetStatusBarColor(r*mult, g*mult, b*mult)
  74.                 end
  75.             end
  76.         end
  77.     elseif b ==2 then
  78.         f.Power = s
  79.         if style.invert then
  80.             f.Power.PostUpdate = function(self, unit, min, max)
  81.                 self.bar_bg:SetMinMaxValues(0, max)
  82.                 self.bar_bg:SetValue(min)
  83.                 self:SetValue(max - min)
  84.                 if not iscustombg then
  85.                     local r, g, b = self:GetStatusBarColor()
  86.                     self.bar_bg:SetStatusBarColor(r*mult, g*mult, b*mult)
  87.                 end
  88.             end
  89.         else
  90.             f.Power.PostUpdate = function(self, unit, min, max)
  91.                 self.bar_bg:SetMinMaxValues(0, max)
  92.                 self.bar_bg:SetValue(max - min)
  93.                 if not iscustombg then
  94.                     local r, g, b = self:GetStatusBarColor()
  95.                     self.bar_bg:SetStatusBarColor(r*mult, g*mult, b*mult)
  96.                 end
  97.             end
  98.         end
  99.     elseif b == 3 then
  100.         f.AltPowerBar = s
  101.         if style.invert then
  102.             f.AltPowerBar.PostUpdate = function(self, min, cur, max)
  103.                 self.bar_bg:SetMinMaxValues(0, max)
  104.                 self.bar_bg:SetValue(cur)
  105.                 self:SetValue(max - cur)
  106.                 if not iscustombg then
  107.                     local r, g, b = self:GetStatusBarColor()
  108.                     self.bar_bg:SetStatusBarColor(r*mult, g*mult, b*mult)
  109.                 end
  110.             end
  111.         else
  112.             f.AltPowerBar.PostUpdate = function(self, min, cur, max)
  113.                 self.bar_bg:SetMinMaxValues(0, max)
  114.                 self.bar_bg:SetValue(max - cur)
  115.                 if not iscustombg then
  116.                     local r, g, b = self:GetStatusBarColor()
  117.                     self.bar_bg:SetStatusBarColor(r*mult, g*mult, b*mult)
  118.                 end
  119.             end
  120.         end
  121.     end
  122. end

Last edited by kaels : 01-25-12 at 05:57 PM.
  Reply With Quote
01-25-12, 05:57 PM   #6
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
And this is getting incredibly frustrating. I know it's *trying* to SetStatusBarColor, because if I change it to SetVertexColor, it spams me with errors. But no matter how many times it tries to set the color, the color doesn't get set.

I tried, as an experiment, changing the Health element code in oUF itself to do what I want instead of doing it in a PostUpdate. It behaves exactly the same way. White bar that doesn't update. What can I possibly be doing wrong that only affects the Health element?
  Reply With Quote
01-25-12, 07:23 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Install BugSack/!BugGrabber and report the errors you're getting at load, if any.

Also, post the rest of your addon code.
  Reply With Quote
01-25-12, 07:29 PM   #8
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
I tried adding some debug text and moving the background bar out of the frame so I could see it clearly:
lua Code:
  1. else
  2.             f.Health.PostUpdate = function(self, unit, min, max)
  3.                 self.bar_bg:SetMinMaxValues(0, max)
  4.                 self.bar_bg:SetValue(max - min)
  5.                 oUF_Kael:Print("Intended value is "..(max - min))
  6.                 oUF_Kael:Print("My value is "..self.bar_bg:GetValue())
  7.                 if not iscustombg then
  8.                     local r, g, b = self:GetStatusBarColor()
  9.                     oUF_Kael:Print("Statusbar color is "..r.." "..g.." "..b)
  10.                     self.bar_bg:SetStatusBarColor(r*mult, g*mult, b*mult)
  11.                     local testr, testb, testg = self.bar_bg:GetStatusBarColor()
  12.                     oUF_Kael:Print("My color is "..testr.." "..testg.." "..testb)
  13.                 end
  14.             end
  15.         end


As you can see, it *thinks* it has a color and a value, it's getting them properly from the health bar updates, but it's not actually displaying them; it's permanently white and full. The dark blue bar (mana) is behaving properly using exactly the same syntax.
  Reply With Quote
01-25-12, 07:33 PM   #9
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
Originally Posted by Phanx View Post
Install BugSack/!BugGrabber and report the errors you're getting at load, if any.

Also, post the rest of your addon code.
There's way more code than anyone would want to wade through on a forum...any suggestions on where to post it?

I haven't documented it yet, either. And most of it isn't called until the GUI is called, and the GUI portion is a mess that nobody wants to read. I could just post the lib functions that are called for constructing the frames?

Will definitely try BugSack/!BugGrabber. I haven't seen any errors in the standard Lua error frame.
  Reply With Quote
01-25-12, 07:54 PM   #10
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
Got BugSack. No errors on load, and I'm unable to trigger any errors except by triggering GUI functions that reference the old static bar background texture.
  Reply With Quote
01-25-12, 08:00 PM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by kaels View Post
There's way more code than anyone would want to wade through on a forum...any suggestions on where to post it?
Just zip it up and attach it to a post. My main thought was that it might be easier for someone to load your addon in-game and see the behavior in question than try to make sense of screenshots.

Originally Posted by kaels View Post
I haven't seen any errors in the standard Lua error frame.
The problem with the standard error frame is that it does not show errors that occur early during the loading process, which is where many addon errors occur if there is a problem with your code.

Also, BugSack has the advantage of being able to store errors for later perusal, instead of forcing you to deal with it immediately or lose it forever.
  Reply With Quote
01-25-12, 08:22 PM   #12
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
Ah, ok. Here:

(the chat command to open the GUI is /kael or /kl. Most of the options currently implemented work, but the color selections for the bars do nothing at the moment - edit values in database.lua under default.unitframes.**.bars.** to change them.)
Attached Files
File Type: zip oUF_Kael.zip (313.2 KB, 625 views)

Last edited by kaels : 01-25-12 at 08:35 PM.
  Reply With Quote
01-26-12, 12:37 AM   #13
kaels
A Cyclonian
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 46
Followup: I have absolutely no idea why, but splitting out the background constructor into its own function fixed the problem. Thanks Phanx and Zork for the advice, and thanks especially for pointing me to BugSack

Oh! I figured out the problem. It wasn't actually the health bar that was misbehaving - it was the alternate power bar, which just happened to default to being exactly on top of the health bar.

Last edited by kaels : 01-26-12 at 01:32 AM.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Changing statusbar alpha independently of background alpha

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