Skip to content

Commit 9dfbba8

Browse files
authored
Add progress bar to power report (#9461)
* feat: add progress bar to power report * feat: include a toast for the power report progress * feat: update how we handle power report toast
1 parent ca26f3d commit 9dfbba8

2 files changed

Lines changed: 73 additions & 6 deletions

File tree

src/Classes/CalcsTab.lua

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ end
473473

474474
-- Estimate the offensive and defensive power of all unallocated nodes
475475
function CalcsTabClass:PowerBuilder()
476-
--local timer_start = GetTime()
476+
-- local timer_start = GetTime()
477477
local useFullDPS = self.powerStat and self.powerStat.stat == "FullDPS"
478478
local calcFunc, calcBase = self:GetMiscCalculator()
479479
local cache = { }
@@ -494,18 +494,31 @@ function CalcsTabClass:PowerBuilder()
494494
end
495495

496496
local start = GetTime()
497+
local nodeIndex = 0
498+
local total = 0
499+
497500
for nodeId, node in pairs(self.build.spec.nodes) do
498501
wipeTable(node.power)
499502
if node.modKey ~= "" and not self.mainEnv.grantedPassives[nodeId] then
500503
distanceMap[node.pathDist or 1000] = distanceMap[node.pathDist or 1000] or { }
501504
distanceMap[node.pathDist or 1000][nodeId] = node
505+
if not (self.nodePowerMaxDepth and self.nodePowerMaxDepth < node.pathDist) then
506+
total = total + 1
507+
end
502508
end
503509
end
504510
for distance, nodes in pairs(distanceMap) do
505511
t_insert(distanceList, { distance, nodes })
506512
end
507513
distanceMap = nil
508514
table.sort(distanceList, function(a, b) return a[1] < b[1] end)
515+
-- Count eligible cluster nodes
516+
for _, node in pairs(self.build.spec.tree.clusterNodeMap) do
517+
if not node.alloc and node.modKey ~= "" and not self.mainEnv.grantedPassives[node.id] then
518+
total = total + 1
519+
end
520+
end
521+
509522
for _, data in ipairs(distanceList) do
510523
local distance, nodes = data[1], data[2]
511524
if self.nodePowerMaxDepth and self.nodePowerMaxDepth < distance then
@@ -559,7 +572,11 @@ function CalcsTabClass:PowerBuilder()
559572
end
560573
end
561574
end
575+
nodeIndex = nodeIndex + 1
562576
if coroutine.running() and GetTime() - start > 100 then
577+
if self.build.powerBuilderProgressCallback then
578+
self.build.powerBuilderProgressCallback(m_floor(nodeIndex/total*100))
579+
end
563580
coroutine.yield()
564581
start = GetTime()
565582
end
@@ -581,15 +598,19 @@ function CalcsTabClass:PowerBuilder()
581598
if self.powerStat and self.powerStat.stat and not self.powerStat.ignoreForNodes then
582599
node.power.singleStat = self:CalculatePowerStat(self.powerStat, output, calcBase)
583600
end
584-
end
585-
if coroutine.running() and GetTime() - start > 100 then
586-
coroutine.yield()
587-
start = GetTime()
601+
nodeIndex = nodeIndex + 1
602+
if coroutine.running() and GetTime() - start > 100 then
603+
if self.build.powerBuilderProgressCallback then
604+
self.build.powerBuilderProgressCallback(m_floor(nodeIndex/total*100))
605+
end
606+
coroutine.yield()
607+
start = GetTime()
608+
end
588609
end
589610
end
590611
self.powerMax = newPowerMax
591612
self.powerBuilderInitialized = true
592-
--ConPrintf("Power Build time: %d ms", GetTime() - timer_start)
613+
-- ConPrintf("Power Build time: %d ms", GetTime() - timer_start)
593614
end
594615

595616
function CalcsTabClass:CalculatePowerStat(selection, original, modified)

src/Classes/TreeTab.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ local s_gsub = string.gsub
1919
local s_byte = string.byte
2020
local dkjson = require "dkjson"
2121

22+
-- Helper function to find toast index by content pattern
23+
-- TODO: remove this when when we can control toast notifications better
24+
local function findToastIndex(pattern)
25+
for i, msg in ipairs(main.toastMessages) do
26+
if msg:match(pattern) then
27+
return i
28+
end
29+
end
30+
return nil
31+
end
32+
2233
local TreeTabClass = newClass("TreeTab", "ControlHost", function(self, build)
2334
self.ControlHost()
2435

@@ -278,10 +289,45 @@ local TreeTabClass = newClass("TreeTab", "ControlHost", function(self, build)
278289
end
279290
end)
280291
self.controls.powerReportList.shown = false
292+
-- Progress callback from the CalcsTab power builder coroutine
293+
self.powerBuilderToastActive = false
294+
self.lastProgressToastUpdate = 0
295+
self.build.powerBuilderProgressCallback = function(percent)
296+
local now = GetTime()
297+
if now - self.lastProgressToastUpdate < 100 then
298+
return
299+
end
300+
301+
local message = percent and string.format("Building Power Report... (%d%%)", percent) or "Building Power Report..."
302+
303+
self.controls.powerReportList.label = message
304+
self.lastProgressToastUpdate = now
305+
local toastIndex = findToastIndex("^Building Power Report")
306+
if toastIndex then
307+
main.toastMessages[toastIndex] = message
308+
else
309+
t_insert(main.toastMessages, message)
310+
self.powerBuilderToastActive = true
311+
end
312+
end
313+
-- Completion callback from the CalcsTab power builder coroutine
281314
self.build.powerBuilderCallback = function()
282315
local powerStat = self.build.calcsTab.powerStat or data.powerStatList[1]
283316
local report = self:BuildPowerReportList(powerStat)
284317
self.controls.powerReportList:SetReport(powerStat, report)
318+
local toastIndex = findToastIndex("^Building Power Report")
319+
if self.powerBuilderToastActive and toastIndex then
320+
-- Remove the toast from the queue instead of triggering hide animation
321+
-- This prevents issues when the toast is not currently displayed (queued behind another toast)
322+
-- TODO: look into allowing toast notifications to stack and have UUID's we can control them better
323+
if toastIndex == 1 then
324+
main.toastMode = "HIDING"
325+
main.toastStart = GetTime()
326+
else
327+
t_remove(main.toastMessages, toastIndex)
328+
end
329+
end
330+
self.powerBuilderToastActive = false
285331
end
286332

287333
self.controls.specConvertText = new("LabelControl", { "BOTTOMLEFT", self.controls.specSelect, "TOPLEFT" }, { 0, -14, 0, 16 }, "^7This is an older tree version, which may not be fully compatible with the current game version.")

0 commit comments

Comments
 (0)