Hi All,
I'm working on a number of small addon projects to teach myself the basics before moving on to a larger project. What I'm doing is starting with the default UI and going through it making small "improvements" here and there.
The fist one I've done is an addon to smooth the health bars of the default unit frames. I'd appreciate some feedback.
Code:
local _HealthBar_OnValueChanged = HealthBar_OnValueChanged
HealthBar_OnValueChanged = function(healthBar, value, ...)
_HealthBar_OnValueChanged(healthBar, value, true)
end
local _UnitFrameHealthBar_Update = UnitFrameHealthBar_Update
UnitFrameHealthBar_Update = function(statusbar, unit)
_UnitFrameHealthBar_Update(statusbar, unit)
if (not statusbar or statusbar.disconnected) then return end
local min, max = statusbar:GetMinMaxValues();
if (max <= min) then return end
local value = statusbar:GetValue()
if ( (value < min) or (value > max) ) then return end
value = (value - min) / (max - min);
local r, g
if(value > 0.5) then
r = (1.0 - value) * 2;
g = 1.0;
else
r = 1.0;
g = value * 2;
end
statusbar:SetStatusBarColor(r, g, 0.0);
end
I'm concerned about the second function I've hooked. It gets called a lot (presumably once per frame for every UnitFrameHealthBar). Am I right to be?
Note: I originally wrote this using events but frames like focustarget and targettarget weren't getting updated because changes to those don't trigger UNIT_HEALTH events.