Skip to content

Commit

Permalink
feat(filter): separate filter for World Events
Browse files Browse the repository at this point in the history
  • Loading branch information
exochron committed Dec 15, 2024
1 parent 2c247a7 commit 79366e9
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 49 deletions.
20 changes: 10 additions & 10 deletions Database/Database.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,15 @@ ADDON.DB.Source = {
[247448] = true, -- Darkmoon Dirigible
},

["Plunderstorm"] = {
[254812] = true, -- Royal Seafeather
[300154] = true, -- Silver Tidestallion
[437162] = true, -- Polly Roger
[446902] = true, -- Polly Roger (classic)
[457656] = true, -- Plunderlord's Midnight Crocolisk
[471696] = true, -- Hooktalon
},

["Call of the Scarab"] = {
[239766] = true, -- Blue Qiraji War Tank
[239767] = true, -- Red Qiraji War Tank
Expand Down Expand Up @@ -1384,16 +1393,7 @@ ADDON.DB.Source = {
[191314] = true, -- Minion of Grumpus
},

["Plunderstorm"] = {
[254812] = true, -- Royal Seafeather
[300154] = true, -- Silver Tidestallion
[437162] = true, -- Polly Roger
[446902] = true, -- Polly Roger (classic)
[457656] = true, -- Plunderlord's Midnight Crocolisk
[471696] = true, -- Hooktalon
},

["Remix: Mists of Pandaria"] = {
["Remix: Pandaria"] = {
[138425] = true, -- Slate Primordial Direhorn
[127170] = true, -- Astral Cloud Serpent
[136471] = true, -- Spawn of Horridon
Expand Down
2 changes: 1 addition & 1 deletion Filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ function ADDON:FilterMounts()
end
else
local allSettingsSource, preparedSource = CheckAllSettings(ADDON.settings.filter.source)
if not preparedSource then
if not allSettingsSource then
preparedSource = prepareSettings(ADDON.settings.filter.source, SourceDB)
end

Expand Down
3 changes: 3 additions & 0 deletions Locals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ L["FAVOR_AUTO"] = "Add new mounts automatically"
L["LDB_TIP_NO_FAVORITES_TITLE"] = "You have not selected any mount as favorite yet."
L["LDB_TIP_NO_FAVORITES_LEFT_CLICK"] = "|cffeda55fLeft click|r to open Mount Collection."
L["LDB_TIP_NO_FAVORITES_RIGHT_CLICK"] = "|cffeda55fRight click|r to select different Favorite Profile."
L["EVENT_PLUNDERSTORM"] = "Plunderstorm"
L["EVENT_SCARAB"] = "Call of the Scarab"
L["EVENT_SECRETS"] = "Secrets of Azeroth"

-- Families
L["Airplanes"] = "Airplanes"
Expand Down
4 changes: 4 additions & 0 deletions Settings/Settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ local function PrepareDefaults()
for categoryName, _ in pairs(ADDON.DB.Source) do
defaultSettings.filter.source[categoryName] = true
end
defaultSettings.filter.source["World Event"] = {}
for categoryName, _ in pairs(ADDON.DB.Source["World Event"]) do
defaultSettings.filter.source["World Event"][categoryName] = true
end
for categoryName, categoryConfig in pairs(ADDON.DB.Family) do
for subCategory, subConfig in pairs(categoryConfig) do
if type(subConfig) == "table" then
Expand Down
42 changes: 5 additions & 37 deletions UI/FilterDropdown/Family.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ local function CheckSetting(settings)
return hasTrue, hasFalse
end

local function AddIcon(menuButton, family, subfamily)
local function GetIcon(family, subfamily)
local sourceDb = subfamily and ADDON.DB.Family[family][subfamily] or ADDON.DB.Family[family]
local mountId = TableUtil.FindMin(GetKeysArray(sourceDb), function(v) return v end)
local _, _, icon = C_MountJournal.GetMountInfoByID(mountId)
ADDON.UI.FDD:AddIcon(menuButton, icon)
return icon
end

function ADDON.UI.FDD:AddFamilyMenu(root)
Expand All @@ -47,39 +47,7 @@ function ADDON.UI.FDD:AddFamilyMenu(root)

for _, family in pairs(sortedFamilies) do
if hasSubFamilies[family] then
local subMenu = root:CreateCheckbox(L[family] or family, function()
local settingHasTrue = CheckSetting(settings[family])

return settingHasTrue
end, function(...)
local _, settingHasFalse = CheckSetting(settings[family])
ADDON.UI.FDD:SetAllSubFilters(settings[family], settingHasFalse)

return MenuResponse.Refresh
end)
subMenu:AddInitializer(function(button)
if button.leftTexture2 then
local settingHasTrue, settingHasFalse = CheckSetting(settings[family])
if settingHasTrue and settingHasFalse then
local dash
if button.leftTexture2 then
-- mainline style
dash = button.leftTexture2
dash:SetPoint("CENTER", button.leftTexture1, "CENTER", 0, 1)
else
-- classic style
dash = button:AttachTexture()
dash:SetPoint("CENTER", button.leftTexture1)
button.leftTexture1:SetAtlas("common-dropdown-ticksquare-classic", true)
end

dash:SetAtlas("voicechat-icon-loudnessbar-2", true)
dash:SetTexCoord(1, 0, 0, 0, 1, 1, 0, 1)
dash:SetSize(16, 16)
end
end
end)
AddIcon(subMenu, family, next(ADDON.DB.Family[family]))
local subMenu = ADDON.UI.FDD:CreateFilterSubmenu(root, L[family] or family, GetIcon(family, next(ADDON.DB.Family[family])), settings[family])
local sortedSubFamilies = {}
for subfamily, _ in pairs(ADDON.DB.Family[family]) do
tInsert(sortedSubFamilies, subfamily)
Expand All @@ -88,11 +56,11 @@ function ADDON.UI.FDD:AddFamilyMenu(root)
return (L[a] or a) < (L[b] or b)
end)
for _, subfamily in pairs(sortedSubFamilies) do
AddIcon(ADDON.UI.FDD:CreateFilter(subMenu, L[subfamily] or subfamily, subfamily, settings[family], settings), family, subfamily)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(subMenu, L[subfamily] or subfamily, subfamily, settings[family], settings), GetIcon(family, subfamily))
end

else
AddIcon(ADDON.UI.FDD:CreateFilter(root, L[family] or family, family, settings, true), family)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(root, L[family] or family, family, settings, true), GetIcon(family))
end
end
end
82 changes: 81 additions & 1 deletion UI/FilterDropdown/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ local SETTING_HIDDEN = "hidden"
local SETTING_HIDDEN_INGAME = "hiddenIngame"
local SETTING_RARITY = "rarity"

