Skip to content

Commit

Permalink
impl option to copy widget settings from one unit to another
Browse files Browse the repository at this point in the history
  • Loading branch information
Krealle committed Aug 31, 2024
1 parent 6c64442 commit 1f65614
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Annotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
---@field button button
---@field ClearSelected function
---@field GetSelected function
---@field AddItem function
---@field ClearItems function

---@class CellColorPicker: Frame, BackdropTemplate
---@field SetColor function
Expand Down
2 changes: 2 additions & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ L.CopyFromTooltip = [[|cFFFF0000This will overwrite all settings in the current
Copy settings from another layout]]
L.CopyFromPopUp = "Copy settings from |cFFFFD700%s|r to |cFFFFD700%s|r?"

L.CopyWidgetsFrom = "Copy Widgets From"
L.CopyWidgetsFromTooltip = "Copy widget settings from another unit"
-- Units
L.targettarget = "TargetTarget"
L.player = "Player"
Expand Down
29 changes: 29 additions & 0 deletions UnitFrames/MenuOptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ local CUF = select(2, ...)
local Cell = CUF.Cell
local L = CUF.L

local Menu = CUF.Menu

local function UpdateSize()
if CUF.vars.selectedLayout == CUF.DB.GetMasterLayout() then
CUF:Fire("UpdateLayout", CUF.vars.selectedLayout, CUF.vars.selectedUnit .. "-size")
Expand Down Expand Up @@ -51,6 +53,26 @@ local function AddLoadPageDB(unitPage)
unitPage.anchorDropdown:SetEnabled(not isSameSizeAsPlayer)
end

-- copy from
unitPage.copyFromDropdown:ClearItems()
for _, unit in pairs(CUF.constants.UNIT) do
if unitPage.id ~= unit then
unitPage.copyFromDropdown:AddItem({
["text"] = L[unit],
["value"] = unit,
["onClick"] = function()
Menu:ShowPopup(string.format(L.CopyFromPopUp, unit, unitPage.id),
function()
CUF.DB.CopyWidgetSettings(unit, unitPage.id)
CUF:Fire("LoadPageDB", unitPage.id, CUF.vars.selectedWidget)
CUF:Fire("UpdateWidget", CUF.vars.selectedLayout)
end)
unitPage.copyFromDropdown:ClearSelected()
end,
})
end
end

unitPage.enabledCB:SetChecked(pageDB.enabled)
end
CUF:RegisterCallback("LoadPageDB", "Units_" .. unitPage.id .. "_LoadPageDB", LoadPageDB)
Expand Down Expand Up @@ -135,6 +157,13 @@ local function AddUnitsToMenu()
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:SetLabel(L.CopyWidgetsFrom)
CUF:SetTooltips(unitPage.copyFromDropdown, "ANCHOR_TOPLEFT", 0, 3, L.CopyWidgetsFrom,
L.CopyWidgetsFromTooltip)

---@type CellSlider
unitPage.heightSlider = Cell:CreateSlider(L["Height"], unitPage.frame, 20, 500, 117, 1, function(value)
CUF.DB.SelectedLayoutTable()[unit].size[2] = value
Expand Down

0 comments on commit 1f65614

Please sign in to comment.