Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Profile options #43

Merged
merged 28 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a39e0d4
implement tab system for menu
Krealle Aug 31, 2024
985ce26
update annotations
Krealle Aug 31, 2024
b49fa0a
merge MenuFrame.lua into Menu.lua
Krealle Aug 31, 2024
15415e8
ensure LoadLayoutDB is called when UnitFramesTab is opened
Krealle Aug 31, 2024
be7ba2e
show and hide selected tab when menu hides
Krealle Aug 31, 2024
98297c4
prevent ShowMenu running when menu is already shown
Krealle Aug 31, 2024
cdf04e0
move Unit/Widget add fns into UnitFramesTab.lua
Krealle Aug 31, 2024
806f13c
Limit when LoadPageDB runs
Krealle Aug 31, 2024
a7f771c
OnLoad hide blizzard frames based on CurrentLayoutTable instead of Se…
Krealle Aug 31, 2024
45142df
implement GeneralTab
Krealle Aug 31, 2024
e8f85c7
impl MasterLayout DB fns
Krealle Aug 31, 2024
be3696a
properly update widgetList
Krealle Aug 31, 2024
5f2c970
use masterLayout for widgets profile
Krealle Aug 31, 2024
2b8c4a6
update layout when changing master layout
Krealle Aug 31, 2024
cb78bdb
check against master layout when updating unit button layout
Krealle Aug 31, 2024
30166f3
get raw value of masterlayout when determining which to use
Krealle Aug 31, 2024
36156d9
change remaining widget updates to use current widget table
Krealle Aug 31, 2024
f109760
update annotation for IterateAllUnitButtons
Krealle Aug 31, 2024
4bc207f
add tooltip for master layout
Krealle Aug 31, 2024
ec7ec81
update tab buttons positioning
Krealle Aug 31, 2024
2d3abd8
only set widget as selected when in correct layout
Krealle Aug 31, 2024
8bb97ae
better tooltip for master layout
Krealle Aug 31, 2024
c4508c7
add a title to the menu frame
Krealle Aug 31, 2024
8a3b870
impl copyLayoutFrom
Krealle Aug 31, 2024
9510c31
a bit of cleanup
Krealle Aug 31, 2024
81a6646
impl DB.CopyFullLayout
Krealle Aug 31, 2024
0c248cf
finish implementing copyLayoutFrom
Krealle Aug 31, 2024
c30ce71
make generalTab a bit shorter
Krealle Aug 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Annotations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Cell_UnitFrames.toc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ Core/SlashCommands.lua

Menu/Builder.lua
Menu/AuraFilterList.lua
Menu/MenuFrame.lua
Menu/Menu.lua
Menu/GeneralTab.lua
Menu/UnitFramesTab.lua

Widgets/Common.lua

Expand Down
1 change: 1 addition & 0 deletions Core/Init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ CUF.Builder = {}
---@field testMode boolean
---@field isMenuOpen boolean
---@field isRetail boolean
---@field selectedTab string
CUF.vars = {}
CUF.unitButtons = {}
4 changes: 2 additions & 2 deletions Core/OnLoad.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions Data/DBUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -38,4 +45,28 @@ 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(true)
if masterLayout == "CUFLayoutMasterNone" then return end

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)
73 changes: 53 additions & 20 deletions Data/Database.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local CUF = select(2, ...)
local DB = CUF.DB

-----------------------------------------
-- Getters
-- MARK: Layout Getters
-----------------------------------------

-- Returns CUF UnitLayoutTable from CellDB
Expand Down Expand Up @@ -34,45 +34,78 @@ 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

-----------------------------------------
-- Setters
-- MARK: Layout Setters
-----------------------------------------

---@param which "buffs"|"debuffs"
---@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

-----------------------------------------
-- MARK: General Getters
-----------------------------------------

---@param rawValue boolean?
---@return string
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

-----------------------------------------
-- MARK: General Setters
-----------------------------------------

---@param layout string
function DB.SetMasterLayout(layout)
CUF_DB.masterLayout = layout
end
2 changes: 1 addition & 1 deletion Debug/Debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ local CUF = select(2, ...)
local L = Cell.L
CUF.L = L

-- Tabs
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 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.]]

L.CopyLayoutFrom = "Copy Layout From"
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"
L.player = "Player"
Expand Down
20 changes: 10 additions & 10 deletions Menu/Builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Builder.MenuOptions = {
---@field pageName string
---@field options table<MenuOptions>

---@param settingsFrame MenuFrame.settingsFrame
---@param settingsFrame UnitsFramesTab.settingsFrame
---@param widgetName WIDGET_KIND
---@param ... MenuOptions
---@return WidgetMenuPage
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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")

Expand Down
Loading