diff --git a/Changelog b/Changelog index eb72380..314575a 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,11 @@ ------------------------------------------------------------------------------- -Summon Assistant +Memento bar ------------------------------------------------------------------------------- +Version 1.7.0 (06-05-2018) +- Mainstreamed code base in MementoBar and SummonAssistant. +- Split shared code into seperate library: "LibJarthSharedBase". +-- Should make it easier to maintain, and might reduce memory usage. + Version 1.6.2 (18-03-2018) - Updated visibility fragments to support: -- hud diff --git a/Libs/LibAddonMenu-2.0.txt b/Libs/LibAddonMenu-2.0.txt deleted file mode 100644 index b2a7a42..0000000 --- a/Libs/LibAddonMenu-2.0.txt +++ /dev/null @@ -1,32 +0,0 @@ -## APIVersion: 100020 100021 -## Title: LibAddonMenu-2.0 -## Version: 2.0 r25 -## AddOnVersion: 25 -## Author: Seerah, sirinsidiator, et al. -## Contributors: votan, merlight, Garkin, Randactyl, KuroiLight, silvereyes333, Baertram, kyoma -## Description: A library to aid in the creation of option panels. -## -## This Add-on is not created by, affiliated with or sponsored by ZeniMax Media Inc. or its affiliates. -## The Elder Scrolls® and related logos are registered trademarks or trademarks of ZeniMax Media Inc. in the United States and/or other countries. -## All rights reserved -## -## You can read the full terms at https://account.elderscrollsonline.com/add-on-terms - -LibStub\LibStub.lua - -LibAddonMenu-2.0\LibAddonMenu-2.0.lua - -LibAddonMenu-2.0\controls\panel.lua -LibAddonMenu-2.0\controls\submenu.lua -LibAddonMenu-2.0\controls\button.lua -LibAddonMenu-2.0\controls\checkbox.lua -LibAddonMenu-2.0\controls\colorpicker.lua -LibAddonMenu-2.0\controls\custom.lua -LibAddonMenu-2.0\controls\description.lua -LibAddonMenu-2.0\controls\dropdown.lua -LibAddonMenu-2.0\controls\editbox.lua -LibAddonMenu-2.0\controls\header.lua -LibAddonMenu-2.0\controls\slider.lua -LibAddonMenu-2.0\controls\texture.lua -LibAddonMenu-2.0\controls\iconpicker.lua -LibAddonMenu-2.0\controls\divider.lua diff --git a/Libs/LibAddonMenu-2.0/LibAddonMenu-2.0.txt b/Libs/LibAddonMenu-2.0/LibAddonMenu-2.0.txt new file mode 100644 index 0000000..b2a7a42 --- /dev/null +++ b/Libs/LibAddonMenu-2.0/LibAddonMenu-2.0.txt @@ -0,0 +1,32 @@ +## APIVersion: 100020 100021 +## Title: LibAddonMenu-2.0 +## Version: 2.0 r25 +## AddOnVersion: 25 +## Author: Seerah, sirinsidiator, et al. +## Contributors: votan, merlight, Garkin, Randactyl, KuroiLight, silvereyes333, Baertram, kyoma +## Description: A library to aid in the creation of option panels. +## +## This Add-on is not created by, affiliated with or sponsored by ZeniMax Media Inc. or its affiliates. +## The Elder Scrolls® and related logos are registered trademarks or trademarks of ZeniMax Media Inc. in the United States and/or other countries. +## All rights reserved +## +## You can read the full terms at https://account.elderscrollsonline.com/add-on-terms + +LibStub\LibStub.lua + +LibAddonMenu-2.0\LibAddonMenu-2.0.lua + +LibAddonMenu-2.0\controls\panel.lua +LibAddonMenu-2.0\controls\submenu.lua +LibAddonMenu-2.0\controls\button.lua +LibAddonMenu-2.0\controls\checkbox.lua +LibAddonMenu-2.0\controls\colorpicker.lua +LibAddonMenu-2.0\controls\custom.lua +LibAddonMenu-2.0\controls\description.lua +LibAddonMenu-2.0\controls\dropdown.lua +LibAddonMenu-2.0\controls\editbox.lua +LibAddonMenu-2.0\controls\header.lua +LibAddonMenu-2.0\controls\slider.lua +LibAddonMenu-2.0\controls\texture.lua +LibAddonMenu-2.0\controls\iconpicker.lua +LibAddonMenu-2.0\controls\divider.lua diff --git a/Libs/LibAddonMenu-2.0/exampleoptions.lua b/Libs/LibAddonMenu-2.0/exampleoptions.lua new file mode 100644 index 0000000..3b02d44 --- /dev/null +++ b/Libs/LibAddonMenu-2.0/exampleoptions.lua @@ -0,0 +1,119 @@ +local panelData = { + type = "panel", + name = "Window Title", + displayName = "Longer Window Title", + author = "Seerah", + version = "1.3", + slashCommand = "/myaddon", --(optional) will register a keybind to open to this panel + registerForRefresh = true, --boolean (optional) (will refresh all options controls when a setting is changed and when the panel is shown) + registerForDefaults = true, --boolean (optional) (will set all options controls back to default values) +} + +local optionsTable = { + [1] = { + type = "header", + name = "My Header", + width = "full", --or "half" (optional) + }, + [2] = { + type = "description", + --title = "My Title", --(optional) + title = nil, --(optional) + text = "My description text to display. blah blah blah blah blah blah blah - even more sample text!!", + width = "full", --or "half" (optional) + }, + [3] = { + type = "dropdown", + name = "My Dropdown", + tooltip = "Dropdown's tooltip text.", + choices = {"table", "of", "choices"}, + getFunc = function() return "of" end, + setFunc = function(var) print(var) end, + width = "half", --or "half" (optional) + warning = "Will need to reload the UI.", --(optional) + }, + [4] = { + type = "dropdown", + name = "My Dropdown", + tooltip = "Dropdown's tooltip text.", + choices = {"table", "of", "choices"}, + getFunc = function() return "of" end, + setFunc = function(var) print(var) end, + width = "half", --or "half" (optional) + warning = "Will need to reload the UI.", --(optional) + }, + [5] = { + type = "slider", + name = "My Slider", + tooltip = "Slider's tooltip text.", + min = 0, + max = 20, + step = 1, --(optional) + getFunc = function() return 3 end, + setFunc = function(value) d(value) end, + width = "half", --or "half" (optional) + default = 5, --(optional) + }, + [6] = { + type = "button", + name = "My Button", + tooltip = "Button's tooltip text.", + func = function() d("button pressed!") end, + width = "half", --or "half" (optional) + warning = "Will need to reload the UI.", --(optional) + }, + [7] = { + type = "submenu", + name = "Submenu Title", + tooltip = "My submenu tooltip", --(optional) + controls = { + [1] = { + type = "checkbox", + name = "My Checkbox", + tooltip = "Checkbox's tooltip text.", + getFunc = function() return true end, + setFunc = function(value) d(value) end, + width = "half", --or "half" (optional) + warning = "Will need to reload the UI.", --(optional) + }, + [2] = { + type = "colorpicker", + name = "My Color Picker", + tooltip = "Color Picker's tooltip text.", + getFunc = function() return 1, 0, 0, 1 end, --(alpha is optional) + setFunc = function(r,g,b,a) print(r, g, b, a) end, --(alpha is optional) + width = "half", --or "half" (optional) + warning = "warning text", + }, + [3] = { + type = "editbox", + name = "My Editbox", + tooltip = "Editbox's tooltip text.", + getFunc = function() return "this is some text" end, + setFunc = function(text) print(text) end, + isMultiline = false, --boolean + width = "half", --or "half" (optional) + warning = "Will need to reload the UI.", --(optional) + default = "", --(optional) + }, + }, + }, + [8] = { + type = "custom", + reference = "MyAddonCustomControl", --unique name for your control to use as reference + refreshFunc = function(customControl) end, --(optional) function to call when panel/controls refresh + width = "half", --or "half" (optional) + }, + [9] = { + type = "texture", + image = "EsoUI\\Art\\ActionBar\\abilityframe64_up.dds", + imageWidth = 64, --max of 250 for half width, 510 for full + imageHeight = 64, --max of 100 + tooltip = "Image's tooltip text.", --(optional) + width = "half", --or "half" (optional) + }, +} + +local LAM = LibStub("LibAddonMenu-2.0") +LAM:RegisterAddonPanel("MyAddon", panelData) +LAM:RegisterOptionControls("MyAddon", optionsTable) diff --git a/Libs/LibJarthSharedBase/LibJarthSharedBase.lua b/Libs/LibJarthSharedBase/LibJarthSharedBase.lua new file mode 100644 index 0000000..53355fe --- /dev/null +++ b/Libs/LibJarthSharedBase/LibJarthSharedBase.lua @@ -0,0 +1,31 @@ +--[[ +Author: Jarth +Filename: LibJarthSharedBase.lua +]] -- + +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +JarthSharedBase = {} +local sharedBaseModule = JarthSharedBase + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +------------------------------------------------------------------------------------------------- +function sharedBaseModule:RestorePosition(baseModule, frame) + local Top = baseModule.Saved.Top + local Left = baseModule.Saved.Left + + frame:ClearAnchors() + frame:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, Left, Top) +end + +function sharedBaseModule:GetVersion(baseModule, showMinor) + if showMinor == false or ADDON_MINOR_VERSION == nil then + return tostring(baseModule.Addon.Version) + end + + return tostring(baseModule.Addon.Version) .. "." .. tostring(baseModule.Addon.MinorVersion) +end + + diff --git a/Libs/LibJarthSharedBase/LibJarthSharedBase.txt b/Libs/LibJarthSharedBase/LibJarthSharedBase.txt new file mode 100644 index 0000000..60c6831 --- /dev/null +++ b/Libs/LibJarthSharedBase/LibJarthSharedBase.txt @@ -0,0 +1,23 @@ +; This Add-on is not created by, affiliated with or sponsored by ZeniMax +; Media Inc. or its affiliates. The Elder Scrolls® and related logos are +; registered trademarks or trademarks of ZeniMax Media Inc. in the United +; States and/or other countries. All rights reserved. +; You can read the full terms at https://account.elderscrollsonline.com/add-on-terms + +## APIVersion: 100022 100023 +## Title: LibJarthSharedBase +## Version: 1.0.1 +## Author: Jarth +## Description: LibJarthSharedBase +## +## This Add-on is not created by, affiliated with or sponsored by ZeniMax Media Inc. or its affiliates. +## The Elder Scrolls® and related logos are registered trademarks or trademarks of ZeniMax Media Inc. in the United States and/or other countries. +## All rights reserved +## +## You can read the full terms at https://account.elderscrollsonline.com/add-on-terms + +libs\LibJarthSharedBase\LibJarthSharedBase.lua +libs\LibJarthSharedBase\LibJarthSharedBase_Hotkeys.lua +libs\LibJarthSharedBase\LibJarthSharedBase_Fragments.lua +libs\LibJarthSharedBase\LibJarthSharedBase_Move.lua +libs\LibJarthSharedBase\LibJarthSharedBase_Buttons.lua \ No newline at end of file diff --git a/Libs/LibJarthSharedBase/LibJarthSharedBase_Buttons.lua b/Libs/LibJarthSharedBase/LibJarthSharedBase_Buttons.lua new file mode 100644 index 0000000..ccecba6 --- /dev/null +++ b/Libs/LibJarthSharedBase/LibJarthSharedBase_Buttons.lua @@ -0,0 +1,109 @@ +--[[ +Author: Jarth +Filename: LibJarthSharedBase_Buttons.lua +]] -- + +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local sharedBaseModule = JarthSharedBase + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +------------------------------------------------------------------------------------------------- +function sharedBaseModule:SetFrameSettings(frame, isHidden, height, width) + if frame ~= nil then + frame:SetHidden(isHidden) + frame:SetHeight(height) + frame:SetWidth(width) + end +end + +function sharedBaseModule.ButtonHighlightEnter(frame) + local highlightColor = frame.Saved.HighlightColor + local buttonBackdrop = GetControl(frame, "Backdrop") + + if buttonBackdrop ~= nil then + if frame.Saved.IsAudioEnabled then + PlaySound(SOUNDS.QUICKSLOT_MOUSEOVER) + end + + buttonBackdrop:SetEdgeColor(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a) + end +end + +function sharedBaseModule.ButtonHighlightExit(frame) + local edgeColor = frame.Saved.EdgeColor + local buttonBackdrop = GetControl(frame, "Backdrop") + + if buttonBackdrop ~= nil then + buttonBackdrop:SetEdgeColor(edgeColor.r, edgeColor.g, edgeColor.b, edgeColor.a) + end +end + +function sharedBaseModule:GetButtonPosition(baseModule, index) + local left = baseModule.Saved.Width * ((index - 1) % baseModule.Saved.BarDepth) + local top = baseModule.Saved.Height * (math.floor((index - 1) / baseModule.Saved.BarDepth)) + + if not baseModule.Saved.Horizontal then + left = baseModule.Saved.Width * (math.floor((index - 1) / baseModule.Saved.BarDepth)) + top = baseModule.Saved.Height * ((index - 1) % baseModule.Saved.BarDepth) + end + + return left, top +end + +function sharedBaseModule:SetupButton(baseModule, key, left, top, position) + local button = baseModule.Buttons[key] + button:ClearAnchors() + button:SetAnchor(position, baseModule.Frame, position, left, top) + button:SetHeight(baseModule.Saved.Height) + button:SetWidth(baseModule.Saved.Width) + button:SetHidden(false) +end + +function sharedBaseModule:SetupButtonBinding(baseModule, key) + local button = baseModule.Buttons[key] + local buttonBinding = GetControl(button, "Binding") + + if buttonBinding ~= nil and baseModule.Saved.ShowKeyBinding then + sharedBaseModule:HotkeyUpdateColor(baseModule, buttonBinding) + buttonBinding:SetText(sharedBaseModule:HotkeyGetKey(baseModule, key)) + buttonBinding:SetDrawLevel(3) + buttonBinding:ClearAnchors() + buttonBinding:SetAnchor(baseModule.Saved.KeyBindingLocation, button, baseModule.Saved.KeyBindingLocation, 0, 0) + end + + if buttonBinding ~= nil then + buttonBinding:SetHidden(not baseModule.Saved.ShowKeyBinding) + end +end + +function sharedBaseModule:SetupButtonTexture(baseModule, key, left, top, collection, position) + local button = baseModule.Buttons[key] + local buttonTexture = GetControl(button, "Texture") + + if buttonTexture ~= nil then + button:SetHandler("OnClicked", baseModule.ButtonOnClicked) + buttonTexture:SetDrawLevel(3) + buttonTexture:SetTexture(collection[key].EnabledTexture) + buttonTexture:ClearAnchors() + buttonTexture:SetAnchor(position, baseModule.Frame, position, left + baseModule.Saved.Margin, top + baseModule.Saved.Margin) + buttonTexture:SetHeight(button:GetHeight() - (2 * baseModule.Saved.Margin)) + buttonTexture:SetWidth(button:GetWidth() - (2 * baseModule.Saved.Margin)) + end +end + +function sharedBaseModule:SetupButtonBackdrop(baseModule, key, left, top, position) + local button = baseModule.Buttons[key] + local buttonBackdrop = GetControl(button, "Backdrop") + + if buttonBackdrop ~= nil then + buttonBackdrop:SetDrawLevel(2) + buttonBackdrop:SetEdgeTexture(nil, 1, 1, baseModule.Saved.Margin) + buttonBackdrop:ClearAnchors() + buttonBackdrop:SetAnchor(position, baseModule.Frame, position, left, top) + buttonBackdrop:SetHeight(button:GetHeight()) + buttonBackdrop:SetWidth(button:GetWidth()) + end +end diff --git a/Libs/LibJarthSharedBase/LibJarthSharedBase_Fragments.lua b/Libs/LibJarthSharedBase/LibJarthSharedBase_Fragments.lua new file mode 100644 index 0000000..3df6d24 --- /dev/null +++ b/Libs/LibJarthSharedBase/LibJarthSharedBase_Fragments.lua @@ -0,0 +1,54 @@ +--[[ +Author: Jarth +Filename: LibJarthSharedBase_Fragments.lua +]] -- + +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local sharedBaseModule = JarthSharedBase + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +------------------------------------------------------------------------------------------------- +function JarthSharedBase.HelperSetFragmentBehaviour(value, scene, fragment, statement, isHidden) + if scene ~= nil then + if value then + if not scene:HasFragment(fragment) then + scene:AddFragment(fragment) + end + -- Case when landing on a scene, before a transition + if statement then + isHidden = false + end + else + scene:RemoveFragment(fragment) + end + end + return isHidden +end +------------------------------------------------------------------------------------------------- +-- PRIVATE FUNCTIONS -- +------------------------------------------------------------------------------------------------- +function JarthSharedBase:SetFragmentBehaviour(frame, saved, fragment, isVisible) + local isHidden = true + local currentScene = SCENE_MANAGER:GetCurrentScene() + local currentSceneIsGameMenuInGame = currentScene ~= nil and currentScene:GetName() == "gameMenuInGame" + + if fragment == nil then + fragment = ZO_HUDFadeSceneFragment:New(frame) + end + + isHidden = sharedBaseModule.HelperSetFragmentBehaviour(saved.ShowBarOnHud, HUD_SCENE, fragment, currentScene == nil, isHidden) + isHidden = sharedBaseModule.HelperSetFragmentBehaviour(saved.ShowBarOnHudUI, HUD_UI_SCENE, fragment, false, isHidden) + isHidden = sharedBaseModule.HelperSetFragmentBehaviour(saved.ShowBarInMenu, SCENE_MANAGER:GetScene("gameMenuInGame"), fragment, currentSceneIsGameMenuInGame, isHidden) + isHidden = sharedBaseModule.HelperSetFragmentBehaviour(saved.ShowBarInInventory, SCENE_MANAGER:GetScene("inventory"), fragment, false, isHidden) + isHidden = sharedBaseModule.HelperSetFragmentBehaviour(saved.ShowBarInInteract, SCENE_MANAGER:GetScene("interact"), fragment, false, isHidden) + isHidden = sharedBaseModule.HelperSetFragmentBehaviour(saved.ShowBarInBank, SCENE_MANAGER:GetScene("bank"), fragment, false, isHidden) + isHidden = sharedBaseModule.HelperSetFragmentBehaviour(saved.ShowBarInFence, SCENE_MANAGER:GetScene("fence_keyboard"), fragment, false, isHidden) + isHidden = sharedBaseModule.HelperSetFragmentBehaviour(saved.ShowBarInStore, SCENE_MANAGER:GetScene("store"), fragment, false, isHidden) + + frame:SetHidden(isHidden and not isVisible) + + return fragment +end diff --git a/Libs/LibJarthSharedBase/LibJarthSharedBase_Hotkeys.lua b/Libs/LibJarthSharedBase/LibJarthSharedBase_Hotkeys.lua new file mode 100644 index 0000000..ec7aa26 --- /dev/null +++ b/Libs/LibJarthSharedBase/LibJarthSharedBase_Hotkeys.lua @@ -0,0 +1,114 @@ +--[[ +Author: Jarth +Filename: MementoBar_Hotkeys.lua +]] -- + +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local sharedBaseModule = JarthSharedBase + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +------------------------------------------------------------------------------------------------- +function sharedBaseModule: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 sharedBaseModule:HotkeyUpdate(baseModule, newKeyId, newCollectibleId) + baseModule.Global.ReverseKeyBindings = {} + + for keyId, collectibleId in ipairs(baseModule.Saved.KeyBindings) do + if newCollectibleId and newKeyId == keyId then + baseModule.Saved.KeyBindings[keyId] = newCollectibleId + baseModule.Global.ReverseKeyBindings[newCollectibleId] = keyId + elseif newCollectibleId == collectibleId and newKeyId ~= keyId then + baseModule.Saved.KeyBindings[keyId] = 0 + elseif collectibleId > 0 and not baseModule.Saved.SelectedMementos[collectibleId] then + baseModule.Saved.KeyBindings[keyId] = 0 + elseif collectibleId > 0 then + baseModule.Global.ReverseKeyBindings[collectibleId] = keyId + end + end +end + +function sharedBaseModule:HotkeyUpdateColor(baseModule, frame) + local fontColor = baseModule.Saved.FontColor + + frame:SetColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a) +end + +function sharedBaseModule: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 sharedBaseModule: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 + +function sharedBaseModule:HotkeyGetKey(baseModule, keyBinding) + local result = "" + keyBinding = baseModule.Global.ReverseKeyBindings and baseModule.Global.ReverseKeyBindings[keyBinding] or keyBinding + + if keyBinding then + local keyBindingTable = {GetHighestPriorityActionBindingInfoFromName(baseModule.Addon.Name .. "_" .. keyBinding)} + + for _, keyValue in pairs(keyBindingTable) do + if keyValue > 0 then + result = sharedBaseModule:HotkeyGetKeyName(result, keyValue) + end + end + end + return result +end diff --git a/Libs/LibJarthSharedBase/LibJarthSharedBase_Move.lua b/Libs/LibJarthSharedBase/LibJarthSharedBase_Move.lua new file mode 100644 index 0000000..388c1af --- /dev/null +++ b/Libs/LibJarthSharedBase/LibJarthSharedBase_Move.lua @@ -0,0 +1,154 @@ +--[[ +Author: Jarth +Filename: LibJarthSharedBase_Move.lua +]] -- + +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local sharedBaseModule = JarthSharedBase + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +------------------------------------------------------------------------------------------------- +function sharedBaseModule:UpdateMoveFrame(baseModule, targetFrame) + local moveFrame = baseModule.MoveFrame + local onMouseEnter, onMouseExit, onMouseDown, onMouseUp = nil, nil, nil, nil + + if baseModule.Global.IsMoveEnabled then + moveFrame = sharedBaseModule.GetOrCreateMoveFrame(baseModule, targetFrame) + onMouseEnter = sharedBaseModule.MoveFrameOnEnter + onMouseExit = sharedBaseModule.MoveFrameOnExit + onMouseDown = sharedBaseModule.MoveFrameOnDown + onMouseUp = sharedBaseModule.MoveFrameOnUp + end + + if moveFrame then + moveFrame:SetHandler("OnMouseEnter", onMouseEnter) + moveFrame:SetHandler("OnMouseExit", onMouseExit) + moveFrame:SetHandler("OnMouseDown", onMouseDown) + moveFrame:SetHandler("OnMouseUp", onMouseUp) + 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) + end +end + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +-- Move handlers -- +------------------------------------------------------------------------------------------------- +function sharedBaseModule.GetOrCreateMoveFrame(baseModule, targetFrame) + if baseModule.MoveFrame == nil then + local newMoveFrame = baseModule.WM:CreateControlFromVirtual(nil, GuiRoot, baseModule.Addon.Name .. "_MoveFrame") + + --Variable is used to define what savedVariable the Frame refers to. + newMoveFrame.TargetFrame = targetFrame + newMoveFrame.Saved = baseModule.Saved + + newMoveFrame["MoveFrameAnchorToTarget"] = sharedBaseModule.MoveFrameAnchorToTarget + newMoveFrame["MoveFrameGetSnapPosition"] = sharedBaseModule.MoveFrameGetSnapPosition + newMoveFrame["MoveFrameUpdateText"] = sharedBaseModule.MoveFrameUpdateText + newMoveFrame["MoveFrameUpdateColor"] = sharedBaseModule.MoveFrameUpdateColor + newMoveFrame["MoveFrameOnUpdate"] = sharedBaseModule.MoveFrameOnUpdate + newMoveFrame["MoveFrameStorePosition"] = sharedBaseModule.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 = baseModule.WM:CreateControl(nil, newMoveFrame, CT_BACKDROP) + newMoveFrame.overlay:SetDrawLevel(2) + newMoveFrame.overlay:SetAnchorFill(targetFrame) + newMoveFrame.overlay:SetEdgeTexture("", 8, 1, 0) + -- 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 = 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) + + baseModule.MoveFrame = newMoveFrame + end + + return baseModule.MoveFrame +end + +function sharedBaseModule.MoveFrameOnEnter(frame) + frame.MoveFrameUpdateText(frame, true) +end + +function sharedBaseModule.MoveFrameOnExit(frame) + frame.MoveFrameUpdateText(frame, false) +end + +function sharedBaseModule.MoveFrameOnDown(frame) + frame:SetHandler("OnUpdate", frame.MoveFrameOnUpdate) +end + +function sharedBaseModule.MoveFrameOnUp(frame) + frame.MoveFrameOnUpdate(frame) + frame.MoveFrameUpdateText(frame, false) + frame:SetHandler("OnUpdate", nil) + frame.MoveFrameStorePosition(frame) +end + +function sharedBaseModule.MoveFrameOnUpdate(frame) + frame.TargetFrame:ClearAnchors() + frame.TargetFrame:SetAnchor(TOPLeft, GuiRoot, TOPLeft, sharedBaseModule.MoveFrameGetSnapPosition(frame, frame:GetLeft()), sharedBaseModule.MoveFrameGetSnapPosition(frame, frame:GetTop())) + frame.MoveFrameUpdateText(frame, true) +end + +function sharedBaseModule.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 sharedBaseModule.MoveFrameGetSnapPosition(frame, value) + return (zo_round(value / frame.Saved.SnapSize) * frame.Saved.SnapSize) +end + +function sharedBaseModule.MoveFrameStorePosition(frame) + frame.Saved.Top = frame.MoveFrameGetSnapPosition(frame, frame:GetTop()) + frame.Saved.Left = frame.MoveFrameGetSnapPosition(frame, frame:GetLeft()) +end + +function sharedBaseModule.MoveFrameAnchorToTarget(frame, target) + frame:ClearAnchors() + frame:SetDimensions(target:GetWidth(), target:GetHeight()) + frame:SetAnchor(TOPLeft, GuiRoot, TOPLeft, target:GetLeft(), target:GetTop()) +end + +function sharedBaseModule.MoveFrameUpdateColor(frame) + local centerColor = frame.Saved.CenterColor + local edgeColor = frame.Saved.EdgeColor + local fontColor = frame.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 diff --git a/Libs/exampleoptions.lua b/Libs/exampleoptions.lua deleted file mode 100644 index 3b02d44..0000000 --- a/Libs/exampleoptions.lua +++ /dev/null @@ -1,119 +0,0 @@ -local panelData = { - type = "panel", - name = "Window Title", - displayName = "Longer Window Title", - author = "Seerah", - version = "1.3", - slashCommand = "/myaddon", --(optional) will register a keybind to open to this panel - registerForRefresh = true, --boolean (optional) (will refresh all options controls when a setting is changed and when the panel is shown) - registerForDefaults = true, --boolean (optional) (will set all options controls back to default values) -} - -local optionsTable = { - [1] = { - type = "header", - name = "My Header", - width = "full", --or "half" (optional) - }, - [2] = { - type = "description", - --title = "My Title", --(optional) - title = nil, --(optional) - text = "My description text to display. blah blah blah blah blah blah blah - even more sample text!!", - width = "full", --or "half" (optional) - }, - [3] = { - type = "dropdown", - name = "My Dropdown", - tooltip = "Dropdown's tooltip text.", - choices = {"table", "of", "choices"}, - getFunc = function() return "of" end, - setFunc = function(var) print(var) end, - width = "half", --or "half" (optional) - warning = "Will need to reload the UI.", --(optional) - }, - [4] = { - type = "dropdown", - name = "My Dropdown", - tooltip = "Dropdown's tooltip text.", - choices = {"table", "of", "choices"}, - getFunc = function() return "of" end, - setFunc = function(var) print(var) end, - width = "half", --or "half" (optional) - warning = "Will need to reload the UI.", --(optional) - }, - [5] = { - type = "slider", - name = "My Slider", - tooltip = "Slider's tooltip text.", - min = 0, - max = 20, - step = 1, --(optional) - getFunc = function() return 3 end, - setFunc = function(value) d(value) end, - width = "half", --or "half" (optional) - default = 5, --(optional) - }, - [6] = { - type = "button", - name = "My Button", - tooltip = "Button's tooltip text.", - func = function() d("button pressed!") end, - width = "half", --or "half" (optional) - warning = "Will need to reload the UI.", --(optional) - }, - [7] = { - type = "submenu", - name = "Submenu Title", - tooltip = "My submenu tooltip", --(optional) - controls = { - [1] = { - type = "checkbox", - name = "My Checkbox", - tooltip = "Checkbox's tooltip text.", - getFunc = function() return true end, - setFunc = function(value) d(value) end, - width = "half", --or "half" (optional) - warning = "Will need to reload the UI.", --(optional) - }, - [2] = { - type = "colorpicker", - name = "My Color Picker", - tooltip = "Color Picker's tooltip text.", - getFunc = function() return 1, 0, 0, 1 end, --(alpha is optional) - setFunc = function(r,g,b,a) print(r, g, b, a) end, --(alpha is optional) - width = "half", --or "half" (optional) - warning = "warning text", - }, - [3] = { - type = "editbox", - name = "My Editbox", - tooltip = "Editbox's tooltip text.", - getFunc = function() return "this is some text" end, - setFunc = function(text) print(text) end, - isMultiline = false, --boolean - width = "half", --or "half" (optional) - warning = "Will need to reload the UI.", --(optional) - default = "", --(optional) - }, - }, - }, - [8] = { - type = "custom", - reference = "MyAddonCustomControl", --unique name for your control to use as reference - refreshFunc = function(customControl) end, --(optional) function to call when panel/controls refresh - width = "half", --or "half" (optional) - }, - [9] = { - type = "texture", - image = "EsoUI\\Art\\ActionBar\\abilityframe64_up.dds", - imageWidth = 64, --max of 250 for half width, 510 for full - imageHeight = 64, --max of 100 - tooltip = "Image's tooltip text.", --(optional) - width = "half", --or "half" (optional) - }, -} - -local LAM = LibStub("LibAddonMenu-2.0") -LAM:RegisterAddonPanel("MyAddon", panelData) -LAM:RegisterOptionControls("MyAddon", optionsTable) diff --git a/SummonAssistant.lua b/SummonAssistant.lua index 7413c4e..aed5a7d 100644 --- a/SummonAssistant.lua +++ b/SummonAssistant.lua @@ -7,6 +7,7 @@ Filename: SummonAssistant.lua -- VARIABLES -- ------------------------------------------------------------------------------------------------- local baseModule = SummonAssistant +local sharedBaseModule = JarthSharedBase ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- @@ -25,8 +26,8 @@ function baseModule.Initialize() baseModule.Saved = ZO_SavedVars:NewAccountWide("SummonAssistant_Account", baseModule.Addon.Version, nil, baseModule.Default) end - baseModule:RestorePanel() - baseModule:HoykeyCreateSelections() + baseModule:RestorePanel(baseModule.Frame) + baseModule:HotkeyCreateSelections() baseModule:CreateSettingsWindow() EVENT_MANAGER:UnregisterForEvent(baseModule.Addon.Name, EVENT_ADD_ON_LOADED) @@ -35,29 +36,13 @@ end ------------------------------------------------------------------------------------------------- -- PRIVATE FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function baseModule:GetVersion(showMinor) - if showMinor == false or baseModule.Addon.MinorVersion == nil then - return tostring(baseModule.Addon.Version) - end - - return tostring(baseModule.Addon.Version) .. "." .. tostring(baseModule.Addon.MinorVersion) -end - -function baseModule:RestorePanel() - baseModule:SetButtonFrameWidth() - baseModule:InitializeButtons() - baseModule:ButtonsBackdropColor() - baseModule:RestorePosition() - baseModule:UpdateMoveFrame() - baseModule:SetFragmentBehaviour() -end - -function baseModule:RestorePosition() - local Top = baseModule.Saved.Top - local Left = baseModule.Saved.Left - - SummonAssistant_Frame:ClearAnchors() - SummonAssistant_Frame:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, Left, Top) +function baseModule:RestorePanel(frame) + baseModule:SetButtonFrameWidth(baseModule.Saved.ShowAssistants) + baseModule:InitializeButtons(frame, baseModule.OrderedTypes) + baseModule:RestoreButtons(baseModule.OrderedTypes) + sharedBaseModule:RestorePosition(baseModule, frame) + sharedBaseModule:UpdateMoveFrame(baseModule, frame) + baseModule.Fragment = sharedBaseModule:SetFragmentBehaviour(frame, baseModule.Saved, baseModule.Fragment) end EVENT_MANAGER:RegisterForEvent(baseModule.Addon.Name, EVENT_ADD_ON_LOADED, baseModule.OnAddOnLoaded) diff --git a/SummonAssistant.txt b/SummonAssistant.txt index 0a0ed3d..2875f47 100644 --- a/SummonAssistant.txt +++ b/SummonAssistant.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: 100022 +## APIVersion: 100022 100023 ## Title: SummonAssistant -## Version: 1.6.0 +## Version: 1.7.0 ## Author: Jarth ## Description: Summon assistant, by hotkey or button! ## @@ -36,12 +36,17 @@ libs\LibAddonMenu-2.0\controls\texture.lua libs\LibAddonMenu-2.0\controls\iconpicker.lua libs\LibAddonMenu-2.0\controls\divider.lua +## OptionalDependsOn: LibJarthSharedBase +libs\LibJarthSharedBase\LibJarthSharedBase.lua +libs\LibJarthSharedBase\LibJarthSharedBase_Hotkeys.lua +libs\LibJarthSharedBase\LibJarthSharedBase_Fragments.lua +libs\LibJarthSharedBase\LibJarthSharedBase_Move.lua +libs\LibJarthSharedBase\LibJarthSharedBase_Buttons.lua + +SummonAssistant.xml SummonAssistant_Constants.lua -SummonAssistant_Fragments.lua SummonAssistant_Hotkeys.lua SummonAssistant_Menu.lua -SummonAssistant_Move.lua SummonAssistant_Buttons.lua SummonAssistant.lua -SummonAssistant.xml Bindings.xml \ No newline at end of file diff --git a/SummonAssistant_Buttons.lua b/SummonAssistant_Buttons.lua index c905ced..0f4a004 100644 --- a/SummonAssistant_Buttons.lua +++ b/SummonAssistant_Buttons.lua @@ -6,35 +6,14 @@ Filename: SummonAssistant_Buttons.lua ------------------------------------------------------------------------------------------------- -- VARIABLES -- ------------------------------------------------------------------------------------------------- -local SummonAssistant = SummonAssistant +local baseModule = SummonAssistant +local sharedBaseModule = JarthSharedBase ------------------------------------------------------------------------------------------------- -- FUNCTIONS -- -- Button highlight -- ------------------------------------------------------------------------------------------------- -function SummonAssistant.ButtonHighlightEnter(frame) - local highlightColor = SummonAssistant.Saved.HighlightColor - local buttonBackdrop = GetControl(frame, "Backdrop") - - if buttonBackdrop ~= nil then - if SummonAssistant.Saved.IsAudioEnabled then - PlaySound(SOUNDS.QUICKSLOT_MOUSEOVER) - end - - buttonBackdrop:SetEdgeColor(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a) - end -end - -function SummonAssistant.ButtonHighlightExit(frame) - local edgeColor = SummonAssistant.Saved.EdgeColor - local buttonBackdrop = GetControl(frame, "Backdrop") - - if buttonBackdrop ~= nil then - buttonBackdrop:SetEdgeColor(edgeColor.r, edgeColor.g, edgeColor.b, edgeColor.a) - end -end - -function SummonAssistant.ButtonOnClicked(button) +function baseModule.ButtonOnClicked(button) local id = button:GetId() if id > 0 then @@ -49,130 +28,61 @@ end ------------------------------------------------------------------------------------------------- -- PRIVATE FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function SummonAssistant:SetupButton(button, left, top) - button:ClearAnchors() - button:SetAnchor(TOPLEFT, SummonAssistant_Frame, TOPLEFT, left, top) - button:SetHeight(SummonAssistant.Saved.Height) - button:SetWidth(SummonAssistant.Saved.Width) - button:SetHidden(false) -end -function SummonAssistant:SetupButtonBinding(button, key, left, top) - local buttonBinding = GetControl(button, "Binding") +function baseModule:SetButtonFrameWidth(collection) + local count, height, width = 0, 0, 0 - if buttonBinding ~= nil and SummonAssistant.Saved.ShowKeyBinding then - SummonAssistant:HotkeyUpdateColor(buttonBinding) - buttonBinding:SetText(SummonAssistant:HoykeyGetKey(SummonAssistant.Types[key].Name)) - buttonBinding:SetDrawLevel(3) - buttonBinding:ClearAnchors() - buttonBinding:SetAnchor(SummonAssistant.Saved.KeyBindingLocation, button, SummonAssistant.Saved.KeyBindingLocation, 0, 0) - end - - if buttonBinding ~= nil then - buttonBinding:SetHidden(not SummonAssistant.Saved.ShowKeyBinding) - end -end - -function SummonAssistant:SetupButtonTexture(button, key, left, top) - local buttonTexture = GetControl(button, "Texture") - - if buttonTexture ~= nil then - button:SetHandler("OnClicked", SummonAssistant.ButtonOnClicked) - buttonTexture:SetDrawLevel(3) - buttonTexture:SetTexture(SummonAssistant.Types[key].EnabledTexture) - buttonTexture:ClearAnchors() - buttonTexture:SetAnchor(TOPLEFT, SummonAssistant_Frame, TOPLEFT, left + SummonAssistant.Saved.Margin, top + SummonAssistant.Saved.Margin) - buttonTexture:SetHeight(button:GetHeight() - (2 * SummonAssistant.Saved.Margin)) - buttonTexture:SetWidth(button:GetWidth() - (2 * SummonAssistant.Saved.Margin)) - end -end - -function SummonAssistant:SetupButtonBackdrop(button, key, left, top) - local buttonBackdrop = GetControl(button, "Backdrop") - - if buttonBackdrop ~= nil then - buttonBackdrop:SetDrawLevel(2) - buttonBackdrop:SetEdgeTexture(nil, 1, 1, SummonAssistant.Saved.Margin) - buttonBackdrop:ClearAnchors() - buttonBackdrop:SetAnchor(TOPLEFT, SummonAssistant_Frame, TOPLEFT, left, top) - buttonBackdrop:SetHeight(button:GetHeight()) - buttonBackdrop:SetWidth(button:GetWidth()) - end -end - -function SummonAssistant:SetButtonFrameWidth() - local count, show, height, width = 0, 0, 0, 0 - - for key, value in pairs(SummonAssistant.Saved.ShowAssistants) do - if IsCollectibleUnlocked(key) and SummonAssistant.Saved.ShowAssistants[key] then + for key, _ in pairs(collection) do + if IsCollectibleUnlocked(key) and collection[key] then count = count + 1 end end if count > 0 then - show = 1 + local depth = math.ceil(count / baseModule.Saved.BarDepth) + height = baseModule.Saved.Height * (baseModule.Saved.Horizontal and depth or baseModule.Saved.BarDepth) + width = baseModule.Saved.Width * (not baseModule.Saved.Horizontal and depth or baseModule.Saved.BarDepth) end - height = SummonAssistant.Saved.Height * (SummonAssistant.Saved.Horizontal and show or count) - width = SummonAssistant.Saved.Width * (SummonAssistant.Saved.Horizontal and count or show) - - SummonAssistant:SetFrameSettings(SummonAssistant_Frame, count == 0, height, width) - SummonAssistant:SetFrameSettings(SummonAssistant_FrameBackdrop, count == 0, height, width) + sharedBaseModule:SetFrameSettings(baseModule.Frame, count == 0, height, width) end -function SummonAssistant:SetFrameSettings(frame, isHidden, height, width) - if frame ~= nil then - frame:SetHidden(count == 0) - frame:SetHeight(height) - frame:SetWidth(width) - end -end - -function SummonAssistant:InitializeButtons() +function baseModule:InitializeButtons(frame, orderedCollection) local index = 1 - for _, _value in ipairs(SummonAssistant.OrderedTypes) do + local position = TOPLEFT + + for _, _value in ipairs(orderedCollection) do local id = _value.Id local key = _value.Name - local left, top = SummonAssistant:GetButtonPosition(index) - if SummonAssistant.Saved.ShowAssistants[id] and IsCollectibleUnlocked(_value.Id) then - if SummonAssistant.Buttons[key] == nil then - SummonAssistant.Buttons[key] = WINDOW_MANAGER:CreateControlFromVirtual("SummonAssistant_Button", SummonAssistant_Frame, "SummonAssistant_Button", key) - SummonAssistant.Buttons[key]:SetId(id) + if baseModule.Saved.ShowAssistants[id] and IsCollectibleUnlocked(_value.Id) then + if baseModule.Buttons[key] == nil then + baseModule.Buttons[key] = WINDOW_MANAGER:CreateControlFromVirtual("SummonAssistant_Button", frame, "SummonAssistant_Button", key) + baseModule.Buttons[key].Saved = baseModule.Saved + baseModule.Buttons[key]:SetId(id) end - SummonAssistant:SetupButton(SummonAssistant.Buttons[key], left, top) - SummonAssistant:SetupButtonBinding(SummonAssistant.Buttons[key], key, left, top) - SummonAssistant:SetupButtonBackdrop(SummonAssistant.Buttons[key], key, left, top) - SummonAssistant:SetupButtonTexture(SummonAssistant.Buttons[key], key, left, top) - SummonAssistant.Buttons[key]:SetHandler("OnMouseEnter", SummonAssistant.ButtonHighlightEnter) - SummonAssistant.Buttons[key]:SetHandler("OnMouseExit", SummonAssistant.ButtonHighlightExit) + local left, top = sharedBaseModule:GetButtonPosition(baseModule, index) + sharedBaseModule:SetupButton(baseModule, key, left, top, position) + sharedBaseModule:SetupButtonBinding(baseModule, key) + sharedBaseModule:SetupButtonBackdrop(baseModule, key, left, top, position) + sharedBaseModule:SetupButtonTexture(baseModule, key, left, top, baseModule.Types, position) + baseModule.Buttons[key]:SetHandler("OnMouseEnter", sharedBaseModule.ButtonHighlightEnter) + baseModule.Buttons[key]:SetHandler("OnMouseExit", sharedBaseModule.ButtonHighlightExit) index = index + 1 - elseif SummonAssistant.Buttons[key] ~= nil then - SummonAssistant.Buttons[key]:SetHidden(true) + elseif baseModule.Buttons[key] ~= nil then + baseModule.Buttons[key]:SetHidden(true) end end end -function SummonAssistant:GetButtonPosition(index) - local left = 0 - local top = SummonAssistant.Saved.Height * (index - 1) - - if SummonAssistant.Saved.Horizontal then - left = SummonAssistant.Saved.Width * (index - 1) - top = 0 - end - - return left, top -end - -function SummonAssistant:ButtonsBackdropColor() - local centerColor = SummonAssistant.Saved.CenterColor - local edgeColor = SummonAssistant.Saved.EdgeColor +function baseModule:RestoreButtons(orderedCollection) + local centerColor = baseModule.Saved.CenterColor + local edgeColor = baseModule.Saved.EdgeColor - for _, _value in ipairs(SummonAssistant.OrderedTypes) do - if SummonAssistant.Buttons[_value.Name] ~= nil then - local buttonBackdrop = GetControl(SummonAssistant.Buttons[_value.Name], "Backdrop") + for _, _value in ipairs(orderedCollection) do + if baseModule.Buttons[_value.Name] ~= nil then + local buttonBackdrop = GetControl(baseModule.Buttons[_value.Name], "Backdrop") if buttonBackdrop ~= nil then buttonBackdrop:SetCenterColor(centerColor.r, centerColor.g, centerColor.b, centerColor.a) diff --git a/SummonAssistant_Constants.lua b/SummonAssistant_Constants.lua index 75065b0..ab3b921 100644 --- a/SummonAssistant_Constants.lua +++ b/SummonAssistant_Constants.lua @@ -8,17 +8,19 @@ Filename: SummonAssistant_Constants.lua ------------------------------------------------------------------------------------------------- SummonAssistant = {} local baseModule = SummonAssistant +local sharedBaseModule = JarthSharedBase baseModule.Addon = { Name = "SummonAssistant", DisplayName = "Summon Assistant", - Version = 1.6, + Version = 1.7, MinorVersion = 0, SlashCommand = "/sa", Author = "Jarth", Website = "" } baseModule.WM = GetWindowManager() +baseModule.Frame = SummonAssistant_Frame baseModule.Buttons = {} baseModule.Fragment = nil baseModule.Default = { @@ -42,6 +44,7 @@ baseModule.Default = { Height = 60, Width = 60, SnapSize = 5, + BarDepth = 1, ShowAssistants = { [267] = IsCollectibleUnlocked(267), [300] = IsCollectibleUnlocked(300), diff --git a/SummonAssistant_Fragments.lua b/SummonAssistant_Fragments.lua deleted file mode 100644 index 63fffcc..0000000 --- a/SummonAssistant_Fragments.lua +++ /dev/null @@ -1,55 +0,0 @@ ---[[ -Author: Jarth -Filename: SummonAssistant_Fragments.lua -]] -- - -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local baseModule = SummonAssistant - -------------------------------------------------------------------------------------------------- --- Helper FUNCTIONS -- -------------------------------------------------------------------------------------------------- -function baseModule:HelperSetFragmentBehaviour(value, scene, fragment, statement, frameIsHidden) - if value then - scene:AddFragment(fragment) - - -- Case when landing on a scene, before a transition - if statement then - frameIsHidden = false - end - else - scene:RemoveFragment(fragment) - end - return frameIsHidden -end - -------------------------------------------------------------------------------------------------- --- PRIVATE FUNCTIONS -- -------------------------------------------------------------------------------------------------- -function baseModule:SetFragmentBehaviour() - local frame = SummonAssistant_Frame - local saved = baseModule.Saved - local fragment = baseModule.Fragment - local currentScene = SCENE_MANAGER:GetCurrentScene() - local frameIsHidden = true - local currentSceneIsGameMenuInGame = currentScene ~= nil and currentScene:GetName() == "gameMenuInGame" - - - if fragment == nil then - baseModule.Fragment = ZO_HUDFadeSceneFragment:New(frame) - fragment = baseModule.Fragment - end - - frameIsHidden = baseModule:HelperSetFragmentBehaviour(saved.ShowBarOnHud, HUD_SCENE, fragment, currentScene == nil, frameIsHidden) - frameIsHidden = baseModule:HelperSetFragmentBehaviour(saved.ShowBarOnHudUI, HUD_UI_SCENE, fragment, false, frameIsHidden) - frameIsHidden = baseModule:HelperSetFragmentBehaviour(saved.ShowBarInMenu, SCENE_MANAGER:GetScene("gameMenuInGame"), fragment, currentSceneIsGameMenuInGame, frameIsHidden) - frameIsHidden = baseModule:HelperSetFragmentBehaviour(saved.ShowBarInInventory, SCENE_MANAGER:GetScene("inventory"), fragment, false, frameIsHidden) - frameIsHidden = baseModule:HelperSetFragmentBehaviour(saved.ShowBarInInteract, SCENE_MANAGER:GetScene("interact"), fragment, false, frameIsHidden) - frameIsHidden = baseModule:HelperSetFragmentBehaviour(saved.ShowBarInBank, SCENE_MANAGER:GetScene("bank"), fragment, false, frameIsHidden) - frameIsHidden = baseModule:HelperSetFragmentBehaviour(saved.ShowBarInFence, SCENE_MANAGER:GetScene("fence_keyboard"), fragment, false, frameIsHidden) - frameIsHidden = baseModule:HelperSetFragmentBehaviour(saved.ShowBarInStore, SCENE_MANAGER:GetScene("store"), fragment, false, frameIsHidden) - - frame:SetHidden(frameIsHidden) -end diff --git a/SummonAssistant_Hotkeys.lua b/SummonAssistant_Hotkeys.lua index 7cc68c1..a08cf11 100644 --- a/SummonAssistant_Hotkeys.lua +++ b/SummonAssistant_Hotkeys.lua @@ -7,98 +7,16 @@ Filename: SummonAssistant_Hotkeys.lua -- VARIABLES -- ------------------------------------------------------------------------------------------------- local baseModule = SummonAssistant +local sharedBaseModule = JarthSharedBase ------------------------------------------------------------------------------------------------- -- PRIVATE FUNCTIONS -- ------------------------------------------------------------------------------------------------- -function baseModule:HoykeyCreateSelections() + +function baseModule:HotkeyCreateSelections() for _, _value in ipairs(baseModule.OrderedTypes) do if IsCollectibleUnlocked(_value.Id) then ZO_CreateStringId(_value.KeyBinding, _value.Name) end end end - -function baseModule:HoykeyGetKey(keyBinding) - local result = "" - - if keyBinding then - local keyBindingTable = {GetHighestPriorityActionBindingInfoFromName("SummonAssistant_" .. keyBinding)} - - for _, keyValue in pairs(keyBindingTable) do - if keyValue > 0 then - result = baseModule:HotkeyGetKeyName(result, keyValue) - end - end - end - return result -end - -function baseModule: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 baseModule:HotkeyUpdateColor(frame) - local fontColor = baseModule.Saved.FontColor - - frame:SetColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a) -end - -function baseModule: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 baseModule: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/SummonAssistant_Menu.lua b/SummonAssistant_Menu.lua index 5ab0e69..21228e9 100644 --- a/SummonAssistant_Menu.lua +++ b/SummonAssistant_Menu.lua @@ -12,6 +12,7 @@ local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0") -- VARIABLES -- ------------------------------------------------------------------------------------------------- local baseModule = SummonAssistant +local sharedBaseModule = JarthSharedBase ------------------------------------------------------------------------------------------------- -- Menu Functions -- @@ -22,7 +23,7 @@ function baseModule:CreateSettingsWindow() name = baseModule.Addon.DisplayName, displayName = baseModule.Addon.DisplayName, author = baseModule.Addon.Author, - version = baseModule:GetVersion(true), + version = sharedBaseModule:GetVersion(baseModule, true), slashCommand = baseModule.Addon.SlashCommand, registerForRefresh = true, registerForDefaults = true @@ -53,7 +54,7 @@ function baseModule:CreateSettingsWindow() baseModule.Saved = ZO_SavedVars:New("SummonAssistant_Character", baseModule.Addon.Version, nil, baseModule.Default) end baseModule.Saved.UseAccountSettings = newValue - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end }, [4] = { @@ -64,6 +65,20 @@ function baseModule:CreateSettingsWindow() [1] = { type = "description", text = "Choose what assistant buttons you want to see." + }, + [2] = { + type = "slider", + name = "Choose bar depth (number of rows/columns)", -- or string id or function returning a string + default = baseModule.Default.BarDepth, + getFunc = function() + return baseModule.Saved.BarDepth + end, + setFunc = function(value) + baseModule.Saved.BarDepth = value + baseModule:RestorePanel(baseModule.Frame) + end, + min = 1, + max = 3 -- TODO: Add calculation for max assistants } } }, @@ -101,7 +116,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(newValue) baseModule.Global.IsMoveEnabled = newValue - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end }, [3] = { @@ -114,7 +129,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(newValue) baseModule.Saved.Horizontal = newValue - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end }, [4] = { @@ -127,7 +142,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(value) baseModule.Saved.Margin = value - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end, min = 1, max = 50 @@ -141,7 +156,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(value) baseModule.Saved.Height = value - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end, min = 1, max = 100 @@ -155,7 +170,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(value) baseModule.Saved.Width = value - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end, min = 1, max = 100 @@ -169,7 +184,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(value) baseModule.Saved.SnapSize = value - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end, min = 1, max = 10 @@ -184,7 +199,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(newValue) baseModule.Saved.ShowKeyBinding = newValue - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end, width = "half" }, @@ -198,11 +213,11 @@ function baseModule:CreateSettingsWindow() return not baseModule.Saved.ShowKeyBinding end, getFunc = function() - return baseModule:HotKeyGetLocationText(baseModule.Saved.KeyBindingLocation) + return sharedBaseModule:HotKeyGetLocationText(baseModule.Saved.KeyBindingLocation) end, setFunc = function(value) - baseModule.Saved.KeyBindingLocation = baseModule:HotKeyGetLocationValue(value) - baseModule:RestorePanel() + baseModule.Saved.KeyBindingLocation = sharedBaseModule:HotKeyGetLocationValue(value) + baseModule:RestorePanel(baseModule.Frame) end, width = "half" } @@ -229,7 +244,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(r, g, b, a) baseModule.Saved.CenterColor = {r = r, g = g, b = b, a = a} - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end, width = "half" }, @@ -245,7 +260,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(r, g, b, a) baseModule.Saved.EdgeColor = {r = r, g = g, b = b, a = a} - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end, width = "half" }, @@ -261,7 +276,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(r, g, b, a) baseModule.Saved.HighlightColor = {r = r, g = g, b = b, a = a} - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end, width = "half" }, @@ -275,7 +290,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(r, g, b, a) baseModule.Saved.FontColor = {r = r, g = g, b = b, a = a} - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end, width = "half" } @@ -321,7 +336,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(newValue) baseModule.Saved.ShowBarOnHud = newValue - baseModule:SetFragmentBehaviour() + baseModule.Fragment = sharedBaseModule:SetFragmentBehaviour(baseModule.Frame, baseModule.Saved, baseModule.Fragment) end }, [2] = { @@ -334,7 +349,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(newValue) baseModule.Saved.ShowBarOnHudUI = newValue - baseModule:SetFragmentBehaviour() + baseModule.Fragment = sharedBaseModule:SetFragmentBehaviour(baseModule.Frame, baseModule.Saved, baseModule.Fragment) end }, [3] = { @@ -347,7 +362,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(newValue) baseModule.Saved.ShowBarInMenu = newValue - baseModule:SetFragmentBehaviour() + baseModule.Fragment = sharedBaseModule:SetFragmentBehaviour(baseModule.Frame, baseModule.Saved, baseModule.Fragment) end }, [4] = { @@ -360,7 +375,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(newValue) baseModule.Saved.ShowBarInInventory = newValue - baseModule:SetFragmentBehaviour() + baseModule.Fragment = sharedBaseModule:SetFragmentBehaviour(baseModule.Frame, baseModule.Saved, baseModule.Fragment) end }, [5] = { @@ -373,7 +388,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(newValue) baseModule.Saved.ShowBarInInteract = newValue - baseModule:SetFragmentBehaviour() + baseModule.Fragment = sharedBaseModule:SetFragmentBehaviour(baseModule.Frame, baseModule.Saved, baseModule.Fragment) end }, [6] = { @@ -386,7 +401,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(newValue) baseModule.Saved.ShowBarInBank = newValue - baseModule:SetFragmentBehaviour() + baseModule.Fragment = sharedBaseModule:SetFragmentBehaviour(baseModule.Frame, baseModule.Saved, baseModule.Fragment) end }, [7] = { @@ -399,7 +414,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(newValue) baseModule.Saved.ShowBarInFence = newValue - baseModule:SetFragmentBehaviour() + baseModule.Fragment = sharedBaseModule:SetFragmentBehaviour(baseModule.Frame, baseModule.Saved, baseModule.Fragment) end }, [8] = { @@ -412,7 +427,7 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(newValue) baseModule.Saved.ShowBarInStore = newValue - baseModule:SetFragmentBehaviour() + baseModule.Fragment = sharedBaseModule:SetFragmentBehaviour(baseModule.Frame, baseModule.Saved, baseModule.Fragment) end } } @@ -431,10 +446,10 @@ function baseModule:CreateSettingsWindow() end, setFunc = function(newValue) baseModule.Saved.ShowAssistants[_type.Id] = newValue - baseModule:RestorePanel() + baseModule:RestorePanel(baseModule.Frame) end } - table.insert(optionsData[4].controls, index + 1, line) + table.insert(optionsData[4].controls, index + 2, line) end LAM2:RegisterOptionControls(baseModule.Addon.Name, optionsData) diff --git a/SummonAssistant_Move.lua b/SummonAssistant_Move.lua deleted file mode 100644 index 301cddb..0000000 --- a/SummonAssistant_Move.lua +++ /dev/null @@ -1,155 +0,0 @@ ---[[ -Author: Jarth -Filename: SummonAssistant_Move.lua -]] -- - -------------------------------------------------------------------------------------------------- --- VARIABLES -- -------------------------------------------------------------------------------------------------- -local baseModule = SummonAssistant - -------------------------------------------------------------------------------------------------- --- FUNCTIONS -- --- Move frame -- -------------------------------------------------------------------------------------------------- -function baseModule:UpdateMoveFrame() - local moveFrame = baseModule.MoveFrame - local onMouseEnter, onMouseExit, onMouseDown, onMouseUp = nil, nil, nil, nil - - if baseModule.Global.IsMoveEnabled then - moveFrame = baseModule:GetOrCreateMoveFrame() - onMouseEnter = baseModule.MoveFrameOnEnter - onMouseExit = baseModule.MoveFrameOnExit - onMouseDown = baseModule.MoveFrameOnDown - onMouseUp = baseModule.MoveFrameOnUp - end - - if moveFrame then - moveFrame:SetHandler("OnMouseEnter", onMouseEnter) - moveFrame:SetHandler("OnMouseExit", onMouseExit) - moveFrame:SetHandler("OnMouseDown", onMouseDown) - moveFrame:SetHandler("OnMouseUp", onMouseUp) - 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) - end -end - -------------------------------------------------------------------------------------------------- --- FUNCTIONS -- --- Move handlers -- -------------------------------------------------------------------------------------------------- -function baseModule:GetOrCreateMoveFrame(show) - if baseModule.MoveFrame == nil then - local newMoveFrame = baseModule.WM:CreateControlFromVirtual(nil, GuiRoot, "SummonAssistant_MoveFrame") - local targetFrame = SummonAssistant_Frame - - --Variable is used to define what savedVariable the Frame refers to. - newMoveFrame.TargetFrame = targetFrame - - 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) - newMoveFrame:SetParent(GuiRoot) - newMoveFrame:SetMouseEnabled(true) - newMoveFrame:SetMovable(true) - newMoveFrame:SetClampedToScreen(true) - - -- overlay - 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 = 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 = 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) - - baseModule.MoveFrame = newMoveFrame - end - - return baseModule.MoveFrame -end - -function baseModule.MoveFrameOnEnter(frame) - frame.MoveFrameUpdateText(frame, true) -end - -function baseModule.MoveFrameOnExit(frame) - frame.MoveFrameUpdateText(frame, false) -end - -function baseModule.MoveFrameOnDown(frame) - frame:SetHandler("OnUpdate", frame.MoveFrameOnUpdate) -end - -function baseModule.MoveFrameOnUp(frame) - frame.MoveFrameOnUpdate(frame) - frame.MoveFrameUpdateText(frame, false) - frame:SetHandler("OnUpdate", nil) - frame.MoveFrameStorePosition(frame) -end - -function baseModule.MoveFrameOnUpdate(frame) - frame.TargetFrame:ClearAnchors() - frame.TargetFrame:SetAnchor(TOPLeft, GuiRoot, TOPLeft, baseModule.MoveFrameGetSnapPosition(frame:GetLeft()), baseModule.MoveFrameGetSnapPosition(frame:GetTop())) - frame.MoveFrameUpdateText(frame, true) -end - -function baseModule.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 baseModule.MoveFrameGetSnapPosition(value) - return (zo_round(value / baseModule.Saved.SnapSize) * baseModule.Saved.SnapSize) -end - -function baseModule.MoveFrameStorePosition(frame) - baseModule.Saved.Top = frame.MoveFrameGetSnapPosition(frame:GetTop()) - baseModule.Saved.Left = frame.MoveFrameGetSnapPosition(frame:GetLeft()) -end - -function baseModule.MoveFrameAnchorToTarget(frame, target) - frame:ClearAnchors() - frame:SetDimensions(target:GetWidth(), target:GetHeight()) - frame:SetAnchor(TOPLeft, GuiRoot, TOPLeft, target:GetLeft(), target:GetTop()) -end - -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) - frame.labelCenter:SetColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a) - frame.labelTopLeft:SetColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a) -end