Change 1.1.0

Jarth [03-01-17 - 19:56]
Change 1.1.0
Filename
Changelog
SummonAssistant.lua
diff --git a/Changelog b/Changelog
index 509ed69..df1e48d 100644
--- a/Changelog
+++ b/Changelog
@@ -1,11 +1,17 @@
 -------------------------------------------------------------------------------
 Summon Assistant V1.0.3 11-02-2017
 -------------------------------------------------------------------------------
+Version 1.1.0 (01-03-2017)
+- Fixed default settings:
+-- Fixed issue where default color were not set correctly
+-- Fixed issue where wrong assistants were enabled by default and could not be disabled
+-- Fixed issue where account setting could not be disabled
+
 Version 1.0.3 (11-02-2017)
 - Migrated repository to Git

 Version 1.0.2 (Februar 11, 2017)
-- fixed issue when 'Pirharri the Smuggler' is not enabled:
+- Fixed issue when 'Pirharri the Smuggler' is not enabled:
 -- user:/AddOns/SummonAssistant/SummonAssistant.lua:104: function expected instead of nil.

 Version 1.0.1 (Februar 11, 2017)
diff --git a/SummonAssistant.lua b/SummonAssistant.lua
index b54b2d7..705cca6 100644
--- a/SummonAssistant.lua
+++ b/SummonAssistant.lua
@@ -1,18 +1,19 @@
 --[[
 Author: Jarth
 Filename: SummonAssistant.lua
-Version: V1.0.3
+Version: V1.1.0
 ]]--

 -------------------------------------------------------------------------------------------------
 --  Libraries --
 -------------------------------------------------------------------------------------------------
 local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0")
+
 -------------------------------------------------------------------------------------------------
 --  VARIABLE --
 -------------------------------------------------------------------------------------------------
 local ADDON_NAME = "SummonAssistant"
-local ADDON_VERSION = 1
+local ADDON_VERSION = 1.1
 local ADDON_AUTHOR = "Jarth"
 local ADDON_WEBSITE = ""
 local SummonAssistant = {} -- this may seem odd, but it sets the access level for "SummonAssistant"
@@ -21,13 +22,13 @@ SummonAssistant.name = ADDON_NAME
 SummonAssistant.saCountUnlocked = GetTotalCollectiblesByCategoryType(COLLECTIBLE_CATEGORY_TYPE_ASSISTANT)
 SummonAssistant.SA_Button = {}
 SummonAssistant.Default = {
-  left = 0,
-  top = 0,
-  centerColor = {r=226,b=226,g=226,a=0.4}, -- {red, green, blue, alpha}
-  edgeColor = {r=147,b=142,g=142,a=0.6}, -- {red, green, blue, alpha}
-  showFence = true,
-  showBanker = true,
-  showVendor = true,
+  left = CENTER,
+  top = CENTER,
+  centerColor = {0.88,0.88,0.88,0.4}, -- {red, green, blue, alpha}
+  edgeColor = {0.57,0.57,0.57,0.6}, -- {red, green, blue, alpha}
+  showFence = IsCollectibleUnlocked(300),
+  showBanker = IsCollectibleUnlocked(267),
+  showVendor = IsCollectibleUnlocked(301),
   useAccountSettings = true,
 }

@@ -47,30 +48,30 @@ function SummonAssistant.saClicked(id)
 end

 function SummonAssistant.initializeButtons()
-    local position = 0
-    for i = 1, SummonAssistant.saCountUnlocked do
-        local id = GetCollectibleIdFromType(COLLECTIBLE_CATEGORY_TYPE_ASSISTANT, i)
-        if SummonAssistant.isCollectibleEnabled(id) then
-          local enabled = true
-          if id > 0 then
-            enabled = IsCollectibleUnlocked(id)
-          end
-          if SummonAssistant.SA_Button[i] == nil then
-            SummonAssistant.SA_Button[i] = WINDOW_MANAGER:CreateControlFromVirtual("SA_Button"..i, SA_FrameBackdrop, "SA_Button", 1)
-            SummonAssistant.SA_Button[i]:SetId(i)
-          end
-          SummonAssistant.setupButton(i, SummonAssistant.SA_Button[i], id, enabled)
-          SummonAssistant.SA_Button[i]:SetHidden(false)
-          SummonAssistant.SA_Button[i]:ClearAnchors()
-          SummonAssistant.SA_Button[i]:SetAnchor(TOPLEFT, SA_FrameBackdrop, TOPLEFT, 10+60*(position), 10)
-          position = position + 1
-        else
-          if SummonAssistant.SA_Button[i] == nil then
-          else
-            SummonAssistant.SA_Button[i]:SetHidden(true)
-          end
-        end
+  local position = 0
+  for i = 1, SummonAssistant.saCountUnlocked do
+    local id = GetCollectibleIdFromType(COLLECTIBLE_CATEGORY_TYPE_ASSISTANT, i)
+    if SummonAssistant.isCollectibleEnabled(id) then
+      local enabled = true
+      if id > 0 then
+        enabled = IsCollectibleUnlocked(id)
+      end
+      if SummonAssistant.SA_Button[i] == nil then
+        SummonAssistant.SA_Button[i] = WINDOW_MANAGER:CreateControlFromVirtual("SA_Button"..i, SA_FrameBackdrop, "SA_Button", 1)
+        SummonAssistant.SA_Button[i]:SetId(i)
+      end
+      SummonAssistant.setupButton(i, SummonAssistant.SA_Button[i], id, enabled)
+      SummonAssistant.SA_Button[i]:SetHidden(false)
+      SummonAssistant.SA_Button[i]:ClearAnchors()
+      SummonAssistant.SA_Button[i]:SetAnchor(TOPLEFT, SA_FrameBackdrop, TOPLEFT, 10+60*(position), 10)
+      position = position + 1
+    else
+      if SummonAssistant.SA_Button[i] == nil then
+      else
+        SummonAssistant.SA_Button[i]:SetHidden(true)
+      end
     end
