WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Help with some Font settings (https://www.wowinterface.com/forums/showthread.php?t=48970)

Phanx 03-12-14 06:16 PM

Add the part highlighted in teal:
Code:

                        else
                                if value < valueMax then
                                        for j = 1, #shorts do
                                                local v = shorts[j]
                                                if valueMax >= v[1] then
                                                        return fontString:SetFormattedText(t[3] .. "/" .. v[3], value / t[2], valueMax / v[2])
                                                end
                                        end
                                end

                                return fontString:SetFormattedText(t[3], value / t[2])
                        end


cokedrivers 03-13-14 04:35 PM

Quote:

Originally Posted by Phanx (Post 291481)
Add the part highlighted in teal:
Code:

                        else
                                if value < valueMax then
                                        for j = 1, #shorts do
                                                local v = shorts[j]
                                                if valueMax >= v[1] then
                                                        return fontString:SetFormattedText(t[3] .. "/" .. v[3], value / t[2], valueMax / v[2])
                                                end
                                        end
                                end

                                return fontString:SetFormattedText(t[3], value / t[2])
                        end


Thank You for this code it works perfectly.

Last question then I think I'm done with font's.

My tooltip addon I use is based primarily off of nTooltip and for his pets he uses a color like:

Code:

r = 157/255
g = 197/255
b = 255/255


How would I get the highlighted yellow code to be this color:

Code:

hooksecurefunc("UnitFrame_Update", function(self)
    if not self.name then return end

    local unit, color = self.unit
    if UnitPlayerControlled(unit) then
        if UnitIsPlayer(unit) then
            local _, class = UnitClass(unit)
            color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
        else
            color = HIGHLIGHT_FONT_COLOR
        end
    elseif UnitIsDead(unit) or UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit) then
        color = GRAY_FONT_COLOR
    else
        color = FACTION_BAR_COLORS[UnitIsEnemy(unit, "player") and 1 or UnitReaction(unit, "player") or 5]
    end
 
    if not color then
        color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)["PRIEST"]
    end
 
    self.name:SetTextColor(color.r, color.g, color.b)
end)

I know its a minor thing but I would like when I tooltip over a unit for the color in the tooltip to match the color of the font on the unit.

I know I couldjust change the tooltip font to:

Code:

r = 1
g = 1
b = 1

and this would give me a white on the tooltip. But I kinda like the other color.

Thanks again for all your guys help with my font questions.

Coke

Phanx 03-13-14 04:36 PM

Code:

local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }

