feat: add lifetime total tracking (step 8)

Accumulate lifetimeTotal on every positive PLAYER_MONEY delta and
persist to SavedVariables so it survives /reload and Reset. Display
a 'Lifetime: Xg Ys Zc' label on the HUD frame. Also fix missing
closing 'end' in SlashCmdList closure.
This commit is contained in:
bepis
2026-10-19 21:28:51 +11:00
parent 9a30efa170
commit f7e32111f1
3 changed files with 128 additions and 12 deletions
Regular → Executable
+57 -3
View File
@@ -100,14 +100,19 @@ local timeLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
timeLabel:SetPoint("TOPLEFT", gphLabel, "BOTTOMLEFT", 0, -4)
timeLabel:SetText("Time: 0s")
-- Lifetime total label
local lifetimeLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
lifetimeLabel:SetPoint("TOPLEFT", timeLabel, "BOTTOMLEFT", 0, -4)
lifetimeLabel:SetText("Lifetime: 0g 0s 0c")
-- Update display function
local function UpdateDisplay()
local elapsed = GetTime() - sessionStart
local hours = elapsed / 3600
-- Earned (gross)
earnedLabel:SetText("Earned: " .. FormatCopper(sessionGross))
-- Gold per hour (show "---" until threshold)
if elapsed >= GOLD_PER_HOUR_SHOW_AFTER and hours > 0 then
local gph = sessionGross / hours
@@ -115,10 +120,13 @@ local function UpdateDisplay()
else
gphLabel:SetText("Rate: ---")
end
-- Time elapsed
local timeStr = SecondsToTime(elapsed, false, false, 1)
timeLabel:SetText("Time: " .. timeStr)
-- Lifetime total
lifetimeLabel:SetText("Lifetime: " .. FormatCopper(lifetimeTotal))
end
-- ---------------------------------------------------------------------------
@@ -171,6 +179,12 @@ loginFrame:SetScript("OnEvent", function(self, event)
end)
end)
-- ---------------------------------------------------------------------------
-- Lifetime total (Step 8)
-- ---------------------------------------------------------------------------
local lifetimeTotal = SessionGoldTrackerDB.lifetimeTotal or 0
SessionGoldTrackerDB.lifetimeTotal = lifetimeTotal
-- ---------------------------------------------------------------------------
-- Money tracking (PLAYER_MONEY event)
-- ---------------------------------------------------------------------------
@@ -183,6 +197,8 @@ moneyFrame:SetScript("OnEvent", function(self, event)
if delta > 0 then
sessionGross = sessionGross + delta
lifetimeTotal = lifetimeTotal + delta
SessionGoldTrackerDB.lifetimeTotal = lifetimeTotal
end
sessionNet = sessionNet + delta
@@ -195,3 +211,41 @@ moneyFrame:SetScript("OnEvent", function(self, event)
))
end
end)
-- ---------------------------------------------------------------------------
-- Reset Button (Step 6)
-- ---------------------------------------------------------------------------
local resetButton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
resetButton:SetSize(60, 22)
resetButton:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -8, 8)
resetButton:SetText("Reset")
local function DoReset()
sessionGross = 0
sessionNet = 0
sessionStart = GetTime()
sessionGoldStart = GetMoney()
lastMoney = GetMoney()
UpdateDisplay()
print("[SessionGoldTracker] Session reset.")
end
resetButton:SetScript("OnClick", DoReset)
-- ---------------------------------------------------------------------------
-- Slash Command (Step 7)
-- ---------------------------------------------------------------------------
SlashCmdList["SESSIONGOLDTRACKER"] = function(msg)
msg = msg and msg:lower() or ""
if msg == "reset" then
DoReset()
else
if frame:IsShown() then
frame:Hide()
else
frame:Show()
end
end
end
SLASH_SESSIONGOLDTRACKER1 = "/gt"