From cf9e55442b4a9e472f06fabd39ceee0ab4fc1abb Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sun, 8 Sep 2024 23:44:12 +0200 Subject: [PATCH 01/22] Remove Menu Button --- Cell_UnitFrames.toc | 1 - UnitFrames/UnitButton.lua | 270 ++++++++++---------------------------- UnitFrames/Units.lua | 91 ------------- 3 files changed, 71 insertions(+), 291 deletions(-) delete mode 100644 UnitFrames/Units.lua diff --git a/Cell_UnitFrames.toc b/Cell_UnitFrames.toc index a41e0f8..b20093f 100644 --- a/Cell_UnitFrames.toc +++ b/Cell_UnitFrames.toc @@ -70,7 +70,6 @@ Widgets/Auras/Handler.lua UnitFrames/UnitButton.xml UnitFrames/UnitButton.lua UnitFrames/OnLoad.lua -UnitFrames/Units.lua UnitFrames/MenuOptions.lua Core/OnLoad.lua \ No newline at end of file diff --git a/UnitFrames/UnitButton.lua b/UnitFrames/UnitButton.lua index a9b086e..d82e143 100644 --- a/UnitFrames/UnitButton.lua +++ b/UnitFrames/UnitButton.lua @@ -2,10 +2,8 @@ local CUF = select(2, ...) local Cell = CUF.Cell -local L = CUF.L local F = Cell.funcs local P = Cell.pixelPerfectFuncs -local A = Cell.animations ---@class CUF.uFuncs local U = CUF.uFuncs @@ -14,146 +12,17 @@ local W = CUF.widgets local const = CUF.constants local Util = CUF.Util -------------------------------------------------- --- MARK: Save Tooltip Position -------------------------------------------------- - ----@param unit Unit ----@param tooltipPoint FramePoint ----@param tooltipRelativePoint FramePoint ----@param tooltipX number ----@param tooltipY number -function U:SaveTooltipPosition(unit, tooltipPoint, tooltipRelativePoint, tooltipX, tooltipY) - CUF.DB.CurrentLayoutTable()[unit].tooltipPosition = { tooltipPoint, tooltipRelativePoint, tooltipX, tooltipY } -end - -------------------------------------------------- --- MARK: Create Unit Frame -------------------------------------------------- - ----@param unit Unit ----@param onEnterLogic function? ----@return CUFUnitFrame CUFUnitFrame ----@return CUFAnchorFrame CUFAnchorFrame ----@return CUFHoverFrame CUFHoverFrame ----@return CUFConfigButton CUFConfigButton -function U:CreateBaseUnitFrame(unit, onEnterLogic) - local name = const.TITLE_CASED_UNITS[unit] - - ---@class CUFUnitFrame: Frame - local frame = CreateFrame("Frame", "CUF_" .. name .. "_Frame", Cell.frames.mainFrame, "SecureFrameTemplate") - - -- Anchor - ---@class CUFAnchorFrame: Frame, CellAnimation - local anchorFrame = CreateFrame("Frame", "CUF_" .. name .. "_AnchorFrame", frame) - PixelUtil.SetPoint(anchorFrame, "TOPLEFT", UIParent, "CENTER", 1, -1) - anchorFrame:SetMovable(true) - anchorFrame:SetClampedToScreen(true) - - -- Hover - ---@class CUFHoverFrame: Frame - local hoverFrame = CreateFrame("Frame", nil, frame, "BackdropTemplate") - hoverFrame:SetPoint("TOP", anchorFrame, 0, 1) - hoverFrame:SetPoint("BOTTOM", anchorFrame, 0, -1) - hoverFrame:SetPoint("LEFT", anchorFrame, -1, 0) - hoverFrame:SetPoint("RIGHT", anchorFrame, 1, 0) - - A:ApplyFadeInOutToMenu(anchorFrame, hoverFrame) - - ---@class CUFConfigButton: Button - ---@field UpdatePixelPerfect function - local config = Cell:CreateButton(anchorFrame, nil, "accent", { 20, 10 }, false, true, nil, nil, - "SecureHandlerAttributeTemplate,SecureHandlerClickTemplate") - config:SetFrameStrata("MEDIUM") - config:SetAllPoints(anchorFrame) - config:RegisterForDrag("LeftButton") - config:SetScript("OnDragStart", function() - anchorFrame:StartMoving() - anchorFrame:SetUserPlaced(false) - end) - config:SetScript("OnDragStop", function() - anchorFrame:StopMovingOrSizing() - P:SavePosition(anchorFrame, CUF.DB.CurrentLayoutTable()[unit].position) - end) - config:HookScript("OnEnter", function() - hoverFrame:GetScript("OnEnter")(hoverFrame) - CellTooltip:SetOwner(config, "ANCHOR_NONE") - - local tooltipPoint, tooltipRelativePoint, tooltipX, tooltipY = unpack(CUF.DB.CurrentLayoutTable()[unit] - .tooltipPosition) - P:Point(CellTooltip, tooltipPoint, config, tooltipRelativePoint, tooltipX, tooltipY) - - CellTooltip:AddLine(L[unit] .. " " .. L.Frame) - - -- Execute additional logic passed to the function - if type(onEnterLogic) == "function" then - onEnterLogic(CellTooltip) - end - - CellTooltip:Show() - end) - config:HookScript("OnLeave", function() - hoverFrame:GetScript("OnLeave")(hoverFrame) - CellTooltip:Hide() - end) - - return frame, anchorFrame, hoverFrame, config -end - ------------------------------------------------- -- MARK: Button Position ------------------------------------------------- ---@param unit Unit ---@param button CUFUnitButton ----@param anchorFrame CUFAnchorFrame -function U:UpdateUnitButtonPosition(unit, button, anchorFrame) +function U:UpdateUnitButtonPosition(unit, button) local layout = CUF.DB.CurrentLayoutTable() - local anchorPoint - if layout[unit].sameSizeAsPlayer then - anchorPoint = layout[const.UNIT.PLAYER].point - else - anchorPoint = layout[unit].point - end - button:ClearAllPoints() - -- NOTE: detach from PreviewAnchor - P:LoadPosition(anchorFrame, layout[unit].position) - - if CellDB.general.menuPosition == "top_bottom" then - P:Size(anchorFrame, 20, 10) - - if anchorPoint == "BOTTOMLEFT" then - P:Point(button, "BOTTOMLEFT", anchorFrame, "TOPLEFT", 0, 4) - U:SaveTooltipPosition(unit, "TOPLEFT", "BOTTOMLEFT", 0, -3) - elseif anchorPoint == "BOTTOMRIGHT" then - P:Point(button, "BOTTOMRIGHT", anchorFrame, "TOPRIGHT", 0, 4) - U:SaveTooltipPosition(unit, "TOPRIGHT", "BOTTOMRIGHT", 0, -3) - elseif anchorPoint == "TOPLEFT" then - P:Point(button, "TOPLEFT", anchorFrame, "BOTTOMLEFT", 0, -4) - U:SaveTooltipPosition(unit, "BOTTOMLEFT", "TOPLEFT", 0, 3) - elseif anchorPoint == "TOPRIGHT" then - P:Point(button, "TOPRIGHT", anchorFrame, "BOTTOMRIGHT", 0, -4) - U:SaveTooltipPosition(unit, "BOTTOMRIGHT", "TOPRIGHT", 0, 3) - end - else -- left_right - P:Size(anchorFrame, 10, 20) - - if anchorPoint == "BOTTOMLEFT" then - P:Point(button, "BOTTOMLEFT", anchorFrame, "BOTTOMRIGHT", 4, 0) - U:SaveTooltipPosition(unit, "BOTTOMRIGHT", "BOTTOMLEFT", -3, 0) - elseif anchorPoint == "BOTTOMRIGHT" then - P:Point(button, "BOTTOMRIGHT", anchorFrame, "BOTTOMLEFT", -4, 0) - U:SaveTooltipPosition(unit, "BOTTOMLEFT", "BOTTOMRIGHT", 3, 0) - elseif anchorPoint == "TOPLEFT" then - P:Point(button, "TOPLEFT", anchorFrame, "TOPRIGHT", 4, 0) - U:SaveTooltipPosition(unit, "TOPRIGHT", "TOPLEFT", -3, 0) - elseif anchorPoint == "TOPRIGHT" then - P:Point(button, "TOPRIGHT", anchorFrame, "TOPLEFT", -4, 0) - U:SaveTooltipPosition(unit, "TOPLEFT", "TOPRIGHT", 3, 0) - end - end + button:SetPoint("CENTER", UIParent, "CENTER", unpack(layout[unit].position)) end ------------------------------------------------- @@ -163,8 +32,7 @@ end ---@param unit Unit ---@param kind string? ---@param button CUFUnitButton ----@param anchorFrame CUFAnchorFrame -function U:UpdateUnitButtonLayout(unit, kind, button, anchorFrame) +function U:UpdateUnitButtonLayout(unit, kind, button) local layout = CUF.DB.CurrentLayoutTable() -- Size @@ -179,33 +47,6 @@ function U:UpdateUnitButtonLayout(unit, kind, button, anchorFrame) P:Size(button, width, height) end - -- Anchor points - if not kind or strfind(kind, "arrangement$") then - local anchorPoint - if layout[unit].sameSizeAsPlayer then - anchorPoint = layout[const.UNIT.PLAYER].point - else - anchorPoint = layout[unit].point - end - - -- anchors - local relativePoint - if anchorPoint == "BOTTOMLEFT" then - relativePoint = "TOPLEFT" - elseif anchorPoint == "BOTTOMRIGHT" then - relativePoint = "TOPRIGHT" - elseif anchorPoint == "TOPLEFT" then - relativePoint = "BOTTOMLEFT" - elseif anchorPoint == "TOPRIGHT" then - relativePoint = "BOTTOMRIGHT" - end - - button:ClearAllPoints() - button:SetPoint(anchorPoint, anchorFrame, relativePoint, 0) - - U:UpdateUnitButtonPosition(unit, button, anchorFrame) - end - -- NOTE: SetOrientation BEFORE SetPowerSize if not kind or kind == "barOrientation" then U:SetOrientation(button, Cell.vars.currentLayoutTable.barOrientation[1], @@ -220,43 +61,7 @@ function U:UpdateUnitButtonLayout(unit, kind, button, anchorFrame) end end - -- load position - if not P:LoadPosition(anchorFrame, layout[unit].position) then - P:ClearPoints(anchorFrame) - -- no position, use default - anchorFrame:SetPoint("TOPLEFT", UIParent, "CENTER") - end -end - -------------------------------------------------- --- MARK: Update Menu -------------------------------------------------- - ----@param kind ("lock" | "fadeOut" | "position")? ----@param unit Unit ----@param button CUFUnitButton ----@param anchorFrame CUFAnchorFrame ----@param config CUFConfigButton -function U:UpdateUnitButtonMenu(kind, unit, button, anchorFrame, config) - if not kind or kind == "lock" then - if CellDB.general.locked then - config:RegisterForDrag() - else - config:RegisterForDrag("LeftButton") - end - end - - if not kind or kind == "fadeOut" then - if CellDB.general.fadeOut then - anchorFrame.fadeOut:Play() - else - anchorFrame.fadeIn:Play() - end - end - - if kind == "position" then - U:UpdateUnitButtonPosition(unit, button, anchorFrame) - end + U:UpdateUnitButtonPosition(unit, button) end ------------------------------------------------- @@ -459,3 +264,70 @@ function U.UpdateClickCasting(noReload, onlyqueued, which) end CUF:RegisterCallback("UpdateClickCasting", "UpdateClickCasting", U.UpdateClickCasting) + +------------------------------------------------- +-- MARK: Create +------------------------------------------------- + +---@param unit Unit +---@return CUFUnitButton +---@return CUFUnitFrame CUFUnitFrame +local function CreateUnitButton(unit) + local name = CUF.constants.TITLE_CASED_UNITS[unit] + + ---@class CUFUnitFrame: Frame + local frame = CreateFrame("Frame", "CUF_" .. name .. "_Frame", Cell.frames.mainFrame, "SecureFrameTemplate") + + local button = CreateFrame("Button", + "CUF_" .. name, + frame, + "CUFUnitButtonTemplate") --[[@as CUFUnitButton]] + button:SetAttribute("unit", unit) + button:SetPoint("TOPLEFT") + + button.name = name + CUF.unitButtons[unit] = button + + return button, frame +end + +------------------------------------------------- +-- MARK: Register Callbacks +------------------------------------------------- + +-- Register callbacks: UpdateLayout, UpdateVisibility, UpdateUnitButtons +---@param unit Unit +---@param button CUFUnitButton +---@param unitFrame CUFUnitFrame +local function RegisterUnitButtonCallbacks(unit, button, unitFrame) + ---@param kind string? + local function UpdateLayout(_, kind) + U:UpdateUnitButtonLayout(unit, kind, button) + end + CUF:RegisterCallback("UpdateLayout", button.name .. "Frame_UpdateLayout", UpdateLayout) + + ---@param which string? Frame name (unit) + local function UnitFrame_UpdateVisibility(which) + U:UpdateUnitFrameVisibility(which, unit, button, unitFrame) + end + CUF:RegisterCallback("UpdateVisibility", button.name .. "Frame_UpdateVisibility", UnitFrame_UpdateVisibility) + + -- Call all callback functions and do a full update + local function UpdateUnitButtons() + UpdateLayout() + UnitFrame_UpdateVisibility() + end + CUF:RegisterCallback("UpdateUnitButtons", button.name .. "UpdateUnitButtons", UpdateUnitButtons) +end + +------------------------------------------------- +-- MARK: Init +------------------------------------------------- + +-- Initialize unit buttons +function U:InitUnitButtons() + for _, unit in pairs(CUF.constants.UNIT) do + local button, unitFrame = CreateUnitButton(unit) + RegisterUnitButtonCallbacks(unit, button, unitFrame) + end +end diff --git a/UnitFrames/Units.lua b/UnitFrames/Units.lua deleted file mode 100644 index 5fc6074..0000000 --- a/UnitFrames/Units.lua +++ /dev/null @@ -1,91 +0,0 @@ ----@class CUF -local CUF = select(2, ...) - -local Cell = CUF.Cell -local L = CUF.L -local P = Cell.pixelPerfectFuncs - ----@class CUF.uFuncs -local U = CUF.uFuncs - -------------------------------------------------- --- MARK: Create -------------------------------------------------- - ----@param unit Unit ----@param unitFrame CUFUnitFrame ----@return CUFUnitButton -local function CreateUnitButton(unit, unitFrame) - local name = CUF.constants.TITLE_CASED_UNITS[unit] - local button = CreateFrame("Button", - "CUF_" .. name, - unitFrame, - "CUFUnitButtonTemplate") --[[@as CUFUnitButton]] - button:SetAttribute("unit", unit) - button:SetPoint("TOPLEFT") - - button.name = name - CUF.unitButtons[unit] = button - return button -end - -------------------------------------------------- --- MARK: Register Callbacks -------------------------------------------------- - --- Register callbacks: UpdateMenu, UpdateLayout, UpdatePixelPerfect, UpdateVisibility, UpdateUnitButtons ----@param unit Unit ----@param button CUFUnitButton ----@param unitFrame CUFUnitFrame ----@param anchorFrame CUFAnchorFrame ----@param hoverFrame CUFHoverFrame ----@param config CUFConfigButton -local function RegisterUnitButtonCallbacks(unit, button, unitFrame, anchorFrame, hoverFrame, config) - ---@param kind ("lock" | "fadeOut" | "position")? - local function UpdateMenu(kind) - U:UpdateUnitButtonMenu(kind, unit, button, anchorFrame, config) - end - CUF:RegisterCallback("UpdateMenu", button.name .. "Frame_UpdateMenu", UpdateMenu) - - ---@param kind string? - local function UpdateLayout(_, kind) - U:UpdateUnitButtonLayout(unit, kind, button, anchorFrame) - end - CUF:RegisterCallback("UpdateLayout", button.name .. "Frame_UpdateLayout", UpdateLayout) - - local function UpdatePixelPerfect() - P:Resize(unitFrame) - P:Resize(anchorFrame) - config:UpdatePixelPerfect() - end - CUF:RegisterCallback("UpdatePixelPerfect", button.name .. "Frame_UpdatePixelPerfect", UpdatePixelPerfect) - - ---@param which string? Frame name (unit) - local function UnitFrame_UpdateVisibility(which) - U:UpdateUnitFrameVisibility(which, unit, button, unitFrame) - end - CUF:RegisterCallback("UpdateVisibility", button.name .. "Frame_UpdateVisibility", UnitFrame_UpdateVisibility) - - -- Call all callback functions and do a full update - local function UpdateUnitButtons() - UpdateMenu() - UpdateLayout() - UpdatePixelPerfect() - UnitFrame_UpdateVisibility() - end - CUF:RegisterCallback("UpdateUnitButtons", button.name .. "UpdateUnitButtons", UpdateUnitButtons) -end - -------------------------------------------------- --- MARK: Init -------------------------------------------------- - --- Initialize unit buttons -function U:InitUnitButtons() - for _, unit in pairs(CUF.constants.UNIT) do - local unitFrame, anchorFrame, hoverFrame, config = U:CreateBaseUnitFrame(unit) - local button = CreateUnitButton(unit, unitFrame) - - RegisterUnitButtonCallbacks(unit, button, unitFrame, anchorFrame, hoverFrame, config) - end -end From 250233a8ea038971b2435fae2fff634da67c8d27 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 00:31:54 +0200 Subject: [PATCH 02/22] first pass at an editmode --- Cell_UnitFrames.toc | 1 + Core/Init.lua | 4 + Core/OnLoad.lua | 1 + Core/SlashCommands.lua | 2 + Data/Defaults.lua | 2 + UnitFrames/EditMode.lua | 190 ++++++++++++++++++++++++++++++++++++++ UnitFrames/UnitButton.lua | 20 +++- Util/Utils.lua | 24 +++++ 8 files changed, 240 insertions(+), 4 deletions(-) create mode 100644 UnitFrames/EditMode.lua diff --git a/Cell_UnitFrames.toc b/Cell_UnitFrames.toc index b20093f..cc1b0d8 100644 --- a/Cell_UnitFrames.toc +++ b/Cell_UnitFrames.toc @@ -71,5 +71,6 @@ UnitFrames/UnitButton.xml UnitFrames/UnitButton.lua UnitFrames/OnLoad.lua UnitFrames/MenuOptions.lua +UnitFrames/EditMode.lua Core/OnLoad.lua \ No newline at end of file diff --git a/Core/Init.lua b/Core/Init.lua index b61c9ec..7e013c3 100644 --- a/Core/Init.lua +++ b/Core/Init.lua @@ -31,5 +31,9 @@ CUF.Builder = {} ---@field isMenuOpen boolean ---@field isRetail boolean ---@field selectedTab string +---@field inEditMode boolean CUF.vars = {} + +---@class CUF.unitButtons +---@field [Unit] CUFUnitButton CUF.unitButtons = {} diff --git a/Core/OnLoad.lua b/Core/OnLoad.lua index 5bee123..9696b37 100644 --- a/Core/OnLoad.lua +++ b/Core/OnLoad.lua @@ -17,6 +17,7 @@ local function OnCellInitialUpdateLayout(_layout) CUF.vars.selectedWidget = CUF.constants.WIDGET_KIND.NAME_TEXT CUF.vars.selectedLayout = Cell.vars.currentLayout CUF.vars.isRetail = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE + CUF.vars.inEditMode = false -- Hide Blizzard Unit Frames for _, unit in pairs(CUF.constants.UNIT) do diff --git a/Core/SlashCommands.lua b/Core/SlashCommands.lua index d7dd16c..e69a55b 100644 --- a/Core/SlashCommands.lua +++ b/Core/SlashCommands.lua @@ -19,6 +19,8 @@ function SlashCmdList.CUF(msg, editbox) return end CUF.DB.RestoreFromBackup(rest) + elseif command == "edit" then + CUF.uFuncs:EditMode() else CUF:Print("Available commands:" .. "\n" .. "/cuf test - toggle test mode" .. "\n" .. diff --git a/Data/Defaults.lua b/Data/Defaults.lua index c856c36..2aa42a6 100644 --- a/Data/Defaults.lua +++ b/Data/Defaults.lua @@ -599,6 +599,7 @@ Defaults.Widgets = { ---@field sameSizeAsPlayer boolean? ---@field hideBlizzardCastBar boolean? ---@field clickCast boolean +---@field mirrorPlayer boolean? ---@alias UnitLayoutTable table ---@type UnitLayoutTable @@ -638,6 +639,7 @@ Defaults.Layouts = { tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, }, sameSizeAsPlayer = false, clickCast = false, + mirrorPlayer = false, }, focus = { enabled = false, diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua new file mode 100644 index 0000000..d500056 --- /dev/null +++ b/UnitFrames/EditMode.lua @@ -0,0 +1,190 @@ +---@class CUF +local CUF = select(2, ...) + +local Cell = CUF.Cell +local P = Cell.pixelPerfectFuncs + +---@class CUF.uFuncs +local U = CUF.uFuncs + +local const = CUF.constants +local Util = CUF.Util +local L = CUF.L + +------------------------------------------------- +-- MARK: Positioning Popup +------------------------------------------------- + +---@type CUFPositioningPopup +local positioningPopup + +local function CreatePositioningPopup() + ---@class CUFPositioningPopup: Frame + positioningPopup = CUF:CreateFrame("CUFPositioningPopup", UIParent, 200, 160) + positioningPopup:SetPoint("CENTER") + positioningPopup:Hide() + + positioningPopup:SetMovable(true) + positioningPopup:EnableMouse(true) + positioningPopup:RegisterForDrag("LeftButton") + positioningPopup:SetScript("OnDragStart", function(self) + self:StartMoving() + end) + positioningPopup:SetScript("OnDragStop", function(self) + self:StopMovingOrSizing() + end) + + local closeBtn = Cell:CreateButton(positioningPopup, "×", "red", { 18, 18 }, false, false, "CELL_FONT_SPECIAL", + "CELL_FONT_SPECIAL") + closeBtn:SetPoint("TOPRIGHT", P:Scale(-5), P:Scale(-1)) + closeBtn:SetScript("OnClick", function() positioningPopup:Hide() end) + + local title = positioningPopup:CreateFontString(nil, "OVERLAY", "CELL_FONT_CLASS") + title:SetPoint("TOPLEFT", 5, -5) + positioningPopup.title = title + + local xVal = GetScreenWidth() / 2 + local yVal = GetScreenHeight() / 2 + + positioningPopup.xPosSlider = Cell:CreateSlider(L["X Offset"], positioningPopup, -xVal, xVal, 150, 1) + positioningPopup.xPosSlider:SetPoint("TOP", 0, -45) + + positioningPopup.yPosSlider = Cell:CreateSlider(L["Y Offset"], positioningPopup, -yVal, yVal, 150, 1) + positioningPopup.yPosSlider:SetPoint("TOPLEFT", positioningPopup.xPosSlider, "BOTTOMLEFT", 0, -40) + + ---@type CheckButton + local mirrorCB = Cell:CreateCheckButton(positioningPopup, L["MirrorPlayer"], function(checked) + CUF.DB.CurrentLayoutTable()[const.UNIT.TARGET].mirrorPlayer = checked + U:UpdateUnitButtonPosition("target", CUF.unitButtons.target) + positioningPopup.xPosSlider:SetEnabled(not checked) + positioningPopup.yPosSlider:SetEnabled(not checked) + end) + mirrorCB:SetPoint("TOPLEFT", positioningPopup.yPosSlider, "BOTTOMLEFT", 0, -30) + positioningPopup.mirrorCB = mirrorCB +end + +---@param unit Unit +---@param button CUFUnitButton +local function ShowPositioningPopup(unit, button) + if not positioningPopup then + CreatePositioningPopup() + end + positioningPopup:Show() + positioningPopup.title:SetText(L["Positioning"] .. ": " .. CUF.constants.TITLE_CASED_UNITS[unit]) + + positioningPopup.xPosSlider:SetValue(CUF.DB.CurrentLayoutTable()[unit].position[1]) + positioningPopup.yPosSlider:SetValue(CUF.DB.CurrentLayoutTable()[unit].position[2]) + + positioningPopup.xPosSlider.onValueChangedFn = function(value) + CUF.DB.CurrentLayoutTable()[unit].position[1] = value + U:UpdateUnitButtonPosition(unit, button) + + if unit == const.UNIT.PLAYER then + CUF:Fire("UpdateLayout", nil, "position", const.UNIT.TARGET) + end + end + positioningPopup.yPosSlider.onValueChangedFn = function(value) + CUF.DB.CurrentLayoutTable()[unit].position[2] = value + U:UpdateUnitButtonPosition(unit, button) + + if unit == const.UNIT.PLAYER then + CUF:Fire("UpdateLayout", nil, "position", const.UNIT.TARGET) + end + end + + local isMirrored = CUF.DB.CurrentLayoutTable()[unit].mirrorPlayer or false + + if unit == const.UNIT.TARGET then + positioningPopup.mirrorCB:SetChecked(isMirrored) + positioningPopup.mirrorCB:Show() + else + positioningPopup.mirrorCB:Hide() + end + + positioningPopup.xPosSlider:SetEnabled(not isMirrored) + positioningPopup.yPosSlider:SetEnabled(not isMirrored) +end + +------------------------------------------------- +-- MARK: Overlay +------------------------------------------------- + +---@param button CUFUnitButton +---@param unit Unit +local function CreateOverlayBox(button, unit) + ---@class CUFOverlayBox: Button, BackdropTemplate + local overlay = CreateFrame("Button", nil, UIParent, "BackdropTemplate") + overlay:SetAllPoints(button) + overlay:SetBackdrop({ + bgFile = "Interface\\Buttons\\WHITE8x8", + }) + overlay:SetBackdropColor(0, 1, 1, 0.5) + + overlay:SetFrameStrata("HIGH") + overlay:SetFrameLevel(overlay:GetFrameLevel() + 100) + + local overlayText = overlay:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge") + overlayText:SetPoint("BOTTOM", overlay, "TOP", 0, 5) + overlayText:SetText(L[unit]) + overlayText:SetTextColor(0, 1, 1, 1) + + overlay:RegisterForDrag("LeftButton") + overlay:RegisterForClicks("LeftButtonUp") + overlay:SetMovable(true) + button:SetMovable(true) + + overlay:SetScript("OnDragStart", function() + button:StartMoving() + end) + + overlay:SetScript("OnDragStop", function() + button:StopMovingOrSizing() + local x, y = Util.GetPositionRelativeToUIParentCenter(button) + + CUF.DB.CurrentLayoutTable()[unit].position = { x, y } + U:UpdateUnitButtonPosition(unit, button) + + if unit == const.UNIT.PLAYER then + CUF:Fire("UpdateLayout", nil, "position", const.UNIT.TARGET) + end + end) + + overlay:SetScript("OnClick", function() + ShowPositioningPopup(unit, button) + end) + + overlay:HookScript("OnShow", function() + button:SetMovable(true) + end) + overlay:HookScript("OnHide", function() + button:SetMovable(false) + end) + + return overlay +end + +---@type table +local overlays = {} + +function U:EditMode() + CUF.vars.inEditMode = not CUF.vars.inEditMode + if CUF.vars.inEditMode then + for _, unit in pairs(CUF.constants.UNIT) do + if overlays[unit] then + overlays[unit]:Show() + else + overlays[unit] = CreateOverlayBox(CUF.unitButtons[unit], unit) + end + end + else + for _, unit in pairs(CUF.constants.UNIT) do + if overlays[unit] then + overlays[unit]:Hide() + end + end + + if positioningPopup then + positioningPopup:Hide() + end + end +end diff --git a/UnitFrames/UnitButton.lua b/UnitFrames/UnitButton.lua index d82e143..1028b17 100644 --- a/UnitFrames/UnitButton.lua +++ b/UnitFrames/UnitButton.lua @@ -21,8 +21,15 @@ local Util = CUF.Util function U:UpdateUnitButtonPosition(unit, button) local layout = CUF.DB.CurrentLayoutTable() + local x, y + if unit == const.UNIT.TARGET and layout[unit].mirrorPlayer then + x, y = -layout[const.UNIT.PLAYER].position[1], layout[const.UNIT.PLAYER].position[2] + else + x, y = unpack(layout[unit].position) + end + button:ClearAllPoints() - button:SetPoint("CENTER", UIParent, "CENTER", unpack(layout[unit].position)) + button:SetPoint("CENTER", UIParent, "CENTER", x, y) end ------------------------------------------------- @@ -61,7 +68,9 @@ function U:UpdateUnitButtonLayout(unit, kind, button) end end - U:UpdateUnitButtonPosition(unit, button) + if not kind or kind == "position" then + U:UpdateUnitButtonPosition(unit, button) + end end ------------------------------------------------- @@ -301,8 +310,11 @@ end ---@param unitFrame CUFUnitFrame local function RegisterUnitButtonCallbacks(unit, button, unitFrame) ---@param kind string? - local function UpdateLayout(_, kind) - U:UpdateUnitButtonLayout(unit, kind, button) + ---@param which Unit? + local function UpdateLayout(_, kind, which) + if not which or which == unit then + U:UpdateUnitButtonLayout(unit, kind, button) + end end CUF:RegisterCallback("UpdateLayout", button.name .. "Frame_UpdateLayout", UpdateLayout) diff --git a/Util/Utils.lua b/Util/Utils.lua index 7bea9e7..993c500 100644 --- a/Util/Utils.lua +++ b/Util/Utils.lua @@ -423,6 +423,30 @@ function Util.SetIconZoom(icon, zoomLevel) icon:SetTexCoord(offset, offset + scale, offset, offset + scale) end +------------------------------------------------- +-- MARK: Pixel Perfect +------------------------------------------------- + +--- Calculates the nearest pixel size of a number +---@param number number +---@return number +function Util.GetNearestPixelSize(number) + return PixelUtil.GetNearestPixelSize(number, PixelUtil.GetPixelToUIUnitFactor()) +end + +--- Calculates the relative position of a frame to the center of the UIParent +---@param frame Frame +---@return number, number +function Util.GetPositionRelativeToUIParentCenter(frame) + local uiParentX, uiParentY = UIParent:GetCenter() + local frameX, frameY = frame:GetCenter() + + local relativeX = Util.GetNearestPixelSize(frameX - uiParentX) + local relativeY = Util.GetNearestPixelSize(frameY - uiParentY) + + return relativeX, relativeY +end + ------------------------------------------------- -- MARK: Formatting ------------------------------------------------- From 2f53829be59341bae94deeb2487f1ceddc0d2865 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 09:13:24 +0200 Subject: [PATCH 03/22] add a button to toggle edit mode --- Menu/Menu.lua | 10 ++++++++++ UnitFrames/EditMode.lua | 10 ++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Menu/Menu.lua b/Menu/Menu.lua index c939211..9e9810c 100644 --- a/Menu/Menu.lua +++ b/Menu/Menu.lua @@ -230,6 +230,16 @@ function menu:CreateMenu() titleFrame:SetHeight(title:GetStringHeight() + pad * 2) titleFrame:SetWidth(title:GetStringWidth() + pad * 2) + local previewModeButton = Cell:CreateButton(titleFrame, L["Edit Mode"], "accent", + { 80, 20 }) + previewModeButton:SetPoint("BOTTOMLEFT", titleFrame, "BOTTOMRIGHT", -1, 0) + previewModeButton:SetScript("OnClick", function() + CUF.uFuncs:EditMode() + end) + previewModeButton:SetScript("OnHide", function() + CUF.uFuncs:EditMode(false) + end) + -- Title local layoutTitleFrame = CUF:CreateFrame(nil, titleFrame, 160, 10, false, true) layoutTitleFrame:SetPoint("BOTTOMLEFT", titleFrame, "TOPLEFT", 0, -1) diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua index d500056..09846ce 100644 --- a/UnitFrames/EditMode.lua +++ b/UnitFrames/EditMode.lua @@ -166,8 +166,14 @@ end ---@type table local overlays = {} -function U:EditMode() - CUF.vars.inEditMode = not CUF.vars.inEditMode +---@param show boolean? +function U:EditMode(show) + if show ~= nil then + CUF.vars.inEditMode = show + else + CUF.vars.inEditMode = not CUF.vars.inEditMode + end + if CUF.vars.inEditMode then for _, unit in pairs(CUF.constants.UNIT) do if overlays[unit] then From 133e67b9ead639679eab27591cbf7b969264da90 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 09:15:20 +0200 Subject: [PATCH 04/22] move menu frame down to compensate --- Menu/Menu.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Menu/Menu.lua b/Menu/Menu.lua index 9e9810c..9138d06 100644 --- a/Menu/Menu.lua +++ b/Menu/Menu.lua @@ -210,7 +210,7 @@ function menu:CreateMenu() ---@class CellCombatFrame self.window = CUF:CreateFrame("CUF_Menu", optionsFrame, self.baseWidth, 300) - self.window:SetPoint("TOPRIGHT", CellLayoutsPreviewButton, "BOTTOMRIGHT", 0, -self.inset) + self.window:SetPoint("TOPRIGHT", CellLayoutsPreviewButton, "BOTTOMRIGHT", 0, -self.inset - 20) -- mask F:ApplyCombatProtectionToFrame(self.window) From 3f9be835f7dae6364311f8963407d6eaf8e55db1 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 09:25:38 +0200 Subject: [PATCH 05/22] hide overlays when in combat --- UnitFrames/EditMode.lua | 60 ++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua index 09846ce..357e105 100644 --- a/UnitFrames/EditMode.lua +++ b/UnitFrames/EditMode.lua @@ -105,10 +105,19 @@ local function ShowPositioningPopup(unit, button) positioningPopup.yPosSlider:SetEnabled(not isMirrored) end +local function HidePositioningPopup() + if positioningPopup then + positioningPopup:Hide() + end +end + ------------------------------------------------- -- MARK: Overlay ------------------------------------------------- +---@type table +local overlays = {} + ---@param button CUFUnitButton ---@param unit Unit local function CreateOverlayBox(button, unit) @@ -155,16 +164,42 @@ local function CreateOverlayBox(button, unit) overlay:HookScript("OnShow", function() button:SetMovable(true) + overlay:RegisterEvent("PLAYER_REGEN_DISABLED") end) overlay:HookScript("OnHide", function() button:SetMovable(false) + overlay:UnregisterEvent("PLAYER_REGEN_DISABLED") end) return overlay end ----@type table -local overlays = {} +local function HideOverlays() + for _, overlay in pairs(overlays) do + overlay:Hide() + end +end + +local function ShowOverlays() + for _, unit in pairs(CUF.constants.UNIT) do + if overlays[unit] then + overlays[unit]:Show() + else + overlays[unit] = CreateOverlayBox(CUF.unitButtons[unit], unit) + end + end +end + +------------------------------------------------- +-- MARK: Edit Mode +------------------------------------------------- + +local eventFrame = CreateFrame("Frame") +eventFrame:SetScript("OnEvent", function() + CUF.vars.inEditMode = false + HideOverlays() + HidePositioningPopup() +end) ---@param show boolean? function U:EditMode(show) @@ -175,22 +210,11 @@ function U:EditMode(show) end if CUF.vars.inEditMode then - for _, unit in pairs(CUF.constants.UNIT) do - if overlays[unit] then - overlays[unit]:Show() - else - overlays[unit] = CreateOverlayBox(CUF.unitButtons[unit], unit) - end - end + ShowOverlays() + eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED") else - for _, unit in pairs(CUF.constants.UNIT) do - if overlays[unit] then - overlays[unit]:Hide() - end - end - - if positioningPopup then - positioningPopup:Hide() - end + HideOverlays() + HidePositioningPopup() + eventFrame:UnregisterEvent("PLAYER_REGEN_DISABLED") end end From 79b5ceec5cd01985dc1260b07e977b4eae49f546 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 09:41:29 +0200 Subject: [PATCH 06/22] increase overlayText scale and use cell widget font --- UnitFrames/EditMode.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua index 357e105..b4a30aa 100644 --- a/UnitFrames/EditMode.lua +++ b/UnitFrames/EditMode.lua @@ -132,10 +132,10 @@ local function CreateOverlayBox(button, unit) overlay:SetFrameStrata("HIGH") overlay:SetFrameLevel(overlay:GetFrameLevel() + 100) - local overlayText = overlay:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge") + local overlayText = overlay:CreateFontString(nil, "OVERLAY", const.FONTS.CELL_WIGET) overlayText:SetPoint("BOTTOM", overlay, "TOP", 0, 5) overlayText:SetText(L[unit]) - overlayText:SetTextColor(0, 1, 1, 1) + overlayText:SetScale(1.5) overlay:RegisterForDrag("LeftButton") overlay:RegisterForClicks("LeftButtonUp") From 3a6095c6fcff519786c2c30db776d3a1e0778ee7 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 09:59:11 +0200 Subject: [PATCH 07/22] update overlay styling --- UnitFrames/EditMode.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua index b4a30aa..2570d63 100644 --- a/UnitFrames/EditMode.lua +++ b/UnitFrames/EditMode.lua @@ -118,16 +118,36 @@ end ---@type table local overlays = {} +local colors = { + [const.UNIT.PLAYER] = { 1, 0, 0 }, + [const.UNIT.TARGET] = { 1, 0.5, 0 }, + [const.UNIT.TARGET_TARGET] = { 1, 1, 0 }, + [const.UNIT.FOCUS] = { 0, 1, 0 }, + [const.UNIT.PET] = { 0, 0.5, 1 }, +} + ---@param button CUFUnitButton ---@param unit Unit local function CreateOverlayBox(button, unit) ---@class CUFOverlayBox: Button, BackdropTemplate local overlay = CreateFrame("Button", nil, UIParent, "BackdropTemplate") overlay:SetAllPoints(button) - overlay:SetBackdrop({ - bgFile = "Interface\\Buttons\\WHITE8x8", + + overlay.border = CreateFrame("Frame", nil, overlay, "BackdropTemplate") + overlay.border:SetAllPoints() + overlay.border:SetBackdrop({ + bgFile = nil, + edgeFile = "Interface\\Buttons\\WHITE8X8", + edgeSize = 1, }) - overlay:SetBackdropColor(0, 1, 1, 0.5) + overlay.border:SetBackdropBorderColor(0, 0, 0, 1) + + overlay.tex = overlay:CreateTexture(nil, "ARTWORK") + overlay.tex:SetTexture(Cell.vars.whiteTexture) + overlay.tex:SetAllPoints() + + local r, g, b = unpack(colors[unit]) + overlay.tex:SetVertexColor(r, g, b, 0.5) overlay:SetFrameStrata("HIGH") overlay:SetFrameLevel(overlay:GetFrameLevel() + 100) From 3b99dfc3bf67c5233b6a9c534d06b0c92f5a5fe7 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 10:04:06 +0200 Subject: [PATCH 08/22] update overlay label --- UnitFrames/EditMode.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua index 2570d63..6945195 100644 --- a/UnitFrames/EditMode.lua +++ b/UnitFrames/EditMode.lua @@ -152,10 +152,9 @@ local function CreateOverlayBox(button, unit) overlay:SetFrameStrata("HIGH") overlay:SetFrameLevel(overlay:GetFrameLevel() + 100) - local overlayText = overlay:CreateFontString(nil, "OVERLAY", const.FONTS.CELL_WIGET) - overlayText:SetPoint("BOTTOM", overlay, "TOP", 0, 5) - overlayText:SetText(L[unit]) - overlayText:SetScale(1.5) + local label = overlay:CreateFontString(nil, "OVERLAY", const.FONTS.CELL_WIGET) + label:SetPoint("CENTER") + label:SetText(L[unit]) overlay:RegisterForDrag("LeftButton") overlay:RegisterForClicks("LeftButtonUp") From 9aa9b5aee14c2778dbc0c0ceb078a9ad7568629a Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 10:18:36 +0200 Subject: [PATCH 09/22] add animation --- UnitFrames/EditMode.lua | 74 +++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 21 deletions(-) diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua index 6945195..9ca1e2f 100644 --- a/UnitFrames/EditMode.lua +++ b/UnitFrames/EditMode.lua @@ -115,7 +115,7 @@ end -- MARK: Overlay ------------------------------------------------- ----@type table +---@type table local overlays = {} local colors = { @@ -132,39 +132,60 @@ local function CreateOverlayBox(button, unit) ---@class CUFOverlayBox: Button, BackdropTemplate local overlay = CreateFrame("Button", nil, UIParent, "BackdropTemplate") overlay:SetAllPoints(button) + overlay:SetFrameStrata("HIGH") + overlay:SetFrameLevel(overlay:GetFrameLevel() + 100) + overlay:Hide() - overlay.border = CreateFrame("Frame", nil, overlay, "BackdropTemplate") - overlay.border:SetAllPoints() - overlay.border:SetBackdrop({ + local border = CreateFrame("Frame", nil, overlay, "BackdropTemplate") + border:SetAllPoints() + border:SetBackdrop({ bgFile = nil, edgeFile = "Interface\\Buttons\\WHITE8X8", edgeSize = 1, }) - overlay.border:SetBackdropBorderColor(0, 0, 0, 1) - - overlay.tex = overlay:CreateTexture(nil, "ARTWORK") - overlay.tex:SetTexture(Cell.vars.whiteTexture) - overlay.tex:SetAllPoints() + border:SetBackdropBorderColor(0, 0, 0, 1) + local tex = overlay:CreateTexture(nil, "ARTWORK") + tex:SetTexture(Cell.vars.whiteTexture) + tex:SetAllPoints() local r, g, b = unpack(colors[unit]) - overlay.tex:SetVertexColor(r, g, b, 0.5) - - overlay:SetFrameStrata("HIGH") - overlay:SetFrameLevel(overlay:GetFrameLevel() + 100) + tex:SetVertexColor(r, g, b, 0.5) local label = overlay:CreateFontString(nil, "OVERLAY", const.FONTS.CELL_WIGET) label:SetPoint("CENTER") label:SetText(L[unit]) + -- Register mouse and movable overlay:RegisterForDrag("LeftButton") overlay:RegisterForClicks("LeftButtonUp") overlay:SetMovable(true) button:SetMovable(true) + -- Animation + overlay.fadeIn = overlay:CreateAnimationGroup() + local fadeIn = overlay.fadeIn:CreateAnimation("alpha") + fadeIn:SetFromAlpha(0) + fadeIn:SetToAlpha(1) + fadeIn:SetDuration(0.5) + fadeIn:SetSmoothing("OUT") + fadeIn:SetScript("OnPlay", function() + overlay:Show() + end) + + overlay.fadeOut = overlay:CreateAnimationGroup() + local fadeOut = overlay.fadeOut:CreateAnimation("alpha") + fadeOut:SetFromAlpha(1) + fadeOut:SetToAlpha(0) + fadeOut:SetDuration(0.5) + fadeOut:SetSmoothing("IN") + fadeOut:SetScript("OnFinished", function() + overlay:Hide() + end) + + -- Scripts overlay:SetScript("OnDragStart", function() button:StartMoving() end) - overlay:SetScript("OnDragStop", function() button:StopMovingOrSizing() local x, y = Util.GetPositionRelativeToUIParentCenter(button) @@ -176,35 +197,43 @@ local function CreateOverlayBox(button, unit) CUF:Fire("UpdateLayout", nil, "position", const.UNIT.TARGET) end end) - overlay:SetScript("OnClick", function() ShowPositioningPopup(unit, button) end) + -- Hooks overlay:HookScript("OnShow", function() button:SetMovable(true) - overlay:RegisterEvent("PLAYER_REGEN_DISABLED") end) overlay:HookScript("OnHide", function() button:SetMovable(false) - overlay:UnregisterEvent("PLAYER_REGEN_DISABLED") end) return overlay end -local function HideOverlays() +--- Play the fade out animation and hide the overlays +--- +--- If instant is true, the overlays will be hidden instantly +---@param instant boolean? +local function HideOverlays(instant) for _, overlay in pairs(overlays) do - overlay:Hide() + if instant then + overlay:Hide() + else + overlay.fadeOut:Play() + end end end +--- Play the fade in animation and show the overlays local function ShowOverlays() for _, unit in pairs(CUF.constants.UNIT) do if overlays[unit] then - overlays[unit]:Show() + overlays[unit].fadeIn:Play() else overlays[unit] = CreateOverlayBox(CUF.unitButtons[unit], unit) + overlays[unit].fadeIn:Play() end end end @@ -216,10 +245,13 @@ end local eventFrame = CreateFrame("Frame") eventFrame:SetScript("OnEvent", function() CUF.vars.inEditMode = false - HideOverlays() + HideOverlays(true) HidePositioningPopup() end) +--- Enable or disable edit mode +--- +--- If show is nil then the current state will be toggled ---@param show boolean? function U:EditMode(show) if show ~= nil then From 5a57d1cb060f9b52600cb5a1eab083f1832b5198 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 10:24:40 +0200 Subject: [PATCH 10/22] update position Popup when dragging --- UnitFrames/EditMode.lua | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua index 9ca1e2f..894a94c 100644 --- a/UnitFrames/EditMode.lua +++ b/UnitFrames/EditMode.lua @@ -20,6 +20,7 @@ local positioningPopup local function CreatePositioningPopup() ---@class CUFPositioningPopup: Frame + ---@field unit Unit positioningPopup = CUF:CreateFrame("CUFPositioningPopup", UIParent, 200, 160) positioningPopup:SetPoint("CENTER") positioningPopup:Hide() @@ -63,6 +64,26 @@ local function CreatePositioningPopup() positioningPopup.mirrorCB = mirrorCB end +local function UpdatePositioningPopup() + if not positioningPopup then return end + local unit = positioningPopup.unit + + positioningPopup.xPosSlider:SetValue(CUF.DB.CurrentLayoutTable()[unit].position[1]) + positioningPopup.yPosSlider:SetValue(CUF.DB.CurrentLayoutTable()[unit].position[2]) + + local isMirrored = CUF.DB.CurrentLayoutTable()[unit].mirrorPlayer or false + + if unit == const.UNIT.TARGET then + positioningPopup.mirrorCB:SetChecked(isMirrored) + positioningPopup.mirrorCB:Show() + else + positioningPopup.mirrorCB:Hide() + end + + positioningPopup.xPosSlider:SetEnabled(not isMirrored) + positioningPopup.yPosSlider:SetEnabled(not isMirrored) +end + ---@param unit Unit ---@param button CUFUnitButton local function ShowPositioningPopup(unit, button) @@ -72,8 +93,7 @@ local function ShowPositioningPopup(unit, button) positioningPopup:Show() positioningPopup.title:SetText(L["Positioning"] .. ": " .. CUF.constants.TITLE_CASED_UNITS[unit]) - positioningPopup.xPosSlider:SetValue(CUF.DB.CurrentLayoutTable()[unit].position[1]) - positioningPopup.yPosSlider:SetValue(CUF.DB.CurrentLayoutTable()[unit].position[2]) + positioningPopup.unit = unit positioningPopup.xPosSlider.onValueChangedFn = function(value) CUF.DB.CurrentLayoutTable()[unit].position[1] = value @@ -92,17 +112,7 @@ local function ShowPositioningPopup(unit, button) end end - local isMirrored = CUF.DB.CurrentLayoutTable()[unit].mirrorPlayer or false - - if unit == const.UNIT.TARGET then - positioningPopup.mirrorCB:SetChecked(isMirrored) - positioningPopup.mirrorCB:Show() - else - positioningPopup.mirrorCB:Hide() - end - - positioningPopup.xPosSlider:SetEnabled(not isMirrored) - positioningPopup.yPosSlider:SetEnabled(not isMirrored) + UpdatePositioningPopup() end local function HidePositioningPopup() @@ -196,6 +206,8 @@ local function CreateOverlayBox(button, unit) if unit == const.UNIT.PLAYER then CUF:Fire("UpdateLayout", nil, "position", const.UNIT.TARGET) end + + UpdatePositioningPopup() end) overlay:SetScript("OnClick", function() ShowPositioningPopup(unit, button) From 9e8a76dca8a22a580caea27a46e53c435aab9d41 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 10:29:26 +0200 Subject: [PATCH 11/22] update popup on UpdateLayout & UpdateUnitButton callbacks --- UnitFrames/EditMode.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua index 894a94c..c8b5423 100644 --- a/UnitFrames/EditMode.lua +++ b/UnitFrames/EditMode.lua @@ -113,12 +113,18 @@ local function ShowPositioningPopup(unit, button) end UpdatePositioningPopup() + + CUF:RegisterCallback("UpdateUnitButtons", "UpdatePositioningPopup", UpdatePositioningPopup) + CUF:RegisterCallback("UpdateLayout", "UpdatePositioningPopup", UpdatePositioningPopup) end local function HidePositioningPopup() if positioningPopup then positioningPopup:Hide() end + + CUF:UnregisterCallback("UpdateUnitButtons", "UpdatePositioningPopup") + CUF:UnregisterCallback("UpdateLayout", "UpdatePositioningPopup") end ------------------------------------------------- From 294ba513c84a75feed54a7fa25d1e44d74fb5a21 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 10:35:38 +0200 Subject: [PATCH 12/22] remove anchor dropdown from units --- Data/Defaults.lua | 6 ------ UnitFrames/MenuOptions.lua | 33 +-------------------------------- 2 files changed, 1 insertion(+), 38 deletions(-) diff --git a/Data/Defaults.lua b/Data/Defaults.lua index 2aa42a6..07e990c 100644 --- a/Data/Defaults.lua +++ b/Data/Defaults.lua @@ -592,7 +592,6 @@ Defaults.Widgets = { ---@field enabled boolean ---@field powerSize number ---@field size Size ----@field point FramePoint ---@field position Position ---@field widgets WidgetTables ---@field tooltipPosition TooltipPosition @@ -608,7 +607,6 @@ Defaults.Layouts = { enabled = false, powerSize = 2, size = { 200, 40 }, - point = "BOTTOMLEFT", position = { 800, 500 }, widgets = Defaults.Widgets, tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, }, @@ -619,7 +617,6 @@ Defaults.Layouts = { enabled = false, powerSize = 2, size = { 200, 40 }, - point = "BOTTOMLEFT", position = { 1400, 500 }, widgets = { nameText = Defaults.Widgets.nameText, @@ -645,7 +642,6 @@ Defaults.Layouts = { enabled = false, powerSize = 2, size = { 100, 30 }, - point = "BOTTOMLEFT", position = { 800, 700 }, widgets = { nameText = Defaults.Widgets.nameText, @@ -670,7 +666,6 @@ Defaults.Layouts = { enabled = false, powerSize = 2, size = { 200, 40 }, - point = "BOTTOMLEFT", position = { 1620, 500 }, widgets = { nameText = Defaults.Widgets.nameText, @@ -687,7 +682,6 @@ Defaults.Layouts = { enabled = false, powerSize = 2, size = { 200, 30 }, - point = "BOTTOMLEFT", position = { 800, 460 }, widgets = { nameText = Defaults.Widgets.nameText, diff --git a/UnitFrames/MenuOptions.lua b/UnitFrames/MenuOptions.lua index 37e8f14..3f81dd1 100644 --- a/UnitFrames/MenuOptions.lua +++ b/UnitFrames/MenuOptions.lua @@ -12,12 +12,6 @@ local function UpdateSize() end end -local function UpdateArrangement() - if CUF.vars.selectedLayout == CUF.DB.GetMasterLayout() then - CUF:Fire("UpdateLayout", CUF.vars.selectedLayout, CUF.vars.selectedUnit .. "-arrangement") - end -end - ---@param unitPage UnitsMenuPage local function AddLoadPageDB(unitPage) -- Load page from DB @@ -33,9 +27,6 @@ local function AddLoadPageDB(unitPage) unitPage.heightSlider:SetValue(pageDB.size[2]) unitPage.powerSizeSlider:SetValue(pageDB.powerSize) - -- unit arrangement - unitPage.anchorDropdown:SetSelectedValue(pageDB.point) - -- same as player if not isPlayerPage then unitPage.sameSizeAsPlayerCB:SetChecked(isSameSizeAsPlayer) @@ -50,12 +41,10 @@ local function AddLoadPageDB(unitPage) unitPage.widthSlider:SetEnabled(true) unitPage.heightSlider:SetEnabled(true) unitPage.powerSizeSlider:SetEnabled(true) - unitPage.anchorDropdown:SetEnabled(true) else unitPage.widthSlider:SetEnabled(not isSameSizeAsPlayer) unitPage.heightSlider:SetEnabled(not isSameSizeAsPlayer) unitPage.powerSizeSlider:SetEnabled(not isSameSizeAsPlayer) - unitPage.anchorDropdown:SetEnabled(not isSameSizeAsPlayer) end -- copy from @@ -133,8 +122,6 @@ local function AddUnitsToMenu() unitPage.widthSlider:SetEnabled(not checked) unitPage.heightSlider:SetEnabled(not checked) unitPage.powerSizeSlider:SetEnabled(not checked) - -- TODO: should be arrangment based instead - unitPage.anchorDropdown:SetEnabled(not checked) -- update size and power UpdateSize() @@ -162,27 +149,9 @@ local function AddUnitsToMenu() end) unitPage.widthSlider:SetPoint("TOPLEFT", unitPage.enabledCB, 0, -50) - ---@type CellDropdown - unitPage.anchorDropdown = Cell:CreateDropdown(unitPage.frame, 117) - unitPage.anchorDropdown:SetPoint("TOPLEFT", unitPage.widthSlider, "TOPRIGHT", 30, 0) - - local dropdownItems = {} - for _, point in ipairs(CUF.constants.UNIT_ANCHOR_POINTS) do - tinsert(dropdownItems, { - ["text"] = L[point], - ["value"] = point, - ["onClick"] = function() - CUF.DB.SelectedLayoutTable()[unit].point = point - UpdateArrangement() - end, - }) - end - unitPage.anchorDropdown:SetItems(dropdownItems) - unitPage.anchorDropdown:SetLabel(L["Anchor Point"]) - ---@type CellDropdown unitPage.copyFromDropdown = Cell:CreateDropdown(unitPage.frame, 117) - unitPage.copyFromDropdown:SetPoint("TOPLEFT", unitPage.anchorDropdown, "TOPRIGHT", 30, 0) + unitPage.copyFromDropdown:SetPoint("TOPLEFT", unitPage.widthSlider, "TOPRIGHT", 30, 0) unitPage.copyFromDropdown:SetLabel(L.CopyWidgetsFrom) CUF:SetTooltips(unitPage.copyFromDropdown, "ANCHOR_TOPLEFT", 0, 3, L.CopyWidgetsFrom, L.CopyWidgetsFromTooltip) From 2fca4935c775fc731eadd854b9cefb525da9d381 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 11:47:52 +0200 Subject: [PATCH 13/22] add parent anchor options --- Data/Defaults.lua | 35 ++++++--- UnitFrames/EditMode.lua | 156 +++++++++++++++++++++++++++++++------- UnitFrames/UnitButton.lua | 22 ++++-- 3 files changed, 169 insertions(+), 44 deletions(-) diff --git a/Data/Defaults.lua b/Data/Defaults.lua index 07e990c..f1f3a88 100644 --- a/Data/Defaults.lua +++ b/Data/Defaults.lua @@ -582,11 +582,11 @@ Defaults.Widgets = { ---@field [1] number ---@field [2] number ----@class TooltipPosition ----@field [1] FramePoint ----@field [2] FramePoint ----@field [3] number ----@field [4] number +---@class ParentAnchor +---@field point FramePoint +---@field relativePoint FramePoint +---@field offsetX number +---@field offsetY number ---@class UnitLayout ---@field enabled boolean @@ -594,11 +594,13 @@ Defaults.Widgets = { ---@field size Size ---@field position Position ---@field widgets WidgetTables ----@field tooltipPosition TooltipPosition ---@field sameSizeAsPlayer boolean? ---@field hideBlizzardCastBar boolean? ---@field clickCast boolean ---@field mirrorPlayer boolean? +---@field parent Unit? +---@field anchorToParent boolean? +---@field anchorPosition ParentAnchor? ---@alias UnitLayoutTable table ---@type UnitLayoutTable @@ -609,7 +611,6 @@ Defaults.Layouts = { size = { 200, 40 }, position = { 800, 500 }, widgets = Defaults.Widgets, - tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, }, hideBlizzardCastBar = false, clickCast = false, }, @@ -633,7 +634,6 @@ Defaults.Layouts = { shieldBar = Defaults.Widgets.shieldBar, castBar = Defaults.Widgets.castBar, }, - tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, }, sameSizeAsPlayer = false, clickCast = false, mirrorPlayer = false, @@ -658,7 +658,6 @@ Defaults.Layouts = { shieldBar = Defaults.Widgets.shieldBar, castBar = Defaults.Widgets.castBar, }, - tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, }, sameSizeAsPlayer = false, clickCast = false, }, @@ -674,9 +673,16 @@ Defaults.Layouts = { levelText = Defaults.Widgets.levelText, raidIcon = Defaults.Widgets.raidIcon, }, - tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, }, sameSizeAsPlayer = false, clickCast = false, + anchorToParent = true, + parent = CUF.constants.UNIT.TARGET, + anchorPosition = { + point = "BOTTOMLEFT", + relativePoint = "BOTTOMRIGHT", + offsetX = 2, + offsetY = 0 + }, }, pet = { enabled = false, @@ -694,8 +700,15 @@ Defaults.Layouts = { shieldBar = Defaults.Widgets.shieldBar, castBar = Defaults.Widgets.castBar, }, - tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, }, sameSizeAsPlayer = false, clickCast = false, + anchorToParent = true, + parent = CUF.constants.UNIT.PLAYER, + anchorPosition = { + point = "TOPLEFT", + relativePoint = "BOTTOMLEFT", + offsetX = 0, + offsetY = -5 + }, }, } diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua index c8b5423..ada6d5f 100644 --- a/UnitFrames/EditMode.lua +++ b/UnitFrames/EditMode.lua @@ -21,7 +21,7 @@ local positioningPopup local function CreatePositioningPopup() ---@class CUFPositioningPopup: Frame ---@field unit Unit - positioningPopup = CUF:CreateFrame("CUFPositioningPopup", UIParent, 200, 160) + positioningPopup = CUF:CreateFrame("CUFPositioningPopup", UIParent, 340, 160) positioningPopup:SetPoint("CENTER") positioningPopup:Hide() @@ -44,15 +44,34 @@ local function CreatePositioningPopup() title:SetPoint("TOPLEFT", 5, -5) positioningPopup.title = title + -- Offsets local xVal = GetScreenWidth() / 2 local yVal = GetScreenHeight() / 2 positioningPopup.xPosSlider = Cell:CreateSlider(L["X Offset"], positioningPopup, -xVal, xVal, 150, 1) - positioningPopup.xPosSlider:SetPoint("TOP", 0, -45) + positioningPopup.xPosSlider:SetPoint("TOPLEFT", 10, -45) + positioningPopup.xPosSlider.onValueChangedFn = function(value) + CUF.DB.CurrentLayoutTable()[positioningPopup.unit].position[1] = value + CUF:Fire("UpdateLayout", nil, "position", positioningPopup.unit) + + if positioningPopup.unit == const.UNIT.PLAYER then + CUF:Fire("UpdateLayout", nil, "position", const.UNIT.TARGET) + end + end positioningPopup.yPosSlider = Cell:CreateSlider(L["Y Offset"], positioningPopup, -yVal, yVal, 150, 1) - positioningPopup.yPosSlider:SetPoint("TOPLEFT", positioningPopup.xPosSlider, "BOTTOMLEFT", 0, -40) + positioningPopup.yPosSlider:SetPoint("TOPLEFT", positioningPopup.xPosSlider, "TOPRIGHT", 20, 0) + + positioningPopup.yPosSlider.onValueChangedFn = function(value) + CUF.DB.CurrentLayoutTable()[positioningPopup.unit].position[2] = value + CUF:Fire("UpdateLayout", nil, "position", positioningPopup.unit) + + if positioningPopup.unit == const.UNIT.PLAYER then + CUF:Fire("UpdateLayout", nil, "position", const.UNIT.TARGET) + end + end + -- Mirror ---@type CheckButton local mirrorCB = Cell:CreateCheckButton(positioningPopup, L["MirrorPlayer"], function(checked) CUF.DB.CurrentLayoutTable()[const.UNIT.TARGET].mirrorPlayer = checked @@ -60,18 +79,88 @@ local function CreatePositioningPopup() positioningPopup.xPosSlider:SetEnabled(not checked) positioningPopup.yPosSlider:SetEnabled(not checked) end) - mirrorCB:SetPoint("TOPLEFT", positioningPopup.yPosSlider, "BOTTOMLEFT", 0, -30) + mirrorCB:SetPoint("TOPLEFT", positioningPopup.xPosSlider, "BOTTOMLEFT", 0, -40) positioningPopup.mirrorCB = mirrorCB + + -- Parent Anchor + local parentAnchorFrame = CreateFrame("Frame", nil, positioningPopup) + + ---@type CellCheckButton + local anchorToParentCB = Cell:CreateCheckButton(parentAnchorFrame, "", function(checked) + CUF.DB.CurrentLayoutTable()[positioningPopup.unit].anchorToParent = checked + U:UpdateUnitButtonPosition("target", CUF.unitButtons.target) + CUF:Fire("UpdateLayout", nil, "position", positioningPopup.unit) + + positioningPopup.pointDropdown:SetEnabled(checked) + positioningPopup.relativeDropdown:SetEnabled(checked) + positioningPopup.parentOffsetXSlider:SetEnabled(checked) + positioningPopup.parentOffsetYSlider:SetEnabled(checked) + + positioningPopup.xPosSlider:SetEnabled(not checked) + positioningPopup.yPosSlider:SetEnabled(not checked) + end) + anchorToParentCB:SetPoint("TOPLEFT", positioningPopup.xPosSlider, "BOTTOMLEFT", 0, -40) + positioningPopup.anchorToParentCB = anchorToParentCB + + ---@type CellDropdown + local pointDropdown = Cell:CreateDropdown(parentAnchorFrame, 117) + pointDropdown:SetPoint("TOPLEFT", anchorToParentCB, "BOTTOMLEFT", 0, -30) + pointDropdown:SetLabel(L["Anchor Point"]) + + ---@type CellDropdown + local relativePointDropdown = Cell:CreateDropdown(parentAnchorFrame, 117) + relativePointDropdown:SetPoint("TOPLEFT", pointDropdown, "TOPRIGHT", 30, 0) + relativePointDropdown:SetLabel(L["To UnitButton's"]) + + for _, point in pairs(const.ANCHOR_POINTS) do + pointDropdown:AddItem({ + text = L[point], + value = point, + onClick = function() + CUF.DB.CurrentLayoutTable()[positioningPopup.unit].anchorPosition.point = point + CUF:Fire("UpdateLayout", nil, "position", positioningPopup.unit) + end, + }) + relativePointDropdown:AddItem({ + text = L[point], + value = point, + onClick = function() + CUF.DB.CurrentLayoutTable()[positioningPopup.unit].anchorPosition.relativePoint = point + CUF:Fire("UpdateLayout", nil, "position", positioningPopup.unit) + end, + }) + end + + local parentOffsetXSlider = Cell:CreateSlider(L["X Offset"], parentAnchorFrame, -xVal, xVal, 150, 1) + parentOffsetXSlider:SetPoint("TOPLEFT", pointDropdown, "BOTTOMLEFT", 0, -30) + parentOffsetXSlider.onValueChangedFn = function(value) + CUF.DB.CurrentLayoutTable()[positioningPopup.unit].anchorPosition.offsetX = value + CUF:Fire("UpdateLayout", nil, "position", positioningPopup.unit) + end + + local parentOffsetYSlider = Cell:CreateSlider(L["Y Offset"], parentAnchorFrame, -yVal, yVal, 150, 1) + parentOffsetYSlider:SetPoint("TOPLEFT", parentOffsetXSlider, "TOPRIGHT", 20, 0) + parentOffsetYSlider.onValueChangedFn = function(value) + CUF.DB.CurrentLayoutTable()[positioningPopup.unit].anchorPosition.offsetY = value + CUF:Fire("UpdateLayout", nil, "position", positioningPopup.unit) + end + + positioningPopup.parentAnchorFrame = parentAnchorFrame + positioningPopup.pointDropdown = pointDropdown + positioningPopup.relativeDropdown = relativePointDropdown + positioningPopup.parentOffsetXSlider = parentOffsetXSlider + positioningPopup.parentOffsetYSlider = parentOffsetYSlider end local function UpdatePositioningPopup() if not positioningPopup then return end local unit = positioningPopup.unit + local layout = CUF.DB.CurrentLayoutTable()[unit] - positioningPopup.xPosSlider:SetValue(CUF.DB.CurrentLayoutTable()[unit].position[1]) - positioningPopup.yPosSlider:SetValue(CUF.DB.CurrentLayoutTable()[unit].position[2]) + positioningPopup.xPosSlider:SetValue(layout.position[1]) + positioningPopup.yPosSlider:SetValue(layout.position[2]) - local isMirrored = CUF.DB.CurrentLayoutTable()[unit].mirrorPlayer or false + local isMirrored = layout.mirrorPlayer or false if unit == const.UNIT.TARGET then positioningPopup.mirrorCB:SetChecked(isMirrored) @@ -80,13 +169,33 @@ local function UpdatePositioningPopup() positioningPopup.mirrorCB:Hide() end - positioningPopup.xPosSlider:SetEnabled(not isMirrored) - positioningPopup.yPosSlider:SetEnabled(not isMirrored) + if layout.anchorToParent ~= nil then + local checked = layout.anchorToParent + + positioningPopup.anchorToParentCB:SetChecked(checked) + positioningPopup.anchorToParentCB.label:SetText(L["Anchor To"] .. " " .. L[layout.parent]) + + positioningPopup.pointDropdown:SetSelectedValue(layout.anchorPosition.point) + positioningPopup.relativeDropdown:SetSelectedValue(layout.anchorPosition + .relativePoint) + positioningPopup.parentOffsetXSlider:SetValue(layout.anchorPosition.offsetX) + positioningPopup.parentOffsetYSlider:SetValue(layout.anchorPosition.offsetY) + + positioningPopup.pointDropdown:SetEnabled(checked) + positioningPopup.relativeDropdown:SetEnabled(checked) + positioningPopup.parentOffsetXSlider:SetEnabled(checked) + positioningPopup.parentOffsetYSlider:SetEnabled(checked) + + positioningPopup.xPosSlider:SetEnabled(not checked) + positioningPopup.yPosSlider:SetEnabled(not checked) + else + positioningPopup.xPosSlider:SetEnabled(not isMirrored) + positioningPopup.yPosSlider:SetEnabled(not isMirrored) + end end ---@param unit Unit ----@param button CUFUnitButton -local function ShowPositioningPopup(unit, button) +local function ShowPositioningPopup(unit) if not positioningPopup then CreatePositioningPopup() end @@ -95,20 +204,15 @@ local function ShowPositioningPopup(unit, button) positioningPopup.unit = unit - positioningPopup.xPosSlider.onValueChangedFn = function(value) - CUF.DB.CurrentLayoutTable()[unit].position[1] = value - U:UpdateUnitButtonPosition(unit, button) - - if unit == const.UNIT.PLAYER then - CUF:Fire("UpdateLayout", nil, "position", const.UNIT.TARGET) - end - end - positioningPopup.yPosSlider.onValueChangedFn = function(value) - CUF.DB.CurrentLayoutTable()[unit].position[2] = value - U:UpdateUnitButtonPosition(unit, button) - - if unit == const.UNIT.PLAYER then - CUF:Fire("UpdateLayout", nil, "position", const.UNIT.TARGET) + if CUF.DB.CurrentLayoutTable()[unit].anchorToParent ~= nil then + positioningPopup.parentAnchorFrame:Show() + positioningPopup:SetHeight(230) + else + positioningPopup.parentAnchorFrame:Hide() + if unit == const.UNIT.TARGET then + positioningPopup:SetHeight(120) + else + positioningPopup:SetHeight(85) end end @@ -216,7 +320,7 @@ local function CreateOverlayBox(button, unit) UpdatePositioningPopup() end) overlay:SetScript("OnClick", function() - ShowPositioningPopup(unit, button) + ShowPositioningPopup(unit) end) -- Hooks diff --git a/UnitFrames/UnitButton.lua b/UnitFrames/UnitButton.lua index 1028b17..14e4d13 100644 --- a/UnitFrames/UnitButton.lua +++ b/UnitFrames/UnitButton.lua @@ -20,16 +20,24 @@ local Util = CUF.Util ---@param button CUFUnitButton function U:UpdateUnitButtonPosition(unit, button) local layout = CUF.DB.CurrentLayoutTable() + local unitLayout = layout[unit] - local x, y - if unit == const.UNIT.TARGET and layout[unit].mirrorPlayer then - x, y = -layout[const.UNIT.PLAYER].position[1], layout[const.UNIT.PLAYER].position[2] + button:ClearAllPoints() + if unitLayout.anchorToParent then + local parent = CUF.unitButtons[unitLayout.parent] + local anchor = unitLayout.anchorPosition --[[@as ParentAnchor]] + + button:SetPoint(anchor.point, parent, anchor.relativePoint, anchor.offsetX, anchor.offsetY) else - x, y = unpack(layout[unit].position) - end + local x, y + if unit == const.UNIT.TARGET and unitLayout.mirrorPlayer then + x, y = -layout[const.UNIT.PLAYER].position[1], layout[const.UNIT.PLAYER].position[2] + else + x, y = unpack(unitLayout.position) + end - button:ClearAllPoints() - button:SetPoint("CENTER", UIParent, "CENTER", x, y) + button:SetPoint("CENTER", UIParent, "CENTER", x, y) + end end ------------------------------------------------- From f46f4e4d82a4d7a176846a1b6910bc10984b5c70 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 11:53:08 +0200 Subject: [PATCH 14/22] locale --- Locales/enUS.lua | 2 ++ UnitFrames/EditMode.lua | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Locales/enUS.lua b/Locales/enUS.lua index 01b2afe..0251747 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -152,6 +152,8 @@ L.texture = "Texture" L.VerticalFill = "Vertical Fill" L.SameSizeAsHealthBar = "Same Size As Health Bar" L.EditingLayout = "Editing Layout" +L.MirrorPlayer = "Mirror Player" +L.Positioning = "Positioning" -- Custom Formats L.ValidTags = "Valid Tags" diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua index ada6d5f..9232346 100644 --- a/UnitFrames/EditMode.lua +++ b/UnitFrames/EditMode.lua @@ -73,7 +73,7 @@ local function CreatePositioningPopup() -- Mirror ---@type CheckButton - local mirrorCB = Cell:CreateCheckButton(positioningPopup, L["MirrorPlayer"], function(checked) + local mirrorCB = Cell:CreateCheckButton(positioningPopup, L.MirrorPlayer, function(checked) CUF.DB.CurrentLayoutTable()[const.UNIT.TARGET].mirrorPlayer = checked U:UpdateUnitButtonPosition("target", CUF.unitButtons.target) positioningPopup.xPosSlider:SetEnabled(not checked) @@ -200,7 +200,7 @@ local function ShowPositioningPopup(unit) CreatePositioningPopup() end positioningPopup:Show() - positioningPopup.title:SetText(L["Positioning"] .. ": " .. CUF.constants.TITLE_CASED_UNITS[unit]) + positioningPopup.title:SetText(L.Positioning .. ": " .. L[unit]) positioningPopup.unit = unit From 7afe13ac72d987cc553a77d253a302ffd63854fc Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 12:16:42 +0200 Subject: [PATCH 15/22] move Edit Mode button to Unit Frames tab --- Core/SlashCommands.lua | 1 + Locales/enUS.lua | 3 +++ Menu/Menu.lua | 29 ++++++++++++++++++----------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Core/SlashCommands.lua b/Core/SlashCommands.lua index e69a55b..bb2956a 100644 --- a/Core/SlashCommands.lua +++ b/Core/SlashCommands.lua @@ -25,6 +25,7 @@ function SlashCmdList.CUF(msg, editbox) CUF:Print("Available commands:" .. "\n" .. "/cuf test - toggle test mode" .. "\n" .. "/cuf dev - toggle debug mode" .. "\n" .. + "/cuf edit - toggle edit mode" .. "\n" .. "/cuf restore - restore a backup" ) end diff --git a/Locales/enUS.lua b/Locales/enUS.lua index 0251747..062816c 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -154,6 +154,9 @@ L.SameSizeAsHealthBar = "Same Size As Health Bar" L.EditingLayout = "Editing Layout" L.MirrorPlayer = "Mirror Player" L.Positioning = "Positioning" +L.EditMode = "Edit Mode" +L.ToggleEditMode = "Toggle Edit Mode" +L.EditModeButtonTooltip = "Edit mode allows you to position the Unit Frames." -- Custom Formats L.ValidTags = "Valid Tags" diff --git a/Menu/Menu.lua b/Menu/Menu.lua index 9138d06..02a3e85 100644 --- a/Menu/Menu.lua +++ b/Menu/Menu.lua @@ -91,10 +91,12 @@ end function menu:ShowLayoutTitle() self.layoutTitleFrame:Show() self:SetLayoutTitle() + self.editModeButton:Show() end function menu:HideLayoutTitle() self.layoutTitleFrame:Hide() + self.editModeButton:Hide() end ------------------------------------------------- @@ -210,7 +212,7 @@ function menu:CreateMenu() ---@class CellCombatFrame self.window = CUF:CreateFrame("CUF_Menu", optionsFrame, self.baseWidth, 300) - self.window:SetPoint("TOPRIGHT", CellLayoutsPreviewButton, "BOTTOMRIGHT", 0, -self.inset - 20) + self.window:SetPoint("TOPRIGHT", CellLayoutsPreviewButton, "BOTTOMRIGHT", 0, -self.inset) -- mask F:ApplyCombatProtectionToFrame(self.window) @@ -230,16 +232,6 @@ function menu:CreateMenu() titleFrame:SetHeight(title:GetStringHeight() + pad * 2) titleFrame:SetWidth(title:GetStringWidth() + pad * 2) - local previewModeButton = Cell:CreateButton(titleFrame, L["Edit Mode"], "accent", - { 80, 20 }) - previewModeButton:SetPoint("BOTTOMLEFT", titleFrame, "BOTTOMRIGHT", -1, 0) - previewModeButton:SetScript("OnClick", function() - CUF.uFuncs:EditMode() - end) - previewModeButton:SetScript("OnHide", function() - CUF.uFuncs:EditMode(false) - end) - -- Title local layoutTitleFrame = CUF:CreateFrame(nil, titleFrame, 160, 10, false, true) layoutTitleFrame:SetPoint("BOTTOMLEFT", titleFrame, "TOPLEFT", 0, -1) @@ -267,6 +259,21 @@ function menu:CreateMenu() self:InitTabs() + local editModeButton = Cell:CreateButton(self.tabPane, L.EditMode, "accent", + { 100, 25 }) + editModeButton:SetPoint("TOPLEFT", self.tabPane, "BOTTOMLEFT", 0, 0) + CUF:SetTooltips(editModeButton, "ANCHOR_TOPLEFT", 0, 3, L.ToggleEditMode, + L.EditModeButtonTooltip) + + editModeButton:SetScript("OnClick", function() + CUF.uFuncs:EditMode() + end) + editModeButton:SetScript("OnHide", function() + CUF.uFuncs:EditMode(false) + end) + self.editModeButton = editModeButton + self.editModeButton:Hide() + hooksecurefunc(optionsFrame, "Hide", function() self:HideMenu() end) From 41a85c98c4098b477907d16685377b194f8b74c0 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 12:21:35 +0200 Subject: [PATCH 16/22] inform user of /cuf edit in tooltip --- Locales/enUS.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Locales/enUS.lua b/Locales/enUS.lua index 062816c..850d9f1 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -156,7 +156,9 @@ L.MirrorPlayer = "Mirror Player" L.Positioning = "Positioning" L.EditMode = "Edit Mode" L.ToggleEditMode = "Toggle Edit Mode" -L.EditModeButtonTooltip = "Edit mode allows you to position the Unit Frames." +L.EditModeButtonTooltip = [[Edit mode allows you to position the Unit Frames. + +"/cuf edit" will also toggle this mode.]] -- Custom Formats L.ValidTags = "Valid Tags" From 280b9b4bbe777820165188b58b4d85890c323344 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 12:25:04 +0200 Subject: [PATCH 17/22] inform user that unit frames are clickable --- Locales/enUS.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Locales/enUS.lua b/Locales/enUS.lua index 850d9f1..7958f91 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -158,6 +158,8 @@ L.EditMode = "Edit Mode" L.ToggleEditMode = "Toggle Edit Mode" L.EditModeButtonTooltip = [[Edit mode allows you to position the Unit Frames. +Clicking on a Unit Frame will bring up more options. + "/cuf edit" will also toggle this mode.]] -- Custom Formats From ae09b73b20e2f4fa73dc6e0253a9586984e05d6c Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 12:30:27 +0200 Subject: [PATCH 18/22] cancel animations if they overlap --- UnitFrames/EditMode.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua index 9232346..cfc26d1 100644 --- a/UnitFrames/EditMode.lua +++ b/UnitFrames/EditMode.lua @@ -331,6 +331,7 @@ local function CreateOverlayBox(button, unit) button:SetMovable(false) end) + overlays[unit] = overlay return overlay end @@ -344,6 +345,9 @@ local function HideOverlays(instant) overlay:Hide() else overlay.fadeOut:Play() + if overlay.fadeIn:IsPlaying() then + overlay.fadeIn:Stop() + end end end end @@ -351,11 +355,11 @@ end --- Play the fade in animation and show the overlays local function ShowOverlays() for _, unit in pairs(CUF.constants.UNIT) do - if overlays[unit] then - overlays[unit].fadeIn:Play() - else - overlays[unit] = CreateOverlayBox(CUF.unitButtons[unit], unit) - overlays[unit].fadeIn:Play() + local overlay = overlays[unit] or CreateOverlayBox(CUF.unitButtons[unit], unit) + + overlay.fadeIn:Play() + if overlay.fadeOut:IsPlaying() then + overlay.fadeOut:Stop() end end end From 1d0115fbefda3c1e2d31272cd011fcada3c0132a Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 12:54:33 +0200 Subject: [PATCH 19/22] update edit mode button styling --- UnitFrames/EditMode.lua | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/UnitFrames/EditMode.lua b/UnitFrames/EditMode.lua index cfc26d1..c388b63 100644 --- a/UnitFrames/EditMode.lua +++ b/UnitFrames/EditMode.lua @@ -249,35 +249,20 @@ local colors = { ---@param button CUFUnitButton ---@param unit Unit local function CreateOverlayBox(button, unit) - ---@class CUFOverlayBox: Button, BackdropTemplate - local overlay = CreateFrame("Button", nil, UIParent, "BackdropTemplate") + ---@class CUFOverlayBox: CellButton + local overlay = CUF:CreateButton(UIParent, "", { 1, 1 }, + function() ShowPositioningPopup(unit) end, "accent") overlay:SetAllPoints(button) overlay:SetFrameStrata("HIGH") overlay:SetFrameLevel(overlay:GetFrameLevel() + 100) overlay:Hide() - local border = CreateFrame("Frame", nil, overlay, "BackdropTemplate") - border:SetAllPoints() - border:SetBackdrop({ - bgFile = nil, - edgeFile = "Interface\\Buttons\\WHITE8X8", - edgeSize = 1, - }) - border:SetBackdropBorderColor(0, 0, 0, 1) - - local tex = overlay:CreateTexture(nil, "ARTWORK") - tex:SetTexture(Cell.vars.whiteTexture) - tex:SetAllPoints() - local r, g, b = unpack(colors[unit]) - tex:SetVertexColor(r, g, b, 0.5) - local label = overlay:CreateFontString(nil, "OVERLAY", const.FONTS.CELL_WIGET) label:SetPoint("CENTER") label:SetText(L[unit]) -- Register mouse and movable overlay:RegisterForDrag("LeftButton") - overlay:RegisterForClicks("LeftButtonUp") overlay:SetMovable(true) button:SetMovable(true) @@ -319,9 +304,6 @@ local function CreateOverlayBox(button, unit) UpdatePositioningPopup() end) - overlay:SetScript("OnClick", function() - ShowPositioningPopup(unit) - end) -- Hooks overlay:HookScript("OnShow", function() From 96638f3f485da3ba9d172ff42f01be9e2e7f2ea2 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 13:08:58 +0200 Subject: [PATCH 20/22] use PixelUtil to set point --- UnitFrames/UnitButton.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UnitFrames/UnitButton.lua b/UnitFrames/UnitButton.lua index 14e4d13..0fa624f 100644 --- a/UnitFrames/UnitButton.lua +++ b/UnitFrames/UnitButton.lua @@ -27,7 +27,7 @@ function U:UpdateUnitButtonPosition(unit, button) local parent = CUF.unitButtons[unitLayout.parent] local anchor = unitLayout.anchorPosition --[[@as ParentAnchor]] - button:SetPoint(anchor.point, parent, anchor.relativePoint, anchor.offsetX, anchor.offsetY) + PixelUtil.SetPoint(button, anchor.point, parent, anchor.relativePoint, anchor.offsetX, anchor.offsetY) else local x, y if unit == const.UNIT.TARGET and unitLayout.mirrorPlayer then @@ -36,7 +36,7 @@ function U:UpdateUnitButtonPosition(unit, button) x, y = unpack(unitLayout.position) end - button:SetPoint("CENTER", UIParent, "CENTER", x, y) + PixelUtil.SetPoint(button, "CENTER", UIParent, "CENTER", x, y) end end From 0c1914c9a8d4a4353d6287569ff182100cd159af Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 14:56:50 +0200 Subject: [PATCH 21/22] Bump DB version to 5 --- Core/Init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/Init.lua b/Core/Init.lua index 7e013c3..4f88936 100644 --- a/Core/Init.lua +++ b/Core/Init.lua @@ -2,7 +2,7 @@ local CUF = select(2, ...) _G.CUF = CUF -CUF.version = 4 +CUF.version = 5 CUF.Cell = Cell From c5df6c62751a0950729c093f17ec46cd48f90503 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 9 Sep 2024 14:59:11 +0200 Subject: [PATCH 22/22] Revise unit frame positioning to (hopefully) keep them in place with new anchoring --- Data/Revise.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/Data/Revise.lua b/Data/Revise.lua index 6177ff6..e69a0e3 100644 --- a/Data/Revise.lua +++ b/Data/Revise.lua @@ -1,4 +1,4 @@ ----@diagnostic disable: inject-field +---@diagnostic disable: inject-field, undefined-field ---@class CUF local CUF = select(2, ...) @@ -34,4 +34,52 @@ function DB:Revise() end end) end + if CUF_DB.version < 5 then + -- Load late since we need proper screen size + CUF:AddEventListener("LOADING_SCREEN_DISABLED", function() + local sWidth = GetScreenWidth() / 2 + local sHeight = GetScreenHeight() / 2 + local buffer = 14 + + IterateUnitLayouts(function(layout) + if not layout.point then return end + local anchorPoint = layout.point + + local xPos, yPos = unpack(layout.position) + local bWidth, bHeight = unpack(layout.size) + local bOffsetX = bWidth / 2 + local bOffsetY = bHeight / 2 + + local newX = xPos - sWidth + local newY = yPos - sHeight + + if CellDB.general.menuPosition == "top_bottom" then + if anchorPoint == "BOTTOMLEFT" then + newY = newY + buffer + bOffsetY + elseif anchorPoint == "BOTTOMRIGHT" then + newY = newY + buffer + bOffsetY + elseif anchorPoint == "TOPLEFT" then + newY = newY - 4 - bOffsetY + elseif anchorPoint == "TOPRIGHT" then + newY = newY - 4 - bOffsetY + end + else + if anchorPoint == "BOTTOMLEFT" then + newX = newX + buffer + bOffsetX + elseif anchorPoint == "BOTTOMRIGHT" then + newX = newX - 4 - bOffsetX + elseif anchorPoint == "TOPLEFT" then + newX = newX + buffer + bOffsetX + elseif anchorPoint == "TOPRIGHT" then + newX = newX - 4 - bOffsetX + end + end + + layout.position = { newX, newY } + end) + + CUF:Fire("UpdateUnitButtons") + return true + end) + end end