hooksecurefunc("UnitFrame_Update", function(self)
    if not self.name then return end

    local unit, color = self.unit
    if UnitPlayerControlled(unit) then
        if UnitIsPlayer(unit) then
            local _, class = UnitClass(unit)
            color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
        else
            color = PET_COLOR
        end


cokedrivers 03-13-14 04:44 PM

Quote:

Originally Posted by Phanx (Post 291499)
Code:

local PET_COLOR = { r = 157/255, g = 197/255, b = 255/255 }

hooksecurefunc("UnitFrame_Update", function(self)
    if not self.name then return end

    local unit, color = self.unit
    if UnitPlayerControlled(unit) then
        if UnitIsPlayer(unit) then
            local _, class = UnitClass(unit)
            color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
        else
            color = PET_COLOR
        end


So simple yet I couldn't figure it out.

Now for a personal question do you do programming for a living or is this just a hobby like me?

Either way you are great at it and thank you for all you do for us less then program savvy people.

Coke

cokedrivers 03-31-14 11:05 AM

Yet another font string question...

Is there a way to hide a party members realm, I've search the forums and only found this function for the chat not for the unit frames.

I would really like to change "-REALNAME" to (*) if possible.

Coke

Clamsoda 03-31-14 11:16 AM

Lua Code:
  1. -- originalName is defined is this fashion as an example; in practice
  2. -- you will want to pass whatever variable contains the NAME-REALM key
  3. -- into strsplit().
  4. local originalName = "Clamsoda-BleedingHollow"
  5. local unitName, unitRealm = strsplit("-", originalName)
  6.  
  7. print(unitRealm and unitName.."(*)" or unitName)

What is happening here is that strsplit will pass everything before and after the defined delimiter to as many variables as we allow it to. NAME-REALM keys are always delimited by a "-", and I am almost positive that no REALM keys contain a "-", thus we can safely split the name from the realm in this way. If unitRealm becomes defined, we print unitName with "(*)" concatenated; else we print just the name.

This should be quite adaptable, let me know if you need any further assistance.

cokedrivers 03-31-14 11:47 AM

Quote:

Originally Posted by Clamsoda (Post 291849)
Lua Code:
  1. -- originalName is defined is this fashion as an example; in practice
  2. -- you will want to pass whatever variable contains the NAME-REALM key
  3. -- into strsplit().
  4. local originalName = "Clamsoda-BleedingHollow"
  5. local unitName, unitRealm = strsplit("-", originalName)
  6.  
  7. print(unitRealm and unitName.."(*)" or unitName)

What is happening here is that strsplit will pass everything before and after the defined delimiter to as many variables as we allow it to. NAME-REALM keys are always delimited by a "-", and I am almost positive that no REALM keys contain a "-", thus we can safely split the name from the realm in this way. If unitRealm becomes defined, we print unitName with "(*)" concatenated; else we print just the name.

This should be quite adaptable, let me know if you need any further assistance.

Will this just work on Party member names or all name game wide?

Coke

Clamsoda 03-31-14 12:05 PM

I mean....it doesn't necessarily pertain to anything in particular, it is just applied API. Technically, you could pass any name token through it as long as there aren't any "-" outside of the delimitation. If there is no realm name, you just get a name; if there is a realm name, you get the "(*)".

The one issue I see is the inconsistency in how name-realm tokens are passed through certain functions and events at the moment. "(*)" has typically been used for units on other realms, but some events -- CLEU for example -- are passing names with realms attached regardless of if they are on your realm or not.

Tl;dr: You may get "(*)" for units that are on your realm as well, giving the false impression that they are cross-realm.

Of course, you could cache your realm and match it against what got split and go from there.

cokedrivers 03-31-14 12:42 PM

Quote:

Originally Posted by Clamsoda (Post 291851)
I mean....it doesn't necessarily pertain to anything in particular, it is just applied API. Technically, you could pass any name token through it as long as there aren't any "-" outside of the delimitation. If there is no realm name, you just get a name; if there is a realm name, you get the "(*)".

The one issue I see is the inconsistency in how name-realm tokens are passed through certain functions and events at the moment. "(*)" has typically been used for units on other realms, but some events -- CLEU for example -- are passing names with realms attached regardless of if they are on your realm or not.

Tl;dr: You may get "(*)" for units that are on your realm as well, giving the false impression that they are cross-realm.

Of course, you could cache your realm and match it against what got split and go from there.

Ok so something like:
Lua Code:
  1. if db.unitframes.party.enable then
  2.         for i = 1, MAX_PARTY_MEMBERS do
  3.             local partyFrame = "PartyMemberFrame"..i
  4.             local originalName = _G[partyFrame].name
  5.             local unitName, unitRealm = strsplit("-", originalName)
  6.             _G[partyFrame].name:SetText(unitRealm and unitName.."(*)" or unitName)         
  7.             _G[partyFrame]:SetScale(db.unitframes.party.scale);
  8.             _G[partyFrame.."HealthBarText"]:SetFont(db.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE");
  9.             _G[partyFrame.."ManaBarText"]:SetFont(db.fontNormal, db.unitframes.party.fontSize, "THINOUTLINE");
  10.     end

Should set the name of my party members to just there name?

Clamsoda 03-31-14 01:03 PM

That looks functional to me, log into WoW and try it =~].

cokedrivers 03-31-14 01:47 PM

when I log in I get this error with all addons enabled:
Code:

3x BasicUI-5.4.7\Modules\Unitframes.lua:50: bad argument #2 to "strsplit" (string expected, got table)
<in C code>
BasicUI-5.4.7\Modules\Unitframes.lua:50: in function <BasicUI\Modules\Unitframes.lua:7>
(tail call): ?
<in C code>
<string>:"safecall Dispatcher[1]":9: in function <string>:"safecall Dispatcher[1]":5
(tail call): ?
AuctionLite-v1.8.12\Libs\AceAddon-3.0\AceAddon-3.0-12.lua:558: in function "EnableAddon"
AuctionLite-v1.8.12\Libs\AceAddon-3.0\AceAddon-3.0-12.lua:571: in function "EnableAddon"
AuctionLite-v1.8.12\Libs\AceAddon-3.0\AceAddon-3.0-12.lua:651: in function <AuctionLite\Libs\AceAddon-3.0\AceAddon-3.0.lua:636>
<in C code>
FrameXML\UIParent.lua:306: in function "UIParentLoadAddOn"
FrameXML\UIParent.lua:329: in function "CombatLog_LoadUI"
FrameXML\UIParent.lua:742: in function <FrameXML\UIParent.lua:705>

Locals:
nil

and this one with just BasicUI enabled:
Code:

Message: Interface\AddOns\BasicUI\Modules\Unitframes.lua:50: bad argument #2 to 'strsplit' (string expected, got table)
Time: 03/31/14 12:45:00
Count: 1
Stack: [C]: in function `strsplit'
Interface\AddOns\BasicUI\Modules\Unitframes.lua:50: in function <Interface\AddOns\BasicUI\Modules\Unitframes.lua:7>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[1]"]:9: in function <[string "safecall Dispatcher[1]"]:5>
(tail call): ?
...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:543: in function `EnableAddon'
...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:556: in function `EnableAddon'
...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:636: in function <...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:621>
[C]: in function `LoadAddOn'
Interface\FrameXML\UIParent.lua:306: in function `UIParentLoadAddOn'
Interface\FrameXML\UIParent.lua:329: in function `CombatLog_LoadUI'
Interface\FrameXML\UIParent.lua:742: in function <Interface\FrameXML\UIParent.lua:705>

Locals: <none>


Duugu 03-31-14 01:51 PM

It's a table value. The fontstring widget itself.
Use:
_G[partyFrame].name:GetText()

Clamsoda 03-31-14 01:52 PM

Lua Code:
  1. local originalName = _G[partyFrame].name

needs to be

Lua Code:
  1. local originalName = _G[partyFrame].name:GetText()

cokedrivers 03-31-14 02:52 PM

2 Attachment(s)
Quote:

Originally Posted by Clamsoda (Post 291856)
Lua Code:
  1. local originalName = _G[partyFrame].name

needs to be

Lua Code:
  1. local originalName = _G[partyFrame].name:GetText()

Ok this is not working for me.

Below I have attached my Unitframes.lua, Phanx helped me with a code to change my Unit Text color and I think it is conflicting with this script.

I get this error:
Code:

Message: Interface\AddOns\BasicUI\Modules\Unitframes.lua:52: bad argument #2 to 'strsplit' (string expected, got table)
Time: 03/31/14 13:48:33
Count: 1
Stack: [C]: in function `strsplit'
Interface\AddOns\BasicUI\Modules\Unitframes.lua:52: in function <Interface\AddOns\BasicUI\Modules\Unitframes.lua:7>
(tail call): ?
[C]: ?
[string "safecall Dispatcher[1]"]:9: in function <[string "safecall Dispatcher[1]"]:5>
(tail call): ?
...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:543: in function `EnableAddon'
...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:556: in function `EnableAddon'
...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:636: in function <...ce\AddOns\BasicUI\Libs\AceAddon-3.0\AceAddon-3.0.lua:621>
[C]: in function `LoadAddOn'
Interface\FrameXML\UIParent.lua:306: in function `UIParentLoadAddOn'
Interface\FrameXML\UIParent.lua:329: in function `CombatLog_LoadUI'
Interface\FrameXML\UIParent.lua:742: in function <Interface\FrameXML\UIParent.lua:705>

Locals: <none>

Thanks for helping with this.
Coke

Clamsoda 03-31-14 04:43 PM

I suspect the issue is that you are iterating over every possible party unitframe, even when no unit has been assigned to it. If there is no unit, there is no name token to pass into strsplit.

What I suspect you need to do is listen to GROUP_ROSTER_UPDATE and iterate over the party frames that actually have assigned units.

That is the only thing I can think of looking over your code.

Hopefully someone else will take a look and offer some insight.

Phanx 03-31-14 05:01 PM

It would be simpler to just ignore the original text and get the name again:
Code:

_G[partyFrame].name:SetText(GetUnitName("party"..i))
If you wanted to show the realm name again in the future, add a second argument true to GetUnitName:
Code:

_G[partyFrame].name:SetText(GetUnitName("party"..i, true))
However, the error you posted indicates that either:

(a) you did not, in fact, make the change Clamsoda suggested, as your originalName variable is still referring to the fontstring, rather than its text contents, or

(b) the unit in question doesn't exist. Using GetUnitName instead of manipulating the existing text will avoid this problem, but you should really not bother doing anything with frames that aren't shown. I see you're checking GetNumGroupMembers() >= 1 on each loop iteration; this is wasteful and won't achieve the desired result anyway, because having 1 party member doesn't mean you have 4 party members. Instead, just check that the frame being processed is shown:

Code:

                for i = 1, MAX_PARTY_MEMBERS do       
                        local partyFrame = "PartyMemberFrame"..i
                        if partyFrame:IsShown() then
                                local originalName = _G[partyFrame].name:GetText()
                                local unitName, unitRealm = strsplit("-", originalName)
                                _G[partyFrame].name:SetText(unitRealm and unitName.."(*)" or unitName)
                        end

However, upon looking at your file, this entire block of code is pointless, because you only run it once when you log in, at which time information about party members may not even be available, and certainly won't update when your group changes. Instead, you should add this code to your UnitFrame_Update hook and remove it from your OnEnable function:

Code:

        hooksecurefunc("UnitFrame_Update", function(self, isParty)
                if not self.name or not self:IsShown() then return end
               
                -- other code here is fine, just omitted from this post for brevity
       
                self.name:SetTextColor(color.r, color.g, color.b)
                if isParty then
                        self.name:SetText(GetUnitName(self.overrideName or unit))
                end

        end)



All times are GMT -6. The time now is 02:40 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI