From a39e0d49d48a8431493d3dccefe454339736ca01 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 09:21:08 +0200 Subject: [PATCH 01/28] implement tab system for menu --- Cell_UnitFrames.toc | 1 + Locales/enUS.lua | 3 + Menu/MenuFrame.lua | 302 ++++++++++------------------------------- Menu/UnitFramesTab.lua | 301 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 377 insertions(+), 230 deletions(-) create mode 100644 Menu/UnitFramesTab.lua diff --git a/Cell_UnitFrames.toc b/Cell_UnitFrames.toc index 155d9d5..90ab48f 100644 --- a/Cell_UnitFrames.toc +++ b/Cell_UnitFrames.toc @@ -35,6 +35,7 @@ Core/SlashCommands.lua Menu/Builder.lua Menu/AuraFilterList.lua Menu/MenuFrame.lua +Menu/UnitFramesTab.lua Menu/Menu.lua Widgets/Common.lua diff --git a/Locales/enUS.lua b/Locales/enUS.lua index 3c18266..9b9b6d0 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -5,6 +5,9 @@ local CUF = select(2, ...) local L = Cell.L CUF.L = L +-- Tabs +L.unitFramesTab = "Unit Frames" + -- Units L.targettarget = "TargetTarget" L.player = "Player" diff --git a/Menu/MenuFrame.lua b/Menu/MenuFrame.lua index 8b0321d..6559609 100644 --- a/Menu/MenuFrame.lua +++ b/Menu/MenuFrame.lua @@ -8,141 +8,71 @@ local F = Cell.funcs local Builder = CUF.Builder local Handler = CUF.Handler +---@class Menu.Tab +---@field id string +---@field window Frame +---@field Create function +---@field ShowTab function +---@field HideTab function + ---@class MenuFrame ---@field window CellCombatFrame ----@field unitPages table ----@field unitPageButtons UnitMenuPageButton[] ----@field widgetPages table ----@field listButtons table +---@field tabs table +---@field tabsToAdd Menu.Tab[] +---@field tabButtons Menu.TabButton[] +---@field selectedTab Menu.Tab? local menuWindow = {} -menuWindow.unitPages = {} -menuWindow.unitPageButtons = {} -menuWindow.widgetPages = {} -menuWindow.listButtons = {} -menuWindow.firstWidgetInList = nil +menuWindow.tabs = {} +menuWindow.tabsToAdd = {} +menuWindow.tabButtons = {} +menuWindow.baseWidth = 450 +menuWindow.paneHeight = 22 +menuWindow.paneBuffer = 10 +menuWindow.inset = 5 CUF.MenuWindow = menuWindow ----@param unit Unit -function menuWindow:SetUnitPage(unit) - -- Hide old unit - if self.selectedUnitPage then - self.selectedUnitPage.frame:Hide() - end - - self.selectedUnitPage = self.unitPages[unit] - self.selectedUnitPage.frame:Show() - - self:LoadWidgetList(unit) - CUF.Menu:UpdateSelectedPages(unit) -end - --- Update the selected widge ----@param widget WIDGET_KIND -function menuWindow:SetWidget(widget) - -- Hide old widget - if self.selectedWidget then - self.selectedWidget.frame:Hide() - end - - self.selectedWidget = self.widgetPages[widget] - self.selectedWidget.frame:Show() - - self.selectedWidget.frame:ClearAllPoints() - self.selectedWidget.frame:SetPoint("TOPLEFT", self.settingsFrame.scrollFrame.content) - - -- Extremely dirty hack, but without this options will sometimes not be shown - C_Timer.After(0.1, function() - self.settingsFrame.scrollFrame:SetContentHeight(self.selectedWidget.height) - self.settingsFrame.scrollFrame:ResetScroll() - end) - - CUF.Menu:UpdateSelectedPages(nil, widget) -end - ----@param unit Unit -function menuWindow:LoadWidgetList(unit) - self.widgetListFrame.scrollFrame:Reset() - - local optionCount = 0 - local widgetTable = CUF.DB.GetAllWidgetTables(unit) +function menuWindow:InitTabs() + --CUF:Log("menuWindow - InitUnits") local prevButton - self.firstWidgetInList = nil - - -- The list is ordered by load order from .toc - for _, widgetPage in pairs(CUF.Menu.widgetsToAdd) do - local widgetName = widgetPage.widgetName - local widget = widgetTable[widgetName] - - if widget then - if not self.listButtons[widgetName] then - self.listButtons[widgetName] = CUF:CreateButton(self.widgetListFrame.scrollFrame.content, " ", - { 20, 20 }, nil, "transparent-accent") - end + local prevAnchor + local idx = 1 - ---@class WidgetMenuPageButton: CellButton - local button = self.listButtons[widgetName] - button:SetText(L[widgetName]) - button:GetFontString():ClearAllPoints() - button:GetFontString():SetPoint("LEFT", 5, 0) - button:GetFontString():SetPoint("RIGHT", -5, 0) + for _, tab in pairs(self.tabsToAdd) do + ---@cast tab Menu.Tab + self.tabs[tab.id] = tab - button.id = widgetName - optionCount = optionCount + 1 + ---@class Menu.TabButton: CellButton + local tabButton = CUF:CreateButton(self.window, L[tab.id], { 100, self.paneHeight }) + tabButton.id = tab.id - if widget.enabled then - button:SetTextColor(1, 1, 1, 1) - else - button:SetTextColor(0.466, 0.466, 0.466, 1) - end + if prevButton then + -- Max 4 buttons per row + if idx % 4 == 0 then + tabButton:SetPoint("BOTTOMRIGHT", prevAnchor, "TOPRIGHT", 0, 0) + idx = 1 + prevAnchor = tabButton - button:SetParent(self.widgetListFrame.scrollFrame.content) - button:SetPoint("RIGHT") - if not prevButton then - button:SetPoint("TOPLEFT") + self.window:SetHeight(self.window:GetHeight() + self.paneHeight) + self.tabPane:SetHeight(self.tabPane:GetHeight() + self.paneHeight) else - button:SetPoint("TOPLEFT", prevButton, "BOTTOMLEFT", 0, 1) - end - button:Show() - - prevButton = button - if not self.firstWidgetInList then - self.firstWidgetInList = widgetName + tabButton:SetPoint("TOPLEFT", prevButton, "TOPRIGHT", 1) + idx = idx + 1 end + else + tabButton:SetPoint("BOTTOMLEFT", self.tabPane, "BOTTOMLEFT", 0, 1) + prevAnchor = tabButton end - end - - self.widgetListFrame.scrollFrame:SetContentHeight(20, optionCount, -1) - - Cell:CreateButtonGroup(self.listButtons, function(widget, b) - self:SetWidget(widget) - end) + prevButton = tabButton - -- Make sure that the currently selected widget is valid - if self.selectedWidget then - if not widgetTable[self.selectedWidget.id] then - self.listButtons[self.firstWidgetInList]:Click() - end + table.insert(self.tabButtons, tabButton) end -end ----@param layout string? ----@param unit Unit? ----@param widgetName WIDGET_KIND? -function menuWindow.UpdateWidgetListEnabled(layout, unit, widgetName, setting) - if not widgetName then return end - if not setting == CUF.constants.OPTION_KIND.ENABLED then return end - if not menuWindow.listButtons[widgetName] then return end - - if CUF.DB.GetWidgetTable(widgetName, unit, layout).enabled then - menuWindow.listButtons[widgetName]:SetTextColor(1, 1, 1, 1) - else - menuWindow.listButtons[widgetName]:SetTextColor(0.466, 0.466, 0.466, 1) - end + Cell:CreateButtonGroup(self.tabButtons, function(which, b) + self:SetTab(which) + end) end -CUF:RegisterCallback("UpdateWidget", "UpdateWidgetListEnabled", menuWindow.UpdateWidgetListEnabled) - function menuWindow:ShowMenu() CUF:Log("|cff00ccffShow Menu|r") if not self.window then @@ -150,8 +80,7 @@ function menuWindow:ShowMenu() self.window:Show() - self.unitPageButtons[1]:Click() - self.listButtons[self.firstWidgetInList]:Click() + self.tabButtons[1]:Click() self.init = true CUF.vars.isMenuOpen = true @@ -172,54 +101,22 @@ function menuWindow:HideMenu() Handler.UpdateSelected() end -------------------------------------------------- --- MARK: Init -------------------------------------------------- - -function menuWindow:InitUnits() - --CUF:Log("menuWindow - InitUnits") - local prevButton - local prevAnchor - local idx = 1 - - for _, fn in pairs(CUF.Menu.unitsToAdd) do - ---@type UnitsMenuPage - local unit = fn(self) - - self.unitPages[unit.id] = unit - - if prevButton then - -- Max 4 buttons per row - if idx % 4 == 0 then - unit.pageButton:SetPoint("BOTTOMLEFT", prevAnchor, "TOPLEFT", 0, 0) - idx = 1 - prevAnchor = unit.pageButton - - self.window:SetHeight(self.window:GetHeight() + self.paneHeight) - self.unitPane:SetHeight(self.unitPane:GetHeight() + self.paneHeight) - else - unit.pageButton:SetPoint("TOPRIGHT", prevButton, "TOPLEFT", 1) - idx = idx + 1 - end - else - unit.pageButton:SetPoint("BOTTOMRIGHT", self.unitPane, "BOTTOMRIGHT", 0, 1) - prevAnchor = unit.pageButton - end - prevButton = unit.pageButton - - table.insert(self.unitPageButtons, unit.pageButton) +---@param which string +function menuWindow:SetTab(which) + -- Hide old unit + if self.selectedTab then + self.selectedTab:HideTab() end -end -function menuWindow:InitWidgets() - --CUF:Log("menuWindow - InitWidgets") + self.selectedTab = self.tabs[which] + self.selectedTab:ShowTab() - for _, widget in pairs(CUF.Menu.widgetsToAdd) do - ---@type WidgetMenuPage - local widgetPage = Builder:CreateWidgetMenuPage(self.settingsFrame, widget.widgetName, unpack(widget.options)) + self.window:SetHeight(self.selectedTab.window:GetHeight() + self.paneHeight + self.paneBuffer) +end - self.widgetPages[widgetPage.id] = widgetPage - end +---@param tab Menu.Tab +function menuWindow:AddTab(tab) + table.insert(self.tabsToAdd, tab) end ------------------------------------------------- @@ -230,85 +127,30 @@ function menuWindow:Create() CUF:Log("|cff00ccffCreate Menu|r") local optionsFrame = Cell.frames.optionsFrame - self.unitHeight = 180 - self.widgetHeight = 400 - self.baseWidth = 450 - self.paneHeight = 17 - - local buffer = 5 - local gap = buffer * 2 - local windowHeight = self.unitHeight + self.widgetHeight + (self.paneHeight * 2) - local sectionWidth = self.baseWidth - gap - ---@class CellCombatFrame - self.window = CUF:CreateFrame("CUF_Menu", optionsFrame, - self.baseWidth, - windowHeight) - self.window:SetPoint("TOPRIGHT", CellLayoutsPreviewButton, "BOTTOMRIGHT", 0, -buffer) + self.window = CUF:CreateFrame("CUF_Menu", optionsFrame, self.baseWidth, 300) + self.window:SetPoint("TOPRIGHT", CellLayoutsPreviewButton, "BOTTOMRIGHT", 0, -self.inset) -- mask F:ApplyCombatProtectionToFrame(self.window) Cell:CreateMask(self.window, nil, { 1, -1, -1, 1 }) self.window.mask:Hide() - -- Unit Buttons - self.unitPane = Cell:CreateTitledPane(self.window, L.UnitFrames, sectionWidth, - self.paneHeight) - self.unitPane:SetPoint("TOPLEFT", buffer, -buffer) + -- Tabs + self.tabPane = Cell:CreateTitledPane(self.window, nil, self.baseWidth, self.paneHeight) + self.tabPane:SetPoint("TOPLEFT") -- Repoint so it's anchored to bottom - self.unitPane.line:ClearAllPoints() - self.unitPane.line:SetPoint("BOTTOMLEFT", self.unitPane, "BOTTOMLEFT") - self.unitPane.line:SetPoint("BOTTOMRIGHT", self.unitPane, "BOTTOMRIGHT") - - -- Unit Settings - self.unitSection = CUF:CreateFrame("CUF_Menu_Unit", self.unitPane, - sectionWidth, - self.unitHeight, true, true) - self.unitSection:SetPoint("TOPLEFT", self.unitPane, "BOTTOMLEFT") - - self:InitUnits() - Cell:CreateButtonGroup(self.unitPageButtons, function(unit, b) - self:SetUnitPage(unit) - end) + self.tabPane.line:ClearAllPoints() + self.tabPane.line:SetPoint("BOTTOMLEFT", self.tabPane, "BOTTOMLEFT") + self.tabPane.line:SetPoint("BOTTOMRIGHT", self.tabPane, "BOTTOMRIGHT") - -- Widget Buttons - self.widgetPane = Cell:CreateTitledPane(self.unitSection, L.Widgets, - sectionWidth, self.paneHeight) - self.widgetPane:SetPoint("TOPLEFT", self.unitSection, "BOTTOMLEFT") + local gap = self.inset * 2 + local anchorWidth = self.baseWidth - gap + self.tabAnchor = CUF:CreateFrame(nil, self.tabPane, anchorWidth, 1, true) + self.tabAnchor:SetPoint("TOPLEFT", self.tabPane, "BOTTOMLEFT", self.inset, -self.paneBuffer) - -- Repoint so it's anchored to bottom - self.widgetPane.line:ClearAllPoints() - self.widgetPane.line:SetPoint("BOTTOMLEFT", self.widgetPane, "BOTTOMLEFT") - self.widgetPane.line:SetPoint("BOTTOMRIGHT", self.widgetPane, "BOTTOMRIGHT") - - -- settings frame - ---@class MenuFrame.settingsFrame: Frame - ---@field scrollFrame CellScrollFrame - self.settingsFrame = CUF:CreateFrame("CUF_Menu_Widget", self.widgetPane, - sectionWidth, - (self.widgetHeight - self.paneHeight), true, true) - self.settingsFrame:SetPoint("TOPLEFT", self.widgetPane, "BOTTOMLEFT", 0, -buffer) - - Cell:CreateScrollFrame(self.settingsFrame) - self.settingsFrame.scrollFrame:SetScrollStep(50) - - self:InitWidgets() - - local widgetListWindow = CUF:CreateFrame("CUF_Menu_WidgetList", self.window, - sectionWidth / 3, - self.settingsFrame:GetHeight(), false, true) - widgetListWindow:SetPoint("BOTTOMRIGHT", self.window, "BOTTOMLEFT", 1, 0) - - ---@class MenuFrame.widgetListFrame: Frame - ---@field scrollFrame CellScrollFrame - self.widgetListFrame = CUF:CreateFrame("CUF_Menu_WidgetListFrame", widgetListWindow, - widgetListWindow:GetWidth(), - widgetListWindow:GetHeight(), false, true) - self.widgetListFrame:SetPoint("TOPLEFT", widgetListWindow, "TOPLEFT", 0, 0) - - Cell:CreateScrollFrame(self.widgetListFrame) - self.widgetListFrame.scrollFrame:SetScrollStep(25) + self:InitTabs() hooksecurefunc(optionsFrame, "Hide", function() self:HideMenu() diff --git a/Menu/UnitFramesTab.lua b/Menu/UnitFramesTab.lua new file mode 100644 index 0000000..39da32c --- /dev/null +++ b/Menu/UnitFramesTab.lua @@ -0,0 +1,301 @@ +---@class CUF +local CUF = select(2, ...) + +local Cell = CUF.Cell +local L = CUF.L +local F = Cell.funcs + +local Builder = CUF.Builder +local Handler = CUF.Handler +local MenuWindow = CUF.MenuWindow + +---@class UnitsFramesTab: Menu.Tab +---@field unitPages table +---@field unitPageButtons UnitMenuPageButton[] +---@field widgetPages table +---@field listButtons table +local unitFramesTab = {} +unitFramesTab.unitPages = {} +unitFramesTab.unitPageButtons = {} +unitFramesTab.widgetPages = {} +unitFramesTab.listButtons = {} +unitFramesTab.firstWidgetInList = nil +unitFramesTab.id = "unitFramesTab" +unitFramesTab.widgetHeight = 400 +unitFramesTab.unitHeight = 180 +unitFramesTab.paneHeight = 17 + +MenuWindow:AddTab(unitFramesTab) + +---@param unit Unit +function unitFramesTab:SetUnitPage(unit) + -- Hide old unit + if self.selectedUnitPage then + self.selectedUnitPage.frame:Hide() + end + + self.selectedUnitPage = self.unitPages[unit] + self.selectedUnitPage.frame:Show() + + self:LoadWidgetList(unit) + CUF.Menu:UpdateSelectedPages(unit) +end + +-- Update the selected widge +---@param widget WIDGET_KIND +function unitFramesTab:SetWidget(widget) + -- Hide old widget + if self.selectedWidget then + self.selectedWidget.frame:Hide() + end + + self.selectedWidget = self.widgetPages[widget] + self.selectedWidget.frame:Show() + + self.selectedWidget.frame:ClearAllPoints() + self.selectedWidget.frame:SetPoint("TOPLEFT", self.settingsFrame.scrollFrame.content) + + -- Extremely dirty hack, but without this options will sometimes not be shown + C_Timer.After(0.1, function() + self.settingsFrame.scrollFrame:SetContentHeight(self.selectedWidget.height) + self.settingsFrame.scrollFrame:ResetScroll() + end) + + CUF.Menu:UpdateSelectedPages(nil, widget) +end + +---@param unit Unit +function unitFramesTab:LoadWidgetList(unit) + self.widgetListFrame.scrollFrame:Reset() + + local optionCount = 0 + local widgetTable = CUF.DB.GetAllWidgetTables(unit) + local prevButton + self.firstWidgetInList = nil + + -- The list is ordered by load order from .toc + for _, widgetPage in pairs(CUF.Menu.widgetsToAdd) do + local widgetName = widgetPage.widgetName + local widget = widgetTable[widgetName] + + if widget then + if not self.listButtons[widgetName] then + self.listButtons[widgetName] = CUF:CreateButton(self.widgetListFrame.scrollFrame.content, " ", + { 20, 20 }, nil, "transparent-accent") + end + + ---@class WidgetMenuPageButton: CellButton + local button = self.listButtons[widgetName] + button:SetText(L[widgetName]) + button:GetFontString():ClearAllPoints() + button:GetFontString():SetPoint("LEFT", 5, 0) + button:GetFontString():SetPoint("RIGHT", -5, 0) + + button.id = widgetName + optionCount = optionCount + 1 + + if widget.enabled then + button:SetTextColor(1, 1, 1, 1) + else + button:SetTextColor(0.466, 0.466, 0.466, 1) + end + + button:SetParent(self.widgetListFrame.scrollFrame.content) + button:SetPoint("RIGHT") + if not prevButton then + button:SetPoint("TOPLEFT") + else + button:SetPoint("TOPLEFT", prevButton, "BOTTOMLEFT", 0, 1) + end + button:Show() + + prevButton = button + if not self.firstWidgetInList then + self.firstWidgetInList = widgetName + end + end + end + + self.widgetListFrame.scrollFrame:SetContentHeight(20, optionCount, -1) + + Cell:CreateButtonGroup(self.listButtons, function(widget, b) + self:SetWidget(widget) + end) + + -- Make sure that the currently selected widget is valid + if self.selectedWidget then + if not widgetTable[self.selectedWidget.id] then + self.listButtons[self.firstWidgetInList]:Click() + end + end +end + +---@param layout string? +---@param unit Unit? +---@param widgetName WIDGET_KIND? +function unitFramesTab.UpdateWidgetListEnabled(layout, unit, widgetName, setting) + if not widgetName then return end + if not setting == CUF.constants.OPTION_KIND.ENABLED then return end + if not unitFramesTab.listButtons[widgetName] then return end + + if CUF.DB.GetWidgetTable(widgetName, unit, layout).enabled then + unitFramesTab.listButtons[widgetName]:SetTextColor(1, 1, 1, 1) + else + unitFramesTab.listButtons[widgetName]:SetTextColor(0.466, 0.466, 0.466, 1) + end +end + +CUF:RegisterCallback("UpdateWidget", "UpdateWidgetListEnabled", unitFramesTab.UpdateWidgetListEnabled) + +function unitFramesTab:ShowTab() + CUF:Log("|cff00ccffShow unitFramesTab|r") + if not self.window then + self:Create() + + self.window:Show() + + self.unitPageButtons[1]:Click() + self.listButtons[self.firstWidgetInList]:Click() + + self.init = true + + return + end + + self.window:Show() +end + +function unitFramesTab:HideTab() + if not self.window or not self.window:IsShown() then return end + CUF:Log("|cff00ccffHide unitFramesTab|r") + self.window:Hide() + + Handler.UpdateSelected() +end + +------------------------------------------------- +-- MARK: Init +------------------------------------------------- + +function unitFramesTab:InitUnits() + --CUF:Log("menuWindow - InitUnits") + local prevButton + local prevAnchor + local idx = 1 + + for _, fn in pairs(CUF.Menu.unitsToAdd) do + ---@type UnitsMenuPage + local unit = fn(self) + + self.unitPages[unit.id] = unit + + if prevButton then + -- Max 4 buttons per row + if idx % 4 == 0 then + unit.pageButton:SetPoint("BOTTOMLEFT", prevAnchor, "TOPLEFT", 0, 0) + idx = 1 + prevAnchor = unit.pageButton + + self.window:SetHeight(self.window:GetHeight() + self.paneHeight) + self.unitPane:SetHeight(self.unitPane:GetHeight() + self.paneHeight) + else + unit.pageButton:SetPoint("TOPRIGHT", prevButton, "TOPLEFT", 1) + idx = idx + 1 + end + else + unit.pageButton:SetPoint("BOTTOMRIGHT", self.unitPane, "BOTTOMRIGHT", 0, 1) + prevAnchor = unit.pageButton + end + prevButton = unit.pageButton + + table.insert(self.unitPageButtons, unit.pageButton) + end +end + +function unitFramesTab:InitWidgets() + --CUF:Log("menuWindow - InitWidgets") + + for _, widget in pairs(CUF.Menu.widgetsToAdd) do + ---@type WidgetMenuPage + local widgetPage = Builder:CreateWidgetMenuPage(self.settingsFrame, widget.widgetName, unpack(widget.options)) + + self.widgetPages[widgetPage.id] = widgetPage + end +end + +------------------------------------------------- +-- MARK: Create +------------------------------------------------- + +function unitFramesTab:Create() + CUF:Log("|cff00ccffCreate UnitFramesTab|r") + + local inset = MenuWindow.inset + local windowHeight = self.unitHeight + self.widgetHeight + (self.paneHeight * 2) + + local sectionWidth = MenuWindow.tabAnchor:GetWidth() + + self.window = CUF:CreateFrame("CUF_Menu_UnitFrame", MenuWindow.window, + sectionWidth, + windowHeight, true) + self.window:SetPoint("TOPLEFT", MenuWindow.tabAnchor, "TOPLEFT") + + -- Unit Buttons + self.unitPane = Cell:CreateTitledPane(self.window, L.UnitFrames, sectionWidth, + self.paneHeight) + self.unitPane:SetPoint("TOPLEFT") + + -- Repoint so it's anchored to bottom + self.unitPane.line:ClearAllPoints() + self.unitPane.line:SetPoint("BOTTOMLEFT", self.unitPane, "BOTTOMLEFT") + self.unitPane.line:SetPoint("BOTTOMRIGHT", self.unitPane, "BOTTOMRIGHT") + + -- Unit Settings + self.unitSection = CUF:CreateFrame("CUF_Menu_UnitFrame_Unit", self.unitPane, + sectionWidth, + self.unitHeight, true, true) + self.unitSection:SetPoint("TOPLEFT", self.unitPane, "BOTTOMLEFT") + + self:InitUnits() + Cell:CreateButtonGroup(self.unitPageButtons, function(unit, b) + self:SetUnitPage(unit) + end) + + -- Widget Buttons + self.widgetPane = Cell:CreateTitledPane(self.unitSection, L.Widgets, + sectionWidth, self.paneHeight) + self.widgetPane:SetPoint("TOPLEFT", self.unitSection, "BOTTOMLEFT") + + -- Repoint so it's anchored to bottom + self.widgetPane.line:ClearAllPoints() + self.widgetPane.line:SetPoint("BOTTOMLEFT", self.widgetPane, "BOTTOMLEFT") + self.widgetPane.line:SetPoint("BOTTOMRIGHT", self.widgetPane, "BOTTOMRIGHT") + + -- settings frame + ---@class UnitsFramesTab.settingsFrame: Frame + ---@field scrollFrame CellScrollFrame + self.settingsFrame = CUF:CreateFrame("CUF_Menu_UnitFrame_Widget", self.widgetPane, + sectionWidth, + (self.widgetHeight - self.paneHeight), true, true) + self.settingsFrame:SetPoint("TOPLEFT", self.widgetPane, "BOTTOMLEFT", 0, -inset) + + Cell:CreateScrollFrame(self.settingsFrame) + self.settingsFrame.scrollFrame:SetScrollStep(50) + + self:InitWidgets() + + local widgetListWindow = CUF:CreateFrame("CUF_Menu_UnitFrame_WidgetList", self.window, + sectionWidth / 3, + self.settingsFrame:GetHeight(), false, true) + widgetListWindow:SetPoint("BOTTOMRIGHT", self.window, "BOTTOMLEFT", 1 - inset, 0) + + ---@class UnitsFramesTab.widgetListFrame: Frame + ---@field scrollFrame CellScrollFrame + self.widgetListFrame = CUF:CreateFrame("CUF_Menu_UnitFrame_WidgetListFrame", widgetListWindow, + widgetListWindow:GetWidth(), + widgetListWindow:GetHeight(), false, true) + self.widgetListFrame:SetPoint("TOPLEFT", widgetListWindow, "TOPLEFT", 0, 0) + + Cell:CreateScrollFrame(self.widgetListFrame) + self.widgetListFrame.scrollFrame:SetScrollStep(25) +end From 985ce2631fc36f537c4c816d3e5aee0f225029be Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 09:21:17 +0200 Subject: [PATCH 02/28] update annotations --- Menu/Builder.lua | 2 +- UnitFrames/MenuOptions.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Menu/Builder.lua b/Menu/Builder.lua index 2e25cfe..2304268 100644 --- a/Menu/Builder.lua +++ b/Menu/Builder.lua @@ -63,7 +63,7 @@ Builder.MenuOptions = { ---@field pageName string ---@field options table ----@param settingsFrame MenuFrame.settingsFrame +---@param settingsFrame UnitsFramesTab.settingsFrame ---@param widgetName WIDGET_KIND ---@param ... MenuOptions ---@return WidgetMenuPage diff --git a/UnitFrames/MenuOptions.lua b/UnitFrames/MenuOptions.lua index 9ef67b3..59e6603 100644 --- a/UnitFrames/MenuOptions.lua +++ b/UnitFrames/MenuOptions.lua @@ -59,7 +59,7 @@ end local function AddUnitsToMenu() for _, unit in pairs(CUF.constants.UNIT) do CUF.Menu:AddUnit( - ---@param parent MenuFrame + ---@param parent UnitsFramesTab ---@return UnitsMenuPage function(parent) ---@class UnitsMenuPage From b49fa0a84ed40ae7703e6b6340cad837f82c436a Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 11:31:49 +0200 Subject: [PATCH 03/28] merge MenuFrame.lua into Menu.lua --- Cell_UnitFrames.toc | 3 +- Menu/Menu.lua | 171 ++++++++++++++++++++++++++++++++++++++--- Menu/MenuFrame.lua | 158 ------------------------------------- Menu/UnitFramesTab.lua | 13 ++-- 4 files changed, 168 insertions(+), 177 deletions(-) delete mode 100644 Menu/MenuFrame.lua diff --git a/Cell_UnitFrames.toc b/Cell_UnitFrames.toc index 90ab48f..3e1aabe 100644 --- a/Cell_UnitFrames.toc +++ b/Cell_UnitFrames.toc @@ -34,9 +34,8 @@ Core/SlashCommands.lua Menu/Builder.lua Menu/AuraFilterList.lua -Menu/MenuFrame.lua -Menu/UnitFramesTab.lua Menu/Menu.lua +Menu/UnitFramesTab.lua Widgets/Common.lua diff --git a/Menu/Menu.lua b/Menu/Menu.lua index 3d80d3a..c10680c 100644 --- a/Menu/Menu.lua +++ b/Menu/Menu.lua @@ -2,20 +2,33 @@ local CUF = select(2, ...) local Cell = CUF.Cell -local Util = CUF.Util +local F = Cell.funcs -local menuWindow = CUF.MenuWindow +local L = CUF.L +local Util = CUF.Util +local Handler = CUF.Handler ---@class CUF.Menu +---@field window CellCombatFrame +---@field tabs table +---@field tabsToAdd Menu.Tab[] +---@field tabButtons Menu.TabButton[] +---@field selectedTab Menu.Tab? ---@field selectedWidgetTable WidgetTable ---@field unitsToAdd table ---@field widgetsToAdd table local menu = {} -menu.window = menuWindow +menu.tabs = {} +menu.tabsToAdd = {} menu.unitsToAdd = {} +menu.tabButtons = {} menu.widgetsToAdd = {} menu.init = false menu.hookInit = false +menu.baseWidth = 450 +menu.paneHeight = 22 +menu.paneBuffer = 10 +menu.inset = 5 CUF.Menu = menu @@ -52,7 +65,7 @@ function menu:UpdateSelectedPages(unit, widget) end -- Prevent excessive calls when initializing - if not menu.window.init then return end + if not menu.init then return end CUF:Fire("LoadPageDB", unit, widget) end @@ -63,17 +76,155 @@ end -- -- Fires `LoadPageDB` and `UpdateVisibility` callbacks ---@param layout string -local function LoadLayoutDB(layout) +function menu:LoadLayoutDB(layout) CUF:Log("|cff00ff00LoadLayoutDB:|r", layout, CUF.vars.selectedUnit, CUF.vars.selectedWidget) CUF.DB.VerifyDB() CUF.vars.selectedLayout = layout - menu.window:ShowMenu() + menu:ShowMenu() CUF:Fire("LoadPageDB", CUF.vars.selectedUnit, CUF.vars.selectedWidget) CUF:Fire("UpdateVisibility") end +------------------------------------------------- +-- MARK: Menu Window +------------------------------------------------- + +---@class Menu.Tab +---@field id string +---@field window Frame +---@field Create function +---@field ShowTab function +---@field HideTab function + +--- Initialize tabs buttons and adds them to the tab pane +function menu:InitTabs() + --CUF:Log("menu - InitUnits") + local prevButton + local prevAnchor + local idx = 1 + + for _, tab in pairs(self.tabsToAdd) do + ---@cast tab Menu.Tab + self.tabs[tab.id] = tab + + ---@class Menu.TabButton: CellButton + local tabButton = CUF:CreateButton(self.window, L[tab.id], { 100, self.paneHeight }) + tabButton.id = tab.id + + if prevButton then + -- Max 4 buttons per row + if idx % 4 == 0 then + tabButton:SetPoint("BOTTOMRIGHT", prevAnchor, "TOPRIGHT", 0, 0) + idx = 1 + prevAnchor = tabButton + + self.window:SetHeight(self.window:GetHeight() + self.paneHeight) + self.tabPane:SetHeight(self.tabPane:GetHeight() + self.paneHeight) + else + tabButton:SetPoint("TOPLEFT", prevButton, "TOPRIGHT", 1) + idx = idx + 1 + end + else + tabButton:SetPoint("BOTTOMLEFT", self.tabPane, "BOTTOMLEFT", 0, 1) + prevAnchor = tabButton + end + prevButton = tabButton + + table.insert(self.tabButtons, tabButton) + end + + Cell:CreateButtonGroup(self.tabButtons, function(which, b) + self:SetTab(which) + end) +end + +--- Show the menu +--- +--- Initializes the menu if it hasn't been initialized yet +function menu:ShowMenu() + CUF:Log("|cff00ccffShow Menu|r") + if not self.window then + self:CreateMenu() + + self.window:Show() + + self.tabButtons[1]:Click() + + self.init = true + CUF.vars.isMenuOpen = true + + return + end + + self.window:Show() + CUF.vars.isMenuOpen = true +end + +--- Hide the menu and the current tab +function menu:HideMenu() + if not self.window or not self.window:IsShown() then return end + CUF:Log("|cff00ccffHide Menu|r") + self.window:Hide() + + CUF.vars.isMenuOpen = false + Handler.UpdateSelected() +end + +---@param which string +function menu:SetTab(which) + -- Hide old unit + if self.selectedTab then + self.selectedTab:HideTab() + end + CUF.vars.selectedTab = which + + self.selectedTab = self.tabs[which] + self.selectedTab:ShowTab() + + self.window:SetHeight(self.selectedTab.window:GetHeight() + self.paneHeight + self.paneBuffer) +end + +---@param tab Menu.Tab +function menu:AddTab(tab) + table.insert(self.tabsToAdd, tab) +end + +function menu:CreateMenu() + CUF:Log("|cff00ccffCreate Menu|r") + local optionsFrame = Cell.frames.optionsFrame + + ---@class CellCombatFrame + self.window = CUF:CreateFrame("CUF_Menu", optionsFrame, self.baseWidth, 300) + self.window:SetPoint("TOPRIGHT", CellLayoutsPreviewButton, "BOTTOMRIGHT", 0, -self.inset) + + -- mask + F:ApplyCombatProtectionToFrame(self.window) + Cell:CreateMask(self.window, nil, { 1, -1, -1, 1 }) + self.window.mask:Hide() + + -- Tabs + self.tabPane = Cell:CreateTitledPane(self.window, nil, self.baseWidth, self.paneHeight) + self.tabPane:SetPoint("TOPLEFT") + + -- Repoint so it's anchored to bottom + self.tabPane.line:ClearAllPoints() + self.tabPane.line:SetPoint("BOTTOMLEFT", self.tabPane, "BOTTOMLEFT") + self.tabPane.line:SetPoint("BOTTOMRIGHT", self.tabPane, "BOTTOMRIGHT") + + local gap = self.inset * 2 + local anchorWidth = self.baseWidth - gap + self.tabAnchor = CUF:CreateFrame(nil, self.tabPane, anchorWidth, 1, true) + self.tabAnchor:SetPoint("TOPLEFT", self.tabPane, "BOTTOMLEFT", self.inset, -self.paneBuffer) + + self:InitTabs() + + hooksecurefunc(optionsFrame, "Hide", function() + self:HideMenu() + end) +end + ------------------------------------------------- -- MARK: Callbacks - Hooks ------------------------------------------------- @@ -103,11 +254,11 @@ local function UpdatePreview() hooksecurefunc(layoutDropdown, "SetSelectedValue", function(self) --CUF:Log("Cell_SetSelectedValue", self:GetSelected()) - LoadLayoutDB(self:GetSelected()) + menu:LoadLayoutDB(self:GetSelected()) end) -- Initial load - LoadLayoutDB(layoutDropdown:GetSelected()) + menu:LoadLayoutDB(layoutDropdown:GetSelected()) -- Unhook Cell:UnregisterCallback("UpdatePreview", "CUF_UpdatePreview") @@ -117,8 +268,8 @@ end local function ShowTab(tab) --CUF:Log("Cell_ShowTab", tab) if tab ~= "layouts" then - menuWindow:HideMenu() - elseif not menu.window.init then + menu:HideMenu() + elseif not menu.init then -- Inital hook Cell:RegisterCallback("UpdatePreview", "CUF_UpdatePreview", UpdatePreview) end diff --git a/Menu/MenuFrame.lua b/Menu/MenuFrame.lua deleted file mode 100644 index 6559609..0000000 --- a/Menu/MenuFrame.lua +++ /dev/null @@ -1,158 +0,0 @@ ----@class CUF -local CUF = select(2, ...) - -local Cell = CUF.Cell -local L = CUF.L -local F = Cell.funcs - -local Builder = CUF.Builder -local Handler = CUF.Handler - ----@class Menu.Tab ----@field id string ----@field window Frame ----@field Create function ----@field ShowTab function ----@field HideTab function - ----@class MenuFrame ----@field window CellCombatFrame ----@field tabs table ----@field tabsToAdd Menu.Tab[] ----@field tabButtons Menu.TabButton[] ----@field selectedTab Menu.Tab? -local menuWindow = {} -menuWindow.tabs = {} -menuWindow.tabsToAdd = {} -menuWindow.tabButtons = {} -menuWindow.baseWidth = 450 -menuWindow.paneHeight = 22 -menuWindow.paneBuffer = 10 -menuWindow.inset = 5 - -CUF.MenuWindow = menuWindow - -function menuWindow:InitTabs() - --CUF:Log("menuWindow - InitUnits") - local prevButton - local prevAnchor - local idx = 1 - - for _, tab in pairs(self.tabsToAdd) do - ---@cast tab Menu.Tab - self.tabs[tab.id] = tab - - ---@class Menu.TabButton: CellButton - local tabButton = CUF:CreateButton(self.window, L[tab.id], { 100, self.paneHeight }) - tabButton.id = tab.id - - if prevButton then - -- Max 4 buttons per row - if idx % 4 == 0 then - tabButton:SetPoint("BOTTOMRIGHT", prevAnchor, "TOPRIGHT", 0, 0) - idx = 1 - prevAnchor = tabButton - - self.window:SetHeight(self.window:GetHeight() + self.paneHeight) - self.tabPane:SetHeight(self.tabPane:GetHeight() + self.paneHeight) - else - tabButton:SetPoint("TOPLEFT", prevButton, "TOPRIGHT", 1) - idx = idx + 1 - end - else - tabButton:SetPoint("BOTTOMLEFT", self.tabPane, "BOTTOMLEFT", 0, 1) - prevAnchor = tabButton - end - prevButton = tabButton - - table.insert(self.tabButtons, tabButton) - end - - Cell:CreateButtonGroup(self.tabButtons, function(which, b) - self:SetTab(which) - end) -end - -function menuWindow:ShowMenu() - CUF:Log("|cff00ccffShow Menu|r") - if not self.window then - self:Create() - - self.window:Show() - - self.tabButtons[1]:Click() - - self.init = true - CUF.vars.isMenuOpen = true - - return - end - - self.window:Show() - CUF.vars.isMenuOpen = true -end - -function menuWindow:HideMenu() - if not self.window or not self.window:IsShown() then return end - CUF:Log("|cff00ccffHide Menu|r") - self.window:Hide() - - CUF.vars.isMenuOpen = false - Handler.UpdateSelected() -end - ----@param which string -function menuWindow:SetTab(which) - -- Hide old unit - if self.selectedTab then - self.selectedTab:HideTab() - end - - self.selectedTab = self.tabs[which] - self.selectedTab:ShowTab() - - self.window:SetHeight(self.selectedTab.window:GetHeight() + self.paneHeight + self.paneBuffer) -end - ----@param tab Menu.Tab -function menuWindow:AddTab(tab) - table.insert(self.tabsToAdd, tab) -end - -------------------------------------------------- --- MARK: Create -------------------------------------------------- - -function menuWindow:Create() - CUF:Log("|cff00ccffCreate Menu|r") - local optionsFrame = Cell.frames.optionsFrame - - ---@class CellCombatFrame - self.window = CUF:CreateFrame("CUF_Menu", optionsFrame, self.baseWidth, 300) - self.window:SetPoint("TOPRIGHT", CellLayoutsPreviewButton, "BOTTOMRIGHT", 0, -self.inset) - - -- mask - F:ApplyCombatProtectionToFrame(self.window) - Cell:CreateMask(self.window, nil, { 1, -1, -1, 1 }) - self.window.mask:Hide() - - -- Tabs - self.tabPane = Cell:CreateTitledPane(self.window, nil, self.baseWidth, self.paneHeight) - self.tabPane:SetPoint("TOPLEFT") - - -- Repoint so it's anchored to bottom - self.tabPane.line:ClearAllPoints() - self.tabPane.line:SetPoint("BOTTOMLEFT", self.tabPane, "BOTTOMLEFT") - self.tabPane.line:SetPoint("BOTTOMRIGHT", self.tabPane, "BOTTOMRIGHT") - - local gap = self.inset * 2 - local anchorWidth = self.baseWidth - gap - self.tabAnchor = CUF:CreateFrame(nil, self.tabPane, anchorWidth, 1, true) - self.tabAnchor:SetPoint("TOPLEFT", self.tabPane, "BOTTOMLEFT", self.inset, -self.paneBuffer) - - self:InitTabs() - - hooksecurefunc(optionsFrame, "Hide", function() - self:HideMenu() - end) -end diff --git a/Menu/UnitFramesTab.lua b/Menu/UnitFramesTab.lua index 39da32c..ae2b500 100644 --- a/Menu/UnitFramesTab.lua +++ b/Menu/UnitFramesTab.lua @@ -3,11 +3,10 @@ local CUF = select(2, ...) local Cell = CUF.Cell local L = CUF.L -local F = Cell.funcs local Builder = CUF.Builder local Handler = CUF.Handler -local MenuWindow = CUF.MenuWindow +local Menu = CUF.Menu ---@class UnitsFramesTab: Menu.Tab ---@field unitPages table @@ -25,7 +24,7 @@ unitFramesTab.widgetHeight = 400 unitFramesTab.unitHeight = 180 unitFramesTab.paneHeight = 17 -MenuWindow:AddTab(unitFramesTab) +Menu:AddTab(unitFramesTab) ---@param unit Unit function unitFramesTab:SetUnitPage(unit) @@ -230,15 +229,15 @@ end function unitFramesTab:Create() CUF:Log("|cff00ccffCreate UnitFramesTab|r") - local inset = MenuWindow.inset + local inset = Menu.inset local windowHeight = self.unitHeight + self.widgetHeight + (self.paneHeight * 2) - local sectionWidth = MenuWindow.tabAnchor:GetWidth() + local sectionWidth = Menu.tabAnchor:GetWidth() - self.window = CUF:CreateFrame("CUF_Menu_UnitFrame", MenuWindow.window, + self.window = CUF:CreateFrame("CUF_Menu_UnitFrame", Menu.window, sectionWidth, windowHeight, true) - self.window:SetPoint("TOPLEFT", MenuWindow.tabAnchor, "TOPLEFT") + self.window:SetPoint("TOPLEFT", Menu.tabAnchor, "TOPLEFT") -- Unit Buttons self.unitPane = Cell:CreateTitledPane(self.window, L.UnitFrames, sectionWidth, From 15415e879f529f1d0390b0c2207cb24630f7fef8 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 11:33:00 +0200 Subject: [PATCH 04/28] ensure LoadLayoutDB is called when UnitFramesTab is opened --- Menu/UnitFramesTab.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Menu/UnitFramesTab.lua b/Menu/UnitFramesTab.lua index ae2b500..4f77d26 100644 --- a/Menu/UnitFramesTab.lua +++ b/Menu/UnitFramesTab.lua @@ -161,6 +161,8 @@ function unitFramesTab:ShowTab() return end + Menu:LoadLayoutDB(CUF.vars.selectedLayout) + self.window:Show() end From be7ba2e25cbf17eb240a7424af2ca0661da4acc4 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 11:42:36 +0200 Subject: [PATCH 05/28] show and hide selected tab when menu hides --- Menu/Menu.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Menu/Menu.lua b/Menu/Menu.lua index c10680c..ff8c40d 100644 --- a/Menu/Menu.lua +++ b/Menu/Menu.lua @@ -159,6 +159,8 @@ function menu:ShowMenu() end self.window:Show() + self.selectedTab:ShowTab() + CUF.vars.isMenuOpen = true end @@ -167,6 +169,7 @@ function menu:HideMenu() if not self.window or not self.window:IsShown() then return end CUF:Log("|cff00ccffHide Menu|r") self.window:Hide() + self.selectedTab:HideTab() CUF.vars.isMenuOpen = false Handler.UpdateSelected() From 98297c4266d978e027d3fe04409b13096c7d2f22 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 11:43:18 +0200 Subject: [PATCH 06/28] prevent ShowMenu running when menu is already shown --- Menu/Menu.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/Menu/Menu.lua b/Menu/Menu.lua index ff8c40d..e50e45c 100644 --- a/Menu/Menu.lua +++ b/Menu/Menu.lua @@ -144,6 +144,7 @@ end --- --- Initializes the menu if it hasn't been initialized yet function menu:ShowMenu() + if self.window and self.window:IsShown() then return end CUF:Log("|cff00ccffShow Menu|r") if not self.window then self:CreateMenu() From cdf04e0523458d7ce0984408a86a1d95cf4149b0 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 11:52:19 +0200 Subject: [PATCH 07/28] move Unit/Widget add fns into UnitFramesTab.lua --- Core/Init.lua | 1 + Menu/Menu.lua | 19 ------------------- Menu/UnitFramesTab.lua | 36 ++++++++++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Core/Init.lua b/Core/Init.lua index eb603d5..b63e553 100644 --- a/Core/Init.lua +++ b/Core/Init.lua @@ -30,5 +30,6 @@ CUF.Builder = {} ---@field testMode boolean ---@field isMenuOpen boolean ---@field isRetail boolean +---@field selectedTab string CUF.vars = {} CUF.unitButtons = {} diff --git a/Menu/Menu.lua b/Menu/Menu.lua index e50e45c..e2e40e0 100644 --- a/Menu/Menu.lua +++ b/Menu/Menu.lua @@ -14,15 +14,10 @@ local Handler = CUF.Handler ---@field tabsToAdd Menu.Tab[] ---@field tabButtons Menu.TabButton[] ---@field selectedTab Menu.Tab? ----@field selectedWidgetTable WidgetTable ----@field unitsToAdd table ----@field widgetsToAdd table local menu = {} menu.tabs = {} menu.tabsToAdd = {} -menu.unitsToAdd = {} menu.tabButtons = {} -menu.widgetsToAdd = {} menu.init = false menu.hookInit = false menu.baseWidth = 450 @@ -32,20 +27,6 @@ menu.inset = 5 CUF.Menu = menu ----@param unit function -function menu:AddUnit(unit) - --CUF:Log("Menu - AddUnit") - table.insert(self.unitsToAdd, unit) -end - ----@param widgetName WIDGET_KIND ----@param ... MenuOptions -function menu:AddWidget(widgetName, ...) - --CUF:Log("Menu - AddWidget") - table.insert(self.widgetsToAdd, - { ["widgetName"] = widgetName, ["options"] = { ... } }) -end - ------------------------------------------------- -- MARK: Update vars ------------------------------------------------- diff --git a/Menu/UnitFramesTab.lua b/Menu/UnitFramesTab.lua index 4f77d26..ed334ec 100644 --- a/Menu/UnitFramesTab.lua +++ b/Menu/UnitFramesTab.lua @@ -6,6 +6,8 @@ local L = CUF.L local Builder = CUF.Builder local Handler = CUF.Handler + +---@class CUF.Menu local Menu = CUF.Menu ---@class UnitsFramesTab: Menu.Tab @@ -13,19 +15,28 @@ local Menu = CUF.Menu ---@field unitPageButtons UnitMenuPageButton[] ---@field widgetPages table ---@field listButtons table +---@field selectedWidgetTable WidgetTable +---@field unitsToAdd table +---@field widgetsToAdd table local unitFramesTab = {} +unitFramesTab.id = "unitFramesTab" unitFramesTab.unitPages = {} -unitFramesTab.unitPageButtons = {} +unitFramesTab.unitsToAdd = {} unitFramesTab.widgetPages = {} unitFramesTab.listButtons = {} +unitFramesTab.widgetsToAdd = {} +unitFramesTab.unitPageButtons = {} unitFramesTab.firstWidgetInList = nil -unitFramesTab.id = "unitFramesTab" unitFramesTab.widgetHeight = 400 unitFramesTab.unitHeight = 180 unitFramesTab.paneHeight = 17 Menu:AddTab(unitFramesTab) +------------------------------------------------- +-- MARK: Setters +------------------------------------------------- + ---@param unit Unit function unitFramesTab:SetUnitPage(unit) -- Hide old unit @@ -73,7 +84,7 @@ function unitFramesTab:LoadWidgetList(unit) self.firstWidgetInList = nil -- The list is ordered by load order from .toc - for _, widgetPage in pairs(CUF.Menu.widgetsToAdd) do + for _, widgetPage in pairs(self.widgetsToAdd) do local widgetName = widgetPage.widgetName local widget = widgetTable[widgetName] @@ -184,7 +195,7 @@ function unitFramesTab:InitUnits() local prevAnchor local idx = 1 - for _, fn in pairs(CUF.Menu.unitsToAdd) do + for _, fn in pairs(self.unitsToAdd) do ---@type UnitsMenuPage local unit = fn(self) @@ -214,16 +225,25 @@ function unitFramesTab:InitUnits() end function unitFramesTab:InitWidgets() - --CUF:Log("menuWindow - InitWidgets") - - for _, widget in pairs(CUF.Menu.widgetsToAdd) do - ---@type WidgetMenuPage + for _, widget in pairs(self.widgetsToAdd) do local widgetPage = Builder:CreateWidgetMenuPage(self.settingsFrame, widget.widgetName, unpack(widget.options)) self.widgetPages[widgetPage.id] = widgetPage end end +---@param unit function +function Menu:AddUnit(unit) + table.insert(unitFramesTab.unitsToAdd, unit) +end + +---@param widgetName WIDGET_KIND +---@param ... MenuOptions +function Menu:AddWidget(widgetName, ...) + table.insert(unitFramesTab.widgetsToAdd, + { ["widgetName"] = widgetName, ["options"] = { ... } }) +end + ------------------------------------------------- -- MARK: Create ------------------------------------------------- From 806f13c2507b82fbb5efdf06399e4a78e5fcd64a Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 12:29:42 +0200 Subject: [PATCH 08/28] Limit when LoadPageDB runs --- Menu/Menu.lua | 1 - Menu/UnitFramesTab.lua | 1 + Util/Handler.lua | 7 +++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Menu/Menu.lua b/Menu/Menu.lua index e2e40e0..ae2c5a5 100644 --- a/Menu/Menu.lua +++ b/Menu/Menu.lua @@ -154,7 +154,6 @@ function menu:HideMenu() self.selectedTab:HideTab() CUF.vars.isMenuOpen = false - Handler.UpdateSelected() end ---@param which string diff --git a/Menu/UnitFramesTab.lua b/Menu/UnitFramesTab.lua index ed334ec..e783586 100644 --- a/Menu/UnitFramesTab.lua +++ b/Menu/UnitFramesTab.lua @@ -182,6 +182,7 @@ function unitFramesTab:HideTab() CUF:Log("|cff00ccffHide unitFramesTab|r") self.window:Hide() + -- Reset selected widget to hide previews Handler.UpdateSelected() end diff --git a/Util/Handler.lua b/Util/Handler.lua index 4074f85..004b3af 100644 --- a/Util/Handler.lua +++ b/Util/Handler.lua @@ -107,9 +107,16 @@ function Handler.UpdateSelected(selectedUnit, selectedWidget) end) end +--- Load the widget table for the selected unit and widget +--- +--- This is called when we selected a unit or widget in the menu. +--- Or when a layout is loaded. ---@param page Unit ---@param subPage WIDGET_KIND function Handler.LoadPageDB(page, subPage) + if not CUF.vars.isMenuOpen then return end + if CUF.vars.selectedTab ~= "unitFramesTab" then return end + -- Both params are only present when LoadLayoutDB is called if not page or not subPage then if (page and page == Handler.previousPage) From a7f771cfa42e2275d021cccee291eac13d987263 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 12:33:58 +0200 Subject: [PATCH 09/28] OnLoad hide blizzard frames based on CurrentLayoutTable instead of SelectedLayoutTable --- Core/OnLoad.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/OnLoad.lua b/Core/OnLoad.lua index 5a545cc..21d86f2 100644 --- a/Core/OnLoad.lua +++ b/Core/OnLoad.lua @@ -20,7 +20,7 @@ local function OnCellInitialUpdateLayout(_layout) -- Hide Blizzard Unit Frames for _, unit in pairs(CUF.constants.UNIT) do - if CUF.DB.SelectedLayoutTable()[unit].enabled then + if CUF.DB.CurrentLayoutTable()[unit].enabled then CUF:HideBlizzardUnitFrame(unit) end end From 45142dfe2da33c4fcce85bb2c05c7d7a625430dc Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 12:36:59 +0200 Subject: [PATCH 10/28] implement GeneralTab --- Cell_UnitFrames.toc | 1 + Locales/enUS.lua | 3 ++ Menu/GeneralTab.lua | 103 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 Menu/GeneralTab.lua diff --git a/Cell_UnitFrames.toc b/Cell_UnitFrames.toc index 3e1aabe..908d56f 100644 --- a/Cell_UnitFrames.toc +++ b/Cell_UnitFrames.toc @@ -35,6 +35,7 @@ Core/SlashCommands.lua Menu/Builder.lua Menu/AuraFilterList.lua Menu/Menu.lua +Menu/GeneralTab.lua Menu/UnitFramesTab.lua Widgets/Common.lua diff --git a/Locales/enUS.lua b/Locales/enUS.lua index 9b9b6d0..f5c0ca9 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -7,6 +7,9 @@ CUF.L = L -- Tabs L.unitFramesTab = "Unit Frames" +L.generalTab = "General" + +L.MasterLayout = "Master Layout" -- Units L.targettarget = "TargetTarget" diff --git a/Menu/GeneralTab.lua b/Menu/GeneralTab.lua new file mode 100644 index 0000000..59f75d3 --- /dev/null +++ b/Menu/GeneralTab.lua @@ -0,0 +1,103 @@ +---@class CUF +local CUF = select(2, ...) + +local Cell = CUF.Cell + +local L = CUF.L +local DB = CUF.DB + +local Menu = CUF.Menu + +---@class GeneralTab: Menu.Tab +local generalTab = {} +generalTab.id = "generalTab" +generalTab.height = 400 +generalTab.paneHeight = 17 + +Menu:AddTab(generalTab) + +function generalTab:IsShown() + return generalTab.window and generalTab.window:IsShown() +end + +------------------------------------------------- +-- MARK: Layout Profile +------------------------------------------------- + +---@class LayoutProfile: Frame +local layoutProfile = {} +layoutProfile.height = 100 + +function layoutProfile:SetLayoutItems() + if not generalTab:IsShown() then return end + --CUF:Log("|cff00ccffgeneralTab SetLayoutItems|r") + + local dropdownItems = {} + + for layoutName, _ in pairs(CellDB.layouts) do + tinsert(dropdownItems, { + ["text"] = L[layoutName], + ["value"] = layoutName, + ["onClick"] = function() + DB.SetMasterLayout(layoutName) + end, + }) + end + + layoutProfile.layoutDropdown:SetItems(dropdownItems) + layoutProfile.layoutDropdown:SetSelectedValue(DB.GetMasterLayout()) +end + +CUF:RegisterCallback("UpdateLayout", "CUF_LayoutProfile_SetLayoutItems", layoutProfile.SetLayoutItems) +CUF:RegisterCallback("LoadPageDB", "CUF_LayoutProfile_SetLayoutItems", layoutProfile.SetLayoutItems) + +function layoutProfile:CreateLayoutProfile() + CUF:Log("|cff00ccffgeneralTab CreateLayoutProfile|r") + + local sectionWidth = generalTab.window:GetWidth() / 2 + + local layoutPane = Cell:CreateTitledPane(generalTab.window, L.MasterLayout, sectionWidth, generalTab.paneHeight) + layoutPane:SetPoint("TOPLEFT") + + ---@type CellDropdown + self.layoutDropdown = Cell:CreateDropdown(generalTab.window, sectionWidth - 10) + self.layoutDropdown:SetPoint("TOPLEFT", layoutPane, "BOTTOMLEFT", 5, -10) +end + +------------------------------------------------- +-- MARK: Show/Hide +------------------------------------------------- + +function generalTab:ShowTab() + CUF:Log("|cff00ccffShow generalTab|r") + if not self.window then + self:Create() + self.init = true + end + + self.window:Show() + layoutProfile:SetLayoutItems() +end + +function generalTab:HideTab() + if not self.window or not self.window:IsShown() then return end + CUF:Log("|cff00ccffHide generalTab|r") + self.window:Hide() +end + +------------------------------------------------- +-- MARK: Create +------------------------------------------------- + +function generalTab:Create() + CUF:Log("|cff00ccffCreate generalTab|r") + + local sectionWidth = Menu.tabAnchor:GetWidth() + + self.window = CUF:CreateFrame("CUF_Menu_UnitFrame", Menu.window, + sectionWidth, + self.height, true) + self.window:SetPoint("TOPLEFT", Menu.tabAnchor, "TOPLEFT") + + layoutProfile:CreateLayoutProfile() +end From e8f85c74796e07d10dce8c80fb7b8fdf51a65c83 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 12:43:37 +0200 Subject: [PATCH 11/28] impl MasterLayout DB fns --- Data/DBUtil.lua | 22 ++++++++++++++++++++++ Data/Database.lua | 22 ++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Data/DBUtil.lua b/Data/DBUtil.lua index 60aaeee..ae40234 100644 --- a/Data/DBUtil.lua +++ b/Data/DBUtil.lua @@ -38,4 +38,26 @@ function DB.VerifyDB() end end end + + -- Make sure that we have a valid master layout + DB.VerifyMasterLayout() end + +function DB.VerifyMasterLayout() + local masterLayout = DB.GetMasterLayout() + local masterLayoutIsValid = false + + for layoutName, _ in pairs(CellDB.layouts) do + if layoutName == masterLayout then + masterLayoutIsValid = true + end + end + + if not masterLayoutIsValid then + CUF:Warn("Master layout is not valid, setting to default") + DB.SetMasterLayout("default") + end +end + +CUF:RegisterCallback("UpdateLayout", "CUF_VerifyMasterLayout", DB.VerifyMasterLayout) +CUF:RegisterCallback("LoadPageDB", "CUF_VerifyMasterLayout", DB.VerifyMasterLayout) diff --git a/Data/Database.lua b/Data/Database.lua index 1e79df9..1cb2892 100644 --- a/Data/Database.lua +++ b/Data/Database.lua @@ -5,7 +5,7 @@ local CUF = select(2, ...) local DB = CUF.DB ----------------------------------------- --- Getters +-- MARK: Layout Getters ----------------------------------------- -- Returns CUF UnitLayoutTable from CellDB @@ -65,7 +65,7 @@ function DB.GetAuraFilter(which, kind, unit, layout) end ----------------------------------------- --- Setters +-- MARK: Layout Setters ----------------------------------------- ---@param which "buffs"|"debuffs" @@ -76,3 +76,21 @@ end function DB.SetAuraFilter(which, kind, value, unit, layout) DB.GetAllWidgetTables(unit, layout)[which].filter[kind] = value end + +----------------------------------------- +-- MARK: General Getters +----------------------------------------- + +---@return string +function DB.GetMasterLayout() + return CUF_DB.masterLayout +end + +----------------------------------------- +-- MARK: General Setters +----------------------------------------- + +---@param layout string +function DB.SetMasterLayout(layout) + CUF_DB.masterLayout = layout +end From be3696a13de3cbf95613c5ffa0db0e20d7ae8cde Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 13:24:49 +0200 Subject: [PATCH 12/28] properly update widgetList --- Menu/UnitFramesTab.lua | 48 +++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/Menu/UnitFramesTab.lua b/Menu/UnitFramesTab.lua index e783586..613b1ac 100644 --- a/Menu/UnitFramesTab.lua +++ b/Menu/UnitFramesTab.lua @@ -37,6 +37,10 @@ Menu:AddTab(unitFramesTab) -- MARK: Setters ------------------------------------------------- +function unitFramesTab:IsShown() + return unitFramesTab.window and unitFramesTab.window:IsShown() +end + ---@param unit Unit function unitFramesTab:SetUnitPage(unit) -- Hide old unit @@ -47,7 +51,7 @@ function unitFramesTab:SetUnitPage(unit) self.selectedUnitPage = self.unitPages[unit] self.selectedUnitPage.frame:Show() - self:LoadWidgetList(unit) + self.LoadWidgetList(unit) CUF.Menu:UpdateSelectedPages(unit) end @@ -75,27 +79,30 @@ function unitFramesTab:SetWidget(widget) end ---@param unit Unit -function unitFramesTab:LoadWidgetList(unit) - self.widgetListFrame.scrollFrame:Reset() +function unitFramesTab.LoadWidgetList(unit) + if not unitFramesTab:IsShown() then return end + + unitFramesTab.widgetListFrame.scrollFrame:Reset() local optionCount = 0 local widgetTable = CUF.DB.GetAllWidgetTables(unit) local prevButton - self.firstWidgetInList = nil + unitFramesTab.firstWidgetInList = nil -- The list is ordered by load order from .toc - for _, widgetPage in pairs(self.widgetsToAdd) do + for _, widgetPage in pairs(unitFramesTab.widgetsToAdd) do local widgetName = widgetPage.widgetName local widget = widgetTable[widgetName] if widget then - if not self.listButtons[widgetName] then - self.listButtons[widgetName] = CUF:CreateButton(self.widgetListFrame.scrollFrame.content, " ", + if not unitFramesTab.listButtons[widgetName] then + unitFramesTab.listButtons[widgetName] = CUF:CreateButton( + unitFramesTab.widgetListFrame.scrollFrame.content, " ", { 20, 20 }, nil, "transparent-accent") end ---@class WidgetMenuPageButton: CellButton - local button = self.listButtons[widgetName] + local button = unitFramesTab.listButtons[widgetName] button:SetText(L[widgetName]) button:GetFontString():ClearAllPoints() button:GetFontString():SetPoint("LEFT", 5, 0) @@ -110,7 +117,7 @@ function unitFramesTab:LoadWidgetList(unit) button:SetTextColor(0.466, 0.466, 0.466, 1) end - button:SetParent(self.widgetListFrame.scrollFrame.content) + button:SetParent(unitFramesTab.widgetListFrame.scrollFrame.content) button:SetPoint("RIGHT") if not prevButton then button:SetPoint("TOPLEFT") @@ -120,30 +127,33 @@ function unitFramesTab:LoadWidgetList(unit) button:Show() prevButton = button - if not self.firstWidgetInList then - self.firstWidgetInList = widgetName + if not unitFramesTab.firstWidgetInList then + unitFramesTab.firstWidgetInList = widgetName end end end - self.widgetListFrame.scrollFrame:SetContentHeight(20, optionCount, -1) + unitFramesTab.widgetListFrame.scrollFrame:SetContentHeight(20, optionCount, -1) - Cell:CreateButtonGroup(self.listButtons, function(widget, b) - self:SetWidget(widget) + Cell:CreateButtonGroup(unitFramesTab.listButtons, function(widget, b) + unitFramesTab:SetWidget(widget) end) -- Make sure that the currently selected widget is valid - if self.selectedWidget then - if not widgetTable[self.selectedWidget.id] then - self.listButtons[self.firstWidgetInList]:Click() + if unitFramesTab.selectedWidget then + if not widgetTable[unitFramesTab.selectedWidget.id] then + unitFramesTab.listButtons[unitFramesTab.firstWidgetInList]:Click() end end end +CUF:RegisterCallback("LoadPageDB", "unitFramesTab_LoadWidgetList", unitFramesTab.LoadWidgetList) + ---@param layout string? ---@param unit Unit? ---@param widgetName WIDGET_KIND? function unitFramesTab.UpdateWidgetListEnabled(layout, unit, widgetName, setting) + if not unitFramesTab:IsShown() then return end if not widgetName then return end if not setting == CUF.constants.OPTION_KIND.ENABLED then return end if not unitFramesTab.listButtons[widgetName] then return end @@ -155,7 +165,7 @@ function unitFramesTab.UpdateWidgetListEnabled(layout, unit, widgetName, setting end end -CUF:RegisterCallback("UpdateWidget", "UpdateWidgetListEnabled", unitFramesTab.UpdateWidgetListEnabled) +CUF:RegisterCallback("UpdateWidget", "unitFramesTab_UpdateWidgetListEnabled", unitFramesTab.UpdateWidgetListEnabled) function unitFramesTab:ShowTab() CUF:Log("|cff00ccffShow unitFramesTab|r") @@ -178,7 +188,7 @@ function unitFramesTab:ShowTab() end function unitFramesTab:HideTab() - if not self.window or not self.window:IsShown() then return end + if not unitFramesTab:IsShown() then return end CUF:Log("|cff00ccffHide unitFramesTab|r") self.window:Hide() From 5f2c970f92692ddb974af451b0109fe1fbd56616 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 14:05:03 +0200 Subject: [PATCH 13/28] use masterLayout for widgets profile --- Core/OnLoad.lua | 2 +- Data/Database.lua | 45 +++++++++++++++++++++--------------- Debug/Debug.lua | 2 +- Menu/Builder.lua | 18 +++++++-------- Menu/UnitFramesTab.lua | 4 ++-- Util/Handler.lua | 4 ++-- Widgets/Auras/Updater.lua | 2 +- Widgets/Bars/CastBar.lua | 2 +- Widgets/Bars/ShieldBar.lua | 2 +- Widgets/Texts/HealthText.lua | 2 +- Widgets/Texts/NameText.lua | 2 +- Widgets/Texts/PowerText.lua | 2 +- 12 files changed, 48 insertions(+), 39 deletions(-) diff --git a/Core/OnLoad.lua b/Core/OnLoad.lua index 21d86f2..da0ca53 100644 --- a/Core/OnLoad.lua +++ b/Core/OnLoad.lua @@ -52,7 +52,7 @@ local function OnCellInitialUpdateLayout(_layout) function(kind) CUF:Fire("UpdateAppearance", kind) end) -- Init widgets - CUF:Fire("UpdateWidget", CUF.vars.selectedLayout) + CUF:Fire("UpdateWidget", CUF.DB.GetMasterLayout()) Cell:UnregisterCallback("UpdateLayout", "CUF_Initial_UpdateLayout") end diff --git a/Data/Database.lua b/Data/Database.lua index 1cb2892..c55c297 100644 --- a/Data/Database.lua +++ b/Data/Database.lua @@ -34,34 +34,44 @@ function DB.SelectedLayoutTable() return DB.GetLayoutTable(CUF.vars.selectedLayout) end --- Returns active layout table ----@return UnitLayoutTable -function DB.CurrentLayoutTable() - return DB.GetLayoutTable(Cell.vars.currentLayout) -end - ---@param unit Unit? ----@param layout string? ---@return WidgetTables -function DB.GetAllWidgetTables(unit, layout) - return DB.GetUnit(layout or CUF.vars.selectedLayout, unit or CUF.vars.selectedUnit).widgets +function DB.GetSelectedWidgetTables(unit) + return DB.GetUnit(CUF.vars.selectedLayout, unit or CUF.vars.selectedUnit).widgets end ---@param which WIDGET_KIND ---@param unit Unit? ----@param layout string? ---@return WidgetTable -function DB.GetWidgetTable(which, unit, layout) - return DB.GetAllWidgetTables(unit, layout)[which] +function DB.GetSelectedWidgetTable(which, unit) + return DB.GetSelectedWidgetTables(unit)[which] end ---@param which "buffs"|"debuffs" ---@param kind "blacklist"|"whitelist" ---@param unit Unit? ----@param layout string? ---@return table -function DB.GetAuraFilter(which, kind, unit, layout) - return DB.GetAllWidgetTables(unit, layout)[which].filter[kind] +function DB.GetAuraFilter(which, kind, unit) + return DB.GetSelectedWidgetTables(unit)[which].filter[kind] +end + +-- Returns active layout table +---@return UnitLayoutTable +function DB.CurrentLayoutTable() + return DB.GetLayoutTable(DB.GetMasterLayout()) +end + +---@param unit Unit +---@return WidgetTables +function DB.GetCurrentWidgetTables(unit) + return DB.CurrentLayoutTable()[unit].widgets +end + +---@param which WIDGET_KIND +---@param unit Unit +---@return WidgetTable +function DB.GetCurrentWidgetTable(which, unit) + return DB.GetCurrentWidgetTables(unit)[which] end ----------------------------------------- @@ -72,9 +82,8 @@ end ---@param kind "blacklist"|"whitelist" ---@param value table ---@param unit Unit? ----@param layout string? -function DB.SetAuraFilter(which, kind, value, unit, layout) - DB.GetAllWidgetTables(unit, layout)[which].filter[kind] = value +function DB.SetAuraFilter(which, kind, value, unit) + DB.GetSelectedWidgetTables(unit)[which].filter[kind] = value end ----------------------------------------- diff --git a/Debug/Debug.lua b/Debug/Debug.lua index 35df1e5..7882e79 100644 --- a/Debug/Debug.lua +++ b/Debug/Debug.lua @@ -18,7 +18,7 @@ function Debug:InitDebugWindow() self.window:AddVar( "selectedLayoutTable", function() CUF:DevAdd(CUF.DB.SelectedLayoutTable(), "selectedLayoutTable") end) self.window:AddVar("selectedWidgetTable", - function() CUF:DevAdd(CUF.DB.GetAllWidgetTables(), "selectedWidgetTable") end) + function() CUF:DevAdd(CUF.DB.GetSelectedWidgetTables(), "selectedWidgetTable") end) self.window:AddVar("CUF.vars", function() CUF:DevAdd(CUF.vars, "CUF.vars") end) self.window:AddVar("CUF_DB", function() CUF:DevAdd(CUF_DB, "CUF_DB") end) self.window:AddVar("Buttons", function() CUF:DevAdd(CUF.unitButtons, "unitButtons") end) diff --git a/Menu/Builder.lua b/Menu/Builder.lua index 2304268..2b87932 100644 --- a/Menu/Builder.lua +++ b/Menu/Builder.lua @@ -185,7 +185,7 @@ end ---@param optionPath string ---@param newValue any local function HandleWidgetOption(widgetName, optionPath, newValue) - local widgetTable = DB.GetWidgetTable(widgetName) + local widgetTable = DB.GetSelectedWidgetTable(widgetName) local function traversePath(tbl, pathParts, value) for i = 1, #pathParts - 1 do @@ -617,7 +617,7 @@ function Builder:CreateTextColorOptions(parent, widgetName, includePowerType) f.dropdown.Set_DB = function(...) HandleWidgetOption(...) - if DB.GetWidgetTable(widgetName).color.type == const.ColorType.CUSTOM then + if DB.GetSelectedWidgetTable(widgetName).color.type == const.ColorType.CUSTOM then f.colorPicker:Show() else f.colorPicker:Hide() @@ -631,7 +631,7 @@ function Builder:CreateTextColorOptions(parent, widgetName, includePowerType) local function LoadPageDB() f.colorPicker:SetColor(unpack(HandleWidgetOption(widgetName, "color.rgb"))) - if DB.GetWidgetTable(widgetName).color.type == const.ColorType.CUSTOM then + if DB.GetSelectedWidgetTable(widgetName).color.type == const.ColorType.CUSTOM then f.colorPicker:Show() else f.colorPicker:Hide() @@ -1186,16 +1186,16 @@ function Builder:CreateAuraFontOptions(parent, widgetName, kind) self:AnchorBelow(f.fontOptions.shadowCB, f.fontOptions.outlineDropdown) f.colorPicker = Cell:CreateColorPicker(f, L["Color"], false, function(r, g, b, a) - DB.GetWidgetTable(widgetName).font[kind].rgb[1] = r - DB.GetWidgetTable(widgetName).font[kind].rgb[2] = g - DB.GetWidgetTable(widgetName).font[kind].rgb[3] = b + DB.GetSelectedWidgetTable(widgetName).font[kind].rgb[1] = r + DB.GetSelectedWidgetTable(widgetName).font[kind].rgb[2] = g + DB.GetSelectedWidgetTable(widgetName).font[kind].rgb[3] = b end) self:AnchorBelow(f.colorPicker, f.fontOptions.sizeSlider) local function LoadPageDB() - f.colorPicker:SetColor(DB.GetWidgetTable(widgetName).font[kind].rgb[1], - DB.GetWidgetTable(widgetName).font[kind].rgb[2], - DB.GetWidgetTable(widgetName).font[kind].rgb[3]) + f.colorPicker:SetColor(DB.GetSelectedWidgetTable(widgetName).font[kind].rgb[1], + DB.GetSelectedWidgetTable(widgetName).font[kind].rgb[2], + DB.GetSelectedWidgetTable(widgetName).font[kind].rgb[3]) end Handler:RegisterOption(LoadPageDB, widgetName, "CheckBox") diff --git a/Menu/UnitFramesTab.lua b/Menu/UnitFramesTab.lua index 613b1ac..f1aece2 100644 --- a/Menu/UnitFramesTab.lua +++ b/Menu/UnitFramesTab.lua @@ -85,7 +85,7 @@ function unitFramesTab.LoadWidgetList(unit) unitFramesTab.widgetListFrame.scrollFrame:Reset() local optionCount = 0 - local widgetTable = CUF.DB.GetAllWidgetTables(unit) + local widgetTable = CUF.DB.GetSelectedWidgetTables(unit) local prevButton unitFramesTab.firstWidgetInList = nil @@ -158,7 +158,7 @@ function unitFramesTab.UpdateWidgetListEnabled(layout, unit, widgetName, setting if not setting == CUF.constants.OPTION_KIND.ENABLED then return end if not unitFramesTab.listButtons[widgetName] then return end - if CUF.DB.GetWidgetTable(widgetName, unit, layout).enabled then + if CUF.DB.GetSelectedWidgetTable(widgetName, unit).enabled then unitFramesTab.listButtons[widgetName]:SetTextColor(1, 1, 1, 1) else unitFramesTab.listButtons[widgetName]:SetTextColor(0.466, 0.466, 0.466, 1) diff --git a/Util/Handler.lua b/Util/Handler.lua index 004b3af..4e785aa 100644 --- a/Util/Handler.lua +++ b/Util/Handler.lua @@ -29,7 +29,7 @@ local function IterateGenericSetters(button, unit, widgetName, setting, subSetti if not button:HasWidget(widgetName) then return end local widget = button.widgets[widgetName] ---@type Widget - local styleTable = DB.GetWidgetTable(widgetName, unit) + local styleTable = DB.GetCurrentWidgetTable(widgetName, unit) if (not setting or setting == "enabled") and type(widget.SetEnabled) == "function" then widget:SetEnabled(styleTable) @@ -60,7 +60,7 @@ end function Handler.UpdateWidgets(layout, unit, widgetName, setting, ...) CUF:Log("|cffff7777UpdateWidgets:|r", layout, unit, widgetName, setting, ...) - if layout and layout ~= Cell.vars.currentLayout then return end + if layout and layout ~= DB.GetMasterLayout() then return end for name, func in pairs(Handler.widgets) do if not widgetName or name == widgetName then diff --git a/Widgets/Auras/Updater.lua b/Widgets/Auras/Updater.lua index e8ab7dc..46cd4f7 100644 --- a/Widgets/Auras/Updater.lua +++ b/Widgets/Auras/Updater.lua @@ -20,7 +20,7 @@ function W.UpdateAuraWidget(button, unit, which, setting, subSetting, ...) ---@type CellAuraIcons local auras = button.widgets[which] - local styleTable = DB.GetWidgetTable(which, unit) --[[@as AuraWidgetTable]] + local styleTable = DB.GetSelectedWidgetTable(which, unit) --[[@as AuraWidgetTable]] if not setting or setting == const.AURA_OPTION_KIND.FONT or const.AURA_OPTION_KIND.POSITION then auras:SetFont(styleTable.font) diff --git a/Widgets/Bars/CastBar.lua b/Widgets/Bars/CastBar.lua index 6bd5bdc..5bb90de 100644 --- a/Widgets/Bars/CastBar.lua +++ b/Widgets/Bars/CastBar.lua @@ -35,7 +35,7 @@ menu:AddWidget(const.WIDGET_KIND.CAST_BAR, ---@param subSetting string function W.UpdateCastBarWidget(button, unit, setting, subSetting, ...) local castBar = button.widgets.castBar - local styleTable = DB.GetWidgetTable(const.WIDGET_KIND.CAST_BAR, unit) + local styleTable = DB.GetCurrentWidgetTable(const.WIDGET_KIND.CAST_BAR, unit) if not setting or setting == const.OPTION_KIND.COLOR then if not subSetting or subSetting == const.OPTION_KIND.TEXTURE then diff --git a/Widgets/Bars/ShieldBar.lua b/Widgets/Bars/ShieldBar.lua index b439f5a..4b6bb25 100644 --- a/Widgets/Bars/ShieldBar.lua +++ b/Widgets/Bars/ShieldBar.lua @@ -32,7 +32,7 @@ menu:AddWidget(const.WIDGET_KIND.SHIELD_BAR, ---@param subSetting string function W.UpdateShieldBarWidget(button, unit, setting, subSetting, ...) local widget = button.widgets.shieldBar - local styleTable = DB.GetWidgetTable(const.WIDGET_KIND.SHIELD_BAR, unit) --[[@as ShieldBarWidgetTable]] + local styleTable = DB.GetSelectedWidgetTable(const.WIDGET_KIND.SHIELD_BAR, unit) --[[@as ShieldBarWidgetTable]] if not setting or setting == const.OPTION_KIND.RGBA then widget:SetColor(unpack(styleTable.rgba)) diff --git a/Widgets/Texts/HealthText.lua b/Widgets/Texts/HealthText.lua index b601fcc..d98b3f5 100644 --- a/Widgets/Texts/HealthText.lua +++ b/Widgets/Texts/HealthText.lua @@ -36,7 +36,7 @@ menu:AddWidget(const.WIDGET_KIND.HEALTH_TEXT, ---@param subSetting string function W.UpdateHealthTextWidget(button, unit, setting, subSetting, ...) local widget = button.widgets.healthText - local styleTable = DB.GetWidgetTable(const.WIDGET_KIND.HEALTH_TEXT, unit) --[[@as HealthTextWidgetTable]] + local styleTable = DB.GetSelectedWidgetTable(const.WIDGET_KIND.HEALTH_TEXT, unit) --[[@as HealthTextWidgetTable]] if not setting or setting == const.OPTION_KIND.FORMAT then widget:SetFormat(styleTable.format) diff --git a/Widgets/Texts/NameText.lua b/Widgets/Texts/NameText.lua index cd87207..01b53aa 100644 --- a/Widgets/Texts/NameText.lua +++ b/Widgets/Texts/NameText.lua @@ -39,7 +39,7 @@ menu:AddWidget(const.WIDGET_KIND.NAME_TEXT, ---@param subSetting string function W.UpdateNameTextWidget(button, unit, setting, subSetting) local widget = button.widgets.nameText - local styleTable = DB.GetWidgetTable(const.WIDGET_KIND.NAME_TEXT, unit) --[[@as NameTextWidgetTable]] + local styleTable = DB.GetCurrentWidgetTable(const.WIDGET_KIND.NAME_TEXT, unit) --[[@as NameTextWidgetTable]] if not setting or setting == const.OPTION_KIND.WIDTH then widget.width = styleTable.width diff --git a/Widgets/Texts/PowerText.lua b/Widgets/Texts/PowerText.lua index a68f7ab..082f21e 100644 --- a/Widgets/Texts/PowerText.lua +++ b/Widgets/Texts/PowerText.lua @@ -36,7 +36,7 @@ menu:AddWidget(const.WIDGET_KIND.POWER_TEXT, ---@param subSetting string function W.UpdatePowerTextWidget(button, unit, setting, subSetting) local widget = button.widgets.powerText - local styleTable = DB.GetWidgetTable(const.WIDGET_KIND.POWER_TEXT, unit) --[[@as PowerTextWidgetTable]] + local styleTable = DB.GetCurrentWidgetTable(const.WIDGET_KIND.POWER_TEXT, unit) --[[@as PowerTextWidgetTable]] if not setting or setting == const.OPTION_KIND.FORMAT then widget:SetFormat(styleTable.format) From 2b8c4a6e27ad42701e8d63b268ccf9791267d635 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 14:17:18 +0200 Subject: [PATCH 14/28] update layout when changing master layout --- Menu/GeneralTab.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Menu/GeneralTab.lua b/Menu/GeneralTab.lua index 59f75d3..5d9d5dc 100644 --- a/Menu/GeneralTab.lua +++ b/Menu/GeneralTab.lua @@ -40,6 +40,8 @@ function layoutProfile:SetLayoutItems() ["value"] = layoutName, ["onClick"] = function() DB.SetMasterLayout(layoutName) + CUF:Fire("UpdateUnitButtons") + CUF:Fire("UpdateWidget", layoutName) end, }) end From cb78bdb4d4d3a5697e4186d4933ff3444b199c79 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 14:17:44 +0200 Subject: [PATCH 15/28] check against master layout when updating unit button layout --- UnitFrames/MenuOptions.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/UnitFrames/MenuOptions.lua b/UnitFrames/MenuOptions.lua index 59e6603..98e64fb 100644 --- a/UnitFrames/MenuOptions.lua +++ b/UnitFrames/MenuOptions.lua @@ -5,13 +5,13 @@ local Cell = CUF.Cell local L = CUF.L local function UpdateSize() - if CUF.vars.selectedLayout == Cell.vars.currentLayout then + if CUF.vars.selectedLayout == CUF.DB.GetMasterLayout() then CUF:Fire("UpdateLayout", CUF.vars.selectedLayout, CUF.vars.selectedUnit .. "-size") end end local function UpdateArrangement() - if CUF.vars.selectedLayout == Cell.vars.currentLayout then + if CUF.vars.selectedLayout == CUF.DB.GetMasterLayout() then CUF:Fire("UpdateLayout", CUF.vars.selectedLayout, CUF.vars.selectedUnit .. "-arrangement") end end @@ -82,7 +82,7 @@ local function AddUnitsToMenu() .Frame, function(checked) CUF.DB.SelectedLayoutTable()[unit].enabled = checked - if CUF.vars.selectedLayout == Cell.vars.currentLayout then + if CUF.vars.selectedLayout == CUF.DB.GetMasterLayout() then CUF:Fire("UpdateLayout", CUF.vars.selectedLayout, unit) end CUF:Fire("UpdateVisibility", unit) @@ -103,7 +103,7 @@ local function AddUnitsToMenu() -- update size and power UpdateSize() - if CUF.vars.selectedLayout == Cell.vars.currentLayout then + if CUF.vars.selectedLayout == CUF.DB.GetMasterLayout() then CUF:Fire("UpdateLayout", CUF.vars.selectedLayout, unit .. "-power") end end) @@ -128,7 +128,7 @@ local function AddUnitsToMenu() unitPage.powerSizeSlider = Cell:CreateSlider(L["Power Size"], unitPage.frame, 0, 100, 117, 1, function(value) CUF.DB.SelectedLayoutTable()[unit].powerSize = value - if CUF.vars.selectedLayout == Cell.vars.currentLayout then + if CUF.vars.selectedLayout == CUF.DB.GetMasterLayout() then CUF:Fire("UpdateLayout", CUF.vars.selectedLayout, unit .. "-power") end end) From 30166f3f44704553b9787525425ad3b4d139eb10 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 15:33:47 +0200 Subject: [PATCH 16/28] get raw value of masterlayout when determining which to use --- Data/DBUtil.lua | 4 +++- Data/Database.lua | 8 +++++++- Locales/enUS.lua | 1 + Menu/GeneralTab.lua | 12 ++++++++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Data/DBUtil.lua b/Data/DBUtil.lua index ae40234..0a6a564 100644 --- a/Data/DBUtil.lua +++ b/Data/DBUtil.lua @@ -44,7 +44,9 @@ function DB.VerifyDB() end function DB.VerifyMasterLayout() - local masterLayout = DB.GetMasterLayout() + local masterLayout = DB.GetMasterLayout(true) + if masterLayout == "CUFLayoutMasterNone" then return end + local masterLayoutIsValid = false for layoutName, _ in pairs(CellDB.layouts) do diff --git a/Data/Database.lua b/Data/Database.lua index c55c297..9a5ba32 100644 --- a/Data/Database.lua +++ b/Data/Database.lua @@ -90,8 +90,14 @@ end -- MARK: General Getters ----------------------------------------- +---@param rawValue boolean? ---@return string -function DB.GetMasterLayout() +function DB.GetMasterLayout(rawValue) + local layout = CUF_DB.masterLayout + if layout == "CUFLayoutMasterNone" and not rawValue then + return Cell.vars.currentLayout + end + return CUF_DB.masterLayout end diff --git a/Locales/enUS.lua b/Locales/enUS.lua index f5c0ca9..a2edff2 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -104,6 +104,7 @@ L.RelativeTo = "Relative To" L.Texture = "Texture" L["left"] = "Left" L["right"] = "Right" +L.CUFLayoutMasterNone = "None" -- Custom Formats L.ValidTags = "Valid Tags" diff --git a/Menu/GeneralTab.lua b/Menu/GeneralTab.lua index 5d9d5dc..c2d2c5a 100644 --- a/Menu/GeneralTab.lua +++ b/Menu/GeneralTab.lua @@ -32,7 +32,15 @@ function layoutProfile:SetLayoutItems() if not generalTab:IsShown() then return end --CUF:Log("|cff00ccffgeneralTab SetLayoutItems|r") - local dropdownItems = {} + local dropdownItems = { { + ["text"] = L.CUFLayoutMasterNone, + ["value"] = "CUFLayoutMasterNone", + ["onClick"] = function() + DB.SetMasterLayout("CUFLayoutMasterNone") + CUF:Fire("UpdateUnitButtons") + CUF:Fire("UpdateWidget", Cell.vars.currentLayout) + end, + } } for layoutName, _ in pairs(CellDB.layouts) do tinsert(dropdownItems, { @@ -47,7 +55,7 @@ function layoutProfile:SetLayoutItems() end layoutProfile.layoutDropdown:SetItems(dropdownItems) - layoutProfile.layoutDropdown:SetSelectedValue(DB.GetMasterLayout()) + layoutProfile.layoutDropdown:SetSelectedValue(DB.GetMasterLayout(true)) end CUF:RegisterCallback("UpdateLayout", "CUF_LayoutProfile_SetLayoutItems", layoutProfile.SetLayoutItems) From 36156d97ce2c7e3eb2f36782bc01878a0ba55614 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 15:51:39 +0200 Subject: [PATCH 17/28] change remaining widget updates to use current widget table --- Widgets/Auras/Updater.lua | 2 +- Widgets/Bars/ShieldBar.lua | 2 +- Widgets/Texts/HealthText.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Widgets/Auras/Updater.lua b/Widgets/Auras/Updater.lua index 46cd4f7..0a7abf9 100644 --- a/Widgets/Auras/Updater.lua +++ b/Widgets/Auras/Updater.lua @@ -20,7 +20,7 @@ function W.UpdateAuraWidget(button, unit, which, setting, subSetting, ...) ---@type CellAuraIcons local auras = button.widgets[which] - local styleTable = DB.GetSelectedWidgetTable(which, unit) --[[@as AuraWidgetTable]] + local styleTable = DB.GetCurrentWidgetTable(which, unit) --[[@as AuraWidgetTable]] if not setting or setting == const.AURA_OPTION_KIND.FONT or const.AURA_OPTION_KIND.POSITION then auras:SetFont(styleTable.font) diff --git a/Widgets/Bars/ShieldBar.lua b/Widgets/Bars/ShieldBar.lua index 4b6bb25..4b3e409 100644 --- a/Widgets/Bars/ShieldBar.lua +++ b/Widgets/Bars/ShieldBar.lua @@ -32,7 +32,7 @@ menu:AddWidget(const.WIDGET_KIND.SHIELD_BAR, ---@param subSetting string function W.UpdateShieldBarWidget(button, unit, setting, subSetting, ...) local widget = button.widgets.shieldBar - local styleTable = DB.GetSelectedWidgetTable(const.WIDGET_KIND.SHIELD_BAR, unit) --[[@as ShieldBarWidgetTable]] + local styleTable = DB.GetCurrentWidgetTable(const.WIDGET_KIND.SHIELD_BAR, unit) --[[@as ShieldBarWidgetTable]] if not setting or setting == const.OPTION_KIND.RGBA then widget:SetColor(unpack(styleTable.rgba)) diff --git a/Widgets/Texts/HealthText.lua b/Widgets/Texts/HealthText.lua index d98b3f5..6980234 100644 --- a/Widgets/Texts/HealthText.lua +++ b/Widgets/Texts/HealthText.lua @@ -36,7 +36,7 @@ menu:AddWidget(const.WIDGET_KIND.HEALTH_TEXT, ---@param subSetting string function W.UpdateHealthTextWidget(button, unit, setting, subSetting, ...) local widget = button.widgets.healthText - local styleTable = DB.GetSelectedWidgetTable(const.WIDGET_KIND.HEALTH_TEXT, unit) --[[@as HealthTextWidgetTable]] + local styleTable = DB.GetCurrentWidgetTable(const.WIDGET_KIND.HEALTH_TEXT, unit) --[[@as HealthTextWidgetTable]] if not setting or setting == const.OPTION_KIND.FORMAT then widget:SetFormat(styleTable.format) From f10976073ce47cec34ac89d02605f82afa0ea681 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 15:59:30 +0200 Subject: [PATCH 18/28] update annotation for IterateAllUnitButtons --- Util/Handler.lua | 1 - Util/Utils.lua | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Util/Handler.lua b/Util/Handler.lua index 4e785aa..f683091 100644 --- a/Util/Handler.lua +++ b/Util/Handler.lua @@ -95,7 +95,6 @@ end function Handler.UpdateSelected(selectedUnit, selectedWidget) CUF:Log("|cffff7777Handler.UpdateSelected:|r", selectedUnit, selectedWidget, CUF.vars.isMenuOpen) Util:IterateAllUnitButtons( - ---@param button CUFUnitButton function(button) button._isSelected = button.states.unit == selectedUnit and CUF.vars.isMenuOpen for _, widget in pairs(const.WIDGET_KIND) do diff --git a/Util/Utils.lua b/Util/Utils.lua index 667ae83..8ea9020 100644 --- a/Util/Utils.lua +++ b/Util/Utils.lua @@ -79,7 +79,7 @@ end -- MARK: IterateAllUnitButtons ------------------------------------------------- ----@param func function +---@param func fun(button: CUFUnitButton, unit: string, ...) ---@param unitToIterate string? function Util:IterateAllUnitButtons(func, unitToIterate, ...) for _, unit in pairs(CUF.constants.UNIT) do From 4bc207f820da8ed1b20790d20b9c708402ed9769 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 16:56:00 +0200 Subject: [PATCH 19/28] add tooltip for master layout --- Locales/enUS.lua | 5 ++++- Menu/GeneralTab.lua | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Locales/enUS.lua b/Locales/enUS.lua index a2edff2..32d5137 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -10,6 +10,10 @@ L.unitFramesTab = "Unit Frames" L.generalTab = "General" L.MasterLayout = "Master Layout" +L.CUFLayoutMasterNone = "|cffffb5c5None|r" +L.MasterLayoutTooltip = [[The layout to use for |cFFFFD700Cell UnitFrames|r. + +Selecting |cffffb5c5None|r will use the currently active layout in |cFFFFD700Cell|r.]] -- Units L.targettarget = "TargetTarget" @@ -104,7 +108,6 @@ L.RelativeTo = "Relative To" L.Texture = "Texture" L["left"] = "Left" L["right"] = "Right" -L.CUFLayoutMasterNone = "None" -- Custom Formats L.ValidTags = "Valid Tags" diff --git a/Menu/GeneralTab.lua b/Menu/GeneralTab.lua index c2d2c5a..771d884 100644 --- a/Menu/GeneralTab.lua +++ b/Menu/GeneralTab.lua @@ -44,7 +44,8 @@ function layoutProfile:SetLayoutItems() for layoutName, _ in pairs(CellDB.layouts) do tinsert(dropdownItems, { - ["text"] = L[layoutName], + ---@diagnostic disable-next-line: undefined-field + ["text"] = layoutName == "default" and _G.DEFAULT or layoutName, ["value"] = layoutName, ["onClick"] = function() DB.SetMasterLayout(layoutName) @@ -56,6 +57,7 @@ function layoutProfile:SetLayoutItems() layoutProfile.layoutDropdown:SetItems(dropdownItems) layoutProfile.layoutDropdown:SetSelectedValue(DB.GetMasterLayout(true)) + Cell:SetTooltips(layoutProfile.layoutDropdown, "ANCHOR_TOPLEFT", 0, 3, L.MasterLayout, L.MasterLayoutTooltip) end CUF:RegisterCallback("UpdateLayout", "CUF_LayoutProfile_SetLayoutItems", layoutProfile.SetLayoutItems) From ec7ec8182b824780ee5e80171bea341f0b11b759 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 16:56:15 +0200 Subject: [PATCH 20/28] update tab buttons positioning --- Menu/Menu.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Menu/Menu.lua b/Menu/Menu.lua index ae2c5a5..a91f8d4 100644 --- a/Menu/Menu.lua +++ b/Menu/Menu.lua @@ -104,11 +104,11 @@ function menu:InitTabs() self.window:SetHeight(self.window:GetHeight() + self.paneHeight) self.tabPane:SetHeight(self.tabPane:GetHeight() + self.paneHeight) else - tabButton:SetPoint("TOPLEFT", prevButton, "TOPRIGHT", 1) + tabButton:SetPoint("TOPLEFT", prevButton, "TOPRIGHT", -1, 0) idx = idx + 1 end else - tabButton:SetPoint("BOTTOMLEFT", self.tabPane, "BOTTOMLEFT", 0, 1) + tabButton:SetPoint("BOTTOMLEFT", self.tabPane, "BOTTOMLEFT", 0, 0) prevAnchor = tabButton end prevButton = tabButton From 2d3abd8d536a441b49379d75bcd8923128ea6f65 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 16:59:51 +0200 Subject: [PATCH 21/28] only set widget as selected when in correct layout --- Util/Handler.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Util/Handler.lua b/Util/Handler.lua index f683091..c2a75d3 100644 --- a/Util/Handler.lua +++ b/Util/Handler.lua @@ -94,12 +94,13 @@ end ---@param selectedWidget WIDGET_KIND? function Handler.UpdateSelected(selectedUnit, selectedWidget) CUF:Log("|cffff7777Handler.UpdateSelected:|r", selectedUnit, selectedWidget, CUF.vars.isMenuOpen) + local isCorrectLayout = CUF.vars.selectedLayout == DB.GetMasterLayout() Util:IterateAllUnitButtons( function(button) button._isSelected = button.states.unit == selectedUnit and CUF.vars.isMenuOpen for _, widget in pairs(const.WIDGET_KIND) do if button:HasWidget(widget) then - local isSelected = widget == selectedWidget and button._isSelected + local isSelected = widget == selectedWidget and button._isSelected and isCorrectLayout button.widgets[widget]:_SetIsSelected(isSelected) end end From 8bb97ae6fef9032cee6dca4e22ab6f56765b7d8d Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 17:40:20 +0200 Subject: [PATCH 22/28] better tooltip for master layout --- Locales/enUS.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Locales/enUS.lua b/Locales/enUS.lua index 32d5137..5d2817d 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -13,7 +13,11 @@ L.MasterLayout = "Master Layout" L.CUFLayoutMasterNone = "|cffffb5c5None|r" L.MasterLayoutTooltip = [[The layout to use for |cFFFFD700Cell UnitFrames|r. -Selecting |cffffb5c5None|r will use the currently active layout in |cFFFFD700Cell|r.]] +Selecting a specific layout will always use that layout +regardless of |cFFFFD700Cell|r Auto Switch settings. + +Selecting |cffffb5c5None|r will Auto Switch to use the +currently active layout in |cFFFFD700Cell|r.]] -- Units L.targettarget = "TargetTarget" From c4508c7781bddcbd9e31f9a64524374afec3ac30 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 18:07:13 +0200 Subject: [PATCH 23/28] add a title to the menu frame --- Menu/Menu.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Menu/Menu.lua b/Menu/Menu.lua index a91f8d4..7f64878 100644 --- a/Menu/Menu.lua +++ b/Menu/Menu.lua @@ -188,6 +188,19 @@ function menu:CreateMenu() Cell:CreateMask(self.window, nil, { 1, -1, -1, 1 }) self.window.mask:Hide() + -- Title + local titleFrame = CUF:CreateFrame(nil, self.window, 120, 20, false, true) + titleFrame:SetPoint("BOTTOMLEFT", self.window, "TOPLEFT", 0, -1) + + local pad = 5 + + local title = titleFrame:CreateFontString(nil, "OVERLAY", CUF.constants.FONTS.CLASS_TITLE) + title:SetPoint("BOTTOMLEFT", pad, pad) + title:SetText("Cell UnitFrame") + title:SetTextScale(1.5) + titleFrame:SetHeight(title:GetStringHeight() + pad * 2) + titleFrame:SetWidth(title:GetStringWidth() + pad * 2) + -- Tabs self.tabPane = Cell:CreateTitledPane(self.window, nil, self.baseWidth, self.paneHeight) self.tabPane:SetPoint("TOPLEFT") From 8a3b87029a9e25a7c5ce90ac011290ad0d115ab8 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 19:00:26 +0200 Subject: [PATCH 24/28] impl copyLayoutFrom --- Annotations.lua | 2 ++ Locales/enUS.lua | 4 ++++ Menu/GeneralTab.lua | 50 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/Annotations.lua b/Annotations.lua index 205bfcd..015edfd 100644 --- a/Annotations.lua +++ b/Annotations.lua @@ -43,6 +43,8 @@ ---@field SetSelected function ---@field SetFont function ---@field button button +---@field ClearSelected function +---@field GetSelected function ---@class CellColorPicker: Frame, BackdropTemplate ---@field SetColor function diff --git a/Locales/enUS.lua b/Locales/enUS.lua index 5d2817d..7aa695b 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -19,6 +19,10 @@ regardless of |cFFFFD700Cell|r Auto Switch settings. Selecting |cffffb5c5None|r will Auto Switch to use the currently active layout in |cFFFFD700Cell|r.]] +L.CopyLayoutFrom = "Copy Layout From" +L.CopyFromTooltip = "Copy settings from another layout" +L.CopyFromPopUp = "" + -- Units L.targettarget = "TargetTarget" L.player = "Player" diff --git a/Menu/GeneralTab.lua b/Menu/GeneralTab.lua index 771d884..1bface1 100644 --- a/Menu/GeneralTab.lua +++ b/Menu/GeneralTab.lua @@ -20,6 +20,55 @@ function generalTab:IsShown() return generalTab.window and generalTab.window:IsShown() end +------------------------------------------------- +-- MARK: Copy From +------------------------------------------------- + +---@class CopyFrom: Frame +local copyLayoutFrom = {} + +function copyLayoutFrom.SetLayoutItems() + if not generalTab:IsShown() then return end + --CUF:Log("|cff00ccffgeneralTab SetCopyFromItems|r") + + local dropdownItems = {} + + for layoutName, _ in pairs(CellDB.layouts) do + if layoutName ~= DB.GetMasterLayout() then + tinsert(dropdownItems, { + ---@diagnostic disable-next-line: undefined-field + ["text"] = layoutName == "default" and _G.DEFAULT or layoutName, + ["value"] = layoutName, + ["onClick"] = function() + copyLayoutFrom.layoutDropdown:ClearSelected() + CUF:Fire("UpdateUnitButtons") + CUF:Fire("UpdateWidget", layoutName) + end, + }) + end + end + + copyLayoutFrom.layoutDropdown:SetItems(dropdownItems) + copyLayoutFrom.layoutDropdown:ClearSelected() +end + +CUF:RegisterCallback("UpdateLayout", "CUF_CopyFrom_SetLayoutItems", copyLayoutFrom.SetLayoutItems) +CUF:RegisterCallback("LoadPageDB", "CUF_CopyFrom_SetLayoutItems", copyLayoutFrom.SetLayoutItems) + +function copyLayoutFrom:Create() + --CUF:Log("|cff00ccffgeneralTab CreateCopyFrom|r") + + local sectionWidth = (generalTab.window:GetWidth() / 2) - 5 + + local pane = Cell:CreateTitledPane(generalTab.window, L.CopyLayoutFrom, sectionWidth, generalTab.paneHeight) + pane:SetPoint("TOPRIGHT") + + ---@type CellDropdown + self.layoutDropdown = Cell:CreateDropdown(generalTab.window, sectionWidth - 10) + self.layoutDropdown:SetPoint("TOPLEFT", pane, "BOTTOMLEFT", 5, -10) + CUF:SetTooltips(self.layoutDropdown, "ANCHOR_TOPLEFT", 0, 3, L.MasterLayout, L.MasterLayoutTooltip) +end + ------------------------------------------------- -- MARK: Layout Profile ------------------------------------------------- @@ -89,6 +138,7 @@ function generalTab:ShowTab() self.window:Show() layoutProfile:SetLayoutItems() + copyLayoutFrom:SetLayoutItems() end function generalTab:HideTab() From 9510c31764d78f4030cf8ca9dc69519992c3538c Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 19:00:36 +0200 Subject: [PATCH 25/28] a bit of cleanup --- Menu/GeneralTab.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Menu/GeneralTab.lua b/Menu/GeneralTab.lua index 1bface1..b207c9b 100644 --- a/Menu/GeneralTab.lua +++ b/Menu/GeneralTab.lua @@ -75,7 +75,6 @@ end ---@class LayoutProfile: Frame local layoutProfile = {} -layoutProfile.height = 100 function layoutProfile:SetLayoutItems() if not generalTab:IsShown() then return end @@ -88,6 +87,7 @@ function layoutProfile:SetLayoutItems() DB.SetMasterLayout("CUFLayoutMasterNone") CUF:Fire("UpdateUnitButtons") CUF:Fire("UpdateWidget", Cell.vars.currentLayout) + copyLayoutFrom.SetLayoutItems() end, } } @@ -106,16 +106,15 @@ function layoutProfile:SetLayoutItems() layoutProfile.layoutDropdown:SetItems(dropdownItems) layoutProfile.layoutDropdown:SetSelectedValue(DB.GetMasterLayout(true)) - Cell:SetTooltips(layoutProfile.layoutDropdown, "ANCHOR_TOPLEFT", 0, 3, L.MasterLayout, L.MasterLayoutTooltip) end CUF:RegisterCallback("UpdateLayout", "CUF_LayoutProfile_SetLayoutItems", layoutProfile.SetLayoutItems) CUF:RegisterCallback("LoadPageDB", "CUF_LayoutProfile_SetLayoutItems", layoutProfile.SetLayoutItems) -function layoutProfile:CreateLayoutProfile() - CUF:Log("|cff00ccffgeneralTab CreateLayoutProfile|r") +function layoutProfile:Create() + --CUF:Log("|cff00ccffgeneralTab CreateLayoutProfile|r") - local sectionWidth = generalTab.window:GetWidth() / 2 + local sectionWidth = (generalTab.window:GetWidth() / 2) - 5 local layoutPane = Cell:CreateTitledPane(generalTab.window, L.MasterLayout, sectionWidth, generalTab.paneHeight) layoutPane:SetPoint("TOPLEFT") @@ -123,6 +122,7 @@ function layoutProfile:CreateLayoutProfile() ---@type CellDropdown self.layoutDropdown = Cell:CreateDropdown(generalTab.window, sectionWidth - 10) self.layoutDropdown:SetPoint("TOPLEFT", layoutPane, "BOTTOMLEFT", 5, -10) + CUF:SetTooltips(self.layoutDropdown, "ANCHOR_TOPLEFT", 0, 3, L.MasterLayout, L.MasterLayoutTooltip) end ------------------------------------------------- @@ -161,5 +161,6 @@ function generalTab:Create() self.height, true) self.window:SetPoint("TOPLEFT", Menu.tabAnchor, "TOPLEFT") - layoutProfile:CreateLayoutProfile() + layoutProfile:Create() + copyLayoutFrom:Create() end From 81a6646d0ca07282f498309db1aa657693c2815c Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 20:50:12 +0200 Subject: [PATCH 26/28] impl DB.CopyFullLayout --- Data/DBUtil.lua | 7 +++++++ Util/Utils.lua | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/Data/DBUtil.lua b/Data/DBUtil.lua index 0a6a564..4033cd0 100644 --- a/Data/DBUtil.lua +++ b/Data/DBUtil.lua @@ -13,6 +13,13 @@ DB.PropsToOnlyInit = { whitelist = true, } +-- Copy ALL settings from one layout to another +---@param from string +---@param to string +function DB.CopyFullLayout(from, to) + CellDB.layouts[to].CUFUnits = CUF.Util:CopyDeep(DB.GetLayoutTable(from)) +end + -- Make sure that we have an active CellDB and that it has all the UnitLayouts we need ---@return false? noCellDB If CellDB is not present function DB.VerifyDB() diff --git a/Util/Utils.lua b/Util/Utils.lua index 8ea9020..2b78652 100644 --- a/Util/Utils.lua +++ b/Util/Utils.lua @@ -75,6 +75,22 @@ function Util:RenameProp(table, oldKey, newKey) end end +---@param table table +---@param seen table? +---@return table +function Util:CopyDeep(table, seen) + -- Handle non-tables and previously-seen tables. + if type(table) ~= 'table' then return table end + if seen and seen[table] then return seen[table] end + + -- New table; mark it as seen an copy recursively. + local s = seen or {} + local res = {} + s[table] = res + for k, v in next, table do res[self:CopyDeep(k, s)] = self:CopyDeep(v, s) end + return setmetatable(res, getmetatable(table)) +end + ------------------------------------------------- -- MARK: IterateAllUnitButtons ------------------------------------------------- @@ -291,6 +307,18 @@ function CUF:CreateEditBox(parent, width, height, text, isTransparent, isMultiLi return editBox end +---@param parent Frame +---@param width number +---@param text string +---@param onAccept function? +---@param onReject function? +---@param mask boolean? +---@param hasEditBox boolean? +---@param dropdowns boolean? +function CUF:CreateConfirmPopup(parent, width, text, onAccept, onReject, mask, hasEditBox, dropdowns) + return Cell:CreateConfirmPopup(parent, width, text, onAccept, onReject, mask, hasEditBox, dropdowns) +end + ---@param frame Frame ---@param anchor "ANCHOR_TOP" | "ANCHOR_BOTTOM" | "ANCHOR_LEFT" | "ANCHOR_RIGHT" | "ANCHOR_TOPLEFT" | "ANCHOR_TOPRIGHT" | "ANCHOR_BOTTOMLEFT" | "ANCHOR_BOTTOMRIGHT" | "ANCHOR_CURSOR" ---@param x number From 0c248cf20775e4fc69350b898e5344f0b8895ee4 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 20:50:45 +0200 Subject: [PATCH 27/28] finish implementing copyLayoutFrom --- Locales/enUS.lua | 6 ++++-- Menu/GeneralTab.lua | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Locales/enUS.lua b/Locales/enUS.lua index 7aa695b..7a11bb1 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -20,8 +20,10 @@ Selecting |cffffb5c5None|r will Auto Switch to use the currently active layout in |cFFFFD700Cell|r.]] L.CopyLayoutFrom = "Copy Layout From" -L.CopyFromTooltip = "Copy settings from another layout" -L.CopyFromPopUp = "" +L.CopyFromTooltip = [[|cFFFF0000This will overwrite all settings in the current layout!|r + +Copy settings from another layout]] +L.CopyFromPopUp = "Copy settings from |cFFFFD700%s|r to |cFFFFD700%s|r?" -- Units L.targettarget = "TargetTarget" diff --git a/Menu/GeneralTab.lua b/Menu/GeneralTab.lua index b207c9b..9ba6245 100644 --- a/Menu/GeneralTab.lua +++ b/Menu/GeneralTab.lua @@ -20,6 +20,14 @@ function generalTab:IsShown() return generalTab.window and generalTab.window:IsShown() end +--- Replaces "default" with _G.DEFAULT +---@param layoutName string +---@return string +local function normalizeLayoutName(layoutName) + ---@diagnostic disable-next-line: undefined-field + return layoutName == "default" and _G.DEFAULT or layoutName +end + ------------------------------------------------- -- MARK: Copy From ------------------------------------------------- @@ -36,13 +44,19 @@ function copyLayoutFrom.SetLayoutItems() for layoutName, _ in pairs(CellDB.layouts) do if layoutName ~= DB.GetMasterLayout() then tinsert(dropdownItems, { - ---@diagnostic disable-next-line: undefined-field - ["text"] = layoutName == "default" and _G.DEFAULT or layoutName, + ["text"] = normalizeLayoutName(layoutName), ["value"] = layoutName, ["onClick"] = function() + local popup = CUF:CreateConfirmPopup(Menu.window, 300, + string.format(L.CopyFromPopUp, normalizeLayoutName(layoutName), + normalizeLayoutName(DB.GetMasterLayout())), + function() + DB.CopyFullLayout(layoutName, DB.GetMasterLayout()) + CUF:Fire("UpdateUnitButtons") + CUF:Fire("UpdateWidget", DB.GetMasterLayout()) + end, nil, true) + popup:SetPoint("TOP", 0, -70) copyLayoutFrom.layoutDropdown:ClearSelected() - CUF:Fire("UpdateUnitButtons") - CUF:Fire("UpdateWidget", layoutName) end, }) end @@ -66,7 +80,7 @@ function copyLayoutFrom:Create() ---@type CellDropdown self.layoutDropdown = Cell:CreateDropdown(generalTab.window, sectionWidth - 10) self.layoutDropdown:SetPoint("TOPLEFT", pane, "BOTTOMLEFT", 5, -10) - CUF:SetTooltips(self.layoutDropdown, "ANCHOR_TOPLEFT", 0, 3, L.MasterLayout, L.MasterLayoutTooltip) + CUF:SetTooltips(self.layoutDropdown, "ANCHOR_TOPLEFT", 0, 3, L.CopyLayoutFrom, L.CopyFromTooltip) end ------------------------------------------------- @@ -100,6 +114,7 @@ function layoutProfile:SetLayoutItems() DB.SetMasterLayout(layoutName) CUF:Fire("UpdateUnitButtons") CUF:Fire("UpdateWidget", layoutName) + copyLayoutFrom.SetLayoutItems() end, }) end From c30ce71472052b9b5798fa6f31cd6835f5e53ec3 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Sat, 31 Aug 2024 21:05:38 +0200 Subject: [PATCH 28/28] make generalTab a bit shorter --- Menu/GeneralTab.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Menu/GeneralTab.lua b/Menu/GeneralTab.lua index 9ba6245..b4b765e 100644 --- a/Menu/GeneralTab.lua +++ b/Menu/GeneralTab.lua @@ -11,7 +11,7 @@ local Menu = CUF.Menu ---@class GeneralTab: Menu.Tab local generalTab = {} generalTab.id = "generalTab" -generalTab.height = 400 +generalTab.height = 150 generalTab.paneHeight = 17 Menu:AddTab(generalTab)