Skip to content

Commit

Permalink
[Feature] Preview & Absolute Positioning (#60)
Browse files Browse the repository at this point in the history
* Remove Menu Button

* first pass at an editmode

* add a button to toggle edit mode

* move menu frame down to compensate

* hide overlays when in combat

* increase overlayText scale and use cell widget font

* update overlay styling

* update overlay label

* add animation

* update position Popup when dragging

* update popup on UpdateLayout & UpdateUnitButton callbacks

* remove anchor dropdown from units

* add parent anchor options

* locale

* move Edit Mode button to Unit Frames tab

* inform user of /cuf edit in tooltip

* inform user that unit frames are clickable

* cancel animations if they overlap

* update edit mode button styling

* use PixelUtil to set point

* Bump DB version to 5

* Revise unit frame positioning to (hopefully) keep them in place with new anchoring
  • Loading branch information
Krealle authored Sep 9, 2024
1 parent f3a4ffa commit 49c08f3
Show file tree
Hide file tree
Showing 13 changed files with 603 additions and 339 deletions.
2 changes: 1 addition & 1 deletion Cell_UnitFrames.toc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Widgets/Auras/Handler.lua
UnitFrames/UnitButton.xml
UnitFrames/UnitButton.lua
UnitFrames/OnLoad.lua
UnitFrames/Units.lua
UnitFrames/MenuOptions.lua
UnitFrames/EditMode.lua

Core/OnLoad.lua
6 changes: 5 additions & 1 deletion Core/Init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
local CUF = select(2, ...)
_G.CUF = CUF

CUF.version = 4
CUF.version = 5

CUF.Cell = Cell

Expand Down Expand Up @@ -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 = {}
1 change: 1 addition & 0 deletions Core/OnLoad.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Core/SlashCommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ 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" ..
"/cuf dev - toggle debug mode" .. "\n" ..
"/cuf edit - toggle edit mode" .. "\n" ..
"/cuf restore <automatic|manual> - restore a backup"
)
end
Expand Down
43 changes: 26 additions & 17 deletions Data/Defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -582,23 +582,25 @@ 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
---@field powerSize number
---@field size Size
---@field point FramePoint
---@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<Unit, UnitLayout>
---@type UnitLayoutTable
Expand All @@ -607,18 +609,15 @@ Defaults.Layouts = {
enabled = false,
powerSize = 2,
size = { 200, 40 },
point = "BOTTOMLEFT",
position = { 800, 500 },
widgets = Defaults.Widgets,
tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, },
hideBlizzardCastBar = false,
clickCast = false,
},
target = {
enabled = false,
powerSize = 2,
size = { 200, 40 },
point = "BOTTOMLEFT",
position = { 1400, 500 },
widgets = {
nameText = Defaults.Widgets.nameText,
Expand All @@ -635,15 +634,14 @@ Defaults.Layouts = {
shieldBar = Defaults.Widgets.shieldBar,
castBar = Defaults.Widgets.castBar,
},
tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, },
sameSizeAsPlayer = false,
clickCast = false,
mirrorPlayer = false,
},
focus = {
enabled = false,
powerSize = 2,
size = { 100, 30 },
point = "BOTTOMLEFT",
position = { 800, 700 },
widgets = {
nameText = Defaults.Widgets.nameText,
Expand All @@ -660,15 +658,13 @@ Defaults.Layouts = {
shieldBar = Defaults.Widgets.shieldBar,
castBar = Defaults.Widgets.castBar,
},
tooltipPosition = { "BOTTOMLEFT", "BOTTOMLEFT", -3, 0, },
sameSizeAsPlayer = false,
clickCast = false,
},
targettarget = {
enabled = false,
powerSize = 2,
size = { 200, 40 },
point = "BOTTOMLEFT",
position = { 1620, 500 },
widgets = {
nameText = Defaults.Widgets.nameText,
Expand All @@ -677,15 +673,21 @@ 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,
powerSize = 2,
size = { 200, 30 },
point = "BOTTOMLEFT",
position = { 800, 460 },
widgets = {
nameText = Defaults.Widgets.nameText,
Expand All @@ -698,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
},
},
}
50 changes: 49 additions & 1 deletion Data/Revise.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---@diagnostic disable: inject-field
---@diagnostic disable: inject-field, undefined-field
---@class CUF
local CUF = select(2, ...)

Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ 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"
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
L.ValidTags = "Valid Tags"
Expand Down
17 changes: 17 additions & 0 deletions Menu/Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

-------------------------------------------------
Expand Down Expand Up @@ -257,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)
Expand Down
Loading

0 comments on commit 49c08f3

Please sign in to comment.