I don't pvp so I didn't get to test the enemy nameplate part but here is a start:
Lua Code:
local addonName = ...
local iconKey = addonName .. "Icon"
local GetNamePlateForUnit = C_NamePlate.GetNamePlateForUnit
local isInArena = false
local iconTexture = {
["DEATHKNIGHT"] = 135771,
["DEMONHUNTER"] = 236415,
["DRUID"] = 625999,
["HUNTER"] = 626000,
["MAGE"] = 626001,
["MONK"] = 626002,
["PALADIN"] = 626003,
["PRIEST"] = 626004,
["ROGUE"] = 626005,
["SHAMAN"] = 626006,
["WARLOCK"] = 626007,
["WARRIOR"] = 626008
}
local function UpdateNamePlateIcon(namePlate, unit)
local icon = namePlate[iconKey]
if UnitIsPlayer(unit) then
local texture
local specID = GetInspectSpecialization(unit)
if specID then
local _, _, _, icon = GetSpecializationInfoByID(specID)
texture = icon
end
if not texture then
local _, class = UnitClass(unit)
texture = iconTexture[class]
end
if texture then
if not icon then
icon = namePlate:CreateTexture(nil, "OVERLAY")
namePlate[iconKey] = icon
end
local iconStyle = UnitIsFriend("player", unit) and "friend" or "enemy"
if icon.style ~= iconStyle then
icon.style = iconStyle
icon:ClearAllPoints()
if iconStyle == "friend" then
icon:SetPoint('CENTER', 0, 29.46)
icon:SetSize(24, 24)
else
icon:SetPoint('RIGHT', 10, -5)
icon:SetSize(20, 20)
end
end
icon:SetTexture(texture)
icon:Show()
return
end
end
if icon then
icon:Hide()
end
end
local function UpdateAllNamePlateIcons()
local nameplates = C_NamePlate.GetNamePlates()
for index = 1, #nameplates do
UpdateNamePlateIcon(nameplates[index], nameplates[index].namePlateUnitToken)
end
end
local frame = CreateFrame("Frame")
frame:SetScript("OnEvent", function(self, event, unit)
if event == "NAME_PLATE_UNIT_ADDED" then
local namePlate = GetNamePlateForUnit(unit)
UpdateNamePlateIcon(namePlate, unit)
elseif event == "NAME_PLATE_UNIT_REMOVED" then
local namePlate = GetNamePlateForUnit(unit)
if namePlate[iconKey] then
namePlate[iconKey]:Hide()
end
elseif event == "PLAYER_ENTERING_WORLD" then
if isInArena ~= C_PvP.IsArena() then
isInArena = not isInArena
UpdateAllNamePlateIcons()
end
elseif event == "ARENA_PREP_OPPONENT_SPECIALIZATIONS" then
UpdateAllNamePlateIcons()
end
end)
frame:RegisterEvent("ARENA_PREP_OPPONENT_SPECIALIZATIONS")
frame:RegisterEvent("NAME_PLATE_UNIT_ADDED")
frame:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")