diff --git a/Changelog b/Changelog index 3508fdc..0e116d6 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,16 @@ ------------------------------------------------------------------------------- Summon Assistant ------------------------------------------------------------------------------- +Version 1.4.0 (13-01-2018) +- Added functionality: Unlock the bar (the bar is by default locked) +-- An overlay will appear on the bar, showing the size and position (X,Y top left). +-- The bar is movable by dragging the overlay. +- Restructured: +-- Segmented into multiple files. +-- Split visual from frame to button. +-- Edge is now shown on the button and not the frame. +-- Added hover effects on button (Sound and visual). + Version 1.3.1 (09-01-2018) - Added sliders to set: Button margin/height/width. (It is at this time, 'not possible' to move/drag the frame, when the margin is set to 0) diff --git a/SummonAssistant.lua b/SummonAssistant.lua index 634f970..44e5d1a 100644 --- a/SummonAssistant.lua +++ b/SummonAssistant.lua @@ -1,186 +1,44 @@ --[[ Author: Jarth -Filename: SummonAssistant:lua +Filename: SummonAssistant.lua ]] -- ------------------------------------------------------------------------------------------------- --- Libraries -- +-- VARIABLES -- ------------------------------------------------------------------------------------------------- -local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0") +local SummonAssistant = SummonAssistant ------------------------------------------------------------------------------------------------- --- VARIABLE -- -------------------------------------------------------------------------------------------------- -local ADDON_NAME = "SummonAssistant" -local ADDON_DISPLAY_NAME = "Summon Assistant" -local ADDON_VERSION = 1.3 -local ADDON_MINOR_VERSION = 1 -local ADDON_AUTHOR = "Jarth" -local ADDON_WEBSITE = "" -local SummonAssistant = {} -SummonAssistant.wm = GetWindowManager() -SummonAssistant.Buttons = {} -SummonAssistant.Fragment = nil -SummonAssistant.Types = { - Banker = { - Id = 267, - Title = "Banker:", - Name = "Banker", - name = "banker", - Tooltip = "When ON the banker button will be visible. When OFF the banker button will not be visible (disabled if locked for the account).", - EnabledTexture = "/esoui/art/icons/" .. "assistant_banker_01.dds", - KeyBinding = "SI_BINDING_NAME_SummonAssistant_Assistant_Banker", - Disabled = function() - return not IsCollectibleUnlocked(267) - end - }, - Fence = { - Id = 300, - Title = "Fence:", - Name = "Fence", - name = "fence", - Tooltip = "When ON the fence button will be visible. When OFF the fence button will not be visible (disabled if locked for the account).", - EnabledTexture = "/esoui/art/icons/" .. "assistant_fence_01.dds", - KeyBinding = "SI_BINDING_NAME_SummonAssistant_Assistant_Fence", - Disabled = function() - return not IsCollectibleUnlocked(300) - end - }, - Vendor = { - Id = 301, - Title = "Vendor:", - Name = "Vendor", - name = "vendor", - Tooltip = "When ON the vendor button will be visible. When OFF the vendor button will not be visible (disabled if locked for the account).", - EnabledTexture = "/esoui/art/icons/" .. "assistant_vendor_01.dds", - KeyBinding = "SI_BINDING_NAME_SummonAssistant_Assistant_Vendor", - Disabled = function() - return not IsCollectibleUnlocked(301) - end - } -} -SummonAssistant.OrderedTypes = { - [1] = SummonAssistant.Types["Banker"], - [2] = SummonAssistant.Types["Fence"], - [3] = SummonAssistant.Types["Vendor"] -} - -SummonAssistant.Default = { - Left = CENTER, - Top = CENTER, - CenterColor = {r = 0.88, g = 0.88, b = 0.88, a = 0.4}, - EdgeColor = {r = 0.57, g = 0.57, b = 0.57, a = 0.6}, - UseAccountSettings = true, - Horizontal = true, - HideBarInMenu = true, - ShowMoveAssitance = false, - Margin = 10, - Height = 60, - Width = 60, - ShowAssistants = { - [267] = IsCollectibleUnlocked(267), - [300] = IsCollectibleUnlocked(300), - [301] = IsCollectibleUnlocked(301) - } -} ---Shows assistants by default, when unlocked. -SummonAssistant.Global = { - NumberUnlocked = GetTotalCollectiblesByCategoryType(COLLECTIBLE_CATEGORY_TYPE_ASSISTANT) -} -------------------------------------------------------------------------------------------------- --- FUNCTIONS -- +-- FUNCTIONS -- ------------------------------------------------------------------------------------------------- - function SummonAssistant.OnAddOnLoaded(event, addonName) - if addonName == ADDON_NAME then + if addonName == SummonAssistant.Addon.Name then SummonAssistant.Initialize() end end function SummonAssistant.Initialize() -- Load saved values.. - SummonAssistant.Saved = ZO_SavedVars:New("SummonAssistant_Character", ADDON_VERSION, nil, SummonAssistant.Default) + SummonAssistant.Saved = ZO_SavedVars:New("SummonAssistant_Character", SummonAssistant.Addon.Version, nil, SummonAssistant.Default) if SummonAssistant.Saved.UseAccountSettings then - SummonAssistant.Saved = ZO_SavedVars:NewAccountWide("SummonAssistant_Account", ADDON_VERSION, nil, SummonAssistant.Default) + SummonAssistant.Saved = ZO_SavedVars:NewAccountWide("SummonAssistant_Account", SummonAssistant.Addon.Version, nil, SummonAssistant.Default) end - SummonAssistant_Frame:SetHandler("OnMoveStop", SummonAssistant.OnMoveStop) SummonAssistant:RestorePanel() SummonAssistant:CreateHotkeySelections() SummonAssistant:CreateSettingsWindow() - EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED) -end - -function SummonAssistant.OnMoveStop(frame) - SummonAssistant.Saved.Top = frame:GetTop() - SummonAssistant.Saved.Left = frame:GetLeft() + EVENT_MANAGER:UnregisterForEvent(SummonAssistant.Addon.Name, EVENT_ADD_ON_LOADED) end ------------------------------------------------------------------------------------------------- --- PRIVATE FUNCTIONS -- +-- PRIVATE FUNCTIONS -- ------------------------------------------------------------------------------------------------- - function SummonAssistant:GetVersion(showMinor) - if showMinor == false or ADDON_MINOR_VERSION == nil then - return tostring(ADDON_VERSION) - end - return tostring(ADDON_VERSION) .. "." .. tostring(ADDON_MINOR_VERSION) -end - -function SummonAssistant:OnClicked(id) - if id > 0 then - if IsCollectibleUnlocked(id) then - UseCollectible(id) - else - UseCollectible(GetActiveCollectibleByType(COLLECTIBLE_CATEGORY_TYPE_ASSISTANT)) - end - end -end - -function SummonAssistant:addControlToFrame(menuOpen) - if menuOpen then - SummonAssistant_Frame:SetHidden(true) - end - - SCENE_MANAGER:GetScene("hud"):AddFragment(SummonAssistant.Fragment) - SCENE_MANAGER:GetScene("hudui"):AddFragment(SummonAssistant.Fragment) -end - -function SummonAssistant:removeControlToFrame(menuOpen) - if menuOpen then - SummonAssistant_Frame:SetHidden(false) - end - - SCENE_MANAGER:GetScene("hud"):RemoveFragment(SummonAssistant.Fragment) - SCENE_MANAGER:GetScene("hudui"):RemoveFragment(SummonAssistant.Fragment) -end - -function SummonAssistant:SetupButton(key, button, id) - local buttonTexture = SummonAssistant.wm:GetControlByName("SummonAssistant_Button" .. key .. "Texture") - if buttonTexture ~= nil then - button:SetHandler( - "OnClicked", - function(self) - SummonAssistant:OnClicked(button:GetId()) - end - ) - button:SetHeight(SummonAssistant.Saved.Height - (2 * SummonAssistant.Saved.Margin)) - button:SetWidth(SummonAssistant.Saved.Width - (2 * SummonAssistant.Saved.Margin)) - buttonTexture:ClearAnchors() - buttonTexture:SetAnchor(CENTER, button, CENTER, 0, 0) - buttonTexture:SetTexture(SummonAssistant.Types[key].EnabledTexture) - buttonTexture:SetHeight(SummonAssistant.Saved.Height - (2 * SummonAssistant.Saved.Margin)) - buttonTexture:SetWidth(SummonAssistant.Saved.Width - (2 * SummonAssistant.Saved.Margin)) - end -end - -function SummonAssistant:CreateHotkeySelections() - for _, _value in ipairs(SummonAssistant.OrderedTypes) do - if IsCollectibleUnlocked(_value.Id) then - ZO_CreateStringId(_value.KeyBinding, _value.Name) - end + if showMinor == false or SummonAssistant.Addon.MinorVersion == nil then + return tostring(SummonAssistant.Addon.Version) end + return tostring(SummonAssistant.Addon.Version) .. "." .. tostring(SummonAssistant.Addon.MinorVersion) end function SummonAssistant:RestorePanel() @@ -188,96 +46,13 @@ function SummonAssistant:RestorePanel() SummonAssistant:SetButtonFrameWidth() - SummonAssistant:FrameBackdropColor() - SummonAssistant:InitializeButtons() - SummonAssistant:RestorePosition() - - SummonAssistant:ActivateMoveHandlers() -end - -function SummonAssistant:SetFragmentBehaviour(menuOpen) - if SummonAssistant.Fragment == nil then - SummonAssistant.Fragment = ZO_HUDFadeSceneFragment:New(SummonAssistant_Frame) - end - - if SummonAssistant.Saved.HideBarInMenu then - SummonAssistant:addControlToFrame(menuOpen) - else - SummonAssistant:removeControlToFrame(menuOpen) - end -end - -function SummonAssistant:SetButtonFrameWidth() - local count = 0 - local show = 0 - local height = 0 - local width = 0 - - for key, value in pairs(SummonAssistant.Saved.ShowAssistants) do - if IsCollectibleUnlocked(key) and SummonAssistant.Saved.ShowAssistants[key] then - count = count + 1 - end - end - - if count > 0 then - show = 1 - end - height = SummonAssistant.Saved.Height * (SummonAssistant.Saved.Horizontal and show or count) - width = SummonAssistant.Saved.Width * (SummonAssistant.Saved.Horizontal and count or show) - - SummonAssistant:SetFrameValues(SummonAssistant_Frame, count, height, width) - SummonAssistant:SetFrameValues(SummonAssistant_FrameBackdrop, count, height, width) -end - -function SummonAssistant:SetFrameValues(frame, count, height, width) - frame:SetHidden(count == 0) - frame:SetHeight(height) - frame:SetWidth(width) -end + SummonAssistant:ButtonsBackdropColor() -function SummonAssistant:FrameBackdropColor(centerColor, edgeColor) - if not centerColor then - centerColor = SummonAssistant.Saved.CenterColor - end - if not edgeColor then - edgeColor = SummonAssistant.Saved.EdgeColor - end - SummonAssistant_FrameBackdrop:SetCenterColor(centerColor.r, centerColor.g, centerColor.b, centerColor.a) - SummonAssistant_FrameBackdrop:SetEdgeColor(edgeColor.r, edgeColor.g, edgeColor.b, edgeColor.a) -end - -function SummonAssistant:InitializeButtons() - local index = 1 - for _, _value in ipairs(SummonAssistant.OrderedTypes) 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_FrameBackdrop, "SummonAssistant_Button", key) - SummonAssistant.Buttons[key]:SetId(id) - end - SummonAssistant:SetupButton(key, SummonAssistant.Buttons[key], id) - SummonAssistant.Buttons[key]:ClearAnchors() - SummonAssistant.Buttons[key]:SetAnchor(TOPLEFT, SummonAssistant_FrameBackdrop, TOPLEFT, left, top) - SummonAssistant.Buttons[key]:SetHidden(false) - index = index + 1 - elseif SummonAssistant.Buttons[key] ~= nil then - SummonAssistant.Buttons[key]:SetHidden(true) - end - end -end + SummonAssistant:RestorePosition() -function SummonAssistant:GetButtonPosition(index) - local left = (SummonAssistant.Saved.Margin) - local top = (SummonAssistant.Saved.Margin) + SummonAssistant.Saved.Height * (index - 1) - if SummonAssistant.Saved.Horizontal then - left = (SummonAssistant.Saved.Margin) + SummonAssistant.Saved.Width * (index - 1) - top = (SummonAssistant.Saved.Margin) - end - return left, top + SummonAssistant:UpdateMoveFrame() end function SummonAssistant:RestorePosition() @@ -287,271 +62,4 @@ function SummonAssistant:RestorePosition() SummonAssistant_Frame:SetAnchor(TOPLEFT, GuiRoot, TOPLEFT, Left, Top) end -function SummonAssistant:ActivateMoveHandlers() - if not SummonAssistant_Frame.LabelTopLeft and SummonAssistant.Saved.ShowMoveAssitance then - SummonAssistant_Frame.LabelTopLeft = SummonAssistant.wm:CreateControl(nil, SummonAssistant_Frame, CT_LABEL) - SummonAssistant_Frame.LabelTopLeft:SetDrawLevel(3) - SummonAssistant_Frame.LabelTopLeft:SetAnchorFill(SummonAssistant_Frame) - SummonAssistant_Frame.LabelTopLeft:SetFont("ZoFontWinH5") - SummonAssistant_Frame.LabelTopLeft:SetHorizontalAlignment(0) - SummonAssistant_Frame.LabelTopLeft:SetVerticalAlignment(0) - SummonAssistant_Frame["UpdateText"] = SummonAssistant.UpdateText - SummonAssistant_Frame:SetHandler("OnMouseEnter", SummonAssistant.OnMouseEnter) - SummonAssistant_Frame:SetHandler("OnMouseDown", SummonAssistant.OnMouseDown) - SummonAssistant_Frame:SetHandler("OnMouseUp", SummonAssistant.OnMouseUp) - SummonAssistant_Frame:SetHandler("OnMouseExit", SummonAssistant.OnMouseExit) - elseif SummonAssistant_Frame.LabelTopLeft and not SummonAssistant.Saved.ShowMoveAssitance then - SummonAssistant_Frame.LabelTopLeft = nil - SummonAssistant_Frame["UpdateText"] = nil - SummonAssistant_Frame:SetHandler("OnMouseEnter", nil) - SummonAssistant_Frame:SetHandler("OnMouseDown", nil) - SummonAssistant_Frame:SetHandler("OnMouseUp", nil) - SummonAssistant_Frame:SetHandler("OnMouseExit", nil) - end -end - -------------------------------------------------------------------------------------------------- --- FUNCTIONS -- --- Move handlers -- -------------------------------------------------------------------------------------------------- - -function SummonAssistant.OnMouseEnter(frame) - frame.UpdateText(frame, true) -end - -function SummonAssistant.OnMouseDown(frame) - frame:SetHandler("OnUpdate", SummonAssistant.OnMouseEnter) -end - -function SummonAssistant.OnMouseExit(frame) - frame.UpdateText(frame, false) -end - -function SummonAssistant.OnMouseUp(frame) - frame:SetHandler("OnUpdate", nil) -end - -function SummonAssistant.UpdateText(frame, position) - if position then - frame.labelTextTopLeft = frame:GetLeft() .. "," .. frame:GetTop() - else - frame.labelTextTopLeft = "" - end - frame.LabelTopLeft:SetText(frame.labelTextTopLeft) -end - -------------------------------------------------------------------------------------------------- --- Menu Functions -- -------------------------------------------------------------------------------------------------- -function SummonAssistant:CreateSettingsWindow() - local panelData = { - type = "panel", - name = ADDON_DISPLAY_NAME, - displayName = ADDON_DISPLAY_NAME, - author = "Jarth", - version = SummonAssistant:GetVersion(true), - slashCommand = "/sa", - registerForRefresh = true, - registerForDefaults = true - } - local cntrlOptionsPanel = LAM2:RegisterAddonPanel(ADDON_NAME, panelData) - - local optionsData = { - [1] = { - type = "header", - name = ADDON_DISPLAY_NAME .. " Settings" - }, - [2] = { - type = "description", - text = "Here you can adjust how the summon assistant works." - }, - [3] = { - type = "checkbox", - name = "Use account settings", - tooltip = "When ON the account settings will be used. When OFF character settings will be used.", - default = SummonAssistant.Default.UseAccountSettings, - getFunc = function() - return SummonAssistant.Saved.UseAccountSettings - end, - setFunc = function(newValue) - --Apply value to existing variable - SummonAssistant.Saved.UseAccountSettings = newValue - if newValue then - SummonAssistant.Saved = ZO_SavedVars:NewAccountWide("SummonAssistant_Account", ADDON_VERSION, nil, SummonAssistant.Default) - else - SummonAssistant.Saved = ZO_SavedVars:New("SummonAssistant_Character", ADDON_VERSION, nil, SummonAssistant.Default) - end - --Apply value to new variable - SummonAssistant.Saved.UseAccountSettings = newValue - SummonAssistant:RestorePanel() - end - }, - [4] = { - type = "checkbox", - name = "Bar orientation horizontal", - tooltip = "When ON the bar will orientate horizontally.", - default = SummonAssistant.Default.Horizontal, - getFunc = function() - return SummonAssistant.Saved.Horizontal - end, - setFunc = function(newValue) - --Apply value to existing variable - SummonAssistant.Saved.Horizontal = newValue - SummonAssistant:RestorePanel() - end - }, - [5] = { - type = "checkbox", - name = "Hide bar in menu", - tooltip = "When ON the bar will hide when a menu is opened.", - default = SummonAssistant.Default.HideBarInMenu, - getFunc = function() - return SummonAssistant.Saved.HideBarInMenu - end, - setFunc = function(newValue) - SummonAssistant.Saved.HideBarInMenu = newValue - SummonAssistant:SetFragmentBehaviour(true) - end - }, - [6] = { - type = "submenu", - name = "Position and size", - tooltip = "Settings regarding position and size.", - controls = { - [1] = { - type = "checkbox", - name = "Show bar position", - tooltip = "When ON the bar will show the X,Y position of the top left corner, when the mouse enters and drags the panel around.", - default = function() - return SummonAssistant.Default.ShowMoveAssitance - end, - getFunc = function() - return SummonAssistant.Saved.ShowMoveAssitance - end, - setFunc = function(newValue) - SummonAssistant.Saved.ShowMoveAssitance = newValue - SummonAssistant:RestorePanel() - end - }, - [2] = { - type = "slider", - name = "Choose button margin", - tooltip = "It is at this time, 'not possible' to move/drag the frame, when the margin is set to 0", - default = SummonAssistant.Default.Margin, - getFunc = function() - return SummonAssistant.Saved.Margin - end, - setFunc = function(value) - SummonAssistant.Saved.Margin = value - SummonAssistant:RestorePanel() - end, - min = 0, - max = 50 - }, - [3] = { - type = "slider", - name = "Choose button height", - default = SummonAssistant.Default.Height, - getFunc = function() - return SummonAssistant.Saved.Height - end, - setFunc = function(value) - SummonAssistant.Saved.Height = value - SummonAssistant:RestorePanel() - end, - min = 1, - max = 100 - }, - [4] = { - type = "slider", - name = "Choose button width", - default = SummonAssistant.Default.Width, - getFunc = function() - return SummonAssistant.Saved.Width - end, - setFunc = function(value) - SummonAssistant.Saved.Width = value - SummonAssistant:RestorePanel() - end, - min = 1, - max = 100 - } - } - }, - [7] = { - type = "submenu", - name = "Colors", - tooltip = "Allows you to change colors.", - controls = { - [1] = { - type = "description", - text = "Here you can adjust the colors." - }, - [2] = { - type = "colorpicker", - name = "Backdrop Color", - default = function() - return SummonAssistant.Default.CenterColor - end, - tooltip = "Changes the color of the background.", - getFunc = function() - return SummonAssistant.Saved.CenterColor.r, SummonAssistant.Saved.CenterColor.g, SummonAssistant.Saved.CenterColor.b, SummonAssistant.Saved.CenterColor.a - end, - setFunc = function(r, g, b, a) - SummonAssistant.Saved.CenterColor = {r = r, g = g, b = b, a = a} - SummonAssistant:FrameBackdropColor() - end, - width = "half" - }, - [3] = { - type = "colorpicker", - name = "Frame Color", - default = function() - return SummonAssistant.Default.EdgeColor - end, - tooltip = "Changes the color of the frame.", - getFunc = function() - return SummonAssistant.Saved.EdgeColor.r, SummonAssistant.Saved.EdgeColor.g, SummonAssistant.Saved.EdgeColor.b, SummonAssistant.Saved.EdgeColor.a - end, - setFunc = function(r, g, b, a) - SummonAssistant.Saved.EdgeColor = {r = r, g = g, b = b, a = a} - SummonAssistant:FrameBackdropColor() - end, - width = "half" - } - } - }, - [8] = { - type = "submenu", - name = "Visibility", - tooltip = "Allows you to choose what assistant buttons you wants to see.", - controls = { - [1] = { - type = "description", - text = "Select assistant buttons you want enabled." - } - } - } - } - - for index, _type in ipairs(SummonAssistant.OrderedTypes) do - local line = { - type = "checkbox", - name = "Show " .. _type.name, - tooltip = _type.Tooltip, - default = not _type.Disabled, - disabled = _type.Disabled, - getFunc = function() - return SummonAssistant.Saved.ShowAssistants[_type.Id] - end, - setFunc = function(newValue) - SummonAssistant.Saved.ShowAssistants[_type.Id] = newValue - SummonAssistant:RestorePanel() - end - } - table.insert(optionsData[8].controls, index + 1, line) - end - LAM2:RegisterOptionControls(ADDON_NAME, optionsData) -end - -EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_ADD_ON_LOADED, SummonAssistant.OnAddOnLoaded) +EVENT_MANAGER:RegisterForEvent(SummonAssistant.Addon.Name, EVENT_ADD_ON_LOADED, SummonAssistant.OnAddOnLoaded) diff --git a/SummonAssistant.txt b/SummonAssistant.txt index c6f46da..c34e88e 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: 100021 +## APIVersion: 100021 100022 ## Title: SummonAssistant -## Version: 1.3.1 +## Version: 1.4.0 ## Author: Jarth ## Description: Summon assistant, by hotkey or button! ## @@ -37,5 +37,11 @@ libs\LibAddonMenu-2.0\controls\iconpicker.lua libs\LibAddonMenu-2.0\controls\divider.lua Bindings\Bindings.xml -SummonAssistant.lua -SummonAssistant.xml \ No newline at end of file +SummonAssistant.xml +SummonAssistant_Constants.lua +SummonAssistant_Fragments.lua +SummonAssistant_Hotkeys.lua +SummonAssistant_Menu.lua +SummonAssistant_Move.lua +SummonAssistant_Buttons.lua +SummonAssistant.lua \ No newline at end of file diff --git a/SummonAssistant.xml b/SummonAssistant.xml index 6691c2a..e911d13 100644 --- a/SummonAssistant.xml +++ b/SummonAssistant.xml @@ -1,24 +1,16 @@ <GuiXml> <Controls> - <TopLevelControl name="SummonAssistant_Frame" clampedToScreen="true" movable="true" mouseEnabled="true"> + <TopLevelControl name="SummonAssistant_Frame" clampedToScreen="true" movable="false" mouseEnabled="true"> <Anchor point="CENTER" relativePoint="CENTER" relativeTo="GuiRoot"/> - <Dimensions x="180" y="60"/> - <Controls> - <Backdrop name="$(parent)Backdrop" alpha="1"> - <Anchor point="TOPLEFT" relativePoint="TOPLEFT" relativeTo="$(parent)" /> - <Dimensions x="180" y="60"/> - <Edge edgeSize="1"/> - </Backdrop> - </Controls> </TopLevelControl> <Button name="SummonAssistant_Button" relativeTo="$(parent)" virtual="true"> - <Dimensions x="40" y="40"/> <Controls> - <Texture name="$(parent)Texture"> - <Anchor point="128"/> - <Dimensions x="40" y="40"/> + <Backdrop name="$(parent)Backdrop" alpha="1"> + </Backdrop> + <Texture name="$(parent)Texture" alpha="1"> </Texture> </Controls> - </Button> + </Button> + <TopLevelControl name="SummonAssistant_MoveFrame" virtual="true" /> </Controls> </GuiXml> \ No newline at end of file diff --git a/SummonAssistant_Buttons.lua b/SummonAssistant_Buttons.lua new file mode 100644 index 0000000..56c093e --- /dev/null +++ b/SummonAssistant_Buttons.lua @@ -0,0 +1,152 @@ +--[[ +Author: Jarth +Filename: SummonAssistant_Buttons.lua +]] -- + +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local SummonAssistant = SummonAssistant + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +-- Button highlight -- +------------------------------------------------------------------------------------------------- +function SummonAssistant.ButtonHighlightEnter(frame) + local highlightColor = SummonAssistant.Saved.HighlightColor + local buttonBackdrop = GetControl(frame, "Backdrop") + if buttonBackdrop ~= nil then + PlaySound(SOUNDS.QUICKSLOT_MOUSEOVER) + buttonBackdrop:SetEdgeColor(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a) + end +end + +function 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) + local id = button:GetId() + if id > 0 then + if IsCollectibleUnlocked(id) then + UseCollectible(id) + else + UseCollectible(GetActiveCollectibleByType(COLLECTIBLE_CATEGORY_TYPE_ASSISTANT)) + end + end +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: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 + count = count + 1 + end + end + + if count > 0 then + show = 1 + 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) +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() + local index = 1 + for _, _value in ipairs(SummonAssistant.OrderedTypes) 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) + end + SummonAssistant:SetupButton(SummonAssistant.Buttons[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) + index = index + 1 + elseif SummonAssistant.Buttons[key] ~= nil then + SummonAssistant.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 + + for _, _value in ipairs(SummonAssistant.OrderedTypes) do + if SummonAssistant.Buttons[_value.Name] ~= nil then + local buttonBackdrop = GetControl(SummonAssistant.Buttons[_value.Name], "Backdrop") + if buttonBackdrop ~= nil then + buttonBackdrop:SetCenterColor(centerColor.r, centerColor.g, centerColor.b, centerColor.a) + buttonBackdrop:SetEdgeColor(edgeColor.r, edgeColor.g, edgeColor.b, edgeColor.a) + end + end + end +end diff --git a/SummonAssistant_Constants.lua b/SummonAssistant_Constants.lua new file mode 100644 index 0000000..8332dc1 --- /dev/null +++ b/SummonAssistant_Constants.lua @@ -0,0 +1,88 @@ +--[[ +Author: Jarth +Filename: SummonAssistant_Constants.lua +]] -- + +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +SummonAssistant = {} + +SummonAssistant.Addon = { + Name = "SummonAssistant", + DisplayName = "Summon Assistant", + Version = 1.4, + MinorVersion = 0, + SlashCommand = "/sa", + Author = "Jarth", + Website = "" +} +SummonAssistant.WM = GetWindowManager() +SummonAssistant.Buttons = {} +SummonAssistant.Fragment = nil +SummonAssistant.Default = { + Left = CENTER, + Top = CENTER, + CenterColor = {r = 0.88, g = 0.88, b = 0.88, a = 0.4}, + EdgeColor = {r = 0.88, g = 0.88, b = 0.88, a = 0}, + HighlightColor = {r = 0.9, g = 0.9, b = 0.9, a = 0.9}, + FontColor = {r = 0.9, g = 0.9, b = 0.9, a = 0.9}, + UseAccountSettings = true, + Horizontal = true, + HideBarInMenu = true, + Margin = 2, + Height = 60, + Width = 60, + SnapSize = 5, + ShowAssistants = { + [267] = IsCollectibleUnlocked(267), + [300] = IsCollectibleUnlocked(300), + [301] = IsCollectibleUnlocked(301) + } +} +SummonAssistant.Global = { + IsMoveEnabled = false +} +SummonAssistant.Types = { + Banker = { + Id = 267, + Title = "Banker:", + Name = "Banker", + name = "banker", + Tooltip = "When ON the banker button will be visible. When OFF the banker button will not be visible (disabled if locked for the account).", + EnabledTexture = "/esoui/art/icons/" .. "assistant_banker_01.dds", + KeyBinding = "SI_BINDING_NAME_SummonAssistant_Assistant_Banker", + Disabled = function() + return not IsCollectibleUnlocked(267) + end + }, + Fence = { + Id = 300, + Title = "Fence:", + Name = "Fence", + name = "fence", + Tooltip = "When ON the fence button will be visible. When OFF the fence button will not be visible (disabled if locked for the account).", + EnabledTexture = "/esoui/art/icons/" .. "assistant_fence_01.dds", + KeyBinding = "SI_BINDING_NAME_SummonAssistant_Assistant_Fence", + Disabled = function() + return not IsCollectibleUnlocked(300) + end + }, + Vendor = { + Id = 301, + Title = "Vendor:", + Name = "Vendor", + name = "vendor", + Tooltip = "When ON the vendor button will be visible. When OFF the vendor button will not be visible (disabled if locked for the account).", + EnabledTexture = "/esoui/art/icons/" .. "assistant_vendor_01.dds", + KeyBinding = "SI_BINDING_NAME_SummonAssistant_Assistant_Vendor", + Disabled = function() + return not IsCollectibleUnlocked(301) + end + } +} +SummonAssistant.OrderedTypes = { + [1] = SummonAssistant.Types["Banker"], + [2] = SummonAssistant.Types["Fence"], + [3] = SummonAssistant.Types["Vendor"] +} diff --git a/SummonAssistant_Fragments.lua b/SummonAssistant_Fragments.lua new file mode 100644 index 0000000..8037dbd --- /dev/null +++ b/SummonAssistant_Fragments.lua @@ -0,0 +1,42 @@ +--[[ +Author: Jarth +Filename: SummonAssistant_Fragments.lua +]] -- + +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local SummonAssistant = SummonAssistant + +------------------------------------------------------------------------------------------------- +-- PRIVATE FUNCTIONS -- +------------------------------------------------------------------------------------------------- +function SummonAssistant:SetFragmentBehaviour(menuOpen) + if SummonAssistant.Fragment == nil then + SummonAssistant.Fragment = ZO_HUDFadeSceneFragment:New(SummonAssistant_Frame) + end + + if SummonAssistant.Saved.HideBarInMenu then + SummonAssistant:AddControlToFrame(menuOpen) + else + SummonAssistant:RemoveControlToFrame(menuOpen) + end +end + +function SummonAssistant:AddControlToFrame(menuOpen) + if menuOpen then + SummonAssistant_Frame:SetHidden(true) + end + + SCENE_MANAGER:GetScene("hud"):AddFragment(SummonAssistant.Fragment) + SCENE_MANAGER:GetScene("hudui"):AddFragment(SummonAssistant.Fragment) +end + +function SummonAssistant:RemoveControlToFrame(menuOpen) + if menuOpen then + SummonAssistant_Frame:SetHidden(false) + end + + SCENE_MANAGER:GetScene("hud"):RemoveFragment(SummonAssistant.Fragment) + SCENE_MANAGER:GetScene("hudui"):RemoveFragment(SummonAssistant.Fragment) +end diff --git a/SummonAssistant_Hotkeys.lua b/SummonAssistant_Hotkeys.lua new file mode 100644 index 0000000..dff79fd --- /dev/null +++ b/SummonAssistant_Hotkeys.lua @@ -0,0 +1,20 @@ +--[[ +Author: Jarth +Filename: SummonAssistant_Hotkeys.lua +]] -- + +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local SummonAssistant = SummonAssistant + +------------------------------------------------------------------------------------------------- +-- PRIVATE FUNCTIONS -- +------------------------------------------------------------------------------------------------- +function SummonAssistant:CreateHotkeySelections() + for _, _value in ipairs(SummonAssistant.OrderedTypes) do + if IsCollectibleUnlocked(_value.Id) then + ZO_CreateStringId(_value.KeyBinding, _value.Name) + end + end +end diff --git a/SummonAssistant_Menu.lua b/SummonAssistant_Menu.lua new file mode 100644 index 0000000..f3c3eb1 --- /dev/null +++ b/SummonAssistant_Menu.lua @@ -0,0 +1,281 @@ +--[[ +Author: Jarth +Filename: SummonAssistant_Menu.lua +]] -- + +------------------------------------------------------------------------------------------------- +-- Libraries -- +------------------------------------------------------------------------------------------------- +local LAM2 = LibStub:GetLibrary("LibAddonMenu-2.0") + +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local SummonAssistant = SummonAssistant + +------------------------------------------------------------------------------------------------- +-- Menu Functions -- +------------------------------------------------------------------------------------------------- +function SummonAssistant:CreateSettingsWindow() + local panelData = { + type = "panel", + name = SummonAssistant.Addon.DisplayName, + displayName = SummonAssistant.Addon.DisplayName, + author = SummonAssistant.Addon.Author, + version = SummonAssistant:GetVersion(true), + slashCommand = SummonAssistant.Addon.SlashCommand, + registerForRefresh = true, + registerForDefaults = true + } + local cntrlOptionsPanel = LAM2:RegisterAddonPanel(SummonAssistant.Addon.Name, panelData) + local optionsData = { + [1] = { + type = "header", + name = SummonAssistant.Addon.DisplayName .. " Settings" + }, + [2] = { + type = "description", + text = "Here you can adjust how the summon assistant works." + }, + [3] = { + type = "checkbox", + name = "Use account settings", + tooltip = "When ON the account settings will be used. When OFF character settings will be used.", + default = SummonAssistant.Default.UseAccountSettings, + getFunc = function() + return SummonAssistant.Saved.UseAccountSettings + end, + setFunc = function(newValue) + SummonAssistant.Saved.UseAccountSettings = newValue + if newValue then + SummonAssistant.Saved = ZO_SavedVars:NewAccountWide("SummonAssistant_Account", SummonAssistant.Addon.Version, nil, SummonAssistant.Default) + else + SummonAssistant.Saved = ZO_SavedVars:New("SummonAssistant_Character", SummonAssistant.Addon.Version, nil, SummonAssistant.Default) + end + SummonAssistant.Saved.UseAccountSettings = newValue + SummonAssistant:RestorePanel() + end + }, + [4] = { + type = "checkbox", + name = "Bar orientation horizontal", + tooltip = "When ON the bar will orientate horizontally.", + default = SummonAssistant.Default.Horizontal, + getFunc = function() + return SummonAssistant.Saved.Horizontal + end, + setFunc = function(newValue) + SummonAssistant.Saved.Horizontal = newValue + SummonAssistant:RestorePanel() + end + }, + [5] = { + type = "checkbox", + name = "Hide bar in menu", + tooltip = "When ON the bar will hide when a menu is opened.", + default = SummonAssistant.Default.HideBarInMenu, + getFunc = function() + return SummonAssistant.Saved.HideBarInMenu + end, + setFunc = function(newValue) + SummonAssistant.Saved.HideBarInMenu = newValue + SummonAssistant:SetFragmentBehaviour(true) + end + }, + [6] = { + type = "submenu", + name = "Position and size", + tooltip = "Settings regarding position and size.", + controls = { + [1] = { + type = "checkbox", + name = "Show bar position", + tooltip = "When ON the bar will show the X,Y position of the top left corner, when the mouse enters and drags the panel around.", + disabled = function() + local count = 0 + if IsCollectibleUnlocked(267) and SummonAssistant.Saved.ShowAssistants[267] then + count = count + 1 + end + if IsCollectibleUnlocked(300) and SummonAssistant.Saved.ShowAssistants[300] then + count = count + 1 + end + if IsCollectibleUnlocked(301) and SummonAssistant.Saved.ShowAssistants[301] then + count = count + 1 + end + return count == 0 + end, + default = function() + return SummonAssistant.Global.IsMoveEnabled + end, + getFunc = function() + return SummonAssistant.Global.IsMoveEnabled + end, + setFunc = function(newValue) + SummonAssistant.Global.IsMoveEnabled = newValue + SummonAssistant:RestorePanel() + end + }, + [2] = { + type = "slider", + name = "Choose button margin", + tooltip = "It is at this time, 'not possible' to move/drag the frame, when the margin is set to 0", + default = SummonAssistant.Default.Margin, + getFunc = function() + return SummonAssistant.Saved.Margin + end, + setFunc = function(value) + SummonAssistant.Saved.Margin = value + SummonAssistant:RestorePanel() + end, + min = 1, + max = 50 + }, + [3] = { + type = "slider", + name = "Choose button height", + default = SummonAssistant.Default.Height, + getFunc = function() + return SummonAssistant.Saved.Height + end, + setFunc = function(value) + SummonAssistant.Saved.Height = value + SummonAssistant:RestorePanel() + end, + min = 1, + max = 100 + }, + [4] = { + type = "slider", + name = "Choose button width", + default = SummonAssistant.Default.Width, + getFunc = function() + return SummonAssistant.Saved.Width + end, + setFunc = function(value) + SummonAssistant.Saved.Width = value + SummonAssistant:RestorePanel() + end, + min = 1, + max = 100 + }, + [5] = { + type = "slider", + name = "Choose snap size when moving", + default = SummonAssistant.Default.SnapSize, + getFunc = function() + return SummonAssistant.Saved.SnapSize + end, + setFunc = function(value) + SummonAssistant.Saved.SnapSize = value + SummonAssistant:RestorePanel() + end, + min = 1, + max = 10 + }, + [6] = { + type = "colorpicker", + name = "Font Color", + default = SummonAssistant.Default.FontColor, + tooltip = "Changes of the move frame font.", + getFunc = function() + return SummonAssistant.Saved.FontColor.r, SummonAssistant.Saved.FontColor.g, SummonAssistant.Saved.FontColor.b, SummonAssistant.Saved.FontColor.a + end, + setFunc = function(r, g, b, a) + SummonAssistant.Saved.FontColor = {r = r, g = g, b = b, a = a} + SummonAssistant:RestorePanel() + end, + width = "half" + } + } + }, + [7] = { + type = "submenu", + name = "Colors", + tooltip = "Allows you to change colors.", + controls = { + [1] = { + type = "description", + text = "Here you can adjust the colors." + }, + [2] = { + type = "colorpicker", + name = "Button background Color", + default = function() + return SummonAssistant.Default.CenterColor + end, + tooltip = "Changes the background color of the buttons.", + getFunc = function() + return SummonAssistant.Saved.CenterColor.r, SummonAssistant.Saved.CenterColor.g, SummonAssistant.Saved.CenterColor.b, SummonAssistant.Saved.CenterColor.a + end, + setFunc = function(r, g, b, a) + SummonAssistant.Saved.CenterColor = {r = r, g = g, b = b, a = a} + SummonAssistant:RestorePanel() + end, + width = "half" + }, + [3] = { + type = "colorpicker", + name = "Button edge Color", + default = function() + return SummonAssistant.Default.EdgeColor + end, + tooltip = "Changes the edgecolor of the buttons.", + getFunc = function() + return SummonAssistant.Saved.EdgeColor.r, SummonAssistant.Saved.EdgeColor.g, SummonAssistant.Saved.EdgeColor.b, SummonAssistant.Saved.EdgeColor.a + end, + setFunc = function(r, g, b, a) + SummonAssistant.Saved.EdgeColor = {r = r, g = g, b = b, a = a} + SummonAssistant:RestorePanel() + end, + width = "half" + }, + [4] = { + type = "colorpicker", + name = "Button highlight Color", + default = function() + return SummonAssistant.Default.HighlightColor + end, + tooltip = "Changes the highlight color of the buttons.", + getFunc = function() + return SummonAssistant.Saved.HighlightColor.r, SummonAssistant.Saved.HighlightColor.g, SummonAssistant.Saved.HighlightColor.b, SummonAssistant.Saved.HighlightColor.a + end, + setFunc = function(r, g, b, a) + SummonAssistant.Saved.HighlightColor = {r = r, g = g, b = b, a = a} + SummonAssistant:RestorePanel() + end, + width = "half" + } + } + }, + [8] = { + type = "submenu", + name = "Visibility", + tooltip = "Allows you to choose what assistant buttons you wants to see.", + controls = { + [1] = { + type = "description", + text = "Select assistant buttons you want enabled." + } + } + } + } + + for index, _type in ipairs(SummonAssistant.OrderedTypes) do + local line = { + type = "checkbox", + name = "Show " .. _type.name, + tooltip = _type.Tooltip, + default = not _type.Disabled, + disabled = _type.Disabled, + getFunc = function() + return SummonAssistant.Saved.ShowAssistants[_type.Id] + end, + setFunc = function(newValue) + SummonAssistant.Saved.ShowAssistants[_type.Id] = newValue + SummonAssistant:RestorePanel() + end + } + table.insert(optionsData[8].controls, index + 1, line) + end + LAM2:RegisterOptionControls(SummonAssistant.Addon.Name, optionsData) +end diff --git a/SummonAssistant_Move.lua b/SummonAssistant_Move.lua new file mode 100644 index 0000000..e95cf2f --- /dev/null +++ b/SummonAssistant_Move.lua @@ -0,0 +1,149 @@ +--[[ +Author: Jarth +Filename: SummonAssistant_Move.lua +]] -- + +------------------------------------------------------------------------------------------------- +-- VARIABLES -- +------------------------------------------------------------------------------------------------- +local SummonAssistant = SummonAssistant + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +-- Move frame -- +------------------------------------------------------------------------------------------------- +function SummonAssistant:UpdateMoveFrame() + local moveFrame = SummonAssistant.MoveFrame + local onMouseEnter, onMouseExit, onMouseDown, onMouseUp = nil, nil, nil, nil + if SummonAssistant.Global.IsMoveEnabled then + moveFrame = SummonAssistant:GetOrCreateMoveFrame() + onMouseEnter = SummonAssistant.MoveFrameOnEnter + onMouseExit = SummonAssistant.MoveFrameOnExit + onMouseDown = SummonAssistant.MoveFrameOnDown + onMouseUp = SummonAssistant.MoveFrameOnUp + end + + if moveFrame then + moveFrame:SetHandler("OnMouseEnter", onMouseEnter) + moveFrame:SetHandler("OnMouseExit", onMouseExit) + moveFrame:SetHandler("OnMouseDown", onMouseDown) + moveFrame:SetHandler("OnMouseUp", onMouseUp) + moveFrame:SetHidden(not SummonAssistant.Global.IsMoveEnabled) + moveFrame.overlay:SetHidden(not SummonAssistant.Global.IsMoveEnabled) + moveFrame.labelCenter:SetHidden(not SummonAssistant.Global.IsMoveEnabled) + moveFrame.labelTopLeft:SetHidden(not SummonAssistant.Global.IsMoveEnabled) + moveFrame.MoveFrameUpdateText(moveFrame) + moveFrame.MoveFrameUpdateColor(moveFrame) + moveFrame.MoveFrameAnchorToTarget(moveFrame, moveFrame.TargetFrame) + end +end + +------------------------------------------------------------------------------------------------- +-- FUNCTIONS -- +-- Move handlers -- +------------------------------------------------------------------------------------------------- +function SummonAssistant:GetOrCreateMoveFrame(show) + if SummonAssistant.MoveFrame == nil then + local newMoveFrame = SummonAssistant.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"] = SummonAssistant.MoveFrameAnchorToTarget + newMoveFrame["MoveFrameGetSnapPosition"] = SummonAssistant.MoveFrameGetSnapPosition + newMoveFrame["MoveFrameUpdateText"] = SummonAssistant.MoveFrameUpdateText + newMoveFrame["MoveFrameUpdateColor"] = SummonAssistant.MoveFrameUpdateColor + newMoveFrame["MoveFrameOnUpdate"] = SummonAssistant.MoveFrameOnUpdate + newMoveFrame["MoveFrameStorePosition"] = SummonAssistant.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 = SummonAssistant.WM:CreateControl(nil, newMoveFrame, CT_BACKDROP) + newMoveFrame.overlay:SetDrawLevel(2) + newMoveFrame.overlay:SetAnchorFill(targetFrame) + newMoveFrame.overlay:SetEdgeTexture("", 8, 1, 0) + -- label + newMoveFrame.labelCenter = SummonAssistant.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 = SummonAssistant.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) + + SummonAssistant.MoveFrame = newMoveFrame + end + return SummonAssistant.MoveFrame +end + +function SummonAssistant.MoveFrameOnEnter(frame) + frame.MoveFrameUpdateText(frame, true) +end + +function SummonAssistant.MoveFrameOnExit(frame) + frame.MoveFrameUpdateText(frame, false) +end + +function SummonAssistant.MoveFrameOnDown(frame) + frame:SetHandler("OnUpdate", frame.MoveFrameOnUpdate) +end + +function SummonAssistant.MoveFrameOnUp(frame) + frame.MoveFrameOnUpdate(frame) + frame.MoveFrameUpdateText(frame, false) + frame:SetHandler("OnUpdate", nil) + frame.MoveFrameStorePosition(frame) +end + +function SummonAssistant.MoveFrameOnUpdate(frame) + frame.TargetFrame:ClearAnchors() + frame.TargetFrame:SetAnchor(TOPLeft, GuiRoot, TOPLeft, SummonAssistant.MoveFrameGetSnapPosition(frame:GetLeft()), SummonAssistant.MoveFrameGetSnapPosition(frame:GetTop())) + frame.MoveFrameUpdateText(frame, true) +end + +function SummonAssistant.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 SummonAssistant.MoveFrameGetSnapPosition(value) + return (zo_round(value / SummonAssistant.Saved.SnapSize) * SummonAssistant.Saved.SnapSize) +end + +function SummonAssistant.MoveFrameStorePosition(frame) + SummonAssistant.Saved.Top = frame.MoveFrameGetSnapPosition(frame:GetTop()) + SummonAssistant.Saved.Left = frame.MoveFrameGetSnapPosition(frame:GetLeft()) +end + +function SummonAssistant.MoveFrameAnchorToTarget(frame, target) + frame:ClearAnchors() + frame:SetDimensions(target:GetWidth(), target:GetHeight()) + frame:SetAnchor(TOPLeft, GuiRoot, TOPLeft, target:GetLeft(), target:GetTop()) +end + +function SummonAssistant.MoveFrameUpdateColor(frame) + local centerColor = SummonAssistant.Saved.CenterColor + local edgeColor = SummonAssistant.Saved.EdgeColor + local fontColor = SummonAssistant.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