Version 1.5.0 (20-01-2018)

Jarth [01-20-18 - 10:07]
Version 1.5.0 (20-01-2018)
Filename
Bindings.xml
Changelog
MementoBar.lua
MementoBar.txt
MementoBar.xml
MementoBar_Buttons.lua
MementoBar_Constants.lua
MementoBar_Fragments.lua
MementoBar_Hotkeys.lua
MementoBar_Menu.lua
MementoBar_Move.lua
diff --git a/Bindings.xml b/Bindings.xml
new file mode 100644
index 0000000..40765d5
--- /dev/null
+++ b/Bindings.xml
@@ -0,0 +1,11 @@
+<Bindings>
+  <Layer name="SI_KEYBINDINGS_LAYER_GENERAL">
+    <Category name="Memento bar">
+	    <Action name="MementoBar_1"><Down>MementoBar_KeyBindingPressed(1)</Down></Action>
+      <Action name="MementoBar_2"><Down>MementoBar_KeyBindingPressed(2)</Down></Action>
+      <Action name="MementoBar_3"><Down>MementoBar_KeyBindingPressed(3)</Down></Action>
+      <Action name="MementoBar_4"><Down>MementoBar_KeyBindingPressed(4)</Down></Action>
+      <Action name="MementoBar_5"><Down>MementoBar_KeyBindingPressed(5)</Down></Action>
+    </Category>
+  </Layer>
+</Bindings>
\ No newline at end of file
diff --git a/Changelog b/Changelog
index 7f75203..441291c 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,21 @@
 -------------------------------------------------------------------------------
 Memento bar
 -------------------------------------------------------------------------------
+Version 1.5.0 (20-01-2018)
+- Added functionality: Unlock the bar (the bar is by default locked)
+-- An overlay will appear on the bar, showing the size and position (X,Y top left).
+-- The bar is movable by dragging the overlay.
+- Restructured:
+-- Segmented into multiple files.
+-- Split visual from frame to button.
+-- Edge is now shown on the button and not the frame.
+-- Added hover effects on button (Sound and visual).
+- Restructured:
+-- Option to show the keybinding for each button.
+-- Font color affects keybinding label.
+-- Change location of keybinding label.
+INFO: After updating a keybinding, /reloadui or flip a setting in either: Orientation, Visibility or Position and Size.
+
 Version 1.0.0 (07-01-2017)
 (Breaking changes to the saved settings)
 - Added setting to show X,Y coordinates when the bar is moved
diff --git a/MementoBar.lua b/MementoBar.lua
index 8e5d8ab..6989d1a 100644
--- a/MementoBar.lua
+++ b/MementoBar.lua
@@ -4,197 +4,61 @@ Filename: MementoBar.lua
 ]] --

 -------------------------------------------------------------------------------------------------
---  Libraries --
+-- VARIABLES --
 -------------------------------------------------------------------------------------------------
-local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0")
-
--------------------------------------------------------------------------------------------------
---  VARIABLE --
--------------------------------------------------------------------------------------------------
-local ADDON_NAME = "MementoBar"
-local ADDON_VERSION = 1.0
-local ADDON_MINOR_VERSION = 0
-local ADDON_AUTHOR = "Jarth"
-local ADDON_WEBSITE = ""
-local MementoBar = {}
-MementoBar.wm = GetWindowManager()
-MementoBar.Name = ADDON_NAME
-MementoBar.Buttons = {}
-MementoBar.Fragment = nil
-MementoBar.Mementos = {}
-MementoBar.MementosOrdered = {}
-MementoBar.Default = {
-    Left = CENTER,
-    Top = CENTER,
-    CenterColor = {r = 0.88, g = 0.88, b = 0.88, a = 0.4}, -- {red, green, blue, alpha}
-    EdgeColor = {r = 0.57, g = 0.57, b = 0.57, a = 0.6}, -- {red, green, blue, alpha}
-    SelectedMementos = {},
-    UseAccountSettings = true,
-    Horizontal = true,
-    BarDepth = 1,
-    HideBarInMenu = true,
-    ShowMoveAssitance = false
-}
-MementoBar.CountDown = {
-    Event = "Cooldown",
-    Tick = 100,
-    StartTime = 0,
-    CollectibleId = nil
-}
-MementoBar.Global = {
-    LblOffset = 10,
-    LblHeight = 60,
-    LblWidth = 60
-}
+local MementoBar = MementoBar

 -------------------------------------------------------------------------------------------------
 --  FUNCTIONS --
 -------------------------------------------------------------------------------------------------

 function MementoBar.OnAddOnLoaded(_, addonName)
-    if addonName == MementoBar.Name then
+    if addonName == MementoBar.Addon.Name then
         MementoBar:Initialize()
     end
 end

 function MementoBar:Initialize()
     -- Load saved values..
-    MementoBar.Saved = ZO_SavedVars:New("MementoBar_Character", ADDON_VERSION, nil, MementoBar.Default)
+    MementoBar.Saved = ZO_SavedVars:New("MementoBar_Character", MementoBar.Addon.Version, nil, MementoBar.Default)
     if MementoBar.Saved.UseAccountSettings then
-        MementoBar.Saved = ZO_SavedVars:NewAccountWide("MementoBar_Account", ADDON_VERSION, nil, MementoBar.Default)
+        MementoBar.Saved = ZO_SavedVars:NewAccountWide("MementoBar_Account", MementoBar.Addon.Version, nil, MementoBar.Default)
     end

     MementoBar_Frame:SetHandler("OnMoveStop", MementoBar.OnMoveStop)

-    -- Create menu variables.
-    MementoBar:CreateSettingsWindow()
-    MementoBar:FrameBackdropColor()
-    -- Must be run after :CreateSettingsWindow, as it populates the data
     MementoBar:RestorePanel()
-
-    EVENT_MANAGER:UnregisterForEvent(MementoBar.Name, EVENT_ADD_ON_LOADED)
-end
-
-function MementoBar.OnMoveStop()
-    MementoBar.Saved.Top = MementoBar_Frame:GetTop()
-    MementoBar.Saved.Left = MementoBar_Frame:GetLeft()
+    MementoBar:HoykeyCreateSelections()
+    MementoBar:CreateSettingsWindow()
+
+    EVENT_MANAGER:UnregisterForEvent(MementoBar.Addon.Name, EVENT_ADD_ON_LOADED)
 end

 -------------------------------------------------------------------------------------------------
 --  PRIVATE FUNCTIONS --
 -------------------------------------------------------------------------------------------------

-function MementoBar:OnClicked(collectibleId)
-    if collectibleId > 0 and IsCollectibleUnlocked(collectibleId) then
-        local cooldownRemaining, cooldownDuration = GetCollectibleCooldownAndDuration(collectibleId)
-        if cooldownRemaining == 0 then
-            MementoBar:Activate(collectibleId)
-        end
-    end
-end
-
-function MementoBar:InitializeButtons()
-    local index = 1
-    for _, _value in ipairs(MementoBar.MementosOrdered) do
-        local collectibleId = _value.CollectibleId
-        local key = _value.Name
-        local left, top = MementoBar:GetButtonPosition(index)
-        if MementoBar.Saved.SelectedMementos[collectibleId] and IsCollectibleUnlocked(collectibleId) then
-            if MementoBar.Buttons[collectibleId] == nil then
-                MementoBar.Buttons[collectibleId] = WINDOW_MANAGER:CreateControlFromVirtual("MementoBar_Button", MementoBar_FrameBackdrop, "MementoBar_Button", collectibleId)
-                MementoBar.Buttons[collectibleId]:SetId(collectibleId)
-            end
-            MementoBar:SetupButton(collectibleId, MementoBar.Buttons[collectibleId])
-            MementoBar.Buttons[collectibleId]:ClearAnchors()
-            MementoBar.Buttons[collectibleId]:SetAnchor(TOPLEFT, MementoBar_FrameBackdrop, TOPLEFT, left, top)
-            MementoBar.Buttons[collectibleId]:SetHidden(false)
-            index = index + 1
-        elseif MementoBar.Buttons[collectibleId] ~= nil then
-            MementoBar.Buttons[collectibleId]:SetHidden(true)
-        end
-    end
-end
-
-function MementoBar:GetButtonPosition(index)
-    local left = MementoBar.Global.LblOffset + MementoBar.Global.LblWidth * ((index - 1) % MementoBar.Saved.BarDepth)
-    local top = MementoBar.Global.LblOffset + MementoBar.Global.LblHeight * (math.floor((index - 1) / MementoBar.Saved.BarDepth))
-    if MementoBar.Saved.Horizontal then
-        left = MementoBar.Global.LblOffset + MementoBar.Global.LblHeight * (math.floor((index - 1) / MementoBar.Saved.BarDepth))
-        top = MementoBar.Global.LblOffset + MementoBar.Global.LblWidth * ((index - 1) % MementoBar.Saved.BarDepth)
-    end
-    return left, top
-end
-
-function MementoBar:SetFragmentBehaviour(menuOpen)
-    if MementoBar.Fragment == nil then
-        MementoBar.Fragment = ZO_HUDFadeSceneFragment:New(MementoBar_Frame)
-    end
-
-    if MementoBar.Saved.HideBarInMenu then
-        MementoBar:AddControlToFrame(menuOpen)
-    else
-        MementoBar:RemoveControlToFrame(menuOpen)
-    end
-end
-
-function MementoBar:AddControlToFrame(menuOpen)
-    if menuOpen then
-        MementoBar_Frame:SetHidden(true)
+function MementoBar:GetVersion(showMinor)
+    if showMinor == false or ADDON_MINOR_VERSION == nil then
+        return tostring(MementoBar.Addon.Version)
     end
