Version 1.3.0 (07-01-2017)

Jarth [01-07-18 - 10:35]
Version 1.3.0 (07-01-2017)
Filename
Changelog
SummonAssistant.lua
SummonAssistant.xml
diff --git a/Changelog b/Changelog
index 99276fc..2f3b581 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,15 @@
 -------------------------------------------------------------------------------
 Summon Assistant
 -------------------------------------------------------------------------------
+Version 1.3.0 (07-01-2017)
+(Breaking changes to the saved settings)
+- Added setting to show X,Y coordinates when the bar is moved
+    (Should be disabled after move)
+- Fixed issue where the color would not be set properly, after doing a "Reset to default"
+- Refactored the code, should be easier to expand
+-- Focus DRY
+-- Merged settings/variabled into tables, i hope it don't affect memory usage in a bad way
+
 Version 1.2.5 (26-12-2017)
 - Fixed issue where the border would be visible, when no icons were shown
 (Thanks for the feedback: efster)
diff --git a/SummonAssistant.lua b/SummonAssistant.lua
index 2502bc7..2ab8682 100644
--- a/SummonAssistant.lua
+++ b/SummonAssistant.lua
@@ -1,7 +1,7 @@
 --[[
 Author: Jarth
-Filename: SummonAssistant.lua
-]]--
+Filename: SummonAssistant:lua
+]] --

 -------------------------------------------------------------------------------------------------
 --  Libraries --
@@ -12,382 +12,521 @@ local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0")
 --  VARIABLE --
 -------------------------------------------------------------------------------------------------
 local ADDON_NAME = "SummonAssistant"
-local ADDON_VERSION = 1.2
-local ADDON_MINOR_VERSION = 5
+local ADDON_DISPLAY_NAME = "Summon Assistant"
+local ADDON_VERSION = 1.3
+local ADDON_MINOR_VERSION = 0
 local ADDON_AUTHOR = "Jarth"
 local ADDON_WEBSITE = ""
-local SummonAssistant = {} -- this may seem odd, but it sets the access level for "SummonAssistant"
-SummonAssistant.wm = GetWindowManager() -- we want to use whatever window manager the game is
-SummonAssistant.name = ADDON_NAME
-SummonAssistant.saCountUnlocked = GetTotalCollectiblesByCategoryType(COLLECTIBLE_CATEGORY_TYPE_ASSISTANT)
-SummonAssistant.SA_Button = {}
+local SummonAssistant = {}
+SummonAssistant.wm = GetWindowManager()
+SummonAssistant.Buttons = {}
 SummonAssistant.Fragment = nil
+SummonAssistant.Types = {
+    Banker = {
+        Id = 267,
+        Title = "Banker:",
+        Name = "Banker",
+        name = "banker",
+        Tooltip = "When ON the banker button will be visible. When OFF the banker button will not be visible (disabled if locked for the account).",
+        EnabledTexture = "/esoui/art/icons/" .. "assistant_banker_01.dds",
+        DisabledTexture = "/esoui/art/icons/" .. "assistant_banker_01-empty.dds",
+        KeyBinding = "SI_BINDING_NAME_SummonAssistant_Assistant_Banker",
+        Disabled = function()
+            IsCollectibleUnlocked(267)
+        end
+    },
+    Fence = {
+        Id = 300,
+        Title = "Fence:",
+        Name = "Fence",
+        name = "fence",
+        Tooltip = "When ON the fence button will be visible. When OFF the fence button will not be visible (disabled if locked for the account).",
+        EnabledTexture = "/esoui/art/icons/" .. "assistant_fence_01.dds",
+        DisabledTexture = "/esoui/art/icons/" .. "assistant_fence_01-empty.dds",
+        KeyBinding = "SI_BINDING_NAME_SummonAssistant_Assistant_Fence",
+        Disabled = function()
+            IsCollectibleUnlocked(300)
+        end
+    },
+    Vendor = {
+        Id = 301,
+        Title = "Vendor:",
+        Name = "Vendor",
+        name = "vendor",
+        Tooltip = "When ON the vendor button will be visible. When OFF the vendor button will not be visible (disabled if locked for the account).",
+        EnabledTexture = "/esoui/art/icons/" .. "assistant_vendor_01.dds",
+        DisabledTexture = "/esoui/art/icons/" .. "assistant_vendor_01-empty.dds",
+        KeyBinding = "SI_BINDING_NAME_SummonAssistant_Assistant_Vendor",
+        Disabled = function()
+            IsCollectibleUnlocked(301)
+        end
+    }
+}
+
 SummonAssistant.Default = {
-  left = CENTER,
-  top = CENTER,
-  centerColor = { [1] = 0.88, [2] = 0.88, [3] = 0.88, [4] = 0.4 }, -- {red, green, blue, alpha}
-  edgeColor = { [1] = 0.57, [2] = 0.57, [3] = 0.57, [4] = 0.6 }, -- {red, green, blue, alpha}
-  showBanker = IsCollectibleUnlocked(267),
-  showFence = IsCollectibleUnlocked(300),
-  showVendor = IsCollectibleUnlocked(301),
-  useAccountSettings = true,
-  horizontalOrientation = true,
-  hideBarInMenu = true
+    left = CENTER,
+    top = CENTER,
+    centerColor = {r = 0.88, g = 0.88, b = 0.88, a = 0.4},
+    edgeColor = {r = 0.57, g = 0.57, b = 0.57, a = 0.6},
+    useAccountSettings = true,
+    Horizontal = true,
+    hideBarInMenu = true,
+    ShowMoveAssitance = false,
+    ShowAssistants = {}
+}
+--Shows assistants by default, when unlocked.
+SummonAssistant.Default.ShowAssistants[267] = IsCollectibleUnlocked(267)
+SummonAssistant.Default.ShowAssistants[300] = IsCollectibleUnlocked(300)
+SummonAssistant.Default.ShowAssistants[301] = IsCollectibleUnlocked(301)
+SummonAssistant.Global = {
+    NumberUnlocked = GetTotalCollectiblesByCategoryType(COLLECTIBLE_CATEGORY_TYPE_ASSISTANT),
+    LblOffset = 10,
+    LblHeight = 60,
+    LblWidth = 60
 }

 -------------------------------------------------------------------------------------------------
 --  FUNCTIONS --
 -------------------------------------------------------------------------------------------------
