Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Core/Defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ local Defaults = {
IconHeight = 42,
KeepAspectRatio = true,
CenterHorizontally = false,
IconsPerRow = 40,
Layout = {"CENTER", "CENTER", 0, -275.1},
Text = {
FontSize = 15,
Expand All @@ -139,6 +140,7 @@ local Defaults = {
IconHeight = 36,
KeepAspectRatio = true,
CenterHorizontally = false,
IconsPerRow = 40,
Layout = {"TOP", "EssentialCooldownViewer", "BOTTOM", 0, -1.1},
Text = {
FontSize = 15,
Expand All @@ -152,6 +154,7 @@ local Defaults = {
IconHeight = 32,
KeepAspectRatio = true,
CenterBuffs = false,
IconsPerRow = 40,
Layout = {"BOTTOM", "BCDM_SecondaryPowerBar", "TOP", 0, 1.1},
Text = {
FontSize = 15,
Expand Down Expand Up @@ -197,6 +200,7 @@ local Defaults = {
Layout = {"CENTER", "NONE", "CENTER", 0, 0},
Spacing = 1,
GrowthDirection = "RIGHT",
IconsPerRow = 40,
Text = {
FontSize = 12,
Colour = {1, 1, 1},
Expand Down Expand Up @@ -293,6 +297,7 @@ local Defaults = {
Layout = {"CENTER", "NONE", "CENTER", 0, 0},
Spacing = 1,
GrowthDirection = "RIGHT",
IconsPerRow = 40,
Text = {
FontSize = 12,
Colour = {1, 1, 1},
Expand Down Expand Up @@ -389,6 +394,7 @@ local Defaults = {
Layout = {"CENTER", "NONE", "CENTER", 0, 0},
Spacing = 1,
GrowthDirection = "LEFT",
IconsPerRow = 40,
OffsetByParentHeight = true,
HideZeroCharges = false,
Text = {
Expand All @@ -408,6 +414,7 @@ local Defaults = {
Layout = {"CENTER", "NONE", "CENTER", 0, 0},
Spacing = 1,
GrowthDirection = "LEFT",
IconsPerRow = 40,
OffsetByParentHeight = true,
},
ItemSpell = {
Expand All @@ -419,6 +426,7 @@ local Defaults = {
Layout = {"CENTER", "NONE", "CENTER", 0, 0},
Spacing = 1,
GrowthDirection = "LEFT",
IconsPerRow = 40,
OffsetByParentHeight = true,
HideZeroCharges = false,
Text = {
Expand Down
11 changes: 11 additions & 0 deletions Core/GUI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,17 @@ local function CreateCooldownViewerSettings(parentContainer, viewerType)
layoutContainer:AddChild(spacingSlider)
end

local iconsPerRowSlider = AG:Create("Slider")
iconsPerRowSlider:SetLabel(LL("Icons Per Row"))
iconsPerRowSlider:SetValue(BCDM.db.profile.CooldownManager[viewerType].IconsPerRow or 40)
iconsPerRowSlider:SetSliderValues(1, 40, 1)
iconsPerRowSlider:SetCallback("OnValueChanged", function(self, _, value)
BCDM.db.profile.CooldownManager[viewerType].IconsPerRow = value
BCDM:UpdateCooldownViewer(viewerType)
end)
iconsPerRowSlider:SetRelativeWidth(0.5)
layoutContainer:AddChild(iconsPerRowSlider)

local isPrimaryViewer = viewerType == "Essential" or viewerType == "Utility" or viewerType == "Buffs"

local xOffsetSlider = AG:Create("Slider")
Expand Down
76 changes: 76 additions & 0 deletions Core/Globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,82 @@ function BCDM:ApplyIconTexCoord(texture, width, height, baseZoom)
texture:SetTexCoord(left, right, top, bottom)
end

function BCDM:LayoutIconGrid(container, iconTable, db, applyCooldownTextFn)
local iconWidth, iconHeight = BCDM:GetIconDimensions(db)
local iconSpacing = db.Spacing or 0
local iconsPerRow = db.IconsPerRow or 40
local growthDirection = db.GrowthDirection or "RIGHT"
local count = #iconTable

if count == 0 then
container:SetSize(1, 1)
return
end

local isVertical = (growthDirection == "UP" or growthDirection == "DOWN")
local effectivePerRow = math.min(iconsPerRow, count)
local numRows = math.ceil(count / effectivePerRow)

local totalWidth, totalHeight
if isVertical then
totalWidth = (numRows * iconWidth) + ((numRows - 1) * iconSpacing)
totalHeight = (effectivePerRow * iconHeight) + ((effectivePerRow - 1) * iconSpacing)
else
totalWidth = (effectivePerRow * iconWidth) + ((effectivePerRow - 1) * iconSpacing)
totalHeight = (numRows * iconHeight) + ((numRows - 1) * iconSpacing)
end
container:SetSize(totalWidth, totalHeight)

local point = select(1, container:GetPoint(1))
local useCenteredLayout = (point == "TOP" or point == "BOTTOM") and not isVertical

for i, icon in ipairs(iconTable) do
icon:SetParent(container)
icon:SetSize(iconWidth, iconHeight)
icon:ClearAllPoints()

local rowIndex = math.floor((i - 1) / effectivePerRow)
local colIndex = (i - 1) % effectivePerRow

if useCenteredLayout then
local iconsInThisRow = math.min(effectivePerRow, count - rowIndex * effectivePerRow)
local rowWidth = (iconsInThisRow * iconWidth) + ((iconsInThisRow - 1) * iconSpacing)
local startX = -(rowWidth / 2) + (iconWidth / 2)
local xOff = startX + colIndex * (iconWidth + iconSpacing)
if point == "TOP" then
icon:SetPoint("TOP", container, "TOP", xOff, -(rowIndex * (iconHeight + iconSpacing)))
else
icon:SetPoint("BOTTOM", container, "BOTTOM", xOff, rowIndex * (iconHeight + iconSpacing))
end
elseif isVertical then
local visualCol = rowIndex
local visualRow = colIndex
if growthDirection == "DOWN" then
icon:SetPoint("TOPLEFT", container, "TOPLEFT",
visualCol * (iconWidth + iconSpacing),
-(visualRow * (iconHeight + iconSpacing)))
else
icon:SetPoint("BOTTOMLEFT", container, "BOTTOMLEFT",
visualCol * (iconWidth + iconSpacing),
visualRow * (iconHeight + iconSpacing))
end
else
if growthDirection == "RIGHT" then
icon:SetPoint("TOPLEFT", container, "TOPLEFT",
colIndex * (iconWidth + iconSpacing),
-(rowIndex * (iconHeight + iconSpacing)))
else
icon:SetPoint("TOPRIGHT", container, "TOPRIGHT",
-(colIndex * (iconWidth + iconSpacing)),
-(rowIndex * (iconHeight + iconSpacing)))
end
end

if applyCooldownTextFn then applyCooldownTextFn() end
icon:Show()
end
end

function BCDM:Init()
SetupSlashCommands()
BCDM:ResolveLSM()
Expand Down
3 changes: 3 additions & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ L["Enable Power Bar"] = "Enable Power Bar"
L["Reset Profile"] = "Reset Profile"
L["Use Global Profile Settings"] = "Use Global Profile Settings"

-- [[ Grid & Layout ]]
L["Icons Per Row"] = "Icons Per Row"

-- [[ Support & Links ]]
L["Join the Discord Community!"] = "Join the Discord Community!"
L["Report Issues / Feedback on GitHub!"] = "Report Issues / Feedback on GitHub!"
Expand Down
76 changes: 1 addition & 75 deletions Modules/AdditionalCustomCooldownViewer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,81 +190,7 @@ local function LayoutAdditionalCustomCooldownViewer()

CreateCustomIcons(AdditionalCustomCooldownViewerIcons)

local iconWidth, iconHeight = BCDM:GetIconDimensions(CustomDB)
local iconSpacing = CustomDB.Spacing

-- Calculate and set container size first
if #AdditionalCustomCooldownViewerIcons == 0 then
BCDM.AdditionalCustomCooldownViewerContainer:SetSize(1, 1)
else
local point = select(1, BCDM.AdditionalCustomCooldownViewerContainer:GetPoint(1))
local useCenteredLayout = (point == "TOP" or point == "BOTTOM") and (growthDirection == "LEFT" or growthDirection == "RIGHT")

local totalWidth, totalHeight = 0, 0
if useCenteredLayout or growthDirection == "RIGHT" or growthDirection == "LEFT" then
totalWidth = (#AdditionalCustomCooldownViewerIcons * iconWidth) + ((#AdditionalCustomCooldownViewerIcons - 1) * iconSpacing)
totalHeight = iconHeight
elseif growthDirection == "UP" or growthDirection == "DOWN" then
totalWidth = iconWidth
totalHeight = (#AdditionalCustomCooldownViewerIcons * iconHeight) + ((#AdditionalCustomCooldownViewerIcons - 1) * iconSpacing)
end
BCDM.AdditionalCustomCooldownViewerContainer:SetSize(totalWidth, totalHeight)
end

local LayoutConfig = {
TOPLEFT = { anchor="TOPLEFT", xMult=1, yMult=1 },
TOP = { anchor="TOP", xMult=0, yMult=1 },
TOPRIGHT = { anchor="TOPRIGHT", xMult=-1, yMult=1 },
BOTTOMLEFT = { anchor="BOTTOMLEFT", xMult=1, yMult=-1 },
BOTTOM = { anchor="BOTTOM", xMult=0, yMult=-1 },
BOTTOMRIGHT = { anchor="BOTTOMRIGHT", xMult=-1, yMult=-1 },
LEFT = { anchor="LEFT", xMult=1, yMult=0 },
RIGHT = { anchor="RIGHT", xMult=-1, yMult=0 },
CENTER = { anchor="CENTER", xMult=0, yMult=0 },
}

local point = select(1, BCDM.AdditionalCustomCooldownViewerContainer:GetPoint(1))
local useCenteredLayout = (point == "TOP" or point == "BOTTOM") and (growthDirection == "LEFT" or growthDirection == "RIGHT")

if useCenteredLayout and #AdditionalCustomCooldownViewerIcons > 0 then
local totalWidth = (#AdditionalCustomCooldownViewerIcons * iconWidth) + ((#AdditionalCustomCooldownViewerIcons - 1) * iconSpacing)
local startOffset = -(totalWidth / 2) + (iconWidth / 2)

for i, spellIcon in ipairs(AdditionalCustomCooldownViewerIcons) do
spellIcon:SetParent(BCDM.AdditionalCustomCooldownViewerContainer)
spellIcon:SetSize(iconWidth, iconHeight)
spellIcon:ClearAllPoints()

local xOffset = startOffset + ((i - 1) * (iconWidth + iconSpacing))
spellIcon:SetPoint("CENTER", BCDM.AdditionalCustomCooldownViewerContainer, "CENTER", xOffset, 0)
ApplyCooldownText()
spellIcon:Show()
end
else
for i, spellIcon in ipairs(AdditionalCustomCooldownViewerIcons) do
spellIcon:SetParent(BCDM.AdditionalCustomCooldownViewerContainer)
spellIcon:SetSize(iconWidth, iconHeight)
spellIcon:ClearAllPoints()

if i == 1 then
local config = LayoutConfig[point] or LayoutConfig.TOPLEFT
spellIcon:SetPoint(config.anchor, BCDM.AdditionalCustomCooldownViewerContainer, config.anchor, 0, 0)
else
if growthDirection == "RIGHT" then
spellIcon:SetPoint("LEFT", AdditionalCustomCooldownViewerIcons[i - 1], "RIGHT", iconSpacing, 0)
elseif growthDirection == "LEFT" then
spellIcon:SetPoint("RIGHT", AdditionalCustomCooldownViewerIcons[i - 1], "LEFT", -iconSpacing, 0)
elseif growthDirection == "UP" then
spellIcon:SetPoint("BOTTOM", AdditionalCustomCooldownViewerIcons[i - 1], "TOP", 0, iconSpacing)
elseif growthDirection == "DOWN" then
spellIcon:SetPoint("TOP", AdditionalCustomCooldownViewerIcons[i - 1], "BOTTOM", 0, -iconSpacing)
end
end
ApplyCooldownText()
spellIcon:Show()
end
end

BCDM:LayoutIconGrid(BCDM.AdditionalCustomCooldownViewerContainer, AdditionalCustomCooldownViewerIcons, CustomDB, ApplyCooldownText)
BCDM.AdditionalCustomCooldownViewerContainer:Show()
end

Expand Down
35 changes: 30 additions & 5 deletions Modules/CooldownManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,22 @@ local function StyleChargeCount()
end
end

local CenterWrappedRows

local centerBuffsUpdateThrottle = 0.01
local nextcenterBuffsUpdate = 0

local function CenterBuffs()
local currentTime = GetTime()
if currentTime < nextcenterBuffsUpdate then return end
nextcenterBuffsUpdate = currentTime + centerBuffsUpdateThrottle

local buffsSettings = BCDM.db.profile.CooldownManager.Buffs
if (buffsSettings.IconsPerRow or 40) < 40 then
CenterWrappedRows("BuffIconCooldownViewer")
return
end

local visibleBuffIcons = {}

for _, childFrame in ipairs({ BuffIconCooldownViewer:GetChildren() }) do
Expand Down Expand Up @@ -209,19 +218,22 @@ local centerBuffsEventFrame = CreateFrame("Frame")
local function SetupCenterBuffs()
local buffsSettings = BCDM.db.profile.CooldownManager.Buffs

if buffsSettings.CenterBuffs then
if buffsSettings.CenterBuffs or (buffsSettings.IconsPerRow or 40) < 40 then
centerBuffsEventFrame:SetScript("OnUpdate", CenterBuffs)
else
centerBuffsEventFrame:SetScript("OnUpdate", nil)
centerBuffsEventFrame:Hide()
end
end

local function CenterWrappedRows(viewerName)
CenterWrappedRows = function(viewerName)
local viewer = _G[viewerName]
if not viewer then return end

local iconLimit = viewer.iconLimit
local viewerType = BCDM.CooldownManagerViewerToDBViewer[viewerName]
local viewerSettings = viewerType and BCDM.db.profile.CooldownManager[viewerType]
local bcdmIconsPerRow = viewerSettings and viewerSettings.IconsPerRow or 40
local iconLimit = (bcdmIconsPerRow < 40) and bcdmIconsPerRow or viewer.iconLimit
if not iconLimit or iconLimit <= 0 then return end

local visibleIcons = {}
Expand Down Expand Up @@ -254,11 +266,13 @@ local function CenterWrappedRows(viewerName)
end

local rowCount = math.ceil(visibleCount / iconLimit)
local maxRowWidth = 0
for rowIndex = 1, rowCount do
local rowStart = (rowIndex - 1) * iconLimit + 1
local rowEnd = math.min(rowStart + iconLimit - 1, visibleCount)
local rowIcons = rowEnd - rowStart + 1
local rowWidth = (rowIcons * iconWidth) + ((rowIcons - 1) * iconSpacing)
if rowWidth > maxRowWidth then maxRowWidth = rowWidth end
local startX = -rowWidth / 2 + iconWidth / 2
local rowY = baseY + yDirection * (rowIndex - 1) * rowHeight

Expand All @@ -268,15 +282,24 @@ local function CenterWrappedRows(viewerName)
iconFrame:SetPoint(anchorPoint, viewer, relativePoint, startX + (index - rowStart) * (iconWidth + iconSpacing), rowY)
end
end

local totalHeight = rowCount * iconHeight + (rowCount - 1) * rowSpacing
C_Timer.After(0, function()
if not InCombatLockdown() then
viewer:SetSize(maxRowWidth, totalHeight)
end
end)
end

local function CenterWrappedIcons()
local cooldownManagerSettings = BCDM.db.profile.CooldownManager
local essentialSettings = cooldownManagerSettings.Essential
local utilitySettings = cooldownManagerSettings.Utility
local buffsSettings = cooldownManagerSettings.Buffs

if essentialSettings and essentialSettings.CenterHorizontally then CenterWrappedRows("EssentialCooldownViewer") end
if utilitySettings and utilitySettings.CenterHorizontally then CenterWrappedRows("UtilityCooldownViewer") end
if essentialSettings and (essentialSettings.CenterHorizontally or (essentialSettings.IconsPerRow or 40) < 40) then CenterWrappedRows("EssentialCooldownViewer") end
if utilitySettings and (utilitySettings.CenterHorizontally or (utilitySettings.IconsPerRow or 40) < 40) then CenterWrappedRows("UtilityCooldownViewer") end
if buffsSettings and (buffsSettings.IconsPerRow or 40) < 40 then CenterWrappedRows("BuffIconCooldownViewer") end
end

function BCDM:SkinCooldownManager()
Expand Down Expand Up @@ -337,6 +360,8 @@ function BCDM:UpdateCooldownViewer(viewerType)

Position()

CenterWrappedIcons()

StyleChargeCount()

ApplyCooldownText(BCDM.DBViewerToCooldownManagerViewer[viewerType])
Expand Down
Loading