-    SCENE_MANAGER:GetScene("hud"):AddFragment(MementoBar.Fragment)
-    SCENE_MANAGER:GetScene("hudui"):AddFragment(MementoBar.Fragment)
+    return tostring(MementoBar.Addon.Version) .. "." .. tostring(MementoBar.Addon.MinorVersion)
 end

-function MementoBar:RemoveControlToFrame(menuOpen)
-    if menuOpen then
-        MementoBar_Frame:SetHidden(false)
-    end
-
-    SCENE_MANAGER:GetScene("hud"):RemoveFragment(MementoBar.Fragment)
-    SCENE_MANAGER:GetScene("hudui"):RemoveFragment(MementoBar.Fragment)
-end
+function MementoBar:RestorePanel()
+    MementoBar:SetFragmentBehaviour()

-function MementoBar:SetButtonFrameWidth()
-    local mbCount = 0
+    MementoBar:SetButtonFrameWidth()

-    for _ in pairs(MementoBar.Saved.SelectedMementos) do
-        mbCount = mbCount + 1
-    end
+    MementoBar:HotkeyUpdate()

-    local mbDepth = math.ceil(mbCount / MementoBar.Saved.BarDepth)
-    local mbHeight = MementoBar.Global.LblHeight * (MementoBar.Saved.Horizontal and MementoBar.Saved.BarDepth or mbDepth)
-    local mbWidth = MementoBar.Global.LblWidth * (MementoBar.Saved.Horizontal and mbDepth or MementoBar.Saved.BarDepth)
+    MementoBar:InitializeButtons()

-    MementoBar_Frame:SetHidden(mbCount == 0)
-    MementoBar_FrameBackdrop:SetHidden(mbCount == 0)
-    MementoBar_Frame:SetHeight(mbHeight)
-    MementoBar_FrameBackdrop:SetHeight(mbHeight)
-    MementoBar_Frame:SetWidth(mbWidth)
-    MementoBar_FrameBackdrop:SetWidth(mbWidth)
-end
+    MementoBar:ButtonsBackdropColor()

-function MementoBar:FrameBackdropColor(centerColor, edgeColor)
-    if not centerColor then
-        centerColor = MementoBar.Saved.CenterColor
-    end
-    if not edgeColor then
-        edgeColor = MementoBar.Saved.EdgeColor
-    end
-    MementoBar_FrameBackdrop:SetCenterColor(centerColor.r, centerColor.g, centerColor.b, centerColor.a)
-    MementoBar_FrameBackdrop:SetEdgeColor(edgeColor.r, edgeColor.g, edgeColor.b, edgeColor.a)
-end
+    MementoBar:RestorePosition()

-function MementoBar:SetupButton(collectibleId, Buttons)
-    local MementoBar_ButtonTexture = MementoBar.wm:GetControlByName("MementoBar_Button" .. collectibleId .. "Texture")
-    if MementoBar_ButtonTexture and MementoBar.Mementos[collectibleId].CollectibleIcon then
-        MementoBar_ButtonTexture:SetTexture(MementoBar.Mementos[collectibleId].CollectibleIcon)
-        Buttons:SetHandler(
-            "OnClicked",
-            function(self)
-                MementoBar:OnClicked(Buttons:GetId())
-            end
-        )
-    end
+    MementoBar:UpdateMoveFrame()
 end

 function MementoBar:RestorePosition()
@@ -204,317 +68,4 @@ function MementoBar:RestorePosition()
     MementoBar_Frame:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, Left, Top)
 end

