Skip to content

Commit a72d64c

Browse files
committed
1 parent 1017b5f commit a72d64c

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

src/Classes/CalcsTab.lua

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

520520
-- Estimate the offensive and defensive power of all unallocated nodes
521521
function CalcsTabClass:PowerBuilder()
522-
--local timer_start = GetTime()
522+
-- local timer_start = GetTime()
523523
local useFullDPS = self.powerStat and self.powerStat.stat == "FullDPS"
524524
local calcFunc, calcBase = self:GetMiscCalculator()
525525
local cache = { }
@@ -540,18 +540,31 @@ function CalcsTabClass:PowerBuilder()
540540
end
541541

542542
local start = GetTime()
543+
local nodeIndex = 0
544+
local total = 0
545+
543546
for nodeId, node in pairs(self.build.spec.nodes) do
544547
wipeTable(node.power)
545548
if node.modKey ~= "" and not self.mainEnv.grantedPassives[nodeId] then
546549
distanceMap[node.pathDist or 1000] = distanceMap[node.pathDist or 1000] or { }
547550
distanceMap[node.pathDist or 1000][nodeId] = node
551+
if not (self.nodePowerMaxDepth and self.nodePowerMaxDepth < node.pathDist) then
552+
total = total + 1
553+
end
548554
end
549555
end
550556
for distance, nodes in pairs(distanceMap) do
551557
t_insert(distanceList, { distance, nodes })
552558
end
553559
distanceMap = nil
554560
table.sort(distanceList, function(a, b) return a[1] < b[1] end)
561+
-- Count eligible cluster nodes
562+
for _, node in pairs(self.build.spec.tree.clusterNodeMap) do
563+
if not node.alloc and node.modKey ~= "" and not self.mainEnv.grantedPassives[node.id] then
564+
total = total + 1
565+
end
566+
end
567+
555568
for _, data in ipairs(distanceList) do
556569
local distance, nodes = data[1], data[2]
557570
if self.nodePowerMaxDepth and self.nodePowerMaxDepth < distance then
@@ -605,7 +618,11 @@ function CalcsTabClass:PowerBuilder()
605618
end
606619
end
607620
end
621+
nodeIndex = nodeIndex + 1
608622
if coroutine.running() and GetTime() - start > 100 then
623+
if self.build.powerBuilderProgressCallback then
624+
self.build.powerBuilderProgressCallback(m_floor(nodeIndex/total*100))
625+
end
609626
coroutine.yield()
610627
start = GetTime()
611628
end
@@ -627,15 +644,19 @@ function CalcsTabClass:PowerBuilder()
627644
if self.powerStat and self.powerStat.stat and not self.powerStat.ignoreForNodes then
628645
node.power.singleStat = self:CalculatePowerStat(self.powerStat, output, calcBase)
629646
end
630-
end
631-
if coroutine.running() and GetTime() - start > 100 then
632-
coroutine.yield()
633-
start = GetTime()
647+
nodeIndex = nodeIndex + 1
648+
if coroutine.running() and GetTime() - start > 100 then
649+
if self.build.powerBuilderProgressCallback then
650+
self.build.powerBuilderProgressCallback(m_floor(nodeIndex/total*100))
651+
end
652+
coroutine.yield()
653+
start = GetTime()
654+
end
634655
end
635656
end
636657
self.powerMax = newPowerMax
637658
self.powerBuilderInitialized = true
638-
--ConPrintf("Power Build time: %d ms", GetTime() - timer_start)
659+
-- ConPrintf("Power Build time: %d ms", GetTime() - timer_start)
639660
end
640661

641662
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

@@ -266,10 +277,45 @@ local TreeTabClass = newClass("TreeTab", "ControlHost", function(self, build)
266277
end
267278
end)
268279
self.controls.powerReportList.shown = false
280+
-- Progress callback from the CalcsTab power builder coroutine
281+
self.powerBuilderToastActive = false
282+
self.lastProgressToastUpdate = 0
283+
self.build.powerBuilderProgressCallback = function(percent)
284+
local now = GetTime()
285+
if now - self.lastProgressToastUpdate < 100 then
286+
return
287+
end
288+
289+
local message = percent and string.format("Building Power Report... (%d%%)", percent) or "Building Power Report..."
290+
291+
self.controls.powerReportList.label = message
292+
self.lastProgressToastUpdate = now
293+
local toastIndex = findToastIndex("^Building Power Report")
294+
if toastIndex then
295+
main.toastMessages[toastIndex] = message
296+
else
297+
t_insert(main.toastMessages, message)
298+
self.powerBuilderToastActive = true
299+
end
300+
end
301+
-- Completion callback from the CalcsTab power builder coroutine
269302
self.build.powerBuilderCallback = function()
270303
local powerStat = self.build.calcsTab.powerStat or data.powerStatList[1]
271304
local report = self:BuildPowerReportList(powerStat)
272305
self.controls.powerReportList:SetReport(powerStat, report)
306+
local toastIndex = findToastIndex("^Building Power Report")
307+
if self.powerBuilderToastActive and toastIndex then
308+
-- Remove the toast from the queue instead of triggering hide animation
309+
-- This prevents issues when the toast is not currently displayed (queued behind another toast)
310+
-- TODO: look into allowing toast notifications to stack and have UUID's we can control them better
311+
if toastIndex == 1 then
312+
main.toastMode = "HIDING"
313+
main.toastStart = GetTime()
314+
else
315+
t_remove(main.toastMessages, toastIndex)
316+
end
317+
end
318+
self.powerBuilderToastActive = false
273319
end
274320

275321
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)