Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 20 additions & 29 deletions src/Classes/TreeTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ local s_gsub = string.gsub
local s_byte = string.byte
local dkjson = require "dkjson"

-- Helper function to find toast index by content pattern
-- TODO: remove this when when we can control toast notifications better
local function findToastIndex(pattern)
for i, msg in ipairs(main.toastMessages) do
if msg:match(pattern) then
return i
end
end
return nil
end

local TreeTabClass = newClass("TreeTab", "ControlHost", function(self, build)
self.ControlHost()

Expand Down Expand Up @@ -290,7 +279,7 @@ local TreeTabClass = newClass("TreeTab", "ControlHost", function(self, build)
end)
self.controls.powerReportList.shown = false
-- Progress callback from the CalcsTab power builder coroutine
self.powerBuilderToastActive = false
self.powerBuilderToastId = nil
self.lastProgressToastUpdate = 0
self.build.powerBuilderProgressCallback = function(percent)
local now = GetTime()
Expand All @@ -301,33 +290,29 @@ local TreeTabClass = newClass("TreeTab", "ControlHost", function(self, build)
local message = percent and string.format("Building Power Report... (%d%%)", percent) or "Building Power Report..."

self.controls.powerReportList.label = message

if self.powerBuilderToastId and ToastNotification:WasDismissed(self.powerBuilderToastId) then
return
end
self.lastProgressToastUpdate = now
local toastIndex = findToastIndex("^Building Power Report")
if toastIndex then
main.toastMessages[toastIndex] = message

if self.powerBuilderToastId and ToastNotification:Exists(self.powerBuilderToastId) then
ToastNotification:Update(self.powerBuilderToastId, message)
else
t_insert(main.toastMessages, message)
self.powerBuilderToastActive = true
self.powerBuilderToastId = ToastNotification:Add(message)
end
end
-- Completion callback from the CalcsTab power builder coroutine
self.build.powerBuilderCallback = function()
local powerStat = self.build.calcsTab.powerStat or data.powerStatList[1]
local report = self:BuildPowerReportList(powerStat)
self.controls.powerReportList:SetReport(powerStat, report)
local toastIndex = findToastIndex("^Building Power Report")
if self.powerBuilderToastActive and toastIndex then
-- Remove the toast from the queue instead of triggering hide animation
-- This prevents issues when the toast is not currently displayed (queued behind another toast)
-- TODO: look into allowing toast notifications to stack and have UUID's we can control them better
if toastIndex == 1 then
main.toastMode = "HIDING"
main.toastStart = GetTime()
else
t_remove(main.toastMessages, toastIndex)
end

if self.powerBuilderToastId then
ToastNotification:ClearDismissed(self.powerBuilderToastId)
ToastNotification:Remove(self.powerBuilderToastId)
self.powerBuilderToastId = nil
end
self.powerBuilderToastActive = false
end

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.")
Expand Down Expand Up @@ -1029,6 +1014,12 @@ function TreeTabClass:SetPowerCalc(powerStat)
self.build.calcsTab.powerBuildFlag = true
self.build.calcsTab.powerStat = powerStat
self.controls.powerReportList:SetReport(powerStat, nil)
-- Remove old toast and clear dismissed state so toast can show for new power report
if self.powerBuilderToastId then
ToastNotification:ClearDismissed(self.powerBuilderToastId)
ToastNotification:Remove(self.powerBuilderToastId, true)
self.powerBuilderToastId = nil
end
end

function TreeTabClass:BuildPowerReportList(currentStat)
Expand Down
63 changes: 14 additions & 49 deletions src/Modules/Main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ LoadModule("Modules/CalcTools")
LoadModule("Modules/PantheonTools")
LoadModule("Modules/BuildSiteTools")

-- Load as global so other modules can access the same instance
ToastNotification = LoadModule("Modules/ToastNotification")

--[[if launch.devMode then
for skillName, skill in pairs(data.enchantments.Helmet) do
for _, mod in ipairs(skill.ENDGAME) do
Expand Down Expand Up @@ -233,19 +236,14 @@ function main:Init()
self.controls.devMode.shown = function()
return launch.devMode
end
self.controls.dismissToast = new("ButtonControl", {"BOTTOMLEFT",self.anchorMain,"BOTTOMLEFT"}, {0, function() return -self.mainBarHeight + self.toastHeight end, 80, 20}, "Dismiss", function()
self.toastMode = "HIDING"
self.toastStart = GetTime()
end)
self.controls.dismissToast.shown = function()
return self.toastMode == "SHOWN"
end

self.mainBarHeight = 58
self.toastMessages = { }

-- Initialize toast notification system
ToastNotification:Init(self.anchorMain)

if launch.devMode and GetTime() >= 0 and GetTime() < 15000 then
t_insert(self.toastMessages, [[
ToastNotification:Add([[
^xFF7700Warning: ^7Developer Mode active!
The program is currently running in developer
mode, which is not intended for normal use.
Expand Down Expand Up @@ -371,56 +369,23 @@ function main:OnFrame()
self:CallMode("OnFrame", self.inputEvents, self.viewPort)

if launch.updateErrMsg then
t_insert(self.toastMessages, string.format("Update check failed!\n%s", launch.updateErrMsg))
ToastNotification:Add(string.format("Update check failed!\n%s", launch.updateErrMsg))
launch.updateErrMsg = nil
end
if launch.updateAvailable then
if launch.updateAvailable == "none" then
t_insert(self.toastMessages, "No update available\nYou are running the latest version.")
ToastNotification:Add("No update available\nYou are running the latest version.")
launch.updateAvailable = nil
elseif not self.updateAvailableShown then
t_insert(self.toastMessages, "Update Available\nAn update has been downloaded and is ready\nto be applied.")
ToastNotification:Add("Update Available\nAn update has been downloaded and is ready\nto be applied.")
self.updateAvailableShown = true
end
end

-- Run toasts
if self.toastMessages[1] then
if not self.toastMode then
self.toastMode = "SHOWING"
self.toastStart = GetTime()
self.toastHeight = #self.toastMessages[1]:gsub("[^\n]","") * 16 + 20 + 40
end
if self.toastMode == "SHOWING" then
local now = GetTime()
if now >= self.toastStart + 250 then
self.toastMode = "SHOWN"
else
self.mainBarHeight = 58 + self.toastHeight * (now - self.toastStart) / 250
end
end
if self.toastMode == "SHOWN" then
self.mainBarHeight = 58 + self.toastHeight
elseif self.toastMode == "HIDING" then
local now = GetTime()
if now >= self.toastStart + 75 then
self.toastMode = nil
self.mainBarHeight = 58
t_remove(self.toastMessages, 1)
else
self.mainBarHeight = 58 + self.toastHeight * (1 - (now - self.toastStart) / 75)
end
end
if self.toastMode then
SetDrawColor(0.85, 0.85, 0.85)
DrawImage(nil, 0, self.screenH - self.mainBarHeight, 312, self.mainBarHeight)
SetDrawColor(0.1, 0.1, 0.1)
DrawImage(nil, 0, self.screenH - self.mainBarHeight + 4, 308, self.mainBarHeight - 4)
SetDrawColor(1, 1, 1)
DrawString(4, self.screenH - self.mainBarHeight + 8, "LEFT", 20, "VAR", self.toastMessages[1]:gsub("\n.*",""))
DrawString(4, self.screenH - self.mainBarHeight + 28, "LEFT", 16, "VAR", self.toastMessages[1]:gsub("^[^\n]*\n?",""))
end
end
-- Update and render toasts
ToastNotification:UpdateFrame(self.inputEvents, self.viewPort, self.screenH)
local totalToastHeight = ToastNotification:Render()
self.mainBarHeight = 58 + totalToastHeight

-- Draw main controls
SetDrawColor(0.85, 0.85, 0.85)
Expand Down
Loading