diff --git a/Changelog b/Changelog index e29b7b2..7f75203 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,17 @@ ------------------------------------------------------------------------------- Memento bar ------------------------------------------------------------------------------- +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 + (Should be disabled after move) +- Fixed issue where the color would not be set properly, after doing a "Reset to default" +- The addon should no longer meta information about Memento's +- 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 0.9.3 (28-12-2017) - Updated the cooldown event from EVENT_ABILITY_COOLDOWN_UPDATED to EVENT_ACTION_UPDATE_COOLDOWNS. -- It has less updates, and less spam. diff --git a/MementoBar.lua b/MementoBar.lua index ec116d9..8e5d8ab 100644 --- a/MementoBar.lua +++ b/MementoBar.lua @@ -1,7 +1,7 @@ --[[ Author: Jarth Filename: MementoBar.lua -]]-- +]] -- ------------------------------------------------------------------------------------------------- -- Libraries -- @@ -12,403 +12,509 @@ local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0") -- VARIABLE -- ------------------------------------------------------------------------------------------------- local ADDON_NAME = "MementoBar" -local ADDON_VERSION = 0.9 -local ADDON_MINOR_VERSION = 3 +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.MB_Button = {} -MementoBar.Timer = { - EventName = "TimerUpdate" -} +MementoBar.Name = ADDON_NAME +MementoBar.Buttons = {} MementoBar.Fragment = nil +MementoBar.Mementos = {} +MementoBar.MementosOrdered = {} MementoBar.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} - mementos = {}, - useAccountSettings = true, - horizontalOrientation = true, - barDepth = 1, - hideBarInMenu = true + 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 } ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function MementoBar.mbClicked(collectionId) - if collectionId > 0 and IsCollectibleUnlocked(collectionId) then - local cooldownRemaining, cooldownDuration = GetCollectibleCooldownAndDuration(collectionId) - if cooldownRemaining == 0 then - MementoBar.Activate(collectionId) + +function MementoBar.OnAddOnLoaded(_, addonName) + if addonName == MementoBar.Name then + MementoBar:Initialize() + end +end + +function MementoBar:Initialize() + -- Load saved values.. + MementoBar.Saved = ZO_SavedVars:New("MementoBar_Character", ADDON_VERSION, nil, MementoBar.Default) + if MementoBar.Saved.UseAccountSettings then + MementoBar.Saved = ZO_SavedVars:NewAccountWide("MementoBar_Account", 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() +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 end -function MementoBar.initializeButtons() - local index = 0 - local mbHeight = MB_Frame:GetHeight() - local mbWidth = MB_Frame:GetWidth() - - for collectionId in pairs(MementoBar.savedVariables.mementos) do - if MementoBar.savedVariables.mementos[collectionId].show and IsCollectibleUnlocked(collectionId) then - if MementoBar.MB_Button[collectionId] == nil then - MementoBar.MB_Button[collectionId] = WINDOW_MANAGER:CreateControlFromVirtual("MB_Button", MB_FrameBackdrop, "MB_Button", collectionId) - MementoBar.MB_Button[collectionId]:SetId(collectionId) - end - MementoBar.setupButton(collectionId, MementoBar.MB_Button[collectionId]) - MementoBar.MB_Button[collectionId]:SetHidden(false) - MementoBar.MB_Button[collectionId]:ClearAnchors() - if MementoBar.savedVariables.horizontalOrientation then - MementoBar.MB_Button[collectionId]:SetAnchor(TOPLEFT, MB_FrameBackdrop, TOPLEFT, 10+60*(math.floor(index/MementoBar.savedVariables.barDepth)), 10+60*(index % MementoBar.savedVariables.barDepth)) - else - MementoBar.MB_Button[collectionId]:SetAnchor(TOPLEFT, MB_FrameBackdrop, TOPLEFT, 10+60*(index % MementoBar.savedVariables.barDepth), 10+60*(math.floor(index/MementoBar.savedVariables.barDepth))) - end - index = index + 1 - else - if MementoBar.MB_Button[collectionId] then - MementoBar.MB_Button[collectionId]:SetHidden(true) - 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 - end + return left, top end -function MementoBar.setFragmentBehaviour(menuOpen) - if MementoBar.Fragment == nil then - MementoBar.Fragment = ZO_HUDFadeSceneFragment:New( MB_Frame ) - end +function MementoBar:SetFragmentBehaviour(menuOpen) + if MementoBar.Fragment == nil then + MementoBar.Fragment = ZO_HUDFadeSceneFragment:New(MementoBar_Frame) + end - if MementoBar.savedVariables.hideBarInMenu then - MementoBar.addControlToFrame(menuOpen) - else - MementoBar.removeControlToFrame(menuOpen) - end + if MementoBar.Saved.HideBarInMenu then + MementoBar:AddControlToFrame(menuOpen) + else + MementoBar:RemoveControlToFrame(menuOpen) + end end -function MementoBar.addControlToFrame(menuOpen) - if menuOpen then - MB_Frame:SetHidden(true) - end - SCENE_MANAGER:GetScene('hud'):AddFragment(MementoBar.Fragment) - SCENE_MANAGER:GetScene('hudui'):AddFragment(MementoBar.Fragment) +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 - MB_Frame:SetHidden(false) - end - - SCENE_MANAGER:GetScene('hud'):RemoveFragment(MementoBar.Fragment) - SCENE_MANAGER:GetScene('hudui'):RemoveFragment(MementoBar.Fragment) +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.setButtonFrameWidth() - local mbBtnHeight = 60 - local mbBtnWidth = 60 - local mbCount = 0 - local mbHeight = 0 - local mbWidth = 0 +function MementoBar:SetButtonFrameWidth() + local mbCount = 0 - for collection in pairs(MementoBar.savedVariables.mementos) do - if MementoBar.savedVariables.mementos[collection].show then - mbCount = mbCount + 1 + for _ in pairs(MementoBar.Saved.SelectedMementos) do + mbCount = mbCount + 1 end - end - - mbDepth = math.ceil(mbCount / MementoBar.savedVariables.barDepth) - mbHeight = MementoBar.savedVariables.horizontalOrientation and mbBtnHeight * MementoBar.savedVariables.barDepth or mbBtnHeight * mbDepth - mbWidth = MementoBar.savedVariables.horizontalOrientation and mbBtnWidth * mbDepth or mbBtnWidth * MementoBar.savedVariables.barDepth - - MB_Frame:SetHidden(mbCount == 0) - MB_FrameBackdrop:SetHidden(mbCount == 0) - MB_Frame:SetHeight(mbHeight) - MB_FrameBackdrop:SetHeight(mbHeight) - MB_Frame:SetWidth(mbWidth) - MB_FrameBackdrop:SetWidth(mbWidth) + + 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_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 -function MementoBar.setupButton(collectionId, MB_Button) - local MB_ButtonTexture = MementoBar.wm:GetControlByName("MB_Button"..collectionId.."Texture") - if MB_ButtonTexture and MementoBar.savedVariables.mementos[collectionId].collectibleIcon then - MB_ButtonTexture:SetTexture(MementoBar.savedVariables.mementos[collectionId].collectibleIcon) - MB_Button:SetHandler("OnClicked", function(self) MementoBar.mbClicked(MB_Button:GetId()) end) - end +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 -function MementoBar.mbRestorePosition() - local top = MementoBar.savedVariables.top - local left = MementoBar.savedVariables.left - MB_Frame:ClearAnchors() - MB_Frame:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, left, top) +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 end --- Global accessed function, allowing OnMoveStop to find the function. -function MementoBar_OnMoveStop() - MementoBar.savedVariables.top = MB_Frame:GetTop() - MementoBar.savedVariables.left = MB_Frame:GetLeft() +function MementoBar:RestorePosition() + local Top = MementoBar.Saved.Top + local Left = MementoBar.Saved.Left + MementoBar_Frame:ClearAnchors() + MementoBar_Frame:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, Left, Top) end -function MementoBar.RestorePanel() - MementoBar.setFragmentBehaviour() +function MementoBar:RestorePanel() + MementoBar:SetFragmentBehaviour() + + MementoBar:SetButtonFrameWidth() + + MementoBar:FrameBackdropColor() - MementoBar.setButtonFrameWidth() - - MementoBar.initializeButtons() - - MementoBar.mbRestorePosition() + 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 +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(collectionId) - local start = GetTimeStamp() - local cooldownRemaining, cooldownDuration = GetCollectibleCooldownAndDuration(collectionId) - --d("Activate",cooldownRemaining, cooldownDuration, collectionId, start) - - local function Update(eventId) - cooldownRemaining, cooldownDuration = GetCollectibleCooldownAndDuration(collectionId) - -- local updateStr ="Update," .. cooldownRemaining .. "," .. cooldownDuration .. "," .. eventId .. "," .. collectionId .. "," .. start .. "," .. GetTimeStamp() - -- d(updateStr) - +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 (GetTimeStamp() < (start + math.floor(cooldownDuration/1000))) then - --d("Update",cooldownRemaining, cooldownDuration, collectionId, start, GetTimeStamp()) - MementoBar.UpdateLabel(cooldownDuration) - else - MementoBar.UpdateLabel("") - EVENT_MANAGER:UnregisterForEvent(MementoBar.name, EVENT_ACTION_UPDATE_COOLDOWNS) + 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 +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 - if IsCollectibleUsable(collectionId) then - EVENT_MANAGER:UnregisterForEvent(MementoBar.name, EVENT_ACTION_UPDATE_COOLDOWNS) - UseCollectible(collectionId) - EVENT_MANAGER:RegisterForEvent(MementoBar.name, EVENT_ACTION_UPDATE_COOLDOWNS, Update) - 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.UpdateLabel(remaining) - if type(remaining) == "number" and remaining > 0 then - remaining = string.format("%." .. 1 .. "f" .. "s", (math.floor(remaining / 100)/10)) - end - for collectionId in pairs(MementoBar.savedVariables.mementos) do - local MB_ButtonTimer = MementoBar.wm:GetControlByName("MB_Button"..collectionId.."Timer") - if MB_ButtonTimer and MementoBar.savedVariables.mementos[collectionId].show then - MB_ButtonTimer:SetText(remaining) +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 - end + frame.LabelTopLeft:SetText(frame.labelTextTopLeft) end ------------------------------------------------------------------------------------------------- -- Menu Functions -- ------------------------------------------------------------------------------------------------- -function MementoBar.CreateSettingsWindow() - local mementTopLevelIndex = 7 - local catName, catNumSubCat, catNumCollectibles, catNumUnlocked, catTotal, catHidesLocked = GetCollectibleCategoryInfo(mementTopLevelIndex) - --d(catName, catNumSubCat, catNumCollectibles, catNumUnlocked, catTotal, catHidesLocked) - - 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.savedVariables.useAccountSettings end, - setFunc = function(newValue) - --Apply value to existing variable - MementoBar.savedVariables.useAccountSettings = newValue; - if newValue then - MementoBar.savedVariables = ZO_SavedVars:NewAccountWide("MementoBar_Account", ADDON_VERSION, nil, MementoBar.Default) - else - MementoBar.savedVariables = ZO_SavedVars:New("MementoBar_Character", ADDON_VERSION, nil, MementoBar.Default) - end - --Apply value to new variable - MementoBar.savedVariables.useAccountSettings = newValue; - MB_FrameBackdrop:SetCenterColor(unpack(MementoBar.savedVariables.centerColor)) - MB_FrameBackdrop:SetEdgeColor(unpack(MementoBar.savedVariables.edgeColor)) - MementoBar.RestorePanel() - end, - }, - [4] = { - type = "checkbox", - name = "Bar orientation horizontal", - tooltip = "When ON the bar will orientate horizontally.", - default = MementoBar.Default.horizontalOrientation, - getFunc = function() return MementoBar.savedVariables.horizontalOrientation end, - setFunc = function(newValue) - MementoBar.savedVariables.horizontalOrientation = 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.savedVariables.hideBarInMenu end, - setFunc = function(newValue) - MementoBar.savedVariables.hideBarInMenu = newValue - MementoBar.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 = MementoBar.Default.centerColor, - tooltip = "Changes the color of the background.", - getFunc = function() return unpack( MementoBar.savedVariables.centerColor ) end, - setFunc = function(r,g,b,a) - MementoBar.savedVariables.centerColor = {r,g,b,a} - MB_FrameBackdrop:SetCenterColor(r,g,b,a) - end, - width = "half" - }, - [3] = { - type = "colorpicker", - name = "Frame Color", - default = MementoBar.Default.edgeColor, - tooltip = "Changes the color of the frame.", - getFunc = function() return unpack( MementoBar.savedVariables.edgeColor ) end, - setFunc = function(r,g,b,a) - MementoBar.savedVariables.edgeColor = {r,g,b,a} - MB_FrameBackdrop:SetEdgeColor(r,g,b,a) - end, - width = "half" - } - }, - }, - [7] = { - type = "submenu", - name = catName .. " (Total: " .. catTotal .. " Unlocked: ".. catNumUnlocked .. ")", - tooltip = "Choose what memento's you want on the bar.", - controls = { +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 = "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.savedVariables.barDepth end, - setFunc = function(value) - MementoBar.savedVariables.barDepth = value - MementoBar.RestorePanel() - end, - min = 1, - max = catNumUnlocked + type = "header", + name = "Memento Bar Settings" }, [2] = { - type = "description", - text = "Choose what memento's you want enabled." + 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) - --** _Returns:_ *string* _name_, *string* _description_, *textureName* _icon_, *textureName* _deprecatedLockedIcon_, *bool* _unlocked_, *bool* _purchasable_, *bool* _isActive_, *[CollectibleCategoryType|#CollectibleCategoryType]* _categoryType_, *string* _hint_, *bool* _isPlaceholder_ - local collectibleName, collectibleDescription, collectibleIcon, collectibleLockedIcon, collectibleUnlocked, collectiblePurchasable, collectibleIsActive, collectibleCollectibleCategoryType, collectibleHint, collectibleIsPlaceholder = GetCollectibleInfo(collectibleId) - --d('Start', collectibleName, collectibleDescription, collectibleIcon, collectibleLockedIcon, collectibleUnlocked, collectiblePurchasable, collectibleIsActive, collectibleCollectibleCategoryType, collectibleHint, collectibleIsPlaceholder, 'End') - - local line = { - type = "checkbox", - name = "Show " .. collectibleName, - tooltip = collectibleDescription, - --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 MementoBar.savedVariables.mementos[collectibleId] == nil or not MementoBar.savedVariables.mementos[collectibleId].show then - return false - else - return true - end - end, - setFunc = function(newValue) - if MementoBar.savedVariables.mementos[collectibleId] == nil then - MementoBar.savedVariables.mementos[collectibleId] = { - show = newValue, - collectibleIcon = collectibleIcon - } - else - MementoBar.savedVariables.mementos[collectibleId].show = newValue - MementoBar.savedVariables.mementos[collectibleId].collectibleIcon = collectibleIcon - end - - MementoBar.RestorePanel() - end } - table.insert(optionsData[7].controls, index, line) - end - LAM2:RegisterOptionControls(ADDON_NAME, optionsData) -end + 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] -function MementoBar:Initialize() - -- Load saved values.. - MementoBar.savedVariables = ZO_SavedVars:New("MementoBar_Character", ADDON_VERSION, nil, MementoBar.Default) - if MementoBar.savedVariables.useAccountSettings then - MementoBar.savedVariables = ZO_SavedVars:NewAccountWide("MementoBar_Account", ADDON_VERSION, nil, MementoBar.Default) - end - - MementoBar.RestorePanel() - -- Create menu variables. - MementoBar.CreateSettingsWindow() - MB_FrameBackdrop:SetCenterColor(unpack(MementoBar.savedVariables.centerColor)) - MB_FrameBackdrop:SetEdgeColor(unpack(MementoBar.savedVariables.edgeColor)) - -- ToDo - End. - EVENT_MANAGER:UnregisterForEvent(MementoBar.name, EVENT_ADD_ON_LOADED) -end + 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 --- 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 MementoBar.OnAddOnLoaded(event, addonName) - -- The event fires each time *any* addon loads - but we only care about when our own addon loads. - if addonName == MementoBar.name then - MementoBar: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(ADDON_NAME, EVENT_ADD_ON_LOADED, MementoBar.mbLoad) -EVENT_MANAGER:RegisterForEvent(MementoBar.name, EVENT_ADD_ON_LOADED, MementoBar.OnAddOnLoaded) --- EVENT_MANAGER:RegisterForEvent("MementoBar Click", EVENT_GLOBAL_MOUSE_DOWN, MementoBar.mbClicked) -- Edit by Mitsarugi, addon wont work without this line of code \ No newline at end of file +------------------------------------------------------------------------------------------------- +-- Initialize Functions -- +------------------------------------------------------------------------------------------------- + +EVENT_MANAGER:RegisterForEvent(MementoBar.Name, EVENT_ADD_ON_LOADED, MementoBar.OnAddOnLoaded) diff --git a/MementoBar.txt b/MementoBar.txt index 9115369..7b0984d 100644 --- a/MementoBar.txt +++ b/MementoBar.txt @@ -6,7 +6,7 @@ ## APIVersion: 100021 ## Title: Memento Bar -## Version: 0.9.3 +## Version: 1.0.0 ## Author: Jarth ## Description: Show a hotbar with selected memento's. Activate by button press! ## diff --git a/MementoBar.xml b/MementoBar.xml index d9d99dc..35b4ae2 100644 --- a/MementoBar.xml +++ b/MementoBar.xml @@ -1,11 +1,8 @@ <GuiXml> <Controls> - <TopLevelControl name="MB_Frame" clampedToScreen="true" movable="true" mouseEnabled="true"> + <TopLevelControl name="MementoBar_Frame" clampedToScreen="true" movable="true" mouseEnabled="true"> <Anchor point="CENTER" relativePoint="CENTER" relativeTo="GuiRoot"/> <Dimensions x="180" y="60"/> - <OnMoveStop> - MementoBar_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="MB_Button" relativeTo="$(parent)" virtual="true"> + <Button name="MementoBar_Button" relativeTo="$(parent)" virtual="true"> <Dimensions x="40" y="40"/> <Controls> <Label name="$(parent)Timer" font="ZoFontHeader2">