diff --git a/ShaguTweaks-tbc.toc b/ShaguTweaks-tbc.toc index 9cfa30b..aaa14d5 100644 --- a/ShaguTweaks-tbc.toc +++ b/ShaguTweaks-tbc.toc @@ -61,3 +61,4 @@ mods\chat-tweaks.lua mods\hide-gryphons.lua mods\worldmap-colors.lua mods\unitframes-bighealth.lua +mods\unitframes-classportrait.lua diff --git a/ShaguTweaks.toc b/ShaguTweaks.toc index d1e83c2..2aa0d83 100644 --- a/ShaguTweaks.toc +++ b/ShaguTweaks.toc @@ -61,3 +61,4 @@ mods\chat-tweaks.lua mods\hide-gryphons.lua mods\worldmap-colors.lua mods\unitframes-bighealth.lua +mods\unitframes-classportrait.lua diff --git a/img/UI-Classes-Circles.tga b/img/UI-Classes-Circles.tga new file mode 100644 index 0000000..68c6b60 Binary files /dev/null and b/img/UI-Classes-Circles.tga differ diff --git a/mods/unitframes-classportrait.lua b/mods/unitframes-classportrait.lua new file mode 100644 index 0000000..1a52caa --- /dev/null +++ b/mods/unitframes-classportrait.lua @@ -0,0 +1,72 @@ +local _G = _G or getfenv(0) + +local addonpath +local tocs = { "", "-master", "-tbc", "-wotlk" } +for _, name in pairs(tocs) do + local current = string.format("ShaguTweaks%s", name) + local _, title = GetAddOnInfo(current) + if title then + addonpath = "Interface\\AddOns\\" .. current + break + end +end + +local CLASS_ICON_TCOORDS = { + ["WARRIOR"] = { 0, 0.25, 0, 0.25 }, + ["MAGE"] = { 0.25, 0.49609375, 0, 0.25 }, + ["ROGUE"] = { 0.49609375, 0.7421875, 0, 0.25 }, + ["DRUID"] = { 0.7421875, 0.98828125, 0, 0.25 }, + ["HUNTER"] = { 0, 0.25, 0.25, 0.5 }, + ["SHAMAN"] = { 0.25, 0.49609375, 0.25, 0.5 }, + ["PRIEST"] = { 0.49609375, 0.7421875, 0.25, 0.5 }, + ["WARLOCK"] = { 0.7421875, 0.98828125, 0.25, 0.5 }, + ["PALADIN"] = { 0, 0.25, 0.5, 0.75 }, + ["DEATHKNIGHT"] = { 0.25, .5, 0.5, .75 }, +} + +local module = ShaguTweaks:register({ + title = "Unit Frame Class Portraits", + description = "Replace unitframe portraits with class icons.", + expansions = { ["vanilla"] = true, ["tbc"] = true }, + category = "Unit Frames", + enabled = nil, +}) + +local function UpdatePortraits(frame) + -- detect unit class or remove for non-player units + local _, class = UnitClass(frame.unit) + class = UnitIsPlayer(frame.unit) and class or nil + + -- update class icon if possible + if class and frame.portrait then + local iconCoords = CLASS_ICON_TCOORDS[class] + frame.portrait:SetTexture(addonpath .. "\\img\\UI-Classes-Circles") + frame.portrait:SetTexCoord(unpack(iconCoords)) + elseif not class and frame.portrait then + frame.portrait:SetTexCoord(0, 1, 0, 1) + end +end + +module.enable = function(self) + -- overwrite portraits set by the game + local original = UnitFrame_Update + UnitFrame_Update = function(arg1, arg2, arg3) + original(arg1, arg2, arg3) + UpdatePortraits(this) + end + + -- handle portrait update events + local events = CreateFrame("Frame") + events:RegisterEvent("PLAYER_ENTERING_WORLD") + events:RegisterEvent("UNIT_PORTRAIT_UPDATE") + events:SetScript("OnEvent", function(a1, a2) + -- reload player portrait + UpdatePortraits(PlayerFrame) + + -- reload party portraits + UpdatePortraits(PartyMemberFrame1) + UpdatePortraits(PartyMemberFrame2) + UpdatePortraits(PartyMemberFrame3) + UpdatePortraits(PartyMemberFrame4) + end) +end