-function SummonAssistant.saClicked(id)
-  -- increment the counter by one
-  if id > 0 then
-    local id = GetCollectibleIdFromType(COLLECTIBLE_CATEGORY_TYPE_ASSISTANT, id);
-    if IsCollectibleUnlocked(id) then
-      UseCollectible(id)
-    else
-      UseCollectible(GetActiveCollectibleByType(COLLECTIBLE_CATEGORY_TYPE_ASSISTANT))
+
+function SummonAssistant.OnAddOnLoaded(event, addonName)
+    if addonName == ADDON_NAME then
+        SummonAssistant.Initialize()
     end
-  end
 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", SA_FrameBackdrop, "SA_Button", i)
-        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()
-      if SummonAssistant.savedVariables.horizontalOrientation then
-        SummonAssistant.SA_Button[i]:SetAnchor(TOPLEFT, SA_FrameBackdrop, TOPLEFT, 10+60*(position), 10)
-      else
-        SummonAssistant.SA_Button[i]:SetAnchor(TOPLEFT, SA_FrameBackdrop, TOPLEFT, 10, 10+60*(position))
-      end
-      position = position + 1
-    else
-      if SummonAssistant.SA_Button[i] == nil then
-      else
-        SummonAssistant.SA_Button[i]:SetHidden(true)
-      end
+function SummonAssistant.Initialize()
+    -- Load saved values..
+    SummonAssistant.Saved = ZO_SavedVars:New("SummonAssistant_Character", ADDON_VERSION, nil, SummonAssistant.Default)
+    if SummonAssistant.Saved.useAccountSettings then
+        SummonAssistant.Saved = ZO_SavedVars:NewAccountWide("SummonAssistant_Account", ADDON_VERSION, nil, SummonAssistant.Default)
     end
-  end
-end
+    SummonAssistant_Frame:SetHandler("OnMoveStop", SummonAssistant.OnMoveStop)
+
+    SummonAssistant:RestorePanel()
+    SummonAssistant:CreateHotkeySelections()
+    SummonAssistant:CreateSettingsWindow()

-function SummonAssistant.setFragmentBehaviour(menuOpen)
-  if SummonAssistant.Fragment == nil then
-    SummonAssistant.Fragment = ZO_HUDFadeSceneFragment:New( SA_Frame )
-  end
+    EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED)
+end

-  if SummonAssistant.savedVariables.hideBarInMenu then
-    SummonAssistant.addControlToFrame(menuOpen)
-  else
-    SummonAssistant.removeControlToFrame(menuOpen)
-  end
+function SummonAssistant.OnMoveStop(frame)
+    SummonAssistant.Saved.top = frame:GetTop()
+    SummonAssistant.Saved.left = frame:GetLeft()
 end

-function SummonAssistant.addControlToFrame(menuOpen)
-  if menuOpen then
-    SA_Frame:SetHidden(true)
-  end
+-------------------------------------------------------------------------------------------------
+--  PRIVATE FUNCTIONS --
+-------------------------------------------------------------------------------------------------
+
+function SummonAssistant:GetVersion(showMinor)
+    if showMinor == false or ADDON_MINOR_VERSION == nil then
+        return tostring(ADDON_VERSION)
+    end
+    return tostring(ADDON_VERSION) .. "." .. tostring(ADDON_MINOR_VERSION)
+end

