Skip to content

Commit

Permalink
implement option to set abs positioning for Cell frames in Edit Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Krealle committed Sep 30, 2024
1 parent b9eca1f commit 66c5428
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ L.HideIfFull = "Hide if Full"
L.ShowDeadStatus = "Show Dead Status"
L.ShowDeadStatusTooltip = [[Show "Dead" instead of 0.]]

L.CellEditMode = "Cell Frames"
L.CellEditModeTip = "(Previews won't dynamically update)"

-- Custom Formats
L.ValidTags = "Valid Tags"

Expand Down
143 changes: 143 additions & 0 deletions UnitFrames/EditMode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,146 @@ local function ShowOverlays()
end
end

-------------------------------------------------
-- MARK: Cell Edit Mode
-------------------------------------------------

local CellAnchorFrameNames = {
CellAnchorFrame = { name = "Main Frame", key = "main" },
CellSeparateNPCFrameAnchor = { name = "Seperate NPC Frame", key = "npc" },
CellRaidPetAnchorFrame = { name = "Raid Pet Frame", key = "pet" },
CellSpotlightAnchorFrame = { name = "Spotlight Frame", key = "spotlight" },
CellQuickAssistAnchorFrame = { name = "Quick Assist Frame" }, --CellDB["quickAssist"][Cell.vars.playerSpecID] => layoutTable["position"]
}

local cellPopup

local function GetAnchorFrame()
if not cellPopup then return end

local anchor = cellPopup.frameDropdown:GetSelected()
if not anchor then return end

local anchorFrame = _G[anchor]
if not anchorFrame then return end

local key = CellAnchorFrameNames[cellPopup.frameDropdown:GetSelected()].key
return anchorFrame, key
end

local function UpdateCellEditModePopup()
if not cellPopup then return end

local anchorFrame, key = GetAnchorFrame()
if not anchorFrame then return end

local x, y
if key then
x, y = unpack(Cell.vars.currentLayoutTable[key].position)
else
x, y = unpack(CellDB["quickAssist"][Cell.vars.playerSpecID].layout.position)
end

cellPopup.xPosSlider:SetValue(x)
cellPopup.yPosSlider:SetValue(y)
end

local function UpdateCellFramePosition()
if not cellPopup then return end
local x, y = cellPopup.xPosSlider:GetValue(), cellPopup.yPosSlider:GetValue()
local anchorFrame, key = GetAnchorFrame()

-- Use Cell functions directly to reduce chance of error
P:LoadPosition(anchorFrame, { x, y })
if key then
P:SavePosition(anchorFrame, Cell.vars.currentLayoutTable[key].position)
else
P:SavePosition(anchorFrame, CellDB["quickAssist"][Cell.vars.playerSpecID].layout.position)
end
end

local function CreateCellEditModePopup()
---@class CUF_CellEditModePopup: Frame
cellPopup = CUF:CreateFrame("CUF_CellEditModePopup", UIParent, 340, 150)
cellPopup:SetPoint("CENTER", 0, 200)

cellPopup:SetMovable(true)
cellPopup:EnableMouse(true)
cellPopup:RegisterForDrag("LeftButton")
cellPopup:SetScript("OnDragStart", function(self)
self:StartMoving()
end)
cellPopup:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
end)

local closeBtn = Cell:CreateButton(cellPopup, "×", "red", { 18, 18 }, false, false, "CELL_FONT_SPECIAL",
"CELL_FONT_SPECIAL")
closeBtn:SetPoint("TOPRIGHT", P:Scale(-5), P:Scale(-1))
closeBtn:SetScript("OnClick", function() cellPopup:Hide() end)

local title = cellPopup:CreateFontString(nil, "OVERLAY", "CELL_FONT_CLASS")
title:SetPoint("TOPLEFT", 5, -5)
title:SetText(L.CellEditMode)

local subTitle = cellPopup:CreateFontString(nil, "OVERLAY", const.FONTS.CELL_WIGET)
subTitle:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -5)
subTitle:SetText(L.CellEditModeTip)
subTitle:SetScale(0.9)

---@type CellDropdown
local frameDropdown = Cell:CreateDropdown(cellPopup, 200)
frameDropdown:SetPoint("TOPLEFT", 10, -60)
frameDropdown:SetLabel(L["Frame"])

-- Offsets
local maxX, maxY = GetPhysicalScreenSize()
local xVal = maxX
local yVal = maxY

local xPosSlider = Cell:CreateSlider(L["X Offset"], cellPopup, 0, xVal, 150, 1)
xPosSlider:SetPoint("TOPLEFT", frameDropdown, "BOTTOMLEFT", 0, -30)
local yPosSlider = Cell:CreateSlider(L["Y Offset"], cellPopup, 0, yVal, 150, 1)
yPosSlider:SetPoint("TOPLEFT", xPosSlider, "TOPRIGHT", 20, 0)

yPosSlider.onValueChangedFn = UpdateCellFramePosition
xPosSlider.onValueChangedFn = UpdateCellFramePosition

for anchorName, info in pairs(CellAnchorFrameNames) do
frameDropdown:AddItem({
text = L[info.name],
value = anchorName,
onClick = function()
UpdateCellEditModePopup()
end,
})
end

frameDropdown:SetSelected(CellAnchorFrameNames.CellAnchorFrame.name)

cellPopup.xPosSlider = xPosSlider
cellPopup.yPosSlider = yPosSlider
cellPopup.frameDropdown = frameDropdown
end

local function ShowCellEditModePopup()
if not cellPopup then
CreateCellEditModePopup()
end
cellPopup:Show()

UpdateCellEditModePopup()

CUF:RegisterCallback("UpdateLayout", "UpdateCellEditModePopup", UpdateCellEditModePopup)
end

local function HideCellEditModePopup()
if cellPopup then
cellPopup:Hide()
CUF:UnregisterCallback("UpdateLayout", "UpdateCellEditModePopup")
end
end

-------------------------------------------------
-- MARK: Edit Mode
-------------------------------------------------
Expand All @@ -376,6 +516,7 @@ eventFrame:SetScript("OnEvent", function()
CUF.vars.inEditMode = false
HideOverlays(true)
HidePositioningPopup()
HideCellEditModePopup()
end)

--- Enable or disable edit mode
Expand All @@ -393,10 +534,12 @@ function U:EditMode(show)

if CUF.vars.inEditMode then
ShowOverlays()
ShowCellEditModePopup()
eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
else
HideOverlays()
HidePositioningPopup()
HideCellEditModePopup()
eventFrame:UnregisterEvent("PLAYER_REGEN_DISABLED")
end
end

0 comments on commit 66c5428

Please sign in to comment.