-function MementoBar:RestorePanel()
-    MementoBar:SetFragmentBehaviour()
-
-    MementoBar:SetButtonFrameWidth()
-
-    MementoBar:FrameBackdropColor()
-
-    MementoBar:InitializeButtons()
-
-    MementoBar:RestorePosition()
-
-    MementoBar:ActivateMoveHandlers()
-end
-
-function MementoBar: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
-
-function MementoBar:Activate(collectibleId)
-    if collectibleId and IsCollectibleUsable(collectibleId) then
-        MementoBar.CountDown.StartTime = GetTimeStamp()
-        MementoBar.CountDown.CollectibleId = collectibleId
-        EVENT_MANAGER:UnregisterForUpdate(MementoBar.Name .. MementoBar.CountDown.Event)
-        UseCollectible(collectibleId)
-        EVENT_MANAGER:RegisterForUpdate(MementoBar.Name .. MementoBar.CountDown.Event, MementoBar.CountDown.Tick, MementoBar.Update)
-    end
-end
-
-function MementoBar.Update()
-    local cooldownRemaining, cooldownDuration = GetCollectibleCooldownAndDuration(MementoBar.CountDown.CollectibleId)
-    if cooldownRemaining > 0 then
-        MementoBar:UpdateLabel(cooldownRemaining)
-    elseif (cooldownDuration > 0 and (GetTimeStamp() < (MementoBar.CountDown.StartTime + math.floor(cooldownDuration / 1000)))) then
-        --Should not be relevant, it should always have a cooldown remaining and duration.
-        MementoBar:UpdateLabel(cooldownDuration)
-    else
-        MementoBar:UpdateLabel("")
-        EVENT_MANAGER:UnregisterForUpdate(MementoBar.Name .. MementoBar.CountDown.Event)
-    end
-end
-
-function MementoBar:UpdateLabel(remaining)
-    if type(remaining) == "number" and remaining > 0 then
-        remaining = string.format("%.1fs", (math.floor(remaining / 100) / 10))
-    end
-    for collectibleId in pairs(MementoBar.Saved.SelectedMementos) do
-        local MementoBar_ButtonTimer = MementoBar.wm:GetControlByName("MementoBar_Button" .. collectibleId .. "Timer")
-        if MementoBar_ButtonTimer and MementoBar.Mementos[collectibleId] then
-            MementoBar_ButtonTimer:SetText(remaining)
-        end
-    end
-end
-
-function MementoBar:ActivateMoveHandlers()
-    if not MementoBar_Frame.LabelTopLeft and MementoBar.Saved.ShowMoveAssitance then
-        MementoBar_Frame.LabelTopLeft = MementoBar.wm:CreateControl(nil, MementoBar_Frame, CT_LABEL)
-        MementoBar_Frame.LabelTopLeft:SetDrawLevel(3)
-        MementoBar_Frame.LabelTopLeft:SetAnchorFill(MementoBar_Frame)
-        MementoBar_Frame.LabelTopLeft:SetFont("ZoFontWinH5")
-        MementoBar_Frame.LabelTopLeft:SetHorizontalAlignment(0)
-        MementoBar_Frame.LabelTopLeft:SetVerticalAlignment(0)
-        MementoBar_Frame["UpdateText"] = MementoBar.UpdateText
-        MementoBar_Frame:SetHandler("OnMouseEnter", MementoBar.OnMouseEnter)
-        MementoBar_Frame:SetHandler("OnMouseDown", MementoBar.OnMouseDown)
-        MementoBar_Frame:SetHandler("OnMouseUp", MementoBar.OnMouseUp)
-        MementoBar_Frame:SetHandler("OnMouseExit", MementoBar.OnMouseExit)
-    elseif MementoBar_Frame.LabelTopLeft and not MementoBar.Saved.ShowMoveAssitance then
-        MementoBar_Frame.LabelTopLeft = nil
-        MementoBar_Frame["UpdateText"] = nil
-        MementoBar_Frame:SetHandler("OnMouseEnter", nil)
-        MementoBar_Frame:SetHandler("OnMouseDown", nil)
-        MementoBar_Frame:SetHandler("OnMouseUp", nil)
-        MementoBar_Frame:SetHandler("OnMouseExit", nil)
-    end
-end
-
--------------------------------------------------------------------------------------------------
--- FUNCTIONS --
--- Move handlers --
--------------------------------------------------------------------------------------------------
-
-function MementoBar.OnMouseEnter(frame)
-    frame.UpdateText(frame, true)
-end
-
-function MementoBar.OnMouseDown(frame)
-    frame:SetHandler("OnUpdate", MementoBar.OnMouseEnter)
-end
-
-function MementoBar.OnMouseExit(frame)
-    frame.UpdateText(frame, false)
-end
-
-function MementoBar.OnMouseUp(frame)
-    frame:SetHandler("OnUpdate", nil)
-end
-
-function MementoBar.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 MementoBar:CreateSettingsWindow()
-    local mementTopLevelIndex = 7
-    local catName, catNumSubCat, catNumCollectibles, catNumUnlocked, catTotal, catHidesLocked = GetCollectibleCategoryInfo(mementTopLevelIndex)
-
-    local panelData = {
-        type = "panel",
-        name = "Memento Bar",
-        displayName = "Memento Bar",
-        author = ADDON_AUTHOR,
-        version = MementoBar:GetVersion(true),
-        slashCommand = "/mb",
-        registerForRefresh = true,
-        registerForDefaults = true
-    }
-    local cntrlOptionsPanel = LAM2:RegisterAddonPanel(ADDON_NAME, panelData)
-
-    local optionsData = {
-        [1] = {
-            type = "header",
-            name = "Memento Bar Settings"
-        },
-        [2] = {
-            type = "description",
-            text = "Here you can adjust the memento bar settings. Including what icons to show, and color of the bar."
-        },
-        [3] = {
-            type = "checkbox",
-            name = "Use account settings",
-            tooltip = "When ON the account settings will be used. When OFF character settings will be used.",
-            default = MementoBar.Default.UseAccountSettings,
-            getFunc = function()
-                return MementoBar.Saved.UseAccountSettings
-            end,
-            setFunc = function(newValue)
-                --Apply value to existing variable
-                MementoBar.Saved.UseAccountSettings = newValue
-                if newValue then
-                    MementoBar.Saved = ZO_SavedVars:NewAccountWide("MementoBar_Account", ADDON_VERSION, nil, MementoBar.Default)
-                else
-                    MementoBar.Saved = ZO_SavedVars:New("MementoBar_Character", ADDON_VERSION, nil, MementoBar.Default)
-                end
-                --Apply value to new variable
-                MementoBar.Saved.UseAccountSettings = newValue
-                MementoBar:RestorePanel()
-            end
-        },
-        [4] = {
-            type = "checkbox",
-            name = "Bar orientation horizontal",
-            tooltip = "When ON the bar will orientate horizontally.",
-            default = MementoBar.Default.Horizontal,
-            getFunc = function()
-                return MementoBar.Saved.Horizontal
-            end,
-            setFunc = function(newValue)
-                MementoBar.Saved.Horizontal = newValue
-                MementoBar:RestorePanel()
-            end
-        },
-        [5] = {
-            type = "checkbox",
-            name = "Hide bar in menu",
-            tooltip = "When ON the bar will hide when a menu is opened.",
-            default = MementoBar.Default.HideBarInMenu,
-            getFunc = function()
-                return MementoBar.Saved.HideBarInMenu
-            end,
-            setFunc = function(newValue)
-                MementoBar.Saved.HideBarInMenu = newValue
-                MementoBar: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 MementoBar.Default.ShowMoveAssitance
-            end,
-            getFunc = function()
-                return MementoBar.Saved.ShowMoveAssitance
-            end,
-            setFunc = function(newValue)
-                MementoBar.Saved.ShowMoveAssitance = newValue
-                MementoBar: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 MementoBar.Default.CenterColor
-                    end,
-                    tooltip = "Changes the color of the background.",
-                    getFunc = function()
-                        return MementoBar.Saved.CenterColor.r, MementoBar.Saved.CenterColor.g, MementoBar.Saved.CenterColor.b, MementoBar.Saved.CenterColor.a
-                    end,
-                    setFunc = function(r, g, b, a)
-                        MementoBar.Saved.CenterColor = {r = r, g = g, b = b, a = a}
-                        MementoBar:RestorePanel()
-                    end,
-                    width = "half"
-                },
-                [3] = {
-                    type = "colorpicker",
-                    name = "Frame Color",
-                    default = function()
-                        return MementoBar.Default.EdgeColor
-                    end,
-                    tooltip = "Changes the color of the frame.",
-                    getFunc = function()
-                        return MementoBar.Saved.EdgeColor.r, MementoBar.Saved.EdgeColor.g, MementoBar.Saved.EdgeColor.b, MementoBar.Saved.EdgeColor.a
-                    end,
-                    setFunc = function(r, g, b, a)
-                        MementoBar.Saved.EdgeColor = {r = r, g = g, b = b, a = a}
-                        MementoBar:RestorePanel()
-                    end,
-                    width = "half"
-                }
-            }
-        },
-        [8] = {
-            type = "submenu",
-            name = catName .. " (Total: " .. catTotal .. " Unlocked: " .. catNumUnlocked .. ")",
-            tooltip = "Choose what memento's you want on the bar.",
-            controls = {
-                [1] = {
-                    type = "slider",
-                    name = "Choose bar depth (number of rows/columns)", -- or string id or function returning a string
-                    default = MementoBar.Default.BarDepth,
-                    getFunc = function()
-                        return MementoBar.Saved.BarDepth
-                    end,
-                    setFunc = function(value)
-                        MementoBar.Saved.BarDepth = value
-                        MementoBar:RestorePanel()
-                    end,
-                    min = 1,
-                    max = catNumUnlocked
-                },
-                [2] = {
-                    type = "description",
-                    text = "Choose what memento's you want enabled."
-                }
-            }
-        }
-    }
-
-    for i = 1, catTotal do
-        local index = i + 1
-        local collectibleId = GetCollectibleId(mementTopLevelIndex, nil, i)
-        local collectibleName, collectibleDescription, collectibleIcon, collectibleLockedIcon, collectibleUnlocked, _, _, _, collectibleHint, _ = GetCollectibleInfo(collectibleId)
-        MementoBar.Mementos[collectibleId] = {
-            CollectibleId = collectibleId,
-            CollectibleIcon = collectibleIcon
-        }
-        MementoBar.MementosOrdered[i] = MementoBar.Mementos[collectibleId]
-
-        local line = {
-            type = "checkbox",
-            name = "Show " .. collectibleName,
-            tooltip = string.format("Description: %s \nHint: %s", collectibleDescription, collectibleHint),
-            --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 = false,
-            disabled = not collectibleUnlocked,
-            getFunc = function()
-                if not MementoBar.Saved.SelectedMementos[collectibleId] then
-                    return false
-                else
-                    return true
-                end
-            end,
-            setFunc = function(newValue)
-                if newValue == true then
-                    MementoBar.Saved.SelectedMementos[collectibleId] = collectibleId
-                else
-                    MementoBar.Saved.SelectedMementos[collectibleId] = nil
-                end
-
-                MementoBar:RestorePanel()
-            end
-        }
-        table.insert(optionsData[8].controls, index, line)
-    end
-
-    LAM2:RegisterOptionControls(ADDON_NAME, optionsData)
-end
-
--------------------------------------------------------------------------------------------------
---  Initialize Functions --
--------------------------------------------------------------------------------------------------
-
-EVENT_MANAGER:RegisterForEvent(MementoBar.Name, EVENT_ADD_ON_LOADED, MementoBar.OnAddOnLoaded)
+EVENT_MANAGER:RegisterForEvent(MementoBar.Addon.Name, EVENT_ADD_ON_LOADED, MementoBar.OnAddOnLoaded)
diff --git a/MementoBar.txt b/MementoBar.txt
index 7b0984d..250b6a3 100644
--- a/MementoBar.txt
+++ b/MementoBar.txt
@@ -4,9 +4,9 @@
 ; States and/or other countries. All rights reserved.
 ; You can read the full terms at https://account.elderscrollsonline.com/add-on-terms

-## APIVersion: 100021
+## APIVersion: 100021 100022
 ## Title: Memento Bar
-## Version: 1.0.0
+## Version: 1.5.0
 ## Author: Jarth
 ## Description: Show a hotbar with selected memento's. Activate by button press!
 ##
@@ -36,5 +36,12 @@ libs\LibAddonMenu-2.0\controls\texture.lua
 libs\LibAddonMenu-2.0\controls\iconpicker.lua
 libs\LibAddonMenu-2.0\controls\divider.lua

