Skip to content

Commit

Permalink
3.2.0
Browse files Browse the repository at this point in the history
Improved Custom Filter Creation and Deletion
Added Inventory section to the Filter Menu
  • Loading branch information
Noshei committed Dec 12, 2024
1 parent 6ba4060 commit d452dad
Show file tree
Hide file tree
Showing 9 changed files with 461 additions and 211 deletions.
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"utf8": "disable"
},
"Lua.workspace.library": [
"~\\.vscode\\extensions\\ketho.wow-api-0.17.9\\Annotations"
"~\\.vscode\\extensions\\ketho.wow-api-0.18.0\\Annotations"
],
"Lua.diagnostics.globals": [
"RECrystallize_PriceCheckItemID",
Expand Down Expand Up @@ -91,7 +91,9 @@
"CANCEL",
"CLOSE",
"ADD",
"LowHealthFrame"
"LowHealthFrame",
"GameTooltip_SetTitle",
"GameTooltip_AddNormalLine"
],
"Lua.diagnostics.disable": [
"assign-type-mismatch",
Expand Down
5 changes: 2 additions & 3 deletions AlertsMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ local tostring = tostring
local type = type
local unpack = unpack

GT.AlertSystem.Menu = {}

function GT:GenerateAlertsMenu(frame)
local function AlertsMenu(frame, rootDescription)
rootDescription:SetTag("GatheringTracker_Alerts_Menu")
Expand Down Expand Up @@ -171,7 +169,8 @@ function GT:GenerateAlertsMenu(frame)
GT.AlertSystem.Menu.rootDescription = rootDescription
end

---@class GT.AlertSystem.menu: MenuProxy
---@class GT.AlertSystem.Menu: MenuProxy
GT.AlertSystem.Menu = GT.AlertSystem.Menu or {}
GT.AlertSystem.Menu = MenuUtil.CreateContextMenu(frame, AlertsMenu)
end

Expand Down
222 changes: 105 additions & 117 deletions Config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1603,34 +1603,21 @@ local filterOptions = {
args = {
customHeading = {
type = "description",
name = "Use this field to add additional items (by ID only) to be tracked. One ID per line!",
name = "Use this field to add additional items (by ID only) to be tracked.",
width = "full",
order = 1
},
customInput = {
type = "input",
name = "Custom Input",
multiline = true,
name = "Item ID",
width = "full",
usage = "Please only enter item ID's (aka numbers)",
--validate = function(_, key) if string.match(key, "[^%d\n]+") then return false end return true end,
get = function() return GT.db.profile.CustomFilters end,
get = function() end,
set = function(_, key)
GT.db.profile.CustomFilters = key
local tempFilterTable = {}
for itemID in string.gmatch(GT.db.profile.CustomFilters, "[%d]+") do
itemID = tonumber(itemID) or 0
if GT.db.profile.CustomFiltersTable[itemID] then
tempFilterTable[itemID] = GT.db.profile.CustomFiltersTable[itemID]
else
tempFilterTable[itemID] = true
end
GT:RemoveItemData(tempFilterTable[itemID], itemID)
if not string.match(key, "[%D]+") then
local id = tonumber(key) or 0
GT:CreateCustomFilterItem(id)
end
GT.db.profile.CustomFiltersTable = tempFilterTable
GT:CreateCustomFilterOptions()
GT:RebuildIDTables()
GT:InventoryUpdate("Custom Filter Changed", true)
end,
order = 2
},
Expand Down Expand Up @@ -1757,77 +1744,105 @@ for expansion, expansionData in pairs(GT.ItemData) do
end
end

function GT:CreateCustomFilterOptions()
if GT.db.profile.CustomFilters then
for arg, data in pairs(filterOptions.args.custom.args) do
if data.order > 1000 then
filterOptions.args.custom.args[arg] = nil
function GT:DeleteCustomFilter(itemID, itemName)
GT.Debug("Delete Custom Filter", 1, itemID, itemName)

GT.db.profile.CustomFiltersTable[itemID] = nil

filterOptions.args.custom.args[itemName] = nil
AceConfigRegistry:NotifyChange("GT/Filter")

GT:RebuildIDTables()
GT:InventoryUpdate("Custom Filter Deleted", true)
end

function GT:CreateCustomFilterItem(id, enable)
--Create a local item to get data from the server
local item = Item:CreateFromItemID(id)
GT.Debug("Create Custom Filter Options", 2, id)
--Waits for the data to be returned from the server
if not item:IsItemEmpty() then
item:ContinueOnItemLoad(function()
GT.Debug("Create Custom Filter Options", 3, id)
if GT.db.profile.CustomFiltersTable[id] == nil then
GT.db.profile.CustomFiltersTable[id] = false
end
end
for id, value in pairs(GT.db.profile.CustomFiltersTable) do
--Create a local item to get data from the server
local item = Item:CreateFromItemID(id)
GT.Debug("Create Custom Filter Options", 2, id)
--Waits for the data to be returned from the server
if not item:IsItemEmpty() then
item:ContinueOnItemLoad(function()
local itemName = item:GetItemName()
local itemLink = item:GetItemLink()
itemLink = itemLink:gsub("[%[%]]", "")
filterOptions.args.custom.args[itemName] = {
type = "toggle",
dialogControl = "NW_CheckBox",
name = itemLink,
image = function() return C_Item.GetItemIconByID(id) end,
get = function() return GT.db.profile.CustomFiltersTable[id] end,
set = function(_, key)
if key then
GT.db.profile.CustomFiltersTable[id] = key
else
GT.db.profile.CustomFiltersTable[id] = false
end
if enable then
GT.db.profile.CustomFiltersTable[id] = true
end
local itemName = item:GetItemName()
local itemLink = item:GetItemLink()
itemLink = itemLink:gsub("[%[%]]", "")
filterOptions.args.custom.args[itemName] = {
type = "toggle",
dialogControl = "NW_CheckBox",
name = itemLink,
image = function() return C_Item.GetItemIconByID(id) end,
get = function() return GT.db.profile.CustomFiltersTable[id] end,
set = function(_, key)
if key then
GT.db.profile.CustomFiltersTable[id] = key
else
GT.db.profile.CustomFiltersTable[id] = false
end

GT:UpdateIDTable(id, key)
GT:RemoveItemData(key, id)
GT:InventoryUpdate("Filters Custom " .. itemName .. " option clicked", true)
end,
imageCoords = function()
local data = {}
local imageSize = { 24, 24 }
local border = {}
local borderColor = {}
local overlay = {}

if id <= #GT.ItemData.Other.Other then
border = { "Interface\\Common\\WhiteIconFrame", "texture" }
borderColor = { 1, 1, 1, 0.8 }
overlay = nil
else
local rarity = C_Item.GetItemQualityByID(id) or 1
if rarity <= 1 then
border = { "Interface\\Common\\WhiteIconFrame", "texture" }
else
border = { "bags-glow-white", "atlas" }
end
GT:UpdateIDTable(id, key)
GT:RemoveItemData(key, id)
GT:InventoryUpdate("Filters Custom " .. itemName .. " option clicked", true)
end,
imageCoords = function()
local data = {}
local imageSize = { 24, 24 }
local border = {}
local borderColor = {}
local overlay = {}

if id <= #GT.ItemData.Other.Other then
border = { "Interface\\Common\\WhiteIconFrame", "texture" }
borderColor = { 1, 1, 1, 0.8 }
overlay = nil
else
local rarity = C_Item.GetItemQualityByID(id) or 1
if rarity <= 1 then
border = { "Interface\\Common\\WhiteIconFrame", "texture" }
else
border = { "bags-glow-white", "atlas" }
end

local R, G, B = C_Item.GetItemQualityColor(rarity)
borderColor = { R, G, B, 0.8 }
local R, G, B = C_Item.GetItemQualityColor(rarity)
borderColor = { R, G, B, 0.8 }

overlay = nil
end
overlay = nil
end

data = { imageSize, border, borderColor, overlay }
local deleteFunc = function(self)
GT:DeleteCustomFilter(id, itemName)
end

return data
end,
order = (id + 1000)
}
AceConfigRegistry:NotifyChange("GT/Filter")
end)
else
ChatFrame1:AddMessage("|cffff6f00" .. GT.metaData.name .. ":|r " .. id .. " is not a valid item ID")
data = { imageSize, border, borderColor, overlay, deleteFunc }

return data
end,
width = 1.2,
order = (id + 1000)
}
AceConfigRegistry:NotifyChange("GT/Filter")
end)
else
ChatFrame1:AddMessage("|cffff6f00" .. GT.metaData.name .. ":|r " .. id .. " is not a valid item ID")
end
end

function GT:CreateCustomFilterOptions()
if GT.db.profile.CustomFiltersTable then
for arg, data in pairs(filterOptions.args.custom.args) do
if data.order > 1000 then
filterOptions.args.custom.args[arg] = nil
end
end
for id in pairs(GT.db.profile.CustomFiltersTable) do
GT:CreateCustomFilterItem(id)
end
end
end

Expand All @@ -1840,41 +1855,14 @@ function GatheringTracker_OnAddonCompartmentClick(addonName, button)
end

local function UpdateChangedorRemovedSavedVariables()
-- Increment when adding anything to function
local fixConstant = 2
if GT.db.profile.General.fixSettings < fixConstant and GT.db.profile.General.fixSettings == 1 then
--Change debug to int instead of bool
if type(GT.db.profile.General.debugOption) == "boolean" then
GT.db.profile.General.debugOption = 0
end

if GT.db.profile.Filters["gold"] then
GT.db.profile.Filters["gold"] = nil
GT.db.profile.Filters[1] = true
end

if GT.db.profile.Filters["bag"] then
GT.db.profile.Filters["bag"] = nil
GT.db.profile.Filters[2] = true
end

local tempFilterTable = {}
for itemID in string.gmatch(GT.db.profile.CustomFilters, "[%d]+") do
itemID = tonumber(itemID) or 0
if GT.db.profile.CustomFiltersTable[itemID] then
tempFilterTable[itemID] = GT.db.profile.CustomFiltersTable[itemID]
else
tempFilterTable[itemID] = true
end
GT:RemoveItemData(tempFilterTable[itemID], itemID)
end
GT.db.profile.CustomFiltersTable = tempFilterTable

GT.db.profile.General.fixSettings = fixConstant
elseif GT.db.profile.General.fixSettings < fixConstant and GT.db.profile.General.fixSettings == 2 then
if GT.db.profile.Notifications then
GT.db.profile.Notifications = nil
end
if GT.db.profile.General.fixSettings then
GT.db.profile.General.fixSettings = nil
end
if GT.db.profile.Notifications then
GT.db.profile.Notifications = nil
end
if GT.db.profile.CustomFilters then
GT.db.profile.CustomFilters = nil
end
end

Expand Down
4 changes: 2 additions & 2 deletions Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ for index, category in ipairs(GT.categoriesOrder) do
GT.categories[category] = index
end

local ItemData = {
GT.ItemDataFlat = {
-- Classic
{ id = 2447, name = "Peacebloom", order = 1, retail = true, cata = true, wrath = true, bc = true, era = true, season = true, expansion = "Classic", category = "Herb" },
{ id = 765, name = "Silverleaf", order = 2, retail = true, cata = true, wrath = true, bc = true, era = true, season = true, expansion = "Classic", category = "Herb" },
Expand Down Expand Up @@ -1367,7 +1367,7 @@ local ItemData = {

GT.ItemData = {}

for item, itemData in ipairs(ItemData) do
for _, itemData in ipairs(GT.ItemDataFlat) do
if itemData[GT.gameVersion] then
GT.ItemData[itemData.expansion] = GT.ItemData[itemData.expansion] or {}
GT.ItemData[itemData.expansion][itemData.category] = GT.ItemData[itemData.expansion][itemData.category] or {}
Expand Down
Loading

0 comments on commit d452dad

Please sign in to comment.