-  SCENE_MANAGER:GetScene('hud'):AddFragment(SummonAssistant.Fragment)
-  SCENE_MANAGER:GetScene('hudui'):AddFragment(SummonAssistant.Fragment)
+function SummonAssistant:OnClicked(id)
+    -- increment the counter by one
+    if id > 0 then
+        if IsCollectibleUnlocked(id) then
+            UseCollectible(id)
+        else
+            UseCollectible(GetActiveCollectibleByType(COLLECTIBLE_CATEGORY_TYPE_ASSISTANT))
+        end
+    end
 end

-function SummonAssistant.removeControlToFrame(menuOpen)
-  if menuOpen then
-    SA_Frame:SetHidden(false)
-  end
-
-  SCENE_MANAGER:GetScene('hud'):RemoveFragment(SummonAssistant.Fragment)
-  SCENE_MANAGER:GetScene('hudui'):RemoveFragment(SummonAssistant.Fragment)
+function SummonAssistant:addControlToFrame(menuOpen)
+    if menuOpen then
+        SummonAssistant_Frame:SetHidden(true)
+    end
+
+    SCENE_MANAGER:GetScene("hud"):AddFragment(SummonAssistant.Fragment)
+    SCENE_MANAGER:GetScene("hudui"):AddFragment(SummonAssistant.Fragment)
 end

-function SummonAssistant.setButtonFrameWidth()
-  local saBtnHeight = 60
-  local saBtnWidth = 60
-  local saCount = 0
-  local saShow = 0
+function SummonAssistant:removeControlToFrame(menuOpen)
+    if menuOpen then
+        SummonAssistant_Frame:SetHidden(false)
+    end

-  if IsCollectibleUnlocked(267) and SummonAssistant.savedVariables.showBanker then saCount = saCount + 1 end
-  if IsCollectibleUnlocked(300) and SummonAssistant.savedVariables.showFence  then saCount = saCount + 1 end
-  if IsCollectibleUnlocked(301) and SummonAssistant.savedVariables.showVendor then saCount = saCount + 1 end
-  if saCount > 0 then saShow = 1 end
+    SCENE_MANAGER:GetScene("hud"):RemoveFragment(SummonAssistant.Fragment)
+    SCENE_MANAGER:GetScene("hudui"):RemoveFragment(SummonAssistant.Fragment)
+end

-  SA_Frame:SetHidden(saCount == 0)
-  SA_FrameBackdrop:SetHidden(saCount == 0)
+function SummonAssistant:SetupButton(key, SummonAssistant_Button, id, enabled)
+    local SummonAssistant_ButtonTexture = SummonAssistant.wm:GetControlByName("SummonAssistant_Button" .. key .. "Texture")
+    if SummonAssistant_ButtonTexture ~= nil then
+        local handler = nil
+        local texture = SummonAssistant.Types[key].DisabledTexture
+        if enabled then
+            handler = function(self)
+                SummonAssistant:OnClicked(SummonAssistant_Button:GetId())
+            end
+            texture = SummonAssistant.Types[key].EnabledTexture
+        end
+        SummonAssistant_Button:SetHandler("OnClicked", handler)
+        SummonAssistant_ButtonTexture:SetTexture(texture)
+    end
+end

-  SA_Frame:SetHeight(SummonAssistant.savedVariables.horizontalOrientation and saShow * saBtnHeight or saCount * saBtnWidth)
-  SA_FrameBackdrop:SetHeight(SummonAssistant.savedVariables.horizontalOrientation and saShow * saBtnHeight or saCount * saBtnWidth)
-  SA_Frame:SetWidth(SummonAssistant.savedVariables.horizontalOrientation and saCount * saBtnWidth or saShow * saBtnHeight)
-  SA_FrameBackdrop:SetWidth(SummonAssistant.savedVariables.horizontalOrientation and saCount * saBtnWidth or saShow * saBtnHeight)
+function SummonAssistant:CreateHotkeySelections()
+    for key, _ in pairs(SummonAssistant.Types) do
+        if IsCollectibleUnlocked(SummonAssistant.Types[key].Id) then
+            ZO_CreateStringId(SummonAssistant.Types[key].KeyBinding, SummonAssistant.Types[key].Name)
+        end
+    end
 end

-function SummonAssistant.isCollectibleEnabled(id)
-  local result = true
-  if id == 267 and not SummonAssistant.savedVariables.showBanker then result = false
-  elseif id == 300 and not SummonAssistant.savedVariables.showFence  then result = false
-  elseif id == 301 and not SummonAssistant.savedVariables.showVendor then result = false
-  end
-  return result
+function SummonAssistant:RestorePanel()
+    SummonAssistant:SetFragmentBehaviour()
+
+    SummonAssistant:SetButtonFrameWidth()
+
+    SummonAssistant:FrameBackdropColor()
+
+    SummonAssistant:InitializeButtons()
+
+    SummonAssistant:RestorePosition()
+
+    SummonAssistant:ActivateMoveHandlers()
 end