+MementoBar_Constants.lua
+MementoBar_Fragments.lua
+MementoBar_Hotkeys.lua
+MementoBar_Menu.lua
+MementoBar_Move.lua
+MementoBar_Buttons.lua
 MementoBar.lua
-MementoBar.xml
\ No newline at end of file
+MementoBar.xml
+Bindings.xml
\ No newline at end of file
diff --git a/MementoBar.xml b/MementoBar.xml
index 35b4ae2..595bafc 100644
--- a/MementoBar.xml
+++ b/MementoBar.xml
@@ -1,27 +1,21 @@
 <GuiXml>
 	<Controls>
-    <TopLevelControl name="MementoBar_Frame" clampedToScreen="true" movable="true" mouseEnabled="true">
+    <TopLevelControl name="MementoBar_Frame" clampedToScreen="true" movable="false" mouseEnabled="true">
       <Anchor point="CENTER" relativePoint="CENTER" relativeTo="GuiRoot"/>
-      <Dimensions x="180" y="60"/>
+    </TopLevelControl>
+    <Button name="MementoBar_Button" relativeTo="$(parent)" virtual="true">
       <Controls>
         <Backdrop name="$(parent)Backdrop" alpha="1">
-          <Anchor point="TOPLEFT" relativePoint="TOPLEFT" relativeTo="$(parent)" />
-          <Dimensions x="180" y="60"/>
-          <Edge edgeSize="1"/>
         </Backdrop>
-      </Controls>
-    </TopLevelControl>
-    <Button name="MementoBar_Button" relativeTo="$(parent)" virtual="true">
-      <Dimensions x="40" y="40"/>
-      <Controls>
-        <Label name="$(parent)Timer" font="ZoFontHeader2">
+        <Label name="$(parent)Timer" font="ZoFontHeader2" alpha="1">
 					<Anchor point="CENTER" relativeTo="$(parent)" relativePoint="CENTER" />
 				</Label>
-        <Texture name="$(parent)Texture">
-          <Anchor point="128"/>
-          <Dimensions x="40" y="40"/>
+        <Label name="$(parent)Binding" font="ZoFontGameSmall" alpha="1">
+				</Label>
+        <Texture name="$(parent)Texture" alpha="1">
         </Texture>
       </Controls>
     </Button>
-  </Controls>
+		<TopLevelControl name="MementoBar_MoveFrame" virtual="true" />
+  </Controls>
 </GuiXml>