local function CheckSetting(settings)
local hasTrue, hasFalse = false, false
for _, v in pairs(settings) do
if v == true then
hasTrue = true
elseif v == false then
hasFalse = true
end
if hasTrue and hasFalse then
break
end
end

return hasTrue, hasFalse
end
local function setAllSettings(settings, switch)
for key, value in pairs(settings) do
if type(value) == "table" then
Expand Down Expand Up @@ -79,6 +94,45 @@ function ADDON.UI.FDD:CreateFilter(root, text, filterKey, filterSettings, withOn

return button
end
function ADDON.UI.FDD:CreateFilterSubmenu(root, text, icon, settings)
local subMenu = root:CreateCheckbox(text, function()
local settingHasTrue, settingHasFalse = CheckSetting(settings)

return settingHasTrue
end, function(...)
local _, settingHasFalse = CheckSetting(settings)
ADDON.UI.FDD:SetAllSubFilters(settings, settingHasFalse)

return MenuResponse.Refresh
end)
subMenu:AddInitializer(function(button)
if button.leftTexture2 then
local settingHasTrue, settingHasFalse = CheckSetting(settings)
if settingHasTrue and settingHasFalse then
local dash
if button.leftTexture2 then
-- mainline style
dash = button.leftTexture2
dash:SetPoint("CENTER", button.leftTexture1, "CENTER", 0, 1)
else
-- classic style
dash = button:AttachTexture()
dash:SetPoint("CENTER", button.leftTexture1)
button.leftTexture1:SetAtlas("common-dropdown-ticksquare-classic", true)
end

dash:SetAtlas("voicechat-icon-loudnessbar-2", true)
dash:SetTexCoord(1, 0, 0, 0, 1, 1, 0, 1)
dash:SetSize(16, 16)
end
end
end)

ADDON.UI.FDD:AddIcon(subMenu, icon)

return subMenu
end

function ADDON.UI.FDD:AddIcon(menuButton, texture, width, height, left, right, top, bottom)
menuButton:AddInitializer(function(button)
width = width or 20
Expand Down Expand Up @@ -149,6 +203,33 @@ local function setupSourceMenu(root)

AddAllAndNone(root, settings)

local eventSettings = settings["World Event"]
local eventRoot = ADDON.UI.FDD:CreateFilterSubmenu(root, BATTLE_PET_SOURCE_7, 236552, eventSettings)
AddAllAndNone(eventRoot, eventSettings)

if WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC then
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, CALENDAR_FILTER_DARKMOON, "Darkmoon Faire", eventSettings, settings), 134481)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, L.EVENT_PLUNDERSTORM, "Plunderstorm", eventSettings, settings), 133168)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, GetCategoryInfo(187), "Love is in the Air", eventSettings, settings), 368564)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, GetCategoryInfo(159), "Noblegarden", eventSettings, settings), 254858)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, GetCategoryInfo(162), "Brewfest", eventSettings, settings), 133201)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, GetCategoryInfo(158), "Hallow's End", eventSettings, settings), 236552)
else
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, PLAYER_DIFFICULTY_TIMEWALKER, "Timewalking", eventSettings, settings), 5228749)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, CALENDAR_FILTER_DARKMOON, "Darkmoon Faire", eventSettings, settings), 134481)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, WOW_LABS_PRESENCE_GAME_MODE_BATTLE_ROYAL, "Plunderstorm", eventSettings, settings), 133168)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, L.EVENT_SCARAB, "Call of the Scarab", eventSettings, settings), 1574965, 20, 20, 0, 0.71, 0, 0.71)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, GetCategoryInfo(160), "Lunar Festival", eventSettings, settings), 236704)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, GetCategoryInfo(187), "Love is in the Air", eventSettings, settings), 368564)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, GetCategoryInfo(159), "Noblegarden", eventSettings, settings), 254858)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, L.EVENT_SECRETS, "Secrets of Azeroth", eventSettings, settings), 237387)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, GetCategoryInfo(162), "Brewfest", eventSettings, settings), 133201)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, GetCategoryInfo(15532), "Anniversary", eventSettings, settings), 1084434, 20, 20, 0, 0.71, 0, 0.71)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, GetCategoryInfo(158), "Hallow's End", eventSettings, settings), 236552)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, GetCategoryInfo(156), "Feast of Winter Veil", eventSettings, settings), 133202)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(eventRoot, GetCategoryInfo(15536), "Remix: Pandaria", eventSettings, settings), 572034)
end

ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(root, BATTLE_PET_SOURCE_1, "Drop", settings, true), 133639)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(root, BATTLE_PET_SOURCE_2, "Quest", settings, true), 236669)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(root, BATTLE_PET_SOURCE_3, "Vendor", settings, true), 133784)
Expand All @@ -167,7 +248,6 @@ local function setupSourceMenu(root)
end
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(root, PVP, "PVP", settings, true), 132487)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(root, CLASS, "Class", settings, true), 626001)
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(root, BATTLE_PET_SOURCE_7, "World Event", settings, true), 236552)
if serverExpansion >= LE_EXPANSION_MISTS_OF_PANDARIA then
ADDON.UI.FDD:AddIcon(ADDON.UI.FDD:CreateFilter(root, L["Black Market"], "Black Market", settings, true), 626190)
end
Expand Down

0 comments on commit 79366e9

Please sign in to comment.