Skip to content

Commit

Permalink
[Feature] Implement proper Scaling support (#171)
Browse files Browse the repository at this point in the history
* Abstract PixelPerfect funcs

* add useScaling var

* set useScaling to true for testing purposes

* scale unit button border size

* scale unit button size

* use PixelPerfect funcs for pointing power/health loss bars

* use PixelPerfect funcs for pointing auras

* use PixelPerfect funcs for pointing health bar

* use PixelPerfect funcs for pointing power bar

* scale Auras size

* update on scale changes

* update PixelPerfect.GetPositionRelativeToScreenCenter to return proper values when scaled

* use P.Point to set Unit Button positioning

* add "/cuf pixel" slash command for some debugging prints

* use screen size for relativity

* add some more debug info

* renaming for clarity

* update Shield Bar to properly handle borders

* add .Width and .Height scale funcs

* update PixelPerfect annotations

* scale Heal Absorb

* scale Class Bar border

* use PixelPerfect for common widget positioning

* use PixelPerfect for common widget sizing

* use PixelPerfect for Text widget positioning

* use PixelPerfect to scale totems

* annotation

* Use PixelPerfect for CastBar

* use PixelPerfect for ClassBar

* move useScaling to DB

* update SetPixelScale to scale the parsed frame

* add DB.SetUseScaling

* remove useScaling check for "scale" callback

* create Misc section in General Tab

* add locale

* update slash command
  • Loading branch information
Krealle authored Nov 8, 2024
1 parent 0c680c8 commit 87bb785
Show file tree
Hide file tree
Showing 25 changed files with 547 additions and 276 deletions.
1 change: 1 addition & 0 deletions Cell_UnitFrames.toc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Core/Events.lua

Data/Constants.lua
Util/Utils.lua
Util/PixelPerfect.lua
Data/Defaults.lua
Data/Database.lua
Data/DBUtil.lua
Expand Down
3 changes: 3 additions & 0 deletions Core/Init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ CUF.Debug = {}
CUF.Builder = {}
---@class CUF.API
CUF.API = {}
---@class CUF.PixelPerfect
CUF.PixelPerfect = {}

---@class CUF.vars
---@field selectedLayout string
Expand All @@ -36,6 +38,7 @@ CUF.API = {}
---@field selectedSubTab string
---@field inEditMode boolean
---@field customPositioning boolean
---@field useScaling boolean
CUF.vars = {}

---@class CUF.unitButtons
Expand Down
2 changes: 1 addition & 1 deletion Core/OnLoad.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ local function OnCellInitialUpdateLayout(_layout)
local CUFMainFrame = CreateFrame("Frame", "CUFMainFrame", UIParent, "SecureFrameTemplate")
CUF.mainFrame = CUFMainFrame
CUFMainFrame:SetIgnoreParentScale(true)
CUF.Util.SetPixelScale(CUFMainFrame)
CUF.PixelPerfect.SetPixelScale(CUFMainFrame)

-- Init Unit Buttons
CUF.uFuncs:InitUnitButtons()
Expand Down
5 changes: 4 additions & 1 deletion Core/SlashCommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ function SlashCmdList.CUF(msg, editbox)
CUF:Print("All Help Tips have been reset, reload to see them again")
elseif command == "tags" then
CUF.widgets:ShowTooltipFrame()
elseif command == "pixel" then
CUF:Print(CUF.PixelPerfect.DebugInfo())
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" .. "\n" ..
"/cuf resettips - reset all help tips" .. "\n" ..
"/cuf tags - show available tags"
"/cuf tags - show available tags" .. "\n" ..
"/cuf pixel - show pixel debug info"
)
end
end
2 changes: 2 additions & 0 deletions Data/DBUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ function DB.InitDB()
CUF_DB.masterLayout = "default"
end

CUF_DB.useScaling = CUF_DB.useScaling or false

DB.CreateAutomaticBackup()
DB:Revise()