\ No newline at end of file
diff --git a/MementoBar_Buttons.lua b/MementoBar_Buttons.lua
new file mode 100644
index 0000000..1e1b3a5
--- /dev/null
+++ b/MementoBar_Buttons.lua
@@ -0,0 +1,199 @@
+--[[
+Author: Jarth
+Filename: MementoBar_Buttons.lua
+]] --
+
+-------------------------------------------------------------------------------------------------
+-- VARIABLES --
+-------------------------------------------------------------------------------------------------
+local MementoBar = MementoBar
+
+-------------------------------------------------------------------------------------------------
+-- FUNCTIONS --
+-- Button highlight --
+-------------------------------------------------------------------------------------------------
+function MementoBar.ButtonHighlightEnter(frame)
+    local highlightColor = MementoBar.Saved.HighlightColor
+    local buttonBackdrop = GetControl(frame, "Backdrop")
+    if buttonBackdrop ~= nil then
+        PlaySound(SOUNDS.QUICKSLOT_MOUSEOVER)
+        buttonBackdrop:SetEdgeColor(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a)
+    end
+end
+
+function MementoBar.ButtonHighlightExit(frame)
+    local edgeColor = MementoBar.Saved.EdgeColor
+    local buttonBackdrop = GetControl(frame, "Backdrop")
+    if buttonBackdrop ~= nil then
+        buttonBackdrop:SetEdgeColor(edgeColor.r, edgeColor.g, edgeColor.b, edgeColor.a)
+    end
+end
+
+function MementoBar.ButtonOnClicked(button)
+    local id = button:GetId()
+    if id > 0 then
+        local cooldownRemaining, cooldownDuration = GetCollectibleCooldownAndDuration(id)
+        if cooldownRemaining == 0 then
+            MementoBar:Activate(id)
+        end
+    end
+end
+
+-------------------------------------------------------------------------------------------------
+-- PRIVATE FUNCTIONS --
+-------------------------------------------------------------------------------------------------
+function MementoBar:SetupButton(button, left, top)
+    button:ClearAnchors()
+    button:SetAnchor(TOPLEFT, MementoBar_Frame, TOPLEFT, left, top)
+    button:SetHeight(MementoBar.Saved.Height)
+    button:SetWidth(MementoBar.Saved.Width)
+    button:SetHidden(false)
+end
+
+function MementoBar:SetupButtonBinding(button, key, left, top)
+    local buttonBinding = GetControl(button, "Binding")
+    if buttonBinding ~= nil then
+        MementoBar:HotkeyUpdateColor(buttonBinding)
+        buttonBinding:SetText(MementoBar:HoykeyGetKey(button, key))
+        buttonBinding:SetDrawLevel(3)
+        buttonBinding:ClearAnchors()
+        buttonBinding:SetAnchor(MementoBar.Saved.KeyBindingLocation, button, MementoBar.Saved.KeyBindingLocation, 0, 0)
+    end
+    if buttonBinding ~= nil then
+        buttonBinding:SetHidden(not MementoBar.Saved.ShowKeyBinding)
+    end
+end
+
+function MementoBar:SetupButtonTexture(button, key, left, top)
+    local buttonTexture = GetControl(button, "Texture")
+    if buttonTexture ~= nil then
+        button:SetHandler("OnClicked", MementoBar.ButtonOnClicked)
+        buttonTexture:SetDrawLevel(3)
+        buttonTexture:SetTexture(MementoBar.Mementos[key].EnabledTexture)
+        buttonTexture:ClearAnchors()
+        buttonTexture:SetAnchor(TOPLEFT, button, TOPLEFT, MementoBar.Saved.Margin, MementoBar.Saved.Margin)
+        buttonTexture:SetHeight(button:GetHeight() - (2 * MementoBar.Saved.Margin))
+        buttonTexture:SetWidth(button:GetWidth() - (2 * MementoBar.Saved.Margin))
+    end
+end
+
+function MementoBar:SetupButtonBackdrop(button, key, left, top)
+    local buttonBackdrop = GetControl(button, "Backdrop")
+    if buttonBackdrop ~= nil then
+        buttonBackdrop:SetDrawLevel(2)
+        buttonBackdrop:SetEdgeTexture(nil, 1, 1, MementoBar.Saved.Margin)
+        buttonBackdrop:ClearAnchors()
+        buttonBackdrop:SetAnchor(TOPLEFT, MementoBar_Frame, TOPLEFT, left, top)
+        buttonBackdrop:SetHeight(button:GetHeight())
+        buttonBackdrop:SetWidth(button:GetWidth())
+    end
+end
+
+function MementoBar:SetButtonFrameWidth()
+    local count, depth, height, width = 0, 0, 0, 0
+
+    for key, value in pairs(MementoBar.Saved.SelectedMementos) do
+        if IsCollectibleUnlocked(key) and MementoBar.Saved.SelectedMementos[key] then
+            count = count + 1
+        end
+    end
+
+    if count > 0 then
+        depth = math.ceil(count / MementoBar.Saved.BarDepth)
+        height = MementoBar.Saved.Height * (MementoBar.Saved.Horizontal and MementoBar.Saved.BarDepth or depth)
+        width = MementoBar.Saved.Width * (MementoBar.Saved.Horizontal and depth or MementoBar.Saved.BarDepth)
+    end
+
+    MementoBar:SetFrameSettings(MementoBar_Frame, count == 0, height, width)
+    MementoBar:SetFrameSettings(MementoBar_FrameBackdrop, count == 0, height, width)
+end
+
+function MementoBar:SetFrameSettings(frame, isHidden, height, width)
+    if frame ~= nil then
+        frame:SetHidden(count == 0)
+        frame:SetHeight(height)
+        frame:SetWidth(width)
+    end
+end
+
+function MementoBar:InitializeButtons()
+    local index = 1
+    for _, _value in ipairs(MementoBar.OrderedMementos) do
+        local id = _value.Id
+        local left, top = MementoBar:GetButtonPosition(index)
+        if MementoBar.Saved.SelectedMementos[id] and IsCollectibleUnlocked(id) then
+            if MementoBar.Buttons[id] == nil then
+                MementoBar.Buttons[id] = WINDOW_MANAGER:CreateControlFromVirtual("MementoBar_Button", MementoBar_Frame, "MementoBar_Button", id)
+                MementoBar.Buttons[id]:SetId(id)
+            end
+            MementoBar:SetupButton(MementoBar.Buttons[id], left, top)
+            MementoBar:SetupButtonBinding(MementoBar.Buttons[id], id, left, top)
+            MementoBar:SetupButtonBackdrop(MementoBar.Buttons[id], id, left, top)
+            MementoBar:SetupButtonTexture(MementoBar.Buttons[id], id, left, top)
+            MementoBar.Buttons[id]:SetHandler("OnMouseEnter", MementoBar.ButtonHighlightEnter)
+            MementoBar.Buttons[id]:SetHandler("OnMouseExit", MementoBar.ButtonHighlightExit)
+            index = index + 1
+        elseif MementoBar.Buttons[id] ~= nil then
+            MementoBar.Buttons[id]:SetHidden(true)
+        end
+    end
+end
+
+function MementoBar:GetButtonPosition(index)
+    local left = MementoBar.Saved.Width * ((index - 1) % MementoBar.Saved.BarDepth)
+    local top = MementoBar.Saved.Height * (math.floor((index - 1) / MementoBar.Saved.BarDepth))
+    if MementoBar.Saved.Horizontal then
+        left = MementoBar.Saved.Height * (math.floor((index - 1) / MementoBar.Saved.BarDepth))
+        top = MementoBar.Saved.Width * ((index - 1) % MementoBar.Saved.BarDepth)
+    end
+    return left, top
+end
+
+function MementoBar:ButtonsBackdropColor()
+    local centerColor = MementoBar.Saved.CenterColor
+    local edgeColor = MementoBar.Saved.EdgeColor
+
+    for _, _value in ipairs(MementoBar.OrderedMementos) do
+        if MementoBar.Buttons[_value.Id] ~= nil then
+            local buttonBackdrop = GetControl(MementoBar.Buttons[_value.Id], "Backdrop")
+            if buttonBackdrop ~= nil then
+                buttonBackdrop:SetCenterColor(centerColor.r, centerColor.g, centerColor.b, centerColor.a)
+                buttonBackdrop:SetEdgeColor(edgeColor.r, edgeColor.g, edgeColor.b, edgeColor.a)
+            end
+        end
+    end
+end
+
+function MementoBar:Activate(collectibleId)
+    if collectibleId and IsCollectibleUsable(collectibleId) then
+        MementoBar.CountDown.StartTime = GetTimeStamp()
+        MementoBar.CountDown.CollectibleId = collectibleId
+        EVENT_MANAGER:UnregisterForUpdate(MementoBar.Addon.Name .. MementoBar.CountDown.Event)
+        UseCollectible(collectibleId)
+        EVENT_MANAGER:RegisterForUpdate(MementoBar.Addon.Name .. MementoBar.CountDown.Event, MementoBar.CountDown.Tick, MementoBar.Update)
+    end
+end
+
+function MementoBar.Update()
+    local cooldownRemaining, cooldownDuration = GetCollectibleCooldownAndDuration(MementoBar.CountDown.CollectibleId)
+    if cooldownRemaining > 0 then
+        MementoBar:UpdateLabel(cooldownRemaining)
+    elseif (cooldownDuration > 0 and (GetTimeStamp() < (MementoBar.CountDown.StartTime + math.floor(cooldownDuration / 1000)))) then
+        MementoBar:UpdateLabel(cooldownDuration)
+    else
+        MementoBar:UpdateLabel("")
+        EVENT_MANAGER:UnregisterForUpdate(MementoBar.Addon.Name .. MementoBar.CountDown.Event)
+    end
+end
+
+function MementoBar:UpdateLabel(remaining)
+    if type(remaining) == "number" and remaining > 0 then
+        remaining = string.format("%.1fs", (math.floor(remaining / 100) / 10))
+    end
+    for collectibleId in pairs(MementoBar.Saved.SelectedMementos) do
+        local buttonTimer = GetControl(MementoBar.Buttons[collectibleId], "Timer")
+        if buttonTimer and MementoBar.Mementos[collectibleId] then
+            buttonTimer:SetText(remaining)
+        end
+    end
+end
diff --git a/MementoBar_Constants.lua b/MementoBar_Constants.lua
new file mode 100644
index 0000000..880db7e
--- /dev/null
+++ b/MementoBar_Constants.lua
@@ -0,0 +1,82 @@
+--[[
+Author: Jarth
+Filename: MementoBar_Constants.lua
+]] --
+
+-------------------------------------------------------------------------------------------------
+-- VARIABLES --
+-------------------------------------------------------------------------------------------------
+MementoBar = {}
+
+MementoBar.Addon = {
+    Name = "MementoBar",
+    DisplayName = "Memento bar",
+    Version = 1.5,
+    MinorVersion = 0,
+    SlashCommand = "/mb",
+    Author = "Jarth",
+    Website = ""
+}
+MementoBar.WM = GetWindowManager()
+MementoBar.Buttons = {}
+MementoBar.Fragment = nil
+MementoBar.Default = {
+    Left = CENTER,
+    Top = CENTER,
+    CenterColor = {r = 0.88, g = 0.88, b = 0.88, a = 0.4},
+    EdgeColor = {r = 0.88, g = 0.88, b = 0.88, a = 0},
+    HighlightColor = {r = 0.9, g = 0.9, b = 0.9, a = 0.9},
+    FontColor = {r = 0.9, g = 0.9, b = 0.9, a = 0.9},
+    UseAccountSettings = true,
+    HideBarInMenu = true,
+    Horizontal = true,
+    Margin = 2,
+    Height = 60,
+    Width = 60,
+    SnapSize = 5,
+    BarDepth = 1,
+    SelectedMementos = {},
+    KeyBindings = {
+        [1] = 0,
+        [2] = 0,
+        [3] = 0,
+        [4] = 0,
+        [5] = 0
+    },
+    KeyBindingLocation = BOTTOM,
+    ShowKeyBinding = true
+}
+MementoBar.Mementos = {}
+MementoBar.OrderedMementos = {}
+MementoBar.Global = {
+    IsMoveEnabled = false,
+    TopLevelIndex = 7,
+    ReverseKeyBindings = {},
+    ChoisesKeyBindingLocation = {"bottom","bottomleft","bottomright","center","left","right","top","topleft","topright"}
+}
+
+MementoBar.Global.CategoryName,
+    _,
+    MementoBar.Global.CategoryNumCollectibles,
+    MementoBar.Global.CategoryNumUnlocked,
+    MementoBar.Global.CategoryTotal,
+    _ = GetCollectibleCategoryInfo(MementoBar.Global.TopLevelIndex)
+for index = 1, MementoBar.Global.CategoryTotal do
+    local collectibleId = GetCollectibleId(MementoBar.Global.TopLevelIndex, nil, index)
+    local collectibleName, collectibleDescription, collectibleIcon, _, collectibleUnlocked, _, _, _, collectibleHint, _ = GetCollectibleInfo(collectibleId)
+    MementoBar.Mementos[collectibleId] = {
+        Id = collectibleId,
+        Name = collectibleName,
+        EnabledTexture = collectibleIcon,
+        Disabled = not collectibleUnlocked,
+        Tooltip = string.format("Description: %s \nHint: %s", collectibleDescription, collectibleHint)
+    }
+    MementoBar.OrderedMementos[index] = MementoBar.Mementos[collectibleId]
+end
+
+MementoBar.CountDown = {
+    Event = "Cooldown",
+    Tick = 100,
+    StartTime = 0,
+    CollectibleId = nil
+}
diff --git a/MementoBar_Fragments.lua b/MementoBar_Fragments.lua
new file mode 100644
index 0000000..e52d09e
--- /dev/null
+++ b/MementoBar_Fragments.lua
@@ -0,0 +1,42 @@
+--[[
+Author: Jarth
+Filename: MementoBar_Fragments.lua
+]] --
+
+-------------------------------------------------------------------------------------------------
+-- VARIABLES --
+-------------------------------------------------------------------------------------------------
+local MementoBar = MementoBar
+
+-------------------------------------------------------------------------------------------------
+-- PRIVATE FUNCTIONS --
+-------------------------------------------------------------------------------------------------
+function MementoBar:SetFragmentBehaviour(menuOpen)
+    if MementoBar.Fragment == nil then
+        MementoBar.Fragment = ZO_HUDFadeSceneFragment:New(MementoBar_Frame)
+    end
+
+    if MementoBar.Saved.HideBarInMenu then
+        MementoBar:AddControlToFrame(menuOpen)
+    else
+        MementoBar:RemoveControlToFrame(menuOpen)
+    end
+end
+
+function MementoBar:AddControlToFrame(menuOpen)
+    if menuOpen then
+        MementoBar_Frame:SetHidden(true)
+    end
+
+    SCENE_MANAGER:GetScene("hud"):AddFragment(MementoBar.Fragment)
+    SCENE_MANAGER:GetScene("hudui"):AddFragment(MementoBar.Fragment)
+end
+
+function MementoBar:RemoveControlToFrame(menuOpen)
+    if menuOpen then
+        MementoBar_Frame:SetHidden(false)
+    end
+
+    SCENE_MANAGER:GetScene("hud"):RemoveFragment(MementoBar.Fragment)
+    SCENE_MANAGER:GetScene("hudui"):RemoveFragment(MementoBar.Fragment)
+end
diff --git a/MementoBar_Hotkeys.lua b/MementoBar_Hotkeys.lua
new file mode 100644
index 0000000..510755c
--- /dev/null
+++ b/MementoBar_Hotkeys.lua
@@ -0,0 +1,132 @@
+--[[
+Author: Jarth
+Filename: MementoBar_Hotkeys.lua
+]] --
+
+-------------------------------------------------------------------------------------------------
+-- VARIABLES --
+-------------------------------------------------------------------------------------------------
+local MementoBar = MementoBar
+
+-------------------------------------------------------------------------------------------------
+-- PUBLIC FUNCTIONS --
+-------------------------------------------------------------------------------------------------
+function MementoBar_KeyBindingPressed(keyId)
+    local control = MementoBar.WM:GetMouseOverControl()
+    if control ~= nil then
+        for collectibleId, _ in pairs(MementoBar.Saved.SelectedMementos) do
+            if MementoBar.Buttons[collectibleId] == control then
+                MementoBar:HotkeyUpdate(keyId, collectibleId)
+                MementoBar:InitializeButtons()
+                return
+            end
+        end
+    end
+
+    if MementoBar.Saved.KeyBindings[keyId] > 0 then
+        MementoBar.ButtonOnClicked(MementoBar.Buttons[MementoBar.Saved.KeyBindings[keyId]])
+    end
+end
+
+-------------------------------------------------------------------------------------------------
+-- PRIVATE FUNCTIONS --
+-------------------------------------------------------------------------------------------------
+function MementoBar:HoykeyCreateSelections()
+    for key, value in ipairs(MementoBar.Saved.KeyBindings) do
+        ZO_CreateStringId("SI_BINDING_NAME_MementoBar_" .. key, "MementoBar_" .. key)
+    end
+end
+
+function MementoBar:HotkeyUpdate(newKeyId, newCollectibleId)
+    MementoBar.Global.ReverseKeyBindings = {}
+    for keyId, collectibleId in ipairs(MementoBar.Saved.KeyBindings) do
+        if newCollectibleId and newKeyId == keyId then
+            MementoBar.Saved.KeyBindings[keyId] = newCollectibleId
+            MementoBar.Global.ReverseKeyBindings[newCollectibleId] = keyId
+        elseif newCollectibleId == collectibleId and newKeyId ~= keyId then
+            MementoBar.Saved.KeyBindings[keyId] = 0
+        elseif collectibleId > 0 and not MementoBar.Saved.SelectedMementos[collectibleId] then
+            MementoBar.Saved.KeyBindings[keyId] = 0
+        elseif collectibleId > 0 then
+            MementoBar.Global.ReverseKeyBindings[collectibleId] = keyId
+        end
+    end
+end
+
+function MementoBar:HoykeyGetKey(button, collectibleId)
+    local result = ""
+    local keyId = MementoBar.Global.ReverseKeyBindings[collectibleId]
+    if keyId then
+        local keyBindingTable = {GetHighestPriorityActionBindingInfoFromName("MementoBar_" .. keyId)}
+        for _, keyValue in pairs(keyBindingTable) do
+            if keyValue > 0 then
+                result = MementoBar:HotkeyGetKeyName(result, keyValue)
+            end
+        end
+    end
+    return result
+end
+
+function MementoBar:HotkeyGetKeyName(result, keyValue)
+    if keyValue > 0 then
+        if result ~= "" then
+            result = string.format("%s+%s", result, GetKeyName(keyValue))
+        else
+            result = GetKeyName(keyValue)
+        end
+    end
+    return result
+end
+
+function MementoBar:HotkeyUpdateColor(frame)
+    local fontColor = MementoBar.Saved.FontColor
+    frame:SetColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a)
+end
+
+function MementoBar:HotKeyGetLocationValue(value)
+    local result
+    if value == "bottom" then
+        result = BOTTOM
+    elseif value == "bottomleft" then
+        result = BOTTOMLEFT
+    elseif value == "bottomright" then
+        result = BOTTOMRIGHT
+    elseif value == "center" then
+        result = CENTER
+    elseif value == "left" then
+        result = LEFT
+    elseif value == "right" then
+        result = RIGHT
+    elseif value == "top" then
+        result = TOP
+    elseif value == "topleft" then
+        result = TOPLEFT
+    elseif value == "topright" then
+        result = TOPRIGHT
+    end
+    return result
+end
+
+function MementoBar:HotKeyGetLocationText(value)
+    local result
+    if value == BOTTOM then
+        result = "bottom"
+    elseif value == BOTTOMLEFT then
+        result = "bottomleft"
+    elseif value == BOTTOMRIGHT then
+        result = "bottomright"
+    elseif value == CENTER then
+        result = "center"
+    elseif value == LEFT then
+        result = "left"
+    elseif value == RIGHT then
+        result = "right"
+    elseif value == TOP then
+        result = "top"
+    elseif value == TOPLEFT then
+        result = "topleft"
+    elseif value == TOPRIGHT then
+        result = "topright"
+    end
+    return result
+end
diff --git a/MementoBar_Menu.lua b/MementoBar_Menu.lua
new file mode 100644
index 0000000..3af10f4
--- /dev/null
+++ b/MementoBar_Menu.lua
@@ -0,0 +1,331 @@
+--[[
+Author: Jarth
+Filename: MementoBar_Menu.lua
+]] --
+
+-------------------------------------------------------------------------------------------------
+-- Libraries --
+-------------------------------------------------------------------------------------------------
+local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0")
+
+-------------------------------------------------------------------------------------------------
+-- VARIABLES --
+-------------------------------------------------------------------------------------------------
+local MementoBar = MementoBar
+
+-------------------------------------------------------------------------------------------------
+-- Menu Functions --
+-------------------------------------------------------------------------------------------------
+function MementoBar:CreateSettingsWindow()
+    local panelData = {
+        type = "panel",
+        name = MementoBar.Addon.DisplayName,
+        displayName = MementoBar.Addon.DisplayName,
+        author = MementoBar.Addon.Author,
+        version = MementoBar:GetVersion(true),
+        slashCommand = MementoBar.Addon.SlashCommand,
+        registerForRefresh = true,
+        registerForDefaults = true
+    }
+    local cntrlOptionsPanel = LAM2:RegisterAddonPanel(MementoBar.Addon.Name, panelData)
+    local optionsData = {
+        [1] = {
+            type = "header",
+            name = MementoBar.Addon.DisplayName .. " Settings"
+        },
+        [2] = {
+            type = "description",
+            text = string.format("Here you can adjust the %s works.\nSlash command: %s", MementoBar.Addon.DisplayName, MementoBar.Addon.SlashCommand)
+        },
+        [3] = {
+            type = "checkbox",
+            name = "Use account settings",
+            tooltip = "When ON the account settings will be used. When OFF character settings will be used.",
+            default = MementoBar.Default.UseAccountSettings,
+            getFunc = function()
+                return MementoBar.Saved.UseAccountSettings
+            end,
+            setFunc = function(newValue)
+                MementoBar.Saved.UseAccountSettings = newValue
+                if newValue then
+                    MementoBar.Saved = ZO_SavedVars:NewAccountWide("MementoBar_Account", MementoBar.Addon.Version, nil, MementoBar.Default)
+                else
+                    MementoBar.Saved = ZO_SavedVars:New("MementoBar_Character", MementoBar.Addon.Version, nil, MementoBar.Default)
+                end
+                MementoBar.Saved.UseAccountSettings = newValue
+                MementoBar:RestorePanel()
+            end
+        },
+        [4] = {
+            type = "checkbox",
+            name = "Bar orientation horizontal",
+            tooltip = "When ON the bar will orientate horizontally.",
+            default = MementoBar.Default.Horizontal,
+            getFunc = function()
+                return MementoBar.Saved.Horizontal
+            end,
+            setFunc = function(newValue)
+                MementoBar.Saved.Horizontal = newValue
+                MementoBar:RestorePanel()
+            end
+        },
+        [5] = {
+            type = "checkbox",
+            name = "Hide bar in menu",
+            tooltip = "When ON the bar will hide when a menu is opened.",
+            default = MementoBar.Default.HideBarInMenu,
+            getFunc = function()
+                return MementoBar.Saved.HideBarInMenu
+            end,
+            setFunc = function(newValue)
+                MementoBar.Saved.HideBarInMenu = newValue
+                MementoBar:SetFragmentBehaviour(true)
+            end
+        },
+        [6] = {
+            type = "submenu",
+            name = "Position and size",
+            tooltip = "Settings regarding position and size.",
+            controls = {
+                [1] = {
+                    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.",
+                    -- disabled = function()
+                    --     local count = 0
+                    --     if IsCollectibleUnlocked(267) and MementoBar.Saved.ShowAssistants[267] then
+                    --         count = count + 1
+                    --     end
+                    --     if IsCollectibleUnlocked(300) and MementoBar.Saved.ShowAssistants[300] then
+                    --         count = count + 1
+                    --     end
+                    --     if IsCollectibleUnlocked(301) and MementoBar.Saved.ShowAssistants[301] then
+                    --         count = count + 1
+                    --     end
+                    --     return count == 0
+                    -- end,
+                    default = function()
+                        return MementoBar.Global.IsMoveEnabled
+                    end,
+                    getFunc = function()
+                        return MementoBar.Global.IsMoveEnabled
+                    end,
+                    setFunc = function(newValue)
+                        MementoBar.Global.IsMoveEnabled = newValue
+                        MementoBar:RestorePanel()
+                    end
+                },
+                [2] = {
+                    type = "slider",
+                    name = "Choose button margin",
+                    default = MementoBar.Default.Margin,
+                    getFunc = function()
+                        return MementoBar.Saved.Margin
+                    end,
+                    setFunc = function(value)
+                        MementoBar.Saved.Margin = value
+                        MementoBar:RestorePanel()
+                    end,
+                    min = 1,
+                    max = 50
+                },
+                [3] = {
+                    type = "slider",
+                    name = "Choose button height",
+                    default = MementoBar.Default.Height,
+                    getFunc = function()
+                        return MementoBar.Saved.Height
+                    end,
+                    setFunc = function(value)
+                        MementoBar.Saved.Height = value
+                        MementoBar:RestorePanel()
+                    end,
+                    min = 1,
+                    max = 100
+                },
+                [4] = {
+                    type = "slider",
+                    name = "Choose button width",
+                    default = MementoBar.Default.Width,
+                    getFunc = function()
+                        return MementoBar.Saved.Width
+                    end,
+                    setFunc = function(value)
+                        MementoBar.Saved.Width = value
+                        MementoBar:RestorePanel()
+                    end,
+                    min = 1,
+                    max = 100
+                },
+                [5] = {
+                    type = "slider",
+                    name = "Choose snap size when moving",
+                    default = MementoBar.Default.SnapSize,
+                    getFunc = function()
+                        return MementoBar.Saved.SnapSize
+                    end,
+                    setFunc = function(value)
+                        MementoBar.Saved.SnapSize = value
+                        MementoBar:RestorePanel()
+                    end,
+                    min = 1,
+                    max = 10
+                },
+                [6] = {
+                    type = "checkbox",
+                    name = "Show hotkey's on bar",
+                    tooltip = "When ON the bar will hide when a menu is opened.",
+                    default = MementoBar.Default.ShowKeyBinding,
+                    getFunc = function()
+                        return MementoBar.Saved.ShowKeyBinding
+                    end,
+                    setFunc = function(newValue)
+                        MementoBar.Saved.ShowKeyBinding = newValue
+                        MementoBar:RestorePanel()
+                    end,
+                    width = "half"
+                },
+                [7] = {
+                    type = "dropdown",
+                    name = "Hotkey label location",
+                    tooltip = "Select hotkey label location",
+                    choices = MementoBar.Global.ChoisesKeyBindingLocation,
+                    default = MementoBar.Default.KeyBindingLocation,
+                    disabled = function()
+                        return not MementoBar.Saved.ShowKeyBinding
+                    end,
+                    getFunc = function()
+                        return MementoBar:HotKeyGetLocationText(MementoBar.Saved.KeyBindingLocation)
+                    end,
+                    setFunc = function(value)
+                        MementoBar.Saved.KeyBindingLocation = MementoBar:HotKeyGetLocationValue(value)
+                        MementoBar:RestorePanel()
+                    end,
+                    width = "half"
+                },
+                [8] = {
+                    type = "colorpicker",
+                    name = "Font Color",
+                    default = MementoBar.Default.FontColor,
+                    tooltip = "Changes of the move frame font.",
+                    getFunc = function()
+                        return MementoBar.Saved.FontColor.r, MementoBar.Saved.FontColor.g, MementoBar.Saved.FontColor.b, MementoBar.Saved.FontColor.a
+                    end,
+                    setFunc = function(r, g, b, a)
+                        MementoBar.Saved.FontColor = {r = r, g = g, b = b, a = a}
+                        MementoBar:RestorePanel()
+                    end,
+                    width = "half"
+                }
+            }
+        },
+        [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 = "Button background Color",
+                    default = function()
+                        return MementoBar.Default.CenterColor
+                    end,
+                    tooltip = "Changes the background color of the buttons.",
+                    getFunc = function()
+                        return MementoBar.Saved.CenterColor.r, MementoBar.Saved.CenterColor.g, MementoBar.Saved.CenterColor.b, MementoBar.Saved.CenterColor.a
+                    end,
+                    setFunc = function(r, g, b, a)
+                        MementoBar.Saved.CenterColor = {r = r, g = g, b = b, a = a}
+                        MementoBar:RestorePanel()
+                    end,
+                    width = "half"
+                },
+                [3] = {
+                    type = "colorpicker",
+                    name = "Button edge Color",
+                    default = function()
+                        return MementoBar.Default.EdgeColor
+                    end,
+                    tooltip = "Changes the edgecolor of the buttons.",
+                    getFunc = function()
+                        return MementoBar.Saved.EdgeColor.r, MementoBar.Saved.EdgeColor.g, MementoBar.Saved.EdgeColor.b, MementoBar.Saved.EdgeColor.a
+                    end,
+                    setFunc = function(r, g, b, a)
+                        MementoBar.Saved.EdgeColor = {r = r, g = g, b = b, a = a}
+                        MementoBar:RestorePanel()
+                    end,
+                    width = "half"
+                },
+                [4] = {
+                    type = "colorpicker",
+                    name = "Button highlight Color",
+                    default = function()
+                        return MementoBar.Default.HighlightColor
+                    end,
+                    tooltip = "Changes the highlight color of the buttons.",
+                    getFunc = function()
+                        return MementoBar.Saved.HighlightColor.r, MementoBar.Saved.HighlightColor.g, MementoBar.Saved.HighlightColor.b, MementoBar.Saved.HighlightColor.a
+                    end,
+                    setFunc = function(r, g, b, a)
+                        MementoBar.Saved.HighlightColor = {r = r, g = g, b = b, a = a}
+                        MementoBar:RestorePanel()
+                    end,
+                    width = "half"
+                }
+            }
+        },
+        [8] = {
+            type = "submenu",
+            name = MementoBar.Global.CategoryName .. " (Total: " .. MementoBar.Global.CategoryTotal .. " Unlocked: " .. MementoBar.Global.CategoryNumUnlocked .. ")",
+            tooltip = "Choose what memento's you want on the bar.",
+            controls = {
+                [1] = {
+                    type = "slider",
+                    name = "Choose bar depth (number of rows/columns)", -- or string id or function returning a string
+                    default = MementoBar.Default.BarDepth,
+                    getFunc = function()
+                        return MementoBar.Saved.BarDepth
+                    end,
+                    setFunc = function(value)
+                        MementoBar.Saved.BarDepth = value
+                        MementoBar:RestorePanel()
+                    end,
+                    min = 1,
+                    max = MementoBar.Global.CategoryNumUnlocked
+                },
+                [2] = {
+                    type = "description",
+                    text = "Choose what memento's you want enabled."
+                }
+            }
+        }
+    }
+
+    for index, _type in ipairs(MementoBar.OrderedMementos) do
+        local line = {
+            type = "checkbox",
+            name = "Show " .. _type.Name,
+            tooltip = _type.Tooltip,
+            default = not _type.Disabled,
+            disabled = _type.Disabled,
+            getFunc = function()
+                return MementoBar.Saved.SelectedMementos[_type.Id]
+            end,
+            setFunc = function(newValue)
+                if newValue == true then
+                    MementoBar.Saved.SelectedMementos[_type.Id] = newValue
+                else
+                    MementoBar.Saved.SelectedMementos[_type.Id] = nil
+                end
+                MementoBar:RestorePanel()
+            end
+        }
+        table.insert(optionsData[8].controls, index + 2, line)
+    end
+
+    LAM2:RegisterOptionControls(MementoBar.Addon.Name, optionsData)
+end
diff --git a/MementoBar_Move.lua b/MementoBar_Move.lua
new file mode 100644
index 0000000..d114b6c
--- /dev/null
+++ b/MementoBar_Move.lua
@@ -0,0 +1,149 @@
+--[[
+Author: Jarth
+Filename: MementoBar_Move.lua
+]] --
+
+-------------------------------------------------------------------------------------------------
+-- VARIABLES --
+-------------------------------------------------------------------------------------------------
+local MementoBar = MementoBar
+
+-------------------------------------------------------------------------------------------------
+-- FUNCTIONS --
+-- Move frame --
+-------------------------------------------------------------------------------------------------
+function MementoBar:UpdateMoveFrame()
+    local moveFrame = MementoBar.MoveFrame
+    local onMouseEnter, onMouseExit, onMouseDown, onMouseUp = nil, nil, nil, nil
+    if MementoBar.Global.IsMoveEnabled then
+        moveFrame = MementoBar:GetOrCreateMoveFrame()
+        onMouseEnter = MementoBar.MoveFrameOnEnter
+        onMouseExit = MementoBar.MoveFrameOnExit
+        onMouseDown = MementoBar.MoveFrameOnDown
+        onMouseUp = MementoBar.MoveFrameOnUp
+    end
+
+    if moveFrame then
+        moveFrame:SetHandler("OnMouseEnter", onMouseEnter)
+        moveFrame:SetHandler("OnMouseExit", onMouseExit)
+        moveFrame:SetHandler("OnMouseDown", onMouseDown)
+        moveFrame:SetHandler("OnMouseUp", onMouseUp)
+        moveFrame:SetHidden(not MementoBar.Global.IsMoveEnabled)
+        moveFrame.overlay:SetHidden(not MementoBar.Global.IsMoveEnabled)
+        moveFrame.labelCenter:SetHidden(not MementoBar.Global.IsMoveEnabled)
+        moveFrame.labelTopLeft:SetHidden(not MementoBar.Global.IsMoveEnabled)
+        moveFrame.MoveFrameUpdateText(moveFrame)
+        moveFrame.MoveFrameUpdateColor(moveFrame)
+        moveFrame.MoveFrameAnchorToTarget(moveFrame, moveFrame.TargetFrame)
+    end
+end
+
+-------------------------------------------------------------------------------------------------
+-- FUNCTIONS --
+-- Move handlers --
+-------------------------------------------------------------------------------------------------
+function MementoBar:GetOrCreateMoveFrame(show)
+    if MementoBar.MoveFrame == nil then
+        local newMoveFrame = MementoBar.WM:CreateControlFromVirtual(nil, GuiRoot, "MementoBar_MoveFrame")
+        local targetFrame = MementoBar_Frame
+        --Variable is used to define what savedVariable the Frame refers to.
+        newMoveFrame.TargetFrame = targetFrame
+
+        newMoveFrame["MoveFrameAnchorToTarget"] = MementoBar.MoveFrameAnchorToTarget
+        newMoveFrame["MoveFrameGetSnapPosition"] = MementoBar.MoveFrameGetSnapPosition
+        newMoveFrame["MoveFrameUpdateText"] = MementoBar.MoveFrameUpdateText
+        newMoveFrame["MoveFrameUpdateColor"] = MementoBar.MoveFrameUpdateColor
+        newMoveFrame["MoveFrameOnUpdate"] = MementoBar.MoveFrameOnUpdate
+        newMoveFrame["MoveFrameStorePosition"] = MementoBar.MoveFrameStorePosition
+
+        newMoveFrame:SetDimensions(targetFrame:GetWidth(), targetFrame:GetHeight())
+        newMoveFrame:SetDrawLayer(4)
+        newMoveFrame:SetParent(GuiRoot)
+        newMoveFrame:SetMouseEnabled(true)
+        newMoveFrame:SetMovable(true)
+        newMoveFrame:SetClampedToScreen(true)
+
+        -- overlay
+        newMoveFrame.overlay = MementoBar.WM:CreateControl(nil, newMoveFrame, CT_BACKDROP)
+        newMoveFrame.overlay:SetDrawLevel(2)
+        newMoveFrame.overlay:SetAnchorFill(targetFrame)
+        newMoveFrame.overlay:SetEdgeTexture("", 8, 1, 0)
+        -- label
+        newMoveFrame.labelCenter = MementoBar.WM:CreateControl(nil, newMoveFrame, CT_LABEL)
+        newMoveFrame.labelCenter:SetDrawLevel(3)
+        newMoveFrame.labelCenter:SetAnchorFill(targetFrame)
+        newMoveFrame.labelCenter:SetFont("ZoFontWinH5")
+        newMoveFrame.labelCenter:SetHorizontalAlignment(1)
+        newMoveFrame.labelCenter:SetVerticalAlignment(1)
+
+        newMoveFrame.labelTopLeft = MementoBar.WM:CreateControl(nil, newMoveFrame, CT_LABEL)
+        newMoveFrame.labelTopLeft:SetDrawLevel(3)
+        newMoveFrame.labelTopLeft:SetAnchorFill(targetFrame)
+        newMoveFrame.labelTopLeft:SetFont("ZoFontWinH5")
+        newMoveFrame.labelTopLeft:SetHorizontalAlignment(0)
+        newMoveFrame.labelTopLeft:SetVerticalAlignment(0)
+
+        MementoBar.MoveFrame = newMoveFrame
+    end
+    return MementoBar.MoveFrame
+end
+
+function MementoBar.MoveFrameOnEnter(frame)
+    frame.MoveFrameUpdateText(frame, true)
+end
+
+function MementoBar.MoveFrameOnExit(frame)
+    frame.MoveFrameUpdateText(frame, false)
+end
+
+function MementoBar.MoveFrameOnDown(frame)
+    frame:SetHandler("OnUpdate", frame.MoveFrameOnUpdate)
+end
+
+function MementoBar.MoveFrameOnUp(frame)
+    frame.MoveFrameOnUpdate(frame)
+    frame.MoveFrameUpdateText(frame, false)
+    frame:SetHandler("OnUpdate", nil)
+    frame.MoveFrameStorePosition(frame)
+end
+
+function MementoBar.MoveFrameOnUpdate(frame)
+    frame.TargetFrame:ClearAnchors()
+    frame.TargetFrame:SetAnchor(TOPLeft, GuiRoot, TOPLeft, MementoBar.MoveFrameGetSnapPosition(frame:GetLeft()), MementoBar.MoveFrameGetSnapPosition(frame:GetTop()))
+    frame.MoveFrameUpdateText(frame, true)
+end
+
+function MementoBar.MoveFrameUpdateText(frame, position)
+    local labelTextTopLeft = ""
+    frame.labelCenter:SetText(string.format("%s,%s", frame:GetWidth(), frame:GetHeight()))
+    if (position) then
+        labelTextTopLeft = string.format("%s,%s", frame.TargetFrame:GetLeft(), frame.TargetFrame:GetTop())
+    end
+
+    frame.labelTopLeft:SetText(labelTextTopLeft)
+end
+
+function MementoBar.MoveFrameGetSnapPosition(value)
+    return (zo_round(value / MementoBar.Saved.SnapSize) * MementoBar.Saved.SnapSize)
+end
+
+function MementoBar.MoveFrameStorePosition(frame)
+    MementoBar.Saved.Top = frame.MoveFrameGetSnapPosition(frame:GetTop())
+    MementoBar.Saved.Left = frame.MoveFrameGetSnapPosition(frame:GetLeft())
+end
+
+function MementoBar.MoveFrameAnchorToTarget(frame, target)
+    frame:ClearAnchors()
+    frame:SetDimensions(target:GetWidth(), target:GetHeight())
+    frame:SetAnchor(TOPLeft, GuiRoot, TOPLeft, target:GetLeft(), target:GetTop())
+end
+
+function MementoBar.MoveFrameUpdateColor(frame)
+    local centerColor = MementoBar.Saved.CenterColor
+    local edgeColor = MementoBar.Saved.EdgeColor
+    local fontColor = MementoBar.Saved.FontColor
+    frame.overlay:SetCenterColor(centerColor.r, centerColor.g, centerColor.b, centerColor.a)
+    frame.overlay:SetEdgeColor(edgeColor.r, edgeColor.g, edgeColor.b, edgeColor.a)
+    frame.labelCenter:SetColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a)
+    frame.labelTopLeft:SetColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a)
+end