From 4d8746297ba61fb8bbc8e6cd36e5f86c52eda7d8 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Mon, 2 Sep 2024 19:57:10 +0200 Subject: [PATCH 01/27] add Default.Colors --- Data/Defaults.lua | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Data/Defaults.lua b/Data/Defaults.lua index ed07856..7b5b32f 100644 --- a/Data/Defaults.lua +++ b/Data/Defaults.lua @@ -1,6 +1,10 @@ ---@class CUF local CUF = select(2, ...) +------------------------------------------------- +-- MARK: Defaults +------------------------------------------------- + ---@class CUF.defaults local Defaults = CUF.Defaults Defaults.Options = {} @@ -101,6 +105,25 @@ Defaults.Options.fontWidth = { auxValue = 3, } +---@class Defaults.Colors +Defaults.Colors = { + castBar = { + interruptible = { 0.2, 0.57, 0.5, 1 }, + nonInterruptible = { 0.43, 0.43, 0.43, 1 }, + background = { 0, 0, 0, 0.8 }, + stageZero = { 0.2, 0.57, 0.5, 1 }, + stageOne = { 0.3, 0.47, 0.45, 1 }, + stageTwo = { 0.4, 0.4, 0.4, 1 }, + stageThree = { 0.54, 0.3, 0.3, 1 }, + stageFour = { 0.65, 0.2, 0.3, 1 }, + fullyCharged = { 0.77, 0.1, 0.2, 1 }, + } +} + +------------------------------------------------- +-- MARK: Widgets (Text) +------------------------------------------------- + ---@class WidgetTables Defaults.Widgets = { ---@type NameTextWidgetTable @@ -166,7 +189,7 @@ Defaults.Widgets = { offsetX = 0, relativePoint = "CENTER", }, - }, + }, -- MARK: Widgets (Auras) ---@type AuraWidgetTable buffs = { enabled = false, @@ -252,7 +275,7 @@ Defaults.Widgets = { offsetX = 0, relativePoint = "TOPRIGHT", }, - }, + }, -- MARK: Widgets (Icons) ---@type RaidIconWidgetTable raidIcon = { enabled = false, @@ -342,7 +365,7 @@ Defaults.Widgets = { offsetX = -15, relativePoint = "CENTER", }, - }, + }, -- MARK: Widgets (Bars) ---@type ShieldBarWidgetTable shieldBar = { enabled = false, @@ -433,6 +456,10 @@ Defaults.Widgets = { } } +------------------------------------------------- +-- MARK: Units +------------------------------------------------- + ---@class Size ---@field [1] number ---@field [2] number From fdde19758d6f35f4c14bafd01cdcf0eeb19c5392 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 10:30:49 +0200 Subject: [PATCH 02/27] implement generic for creating ImportExport frames --- Cell_UnitFrames.toc | 1 + Menu/ImportExport.lua | 178 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 Menu/ImportExport.lua diff --git a/Cell_UnitFrames.toc b/Cell_UnitFrames.toc index 908d56f..01ae9bd 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/ImportExport.lua Menu/GeneralTab.lua Menu/UnitFramesTab.lua diff --git a/Menu/ImportExport.lua b/Menu/ImportExport.lua new file mode 100644 index 0000000..6bd273d --- /dev/null +++ b/Menu/ImportExport.lua @@ -0,0 +1,178 @@ +---@class CUF +local CUF = select(2, ...) + +local L = CUF.L +local F = Cell.funcs +local P = Cell.pixelPerfectFuncs +local Menu = CUF.Menu + +local Serializer = LibStub:GetLibrary("LibSerialize") +local LibDeflate = LibStub:GetLibrary("LibDeflate") +local deflateConfig = { level = 9 } + +---@class CUF.ImportExport +local ImportExport = {} + +CUF.ImportExport = ImportExport + +------------------------------------------------- +-- MARK: Show +------------------------------------------------- + +---@param self CUF.ImportExport.Frame +local function ShowImportFrame(self) + self:Show() + self.isImport = true + self.importBtn:Show() + self.importBtn:SetEnabled(false) + + self.exported = "" + self.title:SetText(L["Import"]) + self.textArea:SetText("") + self.textArea.eb:SetFocus(true) +end + +---@param self CUF.ImportExport.Frame +local function ShowExportFrame(self) + self:Show() + self.isImport = false + self.importBtn:Hide() + + self.title:SetText(L["Export"] .. ": " .. L[self.which]) + + local prefix = "!CUF:" .. CUF.version .. ":" .. string.upper(self.which) .. "!" + + self.exported = Serializer:Serialize(self.exportFn()) -- serialize + self.exported = LibDeflate:CompressDeflate(self.exported, deflateConfig) -- compress + self.exported = LibDeflate:EncodeForPrint(self.exported) -- encode + self.exported = prefix .. self.exported + + self.textArea:SetText(self.exported) + self.textArea.eb:SetFocus(true) +end + +------------------------------------------------- +-- MARK: Create +------------------------------------------------- + +---@param which string +---@param importFn fun(imported: any) +---@param exportFn fun(): table +---@param verifyFn fun(imported: any): boolean +---@param minVersion number? +function ImportExport:CreateImportExportFrame(which, importFn, exportFn, verifyFn, minVersion) + ---@class CUF.ImportExport.Frame: Frame, BackdropTemplate + local importExportFrame = CreateFrame("Frame", "CUF_ImportExport", Menu.window, "BackdropTemplate") + importExportFrame.which = which + importExportFrame.exportFn = exportFn + + importExportFrame:Hide() + Cell:StylizeFrame(importExportFrame, nil, Cell:GetAccentColorTable()) + importExportFrame:EnableMouse(true) + importExportFrame:SetFrameLevel(Menu.window:GetFrameLevel() + 50) + importExportFrame:SetSize(Menu.window:GetWidth() - 5, 170) + importExportFrame:SetPoint("CENTER", 1, 0) + + -- close + local closeBtn = Cell:CreateButton(importExportFrame, "×", "red", { 18, 18 }, false, false, "CELL_FONT_SPECIAL", + "CELL_FONT_SPECIAL") + closeBtn:SetPoint("TOPRIGHT", P:Scale(-5), P:Scale(-1)) + closeBtn:SetScript("OnClick", function() importExportFrame:Hide() end) + + -- import + local importBtn = Cell:CreateButton(importExportFrame, L["Import"], "green", { 57, 18 }) + importBtn:Hide() + importBtn:SetPoint("TOPRIGHT", closeBtn, "TOPLEFT", P:Scale(1), 0) + importBtn:SetScript("OnClick", function() + -- lower frame level + importExportFrame:SetFrameLevel(Menu.window:GetFrameLevel() + 20) + + local popup = Cell:CreateConfirmPopup(Menu.window, 200, L["Overwrite "] .. L[which] .. "?", + function() + importFn(importExportFrame.imported) + importExportFrame:Hide() + end, nil, true) + popup:SetPoint("TOPLEFT", importExportFrame, 117, -50) + importExportFrame.textArea.eb:ClearFocus() + end) + importExportFrame.importBtn = importBtn + + -- title + local title = importExportFrame:CreateFontString(nil, "OVERLAY", "CELL_FONT_CLASS") + title:SetPoint("TOPLEFT", 5, -5) + importExportFrame.title = title + + -- textArea + local textArea = Cell:CreateScrollEditBox(importExportFrame, function(eb, userChanged) + if userChanged then + if importExportFrame.isImport then + importExportFrame.imported = {} + local text = eb:GetText() + -- check + local version, type, data = string.match(text, + "^!CUF:(%d+):(.+)!(.+)$") + version = tonumber(version) + + if type and type == string.upper(which) and version and data then + if not minVersion or version >= minVersion then + local success + data = LibDeflate:DecodeForPrint(data) -- decode + success, data = pcall(LibDeflate.DecompressDeflate, LibDeflate, data) -- decompress + success, data = Serializer:Deserialize(data) -- deserialize + + if success and data and verifyFn(data) then + title:SetText(L["Import"] .. ": " .. L[which]) + importExportFrame.imported = data + importBtn:SetEnabled(true) + else + title:SetText(L["Import"] .. ": |cffff2222" .. L["Error"]) + importBtn:SetEnabled(false) + end + else -- incompatible version + title:SetText(L["Import"] .. ": |cffff2222" .. L["Incompatible Version"]) + importBtn:SetEnabled(false) + end + else + title:SetText(L["Import"] .. ": |cffff2222" .. L["Error"]) + importBtn:SetEnabled(false) + end + else + eb:SetText(importExportFrame.exported) + eb:SetCursorPosition(0) + eb:HighlightText() + end + end + end) + Cell:StylizeFrame(textArea.scrollFrame, { 0, 0, 0, 0 }, Cell:GetAccentColorTable()) + textArea:SetPoint("TOPLEFT", P:Scale(5), P:Scale(-20)) + textArea:SetPoint("BOTTOMRIGHT", P:Scale(-5), P:Scale(5)) + + -- highlight text + textArea.eb:SetScript("OnEditFocusGained", function() textArea.eb:HighlightText() end) + textArea.eb:SetScript("OnMouseUp", function() + if not importExportFrame.isImport then + textArea.eb:HighlightText() + end + end) + importExportFrame.textArea = textArea + + importExportFrame:SetScript("OnHide", function() + importExportFrame:Hide() + importExportFrame.isImport = false + importExportFrame.exported = "" + importExportFrame.imported = {} + -- hide mask + Menu.window.mask:Hide() + end) + + importExportFrame:SetScript("OnShow", function() + -- raise frame level + importExportFrame:SetFrameLevel(Menu.window:GetFrameLevel() + 50) + Menu.window.mask:Show() + end) + + importExportFrame.ShowImport = ShowImportFrame + importExportFrame.ShowExport = ShowExportFrame + + return importExportFrame +end From 9ae6752200640cc6dd1adf0cf9fe5dd97c3b84ae Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 10:31:25 +0200 Subject: [PATCH 03/27] update annotations --- Annotations.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Annotations.lua b/Annotations.lua index 9423f4c..616e2af 100644 --- a/Annotations.lua +++ b/Annotations.lua @@ -49,7 +49,9 @@ ---@field ClearItems function ---@class CellColorPicker: Frame, BackdropTemplate ----@field SetColor function +---@field SetColor fun(self: CellColorPicker, r: number|table, g: number?, b: number?, a: number?) +---@field label FontString +---@field onChange fun(r: number, g: number, b: number, a: number) ---@class CellSlider: Slider ---@field afterValueChangedFn function From 654175d4a3f8f4b97ed4c5517db644004d1635c8 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 10:32:25 +0200 Subject: [PATCH 04/27] create DB getter/setter for colors --- Data/Database.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Data/Database.lua b/Data/Database.lua index 9a5ba32..37fc0e6 100644 --- a/Data/Database.lua +++ b/Data/Database.lua @@ -101,6 +101,19 @@ function DB.GetMasterLayout(rawValue) return CUF_DB.masterLayout end +--- Returns the colors table from DB +--- +--- Parse the which arg to only return a specific color table +---@param which Defaults.Colors.Types? +---@return Defaults.Colors +function DB.GetColors(which) + local colors = CUF_DB.colors + if which then + return colors[which] + end + return CUF_DB.colors +end + ----------------------------------------- -- MARK: General Setters ----------------------------------------- @@ -109,3 +122,11 @@ end function DB.SetMasterLayout(layout) CUF_DB.masterLayout = layout end + +--- Sets the color of a specific color type +---@param which Defaults.Colors.Types +---@param colorName string +---@param val RGBAOpt +function DB.SetColor(which, colorName, val) + DB.GetColors(which)[colorName] = val +end From a161a17cdebe63ac0dfb4662a64f09fb8edaf1bf Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 10:32:58 +0200 Subject: [PATCH 05/27] init CUF_DB.colors --- Data/DBUtil.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Data/DBUtil.lua b/Data/DBUtil.lua index 9e3906a..63330c2 100644 --- a/Data/DBUtil.lua +++ b/Data/DBUtil.lua @@ -6,6 +6,7 @@ local DB = CUF.DB local Util = CUF.Util local L = CUF.L +local Defaults = CUF.Defaults -- Props that should only be initialized once -- eg we only want to initialize filters, not keep adding to them @@ -26,6 +27,10 @@ function DB.InitDB() ---@field manual CUF.database.backup CUF_DB.backups = CUF_DB.backups or {} + ---@type Defaults.Colors + CUF_DB.colors = CUF_DB.colors or Util:CopyDeep(Defaults.Colors) + Util:AddMissingProps(CUF_DB.colors, Defaults.Colors) + DB.CreateAutomaticBackup() end From 05060fdc10306d524aeff817dc4bde35a78301d8 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 10:33:15 +0200 Subject: [PATCH 06/27] update defaults --- Data/Defaults.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Data/Defaults.lua b/Data/Defaults.lua index 7b5b32f..1b267fd 100644 --- a/Data/Defaults.lua +++ b/Data/Defaults.lua @@ -105,8 +105,12 @@ Defaults.Options.fontWidth = { auxValue = 3, } +---@alias Defaults.Colors.Types +---| "castBar" + ---@class Defaults.Colors Defaults.Colors = { + ---@type table castBar = { interruptible = { 0.2, 0.57, 0.5, 1 }, nonInterruptible = { 0.43, 0.43, 0.43, 1 }, @@ -117,7 +121,22 @@ Defaults.Colors = { stageThree = { 0.54, 0.3, 0.3, 1 }, stageFour = { 0.65, 0.2, 0.3, 1 }, fullyCharged = { 0.77, 0.1, 0.2, 1 }, - } + }, +} + +---@type table +Defaults.ColorsMenuOrder = { + castBar = { + "background", + "interruptible", + "nonInterruptible", + "stageZero", + "stageOne", + "stageTwo", + "stageThree", + "stageFour", + "fullyCharged" + }, } ------------------------------------------------- From e3be0187a70f9f289c6feb71ff7935bc582065e2 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 10:52:15 +0200 Subject: [PATCH 07/27] add colorTab --- Cell_UnitFrames.toc | 1 + Locales/enUS.lua | 17 ++++ Menu/ColorTab.lua | 193 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 Menu/ColorTab.lua diff --git a/Cell_UnitFrames.toc b/Cell_UnitFrames.toc index 01ae9bd..650df00 100644 --- a/Cell_UnitFrames.toc +++ b/Cell_UnitFrames.toc @@ -38,6 +38,7 @@ Menu/Menu.lua Menu/ImportExport.lua Menu/GeneralTab.lua Menu/UnitFramesTab.lua +Menu/ColorTab.lua Widgets/Common.lua diff --git a/Locales/enUS.lua b/Locales/enUS.lua index e4b0bf5..bd7fbff 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -8,6 +8,7 @@ CUF.L = L -- Tabs L.unitFramesTab = "Unit Frames" L.generalTab = "General" +L.colorTab = "Colors" L.MasterLayout = "Master Layout" L.CUFLayoutMasterNone = "|cffffb5c5None|r" @@ -177,3 +178,19 @@ L["def"] = "Displays the deficit." L["def:short"] = "Displays the deficit as a shortvalue." L["def:per"] = "Displays the deficit as a percentage." L["def:per-short"] = "Displays the deficit as a percentage without decimals." + +-- Colors +L.stageZero = "Stage 0" +L.stageOne = "Stage 1" +L.stageTwo = "Stage 2" +L.stageThree = "Stage 3" +L.stageFour = "Stage 4" +L.fullyCharged = "Fully Charged" +L.background = "Background" +L.interruptible = "Interruptible" +L.nonInterruptible = "Non-Interruptible" +L.holyPower = "Holy Power" +L.arcaneCharges = "Arcane Charges" +L.soulShards = "Soul Shards" + +L.ImportExportColors = "Import & Export Color Settings" diff --git a/Menu/ColorTab.lua b/Menu/ColorTab.lua new file mode 100644 index 0000000..5b9fb3e --- /dev/null +++ b/Menu/ColorTab.lua @@ -0,0 +1,193 @@ +---@class CUF +local CUF = select(2, ...) + +local Cell = CUF.Cell + +local L = CUF.L +local DB = CUF.DB +local Menu = CUF.Menu +local Util = CUF.Util + +---@class ColorTab: Menu.Tab +local ColorTab = {} +ColorTab.id = "colorTab" +ColorTab.paneHeight = 17 + +------------------------------------------------- +-- MARK: Import / Export +------------------------------------------------- + +function ColorTab:CreateImportExport() + local section = CUF:CreateFrame(nil, self.window, self.window:GetWidth(), 45, true, true) + section:SetPoint("TOPLEFT") + self.importExportSection = section + + self.importExportFrame = CUF.ImportExport:CreateImportExportFrame("Colors", + function(imported) + CUF_DB.colors = imported + self:UpdateColors() + CUF:Fire("UpdateUnitButtons") + CUF:Fire("UpdateWidget", DB.GetMasterLayout()) + end, + DB.GetColors, + -- TODO: verify colors + function(imported) return true end) + + local pane = Cell:CreateTitledPane(section, L.ImportExportColors, section:GetWidth(), self.paneHeight) + pane:SetPoint("TOPLEFT") + + local buttonWidth = (section:GetWidth() / 2) - 5 + local importButton = CUF:CreateButton(section, L["Import"], { buttonWidth, 20 }, function() + self.importExportFrame:ShowImport() + end) + importButton:SetPoint("TOPLEFT", pane, "BOTTOMLEFT", 0, -5) + + local exportButton = CUF:CreateButton(section, L["Export"], { buttonWidth, 20 }, function() + self.importExportFrame:ShowExport() + end) + exportButton:SetPoint("TOPRIGHT", pane, "BOTTOMRIGHT", 0, -5) +end + +------------------------------------------------- +-- MARK: Sections +------------------------------------------------- + +function ColorTab:UpdateColors() + for _, section in pairs(self.colorSections) do + local colorTable = DB.GetColors(section.id) + for _, cp in pairs(section.cps) do + cp:SetColor(colorTable[cp.id]) + end + end +end + +function ColorTab:CreateSections() + local heightPerCp = 25 + local cpGap = (self.window:GetWidth() / 3) * 0.80 + local sectionGap = 10 + + self.colorSections = {} + + local prevSection + local colorTables = DB.GetColors() + + local colorOrder = CUF.Defaults.ColorsMenuOrder + for which, order in pairs(colorOrder) do + ---@class CUF.ColorSection: Frame + local section = CUF:CreateFrame("ColorSection_" .. Util:ToTitleCase(which), + self.window, + self.window:GetWidth(), + 1, + false, true) + section.id = which + section.cps = {} + + local sectionTitle = CUF:CreateFrame(nil, section, 1, 1, true, true) --[[@as OptionTitle]] + sectionTitle:SetPoint("TOPLEFT", 10, -10) + + sectionTitle.title = sectionTitle:CreateFontString(nil, "OVERLAY", "CELL_FONT_CLASS_TITLE") + sectionTitle.title:SetText(L[which]) + sectionTitle.title:SetScale(1.2) + sectionTitle.title:SetPoint("TOPLEFT") + + ---@type CellColorPicker + local prevCp + local cpInRow = 0 + local numRows = 1 + local rowLenght = 0 + + ---@type table + local colorTable = colorTables[which] + for _, colorName in ipairs(order) do + ---@class CUF.ColorSection.ColorPicker: CellColorPicker + local cp = Cell:CreateColorPicker(section, L[colorName], true) + cp.id = colorName + + cp:SetColor(colorTable[colorName]) + cp.onChange = function(r, g, b, a) + DB.SetColor(which, colorName, { r, g, b, a }) + end + + local cpWidth = cp:GetWidth() + cp.label:GetWidth() + + -- First ColorPicker + if not prevCp then + cp:SetPoint("TOPLEFT", sectionTitle, "BOTTOMLEFT", 0, -heightPerCp) + elseif rowLenght + cpWidth > section:GetWidth() or cpInRow == 3 then + -- Check if cp will fit in the row + numRows = numRows + 1 + rowLenght = 0 + cpInRow = 0 + + cp:SetPoint("TOPLEFT", sectionTitle, "BOTTOMLEFT", 0, -(heightPerCp * numRows)) + else + -- New row + cp:SetPoint("TOPLEFT", prevCp, "TOPRIGHT", cpGap, 0) + + rowLenght = rowLenght + (cpGap / 2) + end + + cpInRow = cpInRow + 1 + rowLenght = rowLenght + cpWidth + prevCp = cp + + tinsert(section.cps, cp) + end + + local sectionHeight = 40 + numRows * heightPerCp + section:SetHeight(sectionHeight) + + if not prevSection then + self.window:SetHeight(self.importExportSection:GetHeight() + sectionHeight + (sectionGap * 2)) + section:SetPoint("TOPLEFT", self.importExportSection, "BOTTOMLEFT", 0, -sectionGap) + else + self.window:SetHeight(self.window:GetHeight() + sectionHeight + sectionGap) + section:SetPoint("TOPLEFT", prevSection, "BOTTOMLEFT", 0, -sectionGap) + end + + prevSection = section + tinsert(self.colorSections, section) + end +end + +------------------------------------------------- +-- MARK: Show/Hide +------------------------------------------------- + +function ColorTab:ShowTab() + --CUF:Log("|cff00ccffShow ColorTab|r") + if not self.window then + self:Create() + self.init = true + end + + self.window:Show() +end + +function ColorTab:HideTab() + if not self.window or not self.window:IsShown() then return end + --CUF:Log("|cff00ccffHide ColorTab|r") + self.window:Hide() +end + +function ColorTab:IsShown() + return ColorTab.window and ColorTab.window:IsShown() +end + +------------------------------------------------- +-- MARK: Create +------------------------------------------------- + +function ColorTab:Create() + local sectionWidth = Menu.tabAnchor:GetWidth() + + self.window = CUF:CreateFrame("CUF_Menu_UnitFrame", Menu.window, + sectionWidth, + 0, true) + self.window:SetPoint("TOPLEFT", Menu.tabAnchor, "TOPLEFT") + + self:CreateImportExport() + self:CreateSections() +end + +Menu:AddTab(ColorTab) From 38ec455a246290bb201d2522981fb19312e9b345 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 11:26:54 +0200 Subject: [PATCH 08/27] Fire UpdateWidget callback when changing colors --- Menu/ColorTab.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Menu/ColorTab.lua b/Menu/ColorTab.lua index 5b9fb3e..a7853f2 100644 --- a/Menu/ColorTab.lua +++ b/Menu/ColorTab.lua @@ -7,6 +7,7 @@ local L = CUF.L local DB = CUF.DB local Menu = CUF.Menu local Util = CUF.Util +local const = CUF.constants ---@class ColorTab: Menu.Tab local ColorTab = {} @@ -106,6 +107,7 @@ function ColorTab:CreateSections() cp:SetColor(colorTable[colorName]) cp.onChange = function(r, g, b, a) DB.SetColor(which, colorName, { r, g, b, a }) + CUF:Fire("UpdateWidget", DB.GetMasterLayout(), nil, which, const.OPTION_KIND.COLOR) end local cpWidth = cp:GetWidth() + cp.label:GetWidth() From 04ac3297843429068a2aa1c5f982fd4b8fb5ebb4 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 11:31:40 +0200 Subject: [PATCH 09/27] use global colors for Cast Bar --- Widgets/Bars/CastBar.lua | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Widgets/Bars/CastBar.lua b/Widgets/Bars/CastBar.lua index 5bb90de..30eca54 100644 --- a/Widgets/Bars/CastBar.lua +++ b/Widgets/Bars/CastBar.lua @@ -44,15 +44,7 @@ function W.UpdateCastBarWidget(button, unit, setting, subSetting, ...) if not subSetting or subSetting == const.OPTION_KIND.USE_CLASS_COLOR then castBar.useClassColor = styleTable.color.useClassColor end - if not subSetting or subSetting == const.OPTION_KIND.INTERRUPTIBLE then - castBar.interruptibleColor = styleTable.color.interruptible - end - if not subSetting or subSetting == const.OPTION_KIND.NON_INTERRUPTIBLE then - castBar.nonInterruptibleColor = styleTable.color.nonInterruptible - end - if not subSetting or subSetting == const.OPTION_KIND.BACKGROUND then - castBar.background:SetVertexColor(unpack(styleTable.color.background)) - end + castBar:SetCastBarColorStyle() end if not setting or setting == const.OPTION_KIND.TIMER then @@ -748,8 +740,12 @@ end local function SetEmpowerStyle(self, styleTable) self.useFullyCharged = styleTable.useFullyCharged self.showEmpowerSpellName = styleTable.showEmpowerName +end + +---@param self CastBarWidget +local function SetCastBarColorStyle(self) + local colors = DB.GetColors().castBar - local colors = styleTable.pipColors self.PipColorMap = { [0] = colors.stageZero, [1] = colors.stageOne, @@ -758,6 +754,10 @@ local function SetEmpowerStyle(self, styleTable) [4] = colors.stageFour, [5] = colors.fullyCharged, } + + self.interruptibleColor = colors.interruptible + self.nonInterruptibleColor = colors.nonInterruptible + self.background:SetVertexColor(unpack(colors.background)) end ---@param self CastBarWidget @@ -941,6 +941,7 @@ function W:CreateCastBar(button) castBar.Disable = Disable castBar.Update = Update + castBar.SetCastBarColorStyle = SetCastBarColorStyle castBar.SetCastBarColor = SetCastBarColor castBar.SetEmpowerStyle = SetEmpowerStyle castBar.SetBorderStyle = SetBorderStyle From f676ef247bbc803a8f913ccf6a2177d7c18cf64a Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 11:57:55 +0200 Subject: [PATCH 10/27] a bit of cleanup --- Data/Database.lua | 11 ++--------- Data/Defaults.lua | 1 - Menu/ColorTab.lua | 12 +++++++----- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Data/Database.lua b/Data/Database.lua index 37fc0e6..084c257 100644 --- a/Data/Database.lua +++ b/Data/Database.lua @@ -102,15 +102,8 @@ function DB.GetMasterLayout(rawValue) end --- Returns the colors table from DB ---- ---- Parse the which arg to only return a specific color table ----@param which Defaults.Colors.Types? ---@return Defaults.Colors -function DB.GetColors(which) - local colors = CUF_DB.colors - if which then - return colors[which] - end +function DB.GetColors() return CUF_DB.colors end @@ -128,5 +121,5 @@ end ---@param colorName string ---@param val RGBAOpt function DB.SetColor(which, colorName, val) - DB.GetColors(which)[colorName] = val + DB.GetColors()[which][colorName] = val end diff --git a/Data/Defaults.lua b/Data/Defaults.lua index 1b267fd..a0f5fc8 100644 --- a/Data/Defaults.lua +++ b/Data/Defaults.lua @@ -110,7 +110,6 @@ Defaults.Options.fontWidth = { ---@class Defaults.Colors Defaults.Colors = { - ---@type table castBar = { interruptible = { 0.2, 0.57, 0.5, 1 }, nonInterruptible = { 0.43, 0.43, 0.43, 1 }, diff --git a/Menu/ColorTab.lua b/Menu/ColorTab.lua index a7853f2..ddeb212 100644 --- a/Menu/ColorTab.lua +++ b/Menu/ColorTab.lua @@ -53,21 +53,25 @@ end -- MARK: Sections ------------------------------------------------- +--- Update all color pickers with the current color table +--- +--- This is called when a new color table is imported function ColorTab:UpdateColors() for _, section in pairs(self.colorSections) do - local colorTable = DB.GetColors(section.id) + local colorTable = DB.GetColors()[section.id] for _, cp in pairs(section.cps) do cp:SetColor(colorTable[cp.id]) end end end +--- Create sections with color pickers for each color type function ColorTab:CreateSections() local heightPerCp = 25 local cpGap = (self.window:GetWidth() / 3) * 0.80 local sectionGap = 10 - self.colorSections = {} + self.colorSections = {} ---@type CUF.ColorSection[] local prevSection local colorTables = DB.GetColors() @@ -81,7 +85,7 @@ function ColorTab:CreateSections() 1, false, true) section.id = which - section.cps = {} + section.cps = {} ---@type CUF.ColorSection.ColorPicker[] local sectionTitle = CUF:CreateFrame(nil, section, 1, 1, true, true) --[[@as OptionTitle]] sectionTitle:SetPoint("TOPLEFT", 10, -10) @@ -157,7 +161,6 @@ end ------------------------------------------------- function ColorTab:ShowTab() - --CUF:Log("|cff00ccffShow ColorTab|r") if not self.window then self:Create() self.init = true @@ -168,7 +171,6 @@ end function ColorTab:HideTab() if not self.window or not self.window:IsShown() then return end - --CUF:Log("|cff00ccffHide ColorTab|r") self.window:Hide() end From a676dbc1add2a8d3806aa4a0e767708c598dfec8 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 14:11:50 +0200 Subject: [PATCH 11/27] add util table functions for importing --- Util/Utils.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Util/Utils.lua b/Util/Utils.lua index fa58574..23c3794 100644 --- a/Util/Utils.lua +++ b/Util/Utils.lua @@ -91,6 +91,52 @@ function Util:CopyDeep(table, seen) return setmetatable(res, getmetatable(table)) end +--- Check if a table is a valid copy of another table, used for import checks +--- +--- This function will check if a table is a valid copy of another table. +--- It will check if the table has the same structure as the template table. +--- @param table table The table to check +--- @param template table The template table to check against +--- @param allowMissing boolean? Whether to allow missing keys +--- @return boolean +function Util:IsValidCopy(table, template, allowMissing) + if type(table) ~= "table" or type(template) ~= "table" then + return false + end + + for k, v in pairs(template) do + if (not table[k] and not allowMissing) + or (not self:IsPropSameType(table[k], v)) then + return false + end + + if type(v) == "table" then + if not Util:IsValidCopy(table[k], v, allowMissing) then + return false + end + end + end + + -- TODO: Maybe check if table has keys not present in template? + -- right now that is dealt with in SafeImport so for now w/e + + return true +end + +--- Safely perform an import +--- +--- This does not overwrite the current table. +--- It instead iterates over the imported table and copies the valid props to the current table. +---@param imported table +---@param current table +function Util:SafeImport(imported, current) + for k, v in pairs(imported) do + if current[k] and self:IsPropSameType(current[k], v) then + current[k] = self:CopyDeep(v) + end + end +end + ------------------------------------------------- -- MARK: IterateAllUnitButtons ------------------------------------------------- @@ -263,6 +309,14 @@ function Util:GetAllLayoutNamesAsString(formatted) return table.concat(layoutNames, ", ") end +--- Check if two values have the same type +---@param a any +---@param b any +---@return boolean +function Util:IsPropSameType(a, b) + return type(a) == type(b) +end + ------------------------------------------------- -- MARK: Frames ------------------------------------------------- From 9c9f18b81acb2f536a626b8ffed1f839b579064d Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 14:12:03 +0200 Subject: [PATCH 12/27] use new util fns --- Menu/ColorTab.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Menu/ColorTab.lua b/Menu/ColorTab.lua index ddeb212..cbed384 100644 --- a/Menu/ColorTab.lua +++ b/Menu/ColorTab.lua @@ -25,14 +25,18 @@ function ColorTab:CreateImportExport() self.importExportFrame = CUF.ImportExport:CreateImportExportFrame("Colors", function(imported) - CUF_DB.colors = imported + Util:SafeImport(imported, CUF_DB.colors) + self:UpdateColors() CUF:Fire("UpdateUnitButtons") CUF:Fire("UpdateWidget", DB.GetMasterLayout()) end, DB.GetColors, - -- TODO: verify colors - function(imported) return true end) + function(imported) + -- We allow missing keys here since we might be importing old versions + -- And it's not a big deal if any new ones are missing + return Util:IsValidCopy(imported, CUF.Defaults.Colors, true) + end) local pane = Cell:CreateTitledPane(section, L.ImportExportColors, section:GetWidth(), self.paneHeight) pane:SetPoint("TOPLEFT") From eba5ac8f99485279ee8988ef81697125186c96fc Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 14:39:57 +0200 Subject: [PATCH 13/27] a little cleanup --- Menu/ColorTab.lua | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/Menu/ColorTab.lua b/Menu/ColorTab.lua index cbed384..8cae27e 100644 --- a/Menu/ColorTab.lua +++ b/Menu/ColorTab.lua @@ -79,21 +79,17 @@ function ColorTab:CreateSections() local prevSection local colorTables = DB.GetColors() - local colorOrder = CUF.Defaults.ColorsMenuOrder + for which, order in pairs(colorOrder) do ---@class CUF.ColorSection: Frame local section = CUF:CreateFrame("ColorSection_" .. Util:ToTitleCase(which), - self.window, - self.window:GetWidth(), - 1, - false, true) + self.window, self.window:GetWidth(), 1, false, true) section.id = which section.cps = {} ---@type CUF.ColorSection.ColorPicker[] local sectionTitle = CUF:CreateFrame(nil, section, 1, 1, true, true) --[[@as OptionTitle]] sectionTitle:SetPoint("TOPLEFT", 10, -10) - sectionTitle.title = sectionTitle:CreateFontString(nil, "OVERLAY", "CELL_FONT_CLASS_TITLE") sectionTitle.title:SetText(L[which]) sectionTitle.title:SetScale(1.2) @@ -101,9 +97,7 @@ function ColorTab:CreateSections() ---@type CellColorPicker local prevCp - local cpInRow = 0 - local numRows = 1 - local rowLenght = 0 + local numRows, cpInRow, rowLength = 1, 0, 0 ---@type table local colorTable = colorTables[which] @@ -111,7 +105,6 @@ function ColorTab:CreateSections() ---@class CUF.ColorSection.ColorPicker: CellColorPicker local cp = Cell:CreateColorPicker(section, L[colorName], true) cp.id = colorName - cp:SetColor(colorTable[colorName]) cp.onChange = function(r, g, b, a) DB.SetColor(which, colorName, { r, g, b, a }) @@ -123,35 +116,30 @@ function ColorTab:CreateSections() -- First ColorPicker if not prevCp then cp:SetPoint("TOPLEFT", sectionTitle, "BOTTOMLEFT", 0, -heightPerCp) - elseif rowLenght + cpWidth > section:GetWidth() or cpInRow == 3 then + elseif rowLength + cpWidth > section:GetWidth() or cpInRow == 3 then -- Check if cp will fit in the row - numRows = numRows + 1 - rowLenght = 0 - cpInRow = 0 - + numRows, cpInRow, rowLength = numRows + 1, 0, 0 cp:SetPoint("TOPLEFT", sectionTitle, "BOTTOMLEFT", 0, -(heightPerCp * numRows)) else -- New row cp:SetPoint("TOPLEFT", prevCp, "TOPRIGHT", cpGap, 0) - - rowLenght = rowLenght + (cpGap / 2) + rowLength = rowLength + (cpGap / 2) end cpInRow = cpInRow + 1 - rowLenght = rowLenght + cpWidth + rowLength = rowLength + cpWidth prevCp = cp tinsert(section.cps, cp) end - local sectionHeight = 40 + numRows * heightPerCp - section:SetHeight(sectionHeight) + section:SetHeight(40 + numRows * heightPerCp) if not prevSection then - self.window:SetHeight(self.importExportSection:GetHeight() + sectionHeight + (sectionGap * 2)) + self.window:SetHeight(self.importExportSection:GetHeight() + section:GetHeight() + (sectionGap * 2)) section:SetPoint("TOPLEFT", self.importExportSection, "BOTTOMLEFT", 0, -sectionGap) else - self.window:SetHeight(self.window:GetHeight() + sectionHeight + sectionGap) + self.window:SetHeight(self.window:GetHeight() + section:GetHeight() + sectionGap) section:SetPoint("TOPLEFT", prevSection, "BOTTOMLEFT", 0, -sectionGap) end From 8ae7c866a4def33fedaad8232bec1b8c970b5d84 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 16:06:13 +0200 Subject: [PATCH 14/27] update colorTab section structure to be more generic --- Data/Defaults.lua | 20 ++++----- Menu/ColorTab.lua | 104 +++++++++++++++++++++++++++++++++------------- 2 files changed, 84 insertions(+), 40 deletions(-) diff --git a/Data/Defaults.lua b/Data/Defaults.lua index a0f5fc8..3fdd805 100644 --- a/Data/Defaults.lua +++ b/Data/Defaults.lua @@ -123,18 +123,18 @@ Defaults.Colors = { }, } ----@type table Defaults.ColorsMenuOrder = { castBar = { - "background", - "interruptible", - "nonInterruptible", - "stageZero", - "stageOne", - "stageTwo", - "stageThree", - "stageFour", - "fullyCharged" + { "background", "rgb" }, + { "interruptible", "rgb" }, + { "nonInterruptible", "rgb" }, + { "Empowers", "seperator" }, + { "stageZero", "rgb" }, + { "stageOne", "rgb" }, + { "stageTwo", "rgb" }, + { "stageThree", "rgb" }, + { "stageFour", "rgb" }, + { "fullyCharged", "rgb" } }, } diff --git a/Menu/ColorTab.lua b/Menu/ColorTab.lua index 8cae27e..7744d73 100644 --- a/Menu/ColorTab.lua +++ b/Menu/ColorTab.lua @@ -69,6 +69,42 @@ function ColorTab:UpdateColors() end end +--- Create a color picker +---@param which Defaults.Colors.Types +---@param colorName string +---@param colorTable table +---@param parent Frame +---@return CUF.ColorSection.ColorPicker, number +local function CreateColorPicker(which, colorName, colorTable, parent) + ---@class CUF.ColorSection.ColorPicker: CellColorPicker + local cp = Cell:CreateColorPicker(parent, L[colorName], true) + cp.id = colorName + cp:SetColor(colorTable[colorName]) + cp.onChange = function(r, g, b, a) + DB.SetColor(which, colorName, { r, g, b, a }) + CUF:Fire("UpdateWidget", DB.GetMasterLayout(), nil, which, const.OPTION_KIND.COLOR) + end + + local cpWidth = math.max(cp:GetWidth() + cp.label:GetWidth() + 5, (ColorTab.window:GetWidth() / 3) - 15) + + return cp, cpWidth +end + +--- Create a sperator title +---@param title string +---@param parent Frame +---@return Frame +local function CreateSperatorTitle(title, parent) + local sectionTitle = CUF:CreateFrame(nil, parent, 1, 1, true, true) --[[@as OptionTitle]] + sectionTitle:SetPoint("TOPLEFT", 0, -10) + sectionTitle.title = sectionTitle:CreateFontString(nil, "OVERLAY", "CELL_FONT_CLASS_TITLE") + sectionTitle.title:SetText(L[title]) + sectionTitle.title:SetScale(1) + sectionTitle.title:SetPoint("TOPLEFT") + + return sectionTitle +end + --- Create sections with color pickers for each color type function ColorTab:CreateSections() local heightPerCp = 25 @@ -89,51 +125,59 @@ function ColorTab:CreateSections() section.cps = {} ---@type CUF.ColorSection.ColorPicker[] local sectionTitle = CUF:CreateFrame(nil, section, 1, 1, true, true) --[[@as OptionTitle]] - sectionTitle:SetPoint("TOPLEFT", 10, -10) + sectionTitle:SetPoint("TOPLEFT", sectionGap, -sectionGap) sectionTitle.title = sectionTitle:CreateFontString(nil, "OVERLAY", "CELL_FONT_CLASS_TITLE") sectionTitle.title:SetText(L[which]) sectionTitle.title:SetScale(1.2) sectionTitle.title:SetPoint("TOPLEFT") - ---@type CellColorPicker - local prevCp - local numRows, cpInRow, rowLength = 1, 0, 0 + local gridLayout = { + maxColumns = 3, + currentRow = 1, + currentColumn = 1, + currentColumnWidth = sectionGap * 2 + } ---@type table local colorTable = colorTables[which] - for _, colorName in ipairs(order) do - ---@class CUF.ColorSection.ColorPicker: CellColorPicker - local cp = Cell:CreateColorPicker(section, L[colorName], true) - cp.id = colorName - cp:SetColor(colorTable[colorName]) - cp.onChange = function(r, g, b, a) - DB.SetColor(which, colorName, { r, g, b, a }) - CUF:Fire("UpdateWidget", DB.GetMasterLayout(), nil, which, const.OPTION_KIND.COLOR) + for _, info in ipairs(order) do + local colorName, colorType = info[1], info[2] + local element, elementWidth + + if colorType == "seperator" then + element = CreateSperatorTitle(colorName, section) + gridLayout.currentColumn = 1 + gridLayout.currentRow = gridLayout.currentRow + 1 + gridLayout.currentColumnWidth = section:GetWidth() + elseif colorType == "rgb" then + element, elementWidth = CreateColorPicker(which, colorName, colorTable, section) + + -- Move to the next column, or wrap to the next row if necessary + if gridLayout.currentColumn > gridLayout.maxColumns + or (gridLayout.currentColumnWidth + elementWidth) > (section:GetWidth()) then + gridLayout.currentColumn = 1 + gridLayout.currentRow = gridLayout.currentRow + 1 + gridLayout.currentColumnWidth = sectionGap * 2 + end + + gridLayout.currentColumnWidth = gridLayout.currentColumnWidth + elementWidth + + tinsert(section.cps, element) end - local cpWidth = cp:GetWidth() + cp.label:GetWidth() - - -- First ColorPicker - if not prevCp then - cp:SetPoint("TOPLEFT", sectionTitle, "BOTTOMLEFT", 0, -heightPerCp) - elseif rowLength + cpWidth > section:GetWidth() or cpInRow == 3 then - -- Check if cp will fit in the row - numRows, cpInRow, rowLength = numRows + 1, 0, 0 - cp:SetPoint("TOPLEFT", sectionTitle, "BOTTOMLEFT", 0, -(heightPerCp * numRows)) + -- Position the element in the grid + if gridLayout.currentColumn == 1 then + -- Start of a new row + element:SetPoint("TOPLEFT", sectionTitle, "BOTTOMLEFT", 0, -(heightPerCp * gridLayout.currentRow)) else - -- New row - cp:SetPoint("TOPLEFT", prevCp, "TOPRIGHT", cpGap, 0) - rowLength = rowLength + (cpGap / 2) + -- Position to the right of the previous element + element:SetPoint("TOPLEFT", section.cps[#section.cps - 1], "TOPRIGHT", cpGap, 0) end - cpInRow = cpInRow + 1 - rowLength = rowLength + cpWidth - prevCp = cp - - tinsert(section.cps, cp) + gridLayout.currentColumn = gridLayout.currentColumn + 1 end - section:SetHeight(40 + numRows * heightPerCp) + section:SetHeight(40 + gridLayout.currentRow * heightPerCp) if not prevSection then self.window:SetHeight(self.importExportSection:GetHeight() + section:GetHeight() + (sectionGap * 2)) From 5bbf5dee02cbf207548de86ffa0b10bd8656c074 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 17:00:07 +0200 Subject: [PATCH 15/27] make GetTextures generic --- Menu/Builder.lua | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Menu/Builder.lua b/Menu/Builder.lua index 2b87932..7cb8191 100644 --- a/Menu/Builder.lua +++ b/Menu/Builder.lua @@ -1047,19 +1047,15 @@ end local LSM = LibStub("LibSharedMedia-3.0", true) local textures -local textureToName = {} +Builder.textureToName = {} ----@class TextureDropdownItem ----@field [1] string ----@field [2] Texture - ----@return TextureDropdownItem[] -local function GetTextures() +---@return table +function Builder:GetTextures() if textures then return textures end textures = F:Copy(LSM:HashTable("statusbar")) for name, texture in pairs(textures) do - textureToName[texture] = name + Builder.textureToName[texture] = name end return textures @@ -1081,7 +1077,7 @@ function Builder:CreateTextureDropdown(parent, widgetName, path) textureDropdown.Get_DB = HandleWidgetOption local textureDropdownItems = {} - for name, tex in pairs(GetTextures()) do + for name, tex in pairs(self:GetTextures()) do tinsert(textureDropdownItems, { ["text"] = name, ["texture"] = tex, @@ -1094,7 +1090,7 @@ function Builder:CreateTextureDropdown(parent, widgetName, path) local function LoadPageDB() local tex = textureDropdown.Get_DB(widgetName, path) - textureDropdown:SetSelected(textureToName[tex], tex) + textureDropdown:SetSelected(Builder.textureToName[tex], tex) end Handler:RegisterOption(LoadPageDB, widgetName, "TextureDropdown_" .. path) From 2ec342e54c0e258c35de4a599fd15d20dfdfeba8 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 17:00:21 +0200 Subject: [PATCH 16/27] add support for texture dropdowns --- Data/Database.lua | 2 +- Data/Defaults.lua | 2 ++ Locales/enUS.lua | 1 + Menu/ColorTab.lua | 88 ++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 80 insertions(+), 13 deletions(-) diff --git a/Data/Database.lua b/Data/Database.lua index 084c257..9e1da1c 100644 --- a/Data/Database.lua +++ b/Data/Database.lua @@ -119,7 +119,7 @@ end --- Sets the color of a specific color type ---@param which Defaults.Colors.Types ---@param colorName string ----@param val RGBAOpt +---@param val RGBAOpt|string function DB.SetColor(which, colorName, val) DB.GetColors()[which][colorName] = val end diff --git a/Data/Defaults.lua b/Data/Defaults.lua index 3fdd805..6dc2cf0 100644 --- a/Data/Defaults.lua +++ b/Data/Defaults.lua @@ -111,6 +111,7 @@ Defaults.Options.fontWidth = { ---@class Defaults.Colors Defaults.Colors = { castBar = { + texture = "Interface\\Buttons\\WHITE8X8", interruptible = { 0.2, 0.57, 0.5, 1 }, nonInterruptible = { 0.43, 0.43, 0.43, 1 }, background = { 0, 0, 0, 0.8 }, @@ -125,6 +126,7 @@ Defaults.Colors = { Defaults.ColorsMenuOrder = { castBar = { + { "texture", "texture" }, { "background", "rgb" }, { "interruptible", "rgb" }, { "nonInterruptible", "rgb" }, diff --git a/Locales/enUS.lua b/Locales/enUS.lua index bd7fbff..9996741 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -147,6 +147,7 @@ L.Backup_automatic = "Automatic Backup" L.HideDefaultCastBar = "Hide Default Cast Bar" L.HideDefaultCastBarTooltip = [[Hides the default cast bar. Reload to show it again after disabling this option.]] +L.texture = "Texture" -- Custom Formats L.ValidTags = "Valid Tags" diff --git a/Menu/ColorTab.lua b/Menu/ColorTab.lua index 7744d73..9b8ce9d 100644 --- a/Menu/ColorTab.lua +++ b/Menu/ColorTab.lua @@ -8,6 +8,7 @@ local DB = CUF.DB local Menu = CUF.Menu local Util = CUF.Util local const = CUF.constants +local Builder = CUF.Builder ---@class ColorTab: Menu.Tab local ColorTab = {} @@ -66,6 +67,9 @@ function ColorTab:UpdateColors() for _, cp in pairs(section.cps) do cp:SetColor(colorTable[cp.id]) end + for _, dropdown in pairs(section.dropdowns) do + dropdown:SetSelected(Builder.textureToName[colorTable[dropdown.id]], colorTable[dropdown.id]) + end end end @@ -96,20 +100,50 @@ end ---@return Frame local function CreateSperatorTitle(title, parent) local sectionTitle = CUF:CreateFrame(nil, parent, 1, 1, true, true) --[[@as OptionTitle]] - sectionTitle:SetPoint("TOPLEFT", 0, -10) + sectionTitle:SetPoint("TOPLEFT") sectionTitle.title = sectionTitle:CreateFontString(nil, "OVERLAY", "CELL_FONT_CLASS_TITLE") sectionTitle.title:SetText(L[title]) sectionTitle.title:SetScale(1) sectionTitle.title:SetPoint("TOPLEFT") + sectionTitle:SetHeight(sectionTitle.title:GetStringHeight()) return sectionTitle end +---- Create a texture dropdown +---@param which Defaults.Colors.Types +---@param colorName string +---@param colorTable table +---@param parent Frame +---@return Frame +local function CreateTextureDropdown(which, colorName, colorTable, parent) + ---@class CUF.ColorSection.Dropdown: CellDropdown + local textureDropdown = Cell:CreateDropdown(parent, 160, "texture") + textureDropdown:SetLabel(L[colorName]) + textureDropdown.id = colorName + + local textureDropdownItems = {} + for name, tex in pairs(Builder:GetTextures()) do + tinsert(textureDropdownItems, { + ["text"] = name, + ["texture"] = tex, + ["onClick"] = function() + DB.SetColor(which, colorName, tex) + end, + }) + end + textureDropdown:SetItems(textureDropdownItems) + textureDropdown:SetSelected(Builder.textureToName[colorTable[colorName]], colorTable[colorName]) + + return textureDropdown +end + --- Create sections with color pickers for each color type function ColorTab:CreateSections() local heightPerCp = 25 local cpGap = (self.window:GetWidth() / 3) * 0.80 local sectionGap = 10 + local baseHeight = 40 self.colorSections = {} ---@type CUF.ColorSection[] @@ -123,6 +157,7 @@ function ColorTab:CreateSections() self.window, self.window:GetWidth(), 1, false, true) section.id = which section.cps = {} ---@type CUF.ColorSection.ColorPicker[] + section.dropdowns = {} ---@type CUF.ColorSection.Dropdown[] local sectionTitle = CUF:CreateFrame(nil, section, 1, 1, true, true) --[[@as OptionTitle]] sectionTitle:SetPoint("TOPLEFT", sectionGap, -sectionGap) @@ -130,12 +165,14 @@ function ColorTab:CreateSections() sectionTitle.title:SetText(L[which]) sectionTitle.title:SetScale(1.2) sectionTitle.title:SetPoint("TOPLEFT") + sectionTitle:SetHeight(sectionTitle.title:GetStringHeight()) local gridLayout = { maxColumns = 3, currentRow = 1, currentColumn = 1, - currentColumnWidth = sectionGap * 2 + currentColumnWidth = sectionGap * 2, + firstInRow = nil } ---@type table @@ -147,8 +184,31 @@ function ColorTab:CreateSections() if colorType == "seperator" then element = CreateSperatorTitle(colorName, section) gridLayout.currentColumn = 1 + gridLayout.currentColumnWidth = section:GetWidth() gridLayout.currentRow = gridLayout.currentRow + 1 + + element:SetPoint("TOPLEFT", gridLayout.firstInRow, "BOTTOMLEFT", 0, -sectionGap) + gridLayout.firstInRow = element + elseif colorType == "texture" then + element = CreateTextureDropdown(which, colorName, colorTable, section) + gridLayout.currentColumn = 1 gridLayout.currentColumnWidth = section:GetWidth() + + if gridLayout.currentRow > 1 then + gridLayout.currentRow = gridLayout.currentRow + 1 + end + + baseHeight = baseHeight + 10 + + -- Start of a new row + if not gridLayout.firstInRow then + element:SetPoint("TOPLEFT", sectionTitle, "BOTTOMLEFT", 0, -sectionGap * 2.5) + else + element:SetPoint("TOPLEFT", gridLayout.firstInRow, "BOTTOMLEFT", 0, -sectionGap * 2.5) + end + gridLayout.firstInRow = element + + tinsert(section.dropdowns, element) elseif colorType == "rgb" then element, elementWidth = CreateColorPicker(which, colorName, colorTable, section) @@ -161,23 +221,27 @@ function ColorTab:CreateSections() end gridLayout.currentColumnWidth = gridLayout.currentColumnWidth + elementWidth - tinsert(section.cps, element) - end - -- Position the element in the grid - if gridLayout.currentColumn == 1 then - -- Start of a new row - element:SetPoint("TOPLEFT", sectionTitle, "BOTTOMLEFT", 0, -(heightPerCp * gridLayout.currentRow)) - else - -- Position to the right of the previous element - element:SetPoint("TOPLEFT", section.cps[#section.cps - 1], "TOPRIGHT", cpGap, 0) + -- Position the element in the grid + if gridLayout.currentColumn == 1 then + -- Start of a new row + if not gridLayout.firstInRow then + element:SetPoint("TOPLEFT", sectionTitle, "BOTTOMLEFT", 0, -sectionGap) + else + element:SetPoint("TOPLEFT", gridLayout.firstInRow, "BOTTOMLEFT", 0, -sectionGap) + end + gridLayout.firstInRow = element + else + -- Position to the right of the previous element + element:SetPoint("TOPLEFT", section.cps[#section.cps - 1], "TOPRIGHT", cpGap, 0) + end end gridLayout.currentColumn = gridLayout.currentColumn + 1 end - section:SetHeight(40 + gridLayout.currentRow * heightPerCp) + section:SetHeight(baseHeight + gridLayout.currentRow * heightPerCp) if not prevSection then self.window:SetHeight(self.importExportSection:GetHeight() + section:GetHeight() + (sectionGap * 2)) From 91b7410b61827e6e95644314ac02f5e021aa3b40 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 17:02:56 +0200 Subject: [PATCH 17/27] Fire UpdateWidget event when updating texture --- Menu/ColorTab.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/Menu/ColorTab.lua b/Menu/ColorTab.lua index 9b8ce9d..f2d03a0 100644 --- a/Menu/ColorTab.lua +++ b/Menu/ColorTab.lua @@ -129,6 +129,7 @@ local function CreateTextureDropdown(which, colorName, colorTable, parent) ["texture"] = tex, ["onClick"] = function() DB.SetColor(which, colorName, tex) + CUF:Fire("UpdateWidget", DB.GetMasterLayout(), nil, which, const.OPTION_KIND.COLOR) end, }) end From f43ee67194ed33efb3871d3c4270c0a6d1198901 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 17:03:22 +0200 Subject: [PATCH 18/27] use global texture for Cast Bar --- Widgets/Bars/CastBar.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Widgets/Bars/CastBar.lua b/Widgets/Bars/CastBar.lua index 30eca54..6d38512 100644 --- a/Widgets/Bars/CastBar.lua +++ b/Widgets/Bars/CastBar.lua @@ -38,9 +38,6 @@ function W.UpdateCastBarWidget(button, unit, setting, subSetting, ...) 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 - castBar.statusBar:SetStatusBarTexture(styleTable.color.texture) - end if not subSetting or subSetting == const.OPTION_KIND.USE_CLASS_COLOR then castBar.useClassColor = styleTable.color.useClassColor end @@ -758,6 +755,8 @@ local function SetCastBarColorStyle(self) self.interruptibleColor = colors.interruptible self.nonInterruptibleColor = colors.nonInterruptible self.background:SetVertexColor(unpack(colors.background)) + + self.statusBar:SetStatusBarTexture(colors.texture) end ---@param self CastBarWidget From e842af5c0baeae8ca0fae9c93490955557faeb15 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 17:06:15 +0200 Subject: [PATCH 19/27] remove old empower color options --- Menu/Builder.lua | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/Menu/Builder.lua b/Menu/Builder.lua index 7cb8191..ca612cf 100644 --- a/Menu/Builder.lua +++ b/Menu/Builder.lua @@ -1465,7 +1465,7 @@ function Builder:CreateCastBarEmpowerOptions(parent, widgetName) ---@class CastBarEmpowerOptions: OptionsFrame local f = CUF:CreateFrame(nil, parent, 1, 1, true, true) f.id = "CastBarEmpowerOptions" - f.optionHeight = 170 + f.optionHeight = 60 -- Title f.title = self:CreateOptionTitle(f, "Empower") @@ -1482,41 +1482,6 @@ function Builder:CreateCastBarEmpowerOptions(parent, widgetName) f.showEmpowerName:SetPoint("TOPLEFT", f.useFullyCharged, "TOPLEFT", (self.spacingX * 1.5) + f.useFullyCharged.label:GetWidth(), 0) - -- Second Row - local colorPath = const.OPTION_KIND.EMPOWER .. "." .. const.OPTION_KIND.PIP_COLORS .. "." - - f.stageZero = self:CreateColorPickerOptions(f, widgetName, - L.Stage .. " " .. 0 .. " " .. L["Color"], - colorPath .. const.OPTION_KIND.STAGE_ZERO) - self:AnchorBelow(f.stageZero, f.useFullyCharged) - - f.stageOne = self:CreateColorPickerOptions(f, widgetName, - L.Stage .. " " .. 1 .. " " .. L["Color"], - colorPath .. const.OPTION_KIND.STAGE_ONE) - self:AnchorRightOfColorPicker(f.stageOne, f.stageZero) - - f.stageTwo = self:CreateColorPickerOptions(f, widgetName, - L.Stage .. " " .. 2 .. " " .. L["Color"], - colorPath .. const.OPTION_KIND.STAGE_TWO) - self:AnchorRightOfColorPicker(f.stageTwo, f.stageOne) - - -- Third Row - f.stageThree = self:CreateColorPickerOptions(f, widgetName, - L.Stage .. " " .. 3 .. " " .. L["Color"], - colorPath .. const.OPTION_KIND.STAGE_THREE) - self:AnchorBelowCB(f.stageThree, f.stageZero) - - f.stageFour = self:CreateColorPickerOptions(f, widgetName, - L.Stage .. " " .. 4 .. " " .. L["Color"], - colorPath .. const.OPTION_KIND.STAGE_FOUR) - self:AnchorRightOfColorPicker(f.stageFour, f.stageThree) - - -- Fourth Row - f.fullyCharged = self:CreateColorPickerOptions(f, widgetName, - L.FullyCharged .. " " .. L["Color"], - colorPath .. const.OPTION_KIND.FULLY_CHARGED) - self:AnchorBelowCB(f.fullyCharged, f.stageThree) - return f end From 72583f681a7c81be8abfd6ab5b5555c202161fa6 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 17:10:01 +0200 Subject: [PATCH 20/27] remove old color options for cast bar --- Menu/Builder.lua | 39 ++------------------------------------- Widgets/Bars/CastBar.lua | 1 - 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/Menu/Builder.lua b/Menu/Builder.lua index ca612cf..f1d27d0 100644 --- a/Menu/Builder.lua +++ b/Menu/Builder.lua @@ -43,7 +43,6 @@ Builder.MenuOptions = { FullAnchor = 19, ColorPicker = 20, CastBarGeneral = 21, - CastBarColor = 22, CastBarTimer = 23, CastBarSpell = 24, CastBarSpark = 25, @@ -1352,42 +1351,9 @@ function Builder:CreateCastBarGeneralOptions(parent, widgetName) f.reverseCB = self:CreateCheckBox(f, widgetName, L.Reverse, const.OPTION_KIND.REVERSE) self:AnchorBelow(f.reverseCB, f.anchorOptions.relativeDropdown) - return f -end - ----@param parent Frame ----@param widgetName WIDGET_KIND ----@return CastBarColorOptions -function Builder:CreateCastBarColorOptions(parent, widgetName) - ---@class CastBarColorOptions: OptionsFrame - local f = CUF:CreateFrame(nil, parent, 1, 1, true, true) - f.id = "CastBarColorOptions" - f.optionHeight = 110 - - -- Title - f.title = self:CreateOptionTitle(f, "Colors") - local path = const.OPTION_KIND.COLOR .. "." - - -- First Row - f.texture = self:CreateTextureDropdown(f, widgetName, path .. const.OPTION_KIND.TEXTURE) - self:AnchorBelow(f.texture, f.title) - f.classColorCB = self:CreateCheckBox(f, widgetName, L.UseClassColor, - path .. const.OPTION_KIND.USE_CLASS_COLOR) - self:AnchorRight(f.classColorCB, f.texture) - - -- Second Row - f.interruptible = self:CreateColorPickerOptions(f, widgetName, L.Interruptible, - path .. const.OPTION_KIND.INTERRUPTIBLE) - self:AnchorBelow(f.interruptible, f.texture) - - f.nonInterruptible = self:CreateColorPickerOptions(f, widgetName, L.NonInterruptible, - path .. const.OPTION_KIND.NON_INTERRUPTIBLE) - self:AnchorRightOfColorPicker(f.nonInterruptible, f.interruptible) - - f.background = self:CreateColorPickerOptions(f, widgetName, L.Background, - path .. const.OPTION_KIND.BACKGROUND) - self:AnchorRightOfColorPicker(f.background, f.nonInterruptible) + const.OPTION_KIND.COLOR .. "." .. const.OPTION_KIND.USE_CLASS_COLOR) + self:AnchorRightOfCB(f.classColorCB, f.reverseCB) return f end @@ -1576,7 +1542,6 @@ Builder.MenuFuncs = { [Builder.MenuOptions.FrameLevel] = Builder.CreateFrameLevelOptions, [Builder.MenuOptions.ColorPicker] = Builder.CreateColorPickerOptions, [Builder.MenuOptions.CastBarGeneral] = Builder.CreateCastBarGeneralOptions, - [Builder.MenuOptions.CastBarColor] = Builder.CreateCastBarColorOptions, [Builder.MenuOptions.CastBarTimer] = Builder.CreateCastBarTimerFontOptions, [Builder.MenuOptions.CastBarSpell] = Builder.CreateCastBarSpellFontOptions, [Builder.MenuOptions.CastBarSpark] = Builder.CreateCastBarSparkOptions, diff --git a/Widgets/Bars/CastBar.lua b/Widgets/Bars/CastBar.lua index 6d38512..77e954e 100644 --- a/Widgets/Bars/CastBar.lua +++ b/Widgets/Bars/CastBar.lua @@ -20,7 +20,6 @@ local Handler = CUF.Handler menu:AddWidget(const.WIDGET_KIND.CAST_BAR, Builder.MenuOptions.CastBarGeneral, - Builder.MenuOptions.CastBarColor, Builder.MenuOptions.CastBarEmpower, Builder.MenuOptions.CastBarTimer, Builder.MenuOptions.CastBarSpell, From 67286a628a876554c56a9fd368adab4b2f45d58f Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 17:19:22 +0200 Subject: [PATCH 21/27] update db structure for cast bar --- Data/Defaults.lua | 16 +--------------- Menu/Builder.lua | 3 +-- WidgetAnnotations.lua | 16 ---------------- Widgets/Bars/CastBar.lua | 6 +++--- 4 files changed, 5 insertions(+), 36 deletions(-) diff --git a/Data/Defaults.lua b/Data/Defaults.lua index 6dc2cf0..c124bae 100644 --- a/Data/Defaults.lua +++ b/Data/Defaults.lua @@ -401,6 +401,7 @@ Defaults.Widgets = { ---@type CastBarWidgetTable castBar = { enabled = false, + useClassColor = true, frameLevel = 10, position = { point = "TOPLEFT", @@ -412,13 +413,6 @@ Defaults.Widgets = { width = 200, height = 30, }, - color = { - texture = "Interface\\AddOns\\Cell\\Media\\statusbar.tga", - useClassColor = true, - interruptible = { 0.2, 0.57, 0.5, 1 }, - nonInterruptible = { 0.43, 0.43, 0.43, 1 }, - background = { 0, 0, 0, 0.8 }, - }, reverse = false, timer = { enabled = true, @@ -453,14 +447,6 @@ Defaults.Widgets = { empower = { useFullyCharged = true, showEmpowerName = false, - pipColors = { - stageZero = { 0.2, 0.57, 0.5, 1 }, - stageOne = { 0.3, 0.47, 0.45, 1 }, - stageTwo = { 0.4, 0.4, 0.4, 1 }, - stageThree = { 0.54, 0.3, 0.3, 1 }, - stageFour = { 0.65, 0.2, 0.3, 1 }, - fullyCharged = { 0.77, 0.1, 0.2, 1 }, - } }, border = { showBorder = true, diff --git a/Menu/Builder.lua b/Menu/Builder.lua index f1d27d0..ce2c500 100644 --- a/Menu/Builder.lua +++ b/Menu/Builder.lua @@ -1351,8 +1351,7 @@ function Builder:CreateCastBarGeneralOptions(parent, widgetName) f.reverseCB = self:CreateCheckBox(f, widgetName, L.Reverse, const.OPTION_KIND.REVERSE) self:AnchorBelow(f.reverseCB, f.anchorOptions.relativeDropdown) - f.classColorCB = self:CreateCheckBox(f, widgetName, L.UseClassColor, - const.OPTION_KIND.COLOR .. "." .. const.OPTION_KIND.USE_CLASS_COLOR) + f.classColorCB = self:CreateCheckBox(f, widgetName, L.UseClassColor, const.OPTION_KIND.USE_CLASS_COLOR) self:AnchorRightOfCB(f.classColorCB, f.reverseCB) return f diff --git a/WidgetAnnotations.lua b/WidgetAnnotations.lua index 6878c21..9f91e8b 100644 --- a/WidgetAnnotations.lua +++ b/WidgetAnnotations.lua @@ -193,7 +193,6 @@ ---@field frameLevel number ---@field position PositionOpt ---@field size SizeOpt ----@field color CastBarColorsOpt ---@field reverse boolean ---@field timer BigFontOpt ---@field timerFormat CastBarTimerFormat @@ -204,13 +203,7 @@ ---@field empower EmpowerOpt ---@field border BorderOpt ---@field icon CastBarIconOpt - ----@class CastBarColorsOpt ----@field texture string ---@field useClassColor boolean ----@field interruptible RGBAOpt ----@field nonInterruptible RGBAOpt ----@field background RGBAOpt ---@class CastBarSparkOpt ---@field enabled boolean @@ -223,18 +216,9 @@ ---@field zoom number ---@class EmpowerOpt ----@field pipColors EmpowerColorOpt ---@field useFullyCharged boolean ---@field showEmpowerName boolean ----@class EmpowerColorOpt ----@field stageZero RGBAOpt ----@field stageOne RGBAOpt ----@field stageTwo RGBAOpt ----@field stageThree RGBAOpt ----@field stageFour RGBAOpt ----@field fullyCharged RGBAOpt - ------------------------------------------------- -- MARK: Generic Options ------------------------------------------------- diff --git a/Widgets/Bars/CastBar.lua b/Widgets/Bars/CastBar.lua index 77e954e..525c28d 100644 --- a/Widgets/Bars/CastBar.lua +++ b/Widgets/Bars/CastBar.lua @@ -37,11 +37,11 @@ function W.UpdateCastBarWidget(button, unit, setting, subSetting, ...) 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.USE_CLASS_COLOR then - castBar.useClassColor = styleTable.color.useClassColor - end castBar:SetCastBarColorStyle() end + if not setting or setting == const.OPTION_KIND.USE_CLASS_COLOR then + castBar.useClassColor = styleTable.useClassColor + end if not setting or setting == const.OPTION_KIND.TIMER then castBar.timerText:SetFontStyle(styleTable.timer) From 6ae74c6fe5893c7fcf7d898087e50cf11a3f9daa Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 19:08:41 +0200 Subject: [PATCH 22/27] update sizing logic --- Menu/ColorTab.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Menu/ColorTab.lua b/Menu/ColorTab.lua index f2d03a0..f9ff421 100644 --- a/Menu/ColorTab.lua +++ b/Menu/ColorTab.lua @@ -141,10 +141,9 @@ end --- Create sections with color pickers for each color type function ColorTab:CreateSections() - local heightPerCp = 25 + local heightPerCp = 30 local cpGap = (self.window:GetWidth() / 3) * 0.80 local sectionGap = 10 - local baseHeight = 40 self.colorSections = {} ---@type CUF.ColorSection[] @@ -175,6 +174,7 @@ function ColorTab:CreateSections() currentColumnWidth = sectionGap * 2, firstInRow = nil } + local baseHeight = 35 ---@type table local colorTable = colorTables[which] @@ -190,6 +190,7 @@ function ColorTab:CreateSections() element:SetPoint("TOPLEFT", gridLayout.firstInRow, "BOTTOMLEFT", 0, -sectionGap) gridLayout.firstInRow = element + baseHeight = baseHeight + element:GetHeight() + sectionGap elseif colorType == "texture" then element = CreateTextureDropdown(which, colorName, colorTable, section) gridLayout.currentColumn = 1 @@ -199,8 +200,6 @@ function ColorTab:CreateSections() gridLayout.currentRow = gridLayout.currentRow + 1 end - baseHeight = baseHeight + 10 - -- Start of a new row if not gridLayout.firstInRow then element:SetPoint("TOPLEFT", sectionTitle, "BOTTOMLEFT", 0, -sectionGap * 2.5) @@ -209,6 +208,8 @@ function ColorTab:CreateSections() end gridLayout.firstInRow = element + baseHeight = baseHeight + element:GetHeight() + sectionGap * 2.5 + tinsert(section.dropdowns, element) elseif colorType == "rgb" then element, elementWidth = CreateColorPicker(which, colorName, colorTable, section) @@ -233,6 +234,7 @@ function ColorTab:CreateSections() element:SetPoint("TOPLEFT", gridLayout.firstInRow, "BOTTOMLEFT", 0, -sectionGap) end gridLayout.firstInRow = element + baseHeight = baseHeight + element:GetHeight() + sectionGap else -- Position to the right of the previous element element:SetPoint("TOPLEFT", section.cps[#section.cps - 1], "TOPRIGHT", cpGap, 0) @@ -242,7 +244,7 @@ function ColorTab:CreateSections() gridLayout.currentColumn = gridLayout.currentColumn + 1 end - section:SetHeight(baseHeight + gridLayout.currentRow * heightPerCp) + section:SetHeight(baseHeight --[[ + gridLayout.currentRow * heightPerCp ]]) if not prevSection then self.window:SetHeight(self.importExportSection:GetHeight() + section:GetHeight() + (sectionGap * 2)) From 54027e6739a6f1cb910462db3307ca51067b3dbf Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 20:21:20 +0200 Subject: [PATCH 23/27] add reaction colors --- Data/Defaults.lua | 13 +++++++++++++ Locales/enUS.lua | 5 +++++ Util/Utils.lua | 11 ++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Data/Defaults.lua b/Data/Defaults.lua index c124bae..ff6ed72 100644 --- a/Data/Defaults.lua +++ b/Data/Defaults.lua @@ -107,6 +107,7 @@ Defaults.Options.fontWidth = { ---@alias Defaults.Colors.Types ---| "castBar" +---| "reaction" ---@class Defaults.Colors Defaults.Colors = { @@ -122,6 +123,12 @@ Defaults.Colors = { stageFour = { 0.65, 0.2, 0.3, 1 }, fullyCharged = { 0.77, 0.1, 0.2, 1 }, }, + reaction = { + friendly = { 0.29, 0.69, 0.3, 1 }, + hostile = { 0.78, 0.25, 0.25, 1 }, + neutral = { 0.85, 0.77, 0.36, 1 }, + pet = { 0.29, 0.69, 0.3, 1 }, + }, } Defaults.ColorsMenuOrder = { @@ -138,6 +145,12 @@ Defaults.ColorsMenuOrder = { { "stageFour", "rgb" }, { "fullyCharged", "rgb" } }, + reaction = { + { "friendly", "rgb" }, + { "hostile", "rgb" }, + { "neutral", "rgb" }, + { "pet", "rgb" }, + }, } ------------------------------------------------- diff --git a/Locales/enUS.lua b/Locales/enUS.lua index 9996741..c30a5c1 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -194,4 +194,9 @@ L.holyPower = "Holy Power" L.arcaneCharges = "Arcane Charges" L.soulShards = "Soul Shards" +L.reaction = "Reaction" +L.friendly = "Friendly" +L.hostile = "Hostile" +L.neutral = "Neutral" + L.ImportExportColors = "Import & Export Color Settings" diff --git a/Util/Utils.lua b/Util/Utils.lua index 23c3794..031262d 100644 --- a/Util/Utils.lua +++ b/Util/Utils.lua @@ -3,6 +3,7 @@ local CUF = select(2, ...) local Cell = CUF.Cell local F = Cell.funcs +local DB = CUF.DB ---@class CUF.Util local Util = CUF.Util @@ -251,25 +252,25 @@ function Util:GetUnitClassColor(unit, class, guid) -- Friendly if selectionType == 3 then - return unpack(CUF.constants.COLORS.FRIENDLY) + return unpack(DB.GetColors().reaction.friendly) end -- Hostile if selectionType == 0 then - return unpack(CUF.constants.COLORS.HOSTILE) + return unpack(DB.GetColors().reaction.hostile) end -- Pet if selectionType == 4 then if UnitIsEnemy(unit, "player") then - return unpack(CUF.constants.COLORS.HOSTILE) + return unpack(DB.GetColors().reaction.hostile) end - return unpack(CUF.constants.COLORS.FRIENDLY) + return unpack(DB.GetColors().reaction.pet) end -- Neutral - return unpack(CUF.constants.COLORS.NEUTRAL) + return unpack(DB.GetColors().reaction.neutral) end --- Converts a dictionary table to an array eg. From c61b57bb6ac465a1c8c01eed74bda555d22eac48 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 20:54:38 +0200 Subject: [PATCH 24/27] reshuffle --- Menu/ColorTab.lua | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/Menu/ColorTab.lua b/Menu/ColorTab.lua index f9ff421..4ede3bc 100644 --- a/Menu/ColorTab.lua +++ b/Menu/ColorTab.lua @@ -55,24 +55,9 @@ function ColorTab:CreateImportExport() end ------------------------------------------------- --- MARK: Sections +-- MARK: Elements ------------------------------------------------- ---- Update all color pickers with the current color table ---- ---- This is called when a new color table is imported -function ColorTab:UpdateColors() - for _, section in pairs(self.colorSections) do - local colorTable = DB.GetColors()[section.id] - for _, cp in pairs(section.cps) do - cp:SetColor(colorTable[cp.id]) - end - for _, dropdown in pairs(section.dropdowns) do - dropdown:SetSelected(Builder.textureToName[colorTable[dropdown.id]], colorTable[dropdown.id]) - end - end -end - --- Create a color picker ---@param which Defaults.Colors.Types ---@param colorName string @@ -139,6 +124,25 @@ local function CreateTextureDropdown(which, colorName, colorTable, parent) return textureDropdown end +------------------------------------------------- +-- MARK: Sections +------------------------------------------------- + +--- Update all color pickers with the current color table +--- +--- This is called when a new color table is imported +function ColorTab:UpdateColors() + for _, section in pairs(self.colorSections) do + local colorTable = DB.GetColors()[section.id] + for _, cp in pairs(section.cps) do + cp:SetColor(colorTable[cp.id]) + end + for _, dropdown in pairs(section.dropdowns) do + dropdown:SetSelected(Builder.textureToName[colorTable[dropdown.id]], colorTable[dropdown.id]) + end + end +end + --- Create sections with color pickers for each color type function ColorTab:CreateSections() local heightPerCp = 30 From 657588c3a6ce8a3d303add1fc5c41592a86b2e64 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Tue, 3 Sep 2024 22:56:08 +0200 Subject: [PATCH 25/27] add scroll frame --- Menu/ColorTab.lua | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/Menu/ColorTab.lua b/Menu/ColorTab.lua index 4ede3bc..a3d64a4 100644 --- a/Menu/ColorTab.lua +++ b/Menu/ColorTab.lua @@ -14,6 +14,7 @@ local Builder = CUF.Builder local ColorTab = {} ColorTab.id = "colorTab" ColorTab.paneHeight = 17 +ColorTab.sectionsHeight = 0 ------------------------------------------------- -- MARK: Import / Export @@ -145,10 +146,19 @@ end --- Create sections with color pickers for each color type function ColorTab:CreateSections() - local heightPerCp = 30 local cpGap = (self.window:GetWidth() / 3) * 0.80 local sectionGap = 10 + ---@class ColorTab.colorSection: Frame + ---@field scrollFrame CellScrollFrame + local colorSection = CUF:CreateFrame("CUF_Menu_ColorSection", self.window, + self.window:GetWidth(), + self.window:GetHeight() - self.importExportSection:GetHeight() - (sectionGap * 2), true, true) + colorSection:SetPoint("TOPLEFT", self.importExportSection, "BOTTOMLEFT", 0, -sectionGap) + + Cell:CreateScrollFrame(colorSection) + colorSection.scrollFrame:SetScrollStep(50) + self.colorSections = {} ---@type CUF.ColorSection[] local prevSection @@ -157,8 +167,8 @@ function ColorTab:CreateSections() for which, order in pairs(colorOrder) do ---@class CUF.ColorSection: Frame - local section = CUF:CreateFrame("ColorSection_" .. Util:ToTitleCase(which), - self.window, self.window:GetWidth(), 1, false, true) + local section = CUF:CreateFrame(colorSection:GetName() .. "_" .. Util:ToTitleCase(which), + colorSection.scrollFrame.content, self.window:GetWidth() - 10, 1, false, true) section.id = which section.cps = {} ---@type CUF.ColorSection.ColorPicker[] section.dropdowns = {} ---@type CUF.ColorSection.Dropdown[] @@ -248,19 +258,20 @@ function ColorTab:CreateSections() gridLayout.currentColumn = gridLayout.currentColumn + 1 end - section:SetHeight(baseHeight --[[ + gridLayout.currentRow * heightPerCp ]]) + section:SetHeight(baseHeight) + self.sectionsHeight = self.sectionsHeight + baseHeight + sectionGap if not prevSection then - self.window:SetHeight(self.importExportSection:GetHeight() + section:GetHeight() + (sectionGap * 2)) - section:SetPoint("TOPLEFT", self.importExportSection, "BOTTOMLEFT", 0, -sectionGap) + section:SetPoint("TOPLEFT", colorSection.scrollFrame.content) else - self.window:SetHeight(self.window:GetHeight() + section:GetHeight() + sectionGap) section:SetPoint("TOPLEFT", prevSection, "BOTTOMLEFT", 0, -sectionGap) end prevSection = section tinsert(self.colorSections, section) end + + self.colorSection = colorSection end ------------------------------------------------- @@ -274,6 +285,9 @@ function ColorTab:ShowTab() end self.window:Show() + + self.colorSection.scrollFrame:SetContentHeight(self.sectionsHeight) + self.colorSection.scrollFrame:ResetScroll() end function ColorTab:HideTab() @@ -292,9 +306,9 @@ end function ColorTab:Create() local sectionWidth = Menu.tabAnchor:GetWidth() - self.window = CUF:CreateFrame("CUF_Menu_UnitFrame", Menu.window, + self.window = CUF:CreateFrame("CUF_Menu_Color", Menu.window, sectionWidth, - 0, true) + 335, true) self.window:SetPoint("TOPLEFT", Menu.tabAnchor, "TOPLEFT") self:CreateImportExport() From ae5936e2ea434d5b0da68e1838e41fd5a1681436 Mon Sep 17 00:00:00 2001 From: Vollmer Date: Wed, 4 Sep 2024 09:36:12 +0200 Subject: [PATCH 26/27] fire UpdateAppearance --- Menu/ColorTab.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Menu/ColorTab.lua b/Menu/ColorTab.lua index a3d64a4..8305315 100644 --- a/Menu/ColorTab.lua +++ b/Menu/ColorTab.lua @@ -72,7 +72,11 @@ local function CreateColorPicker(which, colorName, colorTable, parent) cp:SetColor(colorTable[colorName]) cp.onChange = function(r, g, b, a) DB.SetColor(which, colorName, { r, g, b, a }) - CUF:Fire("UpdateWidget", DB.GetMasterLayout(), nil, which, const.OPTION_KIND.COLOR) + if which == "castBar" then + CUF:Fire("UpdateWidget", DB.GetMasterLayout(), nil, which, const.OPTION_KIND.COLOR) + else + CUF:Fire("UpdateAppearance", "color") + end end local cpWidth = math.max(cp:GetWidth() + cp.label:GetWidth() + 5, (ColorTab.window:GetWidth() / 3) - 15) From 877fe647b049a0bce13d63aee8a8314e5dc7dbaf Mon Sep 17 00:00:00 2001 From: Vollmer Date: Wed, 4 Sep 2024 21:14:10 +0200 Subject: [PATCH 27/27] remove legacy locale --- Locales/enUS.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/Locales/enUS.lua b/Locales/enUS.lua index c30a5c1..a39b5a6 100644 --- a/Locales/enUS.lua +++ b/Locales/enUS.lua @@ -90,7 +90,6 @@ L["duration"] = "Duration" L["duration-and-max"] = "Duration & Max" L.ShowSpell = "Show Spell" L.Empower = "Empower" -L.Stage = "Stage" L.FullyCharged = "Fully Charged" L.UseFullyCharged = "Use Fully Charged" L.ShowEmpowerName = "Show Empower Name"