Merge settings menu code

Sasky [06-21-14 - 12:56]
Merge settings menu code
Filename
LAddMin.lua
LAddMin.txt
LAddMinConfig.lua
diff --git a/LAddMin.lua b/LAddMin.lua
index 73fda7e..1e858fb 100644
--- a/LAddMin.lua
+++ b/LAddMin.lua
@@ -280,56 +280,14 @@ end
 -------------------------------------------------------------------------------
 -- Local functions ------------------------------------------------------------
 -------------------------------------------------------------------------------
-local function CreateSettingsMenu()
-   local panel = {
-      name = "L'AddonMinder",
-      displayName = "|cFFFFB0L'AddonMinder|r",
-      author = "Garkin",
-      version = "0.2",
-      registerForRefresh = true,
-      registerForDefaults = true
-   }
-   LAM2:RegisterAddonPanel("LAddMin_Panel", panel)
-
-   local addonNames = {}
-   for name in pairs(sv.enabled) do
-      table.insert(addonNames, name)
-   end
-   table.sort(addonNames)
-
-   local controlTable = {}
-   for _,name in ipairs(addonNames) do
-      local checkbox = {
-         type = "checkbox",
-         name = name,
-         getFunc = function() return sv.enabled[name] end,
-         setFunc = function(value) sv.enabled[name] = value end,
-         default = false
-      }
-      table.insert(controlTable, checkbox)
-   end
-
-   local text = {}
-   for name in pairs(invalidAddons) do
-      table.insert(text, name)
-   end
-   if #text > 0 then
-      table.insert(controlTable, { type = "description", title = "Invalid addons:", text = table.concat(text, "\n- ") })
-   end
-
-   table.insert(controlTable, { type = "button", name = GetString(SI_ADDON_MANAGER_RELOAD), func = function() ReloadUI("ingame") end } )
-
-   LAM2:RegisterOptionControls("LAddMin_Panel", controlTable)
-end
-
 local function OnAddonLoaded(code, addon)
    if addon ~= "LAddMin" then return end

    sv = ZO_SavedVars:NewAccountWide("LAddMin_ConversionList", 1, "Addons", { enabled = {} })

-   CreateSettingsMenu()
+   LAddMin_createSettingsMenu(sv)

-   CALLBACK_MANAGER:RegisterCallback("LAM-PanelControlsCreated", DelayedCalls)
+   --CALLBACK_MANAGER:RegisterCallback("LAM-PanelControlsCreated", DelayedCalls)

    EVENT_MANAGER:UnregisterForEvent(addon, code)
 end
diff --git a/LAddMin.txt b/LAddMin.txt
index 1c57f59..fee0a9b 100644
--- a/LAddMin.txt
+++ b/LAddMin.txt
@@ -21,5 +21,5 @@ Libs\LibAddonMenu-2.0\controls\slider.lua
 Libs\LibAddonMenu-2.0\controls\texture.lua

 LAddMinCompatability.lua
-LAddMin.lua
 LAddMinConfig.lua
+LAddMin.lua
diff --git a/LAddMinConfig.lua b/LAddMinConfig.lua
index c79b9a1..08379e7 100644
--- a/LAddMinConfig.lua
+++ b/LAddMinConfig.lua
@@ -1,50 +1,54 @@
-local function createPanel()
+function LAddMin_createSettingsMenu(sv)
     local LAM = LibStub("LibAddonMenu-2.0")
     local menuData = {}
     LAM:RegisterAddonPanel("LAddMin_UI", {
         type = "panel",
-        name = "LAddMin",
-        displayName = "|cFFFFB0LAddMin",
-        author = "|c00C000Garkin|r and Sasky",
-        version = "0.1",
+        name = "L'AddonMinder",
+        displayName = "|cFFFFB0L'AddonMinder|r",
+        author = "Garkin and Sasky",
+        version = "0.2",
+        registerForRefresh = true,
+        registerForDefaults = true,
     })
     LAM:RegisterOptionControls("LAddMin_UI", menuData)

     table.insert(menuData,{
-        type = "description",
-        title = "|cFF0000WARNING|r: Using this on addons can break them.",
-        text = "If you have an error after enabling an addon, please disable it.\n" ..
-                "If an addon you check here has an issue, disable the conversion here before filing a bug report."
-    })
-
-    table.insert(menuData,{
-        type = "header",
-        name = "LAM 1.0 Panels"
-    })
-
-    table.insert(menuData,{
-        type = "description",
-        text = "ON to enable LAM2 conversion"
+        {
+            type = "description",
+            title = "|cFF0000WARNING|r: Using this on addons can break them.",
+            text = "If you have an error after enabling an addon, please disable it.\n" ..
+                    "If an addon you check here has an issue, disable the conversion here before filing a bug report."
+        },
+        {
+            type = "header",
+            name = "LAM 1.0 Panels"
+        },
+        {
+            type = "description",
+            text = "ON to enable LAM2 conversion"
+        }
     })

     --Sort into known working (good), known broken (bad), and unknown (ugly)
     --(Couldn't resist... ~Sasky)
     local good, ugly, bad = {}, {}, {}
-    for k,_ in pairs(LAddMinUpconvertSettings.cfg) do
+    for name in pairs(sv.enabled) do
         local checkbox = {
             type = "checkbox",
-            name = k,
-            getFunc = function() return LAddMinUpconvertSettings.cfg[k] end,
-            setFunc = function(val) LAddMinUpconvertSettings.cfg[k] = val end
+            name = name,
+            getFunc = function() return sv.enabled[name] end,
+            setFunc = function(val) sv.enabled[name] = val end,
+            default = false
         }

-        if LAddMinCompatability[k] == nil then
+        if LAddMinCompatability[name] == nil then
             table.insert(ugly, checkbox)
         else
-            if LAddMinCompatability[k] then
+            if LAddMinCompatability[name] then
+                checkbox.default = true
                 table.insert(good, checkbox)
             else
-                checkbox.warning = "Enabling this could cause " .. k .. " to stop working."
+                checkbox.disabled = true --Could set this to override value
                 table.insert(bad, checkbox)
             end
         end
@@ -85,7 +89,9 @@ local function createPanel()
         })
     end

-    EVENT_MANAGER:UnregisterForEvent("LAddMinUI", EVENT_PLAYER_ACTIVATED)
-end
-
-EVENT_MANAGER:RegisterForEvent("LAddMinUI", EVENT_PLAYER_ACTIVATED, createPanel)
\ No newline at end of file
+    table.insert(menuData, {
+        type = "button",
+        name = GetString(SI_ADDON_MANAGER_RELOAD),
+        func = function() ReloadUI("ingame") end
+    })
+end
\ No newline at end of file