The way you have your code right now means that it will only change the font each time the Player Activated event is triggered, which only happens each time you zone in to somewhere.
If you want it to also change as soon as it's toggled, you need to refactor your code to something like this:
Code:
function RidinDirty.AdjustFont()
local fontBoost = RidinDirty.savedVariables.fontBoost
if fontBoost == "enabled" then
local fontString = string.format("%s|%d", "EsoUI/Common/Fonts/Univers67.otf", "26")
SetNameplateKeyboardFont( fontString, 1)
SetNameplateGamepadFont( fontString, 1)
else
local fontString = string.format("%s|%d", "EsoUI/Common/Fonts/Univers57.otf", "20")
SetNameplateKeyboardFont( fontString, 1)
SetNameplateGamepadFont( fontString, 1)
end
end
function RidinDirty.PlayerActivated()
RidinDirty.AdjustFont()
end
-- Nameplate Font Boost Toggle
function RidinDirty.NamePlatesToggle()
local fontBoost = RidinDirty.savedVariables.fontBoost
if fontBoost == nil or fontBoost == "" or fontBoost == "disabled" then
fontBoost = "enabled"
RidinDirty.savedVariables.fontBoost = fontBoost
df("|c9900FF[RidinDirty]|r FontBoost: %s", fontBoost)
else
fontBoost = "disabled"
RidinDirty.savedVariables.fontBoost = fontBoost
df("|c9900FF[RidinDirty]|r FontBoost: %s", fontBoost)
end
RidinDirty.AdjustFont()
end
As for the events, I only unregister the addonload event during the addonload - one of my addons uses many, many events, none of which I unregister at any point after that.
Code:
function BS.OnAddonLoaded(_, addonName)
if (addonName ~= BS.Name) then
return
end
EVENT_MANAGER:UnregisterForEvent(BS.Name, _G.EVENT_ADD_ON_LOADED)
Initialise()
end