-function SummonAssistant.setupButton(i, SA_Button, id, enabled)
-  local SA_ButtonTexture = SummonAssistant.wm:GetControlByName("SA_Button"..i.."Texture")
-  if SA_ButtonTexture == nil then
-  else
-    if enabled then
-      if id == 267 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_banker_01.dds")
-      elseif id == 300 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_fence_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)
+function SummonAssistant:SetFragmentBehaviour(menuOpen)
+    if SummonAssistant.Fragment == nil then
+        SummonAssistant.Fragment = ZO_HUDFadeSceneFragment:New(SummonAssistant_Frame)
+    end
+
+    if SummonAssistant.Saved.hideBarInMenu then
+        SummonAssistant:addControlToFrame(menuOpen)
     else
-      if id == 267 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_banker_01-empty.dds")
-      elseif id == 300 then SA_ButtonTexture:SetTexture("/esoui/art/icons/assistant_fence_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
-  end
+        SummonAssistant:removeControlToFrame(menuOpen)
+    end
 end

-function SummonAssistant.saRestorePosition()
-  local top = SummonAssistant.savedVariables.top
-  local left = SummonAssistant.savedVariables.left
-  SA_Frame:ClearAnchors()
-  SA_Frame:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, left, top)
+function SummonAssistant:SetButtonFrameWidth()
+    local saBtnHeight = 60
+    local saBtnWidth = 60
+    local saCount = 0
+    local saShow = 0
+
+    for key, value in pairs(SummonAssistant.Saved.ShowAssistants) do
+        if IsCollectibleUnlocked(key) and SummonAssistant.Saved.ShowAssistants[key] then
+            saCount = saCount + 1
+        end
+        if saShow == 0 then
+            saShow = 1
+        end
+    end
+
+    SummonAssistant_Frame:SetHidden(saCount == 0)
+    SummonAssistant_Frame:SetHeight(SummonAssistant.Global.LblHeight * (SummonAssistant.Saved.Horizontal and saShow or saCount))
+    SummonAssistant_Frame:SetWidth(SummonAssistant.Global.LblWidth * (SummonAssistant.Saved.Horizontal and saCount or saShow))
+
+    SummonAssistant_FrameBackdrop:SetHidden(saCount == 0)
+    SummonAssistant_FrameBackdrop:SetHeight(SummonAssistant.Global.LblHeight * (SummonAssistant.Saved.Horizontal and saShow or saCount))
+    SummonAssistant_FrameBackdrop:SetWidth(SummonAssistant.Global.LblWidth * (SummonAssistant.Saved.Horizontal and saCount or saShow))
 end

-function SummonAssistant.createHotkeySelections()
-  if IsCollectibleUnlocked(267) then
-    ZO_CreateStringId('SI_BINDING_NAME_SummonAssistant_Assistant_Banker', 'Banker')
-  end
-  if IsCollectibleUnlocked(300) then
-    ZO_CreateStringId('SI_BINDING_NAME_SummonAssistant_Assistant_Fence', 'Fence')
-  end
-  if IsCollectibleUnlocked(301) then
-    ZO_CreateStringId('SI_BINDING_NAME_SummonAssistant_Assistant_Vendor', 'Vendor')
-  end
+function SummonAssistant:FrameBackdropColor(centerColor, edgeColor)
+    if not centerColor then
+        centerColor = SummonAssistant.Saved.centerColor
+    end
+    if not edgeColor then
+        edgeColor = SummonAssistant.Saved.edgeColor
+    end
+    SummonAssistant_FrameBackdrop:SetCenterColor(centerColor.r, centerColor.g, centerColor.b, centerColor.a)
+    SummonAssistant_FrameBackdrop:SetEdgeColor(edgeColor.r, edgeColor.g, edgeColor.b, edgeColor.a)
 end

--- Global accessed function, allowing OnMoveStop to find the function.
-function SummonAssistant_OnMoveStop()
-  SummonAssistant.savedVariables.top = SA_Frame:GetTop()
-  SummonAssistant.savedVariables.left = SA_Frame:GetLeft()
+function SummonAssistant:InitializeButtons()
+    local position = 0
+    local index = 1
+    for key, value in pairs(SummonAssistant.Types) do
+        -- local id = GetCollectibleIdFromType(COLLECTIBLE_CATEGORY_TYPE_ASSISTANT, i)
+        local id = SummonAssistant.Types[key].Id
+        if SummonAssistant.Saved.ShowAssistants[id] then
+            local enabled = IsCollectibleUnlocked(SummonAssistant.Types[key].Id)
+            if SummonAssistant.Buttons[key] == nil then
+                SummonAssistant.Buttons[key] = WINDOW_MANAGER:CreateControlFromVirtual("SummonAssistant_Button", SummonAssistant_FrameBackdrop, "SummonAssistant_Button", key)
+                SummonAssistant.Buttons[key]:SetId(id)
+            end
+            SummonAssistant:SetupButton(key, SummonAssistant.Buttons[key], id, enabled)
+            SummonAssistant.Buttons[key]:SetHidden(false)
+            SummonAssistant.Buttons[key]:ClearAnchors()
+            if SummonAssistant.Saved.Horizontal then
+                SummonAssistant.Buttons[key]:SetAnchor(
+                    TOPLEFT,
+                    SummonAssistant_FrameBackdrop,
+                    TOPLEFT,
+                    SummonAssistant.Global.LblOffset + SummonAssistant.Global.LblHeight * (position),
+                    SummonAssistant.Global.LblOffset
+                )
+            else
+                SummonAssistant.Buttons[key]:SetAnchor(
+                    TOPLEFT,
+                    SummonAssistant_FrameBackdrop,
+                    TOPLEFT,
+                    SummonAssistant.Global.LblOffset,
+                    SummonAssistant.Global.LblOffset + SummonAssistant.Global.LblHeight * (position)
+                )
+            end
+            position = position + 1
+        else
+            if SummonAssistant.Buttons[key] ~= nil then
+                SummonAssistant.Buttons[key]:SetHidden(true)
+            end
+        end
+    end
 end

