Thread Tools Display Modes
Prev Previous Post   Next Post Next
03/22/16, 10:49 AM   #1
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,579
SetSettings issue

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:
  1. -- the settings we want to overwrite when the gui gets hidden
  2. local DESIRED_SETTINGS = {
  3.     [SETTING_TYPE_UI] = {
  4.         [UI_SETTING_SHOW_QUEST_BESTOWER_INDICATORS] = false,
  5.         [UI_SETTING_SHOW_FRAMERATE] = false,
  6.         [UI_SETTING_SHOW_LATENCY] = false,
  7.     },
  8.     [SETTING_TYPE_NAMEPLATES] = {
  9.         [NAMEPLATE_TYPE_ALL_HEALTHBARS] = false,
  10.         [NAMEPLATE_TYPE_ALLIANCE_INDICATORS] = NAMEPLATE_CHOICE_OFF,
  11.         [NAMEPLATE_TYPE_GROUP_INDICATORS] = false,
  12.         [NAMEPLATE_TYPE_RESURRECT_INDICATORS] = false,
  13.         [NAMEPLATE_TYPE_FOLLOWER_INDICATORS] = false,
  14.     },
  15.     [SETTING_TYPE_COMBAT] = {
  16.         [COMBAT_SETTING_SCROLLING_COMBAT_TEXT_ENABLED] = false,
  17.     },
  18.     [SETTING_TYPE_CHAT_BUBBLE] = {
  19.         [CHAT_BUBBLE_SETTING_ENABLED] = false,
  20.     },
  21.     [SETTING_TYPE_IN_WORLD] = {
  22.         [IN_WORLD_UI_SETTING_TARGET_GLOW_ENABLED] = false,
  23.         [IN_WORLD_UI_SETTING_INTERACTABLE_GLOW_ENABLED] = false,
  24.     }
  25. }
  26. -- we copy the structure to a second table where we save the current values
  27. local savedSettings = ZO_DeepTableCopy(DESIRED_SETTINGS)
  28.  
  29. local function SaveSettings()
  30.     for system, entry in pairs(savedSettings) do
  31.         for settingId, value in pairs(entry) do -- for each setting in our structure we get the value either as a boolean or a number
  32.             if(type(value) == "boolean") then
  33.                 savedSettings[system][settingId] = GetSetting_Bool(system, settingId)
  34.             else
  35.                 savedSettings[system][settingId] = tonumber(GetSetting(system, settingId))
  36.             end
  37.         end
  38.     end
  39. end
  40.  
  41. local function ApplyCustomSettings(settings)
  42.     for system, entry in pairs(settings) do
  43.         for settingId, value in pairs(entry) do
  44.             SetSetting(system, settingId, tostring(value)) -- we set each setting as a string
  45.         end
  46.     end
  47.     ApplySettings() -- call apply afterwards (no idea if this does anything)
  48. end
  49.  
  50. local function OnGuiHidden(eventcode, guiName, hidden)
  51.     if (guiName ~= INGAME_GUI_NAME) then return end
  52.     if (hidden) then -- when the gui gets hidden
  53.         SaveSettings()
  54.         ApplyCustomSettings(DESIRED_SETTINGS)
  55.         SetFloatingMarkerGlobalAlpha(0)
  56.     else -- when it becomes visible again
  57.         ApplyCustomSettings(savedSettings)
  58.         SetFloatingMarkerGlobalAlpha(1)
  59.     end
  60. end
  61.  
  62. local handle
  63. handle = RegisterForEvent(EVENT_PLAYER_ACTIVATED, function()
  64.     UnregisterForEvent(EVENT_PLAYER_ACTIVATED, handle)
  65.     SaveSettings() -- we save them once, in case the EVENT_GUI_HIDDEN is called with hidden == false for some reason
  66.     RegisterForEvent(EVENT_GUI_HIDDEN, OnGuiHidden)
  67. end)
  Reply With Quote
 

ESOUI » Developer Discussions » Lua/XML Help » SetSettings issue


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off