Expand Down
6 changes: 6 additions & 0 deletions Data/Database.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,9 @@ end
function DB.SetHelpTip(helpTip, acknowledged)
CUF_DB.helpTips[helpTip] = acknowledged
end

---@param useScaling boolean
function DB.SetUseScaling(useScaling)
CUF_DB.useScaling = useScaling
CUF:Fire("UpdateAppearance", "scale")
end
3 changes: 3 additions & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ L.PlayerTarget = "Player Target"
L.AlwaysUpdate = "Always Update"
L.AlwaysUpdateUnitFrameTooltip = [[Forces an update every %ss
Can help with issues where the Unit Frame is not updating correctly]]
L.UseScaling = "Use Scaling"
L.UseScalingTooltip = [[Enable to apply the Scale set in |cFFFFD700Cell|r
Reload after toggling to fully update all frames]]

-- Custom Formats
L.ValidTags = "Valid Tags"
Expand Down
32 changes: 32 additions & 0 deletions Menu/GeneralTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,36 @@ function layoutBackup:Create()
self.createManulBackup:SetPoint("TOPLEFT", self.restoreDropdown, "BOTTOMLEFT", 0, -10)
end

-------------------------------------------------
-- MARK: Misc
-------------------------------------------------

---@class Misc: Frame
local Misc = {}

function Misc.Update()
if not generalTab:IsShown() then return end

Misc.useScalingCB:SetChecked(CUF_DB.useScaling)
end

function Misc:Create()
local sectionWidth = (generalTab.window:GetWidth() / 2) - 5

self.frame = CUF:CreateFrame(nil, generalTab.window, sectionWidth, 50, true, true)
self.frame:SetPoint("TOPLEFT", copyLayoutFrom.frame, "BOTTOMLEFT", 0, -20)

local pane = Cell:CreateTitledPane(self.frame, L["Misc"], sectionWidth, generalTab.paneHeight)
pane:SetPoint("TOPLEFT")

self.useScalingCB = Cell:CreateCheckButton(self.frame,
L.UseScaling,
function(checked)
DB.SetUseScaling(checked)
end, L.UseScaling, L.UseScalingTooltip)
self.useScalingCB:SetPoint("TOPLEFT", pane, "BOTTOMLEFT", 5, -10)
end

-------------------------------------------------
-- MARK: Show/Hide
-------------------------------------------------
Expand All @@ -234,6 +264,7 @@ function generalTab:ShowTab()
layoutProfile:SetLayoutItems()
copyLayoutFrom:SetLayoutItems()
layoutBackup:Update()
Misc:Update()
end

function generalTab:HideTab()
Expand All @@ -259,4 +290,5 @@ function generalTab:Create()
layoutProfile:Create()
copyLayoutFrom:Create()
layoutBackup:Create()
Misc:Create()
end
3 changes: 2 additions & 1 deletion Menu/Menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local F = Cell.funcs
local L = CUF.L
local Util = CUF.Util
local DB = CUF.DB
local P = CUF.PixelPerfect