+  end
 end

 function SummonAssistant.setButtonFrameWidth()
@@ -92,21 +93,21 @@ function SummonAssistant.isCollectibleEnabled(id)
 end

 function SummonAssistant.setupButton(i, SA_Button, id, enabled)
-    local SA_ButtonTexture = SummonAssistant.wm:GetControlByName("SA_Button"..i.."Texture")
-    if enabled then
-        if id == 300 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_fence_01.dds")
-        elseif id == 267 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_banker_01.dds")
-        elseif id == 301 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_vendor_01.dds")
-        end
-        SA_Button:SetHandler("OnClicked", function(self) SummonAssistant.saClicked(SA_Button:GetId()) end)
+  local SA_ButtonTexture = SummonAssistant.wm:GetControlByName("SA_Button"..i.."Texture")
+  if enabled then
+    if id == 300 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_fence_01.dds")
+    elseif id == 267 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_banker_01.dds")
+    elseif id == 301 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_vendor_01.dds")
+    end
+    SA_Button:SetHandler("OnClicked", function(self) SummonAssistant.saClicked(SA_Button:GetId()) end)
+  else
+    if id == 300 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_fence_01_empty.dds")
+    elseif id == 267 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_banker_01-empty.dds")
+    elseif id == 301 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_vendor_01_empty.dds")
     else
-        if id == 300 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_fence_01_empty.dds")
-        elseif id == 267 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_banker_01-empty.dds")
-        elseif id == 301 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_vendor_01_empty.dds")
-        else
-        SA_Button:SetAlpha(0)
-        end
-    end
+    SA_Button:SetAlpha(0)
+    end
+  end
 end

 function SummonAssistant.saRestorePosition()
@@ -134,6 +135,15 @@ function SummonAssistant_OnMoveStop()
   SummonAssistant.savedVariables.left = SA_Frame:GetLeft()
 end

+function SummonAssistant.RestorePanel()
+  -- Set width of SA_Frame
+  SummonAssistant.setButtonFrameWidth()
+  -- Creates and setup of buttons
+  SummonAssistant.initializeButtons()
+  -- Restore position of bar
+  SummonAssistant.saRestorePosition()
+end
+
 -------------------------------------------------------------------------------------------------
 --  Menu Functions --
 -------------------------------------------------------------------------------------------------
@@ -163,52 +173,55 @@ function SummonAssistant.CreateSettingsWindow()
 			type = "checkbox",
 			name = "Use account settings",
 			tooltip = "When ON the account settings will be used. When OFF character settings will be used.",
-			default = true,
-			getFunc = function() return SummonAssistant.savedVariables.useAccount end,
+			default = SummonAssistant.Default.useAccountSettings,
+			getFunc = function() return SummonAssistant.savedVariables.useAccountSettings end,
 			setFunc = function(newValue)
