diff --git a/Changelog b/Changelog index 44f70dd..de1045d 100644 --- a/Changelog +++ b/Changelog @@ -12,6 +12,7 @@ Version 1.6.2 (18-03-2018) -- Fence -- Store - Tweeked visibility menu items, to better describe the area and for consistency. +- Refactored code to make it more reusable. Version 1.6.1 (11-03-2018) - Added fragment support for Inventory and store views. diff --git a/MementoBar.lua b/MementoBar.lua index c7bc93d..99b5c57 100644 --- a/MementoBar.lua +++ b/MementoBar.lua @@ -6,62 +6,62 @@ Filename: MementoBar.lua ------------------------------------------------------------------------------------------------- -- VARIABLES -- ------------------------------------------------------------------------------------------------- -local baseModul = MementoBar +local baseModule = MementoBar ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function baseModul.OnAddOnLoaded(_, addonName) - if addonName == baseModul.Addon.Name then - baseModul:Initialize() +function baseModule.OnAddOnLoaded(_, addonName) + if addonName == baseModule.Addon.Name then + baseModule:Initialize() end end -function baseModul:Initialize() +function baseModule:Initialize() -- Load saved values.. - baseModul.Saved = ZO_SavedVars:New("MementoBar_Character", baseModul.Addon.Version, nil, baseModul.Default) + baseModule.Saved = ZO_SavedVars:New("MementoBar_Character", baseModule.Addon.Version, nil, baseModule.Default) - if baseModul.Saved.UseAccountSettings then - baseModul.Saved = ZO_SavedVars:NewAccountWide("MementoBar_Account", baseModul.Addon.Version, nil, baseModul.Default) + if baseModule.Saved.UseAccountSettings then + baseModule.Saved = ZO_SavedVars:NewAccountWide("MementoBar_Account", baseModule.Addon.Version, nil, baseModule.Default) end - MementoBar_Frame:SetHandler("OnMoveStop", baseModul.OnMoveStop) - baseModul:RestorePanel() - baseModul:HoykeyCreateSelections() - baseModul:CreateSettingsWindow() + MementoBar_Frame:SetHandler("OnMoveStop", baseModule.OnMoveStop) + baseModule:RestorePanel() + baseModule:HoykeyCreateSelections() + baseModule:CreateSettingsWindow() - EVENT_MANAGER:UnregisterForEvent(baseModul.Addon.Name, EVENT_ADD_ON_LOADED) + EVENT_MANAGER:UnregisterForEvent(baseModule.Addon.Name, EVENT_ADD_ON_LOADED) end ------------------------------------------------------------------------------------------------- -- PRIVATE FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function baseModul:GetVersion(showMinor) +function baseModule:GetVersion(showMinor) if showMinor == false or ADDON_MINOR_VERSION == nil then - return tostring(baseModul.Addon.Version) + return tostring(baseModule.Addon.Version) end - return tostring(baseModul.Addon.Version) .. "." .. tostring(baseModul.Addon.MinorVersion) + return tostring(baseModule.Addon.Version) .. "." .. tostring(baseModule.Addon.MinorVersion) end -function baseModul:RestorePanel() - baseModul:SetButtonFrameWidth() - baseModul:HotkeyUpdate() - baseModul:InitializeButtons() - baseModul:RestoreButtons() - baseModul:RestorePosition() - baseModul:UpdateMoveFrame() - baseModul:SetFragmentBehaviour() +function baseModule:RestorePanel() + baseModule:SetButtonFrameWidth() + baseModule:HotkeyUpdate() + baseModule:InitializeButtons() + baseModule:RestoreButtons() + baseModule:RestorePosition() + baseModule:UpdateMoveFrame() + baseModule:SetFragmentBehaviour() end -function baseModul:RestorePosition() - local Top = baseModul.Saved.Top - local Left = baseModul.Saved.Left +function baseModule:RestorePosition() + local Top = baseModule.Saved.Top + local Left = baseModule.Saved.Left MementoBar_Frame:ClearAnchors() MementoBar_Frame:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, Left, Top) end -EVENT_MANAGER:RegisterForEvent(baseModul.Addon.Name, EVENT_ADD_ON_LOADED, baseModul.OnAddOnLoaded) +EVENT_MANAGER:RegisterForEvent(baseModule.Addon.Name, EVENT_ADD_ON_LOADED, baseModule.OnAddOnLoaded) diff --git a/MementoBar_Hotkeys.lua b/MementoBar_Hotkeys.lua index a77e522..5fc3fdc 100644 --- a/MementoBar_Hotkeys.lua +++ b/MementoBar_Hotkeys.lua @@ -12,11 +12,11 @@ local baseModule = MementoBar -- PUBLIC FUNCTIONS -- ------------------------------------------------------------------------------------------------- function MementoBar_KeyBindingPressed(keyId) - local control = baseModul.WM:GetMouseOverControl() + local control = baseModule.WM:GetMouseOverControl() if control ~= nil then - for collectibleId, _ in pairs(baseModul.Saved.SelectedMementos) do - if baseModul.Buttons[collectibleId] == control then + for collectibleId, _ in pairs(baseModule.Saved.SelectedMementos) do + if baseModule.Buttons[collectibleId] == control then baseModule:HotkeyUpdate(keyId, collectibleId) baseModule:InitializeButtons() return @@ -24,8 +24,8 @@ function MementoBar_KeyBindingPressed(keyId) end end - if baseModul.Saved.KeyBindings[keyId] > 0 then - baseModul.ButtonOnClicked(baseModul.Buttons[baseModul.Saved.KeyBindings[keyId]]) + if baseModule.Saved.KeyBindings[keyId] > 0 then + baseModule.ButtonOnClicked(baseModule.Buttons[baseModule.Saved.KeyBindings[keyId]]) end end @@ -33,31 +33,31 @@ end -- PRIVATE FUNCTIONS -- ------------------------------------------------------------------------------------------------- function baseModule:HoykeyCreateSelections() - for key, value in ipairs(baseModul.Saved.KeyBindings) do + for key, value in ipairs(baseModule.Saved.KeyBindings) do ZO_CreateStringId("SI_BINDING_NAME_MementoBar_" .. key, "MementoBar_" .. key) end end function baseModule:HotkeyUpdate(newKeyId, newCollectibleId) - baseModul.Global.ReverseKeyBindings = {} + baseModule.Global.ReverseKeyBindings = {} - for keyId, collectibleId in ipairs(baseModul.Saved.KeyBindings) do + for keyId, collectibleId in ipairs(baseModule.Saved.KeyBindings) do if newCollectibleId and newKeyId == keyId then - baseModul.Saved.KeyBindings[keyId] = newCollectibleId - baseModul.Global.ReverseKeyBindings[newCollectibleId] = keyId + baseModule.Saved.KeyBindings[keyId] = newCollectibleId + baseModule.Global.ReverseKeyBindings[newCollectibleId] = keyId elseif newCollectibleId == collectibleId and newKeyId ~= keyId then - baseModul.Saved.KeyBindings[keyId] = 0 - elseif collectibleId > 0 and not baseModul.Saved.SelectedMementos[collectibleId] then - baseModul.Saved.KeyBindings[keyId] = 0 + baseModule.Saved.KeyBindings[keyId] = 0 + elseif collectibleId > 0 and not baseModule.Saved.SelectedMementos[collectibleId] then + baseModule.Saved.KeyBindings[keyId] = 0 elseif collectibleId > 0 then - baseModul.Global.ReverseKeyBindings[collectibleId] = keyId + baseModule.Global.ReverseKeyBindings[collectibleId] = keyId end end end function baseModule:HoykeyGetKey(button, collectibleId) local result = "" - local keyId = baseModul.Global.ReverseKeyBindings[collectibleId] + local keyId = baseModule.Global.ReverseKeyBindings[collectibleId] if keyId then local keyBindingTable = {GetHighestPriorityActionBindingInfoFromName("MementoBar_" .. keyId)} @@ -84,7 +84,7 @@ function baseModule:HotkeyGetKeyName(result, keyValue) end function baseModule:HotkeyUpdateColor(frame) - local fontColor = baseModul.Saved.FontColor + local fontColor = baseModule.Saved.FontColor frame:SetColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a) end diff --git a/MementoBar_Move.lua b/MementoBar_Move.lua index 3b44129..16e601e 100644 --- a/MementoBar_Move.lua +++ b/MementoBar_Move.lua @@ -6,22 +6,22 @@ Filename: MementoBar_Move.lua ------------------------------------------------------------------------------------------------- -- VARIABLES -- ------------------------------------------------------------------------------------------------- -local baseModul = MementoBar +local baseModule = MementoBar ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- -- Move frame -- ------------------------------------------------------------------------------------------------- -function baseModul:UpdateMoveFrame() - local moveFrame = baseModul.MoveFrame +function baseModule:UpdateMoveFrame() + local moveFrame = baseModule.MoveFrame local onMouseEnter, onMouseExit, onMouseDown, onMouseUp = nil, nil, nil, nil - if baseModul.Global.IsMoveEnabled then - moveFrame = baseModul:GetOrCreateMoveFrame() - onMouseEnter = baseModul.MoveFrameOnEnter - onMouseExit = baseModul.MoveFrameOnExit - onMouseDown = baseModul.MoveFrameOnDown - onMouseUp = baseModul.MoveFrameOnUp + if baseModule.Global.IsMoveEnabled then + moveFrame = baseModule:GetOrCreateMoveFrame() + onMouseEnter = baseModule.MoveFrameOnEnter + onMouseExit = baseModule.MoveFrameOnExit + onMouseDown = baseModule.MoveFrameOnDown + onMouseUp = baseModule.MoveFrameOnUp end if moveFrame then @@ -29,10 +29,10 @@ function baseModul:UpdateMoveFrame() moveFrame:SetHandler("OnMouseExit", onMouseExit) moveFrame:SetHandler("OnMouseDown", onMouseDown) moveFrame:SetHandler("OnMouseUp", onMouseUp) - moveFrame:SetHidden(not baseModul.Global.IsMoveEnabled) - moveFrame.overlay:SetHidden(not baseModul.Global.IsMoveEnabled) - moveFrame.labelCenter:SetHidden(not baseModul.Global.IsMoveEnabled) - moveFrame.labelTopLeft:SetHidden(not baseModul.Global.IsMoveEnabled) + moveFrame:SetHidden(not baseModule.Global.IsMoveEnabled) + moveFrame.overlay:SetHidden(not baseModule.Global.IsMoveEnabled) + moveFrame.labelCenter:SetHidden(not baseModule.Global.IsMoveEnabled) + moveFrame.labelTopLeft:SetHidden(not baseModule.Global.IsMoveEnabled) moveFrame.MoveFrameUpdateText(moveFrame) moveFrame.MoveFrameUpdateColor(moveFrame) moveFrame.MoveFrameAnchorToTarget(moveFrame, moveFrame.TargetFrame) @@ -43,20 +43,20 @@ end -- FUNCTIONS -- -- Move handlers -- ------------------------------------------------------------------------------------------------- -function baseModul:GetOrCreateMoveFrame(show) - if baseModul.MoveFrame == nil then - local newMoveFrame = baseModul.WM:CreateControlFromVirtual(nil, GuiRoot, "MementoBar_MoveFrame") +function baseModule:GetOrCreateMoveFrame(show) + if baseModule.MoveFrame == nil then + local newMoveFrame = baseModule.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"] = baseModul.MoveFrameAnchorToTarget - newMoveFrame["MoveFrameGetSnapPosition"] = baseModul.MoveFrameGetSnapPosition - newMoveFrame["MoveFrameUpdateText"] = baseModul.MoveFrameUpdateText - newMoveFrame["MoveFrameUpdateColor"] = baseModul.MoveFrameUpdateColor - newMoveFrame["MoveFrameOnUpdate"] = baseModul.MoveFrameOnUpdate - newMoveFrame["MoveFrameStorePosition"] = baseModul.MoveFrameStorePosition + newMoveFrame["MoveFrameAnchorToTarget"] = baseModule.MoveFrameAnchorToTarget + newMoveFrame["MoveFrameGetSnapPosition"] = baseModule.MoveFrameGetSnapPosition + newMoveFrame["MoveFrameUpdateText"] = baseModule.MoveFrameUpdateText + newMoveFrame["MoveFrameUpdateColor"] = baseModule.MoveFrameUpdateColor + newMoveFrame["MoveFrameOnUpdate"] = baseModule.MoveFrameOnUpdate + newMoveFrame["MoveFrameStorePosition"] = baseModule.MoveFrameStorePosition newMoveFrame:SetDimensions(targetFrame:GetWidth(), targetFrame:GetHeight()) newMoveFrame:SetDrawLayer(4) @@ -66,56 +66,56 @@ function baseModul:GetOrCreateMoveFrame(show) newMoveFrame:SetClampedToScreen(true) -- overlay - newMoveFrame.overlay = baseModul.WM:CreateControl(nil, newMoveFrame, CT_BACKDROP) + newMoveFrame.overlay = baseModule.WM:CreateControl(nil, newMoveFrame, CT_BACKDROP) newMoveFrame.overlay:SetDrawLevel(2) newMoveFrame.overlay:SetAnchorFill(targetFrame) newMoveFrame.overlay:SetEdgeTexture("", 8, 1, 0) -- label - newMoveFrame.labelCenter = baseModul.WM:CreateControl(nil, newMoveFrame, CT_LABEL) + newMoveFrame.labelCenter = baseModule.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 = baseModul.WM:CreateControl(nil, newMoveFrame, CT_LABEL) + newMoveFrame.labelTopLeft = baseModule.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) - baseModul.MoveFrame = newMoveFrame + baseModule.MoveFrame = newMoveFrame end - return baseModul.MoveFrame + return baseModule.MoveFrame end -function baseModul.MoveFrameOnEnter(frame) +function baseModule.MoveFrameOnEnter(frame) frame.MoveFrameUpdateText(frame, true) end -function baseModul.MoveFrameOnExit(frame) +function baseModule.MoveFrameOnExit(frame) frame.MoveFrameUpdateText(frame, false) end -function baseModul.MoveFrameOnDown(frame) +function baseModule.MoveFrameOnDown(frame) frame:SetHandler("OnUpdate", frame.MoveFrameOnUpdate) end -function baseModul.MoveFrameOnUp(frame) +function baseModule.MoveFrameOnUp(frame) frame.MoveFrameOnUpdate(frame) frame.MoveFrameUpdateText(frame, false) frame:SetHandler("OnUpdate", nil) frame.MoveFrameStorePosition(frame) end -function baseModul.MoveFrameOnUpdate(frame) +function baseModule.MoveFrameOnUpdate(frame) frame.TargetFrame:ClearAnchors() - frame.TargetFrame:SetAnchor(TOPLeft, GuiRoot, TOPLeft, baseModul.MoveFrameGetSnapPosition(frame:GetLeft()), baseModul.MoveFrameGetSnapPosition(frame:GetTop())) + frame.TargetFrame:SetAnchor(TOPLeft, GuiRoot, TOPLeft, baseModule.MoveFrameGetSnapPosition(frame:GetLeft()), baseModule.MoveFrameGetSnapPosition(frame:GetTop())) frame.MoveFrameUpdateText(frame, true) end -function baseModul.MoveFrameUpdateText(frame, position) +function baseModule.MoveFrameUpdateText(frame, position) local labelTextTopLeft = "" frame.labelCenter:SetText(string.format("%s,%s", frame:GetWidth(), frame:GetHeight())) @@ -127,25 +127,25 @@ function baseModul.MoveFrameUpdateText(frame, position) frame.labelTopLeft:SetText(labelTextTopLeft) end -function baseModul.MoveFrameGetSnapPosition(value) - return (zo_round(value / baseModul.Saved.SnapSize) * baseModul.Saved.SnapSize) +function baseModule.MoveFrameGetSnapPosition(value) + return (zo_round(value / baseModule.Saved.SnapSize) * baseModule.Saved.SnapSize) end -function baseModul.MoveFrameStorePosition(frame) - baseModul.Saved.Top = frame.MoveFrameGetSnapPosition(frame:GetTop()) - baseModul.Saved.Left = frame.MoveFrameGetSnapPosition(frame:GetLeft()) +function baseModule.MoveFrameStorePosition(frame) + baseModule.Saved.Top = frame.MoveFrameGetSnapPosition(frame:GetTop()) + baseModule.Saved.Left = frame.MoveFrameGetSnapPosition(frame:GetLeft()) end -function baseModul.MoveFrameAnchorToTarget(frame, target) +function baseModule.MoveFrameAnchorToTarget(frame, target) frame:ClearAnchors() frame:SetDimensions(target:GetWidth(), target:GetHeight()) frame:SetAnchor(TOPLeft, GuiRoot, TOPLeft, target:GetLeft(), target:GetTop()) end -function baseModul.MoveFrameUpdateColor(frame) - local centerColor = baseModul.Saved.CenterColor - local edgeColor = baseModul.Saved.EdgeColor - local fontColor = baseModul.Saved.FontColor +function baseModule.MoveFrameUpdateColor(frame) + local centerColor = baseModule.Saved.CenterColor + local edgeColor = baseModule.Saved.EdgeColor + local fontColor = baseModule.Saved.FontColor frame.overlay:SetCenterColor(centerColor.r, centerColor.g, centerColor.b, centerColor.a) frame.overlay:SetEdgeColor(edgeColor.r, edgeColor.g, edgeColor.b, edgeColor.a)