View Single Post
01/25/16, 07:55 AM   #5
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,579
While reloading the UI when you toggle the checkbox may solve the problem, it makes for a horrible user experience. Especially when there are multiple settings that each want to reload the ui for themselves, so please use it only as a last resort when there is absolutely no other way to get around it and even then, consider adding a reload ui button instead of automatically reloading it. This advice is also meant for other authors that use forced UI reloads.

As for your problem, I think there are three issues.

1) When you replace the currently used variables in your set function you also need to inform LAM that something changed, so that it can render the changes in its controls.
This can be done by firing the "LAM-RefreshPanel" callback:
Lua Code:
  1. CALLBACK_MANAGER:FireCallbacks("LAM-RefreshPanel", panel)
Where panel is the value that gets returned by RegisterAddonPanel.

2) ZO_SavedVars is a highly complex object. I am not sure if ZO_DeepTableCopy is enough to replace the values correctly. I don't personally use ZO_SavedVars, so correct me if I am wrong, but I think the right way to accomplish what you want is to just create a new ZO_SavedVars object and pass the values that need to be copied as defaults.

3) LAM may call setFunc more often than necessary (not 100% sure, but it might happen), so you should check if something changed before doing your copy routine.

With all of these things considered, it should look something like this:
Lua Code:
  1. {
  2.         type = "checkbox",
  3.         name = "Use Account-Wide settings",
  4.         getFunc = function()
  5.             return SimpleXPBar.accountwide_settings.isAccountWide
  6.         end,
  7.         setFunc = function(val)
  8.             if SimpleXPBar.accountwide_settings.isAccountWide == val then return end
  9.             SimpleXPBar.accountwide_settings.isAccountWide = val
  10.             if SimpleXPBar.accountwide_settings.isAccountWide then
  11.                 SimpleXPBar.AWSV = ZO_SavedVars:NewAccountWide("SimpleXPBar_Settings", "1", nil, SimpleXPBar.CharSV)
  12.                 SimpleXPBar.CurSV = SimpleXPBar.AWSV
  13.             else
  14.                 SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.AWSV)
  15.                 SimpleXPBar.CurSV = SimpleXPBar.CharSV
  16.             end
  17.             CALLBACK_MANAGER:FireCallbacks("LAM-RefreshPanel", panel)
  18.         end,
  19.     },
  Reply With Quote