In my addon
ScreenshotHelper I try to disable all UI elements that are not hidden with the hide interface shortcut. In order to achieve this, I use SetSetting to turn off a couple of things.
This works most of the time, but sometimes it just randomly doesn't and the worst part, it doesn't fail consistently. It seems to only happen after login and only with settings that have a boolean value (checkboxes). Sometimes the group indicators just stay off, another time it is the FPS widget that gets disabled. I have yet to find a reason or a pattern why these stay off and other than that I am all out of ideas. Maybe someone can shed some light on the issue?
The code in question looks like this and for the full code, just download the
addon.
lua Code:
-- the settings we want to overwrite when the gui gets hidden
local DESIRED_SETTINGS = {
[SETTING_TYPE_UI] = {
[UI_SETTING_SHOW_QUEST_BESTOWER_INDICATORS] = false,
[UI_SETTING_SHOW_FRAMERATE] = false,
[UI_SETTING_SHOW_LATENCY] = false,
},
[SETTING_TYPE_NAMEPLATES] = {
[NAMEPLATE_TYPE_ALL_HEALTHBARS] = false,
[NAMEPLATE_TYPE_ALLIANCE_INDICATORS] = NAMEPLATE_CHOICE_OFF,
[NAMEPLATE_TYPE_GROUP_INDICATORS] = false,
[NAMEPLATE_TYPE_RESURRECT_INDICATORS] = false,
[NAMEPLATE_TYPE_FOLLOWER_INDICATORS] = false,
},
[SETTING_TYPE_COMBAT] = {
[COMBAT_SETTING_SCROLLING_COMBAT_TEXT_ENABLED] = false,
},
[SETTING_TYPE_CHAT_BUBBLE] = {
[CHAT_BUBBLE_SETTING_ENABLED] = false,
},
[SETTING_TYPE_IN_WORLD] = {
[IN_WORLD_UI_SETTING_TARGET_GLOW_ENABLED] = false,
[IN_WORLD_UI_SETTING_INTERACTABLE_GLOW_ENABLED] = false,
}
}
-- we copy the structure to a second table where we save the current values
local savedSettings = ZO_DeepTableCopy(DESIRED_SETTINGS)
local function SaveSettings()
for system, entry in pairs(savedSettings) do
for settingId, value in pairs(entry) do -- for each setting in our structure we get the value either as a boolean or a number
if(type(value) == "boolean") then
savedSettings[system][settingId] = GetSetting_Bool(system, settingId)
else
savedSettings[system][settingId] = tonumber(GetSetting(system, settingId))
end
end
end
end
local function ApplyCustomSettings(settings)
for system, entry in pairs(settings) do
for settingId, value in pairs(entry) do
SetSetting(system, settingId, tostring(value)) -- we set each setting as a string
end
end
ApplySettings() -- call apply afterwards (no idea if this does anything)
end
local function OnGuiHidden(eventcode, guiName, hidden)
if (guiName ~= INGAME_GUI_NAME) then return end
if (hidden) then -- when the gui gets hidden
SaveSettings()
ApplyCustomSettings(DESIRED_SETTINGS)
SetFloatingMarkerGlobalAlpha(0)
else -- when it becomes visible again
ApplyCustomSettings(savedSettings)
SetFloatingMarkerGlobalAlpha(1)
end
end
local handle
handle = RegisterForEvent(EVENT_PLAYER_ACTIVATED, function()
UnregisterForEvent(EVENT_PLAYER_ACTIVATED, handle)
SaveSettings() -- we save them once, in case the EVENT_GUI_HIDDEN is called with hidden == false for some reason
RegisterForEvent(EVENT_GUI_HIDDEN, OnGuiHidden)
end)