Thread Tools Display Modes
03/22/16, 10:49 AM   #1
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,602
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
04/28/16, 03:58 PM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,602
I am still trying to figure out this problem.
I found a way to reliably reproduce it and either it is a bug in the game, or I am simply doing something wrong.
Here is a video which shows what I mean:

When I toggle GUI, the addon disables all options that are related to things that show up even when the GUI is hidden, like nameplates, sct, etc.
At this point everything is still okay.
Once I leave the area the settings are suddenly randomly discarded. It's always a different bunch of options that is disabled, but always the ones I have set to off and then on again.
  Reply With Quote
04/28/16, 04:10 PM   #3
haggen
 
haggen's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2015
Posts: 137
Did you try printing messages to see if your functions are called at unexpected times?

Also, I had the same doubts about 'ApplySettings()' and if it actually did something, until I had problems when changing the UI global scale. It only got applied after the aforementioned function has been invoked.

I can't right now, but later I'll check out some stock code that meddle with settings and see if I can figure something out.
  Reply With Quote
04/28/16, 04:47 PM   #4
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,602
The output is what you see in the top right corner.

I tried everything I can think off. Calling ApplySettings after every single SetSetting, once after everything was set, with a delay. I even called each SetSetting with some milliseconds delay between each. That's just a few things I tried, but nothing works.
  Reply With Quote
04/29/16, 09:56 AM   #5
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,602
I looked around a bit more and saw that I used an incorrect value for setting NAMEPLATE_TYPE_ALLIANCE_INDICATORS. After I changed it, the behavior changed and it now always sets NAMEPLATE_TYPE_ALL_HEALTHBARS to off without fail. No other setting is affected. When I remove NAMEPLATE_TYPE_ALL_HEALTHBARS from the list, suddenly some other settings are affected again.
It feels like the game "light off" at this point.

I also saw that ApplySettings is only necessary when setting some of the video settings.
  Reply With Quote
04/29/16, 10:29 AM   #6
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,602
I added this code which seems to solve the problem. Not really happy with it, but at least it seems to work now.
Lua Code:
  1. SaveSettings() -- save and restore the settings when we leave an area through a loading screen, otherwise they may get messed up
  2.     RegisterForEvent(EVENT_PLAYER_ACTIVATED, function()
  3.         if(not GetGuiHidden(INGAME_GUI_NAME)) then
  4.             ApplyCustomSettings(savedSettings)
  5.         else
  6.             ApplyCustomSettings(DESIRED_SETTINGS)
  7.         end
  8.     end)
  9.     RegisterForEvent(EVENT_PLAYER_DEACTIVATED, function()
  10.         if(not GetGuiHidden(INGAME_GUI_NAME)) then
  11.             SaveSettings()
  12.         end
  13.     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