-function SummonAssistant.RestorePanel()
-  SummonAssistant.setFragmentBehaviour()
+function SummonAssistant:RestorePosition()
+    local top = SummonAssistant.Saved.top
+    local left = SummonAssistant.Saved.left
+    SummonAssistant_Frame:ClearAnchors()
+    SummonAssistant_Frame:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, left, top)
+end

-  SummonAssistant.setButtonFrameWidth()
-
-  SummonAssistant.initializeButtons()
-
-  SummonAssistant.saRestorePosition()
+function SummonAssistant:ActivateMoveHandlers()
+    if not SummonAssistant_Frame.LabelTopLeft and SummonAssistant.Saved.ShowMoveAssitance then
+        SummonAssistant_Frame.LabelTopLeft = SummonAssistant.wm:CreateControl(nil, SummonAssistant_Frame, CT_LABEL)
+        SummonAssistant_Frame.LabelTopLeft:SetDrawLevel(3)
+        SummonAssistant_Frame.LabelTopLeft:SetAnchorFill(SummonAssistant_Frame)
+        SummonAssistant_Frame.LabelTopLeft:SetFont("ZoFontWinH5")
+        SummonAssistant_Frame.LabelTopLeft:SetHorizontalAlignment(0)
+        SummonAssistant_Frame.LabelTopLeft:SetVerticalAlignment(0)
+        SummonAssistant_Frame["UpdateText"] = SummonAssistant.UpdateText
+        SummonAssistant_Frame:SetHandler("OnMouseEnter", SummonAssistant.OnMouseEnter)
+        SummonAssistant_Frame:SetHandler("OnMouseDown", SummonAssistant.OnMouseDown)
+        SummonAssistant_Frame:SetHandler("OnMouseUp", SummonAssistant.OnMouseUp)
+        SummonAssistant_Frame:SetHandler("OnMouseExit", SummonAssistant.OnMouseExit)
+    elseif SummonAssistant_Frame.LabelTopLeft and not SummonAssistant.Saved.ShowMoveAssitance then
+        SummonAssistant_Frame.LabelTopLeft = nil
+        SummonAssistant_Frame["UpdateText"] = nil
+        SummonAssistant_Frame:SetHandler("OnMouseEnter", nil)
+        SummonAssistant_Frame:SetHandler("OnMouseDown", nil)
+        SummonAssistant_Frame:SetHandler("OnMouseUp", nil)
+        SummonAssistant_Frame:SetHandler("OnMouseExit", nil)
+    end
 end

-function SummonAssistant.GetVersion(showMinor)
-  if showMinor == false or ADDON_MINOR_VERSION == nil  then
-    return tostring(ADDON_VERSION)
-  end
-    return tostring(ADDON_VERSION) .. "." .. tostring(ADDON_MINOR_VERSION)
+-------------------------------------------------------------------------------------------------
+-- FUNCTIONS --
+-- Move handlers --
+-------------------------------------------------------------------------------------------------
+
+function SummonAssistant.OnMouseEnter(frame)
+    frame.UpdateText(frame, true)
+end
+
+function SummonAssistant.OnMouseDown(frame)
+    frame:SetHandler("OnUpdate", SummonAssistant.OnMouseEnter)
+end
+
+function SummonAssistant.OnMouseExit(frame)
+    frame.UpdateText(frame, false)
+end
+
+function SummonAssistant.OnMouseUp(frame)
+    frame:SetHandler("OnUpdate", nil)
+end
+
+function SummonAssistant.UpdateText(frame, position)
+    if position then
+        frame.labelTextTopLeft = frame:GetLeft() .. "," .. frame:GetTop()
+    else
+        frame.labelTextTopLeft = ""
+    end
+    frame.LabelTopLeft:SetText(frame.labelTextTopLeft)
 end

 -------------------------------------------------------------------------------------------------
 --  Menu Functions --
 -------------------------------------------------------------------------------------------------