---@class CUF.Menu
---@field window CellCombatFrame
Expand Down Expand Up @@ -227,7 +228,7 @@ function menu:CreateMenu()
end)
self.window:SetScript("OnDragStop", function()
self.window:StopMovingOrSizing()
local x, y = Util.GetPositionRelativeToScreenCenter(self.window)
local x, y = P.GetPositionRelativeToScreenCenter(self.window)

-- coords are relative to the screen center so we need to offset them
local centerOffset = self.window:GetHeight() / 2
Expand Down
2 changes: 1 addition & 1 deletion UnitFrames/EditMode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ local function CreateOverlayBox(button, unit, unitN, parentButton)
overlay:SetScript("OnDragStop", function()
button:StopMovingOrSizing()

local x, y = Util.GetPositionRelativeToScreenCenter(button)
local x, y = CUF.PixelPerfect.GetPositionRelativeToScreenCenter(button)
U:SavePosition(unit, x, y)

if unit == const.UNIT.PLAYER then
Expand Down
5 changes: 2 additions & 3 deletions UnitFrames/OnLoad.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ local CUF = select(2, ...)

local Cell = CUF.Cell
local F = Cell.funcs
local P = Cell.pixelPerfectFuncs
local A = Cell.animations
local P = CUF.PixelPerfect

---@class CUF.uFuncs
local U = CUF.uFuncs
Expand Down Expand Up @@ -621,7 +620,7 @@ function CUFUnitButton_OnLoad(button)
button:SetBackdrop({
bgFile = Cell.vars.whiteTexture,
edgeFile = Cell.vars.whiteTexture,
edgeSize = CELL_BORDER_SIZE
edgeSize = P.Scale(CELL_BORDER_SIZE)
})
button:SetBackdropColor(0, 0, 0, 1)
button:SetBackdropBorderColor(unpack(CELL_BORDER_COLOR))
Expand Down
56 changes: 32 additions & 24 deletions UnitFrames/UnitButton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ local CUF = select(2, ...)

local Cell = CUF.Cell
local F = Cell.funcs
local P = Cell.pixelPerfectFuncs

---@class CUF.uFuncs
local U = CUF.uFuncs
Expand All @@ -12,6 +11,7 @@ local W = CUF.widgets
local const = CUF.constants
local Util = CUF.Util
local DB = CUF.DB
local P = CUF.PixelPerfect

local MAX_BOSS_FRAMES = MAX_BOSS_FRAMES or 5

Expand Down Expand Up @@ -50,12 +50,12 @@ function U:UpdateUnitButtonPosition(unit, button)
local layout = CUF.DB.CurrentLayoutTable()
local unitLayout = layout[unit]

button:ClearAllPoints()
P.ClearPoints(button)
if unitLayout.anchorToParent then
local parent = CUF.unitButtons[unitLayout.parent]
local anchor = unitLayout.anchorPosition --[[@as ParentAnchor]]

PixelUtil.SetPoint(button, anchor.point, parent, anchor.relativePoint, anchor.offsetX, anchor.offsetY)
P.Point(button, anchor.point, parent, anchor.relativePoint, anchor.offsetX, anchor.offsetY)
else
-- Anchor 'child' buttons to 'parent' button
local unitN = tonumber(string.match(button._unit, "%d+"))
Expand All @@ -70,13 +70,13 @@ function U:UpdateUnitButtonPosition(unit, button)
local spacing = unitLayout.spacing or 0

if unitLayout.growthDirection == const.GROWTH_ORIENTATION.TOP_TO_BOTTOM then
PixelUtil.SetPoint(button, "TOPLEFT", parent, "BOTTOMLEFT", 0, -spacing)
P.Point(button, "TOPLEFT", parent, "BOTTOMLEFT", 0, -spacing)
elseif unitLayout.growthDirection == const.GROWTH_ORIENTATION.BOTTOM_TO_TOP then
PixelUtil.SetPoint(button, "BOTTOMLEFT", parent, "TOPLEFT", 0, spacing)
P.Point(button, "BOTTOMLEFT", parent, "TOPLEFT", 0, spacing)
elseif unitLayout.growthDirection == const.GROWTH_ORIENTATION.LEFT_TO_RIGHT then
PixelUtil.SetPoint(button, "LEFT", parent, "RIGHT", spacing, 0)
P.Point(button, "LEFT", parent, "RIGHT", spacing, 0)
else
PixelUtil.SetPoint(button, "RIGHT", parent, "LEFT", -spacing, 0)
P.Point(button, "RIGHT", parent, "LEFT", -spacing, 0)
end

return
Expand All @@ -90,7 +90,7 @@ function U:UpdateUnitButtonPosition(unit, button)
x, y = unpack(unitLayout.position)
end

PixelUtil.SetPoint(button, "CENTER", UIParent, "CENTER", x, y)
P.Point(button, "CENTER", UIParent, "CENTER", x, y)
end
end

Expand All @@ -113,7 +113,7 @@ function U:UpdateUnitButtonLayout(unit, kind, button)
width, height = unpack(layout[unit].size)
end

button:SetSize(width, height)
P.Size(button, width, height)
end

-- NOTE: SetOrientation BEFORE SetPowerSize
Expand Down Expand Up @@ -215,29 +215,29 @@ function U:SetOrientation(button, orientation, rotateTexture)

if orientation == "horizontal" then
-- update healthBarLoss
healthBarLoss:ClearAllPoints()
healthBarLoss:SetPoint("TOPRIGHT", healthBar)
healthBarLoss:SetPoint("BOTTOMLEFT", healthBar:GetStatusBarTexture(), "BOTTOMRIGHT")
P.ClearPoints(healthBarLoss)
P.Point(healthBarLoss, "TOPRIGHT", healthBar)
P.Point(healthBarLoss, "BOTTOMLEFT", healthBar:GetStatusBarTexture(), "BOTTOMRIGHT")

-- update powerBarLoss
powerBarLoss:ClearAllPoints()
powerBarLoss:SetPoint("TOPRIGHT", powerBar)
powerBarLoss:SetPoint("BOTTOMLEFT", powerBar:GetStatusBarTexture(), "BOTTOMRIGHT")
P.ClearPoints(powerBarLoss)
P.Point(powerBarLoss, "TOPRIGHT", powerBar)
P.Point(powerBarLoss, "BOTTOMLEFT", powerBar:GetStatusBarTexture(), "BOTTOMRIGHT")
else -- vertical / vertical_health
healthBarLoss:ClearAllPoints()
healthBarLoss:SetPoint("TOPRIGHT", healthBar)
healthBarLoss:SetPoint("BOTTOMLEFT", healthBar:GetStatusBarTexture(), "TOPLEFT")
P.ClearPoints(healthBarLoss)
P.Point(healthBarLoss, "TOPRIGHT", healthBar)
P.Point(healthBarLoss, "BOTTOMLEFT", healthBar:GetStatusBarTexture(), "TOPLEFT")

if orientation == "vertical" then
-- update powerBarLoss
powerBarLoss:ClearAllPoints()
powerBarLoss:SetPoint("TOPRIGHT", powerBar)
powerBarLoss:SetPoint("BOTTOMLEFT", powerBar:GetStatusBarTexture(), "TOPLEFT")
P.ClearPoints(powerBarLoss)
P.Point(powerBarLoss, "TOPRIGHT", powerBar)
P.Point(powerBarLoss, "BOTTOMLEFT", powerBar:GetStatusBarTexture(), "TOPLEFT")
else -- vertical_health
-- update powerBarLoss
powerBarLoss:ClearAllPoints()
powerBarLoss:SetPoint("TOPRIGHT", powerBar)
powerBarLoss:SetPoint("BOTTOMLEFT", powerBar:GetStatusBarTexture(), "BOTTOMRIGHT")
P.ClearPoints(powerBarLoss)
P.Point(powerBarLoss, "TOPRIGHT", powerBar)
P.Point(powerBarLoss, "BOTTOMLEFT", powerBar:GetStatusBarTexture(), "BOTTOMRIGHT")
end
end

Expand Down Expand Up @@ -288,6 +288,14 @@ local function UpdateAppearance(kind)
end)
end)
end
if kind == "scale" then
-- Full update for everything
-- Needs to be delayed
C_Timer.After(0.1, function()
CUF.PixelPerfect.SetPixelScale(CUF.mainFrame)
CUF:Fire("UpdateUnitButtons")
end)
end
end
CUF:RegisterCallback("UpdateAppearance", "UpdateAppearance", UpdateAppearance)

Expand Down
Loading

0 comments on commit 87bb785

Please sign in to comment.