Harden unit frame class color hooks
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
local _G = ShaguTweaks.GetGlobalEnv()
|
local _G = ShaguTweaks.GetGlobalEnv()
|
||||||
local T = ShaguTweaks.T
|
local T = ShaguTweaks.T
|
||||||
|
local hooksecurefunc = hooksecurefunc or ShaguTweaks.hooksecurefunc
|
||||||
|
|
||||||
|
local FALLBACK_CLASS_COLOR = { r = .5, g = .5, b = .5, a = 1 }
|
||||||
|
|
||||||
local module = ShaguTweaks:register({
|
local module = ShaguTweaks:register({
|
||||||
title = T["Unit Frame Class Colors"],
|
title = T["Unit Frame Class Colors"],
|
||||||
@@ -9,37 +12,57 @@ local module = ShaguTweaks:register({
|
|||||||
enabled = nil,
|
enabled = nil,
|
||||||
})
|
})
|
||||||
|
|
||||||
local partycolors = function()
|
local function GetUnitClassColor(unit)
|
||||||
|
local _, class = UnitClass(unit)
|
||||||
|
return RAID_CLASS_COLORS[class] or FALLBACK_CLASS_COLOR
|
||||||
|
end
|
||||||
|
|
||||||
|
local function SetTextColorIfChanged(fontString, r, g, b, a)
|
||||||
|
local cr, cg, cb, ca = fontString:GetTextColor()
|
||||||
|
if cr ~= r or cg ~= g or cb ~= b or ca ~= a then
|
||||||
|
fontString:SetTextColor(r, g, b, a)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function SetVertexColorIfChanged(texture, r, g, b, a)
|
||||||
|
local cr, cg, cb, ca = texture:GetVertexColor()
|
||||||
|
if cr ~= r or cg ~= g or cb ~= b or ca ~= a then
|
||||||
|
texture:SetVertexColor(r, g, b, a)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function UpdatePartyColors()
|
||||||
for id = 1, MAX_PARTY_MEMBERS do
|
for id = 1, MAX_PARTY_MEMBERS do
|
||||||
local name = _G['PartyMemberFrame'..id..'Name']
|
local name = _G["PartyMemberFrame" .. id .. "Name"]
|
||||||
local _, class = UnitClass("party" .. id)
|
if name then
|
||||||
local class = RAID_CLASS_COLORS[class] or { r = .5, g = .5, b = .5, a = 1 }
|
local color = GetUnitClassColor("party" .. id)
|
||||||
if name then name:SetTextColor(class.r, class.g, class.b, 1) end
|
SetTextColorIfChanged(name, color.r, color.g, color.b, 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module.enable = function(self)
|
module.enable = function(self)
|
||||||
-- enable class color backgrounds
|
local function UpdateTargetClassColor()
|
||||||
local original = TargetFrame_CheckFaction
|
if not TargetFrameNameBackground then return end
|
||||||
function TargetFrame_CheckFaction(self)
|
|
||||||
original(self)
|
|
||||||
|
|
||||||
local reaction = UnitReaction("target", "player")
|
local reaction = UnitReaction("target", "player")
|
||||||
|
if UnitIsPlayer("target") then
|
||||||
if UnitIsPlayer("target") then
|
local color = GetUnitClassColor("target")
|
||||||
local _, class = UnitClass("target")
|
SetVertexColorIfChanged(TargetFrameNameBackground,
|
||||||
local class = RAID_CLASS_COLORS[class] or { r = .5, g = .5, b = .5, a = 1 }
|
color.r, color.g, color.b, 1)
|
||||||
TargetFrameNameBackground:SetVertexColor(class.r, class.g, class.b, 1)
|
TargetFrameNameBackground:Show()
|
||||||
TargetFrameNameBackground:Show()
|
elseif reaction and reaction > 4 then
|
||||||
elseif reaction and reaction > 4 then
|
TargetFrameNameBackground:Hide()
|
||||||
TargetFrameNameBackground:Hide()
|
|
||||||
else
|
else
|
||||||
TargetFrameNameBackground:Show()
|
TargetFrameNameBackground:Show()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local _, class = UnitClass("player")
|
-- Let Blizzard and other addons finish their target-faction handling first,
|
||||||
local class = RAID_CLASS_COLORS[class] or { r = .5, g = .5, b = .5, a = 1 }
|
-- then apply the class-color background instead of replacing the global.
|
||||||
|
hooksecurefunc("TargetFrame_CheckFaction", UpdateTargetClassColor)
|
||||||
|
|
||||||
|
local playerColor = GetUnitClassColor("player")
|
||||||
|
|
||||||
-- add name background to player frame
|
-- add name background to player frame
|
||||||
PlayerFrameNameBackground = PlayerFrame:CreateTexture(nil, "BACKGROUND")
|
PlayerFrameNameBackground = PlayerFrame:CreateTexture(nil, "BACKGROUND")
|
||||||
@@ -47,14 +70,14 @@ module.enable = function(self)
|
|||||||
PlayerFrameNameBackground:SetWidth(119)
|
PlayerFrameNameBackground:SetWidth(119)
|
||||||
PlayerFrameNameBackground:SetHeight(19)
|
PlayerFrameNameBackground:SetHeight(19)
|
||||||
PlayerFrameNameBackground:SetPoint("TOPLEFT", 106, -22)
|
PlayerFrameNameBackground:SetPoint("TOPLEFT", 106, -22)
|
||||||
PlayerFrameNameBackground:SetVertexColor(class.r, class.g, class.b, 1)
|
PlayerFrameNameBackground:SetVertexColor(playerColor.r, playerColor.g, playerColor.b, 1)
|
||||||
|
|
||||||
local wait = CreateFrame("Frame")
|
local wait = CreateFrame("Frame")
|
||||||
wait:RegisterEvent("PLAYER_ENTERING_WORLD")
|
wait:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||||
wait:SetScript("OnEvent", function()
|
wait:SetScript("OnEvent", function()
|
||||||
local _, class = UnitClass("player")
|
local color = GetUnitClassColor("player")
|
||||||
local class = RAID_CLASS_COLORS[class] or { r = .5, g = .5, b = .5, a = 1 }
|
SetVertexColorIfChanged(PlayerFrameNameBackground,
|
||||||
PlayerFrameNameBackground:SetVertexColor(class.r, class.g, class.b, 1)
|
color.r, color.g, color.b, 1)
|
||||||
this:UnregisterAllEvents()
|
this:UnregisterAllEvents()
|
||||||
|
|
||||||
-- make sure to keep name background above frame shadow
|
-- make sure to keep name background above frame shadow
|
||||||
@@ -67,12 +90,11 @@ module.enable = function(self)
|
|||||||
PlayerFrame.name:SetFont(font, size, "NONE")
|
PlayerFrame.name:SetFont(font, size, "NONE")
|
||||||
TargetFrame.name:SetFont(font, size, "NONE")
|
TargetFrame.name:SetFont(font, size, "NONE")
|
||||||
|
|
||||||
-- add party frame class colors
|
-- Update party name colors after the stock member refresh instead of
|
||||||
local HookPartyMemberFrame_UpdateMember = PartyMemberFrame_UpdateMember
|
-- replacing PartyMemberFrame_UpdateMember. Cached color writes avoid doing
|
||||||
PartyMemberFrame_UpdateMember = function(self)
|
-- extra rendering work when the class did not change.
|
||||||
HookPartyMemberFrame_UpdateMember(self)
|
hooksecurefunc("PartyMemberFrame_UpdateMember", UpdatePartyColors)
|
||||||
partycolors()
|
|
||||||
end
|
|
||||||
|
|
||||||
partycolors()
|
UpdateTargetClassColor()
|
||||||
|
UpdatePartyColors()
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user