-          if newValue then
-            SummonAssistant.savedVariables = ZO_SavedVars:NewAccountWide("SummonAssistant_Account", ADDON_VERSION, nil, SummonAssistant.Default)
-          else
-            SummonAssistant.savedVariables = ZO_SavedVars:New("SummonAssistant_Character", ADDON_VERSION, nil, SummonAssistant.Default)
-          end
-          SA_FrameBackdrop:SetCenterColor(unpack(SummonAssistant.savedVariables.centerColor))
-          SA_FrameBackdrop:SetEdgeColor(unpack(SummonAssistant.savedVariables.edgeColor))
-          SummonAssistant.setButtonFrameWidth()
-          SummonAssistant.initializeButtons()
-        end,
+        --Apply value to existing variable
+			  SummonAssistant.savedVariables.useAccountSettings = newValue;
+			  if newValue then
+				  SummonAssistant.savedVariables = ZO_SavedVars:NewAccountWide("SummonAssistant_Account", ADDON_VERSION, nil, SummonAssistant.Default)
+			  else
+				  SummonAssistant.savedVariables = ZO_SavedVars:New("SummonAssistant_Character", ADDON_VERSION, nil, SummonAssistant.Default)
+			  end
+        --Apply value to new variable
+			  SummonAssistant.savedVariables.useAccountSettings = newValue;
+			  SA_FrameBackdrop:SetCenterColor(unpack(SummonAssistant.savedVariables.centerColor))
+			  SA_FrameBackdrop:SetEdgeColor(unpack(SummonAssistant.savedVariables.edgeColor))
+			  SummonAssistant.RestorePanel()
+			end,
 		},
 		[4] = {
 			type = "submenu",
 			name = "Colors",
 			tooltip = "Allows you to change colors.",
 			controls = {
-        [1] = {
-          type = "description",
-          text = "Here you can adjust the colors."
-        },
-        [2] = {
-          type = "colorpicker",
-          name = "Backdrop Color",
-          default = SummonAssistant.Default.centerColor,
-          tooltip = "Changes the color of the background.",
-          getFunc = function() return unpack( SummonAssistant.savedVariables.centerColor ) end,
-          setFunc = function(r,g,b,a)
-            SummonAssistant.savedVariables.centerColor = {r,g,b,a}
-            SA_FrameBackdrop:SetCenterColor(r,g,b,a)
-            end,
-          width = "half"
-        },
-				[3] = {
-					type = "colorpicker",
-					name = "Frame Color",
-          default = SummonAssistant.Default.edgeColor,
-					tooltip = "Changes the color of the frame.",
-					getFunc = function() return unpack( SummonAssistant.savedVariables.edgeColor ) end,
-					setFunc = function(r,g,b,a)
-						SummonAssistant.savedVariables.edgeColor = {r,g,b,a}
-            SA_FrameBackdrop:SetEdgeColor(r,g,b,a)
-            end,
-          width = "half"
+			[1] = {
+			  type = "description",
+			  text = "Here you can adjust the colors."
+			},
+			[2] = {
+			  type = "colorpicker",
+			  name = "Backdrop Color",
+			  default = SummonAssistant.Default.centerColor,
+			  tooltip = "Changes the color of the background.",
+			  getFunc = function() return unpack( SummonAssistant.savedVariables.centerColor ) end,
+			  setFunc = function(r,g,b,a)
+          SummonAssistant.savedVariables.centerColor = {r,g,b,a}
+          SA_FrameBackdrop:SetCenterColor(r,g,b,a)
+			  end,
+			width = "half"
+			},
+			[3] = {
+				type = "colorpicker",
+				name = "Frame Color",
+				default = SummonAssistant.Default.edgeColor,
+				tooltip = "Changes the color of the frame.",
+				getFunc = function() return unpack( SummonAssistant.savedVariables.edgeColor ) end,
+				setFunc = function(r,g,b,a)
+					SummonAssistant.savedVariables.edgeColor = {r,g,b,a}
+					SA_FrameBackdrop:SetEdgeColor(r,g,b,a)
+				end,
+				width = "half"
 				}
 			},
     },
@@ -229,9 +242,9 @@ function SummonAssistant.CreateSettingsWindow()
           disabled = not IsCollectibleUnlocked(300),
           getFunc = function() return SummonAssistant.savedVariables.showFence end,
           setFunc = function(newValue)
-            SummonAssistant.savedVariables.showFence = newValue
-            SummonAssistant.setButtonFrameWidth()
-            SummonAssistant.initializeButtons() end,
+             SummonAssistant.savedVariables.showFence = newValue
+             SummonAssistant.RestorePanel()
+			    end,
         },
         [3] = {
           type = "checkbox",
@@ -241,9 +254,9 @@ function SummonAssistant.CreateSettingsWindow()
           disabled = not IsCollectibleUnlocked(267),
           getFunc = function() return SummonAssistant.savedVariables.showBanker end,
           setFunc = function(newValue)
-            SummonAssistant.savedVariables.showBanker = newValue
-            SummonAssistant.setButtonFrameWidth()
-            SummonAssistant.initializeButtons() end,
+             SummonAssistant.savedVariables.showBanker = newValue
+             SummonAssistant.RestorePanel()
+			    end,
         },
         [4] = {
           type = "checkbox",
@@ -253,9 +266,9 @@ function SummonAssistant.CreateSettingsWindow()
           disabled = not IsCollectibleUnlocked(301),
           getFunc = function() return SummonAssistant.savedVariables.showVendor end,
           setFunc = function(newValue)
-            SummonAssistant.savedVariables.showVendor = newValue
-            SummonAssistant.setButtonFrameWidth()
-            SummonAssistant.initializeButtons() end,
+             SummonAssistant.savedVariables.showVendor = newValue
+             SummonAssistant.RestorePanel()
+			    end,
         },
       }
 		},
@@ -269,12 +282,7 @@ function SummonAssistant:Initialize()
   if SummonAssistant.savedVariables.useAccountSettings then
     SummonAssistant.savedVariables = ZO_SavedVars:NewAccountWide("SummonAssistant_Account", ADDON_VERSION, nil, SummonAssistant.Default)
   end
-  -- Set width of SA_Frame
-  SummonAssistant.setButtonFrameWidth()
-  -- Creates and setup of buttons
-  SummonAssistant.initializeButtons()
-  -- Restore position of bar
-  SummonAssistant.saRestorePosition()
+  SummonAssistant.RestorePanel()
   -- Create Hotkey selections for assistants.
   SummonAssistant.createHotkeySelections()
   -- Create menu variables.