-function SummonAssistant.CreateSettingsWindow()
-	local panelData = {
-		type = "panel",
-		name = "Summon Assistant",
-		displayName = "Summon Assistant",
-		author = "Jarth",
-    version = SummonAssistant.GetVersion(true),
-		slashCommand = "/sa",
-		registerForRefresh = true,
-		registerForDefaults = true,
-	}
-	local cntrlOptionsPanel = LAM2:RegisterAddonPanel(SummonAssistant.name, panelData)
-
-	local optionsData = {
-		[1] = {
-			type = "header",
-			name = "Summon Assistant Settings"
-		},
-		[2] = {
-			type = "description",
-			text = "Here you can adjust how the summon assistant works."
-		},
-		[3] = {
-			type = "checkbox",
-			name = "Use account settings",
-			tooltip = "When ON the account settings will be used. When OFF character settings will be used.",
-			default = SummonAssistant.Default.useAccountSettings,
-			getFunc = function() return SummonAssistant.savedVariables.useAccountSettings end,
-			setFunc = function(newValue)
-        --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 = "checkbox",
-			name = "Bar orientation horizontal",
-			tooltip = "When ON the bar will orientate horizontally.",
-			default = SummonAssistant.Default.horizontalOrientation,
-			getFunc = function() return SummonAssistant.savedVariables.horizontalOrientation end,
-			setFunc = function(newValue)
-        --Apply value to existing variable
-        SummonAssistant.savedVariables.horizontalOrientation = newValue;
-        SummonAssistant.RestorePanel()
-			end
-		},
-		[5] = {
-			type = "checkbox",
-			name = "Hide bar in menu",
-			tooltip = "When ON the bar will hide when a menu is opened.",
-			default = SummonAssistant.Default.hideBarInMenu,
-			getFunc = function() return SummonAssistant.savedVariables.hideBarInMenu end,
-      setFunc = function(newValue)
-        SummonAssistant.savedVariables.hideBarInMenu = newValue
-        SummonAssistant.setFragmentBehaviour(true)
-			end,
-		},
-		[6] = {
-			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"
-				}
-			},
-    },
-    [7] = {
-      type = "submenu",
-      name = "Visibility",
-      tooltip = "Allows you to choose what assistant buttons you wants to see.",
-      controls = {
+function SummonAssistant:CreateSettingsWindow()
+    local panelData = {
+        type = "panel",
+        name = ADDON_DISPLAY_NAME,
+        displayName = ADDON_DISPLAY_NAME,
+        author = "Jarth",
+        version = SummonAssistant:GetVersion(true),
+        slashCommand = "/sa",
+        registerForRefresh = true,
+        registerForDefaults = true
+    }
+    local cntrlOptionsPanel = LAM2:RegisterAddonPanel(ADDON_NAME, panelData)
+
+    local optionsData = {
         [1] = {
-          type = "description",
-          text = "Select assistant buttons you want enabled."
+            type = "header",
+            name = ADDON_DISPLAY_NAME .. " Settings"
         },
         [2] = {
-          type = "checkbox",
-          name = "Show banker",
-          tooltip = "When ON the banker button will be visible. When OFF the banker button will not be visible (disabled if locked for the account).",
-          default = SummonAssistant.Default.showBanker,
-          disabled = not IsCollectibleUnlocked(267),
-          getFunc = function() return SummonAssistant.savedVariables.showBanker end,
-          setFunc = function(newValue)
-             SummonAssistant.savedVariables.showBanker = newValue
-             SummonAssistant.RestorePanel()
-          end
+            type = "description",
+            text = "Here you can adjust how the summon assistant works."
         },
         [3] = {
-          type = "checkbox",
-          name = "Show fence",
-          tooltip = "When ON the fence button will be visible. When OFF the fence button will not be visible (disabled if locked for the account).",
-          default = SummonAssistant.Default.showFence,
-          disabled = not IsCollectibleUnlocked(300),
-          getFunc = function() return SummonAssistant.savedVariables.showFence end,
-          setFunc = function(newValue)
-             SummonAssistant.savedVariables.showFence = newValue
-             SummonAssistant.RestorePanel()
-			    end
+            type = "checkbox",
+            name = "Use account settings",
+            tooltip = "When ON the account settings will be used. When OFF character settings will be used.",
+            default = SummonAssistant.Default.useAccountSettings,
+            getFunc = function()
+                return SummonAssistant.Saved.useAccountSettings
+            end,
+            setFunc = function(newValue)
+                --Apply value to existing variable
+                SummonAssistant.Saved.useAccountSettings = newValue
+                if newValue then
+                    SummonAssistant.Saved = ZO_SavedVars:NewAccountWide("SummonAssistant_Account", ADDON_VERSION, nil, SummonAssistant.Default)
+                else
+                    SummonAssistant.Saved = ZO_SavedVars:New("SummonAssistant_Character", ADDON_VERSION, nil, SummonAssistant.Default)
+                end
+                --Apply value to new variable
+                SummonAssistant.Saved.useAccountSettings = newValue
+                SummonAssistant:RestorePanel()
+            end
         },
         [4] = {
-          type = "checkbox",
-          name = "Show vendor",
-          tooltip = "When ON the vendor button will be visible. When OFF the vendor button will not be visible (disabled if locked for the account).",
-          default = SummonAssistant.Default.showVendor,
-          disabled = not IsCollectibleUnlocked(301),
-          getFunc = function() return SummonAssistant.savedVariables.showVendor end,
-          setFunc = function(newValue)
-             SummonAssistant.savedVariables.showVendor = newValue
-             SummonAssistant.RestorePanel()
-			    end
+            type = "checkbox",
+            name = "Bar orientation horizontal",
+            tooltip = "When ON the bar will orientate horizontally.",
+            default = SummonAssistant.Default.Horizontal,
+            getFunc = function()
+                return SummonAssistant.Saved.Horizontal
+            end,
+            setFunc = function(newValue)
+                --Apply value to existing variable
+                SummonAssistant.Saved.Horizontal = newValue
+                SummonAssistant:RestorePanel()
+            end
+        },
+        [5] = {
+            type = "checkbox",
+            name = "Hide bar in menu",
+            tooltip = "When ON the bar will hide when a menu is opened.",
+            default = SummonAssistant.Default.hideBarInMenu,
+            getFunc = function()
+                return SummonAssistant.Saved.hideBarInMenu
+            end,
+            setFunc = function(newValue)
+                SummonAssistant.Saved.hideBarInMenu = newValue
+                SummonAssistant:SetFragmentBehaviour(true)
+            end
+        },
+        [6] = {
+            type = "checkbox",
+            name = "Show bar position",
+            tooltip = "When ON the bar will show the X,Y position of the top left corner, when the mouse enters and drags the panel around.",
+            default = function()
+                return SummonAssistant.Default.ShowMoveAssitance
+            end,
+            getFunc = function()
+                return SummonAssistant.Saved.ShowMoveAssitance
+            end,
+            setFunc = function(newValue)
+                SummonAssistant.Saved.ShowMoveAssitance = newValue
+                SummonAssistant:RestorePanel()
+            end
+        },
+        [7] = {
+            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 = function()
+                        return SummonAssistant.Default.centerColor
+                    end,
+                    tooltip = "Changes the color of the background.",
+                    getFunc = function()
+                        return SummonAssistant.Saved.centerColor.r, SummonAssistant.Saved.centerColor.g, SummonAssistant.Saved.centerColor.b, SummonAssistant.Saved.centerColor.a
+                    end,
+                    setFunc = function(r, g, b, a)
+                        SummonAssistant.Saved.centerColor = {r = r, g = g, b = b, a = a}
+                        SummonAssistant:FrameBackdropColor()
+                    end,
+                    width = "half"
+                },
+                [3] = {
+                    type = "colorpicker",
+                    name = "Frame Color",
+                    default = function()
+                        return SummonAssistant.Default.edgeColor
+                    end,
+                    tooltip = "Changes the color of the frame.",
+                    getFunc = function()
+                        return SummonAssistant.Saved.edgeColor.r, SummonAssistant.Saved.edgeColor.g, SummonAssistant.Saved.edgeColor.b, SummonAssistant.Saved.edgeColor.a
+                    end,
+                    setFunc = function(r, g, b, a)
+                        SummonAssistant.Saved.edgeColor = {r = r, g = g, b = b, a = a}
+                        SummonAssistant:FrameBackdropColor()
+                    end,
+                    width = "half"
+                }
+            }
+        },
+        [8] = {
+            type = "submenu",
+            name = "Visibility",
+            tooltip = "Allows you to choose what assistant buttons you wants to see.",
+            controls = {
+                [1] = {
+                    type = "description",
+                    text = "Select assistant buttons you want enabled."
+                },
+                [2] = {
+                    type = "checkbox",
+                    name = "Show " .. SummonAssistant.Types.Banker.name,
+                    tooltip = SummonAssistant.Types.Banker.Tooltip,
+                    default = not SummonAssistant.Types.Banker.Disabled,
+                    disabled = SummonAssistant.Types.Banker.Disabled,
+                    getFunc = function()
+                        return SummonAssistant.Saved.ShowAssistants[267]
+                    end,
+                    setFunc = function(newValue)
+                        SummonAssistant.Saved.ShowAssistants[267] = newValue
+                        SummonAssistant:RestorePanel()
+                    end
+                },
+                [3] = {
+                    type = "checkbox",
+                    name = "Show " .. SummonAssistant.Types.Fence.name,
+                    tooltip = SummonAssistant.Types.Fence.Tooltip,
+                    default = not SummonAssistant.Types.Fence.Disabled,
+                    disabled = SummonAssistant.Types.Fence.Disabled,
+                    getFunc = function()
+                        return SummonAssistant.Saved.ShowAssistants[300]
+                    end,
+                    setFunc = function(newValue)
+                        SummonAssistant.Saved.ShowAssistants[300] = newValue
+                        SummonAssistant:RestorePanel()
+                    end
+                },
+                [4] = {
+                    type = "checkbox",
+                    name = "Show " .. SummonAssistant.Types.Vendor.name,
+                    tooltip = SummonAssistant.Types.Vendor.Tooltip,
+                    default = not SummonAssistant.Types.Vendor.Disabled,
+                    disabled = SummonAssistant.Types.Vendor.Disabled,
+                    getFunc = function()
+                        return SummonAssistant.Saved.ShowAssistants[301]
+                    end,
+                    setFunc = function(newValue)
+                        SummonAssistant.Saved.ShowAssistants[301] = newValue
+                        SummonAssistant:RestorePanel()
+                    end
+                }
+            }
         }
-      }
-		}
-	}
-	LAM2:RegisterOptionControls(SummonAssistant.name, optionsData)
-end
-
-function SummonAssistant:Initialize()
-  -- Load saved values..
-	SummonAssistant.savedVariables = ZO_SavedVars:New("SummonAssistant_Character", ADDON_VERSION, nil, SummonAssistant.Default)
-  if SummonAssistant.savedVariables.useAccountSettings then
-    SummonAssistant.savedVariables = ZO_SavedVars:NewAccountWide("SummonAssistant_Account", ADDON_VERSION, nil, SummonAssistant.Default)
-  end
-  SummonAssistant.RestorePanel()
-  -- Create Hotkey selections for assistants.
-  SummonAssistant.createHotkeySelections()
-  -- Create menu variables.
-  -- ToDo - Merge the following with with setButtonFrameWidth && initializeButtons && saRestorePosition
-  SummonAssistant.CreateSettingsWindow()
-  SA_FrameBackdrop:SetCenterColor(unpack(SummonAssistant.savedVariables.centerColor))
-  SA_FrameBackdrop:SetEdgeColor(unpack(SummonAssistant.savedVariables.edgeColor))
-  -- ToDo - End.
-  EVENT_MANAGER:UnregisterForEvent(SummonAssistant.name, EVENT_ADD_ON_LOADED)
-end
-
--- Then we create an event handler function which will be called when the "addon loaded" event
--- occurs. We'll use this to initialize our addon after all of its resources are fully loaded.
-function SummonAssistant.OnAddOnLoaded(event, addonName)
-  -- The event fires each time *any* addon loads - but we only care about when our own addon loads.
-  if addonName == SummonAssistant.name then
-    SummonAssistant:Initialize()
-  end
+    }
+    LAM2:RegisterOptionControls(ADDON_NAME, optionsData)
 end

