feat: merge categories
This commit is contained in:
+51
-17
@@ -475,6 +475,11 @@ function CategoryManager:MigrateCategories()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Ensure savedEquipSetProps table exists
|
||||||
|
if not cats.savedEquipSetProps then
|
||||||
|
cats.savedEquipSetProps = {}
|
||||||
|
end
|
||||||
|
|
||||||
-- Migrate: Convert per-category itemOverrides arrays to flat map at categories level
|
-- Migrate: Convert per-category itemOverrides arrays to flat map at categories level
|
||||||
if not cats.itemOverrides then
|
if not cats.itemOverrides then
|
||||||
cats.itemOverrides = {}
|
cats.itemOverrides = {}
|
||||||
@@ -685,9 +690,14 @@ function CategoryManager:UpdateCategory(categoryId, definition)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Preserve isBuiltIn flag
|
-- Shallow merge: update existing definition with new fields
|
||||||
definition.isBuiltIn = cats.definitions[categoryId].isBuiltIn
|
-- This preserves fields the caller didn't pass (group, priority, categoryMark, etc.)
|
||||||
cats.definitions[categoryId] = definition
|
local existing = cats.definitions[categoryId]
|
||||||
|
for k, v in pairs(definition) do
|
||||||
|
existing[k] = v
|
||||||
|
end
|
||||||
|
-- Always preserve isBuiltIn from original
|
||||||
|
existing.isBuiltIn = existing.isBuiltIn
|
||||||
|
|
||||||
self:SaveCategories(cats)
|
self:SaveCategories(cats)
|
||||||
return true
|
return true
|
||||||
@@ -1277,9 +1287,8 @@ end
|
|||||||
-- Equipment Set Category Sync
|
-- Equipment Set Category Sync
|
||||||
-------------------------------------------
|
-------------------------------------------
|
||||||
|
|
||||||
-- Saved properties for equipment set categories that were user-edited
|
-- Note: savedEquipSetProps is stored in cats.savedEquipSetProps (persisted in SavedVariables)
|
||||||
-- Preserves user changes (enabled state, order position) when sets are deleted/recreated
|
-- Preserves user changes (enabled state, group, mark, order position) when sets are deleted/recreated
|
||||||
local savedEquipSetProps = {}
|
|
||||||
|
|
||||||
-- Sync equipment set categories with current set data from EquipmentSets module
|
-- Sync equipment set categories with current set data from EquipmentSets module
|
||||||
function CategoryManager:SyncEquipmentSetCategories()
|
function CategoryManager:SyncEquipmentSetCategories()
|
||||||
@@ -1295,6 +1304,11 @@ function CategoryManager:SyncEquipmentSetCategories()
|
|||||||
local cats = self:GetCategories()
|
local cats = self:GetCategories()
|
||||||
local existingSetCats = {}
|
local existingSetCats = {}
|
||||||
|
|
||||||
|
-- Ensure savedEquipSetProps table exists (persisted in SavedVariables)
|
||||||
|
if not cats.savedEquipSetProps then
|
||||||
|
cats.savedEquipSetProps = {}
|
||||||
|
end
|
||||||
|
|
||||||
-- Find existing EquipSet categories
|
-- Find existing EquipSet categories
|
||||||
for id, def in pairs(cats.definitions) do
|
for id, def in pairs(cats.definitions) do
|
||||||
if string.find(id, "^EquipSet:") then
|
if string.find(id, "^EquipSet:") then
|
||||||
@@ -1307,29 +1321,38 @@ function CategoryManager:SyncEquipmentSetCategories()
|
|||||||
local catId = "EquipSet:" .. setName
|
local catId = "EquipSet:" .. setName
|
||||||
if not cats.definitions[catId] then
|
if not cats.definitions[catId] then
|
||||||
-- Check for saved properties from a previously deleted set
|
-- Check for saved properties from a previously deleted set
|
||||||
local props = savedEquipSetProps[catId]
|
local props = cats.savedEquipSetProps[catId]
|
||||||
local defaultMark = "Interface\\AddOns\\Guda\\Assets\\equipment"
|
local defaultMark = "Interface\\AddOns\\Guda\\Assets\\equipment"
|
||||||
local newDef = {
|
local newDef = {
|
||||||
name = setName,
|
name = setName,
|
||||||
icon = "Interface\\Icons\\INV_Chest_Chain_04",
|
icon = "Interface\\Icons\\INV_Chest_Chain_04",
|
||||||
rules = {},
|
rules = {},
|
||||||
matchMode = "all",
|
matchMode = "all",
|
||||||
priority = 65,
|
priority = props and props.priority or 65,
|
||||||
enabled = props and props.enabled or true,
|
enabled = props and props.enabled or true,
|
||||||
isBuiltIn = false,
|
isBuiltIn = false,
|
||||||
isEquipSetCategory = true,
|
isEquipSetCategory = true,
|
||||||
group = GROUP_MAIN,
|
group = props and props.group or GROUP_MAIN,
|
||||||
categoryMark = props and props.categoryMark or defaultMark,
|
categoryMark = props and props.categoryMark or defaultMark,
|
||||||
}
|
}
|
||||||
cats.definitions[catId] = newDef
|
cats.definitions[catId] = newDef
|
||||||
|
|
||||||
-- Add to order
|
-- Restore saved order position or insert at end of Main group
|
||||||
local insertPos = nil
|
local insertPos = nil
|
||||||
for i = table.getn(cats.order), 1, -1 do
|
if props and props.orderPos then
|
||||||
local existDef = cats.definitions[cats.order[i]]
|
-- Clamp to valid range
|
||||||
if existDef and (existDef.group or GROUP_MAIN) == GROUP_MAIN then
|
insertPos = props.orderPos
|
||||||
insertPos = i + 1
|
if insertPos > table.getn(cats.order) + 1 then
|
||||||
break
|
insertPos = table.getn(cats.order) + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not insertPos then
|
||||||
|
for i = table.getn(cats.order), 1, -1 do
|
||||||
|
local existDef = cats.definitions[cats.order[i]]
|
||||||
|
if existDef and (existDef.group or GROUP_MAIN) == GROUP_MAIN then
|
||||||
|
insertPos = i + 1
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if insertPos then
|
if insertPos then
|
||||||
@@ -1347,10 +1370,21 @@ function CategoryManager:SyncEquipmentSetCategories()
|
|||||||
for catId in pairs(existingSetCats) do
|
for catId in pairs(existingSetCats) do
|
||||||
local def = cats.definitions[catId]
|
local def = cats.definitions[catId]
|
||||||
if def then
|
if def then
|
||||||
-- Save user-edited properties before deletion
|
-- Find current order position before removal
|
||||||
savedEquipSetProps[catId] = {
|
local orderPos = nil
|
||||||
|
for i, id in ipairs(cats.order) do
|
||||||
|
if id == catId then
|
||||||
|
orderPos = i
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Save user-edited properties before deletion (persisted across reloads)
|
||||||
|
cats.savedEquipSetProps[catId] = {
|
||||||
enabled = def.enabled,
|
enabled = def.enabled,
|
||||||
categoryMark = def.categoryMark,
|
categoryMark = def.categoryMark,
|
||||||
|
group = def.group,
|
||||||
|
priority = def.priority,
|
||||||
|
orderPos = orderPos,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
cats.definitions[catId] = nil
|
cats.definitions[catId] = nil
|
||||||
|
|||||||
@@ -1541,6 +1541,31 @@ local function GetCategoryRowFrame(index)
|
|||||||
builtInText:SetTextColor(0.5, 0.5, 0.5)
|
builtInText:SetTextColor(0.5, 0.5, 0.5)
|
||||||
row.builtInText = builtInText
|
row.builtInText = builtInText
|
||||||
|
|
||||||
|
-- Merge checkbox (shown on group header rows)
|
||||||
|
local mergeCheckbox = CreateFrame("CheckButton", rowName .. "_MergeCheckbox", row, "UICheckButtonTemplate")
|
||||||
|
mergeCheckbox:SetWidth(20)
|
||||||
|
mergeCheckbox:SetHeight(20)
|
||||||
|
mergeCheckbox:SetPoint("RIGHT", row, "RIGHT", -5, 0)
|
||||||
|
mergeCheckbox:SetScript("OnClick", function()
|
||||||
|
local groupName = this:GetParent().groupName
|
||||||
|
if groupName then
|
||||||
|
local mergedGroups = Guda.Modules.DB:GetSetting("mergedGroups") or {}
|
||||||
|
if this:GetChecked() == 1 then
|
||||||
|
mergedGroups[groupName] = true
|
||||||
|
else
|
||||||
|
mergedGroups[groupName] = nil
|
||||||
|
end
|
||||||
|
Guda.Modules.DB:SetSetting("mergedGroups", mergedGroups)
|
||||||
|
Guda_SettingsPopup_RefreshBagFrames()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
local mergeLabel = row:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
|
||||||
|
mergeLabel:SetPoint("RIGHT", mergeCheckbox, "LEFT", -2, 0)
|
||||||
|
mergeLabel:SetText("Merge")
|
||||||
|
mergeLabel:SetTextColor(0.8, 0.8, 0.8)
|
||||||
|
row.mergeCheckbox = mergeCheckbox
|
||||||
|
row.mergeLabel = mergeLabel
|
||||||
|
|
||||||
-- Hover highlight
|
-- Hover highlight
|
||||||
row:EnableMouse(true)
|
row:EnableMouse(true)
|
||||||
row:SetScript("OnEnter", function()
|
row:SetScript("OnEnter", function()
|
||||||
@@ -1602,6 +1627,7 @@ function Guda_SettingsPopup_CategoriesTab_Update()
|
|||||||
if entry.type == "header" then
|
if entry.type == "header" then
|
||||||
-- Show as group header row
|
-- Show as group header row
|
||||||
row.categoryId = nil
|
row.categoryId = nil
|
||||||
|
row.groupName = entry.groupName
|
||||||
row.nameText:SetText("|cffffd100-- " .. entry.groupName .. " --|r")
|
row.nameText:SetText("|cffffd100-- " .. entry.groupName .. " --|r")
|
||||||
row.nameText:SetTextColor(1, 0.82, 0)
|
row.nameText:SetTextColor(1, 0.82, 0)
|
||||||
row.checkbox:Hide()
|
row.checkbox:Hide()
|
||||||
@@ -1610,15 +1636,25 @@ function Guda_SettingsPopup_CategoriesTab_Update()
|
|||||||
row.downBtn:Hide()
|
row.downBtn:Hide()
|
||||||
row.deleteBtn:Hide()
|
row.deleteBtn:Hide()
|
||||||
row.builtInText:Hide()
|
row.builtInText:Hide()
|
||||||
|
|
||||||
|
-- Show merge checkbox for group headers
|
||||||
|
local mergedGroups = Guda.Modules.DB:GetSetting("mergedGroups") or {}
|
||||||
|
row.mergeCheckbox:SetChecked(mergedGroups[entry.groupName] and 1 or 0)
|
||||||
|
row.mergeCheckbox:Show()
|
||||||
|
row.mergeLabel:Show()
|
||||||
|
|
||||||
row:Show()
|
row:Show()
|
||||||
elseif entry.type == "category" then
|
elseif entry.type == "category" then
|
||||||
local categoryId = entry.categoryId
|
local categoryId = entry.categoryId
|
||||||
local categoryDef = entry.categoryDef
|
local categoryDef = entry.categoryDef
|
||||||
|
|
||||||
row.categoryId = categoryId
|
row.categoryId = categoryId
|
||||||
|
row.groupName = nil
|
||||||
row.nameText:SetText(categoryDef.name or categoryId)
|
row.nameText:SetText(categoryDef.name or categoryId)
|
||||||
row.checkbox:Show()
|
row.checkbox:Show()
|
||||||
row.checkbox:SetChecked(categoryDef.enabled and 1 or 0)
|
row.checkbox:SetChecked(categoryDef.enabled and 1 or 0)
|
||||||
|
row.mergeCheckbox:Hide()
|
||||||
|
row.mergeLabel:Hide()
|
||||||
|
|
||||||
-- Show/hide delete button based on whether it's built-in
|
-- Show/hide delete button based on whether it's built-in
|
||||||
if categoryDef.isBuiltIn then
|
if categoryDef.isBuiltIn then
|
||||||
|
|||||||
Reference in New Issue
Block a user