From 6a25444d3e54e4889dbe7c5529421fd8288bd5d4 Mon Sep 17 00:00:00 2001 From: tylergraydev Date: Sat, 28 Feb 2026 17:01:08 -0500 Subject: [PATCH] add icons per row setting for all bars --- Core/Defaults.lua | 8 +++ Core/GUI.lua | 11 ++++ Core/Globals.lua | 76 ++++++++++++++++++++++ Locales/enUS.lua | 3 + Modules/AdditionalCustomCooldownViewer.lua | 76 +--------------------- Modules/CooldownManager.lua | 35 ++++++++-- Modules/CustomCooldownViewer.lua | 76 +--------------------- Modules/CustomItemSpellViewer.lua | 76 +--------------------- Modules/CustomItemViewer.lua | 76 +--------------------- Modules/TrinketBar.lua | 75 +-------------------- 10 files changed, 133 insertions(+), 379 deletions(-) diff --git a/Core/Defaults.lua b/Core/Defaults.lua index 523a147..22615fd 100755 --- a/Core/Defaults.lua +++ b/Core/Defaults.lua @@ -126,6 +126,7 @@ local Defaults = { IconHeight = 42, KeepAspectRatio = true, CenterHorizontally = false, + IconsPerRow = 40, Layout = {"CENTER", "CENTER", 0, -275.1}, Text = { FontSize = 15, @@ -139,6 +140,7 @@ local Defaults = { IconHeight = 36, KeepAspectRatio = true, CenterHorizontally = false, + IconsPerRow = 40, Layout = {"TOP", "EssentialCooldownViewer", "BOTTOM", 0, -1.1}, Text = { FontSize = 15, @@ -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, @@ -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}, @@ -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}, @@ -389,6 +394,7 @@ local Defaults = { Layout = {"CENTER", "NONE", "CENTER", 0, 0}, Spacing = 1, GrowthDirection = "LEFT", + IconsPerRow = 40, OffsetByParentHeight = true, HideZeroCharges = false, Text = { @@ -408,6 +414,7 @@ local Defaults = { Layout = {"CENTER", "NONE", "CENTER", 0, 0}, Spacing = 1, GrowthDirection = "LEFT", + IconsPerRow = 40, OffsetByParentHeight = true, }, ItemSpell = { @@ -419,6 +426,7 @@ local Defaults = { Layout = {"CENTER", "NONE", "CENTER", 0, 0}, Spacing = 1, GrowthDirection = "LEFT", + IconsPerRow = 40, OffsetByParentHeight = true, HideZeroCharges = false, Text = { diff --git a/Core/GUI.lua b/Core/GUI.lua index 18029ff..26164c2 100755 --- a/Core/GUI.lua +++ b/Core/GUI.lua @@ -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") diff --git a/Core/Globals.lua b/Core/Globals.lua index 1f483cf..2ea72c0 100755 --- a/Core/Globals.lua +++ b/Core/Globals.lua @@ -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() diff --git a/Locales/enUS.lua b/Locales/enUS.lua index 43196e5..7777a09 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -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!" diff --git a/Modules/AdditionalCustomCooldownViewer.lua b/Modules/AdditionalCustomCooldownViewer.lua index 7fd444a..4c28d89 100755 --- a/Modules/AdditionalCustomCooldownViewer.lua +++ b/Modules/AdditionalCustomCooldownViewer.lua @@ -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 diff --git a/Modules/CooldownManager.lua b/Modules/CooldownManager.lua index 95e51c1..b0843ed 100755 --- a/Modules/CooldownManager.lua +++ b/Modules/CooldownManager.lua @@ -155,6 +155,8 @@ local function StyleChargeCount() end end +local CenterWrappedRows + local centerBuffsUpdateThrottle = 0.01 local nextcenterBuffsUpdate = 0 @@ -162,6 +164,13 @@ 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 @@ -209,7 +218,7 @@ 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) @@ -217,11 +226,14 @@ local function SetupCenterBuffs() 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 = {} @@ -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 @@ -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() @@ -337,6 +360,8 @@ function BCDM:UpdateCooldownViewer(viewerType) Position() + CenterWrappedIcons() + StyleChargeCount() ApplyCooldownText(BCDM.DBViewerToCooldownManagerViewer[viewerType]) diff --git a/Modules/CustomCooldownViewer.lua b/Modules/CustomCooldownViewer.lua index b4c8e2d..1ee68c3 100755 --- a/Modules/CustomCooldownViewer.lua +++ b/Modules/CustomCooldownViewer.lua @@ -187,81 +187,7 @@ local function LayoutCustomCooldownViewer() CreateCustomIcons(customCooldownViewerIcons) - local iconWidth, iconHeight = BCDM:GetIconDimensions(CustomDB) - local iconSpacing = CustomDB.Spacing - - -- Calculate and set container size first - if #customCooldownViewerIcons == 0 then - BCDM.CustomCooldownViewerContainer:SetSize(1, 1) - else - local point = select(1, BCDM.CustomCooldownViewerContainer: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 = (#customCooldownViewerIcons * iconWidth) + ((#customCooldownViewerIcons - 1) * iconSpacing) - totalHeight = iconHeight - elseif growthDirection == "UP" or growthDirection == "DOWN" then - totalWidth = iconWidth - totalHeight = (#customCooldownViewerIcons * iconHeight) + ((#customCooldownViewerIcons - 1) * iconSpacing) - end - BCDM.CustomCooldownViewerContainer: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.CustomCooldownViewerContainer:GetPoint(1)) - local useCenteredLayout = (point == "TOP" or point == "BOTTOM") and (growthDirection == "LEFT" or growthDirection == "RIGHT") - - if useCenteredLayout and #customCooldownViewerIcons > 0 then - local totalWidth = (#customCooldownViewerIcons * iconWidth) + ((#customCooldownViewerIcons - 1) * iconSpacing) - local startOffset = -(totalWidth / 2) + (iconWidth / 2) - - for i, spellIcon in ipairs(customCooldownViewerIcons) do - spellIcon:SetParent(BCDM.CustomCooldownViewerContainer) - spellIcon:SetSize(iconWidth, iconHeight) - spellIcon:ClearAllPoints() - - local xOffset = startOffset + ((i - 1) * (iconWidth + iconSpacing)) - spellIcon:SetPoint("CENTER", BCDM.CustomCooldownViewerContainer, "CENTER", xOffset, 0) - ApplyCooldownText() - spellIcon:Show() - end - else - for i, spellIcon in ipairs(customCooldownViewerIcons) do - spellIcon:SetParent(BCDM.CustomCooldownViewerContainer) - spellIcon:SetSize(iconWidth, iconHeight) - spellIcon:ClearAllPoints() - - if i == 1 then - local config = LayoutConfig[point] or LayoutConfig.TOPLEFT - spellIcon:SetPoint(config.anchor, BCDM.CustomCooldownViewerContainer, config.anchor, 0, 0) - else - if growthDirection == "RIGHT" then - spellIcon:SetPoint("LEFT", customCooldownViewerIcons[i - 1], "RIGHT", iconSpacing, 0) - elseif growthDirection == "LEFT" then - spellIcon:SetPoint("RIGHT", customCooldownViewerIcons[i - 1], "LEFT", -iconSpacing, 0) - elseif growthDirection == "UP" then - spellIcon:SetPoint("BOTTOM", customCooldownViewerIcons[i - 1], "TOP", 0, iconSpacing) - elseif growthDirection == "DOWN" then - spellIcon:SetPoint("TOP", customCooldownViewerIcons[i - 1], "BOTTOM", 0, -iconSpacing) - end - end - ApplyCooldownText() - spellIcon:Show() - end - end - + BCDM:LayoutIconGrid(BCDM.CustomCooldownViewerContainer, customCooldownViewerIcons, CustomDB, ApplyCooldownText) BCDM.CustomCooldownViewerContainer:Show() end diff --git a/Modules/CustomItemSpellViewer.lua b/Modules/CustomItemSpellViewer.lua index eabdd7a..e065537 100755 --- a/Modules/CustomItemSpellViewer.lua +++ b/Modules/CustomItemSpellViewer.lua @@ -348,81 +348,7 @@ local function LayoutCustomItemsSpellsBar() CreateCustomIcons(customItemBarIcons, visibleItemIds) BCDM.CustomItemSpellBarContainer.VisibleItemIds = visibleItemIds - local iconWidth, iconHeight = BCDM:GetIconDimensions(CustomDB) - local iconSpacing = CustomDB.Spacing - - if #customItemBarIcons == 0 then - BCDM.CustomItemSpellBarContainer:SetSize(1, 1) - else - local point = select(1, BCDM.CustomItemSpellBarContainer: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 = (#customItemBarIcons * iconWidth) + ((#customItemBarIcons - 1) * iconSpacing) - totalHeight = iconHeight - elseif growthDirection == "UP" or growthDirection == "DOWN" then - totalWidth = iconWidth - totalHeight = (#customItemBarIcons * iconHeight) + ((#customItemBarIcons - 1) * iconSpacing) - end - BCDM.CustomItemSpellBarContainer:SetWidth(totalWidth) - BCDM.CustomItemSpellBarContainer:SetHeight(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.CustomItemSpellBarContainer:GetPoint(1)) - local useCenteredLayout = (point == "TOP" or point == "BOTTOM") and (growthDirection == "LEFT" or growthDirection == "RIGHT") - - if useCenteredLayout and #customItemBarIcons > 0 then - local totalWidth = (#customItemBarIcons * iconWidth) + ((#customItemBarIcons - 1) * iconSpacing) - local startOffset = -(totalWidth / 2) + (iconWidth / 2) - - for i, spellIcon in ipairs(customItemBarIcons) do - spellIcon:SetParent(BCDM.CustomItemSpellBarContainer) - spellIcon:SetSize(iconWidth, iconHeight) - spellIcon:ClearAllPoints() - - local xOffset = startOffset + ((i - 1) * (iconWidth + iconSpacing)) - spellIcon:SetPoint("CENTER", BCDM.CustomItemSpellBarContainer, "CENTER", xOffset, 0) - ApplyCooldownText() - spellIcon:Show() - end - else - for i, spellIcon in ipairs(customItemBarIcons) do - spellIcon:SetParent(BCDM.CustomItemSpellBarContainer) - spellIcon:SetSize(iconWidth, iconHeight) - spellIcon:ClearAllPoints() - - if i == 1 then - local config = LayoutConfig[point] or LayoutConfig.TOPLEFT - spellIcon:SetPoint(config.anchor, BCDM.CustomItemSpellBarContainer, config.anchor, 0, 0) - else - if growthDirection == "RIGHT" then - spellIcon:SetPoint("LEFT", customItemBarIcons[i - 1], "RIGHT", iconSpacing, 0) - elseif growthDirection == "LEFT" then - spellIcon:SetPoint("RIGHT", customItemBarIcons[i - 1], "LEFT", -iconSpacing, 0) - elseif growthDirection == "UP" then - spellIcon:SetPoint("BOTTOM", customItemBarIcons[i - 1], "TOP", 0, iconSpacing) - elseif growthDirection == "DOWN" then - spellIcon:SetPoint("TOP", customItemBarIcons[i - 1], "BOTTOM", 0, -iconSpacing) - end - end - ApplyCooldownText() - spellIcon:Show() - end - end - + BCDM:LayoutIconGrid(BCDM.CustomItemSpellBarContainer, customItemBarIcons, CustomDB, ApplyCooldownText) BCDM.CustomItemSpellBarContainer:Show() end diff --git a/Modules/CustomItemViewer.lua b/Modules/CustomItemViewer.lua index a0b6fa0..1da3982 100755 --- a/Modules/CustomItemViewer.lua +++ b/Modules/CustomItemViewer.lua @@ -286,81 +286,7 @@ local function LayoutCustomItemBar() CreateCustomIcons(customItemBarIcons, visibleItemIds) BCDM.CustomItemBarContainer.VisibleItemIds = visibleItemIds - local iconWidth, iconHeight = BCDM:GetIconDimensions(CustomDB) - local iconSpacing = CustomDB.Spacing - - if #customItemBarIcons == 0 then - BCDM.CustomItemBarContainer:SetSize(1, 1) - else - local point = select(1, BCDM.CustomItemBarContainer: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 = (#customItemBarIcons * iconWidth) + ((#customItemBarIcons - 1) * iconSpacing) - totalHeight = iconHeight - elseif growthDirection == "UP" or growthDirection == "DOWN" then - totalWidth = iconWidth - totalHeight = (#customItemBarIcons * iconHeight) + ((#customItemBarIcons - 1) * iconSpacing) - end - BCDM.CustomItemBarContainer:SetWidth(totalWidth) - BCDM.CustomItemBarContainer:SetHeight(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.CustomItemBarContainer:GetPoint(1)) - local useCenteredLayout = (point == "TOP" or point == "BOTTOM") and (growthDirection == "LEFT" or growthDirection == "RIGHT") - - if useCenteredLayout and #customItemBarIcons > 0 then - local totalWidth = (#customItemBarIcons * iconWidth) + ((#customItemBarIcons - 1) * iconSpacing) - local startOffset = -(totalWidth / 2) + (iconWidth / 2) - - for i, spellIcon in ipairs(customItemBarIcons) do - spellIcon:SetParent(BCDM.CustomItemBarContainer) - spellIcon:SetSize(iconWidth, iconHeight) - spellIcon:ClearAllPoints() - - local xOffset = startOffset + ((i - 1) * (iconWidth + iconSpacing)) - spellIcon:SetPoint("CENTER", BCDM.CustomItemBarContainer, "CENTER", xOffset, 0) - ApplyCooldownText() - spellIcon:Show() - end - else - for i, spellIcon in ipairs(customItemBarIcons) do - spellIcon:SetParent(BCDM.CustomItemBarContainer) - spellIcon:SetSize(iconWidth, iconHeight) - spellIcon:ClearAllPoints() - - if i == 1 then - local config = LayoutConfig[point] or LayoutConfig.TOPLEFT - spellIcon:SetPoint(config.anchor, BCDM.CustomItemBarContainer, config.anchor, 0, 0) - else - if growthDirection == "RIGHT" then - spellIcon:SetPoint("LEFT", customItemBarIcons[i - 1], "RIGHT", iconSpacing, 0) - elseif growthDirection == "LEFT" then - spellIcon:SetPoint("RIGHT", customItemBarIcons[i - 1], "LEFT", -iconSpacing, 0) - elseif growthDirection == "UP" then - spellIcon:SetPoint("BOTTOM", customItemBarIcons[i - 1], "TOP", 0, iconSpacing) - elseif growthDirection == "DOWN" then - spellIcon:SetPoint("TOP", customItemBarIcons[i - 1], "BOTTOM", 0, -iconSpacing) - end - end - ApplyCooldownText() - spellIcon:Show() - end - end - + BCDM:LayoutIconGrid(BCDM.CustomItemBarContainer, customItemBarIcons, CustomDB, ApplyCooldownText) BCDM.CustomItemBarContainer:Show() end diff --git a/Modules/TrinketBar.lua b/Modules/TrinketBar.lua index 3dff3ad..e8c2b68 100755 --- a/Modules/TrinketBar.lua +++ b/Modules/TrinketBar.lua @@ -180,80 +180,7 @@ local function LayoutTrinketBar() CreateCustomIcons(customTrinketIcons) - local iconWidth, iconHeight = BCDM:GetIconDimensions(CustomDB) - local iconSpacing = CustomDB.Spacing - - if #customTrinketIcons == 0 then - BCDM.TrinketBarContainer:SetSize(1, 1) - else - local point = select(1, BCDM.TrinketBarContainer: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 = (#customTrinketIcons * iconWidth) + ((#customTrinketIcons - 1) * iconSpacing) - totalHeight = iconHeight - elseif growthDirection == "UP" or growthDirection == "DOWN" then - totalWidth = iconWidth - totalHeight = (#customTrinketIcons * iconHeight) + ((#customTrinketIcons - 1) * iconSpacing) - end - BCDM.TrinketBarContainer:SetWidth(totalWidth) - BCDM.TrinketBarContainer:SetHeight(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.TrinketBarContainer:GetPoint(1)) - local useCenteredLayout = (point == "TOP" or point == "BOTTOM") and (growthDirection == "LEFT" or growthDirection == "RIGHT") - - if useCenteredLayout and #customTrinketIcons > 0 then - local totalWidth = (#customTrinketIcons * iconWidth) + ((#customTrinketIcons - 1) * iconSpacing) - local startOffset = -(totalWidth / 2) + (iconWidth / 2) - - for i, spellIcon in ipairs(customTrinketIcons) do - spellIcon:SetParent(BCDM.TrinketBarContainer) - spellIcon:SetSize(iconWidth, iconHeight) - spellIcon:ClearAllPoints() - - local xOffset = startOffset + ((i - 1) * (iconWidth + iconSpacing)) - spellIcon:SetPoint("CENTER", BCDM.TrinketBarContainer, "CENTER", xOffset, 0) - ApplyCooldownText() - spellIcon:Show() - end - else - for i, spellIcon in ipairs(customTrinketIcons) do - spellIcon:SetParent(BCDM.TrinketBarContainer) - spellIcon:SetSize(iconWidth, iconHeight) - spellIcon:ClearAllPoints() - - if i == 1 then - local config = LayoutConfig[point] or LayoutConfig.TOPLEFT - spellIcon:SetPoint(config.anchor, BCDM.TrinketBarContainer, config.anchor, 0, 0) - else - if growthDirection == "RIGHT" then - spellIcon:SetPoint("LEFT", customTrinketIcons[i - 1], "RIGHT", iconSpacing, 0) - elseif growthDirection == "LEFT" then - spellIcon:SetPoint("RIGHT", customTrinketIcons[i - 1], "LEFT", -iconSpacing, 0) - elseif growthDirection == "UP" then - spellIcon:SetPoint("BOTTOM", customTrinketIcons[i - 1], "TOP", 0, iconSpacing) - elseif growthDirection == "DOWN" then - spellIcon:SetPoint("TOP", customTrinketIcons[i - 1], "BOTTOM", 0, -iconSpacing) - end - end - ApplyCooldownText() - spellIcon:Show() - end - end + BCDM:LayoutIconGrid(BCDM.TrinketBarContainer, customTrinketIcons, CustomDB, ApplyCooldownText) if CustomDB.Enabled and #customTrinketIcons > 0 then BCDM.TrinketBarContainer:Show()