--- Load Event
--- We unregistered this at the end of the loadCC function for optimization.
--- Here we register it (after all the functions).
--- EVENT_MANAGER:RegisterForEvent(SummonAssistant.name, EVENT_ADD_ON_LOADED, SummonAssistant.saLoad)
-EVENT_MANAGER:RegisterForEvent(SummonAssistant.name, EVENT_ADD_ON_LOADED, SummonAssistant.OnAddOnLoaded)
--- EVENT_MANAGER:RegisterForEvent("SummonAssistant Click", EVENT_GLOBAL_MOUSE_DOWN, SummonAssistant.saClicked) -- Edit by Mitsarugi, addon wont work without this line of code
\ No newline at end of file
+EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED, SummonAssistant.OnAddOnLoaded)
\ No newline at end of file
diff --git a/SummonAssistant.xml b/SummonAssistant.xml
index afb2a21..6691c2a 100644
--- a/SummonAssistant.xml
+++ b/SummonAssistant.xml
@@ -1,11 +1,8 @@
 <GuiXml>
 	<Controls>
-    <TopLevelControl name="SA_Frame" clampedToScreen="true" movable="true" mouseEnabled="true">
+    <TopLevelControl name="SummonAssistant_Frame" clampedToScreen="true" movable="true" mouseEnabled="true">
       <Anchor point="CENTER" relativePoint="CENTER" relativeTo="GuiRoot"/>
       <Dimensions x="180" y="60"/>
-      <OnMoveStop>
-        SummonAssistant_OnMoveStop()
-      </OnMoveStop>
       <Controls>
         <Backdrop name="$(parent)Backdrop" alpha="1">
           <Anchor point="TOPLEFT" relativePoint="TOPLEFT" relativeTo="$(parent)" />
@@ -14,7 +11,7 @@
         </Backdrop>
       </Controls>
     </TopLevelControl>
-    <Button name="SA_Button" relativeTo="$(parent)" virtual="true">
+    <Button name="SummonAssistant_Button" relativeTo="$(parent)" virtual="true">
       <Dimensions x="40" y="40"/>
       <Controls>
         <Texture name="$(parent)Texture">