Skip to content

Commit f5f2fa7

Browse files
committed
Show a tooltip line with a loading progress % if looking at a tooltip while the addon is still loading data
1 parent b9e2090 commit f5f2fa7

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

TransmogUpgradeMaster.lua

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,21 @@ end
123123

124124
function TUM:InitItemSourceMap()
125125
local itemSourceIDs = {}
126-
TUM.itemSourceIDs = itemSourceIDs
127-
local finished = false
128-
local msPerBatch = 10
126+
self.itemSourceMapInitialized = false
127+
self.itemSourceMapProgress = 0
128+
self.itemSourceMapTotal = 0
129+
self.itemSourceIDs = itemSourceIDs
130+
--- @type table<number, TransmogCategoryAppearanceInfo[]>
131+
local categoryAppearances = {}
132+
for _, category in pairs(Enum.TransmogCollectionType) do
133+
categoryAppearances[category] = C_TransmogCollection.GetCategoryAppearances(category)
134+
self.itemSourceMapTotal = self.itemSourceMapTotal + #categoryAppearances[category]
135+
end
136+
local msPerBatch = 20
129137
local function iterateAppearances()
130138
local start = debugprofilestop()
131-
for _, category in pairs(Enum.TransmogCollectionType) do
132-
for _, info in pairs(C_TransmogCollection.GetCategoryAppearances(category)) do
139+
for _, appearances in pairs(categoryAppearances) do
140+
for _, info in pairs(appearances) do
133141
local appearanceSources = C_TransmogCollection.GetAppearanceSources(info.visualID)
134142
if appearanceSources then
135143
for _, sourceInfo in ipairs(appearanceSources) do
@@ -140,18 +148,19 @@ function TUM:InitItemSourceMap()
140148
end
141149
end
142150
end
151+
self.itemSourceMapProgress = self.itemSourceMapProgress + 1
143152
if debugprofilestop() - start > msPerBatch then
144153
coroutine.yield()
145154
start = debugprofilestop()
146155
end
147156
end
148157
end
149-
finished = true
158+
self.itemSourceMapInitialized = true
150159
end
151160
local resumeFunc = coroutine.wrap(iterateAppearances)
152161
local ticker
153162
ticker = C_Timer.NewTicker(1, function()
154-
if finished then
163+
if self.itemSourceMapInitialized then
155164
ticker:Cancel()
156165
return
157166
end
@@ -263,6 +272,10 @@ function TUM:HandleTooltip(tooltip)
263272
local isCollected = nextSourceInfo and nextSourceInfo.isCollected
264273
self:AddTooltipLine(tooltip, UPGRADE_MARKUP .. " Upgrade appearance", isCollected)
265274
end
275+
elseif not self.itemSourceMapInitialized then
276+
local progress = self.itemSourceMapProgress / self.itemSourceMapTotal * 100
277+
local text = string.format("TransmogUpgradeMaster is loading (%.0f%%)", progress)
278+
tooltip:AddLine(text, nil, nil, nil, true)
266279
end
267280
end
268281
end

0 commit comments

Comments
 (0)