View Single Post
08-30-21, 04:11 PM   #4
rulezyx
A Flamescale Wyrmkin
 
rulezyx's Avatar
Join Date: Jan 2020
Posts: 106
You need something like this:

Code:
hooksecurefunc("HealthBar_OnValueChanged", function (self)
	if UnitIsPlayer(self.unit) then
		local c = RAID_CLASS_COLORS[select(2,UnitClass(self.unit))];
		if c then
			self:SetStatusBarColor(c.r, c.g, c.b)
		end
	end
end);

hooksecurefunc("UnitFrameHealthBar_Update", function (self)
	if UnitIsPlayer(self.unit) then
		local c = RAID_CLASS_COLORS[select(2,UnitClass(self.unit))];
		if c then
			self:SetStatusBarColor(c.r, c.g, c.b)
		end
	end
end);
or Addons like this.

You can set nameplates to classcolors too with Advanced Interface Options which makes it more user-friendly.

You can change the color for mana/powerbars too but then you have to set color variables instead of class colors or it will look the same.
You can put your codes in here to create your addon.

Neav UI is using its own power colors with this code:

Code:
    -- Sets manabar color for default unit frames.

local function CustomManaColor(manaBar)
    local powerType = UnitPowerType(manaBar.unit)

    if powerType == 0 then
        manaBar:SetStatusBarColor(0.0, 0.55, 1.0)
    end
end
hooksecurefunc("UnitFrameManaBar_UpdateType", CustomManaColor)

    -- Set faction colors for Repuation Frame and tracking bar.

local TOOLTIP_FACTION_COLORS = {
    [1] = {r = 1, g = 0, b = 0},
    [2] = {r = 1, g = 0, b = 0},
    [3] = {r = 1, g = 1, b = 0},
    [4] = {r = 1, g = 1, b = 0},
    [5] = {r = 0, g = 1, b = 0},
    [6] = {r = 0, g = 1, b = 0},
    [7] = {r = 0, g = 1, b = 0},
    [8] = {r = 0, g = 1, b = 0},
}

local CUSTOM_FACTION_BAR_COLORS = {
    [1] = {r = 0.63, g = 0, b = 0},
    [2] = {r = 0.63, g = 0, b = 0},
    [3] = {r = 0.63, g = 0, b = 0},
    [4] = {r = 0.82, g = 0.67, b = 0},
    [5] = {r = 0.32, g = 0.67, b = 0},
    [6] = {r = 0.32, g = 0.67, b = 0},
    [7] = {r = 0.32, g = 0.67, b = 0},
    [8] = {r = 0, g = 0.75, b = 0.44},
}

hooksecurefunc("ReputationFrame_Update", function(showLFGPulse)
    local numFactions = GetNumFactions()
    local factionOffset = FauxScrollFrame_GetOffset(ReputationListScrollFrame)

    for i=1, NUM_FACTIONS_DISPLAYED, 1 do
        local factionIndex = factionOffset + i
        local factionBar = _G["ReputationBar"..i.."ReputationBar"]

        if factionIndex <= numFactions then
            local _, _, standingID, _, _, _, _, _, _, _, _, _, _, factionID = GetFactionInfo(factionIndex)

            local colorIndex = standingID

            local friendID = GetFriendshipReputation(factionID)

            if friendID ~= nil then
                colorIndex = 5                              -- always color friendships green
            end

            local color = CUSTOM_FACTION_BAR_COLORS[colorIndex]
            factionBar:SetStatusBarColor(color.r, color.g, color.b)
        end
    end
end)

hooksecurefunc(ReputationBarMixin, "Update", function(self)
    local _, reaction, _, _, _, factionID = GetWatchedFactionInfo()
    local colorIndex = reaction
    local friendshipID = GetFriendshipReputation(factionID)

    if friendshipID then
        colorIndex = 5     -- always color friendships green
    end

    local color = CUSTOM_FACTION_BAR_COLORS[colorIndex]
    self:SetBarColor(color.r, color.g, color.b, 1)
end)

    -- Override the default GameTooltip_UnitColor function.

function GameTooltip_UnitColor(unit) -- luacheck: ignore
    local r, g, b

    if UnitIsDead(unit) or UnitIsGhost(unit) or UnitIsTapDenied(unit) then
        r = 0.5
        g = 0.5
        b = 0.5
    elseif UnitIsPlayer(unit) then
        local _, class = UnitClass(unit)
        if class then
            r = RAID_CLASS_COLORS[class].r
            g = RAID_CLASS_COLORS[class].g
            b = RAID_CLASS_COLORS[class].b
        else
            if UnitIsFriend(unit, "player") then
                r = 0.60
                g = 0.60
                b = 0.60
            else
                r = 1
                g = 0
                b = 0
            end
        end
    elseif UnitPlayerControlled(unit) then
        if UnitCanAttack(unit, "player") then
            if not UnitCanAttack("player", unit) then
                r = 157/255
                g = 197/255
                b = 255/255
            else
                r = 1
                g = 0
                b = 0
            end
        elseif UnitCanAttack("player", unit) then
            r = 1
            g = 1
            b = 0
        elseif UnitIsPVP(unit) then
            r = 0
            g = 1
            b = 0
        else
            r = 157/255
            g = 197/255
            b = 255/255
        end
    else
        local reaction = UnitReaction(unit, "player")

        if reaction then
            r = TOOLTIP_FACTION_COLORS[reaction].r
            g = TOOLTIP_FACTION_COLORS[reaction].g
            b = TOOLTIP_FACTION_COLORS[reaction].b
        else
            r = 157/255
            g = 197/255
            b = 255/255
        end
    end

    return r, g, b
end

    -- Override the name background on default unit frames.

hooksecurefunc("TargetFrame_CheckFaction", function(self)
    if UnitPlayerControlled(self.unit) then
        self.nameBackground:SetVertexColor(GameTooltip_UnitColor(self.unit))
    end
end)

Last edited by rulezyx : 08-30-21 at 04:16 PM.
  Reply With Quote