Skip to content

Commit

Permalink
feat(ui): update count while filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
exochron committed Aug 29, 2024
1 parent 31d029b commit 417c12f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 21 deletions.
15 changes: 15 additions & 0 deletions DevZone/Roadmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### TODOs:
- [ ] maybe toggle enhanced layer and original buttons with entering/exiting combat. so layer doesn't need a background. (beware of taint!)
- [ ] use settings system
- [x] update toy count while filtering
- [ ] add autofavor
- [ ] write unit tests
- [ ] proper indeterminate icon for filter submenus
- [ ] expansion icons for filter menu

### Ideas:
- add preview window
- use list layout with big preview
- collect tracking data
- use rarity of dataforazeroth.com -> colorize names
- note functionality
2 changes: 2 additions & 0 deletions Filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,7 @@ function ADDON:FilterToys()

UpdateDataProvider(result)

ADDON.Events:TriggerEvent("OnFiltered")

return result
end
82 changes: 61 additions & 21 deletions UI/ToyCount.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
local _, ADDON = ...

-- todo: update with filter (like mje)
local function generateText(num, total)
if num < total then
return num .. '/' .. total
end

return total
end

local function count()
local total, owned, usable = 0, 0, 0, 0

for itemId, valid in pairs(ADDON.db.ingameList) do
if valid or ADDON.settings.filter.secret then
total = total + 1

if PlayerHasToy(itemId) then
owned = owned + 1
if C_ToyBox.IsToyUsable(itemId) then
usable = usable + 1
end
end
end
end

return usable, owned, total
end

local function CreateCountFrame(text, counterFunc)
local frame = CreateFrame("Frame", nil, ToyBox, "InsetFrameTemplate3")
Expand All @@ -12,37 +37,52 @@ local function CreateCountFrame(text, counterFunc)
frame:StripTextures()
end

local staticText = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
staticText:ClearAllPoints()
staticText:SetPoint("LEFT", frame, 10, 0)
staticText:SetText(text)
frame.label = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
frame.label:ClearAllPoints()
frame.label:SetPoint("LEFT", frame, 10, 0)
frame.label:SetText(text)

local uniqueCount = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
uniqueCount:ClearAllPoints()
uniqueCount:SetPoint("RIGHT", frame, -10, 0)
uniqueCount:SetText(counterFunc())
frame.counter = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
frame.counter:ClearAllPoints()
frame.counter:SetPoint("RIGHT", frame, -10, 0)
frame.counter:SetText(generateText(counterFunc(frame)))

frame:RegisterEvent("TOYS_UPDATED")
frame:SetScript("OnEvent", function()
uniqueCount:SetText(counterFunc())
frame.counter:SetText(generateText(counterFunc(frame)))
end)

return frame
end

local function GetUsableToysCount()
local usableCount = 0
for itemId in pairs(ADDON.db.ingameList) do
if PlayerHasToy(itemId) and C_ToyBox.IsToyUsable(itemId) then
usableCount = usableCount + 1
ADDON.Events:RegisterCallback("OnLoadUI", function ()
local L = ADDON.L

local updateToysFrame = function(frame)
local dataProvider = ADDON.DataProvider
local displayCount = dataProvider:GetSize()
local _, owned, total = count()

if displayCount == 0 or displayCount == total then
frame.label:SetText(L["Toys"])
return owned, total
end

local collectedFilter = 0
dataProvider:ForEach(function(itemId)
if PlayerHasToy(itemId) then
collectedFilter = collectedFilter + 1
end
end)

frame.label:SetText(FILTER)
return collectedFilter, displayCount
end
local toysFrame = CreateCountFrame(L["Toys"], updateToysFrame)
ADDON.Events:RegisterCallback("OnFiltered", function ()
updateToysFrame(toysFrame)
end, "filtered-count")

return usableCount
end
CreateCountFrame(L["Usable"], count):SetPoint("TOPLEFT", ToyBox, 70, -41)

ADDON.Events:RegisterCallback("OnLoadUI", function ()
local L = ADDON.L
CreateCountFrame(L["Toys"], C_ToyBox.GetNumLearnedDisplayedToys)
CreateCountFrame(L["Usable"], GetUsableToysCount):SetPoint("TOPLEFT", ToyBox, 70, -41)
end, "count")

0 comments on commit 417c12f

Please sign in to comment.