enhanced totemplates functionality

This commit is contained in:
Sumsebrum 2021-07-26 11:46:30 +02:00
parent c43228f0b9
commit 5f4ab71a5a

View File

@ -227,6 +227,7 @@ function TotemPlates:Initialize()
self:RegisterEvent("NAME_PLATE_UNIT_ADDED") self:RegisterEvent("NAME_PLATE_UNIT_ADDED")
self:RegisterEvent("NAME_PLATE_UNIT_REMOVED") self:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
self:RegisterEvent("PLAYER_TARGET_CHANGED") self:RegisterEvent("PLAYER_TARGET_CHANGED")
self:RegisterEvent("UNIT_NAME_UPDATE")
self:SetScript("OnEvent", TotemPlates.OnEvent) self:SetScript("OnEvent", TotemPlates.OnEvent)
if Gladdy.db.npTotems and Gladdy.db.npTotemsShowEnemy then if Gladdy.db.npTotems and Gladdy.db.npTotemsShowEnemy then
--GetCVar("nameplateShowEnemyTotems") --GetCVar("nameplateShowEnemyTotems")
@ -282,9 +283,31 @@ function TotemPlates:UpdateFrameOnce()
nameplate.gladdyTotemFrame.totemName:SetFont(Gladdy.LSM:Fetch("font", Gladdy.db.npTremorFont), Gladdy.db.npTremorFontSize, "OUTLINE") nameplate.gladdyTotemFrame.totemName:SetFont(Gladdy.LSM:Fetch("font", Gladdy.db.npTremorFont), Gladdy.db.npTremorFontSize, "OUTLINE")
nameplate.gladdyTotemFrame.totemName:SetText(Gladdy.db.npTotemColors["totem" .. totemDataEntry.id].customText or "") nameplate.gladdyTotemFrame.totemName:SetText(Gladdy.db.npTotemColors["totem" .. totemDataEntry.id].customText or "")
self:SetTotemAlpha(nameplate.gladdyTotemFrame, k) self:SetTotemAlpha(nameplate.gladdyTotemFrame, k)
if not Gladdy.db.npTotems then
nameplate.gladdyTotemFrame:Hide()
self:ToggleAddon(nameplate, true)
else
nameplate.gladdyTotemFrame:Show()
self:ToggleAddon(nameplate) self:ToggleAddon(nameplate)
end end
for i,gladdyTotemFrame in ipairs(self.totemPlateCache) do local isEnemy = UnitIsEnemy("player", nameplate.gladdyTotemFrame.unitID)
if Gladdy.db.npTotems and Gladdy.db.npTotemsShowEnemy and isEnemy then
nameplate.gladdyTotemFrame:Show()
self:ToggleAddon(nameplate)
elseif Gladdy.db.npTotems and not Gladdy.db.npTotemsShowEnemy and isEnemy then
nameplate.gladdyTotemFrame:Hide()
self:ToggleAddon(nameplate, true)
end
if Gladdy.db.npTotems and Gladdy.db.npTotemsShowFriendly and not isEnemy then
nameplate.gladdyTotemFrame:Show()
self:ToggleAddon(nameplate)
elseif not Gladdy.db.npTotemsShowFriendly and not isEnemy then
nameplate.gladdyTotemFrame:Hide()
self:ToggleAddon(nameplate, true)
end
end
for _,gladdyTotemFrame in ipairs(self.totemPlateCache) do
gladdyTotemFrame:SetWidth(Gladdy.db.npTotemPlatesSize * Gladdy.db.npTotemPlatesWidthFactor) gladdyTotemFrame:SetWidth(Gladdy.db.npTotemPlatesSize * Gladdy.db.npTotemPlatesWidthFactor)
gladdyTotemFrame:SetHeight(Gladdy.db.npTotemPlatesSize) gladdyTotemFrame:SetHeight(Gladdy.db.npTotemPlatesSize)
gladdyTotemFrame.totemBorder:SetTexture(Gladdy.db.npTotemPlatesBorderStyle) gladdyTotemFrame.totemBorder:SetTexture(Gladdy.db.npTotemPlatesBorderStyle)
@ -337,27 +360,47 @@ end
--------------------------------------------------- ---------------------------------------------------
function TotemPlates:GetAddonFrame(nameplate)
if self.addon == "Blizzard" then
if nameplate.UnitFrame then
return nameplate.UnitFrame
end
elseif self.addon == "Plater" or self.addon == "Tukui" or self.addon == "ElvUI" then
if nameplate.unitFrame then
return nameplate.unitFrame
end
elseif self.addon == "Kui_Nameplates" then
if nameplate.kui then
return nameplate.kui
end
elseif self.addon == "NeatPlates" then
if nameplate.extended or nameplate.carrier then
return nameplate.extended , nameplate.carrier
end
elseif self.addon == "TidyPlates_ThreatPlates" then
if nameplate.TPFrame then
return nameplate.TPFrame
end
end
end
function TotemPlates:PLAYER_TARGET_CHANGED() function TotemPlates:PLAYER_TARGET_CHANGED()
for k,nameplate in pairs(self.activeTotemNameplates) do for k,nameplate in pairs(self.activeTotemNameplates) do
TotemPlates:SetTotemAlpha(nameplate.gladdyTotemFrame, k) TotemPlates:SetTotemAlpha(nameplate.gladdyTotemFrame, k)
end end
end end
function TotemPlates:ToggleAddon(nameplate) function TotemPlates:ToggleAddon(nameplate, show)
if self.addon == "Blizzard" then local addonFrames = { self:GetAddonFrame(nameplate) }
nameplate.UnitFrame:Hide() if addonFrames and #addonFrames > 0 then
elseif self.addon == "Plater" then if show then
nameplate.unitFrame:Hide() for i,v in ipairs(addonFrames) do
elseif self.addon == "Kui_Nameplates" then v:Show()
nameplate.kui:Hide() end
elseif self.addon == "NeatPlates" then else
nameplate.extended:Hide() for i,v in ipairs(addonFrames) do
nameplate.carrier:Hide() v:Hide()
elseif self.addon == "TidyPlates_ThreatPlates" then end
nameplate.TPFrame:Hide()
elseif self.addon == "Tukui" or self.addon == "ElvUI" then
if nameplate.unitFrame then
nameplate.unitFrame:Hide()
end end
end end
end end
@ -368,18 +411,27 @@ function TotemPlates.OnUpdate(self)
else else
self.selectionHighlight:SetAlpha(0) self.selectionHighlight:SetAlpha(0)
end end
if (TotemPlates.addon == "Tukui" or TotemPlates.addon == "ElvUI") and self.parent and self.parent.unitFrame then if (TotemPlates.addon == "Plater" or TotemPlates.addon == "Tukui" or TotemPlates.addon == "ElvUI") and self.parent and self.parent.unitFrame then
self.parent.unitFrame:Hide() self.parent.unitFrame:Hide()
end end
end end
function TotemPlates:NAME_PLATE_UNIT_ADDED(...) function TotemPlates:OnUnitEvent(unitID)
local unitID = ...
local isEnemy = UnitIsEnemy("player", unitID) local isEnemy = UnitIsEnemy("player", unitID)
local nameplate = C_NamePlate.GetNamePlateForUnit(unitID)
if not nameplate then
return
end
if not Gladdy.db.npTotems then
self:ToggleAddon(nameplate, true)
return
end
if not Gladdy.db.npTotemsShowEnemy and isEnemy then if not Gladdy.db.npTotemsShowEnemy and isEnemy then
self:ToggleAddon(nameplate, true)
return return
end end
if not Gladdy.db.npTotemsShowFriendly and not isEnemy then if not Gladdy.db.npTotemsShowFriendly and not isEnemy then
self:ToggleAddon(nameplate, true)
return return
end end
local nameplateName = UnitName(unitID) local nameplateName = UnitName(unitID)
@ -387,7 +439,6 @@ function TotemPlates:NAME_PLATE_UNIT_ADDED(...)
totemName = string_gsub(totemName, "%s+$", "") --trim totemName = string_gsub(totemName, "%s+$", "") --trim
totemName = string_gsub(totemName, "%s+[I,V,X]+$", "") --trim rank totemName = string_gsub(totemName, "%s+[I,V,X]+$", "") --trim rank
totemName = string_lower(totemName) totemName = string_lower(totemName)
local nameplate = C_NamePlate.GetNamePlateForUnit(unitID)
local totemDataEntry = localizedTotemData["default"][totemName] or localizedTotemData["frFR"][totemName] or localizedTotemData["ruRU"][totemName] local totemDataEntry = localizedTotemData["default"][totemName] or localizedTotemData["frFR"][totemName] or localizedTotemData["ruRU"][totemName]
if totemDataEntry and Gladdy.db.npTotemColors["totem" .. totemDataEntry.id].enabled then-- modify this nameplates if totemDataEntry and Gladdy.db.npTotemColors["totem" .. totemDataEntry.id].enabled then-- modify this nameplates
if #self.totemPlateCache > 0 then if #self.totemPlateCache > 0 then
@ -412,13 +463,24 @@ function TotemPlates:NAME_PLATE_UNIT_ADDED(...)
TotemPlates:SetTotemAlpha(nameplate.gladdyTotemFrame, unitID) TotemPlates:SetTotemAlpha(nameplate.gladdyTotemFrame, unitID)
self:ToggleAddon(nameplate) self:ToggleAddon(nameplate)
self.activeTotemNameplates[unitID] = nameplate self.activeTotemNameplates[unitID] = nameplate
else
self:ToggleAddon(nameplate, true)
end end
end end
function TotemPlates:NAME_PLATE_UNIT_ADDED(...)
self:OnUnitEvent(...)
end
function TotemPlates:UNIT_NAME_UPDATE(...)
self:OnUnitEvent(...)
end
function TotemPlates:NAME_PLATE_UNIT_REMOVED(...) function TotemPlates:NAME_PLATE_UNIT_REMOVED(...)
local unitID = ... local unitID = ...
local nameplate = C_NamePlate.GetNamePlateForUnit(unitID) local nameplate = C_NamePlate.GetNamePlateForUnit(unitID)
self.activeTotemNameplates[unitID] = nil self.activeTotemNameplates[unitID] = nil
--self:ToggleAddon(nameplate, true)
if nameplate.gladdyTotemFrame then if nameplate.gladdyTotemFrame then
nameplate.gladdyTotemFrame:Hide() nameplate.gladdyTotemFrame:Hide()
nameplate.gladdyTotemFrame:SetParent(nil) nameplate.gladdyTotemFrame:SetParent(nil)