Quantcast Inverted health - WoWInterface
Thread Tools Display Modes
12-09-14, 05:43 PM   #1
MoonWitch
A Firelord
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 455
Inverted health

I am trying to learn - let's start off with that.

Now .colorHealth (and all others) seem only applicable to self.Health. But I would like to have self.Health have a set color (yes, dark as everyone else :P) and have self.Health.bg have the .colorHealth, .colorSmooth (etc).

I tried in the simplest form obviously, but - no.

I thought about doing it by changing the color tables and trying to get it right by using the multiplier on the background. But I am not sure if this is indeed the way to go.

I am not looking for the straight answer, just a pointer so I can "discover" it. (It helps me understand.)

@Phanx, I love your code, but it's way too advanced for me - the color part. Spent an hour trying to make sense of it, and it's just not getting in there :P
__________________
  Reply With Quote
12-09-14, 09:49 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you want anything other than the coloring oUF provides, you have to do it yourself in a PostUpdate or Override function. Based on your description:

I would like to have self.Health have a set color (yes, dark as everyone else :P) and have self.Health.bg have the .colorHealth, .colorSmooth (etc).
The simplest way to achieve that would be to let oUF do its thing, and then just re-color the health bar (but not its background) yourself in your PostUpdate function.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote
12-10-14, 08:37 PM   #3
MoonWitch
A Firelord
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 455
Originally Posted by Phanx View Post
If you want anything other than the coloring oUF provides, you have to do it yourself in a PostUpdate or Override function. Based on your description:



The simplest way to achieve that would be to let oUF do its thing, and then just re-color the health bar (but not its background) yourself in your PostUpdate function.
I seem to have my blonde days, don't I?

I kept on trying though, but got lost in all of it. I actually made the booboo of trying to read about 15 layouts and making sense of it. It's bad.

I think I'll just scratch what I currently have and start again properly. (Seems to be a trend, doesn't it?)

Is there actually a recommended way-to-go?
I mix declaring a local as frame and then register with oUF and using the oUF "globals".

eg (drycode btw)
Lua Code:
  1. local hpbar = self:CreateStatusbar(nil, 'Frame')
  2. self.Health = hpbar

or

Lua Code:
  1. self.Health = self:CreateStatusbar(nil, 'Frame')

I assumed less code is less CPU cycles, but localising everything has more advantages - so I keep feeling rather torn between them. Since I pull the entire oUF namespace into a local; I kinda figured it was ok, but I could be wrong - easily.
__________________
  Reply With Quote
12-10-14, 09:57 PM   #4
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
I'd go with

Code:
local hp = CreateFrame("StatusBar", nil, self)
self.Health = hp
Which means you can save yourself some typing whenever you address hp, at least that's the main advantage for me.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
12-10-14, 10:05 PM   #5
Freebaser
A Molten Kobold Bandit
 
Freebaser's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2008
Posts: 135
To help with the inverted hp idea, Phanx suggestion would work like this.

Code:
self.Health.colorClass = true  -- let oUF color the health bar

...

-- oUF Health will set the color of .bg if it exist
-- Using multiplier for shade of the Health bar
-- 1 is the default original color of the Health bar

self.Health.bg.multiplier = 1

-- Use PostUpdate to change the Health bar to your color of choice

self.Health.PostUpdate = HealthPostUpdate
Code:
local function HealthPostUpdate(health, unit, min, max)
    health:SetStatusBarColor(r, g, b)
end
  Reply With Quote
12-10-14, 10:30 PM   #6
MoonWitch
A Firelord
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 455
I honestly can't -- why didn't I actually consider that Override .... Simple as - well everything.
I -- have no excuse. Really...

Thank you guys and girl .

(I literally had this face btw without the fur though )
__________________
  Reply With Quote
12-10-14, 10:32 PM   #7
MoonWitch
A Firelord
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 455
Originally Posted by Dawn View Post
I'd go with

Code:
local hp = CreateFrame("StatusBar", nil, self)
self.Health = hp
Which means you can save yourself some typing whenever you address hp, at least that's the main advantage for me.
Also; I am a bit fan of multiple selections in ST3; or Atom. So that typing doesn't bother me that much. Heavy use of snippets and such also help a lot. (I have snippets for the base of an add-on with event, without, TOC file, frame creation and oUF layouts)
__________________
  Reply With Quote
12-11-14, 05:06 AM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by MoonWitch View Post
Lua Code:
  1. local hpbar = self:CreateStatusbar(nil, 'Frame')
  2. self.Health = hpbar
or
Lua Code:
  1. self.Health = self:CreateStatusbar(nil, 'Frame')
Well, other than this almost certainly not being valid:
Code:
self:CreateStatusbar(nil, 'Frame')
... both of those achieve the same result once your spawn function is done. The main advantage of the first style is that you avoid performing the same table lookup over and over when you set the position, size, and other properties of the health bar, eg:
Code:
local hpbar = CreateFrame("StatusBar", nil, self)
hpbar:SetPoint("TOPLEFT", self, "TOPLEFT", 1, -1)
hpbar:SetPoint("TOPRIGHT", self, "TOPRIGHT", -1, -1)
hpbar:SetPoint("BOTTOM", self, "BOTTOM", 0, 1)
hpbar:GetStatusBarTexture():SetDrawLayer("ARTWORK")
hpbar.colorClass = true
hpbar.colorReaction = true
hpbar.bg.multiplier = 0.3
hpbar.frequentUpdates = true
hpbar.PostUpdate = addon.Health_PostUpdate
self.Health = hpbar
Using a local variable saves you 9 table lookups in this example, in addition to the typing.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Inverted health

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