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:
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:
{
type = "checkbox",
name = "Use Account-Wide settings",
getFunc = function()
return SimpleXPBar.accountwide_settings.isAccountWide
end,
setFunc = function(val)
if SimpleXPBar.accountwide_settings.isAccountWide == val then return end
SimpleXPBar.accountwide_settings.isAccountWide = val
if SimpleXPBar.accountwide_settings.isAccountWide then
SimpleXPBar.AWSV = ZO_SavedVars:NewAccountWide("SimpleXPBar_Settings", "1", nil, SimpleXPBar.CharSV)
SimpleXPBar.CurSV = SimpleXPBar.AWSV
else
SimpleXPBar.CharSV = ZO_SavedVars:New("SimpleXPBar_Settings", "1", nil, SimpleXPBar.AWSV)
SimpleXPBar.CurSV = SimpleXPBar.CharSV
end
CALLBACK_MANAGER:FireCallbacks("LAM-RefreshPanel", panel)
end,
},