[Help] Hide certain Totem nameplates
Hey,
I want to hide certain Totem nameplates. Threat Plates has this option and it works pretty good, but I don't want other nameplates than default, so I need an addon which hides certain totem nameplates.
There's an addon called "TotemFilter" which has been updated to patch 6.2.2 (which was around 6 years ago).
Maybe someone can update the addon or post me a solution with which I can work? :)
Here's the TotemFilter Code with updated SpellIDs.
Code:
--[[
< TotemFilter v0.1 Beta >
______________________________
Author: Spyro
License: All Rights Reserved
Contact: Spyrö @ ArenaJunkies
Spyro @ WowInterface
Spyro_ @ Curse/WowAce
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
]]
local AddonName, _ = ...
-- Upvalues
local _G, pairs, select, WorldFrame, CreateFrame, hooksecurefunc, InterfaceOptions_AddCategory, InterfaceOptionsFrame_OpenToCategory
= _G, pairs, select, WorldFrame, CreateFrame, hooksecurefunc, InterfaceOptions_AddCategory, InterfaceOptionsFrame_OpenToCategory
-- Misc vars
local UI -- Stores all the configuration user interface
local DB -- Local reference to the saved variable (TotemFilterDB)
local Addon = CreateFrame("Frame") -- Addon's main frame
local NumChildren = -1 -- WorldFrame's child counter
local TotemsToHide = {} -- List of the totem names (in the current locale) that we want to hide their nameplates
-- List of all Shaman totem ID's
local TotemList = {
192058, -- Capacitor Totem (ex-Lightning Surge Totem, baseline since 8.0.1)
192222, -- Liquid Magma Totem
8143, -- Tremor Totem (added in pacth 8.0.1, TP v9.0.9)
98008, -- Spirit Link Totem
5394, -- Healing Stream Totem
108280, -- Healing Tide Totem
160161, -- Earthquake Totem
2484, -- Earthbind Totem (added patch 7.2, TP v8.4.0)
8512, -- Windfury Totem (re-added with 9.0.1)
202188, -- Resonance Totem
210651, -- Storm Totem
210657, -- Ember Totem
210660, -- Tailwind Totem
157153, -- Cloudburst Totem
51485, -- Earthgrab Totem
207399, -- Ancestral Protection Totem
192077, -- Wind Rush Totem
198838, -- Earthen Wall Totem
204331, -- Counterstrike Totem
204330, -- Skyfury Totem
204336, -- Grounding Totem
196932 -- Voodoo Totem (removed in patch 8.0.1)
}
-- Default values of configuration
local Defaults = {
TotemsToHideID = { -- Default list of totems to hide
-- Empty
--[3599] = true, -- Searing Totem
}
}
-- Event registration
Addon:SetScript("OnEvent", function(self, event, ...) return self[event](self, ...) end)
Addon:RegisterEvent("ADDON_LOADED")
Addon:RegisterEvent("PLAYER_LOGIN")
-- CreateCheckButton()
-- Creates a checkbox.
-- > Parent: Checkbutton's parent frame.
-- > Checked: Bool that indicates if it should be checked by default or not.
-- > Label: Text on right of the checkbox.
-- > Tooltip: Tooltip that will appear while mouseovering.
-- > OnClickFunc: Reference to a function that will be executed when clicking this checkbox.
-- < CheckButton: Reference to the created check button.
local function CreateCheckButton(Parent, Checked, Label, Tooltip, OnClickFunc)
local CheckButton = CreateFrame("CheckButton", nil, Parent, "ChatConfigCheckButtonTemplate")
CheckButton.Label = select(6, CheckButton:GetRegions())
CheckButton.Label:SetText(Label)
CheckButton.Label:SetPoint("LEFT", CheckButton.Label:GetParent(), "RIGHT", 2, 0)
CheckButton.tooltip = Tooltip
CheckButton:SetChecked(Checked)
CheckButton:SetScript("OnClick", function(self) OnClickFunc(self) end)
return CheckButton
end
-- CreateConfigUI()
-- Creates the configuration UI panel on Interface->Addons->TotemFilter.
local function CreateConfigUI()
-- Creating new panel for the addon
UI = CreateFrame("Frame", nil, _G.InterfaceOptionsFrame)
UI.name = "TotemFilter"
InterfaceOptions_AddCategory(UI)
-- Title
UI.Title = UI:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
UI.Title:SetText("TotemFilter - Totems to hide:")
UI.Title:SetPoint("TOPLEFT", 16, -16)
-- Creating a checkbox for each totem
local i = 1
for _, TotemID in pairs(TotemList) do
UI["Checkbox"..i] = CreateCheckButton(UI, DB.TotemsToHideID[TotemID] and true or false, GetSpellInfo(TotemID), nil, function(self)
DB.TotemsToHideID[TotemID] = self:GetChecked() and true or nil
end)
if i == 1 then UI["Checkbox"..i]:SetPoint("TOPLEFT", UI.Title, "BOTTOMLEFT", 0, -10)
else UI["Checkbox"..i]:SetPoint("TOPLEFT", UI["Checkbox"..i-1], "BOTTOMLEFT", 0, 0) end
i = i + 1
end
end
-- CopyDefaults()
-- Copies the default settings on the saved variable in the empty fields.
-- > Source: Table with the default settings.
-- > Destination: Table with the current settings.
-- < Destination: Reference to the table with the current settings.
local function CopyDefaults(Source, Destination)
if not Source then return {} end
if not Destination then Destination = {} end
for k, v in pairs(Source) do
if type(v) == "table" then Destination[k] = CopyDefaults(v, Destination[k])
elseif type(v) ~= type(Destination[k]) then Destination[k] = v end
end
return Destination
end
-- PlateSetShown()
-- Shows/hides a nameplate without tainting it.
-- > Plate: Nameplate reference
-- > ShowFlag: Bool for show/hide
local function PlateSetShown(Plate, ShowFlag)
Plate.NameContainer:SetShown(ShowFlag)
-- The ArtContainer cannot be hidden directly without tainting, hidding all regions and children
Plate.ArtContainer.AggroWarningTexture:SetShown(ShowFlag)
Plate.ArtContainer.Border:SetShown(ShowFlag)
Plate.ArtContainer.Highlight:SetShown(ShowFlag)
Plate.ArtContainer.LevelText:SetShown(ShowFlag)
Plate.ArtContainer.HighLevelIcon:SetShown(ShowFlag)
Plate.ArtContainer.RaidTargetIcon:SetShown(ShowFlag)
Plate.ArtContainer.EliteIcon:SetShown(ShowFlag)
Plate.ArtContainer.HealthBar:SetShown(ShowFlag)
Plate.ArtContainer.CastBar:SetShown(ShowFlag)
Plate.ArtContainer.AbsorbBar:SetShown(ShowFlag)
if not ShowFlag then Plate.ArtContainer.AggroWarningTexture.Show = function() end -- The threat texture shows itself again, removing its access to Show()
else Plate.ArtContainer.AggroWarningTexture.Show = Plate.ArtContainer.Border.Show end -- Restoring the access to Show() if we want to show the nameplate
end
-- Event NAMEPLATE_SHOW
-- Fires when a nameplate appears on screen.
-- > Plate: Nameplate reference
local function NAMEPLATE_SHOW(Plate)
-- If it's a totem we don't want to see, hide it
if TotemsToHide[Plate.NameContainer.NameText:GetText()] then PlateSetShown(Plate, false) end
end
-- Event NAMEPLATE_HIDE
-- Fires when a nameplate disappears from screen.
-- > Plate: Nameplate reference
local function NAMEPLATE_HIDE(Plate)
-- If it's a hidden totem, show again all frames and regions that were hidden
if TotemsToHide[Plate.NameContainer.NameText:GetText()] then PlateSetShown(Plate, true) end
end
-- SetScriptHook()
-- Function to re-hook the script handlers OnShow/OnHide on nameplates when other addons destroy them using SetScript() instead of HookScript().
-- > Plate: Nameplate reference
-- > Handler: Script handler used on the SetScript() call
-- > Func: Hooked function
local function SetScriptHook(Plate, Handler, Func)
if Handler == "OnShow" then Plate:HookScript("OnShow", NAMEPLATE_SHOW)
elseif Handler == "OnHide" then Plate:HookScript("OnHide", NAMEPLATE_HIDE) end
end
-- PlateProcess()
-- Process the WorldFrame children whenever a new children it's created, to catch nameplates.
local function PlateProcess()
if WorldFrame:GetNumChildren() == NumChildren then return end
NumChildren = WorldFrame:GetNumChildren()
-- Iterating thru all WorldFrame's children to catch nameplates
for _, Plate in pairs({ WorldFrame:GetChildren() }) do
if not Plate.TotemFilter and Plate.ArtContainer then -- It's a nameplate not seen before
Plate.TotemFilter = true -- Mark as seen to ignore it in future iterations
-- Script handlers
Plate:HookScript("OnShow", NAMEPLATE_SHOW) -- Event to trigger when the nameplate appears on screen
Plate:HookScript("OnHide", NAMEPLATE_HIDE) -- Event to trigger when the nameplate disappears from screen
if Plate:IsVisible() then NAMEPLATE_SHOW(Plate) end -- If it's already visible trigger for the first time
-- Hooking the use of SetScript() on nameplates by other addons, so they don't fuck our hooks :-)
hooksecurefunc(Plate, "SetScript", SetScriptHook)
end
end
end
-- Event ADDON_LOADED
-- Fires when an addon and its saved variables are loaded.
function Addon:ADDON_LOADED(Name)
if Name ~= "TotemFilter" then return end
Addon:UnregisterEvent("ADDON_LOADED")
if not TotemFilterDB then TotemFilterDB = {} end -- No saved variable, creating a new one
DB = TotemFilterDB -- Local reference for faster access
CopyDefaults(Defaults, DB)
-- Populating table of totems to hide
for TotemID, _ in pairs(DB.TotemsToHideID) do
TotemsToHide[GetSpellInfo(TotemID)] = true -- Indexed by name on the current locale
end
CreateConfigUI()
end
-- Event PLAYER_LOGIN
-- Fires after PLAYER_ENTERING_WORLD after logging in and after /reloadui.
function Addon:PLAYER_LOGIN()
Addon:SetScript("OnUpdate", PlateProcess) -- Enabling nameplate processing
end
-- Command /totemfilter
-- Opens the configuration UI of the addon.
SLASH_TOTEMFILTER1 = "/totemfilter"
SlashCmdList["TOTEMFILTER"] = function()
-- Calling 2 times: Workaround for the bug of this function that doesn't open the correct panel the first time
InterfaceOptionsFrame_OpenToCategory(UI)
InterfaceOptionsFrame_OpenToCategory(UI)
end
|