Thread Tools Display Modes
02-07-15, 09:12 AM   #1
Naisz
A Deviate Faerie Dragon
 
Naisz's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2015
Posts: 12
Change Value-Tag on Mouseover?

So i was trying to change the Health-Value from percent to shortVal on Frame-Mouseover.
Sadly it doesn't work although i think the if returns a true.

Lua Code:
  1. if (MouseIsOver(health)) then
  2.     if unit == "target" or unit == "targettarget" then
  3.       local healthText = health:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  4.       healthText:SetPoint("RIGHT", health, "RIGHT")
  5.       healthText:SetTextColor(1, 1, 1, 1)
  6.       healthText:SetPoint("RIGHT", health, "RIGHT")
  7.       healthText:SetFont(font, fontsize, "THINOUTLINE")
  8.       self:Tag(healthText, "[shorthp]")
  9.     end
  10.   else
  11.     if unit == "player" then
  12.     local healthText = health:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  13.     healthText:SetPoint("RIGHT", health, "RIGHT")
  14.     healthText:SetTextColor(1, 1, 1, 1)
  15.     healthText:SetFont(font,fontsize, "THINOUTLINE")
  16.     self:Tag(healthText, "[dead][shorthp]")
  17.  
  18.     elseif unit == "target" or unit == "targettarget" then
  19.       local healthPer = health:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  20.       healthPer:SetPoint("RIGHT", health, 0, 0)
  21.       healthPer:SetFont(font, fontsize, "THINOUTLINE")
  22.       healthPer:SetTextColor(1, 1, 1, 1)
  23.       self:Tag(healthPer, "[dead][perhp]%")
  24.     end
  25.   end

This is my code, Maybe someone can help

Thanks in advance!
  Reply With Quote
02-07-15, 12:10 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
02-07-15, 03:22 PM   #3
Naisz
A Deviate Faerie Dragon
 
Naisz's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2015
Posts: 12
Thank you for your help!

One problem is there,
it works on targettarget, but i not on the target ..

Also thank you for the tips, my code looks better now, since i did something similar on the powertext.
  Reply With Quote
02-07-15, 04:35 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Naisz View Post
it works on targettarget, but i not on the target ..
What exactly "doesn't work"? Is the fontstring created? Does it display any text?
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
02-07-15, 06:02 PM   #5
Naisz
A Deviate Faerie Dragon
 
Naisz's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2015
Posts: 12
It displays the shortValue instead of perhp on the targetunit, but doesn't change on mouse-over
I also noticed that it triggers the change no matter which frame i target. But i think
thats because everything is created on on the style-func

Maybe i did something wrong, although i hope i'm doing stuff right

layout.lua
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Change Value-Tag on Mouseover?


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