Well, your problem there is that you are checking to see if the health bar is being moused over just once, when the frame is first created, at which point
nothing is being moused over yet.
I'd suggest just creating your own tag, like this:
Code:
oUF.Tags.Events["mouseoverhp"] = "UNIT_HEALTH UNIT_MAXHEALTH UPDATE_MOUSEOVER_UNIT"
oUF.Tags.Methods["mouseoverhp"] = function(unit)
if UnitIsDead(unit) then
return DEAD
end
local hp = UnitHealth(unit)
if UnitIsUnit(unit, "mouseover") then
return AbbreviateLargeNumbers(hp)
else
return format("%.0f%%", hp / UnitHealthMax(unit) * 100)
end
end
Then just do this in your setup code:
Code:
local healthText = health:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
healthText:SetPoint("RIGHT", health)
healthText:SetFont(font, fontsize, "OUTLINE")
if unit == "player" then
self:Tag(healthText, "[dead][shorthp]")
elseif unit == "target" or unit == "targettarget" then
self:Tag(healthText, "[mouseoverhp]")
end
Other changes I made in your setup code:
- Use GameFontHighlight instead of GameFontNormal. That way it's already white and you don't need the SetTextColor line. Other than the color it has exactly the same properties.
- Use "OUTLINE" instead of "THINOUTLINE", since that is the correct value. WoW will ignore the "THIN" part since it's meaningless, auto-correcting to "OUTLINE" for you, but you should just use the right value to begin with. Valid outline flags are "OUTLINE" and "THICKOUTLINE". The other possible flag is "MONOCHROME" which must be combined with an outline (by itself it will crash the client) and should generally only be used on pixel-style fonts, since it disables anti-aliasing and makes normal fonts look terrible.
- Don't duplicate code. Your healthText object was created with identical properties and position for any unit, so you should just create it once -- only apply the unit check to code that's actually different per unit.