diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e5b595b..2afdad0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,6 +59,8 @@ jobs: run: python -m pip install --disable-pip-version-check --prefer-binary pillow - name: Verify the Adventurer's Notebook skin run: python tests/notebook.py + - name: Verify the Lifetime Stats and Stats Explorer skins + run: python tests/framed.py - name: Verify release packaging run: python tests/package_release.py diff --git a/CHANGELOG.md b/CHANGELOG.md index fe1d896..06d41c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,26 @@ All notable changes to LifeTimeStats. Format: [Keep a Changelog](https://keepach From in-game screenshots of 1.24.0. ### Added +- **Two new skins built from your mock-ups** (Settings > Appearance > Theme; a change applies after a reload): + - **Lifetime Stats, the new default.** + - A dark wooden frame with gold corners and a "Lifetime Stats" plaque, around clean parchment. + - A menu of pages down the left, with the open page in green. + - A search box, and dropdowns for the character (this one or all characters) and the time range (all time, this session, today, last 7 or 30 days). + - The overview page: + - your character with level, class, faction and Adventurer score; + - four counters (total kills, quests completed, achievement points, gold earned) that open their statistic when clicked; + - a lifetime activity line of your total kills over the last 30 days; + - recent milestones from your Journal; + - highlights of your best moments with their dates (biggest hit, best boss DPS, most gold and most quests in a day, most kills in one fight, longest kill streak, longest life); + - recent activity (quests, good items, levels and Journal moments), five at a time with page buttons. + - **Stats Explorer.** + - The same frame, with a dark wooden menu and a Session / Daily / Weekly / Monthly / Lifetime bar. + - The overview page: + - your lifetime score with a motto that changes as it grows; + - recent activity as a timeline; + - a crest card each for Combat, Exploration, Progression and Collections, which open their pages; + - your pinned statistics along the bottom, or four headline statistics until you pin some. + - **Shared with the notebook:** both skins follow its paper rules, so text is darkened for parchment and sized for reading. The Adventurer's Notebook and the other skins stay in Settings. - **Every statistic has its own story:** click any row on a stat page or on Records to open a card for that statistic. - **What it is:** its name, where it lives (Battles › Crowd control) and how it is measured. - **Counters:** lifetime, this session, today, the last 7 and 30 days, the best day ever with its date, how many days you did it at all, and the total across all your characters. A chart shows the last 30 days. diff --git a/CREDITS.md b/CREDITS.md index 4f002e9..0a35951 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -10,5 +10,5 @@ - **Forever client API:** the captured API surface and live-client findings in Thunderz96/forever-addon-kit (MIT), used by `scripts/api_scan.py` during development; nothing from it is bundled. - **Forever addon restrictions:** findings shared by the authors of Field Guide (cjber/field-guide-forever issue #91) and the WoW Forever addon restriction notes on wowforevertierlist.com, which pointed to the combat log being secure-only. - **API references:** [warcraft.wiki.gg](https://warcraft.wiki.gg/), [Gethe/wow-ui-source](https://github.com/Gethe/wow-ui-source). -- **Artwork:** icon, logo, sidebar glyphs and dot texture drawn for this addon. The Adventurer's Notebook textures (paper, wood, spiral ring, tab, tag, fold, seal) are generated by `scripts/make_notebook_textures.py` and its 19 ink sketches by `scripts/make_notebook_sketches.py`; the layout idea of a tabbed adventurer's notebook was suggested by the user from a printed D&D planner, but no artwork from it is used. Logo/icon text uses Inter (SIL Open Font License 1.1) and DejaVu Sans Mono (Bitstream Vera license). The in-game window uses the game's own fonts and the standard minimap border texture. +- **Artwork:** icon, logo, sidebar glyphs and dot texture drawn for this addon. The Lifetime Stats and Stats Explorer frame textures (parchment, wood, frame rails, gold corners, title plaque, compass emblem, crests, menu highlight, divider) are generated by `scripts/make_framed_textures.py`; their layout follows mock-ups supplied by the user, and no artwork from the mock-ups is used. The overview's milestone and highlight icons are the game's own icons. The Adventurer's Notebook textures (paper, wood, spiral ring, tab, tag, fold, seal) are generated by `scripts/make_notebook_textures.py` and its 19 ink sketches by `scripts/make_notebook_sketches.py`; the layout idea of a tabbed adventurer's notebook was suggested by the user from a printed D&D planner, but no artwork from it is used. Logo/icon text uses Inter (SIL Open Font License 1.1) and DejaVu Sans Mono (Bitstream Vera license). The in-game window uses the game's own fonts and the standard minimap border texture. - **License text:** GNU General Public License v3, Free Software Foundation. diff --git a/Core.lua b/Core.lua index 01346db..2db4ebd 100644 --- a/Core.lua +++ b/Core.lua @@ -344,7 +344,7 @@ function ns.ApplyAccent() -- Very light class colours (Priest) would blend with cream text: tint them slightly darker. if r + g + b > 2.6 then r, g, b = r * 0.82, g * 0.82, b * 0.82 end -- On the notebook's paper, class colours are inked: darker so they read like ink. - if ns.Notebook and ns.Notebook() and ns.W and ns.W.InkRGB then r, g, b = ns.W.InkRGB(r, g, b) end + if ns.Paper and ns.Paper() and ns.W and ns.W.InkRGB then r, g, b = ns.W.InkRGB(r, g, b) end local a = ns.THEME.amber a[1], a[2], a[3] = r, g, b ns.accent2 = { r * 0.78, g * 0.78, b * 0.78, 1 } diff --git a/Framed.lua b/Framed.lua new file mode 100644 index 0000000..fc1303f --- /dev/null +++ b/Framed.lua @@ -0,0 +1,251 @@ +-- LifeTimeStats - the framed tome skins: "Lifetime Stats" (the default) and "Stats Explorer". +-- A dark wooden frame with gold corners and a title plaque around clean parchment, a menu of +-- pages down the left (parchment in Lifetime Stats, dark wood in Stats Explorer) and the +-- character and time-range choices as a dropdown or a segmented bar. Pages are unchanged; the +-- overview page has its own layout for each skin (Overview.lua). +-- Copyright (C) 2026 Malikor. Licensed under GPL-3.0-or-later (see LICENSE). +local _, ns = ... + +local LIGHT = { 0.94, 0.90, 0.80 } -- light text on wood and on the green selection +local GOLD_TEXT = { 1.00, 0.84, 0.48 } -- the plaque's title + +function ns.FramedTitle() return ns.Explorer and ns.Explorer() and "Stats Explorer" or "Lifetime Stats" end + +-- Light text that the paper ink rule must leave alone (on wood, on the plaque, on green). +local function Light(fs, c) + if not fs then return fs end + fs.noInk = true + c = c or LIGHT + fs:SetTextColor(c[1], c[2], c[3], c[4] or 1) + return fs +end +ns.FramedLight = Light + +-- ------------------------------------------------------------ dropdown +-- A button showing the current choice; clicking it opens a list below it. +local function Dropdown(parent, w, items, onPick, opts) + local W, T = ns.W, ns.THEME + opts = opts or {} + local b = CreateFrame("Button", nil, parent) + b:SetSize(w, 28) + local bg = W.Panel(b, T.tile, T.edge); bg:SetAllPoints(); bg:SetFrameLevel(b:GetFrameLevel()) + local x = 10 + if opts.portrait then + b.portrait = b:CreateTexture(nil, "ARTWORK") + b.portrait:SetSize(22, 22); b.portrait:SetPoint("LEFT", 4, 0) + x = 32 + end + if opts.icon then + b.icon = W.Icon(b, opts.icon, 16, T.dim); b.icon:SetPoint("LEFT", 8, 0) + x = 30 + end + b.text = W.Text(b, 12, T.text); b.text:SetPoint("LEFT", x, 0); b.text:SetPoint("RIGHT", -26, 0); b.text:SetJustifyH("LEFT") + b.arrow = b:CreateTexture(nil, "ARTWORK") + b.arrow:SetSize(18, 18); b.arrow:SetPoint("RIGHT", -5, 0) + b.arrow:SetTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up") + local menu = W.Panel(b, T.bg, T.edge) + menu:SetPoint("TOPLEFT", b, "BOTTOMLEFT", 0, -2) + menu:SetSize(w, #items * 24 + 6) + menu:SetFrameLevel((b:GetFrameLevel() or 1) + 40) + menu:Hide() + b.menu, b.items, b.rows = menu, items, {} + for i, it in ipairs(items) do + local r = CreateFrame("Button", nil, menu) + r:SetSize(w - 6, 24); r:SetPoint("TOPLEFT", 3, -3 - (i - 1) * 24) + r.hl = W.Fill(r, T.tileHi); r.hl:SetAllPoints(); r.hl:Hide() + r.text = W.Text(r, 12, T.text); r.text:SetPoint("LEFT", 8, 0); r.text:SetText(it.label) + r.id = it.id + r:SetScript("OnEnter", function(self) + self.hl:Show() + if it.tip then + GameTooltip:SetOwner(self, "ANCHOR_RIGHT") + GameTooltip:AddLine(it.label, ns.TipColor("amber")) + GameTooltip:AddLine(it.tip, ns.TipColor("text", true)) + GameTooltip:Show() + end + end) + r:SetScript("OnLeave", function(self) self.hl:Hide(); GameTooltip:Hide() end) + r:SetScript("OnClick", function() menu:Hide(); onPick(it.id) end) + b.rows[i] = r + end + b:SetScript("OnClick", function() menu:SetShown(not menu:IsShown()) end) + if opts.tip then W.Tip(b, opts.tip[1], opts.tip[2]) end + function b:Select(id) + self.selected = id + for _, it in ipairs(self.items) do + if it.id == id then self.text:SetText(it.short or it.label) end + end + for _, r in ipairs(self.rows) do + local c = r.id == id and T.amber or T.text + r.text:SetTextColor(c[1], c[2], c[3]) + end + if self.portrait and SetPortraitTexture then pcall(SetPortraitTexture, self.portrait, "player") end + end + return b +end +ns.FramedDropdown = Dropdown + +-- ------------------------------------------------------------ the frame +function ns.BuildFramedSkin(win, side, head, dim) + local W, T = ns.W, ns.THEME + local M = W.MEDIA .. "framed\\" + local explorer = ns.Explorer() + local fr = {} + win.framed = fr + if win.SetBackdropColor then pcall(win.SetBackdropColor, win, 0, 0, 0, 0) end + if win.SetBackdropBorderColor then pcall(win.SetBackdropBorderColor, win, 0, 0, 0, 0) end + + -- clean parchment inside the frame + fr.paper = win:CreateTexture(nil, "BACKGROUND", nil, -8) + fr.paper:SetAllPoints() + fr.paper:SetTexture(M .. "parchment") + + -- the wooden frame: four rails just outside the window, gold corners over their joins + local art = CreateFrame("Frame", nil, win) + art:SetAllPoints() + art:SetFrameLevel((win:GetFrameLevel() or 1) + 30) + fr.art = art + local R = 26 + local function Rail(tex, coords) + local t = art:CreateTexture(nil, "BORDER") + t:SetTexture(M .. tex) + if coords then t:SetTexCoord(unpack(coords)) end + return t + end + fr.top = Rail("edge_h"); fr.top:SetPoint("BOTTOMLEFT", win, "TOPLEFT", 0, -4); fr.top:SetPoint("BOTTOMRIGHT", win, "TOPRIGHT", 0, -4); fr.top:SetHeight(R + 4) + fr.bottom = Rail("edge_h", { 0, 1, 1, 0 }); fr.bottom:SetPoint("TOPLEFT", win, "BOTTOMLEFT", 0, 4); fr.bottom:SetPoint("TOPRIGHT", win, "BOTTOMRIGHT", 0, 4); fr.bottom:SetHeight(R + 4) + fr.left = Rail("edge_v"); fr.left:SetPoint("TOPRIGHT", win, "TOPLEFT", 4, 0); fr.left:SetPoint("BOTTOMRIGHT", win, "BOTTOMLEFT", 4, 0); fr.left:SetWidth(R + 4) + fr.right = Rail("edge_v", { 1, 0, 0, 1 }); fr.right:SetPoint("TOPLEFT", win, "TOPRIGHT", -4, 0); fr.right:SetPoint("BOTTOMLEFT", win, "BOTTOMRIGHT", -4, 0); fr.right:SetWidth(R + 4) + fr.corners = {} + for i, c in ipairs({ + { "TOPLEFT", -R + 4, R - 4, { 0, 1, 0, 1 } }, { "TOPRIGHT", R - 4, R - 4, { 1, 0, 0, 1 } }, + { "BOTTOMLEFT", -R + 4, -R + 4, { 0, 1, 1, 0 } }, { "BOTTOMRIGHT", R - 4, -R + 4, { 1, 0, 1, 0 } }, + }) do + local t = art:CreateTexture(nil, "ARTWORK") + t:SetTexture(M .. "corner"); t:SetSize(52, 52); t:SetTexCoord(unpack(c[4])) + t:SetPoint(c[1], win, c[1], c[2], c[3]) + fr.corners[i] = t + end + + -- the title plaque over the top rail + local plaque = CreateFrame("Frame", nil, art) + plaque:SetSize(440, 96) + plaque:SetPoint("CENTER", win, "TOP", 0, 18) -- its body ends just above the header row + plaque:SetFrameLevel((art:GetFrameLevel() or 1) + 2) + local pt = plaque:CreateTexture(nil, "ARTWORK"); pt:SetAllPoints(); pt:SetTexture(M .. "plaque") + local title = Light(W.Text(plaque, 22, GOLD_TEXT, W.FONT, "CENTER"), GOLD_TEXT) + title:SetPoint("CENTER", 14, 0) + title:SetText(ns.FramedTitle()) + if title.SetShadowOffset then title:SetShadowOffset(1, -1); title:SetShadowColor(0, 0, 0, 0.9) end + local emblem = plaque:CreateTexture(nil, "OVERLAY") + emblem:SetSize(34, 34); emblem:SetPoint("RIGHT", title, "LEFT", -10, 0); emblem:SetTexture(M .. "emblem") + fr.plaque, fr.title, fr.emblem = plaque, title, emblem + + -- header: the old title moves into the plaque; character and range become the skin's controls + local hp = win.headParts or {} + for _, k in ipairs({ "logo", "t1", "t2", "rule", "portrait", "ring" }) do if hp[k] then hp[k]:Hide() end end + if win.nameText then win.nameText:Hide() end + if win.level then win.level:Hide() end + local S = ns.settings + local oldScope, oldRange = win.scopeSeg, win.rangeSeg + oldScope:Hide(); oldRange:Hide() + local charDD = Dropdown(head, explorer and 220 or 200, { + { id = "char", label = UnitName("player") or "This character", tip = "Only this character." }, + { id = "account", label = "All characters", tip = "Every character on this account that has logged in with LifeTimeStats." }, + }, function(id) S.scope = id; if ns.InvalidateAccount then ns.InvalidateAccount() end; ns.RefreshWindow() end, + { portrait = true, tip = { "Character", "Whose statistics to show: this character or every character on the account." } }) + win.scopeSeg = charDD + local sb = hp.sb + local close, gear = hp.close, hp.gear + if explorer then + charDD:SetPoint("LEFT", head, "LEFT", 12, 0) + local seg = W.Segmented(head, { + { id = "session", label = "Session", tip = "Since you logged in (or reset the session)." }, + { id = "today", label = "Daily", tip = "Since midnight, local time." }, + { id = "week", label = "Weekly", tip = "The last 7 days, today included." }, + { id = "month", label = "Monthly", tip = "The last 30 days, today included." }, + { id = "lifetime", label = "Lifetime", tip = "Everything since LifeTimeStats was installed." }, + }, function(id) S.range = id; ns.RefreshWindow() end) + for _, b in ipairs(seg.buttons) do b:SetHeight(26); b:SetWidth(math.max(84, b:GetWidth())) end + local x = 1 + for _, b in ipairs(seg.buttons) do b:ClearAllPoints(); b:SetPoint("LEFT", x, 0); x = x + b:GetWidth() end + seg:SetSize(x + 1, 28) + seg:SetPoint("LEFT", charDD, "RIGHT", 16, 0) + -- the chosen range is a green tab with light text + local plain = seg.Select + function seg:Select(id) + plain(self, id) + for _, b in ipairs(self.buttons) do + local on = b.id == id + b.bg:SetShown(on) + if on then W.Color(b.bg, T.amber) end + b.bar:Hide() + b.text.noInk = on or nil + local c = on and LIGHT or T.text + b.text:SetTextColor(c[1], c[2], c[3]) + end + end + win.rangeSeg = seg + if sb then sb:ClearAllPoints(); sb:SetPoint("RIGHT", close, "LEFT", -14, 0); sb:SetSize(250, 28) end + if gear then gear:ClearAllPoints(); gear:SetPoint("RIGHT", sb or close, "LEFT", -10, 0) end + else + local rangeDD = Dropdown(head, 150, { + { id = "lifetime", label = "All time", tip = "Everything since LifeTimeStats was installed." }, + { id = "session", label = "This session", tip = "Since you logged in (or reset the session)." }, + { id = "today", label = "Today", tip = "Since midnight, local time." }, + { id = "week", label = "Last 7 days", tip = "The last 7 days, today included." }, + { id = "month", label = "Last 30 days", tip = "The last 30 days, today included." }, + }, function(id) S.range = id; ns.RefreshWindow() end, { icon = "clock", tip = { "Time range", "Which stretch of time the pages show." } }) + rangeDD:SetPoint("RIGHT", close, "LEFT", -12, 0) + charDD:SetPoint("RIGHT", rangeDD, "LEFT", -10, 0) + win.rangeSeg = rangeDD + if sb then sb:ClearAllPoints(); sb:SetPoint("LEFT", head, "LEFT", 12, 0); sb:SetSize(dim.SIDEBAR_W + 60, 28) end + if gear then gear:ClearAllPoints(); gear:SetPoint("RIGHT", charDD, "LEFT", -10, 0) end + end + + -- the menu of pages + local panel = side:CreateTexture(nil, "BACKGROUND", nil, -6) + panel:SetPoint("TOPLEFT", 6, -2); panel:SetPoint("BOTTOMRIGHT", -4, 2) + if explorer then + panel:SetTexture(M .. "wood") + local rim = W.Panel(side, { 0, 0, 0, 0 }, { 0.79, 0.63, 0.33, 0.9 }) + rim:SetPoint("TOPLEFT", 6, -2); rim:SetPoint("BOTTOMRIGHT", -4, 2) + rim:SetFrameLevel(side:GetFrameLevel()) + else + panel:SetColorTexture(T.tile[1], T.tile[2], T.tile[3], 0.6) + end + fr.menuPanel = panel + for _, b in ipairs(win.navButtons or {}) do + if b.kb then b.kb:Hide() end + b.bar:Hide() + b.bg:SetAlpha(explorer and 0.14 or 0.5) + b.sel = b:CreateTexture(nil, "BACKGROUND", nil, 2) + b.sel:SetPoint("TOPLEFT", 4, 0); b.sel:SetPoint("BOTTOMRIGHT", 6, 0) + b.sel:SetTexture(M .. "navsel") + b.sel:SetVertexColor(T.amber[1], T.amber[2], T.amber[3], 1) + b.sel:Hide() + b.text.noInk = true + b.text:SetFont(W.FONT, 13, "") + if explorer then b.text:SetTextColor(LIGHT[1], LIGHT[2], LIGHT[3]) end + end + if explorer and win.todayBox then win.todayBox:Hide() end -- its pinned statistics sit along the bottom instead + fr.divider = side:CreateTexture(nil, "ARTWORK") + fr.divider:SetSize(140, 9); fr.divider:SetTexture(M .. "divider") + local navBottom = 6 + #(win.navButtons or {}) * 29 + fr.divider:SetPoint("TOP", side, "TOPLEFT", (dim.SIDEBAR_W) / 2, -navBottom - 2) + local dc = explorer and { 0.79, 0.63, 0.33 } or T.edge + fr.divider:SetVertexColor(dc[1], dc[2], dc[3], 0.9) + return fr +end + +-- Selected and unselected menu entries (called from ShowPage after the generic styling). +function ns.StyleFramedNav(b, sel) + local T = ns.THEME + if not b.sel then return end + b.sel:SetShown(sel) + local explorer = ns.Explorer() + local c = sel and LIGHT or (explorer and LIGHT or T.text) + b.text:SetTextColor(c[1], c[2], c[3]) + local ic = sel and LIGHT or (explorer and { 0.80, 0.72, 0.56 } or T.dim) + b.icon:SetVertexColor(ic[1], ic[2], ic[3]) +end diff --git a/LifeTimeStats.toc b/LifeTimeStats.toc index 6f91c04..83c4cf9 100644 --- a/LifeTimeStats.toc +++ b/LifeTimeStats.toc @@ -37,6 +37,8 @@ Achievements.lua Share.lua Backup.lua Notebook.lua +Framed.lua +Overview.lua UI.lua GuideUI.lua RosterUI.lua diff --git a/Media/framed/corner.tga b/Media/framed/corner.tga new file mode 100644 index 0000000..d6c2dde Binary files /dev/null and b/Media/framed/corner.tga differ diff --git a/Media/framed/crest.tga b/Media/framed/crest.tga new file mode 100644 index 0000000..b455b60 Binary files /dev/null and b/Media/framed/crest.tga differ diff --git a/Media/framed/crest_rim.tga b/Media/framed/crest_rim.tga new file mode 100644 index 0000000..5a92703 Binary files /dev/null and b/Media/framed/crest_rim.tga differ diff --git a/Media/framed/divider.tga b/Media/framed/divider.tga new file mode 100644 index 0000000..8fef29d Binary files /dev/null and b/Media/framed/divider.tga differ diff --git a/Media/framed/edge_h.tga b/Media/framed/edge_h.tga new file mode 100644 index 0000000..630b99b Binary files /dev/null and b/Media/framed/edge_h.tga differ diff --git a/Media/framed/edge_v.tga b/Media/framed/edge_v.tga new file mode 100644 index 0000000..01dcada Binary files /dev/null and b/Media/framed/edge_v.tga differ diff --git a/Media/framed/emblem.tga b/Media/framed/emblem.tga new file mode 100644 index 0000000..553cf3c Binary files /dev/null and b/Media/framed/emblem.tga differ diff --git a/Media/framed/navsel.tga b/Media/framed/navsel.tga new file mode 100644 index 0000000..b77e7fe Binary files /dev/null and b/Media/framed/navsel.tga differ diff --git a/Media/framed/parchment.tga b/Media/framed/parchment.tga new file mode 100644 index 0000000..8523154 Binary files /dev/null and b/Media/framed/parchment.tga differ diff --git a/Media/framed/plaque.tga b/Media/framed/plaque.tga new file mode 100644 index 0000000..dbfcb8c Binary files /dev/null and b/Media/framed/plaque.tga differ diff --git a/Media/framed/wood.tga b/Media/framed/wood.tga new file mode 100644 index 0000000..83212b7 Binary files /dev/null and b/Media/framed/wood.tga differ diff --git a/Options.lua b/Options.lua index d1d619c..dd3e950 100644 --- a/Options.lua +++ b/Options.lua @@ -166,7 +166,7 @@ function ns.CreateOptions() -- The notebook palette is dark ink meant for paper; the Options window is dark, so the -- panel gets its own parchment sheet behind it. - if ns.Notebook and ns.Notebook() then + if ns.Paper and ns.Paper() then local sheet = panel:CreateTexture(nil, "BACKGROUND", nil, -7) sheet:SetPoint("TOPLEFT", -6, 6); sheet:SetPoint("BOTTOMRIGHT", 6, -6) sheet:SetTexture(W.MEDIA .. "notebook\\sheet") diff --git a/Overview.lua b/Overview.lua new file mode 100644 index 0000000..42c5d78 --- /dev/null +++ b/Overview.lua @@ -0,0 +1,531 @@ +-- LifeTimeStats - the overview page of the framed skins. +-- Lifetime Stats: the hero, four headline counters, a lifetime activity line, recent +-- milestones, highlights (your best moments) and recent activity, a page at a time. +-- Stats Explorer: the lifetime score with its motto, recent activity, a card for each part of +-- the adventure (combat, exploration, progression, collections) and pinned statistics. +-- The data helpers below are plain functions (tested offline); the builders take the page +-- helpers from UI.lua. +-- Copyright (C) 2026 Malikor. Licensed under GPL-3.0-or-later (see LICENSE). +local _, ns = ... + +local ICON = "Interface\\Icons\\" +local function N(v) return (type(v) == "number" and v == v) and v or 0 end +local function c(v, k) return N(v and v.c and v.c[k]) end +local function r(v, k) return N(v and v.r and v.r[k]) end + +-- "2m ago", "5h ago", "3 days ago" +function ns.Ago(t, now) + if type(t) ~= "number" then return "" end + local d = (now or time()) - t + if d < 60 then return "just now" end + if d < 3600 then return math.floor(d / 60) .. "m ago" end + if d < 86400 then return math.floor(d / 3600) .. "h ago" end + local days = math.floor(d / 86400) + return days == 1 and "1 day ago" or (days .. " days ago") +end + +-- ------------------------------------------------------------ milestones (the Journal) +local function JournalIcon(e) + local text = type(e[2]) == "string" and e[2] or "" + if text:find("^Reached level") then return ICON .. "Spell_Holy_SurgeOfLight" end + if e.kind == "boss" then return ICON .. "INV_Misc_Head_Dragon_01" end + if e.kind == "death" then return ICON .. "INV_Misc_Bone_HumanSkull_01" end + if e.kind == "personalBest" then return ICON .. "INV_Misc_Gem_Pearl_04" end + if e.kind == "first" then return ICON .. "INV_Misc_Map_01" end + return ICON .. "INV_Misc_Book_09" +end +local function JournalSub(e) + local parts = {} + if type(e.zone) == "string" and e.zone ~= "" then parts[#parts + 1] = e.zone end + if N(e[3]) > 0 then parts[#parts + 1] = "level " .. e[3] end + return table.concat(parts, " · ") +end + +-- The newest Journal moments: { at, title, sub, icon }. +function ns.OverviewMilestones(rec, n) + rec = rec or ns.char + local out = {} + local j = (rec and rec.journal) or {} + for i = #j, 1, -1 do + local e = j[i] + if type(e) == "table" and type(e[1]) == "number" and type(e[2]) == "string" then + out[#out + 1] = { at = e[1], title = e[2], sub = JournalSub(e), icon = JournalIcon(e) } + if #out >= (n or 50) then break end + end + end + return out +end + +-- Everything lately, newest first: quests turned in, good items, level-ups and Journal moments. +local QUALITY_ICON = { [2] = "INV_Misc_Bag_10", [3] = "INV_Misc_Gem_Sapphire_02", [4] = "INV_Misc_Gem_Amethyst_02", [5] = "INV_Misc_Gem_Topaz_01" } +function ns.OverviewActivity(rec, n) + rec = rec or ns.char + local out = {} + for _, q in ipairs((rec and rec.quests) or {}) do + if type(q) == "table" and type(q.t) == "number" then + out[#out + 1] = { at = q.t, title = "Completed a quest", sub = tostring(q.n or "?"), icon = ICON .. "INV_Misc_Note_01" } + end + end + for _, it in ipairs((rec and rec.items) or {}) do + if type(it) == "table" and type(it.t) == "number" and N(it.q) >= 2 then + out[#out + 1] = { at = it.t, title = "Obtained " .. tostring(it.n or "an item"), sub = tostring(it.src or ""), icon = ICON .. (QUALITY_ICON[it.q] or QUALITY_ICON[2]) } + end + end + for _, m in ipairs(ns.OverviewMilestones(rec, 200)) do out[#out + 1] = m end + table.sort(out, function(a, b) return a.at > b.at end) + while #out > (n or 60) do table.remove(out) end + return out +end + +-- ------------------------------------------------------------ highlights: your best moments +local function RecordDate(rec, key) + local best + for _, e in ipairs((rec and rec.rh) or {}) do + if type(e) == "table" and e.k == key and type(e.at) == "number" then best = e end + end + return best and best.at +end +local function BestDay(rec, key) + local best + for d, day in pairs((rec and rec.days) or {}) do + local v = N(day[key]) + if v > 0 and (not best or v > best.v) then best = { v = v, d = d } end + end + return best +end +local function DayTime(d) + if type(d) ~= "string" or #d ~= 8 then return nil end + return time({ year = tonumber(d:sub(1, 4)), month = tonumber(d:sub(5, 6)), day = tonumber(d:sub(7, 8)), hour = 12 }) +end + +-- Up to n of: biggest hit, best boss DPS, most gold in a day, most kills in a fight, most +-- quests in a day, longest kill streak, longest life. Only ones you have. +function ns.OverviewHighlights(rec, n) + rec = rec or ns.char + local Int, Money, Time = ns.FormatInt, ns.FormatMoney, ns.FormatTime + local out = {} + local function Add(label, value, text, source, at, icon) + if N(value) > 0 then out[#out + 1] = { label = label, value = text, source = source or "", at = at, icon = ICON .. icon } end + end + Add("Biggest hit", r(rec, "max_hit"), Int(r(rec, "max_hit")), rec.r and rec.r.max_hit_what, RecordDate(rec, "max_hit"), "INV_Sword_04") + Add("Best DPS on a boss", r(rec, "best_boss_dps"), Int(r(rec, "best_boss_dps")), rec.r and rec.r.best_boss_dps_what, RecordDate(rec, "best_boss_dps"), "Spell_Fire_FlameBolt") + local gold = BestDay(rec, "money_in") + if gold then Add("Most gold in a day", gold.v, Money(gold.v), "Gold earned", DayTime(gold.d), "INV_Misc_Coin_02") end + Add("Most kills in one fight", r(rec, "max_fight_kills"), Int(r(rec, "max_fight_kills")), rec.r and rec.r.max_fight_kills_what, RecordDate(rec, "max_fight_kills"), "Ability_Warrior_Cleave") + local quests = BestDay(rec, "quests_done") + if quests then Add("Most quests in a day", quests.v, Int(quests.v), "Quests turned in", DayTime(quests.d), "INV_Misc_Note_01") end + Add("Longest kill streak", r(rec, "max_streak"), Int(r(rec, "max_streak")), "kills without dying", RecordDate(rec, "max_streak"), "Ability_Warrior_Charge") + Add("Longest life", r(rec, "max_alive"), Time(r(rec, "max_alive")), "online between deaths", RecordDate(rec, "max_alive"), "Spell_Holy_Renew") + while #out > (n or 5) do table.remove(out) end + return out +end + +-- ------------------------------------------------------------ the lifetime line +-- A running total over the last n days that ends at today's lifetime value. +function ns.CumulativeSeries(rec, valueFn, total, n) + local days = ns.DaySeries(rec, function(d) return valueFn(d) end, n or 30) + local after = 0 + for i = #days, 1, -1 do + days[i].total = N(total) - after + after = after + N(days[i].v) + end + return days +end + +-- ------------------------------------------------------------ Stats Explorer: the score's motto +local MOTTOS = { + { 0, "Every road starts with a single step." }, + { 500, "The road calls, and you answer." }, + { 2000, "A long road, well traveled." }, + { 6000, "Tales of you are told in the taverns." }, + { 15000, "A legend, written one step at a time." }, +} +function ns.ScoreMotto(score) + local m = MOTTOS[1][2] + for _, e in ipairs(MOTTOS) do if N(score) >= e[1] then m = e[2] end end + return m +end + +-- The four cards of Stats Explorer: { id, title, page, icon, color, stats = { { value, label } x3 } } +function ns.ExplorerCards(view) + local Int = ns.FormatInt + local profs = 0 + local st = ns.FindStat and ns.FindStat("Professions learned") + if st then profs = N((ns.StatValue(st, view))) end + local level = UnitLevel and UnitLevel("player") or 0 + return { + { id = "combat", title = "Combat", page = "combat", icon = "combat", color = { 0.55, 0.18, 0.12 }, + stats = { { Int(c(view, "dmg_done")), "Total damage" }, { Int(ns.Kills and ns.Kills(view) or 0), "Enemies slain" }, { Int(r(view, "max_hit")), "Highest hit" } } }, + { id = "exploration", title = "Exploration", page = "travel", icon = "travel", color = { 0.17, 0.38, 0.32 }, + stats = { { Int(c(view, "zones_discovered")), "Zones discovered" }, { Int(c(view, "quests_done")), "Quests completed" }, { Int(r(view, "flightpaths_known")), "Flight paths" } } }, + { id = "progression", title = "Progression", page = "adventure", icon = "crown", color = { 0.55, 0.42, 0.14 }, + stats = { { "Level " .. Int(math.max(N(level), r(view, "max_level"))), "Level" }, { Int(r(view, "max_exalted")), "Factions exalted" }, { Int(profs), "Professions" } } }, + { id = "collections", title = "Collections", page = "life", icon = "chest", color = { 0.36, 0.22, 0.48 }, + stats = { { Int(r(view, "mounts_owned")), "Mounts" }, { Int(r(view, "pets_owned")), "Pets" }, { Int(N(view.un and view.un.itemsheld)), "Items carried" } } }, + } +end + +-- ============================================================ widgets +local function Ink(fs) return fs end + +-- A list of rows: icon, title, sub line and a right-hand note (e.g. "3 days ago"). +local function RowList(body, bw, bh, n, timeline) + local W, T = ns.W, ns.THEME + local o = { rows = {} } + local rh = math.floor(bh / n) + local left = timeline and 22 or 0 + if timeline then + local spine = W.Fill(body, T.edge, "BORDER"); spine:SetPoint("TOPLEFT", 6, -rh / 2); spine:SetSize(1, math.max(1, bh - rh)); spine:SetAlpha(0.5) + end + for i = 1, n do + local row = CreateFrame("Frame", nil, body) + row:SetPoint("TOPLEFT", 0, -(i - 1) * rh); row:SetSize(bw, rh) + if timeline then + row.dot = row:CreateTexture(nil, "ARTWORK"); row.dot:SetSize(9, 9); row.dot:SetPoint("LEFT", 2, 0) + row.dot:SetTexture(W.MEDIA .. "dot"); row.dot:SetVertexColor(T.amber[1], T.amber[2], T.amber[3]) + end + local isz = math.min(34, rh - 8) + row.icon = row:CreateTexture(nil, "ARTWORK"); row.icon:SetSize(isz, isz); row.icon:SetPoint("LEFT", left, 0) + row.icon:SetTexCoord(0.08, 0.92, 0.08, 0.92) + row.frame = W.Panel(row, { 0, 0, 0, 0 }, T.edge); row.frame:SetPoint("TOPLEFT", row.icon, -1, 1); row.frame:SetPoint("BOTTOMRIGHT", row.icon, 1, -1) + row.title = W.Text(row, 12, T.text); row.title:SetPoint("TOPLEFT", row.icon, "TOPRIGHT", 10, -1); row.title:SetPoint("RIGHT", -84, 0); row.title:SetJustifyH("LEFT") + if ns.Paper() then ns.W.Bold(row.title) end + row.sub = W.Text(row, 10, T.dim); row.sub:SetPoint("BOTTOMLEFT", row.icon, "BOTTOMRIGHT", 10, 1); row.sub:SetPoint("RIGHT", -84, 0); row.sub:SetJustifyH("LEFT") + row.note = W.Text(row, 10, T.dim, nil, "RIGHT"); row.note:SetPoint("RIGHT", -4, 0); row.note:SetWidth(80) + if i < n then local l = W.Line(row); l:SetPoint("BOTTOMLEFT", left, 0); l:SetPoint("BOTTOMRIGHT"); l:SetHeight(1); l:SetAlpha(0.35) end + o.rows[i] = row + end + o.empty = W.Text(body, 11, T.dim); o.empty:SetPoint("TOP", 0, -12) + function o:Set(list, emptyText) + for i, row in ipairs(self.rows) do + local e = list[i] + row:SetShown(e ~= nil) + if e then + row.icon:SetTexture(e.icon) + row.title:SetText(e.title) + row.sub:SetText(e.sub or "") + row.note:SetText(e.note or ns.Ago(e.at)) + end + end + self.empty:SetText(emptyText or "Nothing yet") + self.empty:SetShown(#list == 0) + end + return o +end + +-- A line chart with a soft fill under it, for the running total. +local function LineChart(body, bw, bh, n) + local W, T = ns.W, ns.THEME + local o = { n = n, lines = {}, fills = {}, dots = {} } + local axisW, axisH = 46, 16 + local plot = CreateFrame("Frame", nil, body) + plot:SetPoint("TOPLEFT", axisW, -4); plot:SetSize(bw - axisW - 6, bh - axisH - 8) + o.plot = plot + local pw, ph = bw - axisW - 6, bh - axisH - 8 + o.pw, o.ph = pw, ph + for i = 0, 2 do + local g = W.Line(plot); g:SetPoint("BOTTOMLEFT", 0, ph * i / 2); g:SetSize(pw, 1); g:SetAlpha(0.25) + end + o.ylab = {} + for i = 0, 2 do + local t = W.Text(body, 10, T.dim, W.NUM, "RIGHT"); t:SetPoint("RIGHT", plot, "BOTTOMLEFT", -6, ph * i / 2); t:SetWidth(axisW - 6) + o.ylab[i] = t + end + o.xlab = {} + for i, a in ipairs({ { "BOTTOMLEFT", "LEFT" }, { "BOTTOM", "CENTER" }, { "BOTTOMRIGHT", "RIGHT" } }) do + local t = W.Text(body, 10, T.dim, nil, a[2]); t:SetPoint("TOP", plot, a[1], 0, -3) + o.xlab[i] = t + end + local col = T.teal or T.amber + local step = pw / math.max(1, n - 1) + for i = 1, n do + local f = plot:CreateTexture(nil, "BACKGROUND") + f:SetColorTexture(col[1], col[2], col[3], 0.18) + f:SetWidth(math.max(1, step)); f:SetPoint("BOTTOM", plot, "BOTTOMLEFT", (i - 1) * step, 0) + o.fills[i] = f + local d = plot:CreateTexture(nil, "OVERLAY"); d:SetSize(6, 6); d:SetTexture(W.MEDIA .. "dot"); d:SetVertexColor(col[1], col[2], col[3]) + o.dots[i] = d + if i < n and plot.CreateLine then + local ln = plot:CreateLine(nil, "ARTWORK") + if ln.SetThickness then ln:SetThickness(2) end + ln:SetColorTexture(col[1], col[2], col[3], 1) + o.lines[i] = ln + end + end + function o:Set(values, labels, fmt) + fmt = fmt or ns.FormatInt + local lo, hi + for _, v in ipairs(values) do lo = lo and math.min(lo, v) or v; hi = hi and math.max(hi, v) or v end + lo, hi = lo or 0, hi or 1 + if hi <= lo then hi = lo + 1 end + local function Y(v) return (v - lo) / (hi - lo) * (self.ph - 4) + 2 end + for i = 1, self.n do + local v = values[i] or lo + local x, y = (i - 1) * step, Y(v) + self.fills[i]:SetHeight(math.max(1, y)) + self.dots[i]:ClearAllPoints(); self.dots[i]:SetPoint("CENTER", self.plot, "BOTTOMLEFT", x, y) + local ln = self.lines[i] + if ln and values[i + 1] then + ln:SetStartPoint("BOTTOMLEFT", self.plot, x, y) + ln:SetEndPoint("BOTTOMLEFT", self.plot, x + step, Y(values[i + 1])) + end + end + self.ylab[0]:SetText(fmt(lo)); self.ylab[1]:SetText(fmt((lo + hi) / 2)); self.ylab[2]:SetText(fmt(hi)) + self.xlab[1]:SetText(labels[1] or ""); self.xlab[2]:SetText(labels[math.floor(#labels / 2) + 1] or ""); self.xlab[3]:SetText("Today") + end + return o +end + +-- A small "View all ->" link in a card's title bar. +local function Link(card, text, onClick) + local W, T = ns.W, ns.THEME + local b = CreateFrame("Button", nil, card) + b:SetSize(120, 20); b:SetPoint("TOPRIGHT", -10, -6) + b.text = W.Text(b, 11, T.amber, nil, "RIGHT"); b.text:SetPoint("RIGHT"); b.text:SetText(text .. " >") + b:SetScript("OnClick", onClick) + b:SetScript("OnEnter", function() b.text:SetTextColor(T.text[1], T.text[2], T.text[3]) end) + b:SetScript("OnLeave", function() b.text:SetTextColor(T.amber[1], T.amber[2], T.amber[3]) end) + return b +end + +-- ============================================================ Lifetime Stats overview +local function BuildLedger(ctx) + local W, T = ns.W, ns.THEME + local Int, Money = ns.FormatInt, ns.FormatMoney + local CW, CH, GAP = ctx.CW, ctx.CH, ctx.GAP + local p = ctx.NewPage("dashboard") + local lw = math.floor((CW - GAP) * 0.63) + local rw = CW - lw - GAP + local rx = lw + GAP + + -- the hero + local hero = W.Panel(p, T.tile, T.edge) + hero:SetPoint("TOPLEFT", 0, 0); hero:SetSize(lw, 84) + p.portrait = hero:CreateTexture(nil, "ARTWORK"); p.portrait:SetSize(64, 64); p.portrait:SetPoint("LEFT", 10, 0) + local pf = W.Panel(hero, { 0, 0, 0, 0 }, T.edge); pf:SetPoint("TOPLEFT", p.portrait, -2, 2); pf:SetPoint("BOTTOMRIGHT", p.portrait, 2, -2) + p.heroName = W.Text(hero, 22, T.text); p.heroName:SetPoint("TOPLEFT", p.portrait, "TOPRIGHT", 14, -6) + if ns.Paper() then W.Bold(p.heroName) end + p.heroLine = W.Text(hero, 12, T.dim); p.heroLine:SetPoint("TOPLEFT", p.heroName, "BOTTOMLEFT", 0, -6) + p.heroScore = W.Text(hero, 12, T.amber, nil, "RIGHT"); p.heroScore:SetPoint("RIGHT", -14, 0) + + -- four headline counters + local tiles = { + { label = "Total kills", icon = "sword", stat = "computed:kills", value = function(v) return Int(ns.Kills(v)) end }, + { label = "Quests completed", icon = "scroll", stat = "counter:quests_done", value = function(v) return Int(c(v, "quests_done")) end }, + { label = "Achievement points", icon = "trophy", value = function(v) local _, _, pts = ns.AchTotals(v) return Int(pts) end, page = "achievements" }, + { label = "Gold earned", icon = "coin", stat = "counter:money_in", value = function(v) return Money(c(v, "money_in")) end }, + } + local tw = (lw - GAP * 3) / 4 + p.tiles = {} + for i, d in ipairs(tiles) do + local t = CreateFrame("Button", nil, p) + t:SetPoint("TOPLEFT", (i - 1) * (tw + GAP), -(84 + GAP)); t:SetSize(tw, 92) + local card = W.Panel(t, T.tile, T.edge); card:SetAllPoints() + t.icon = W.Icon(t, d.icon, 26, T.amber); t.icon:SetPoint("TOP", 0, -8) + t.label = W.Text(t, 11, T.text, nil, "CENTER"); t.label:SetPoint("TOP", t.icon, "BOTTOM", 0, -4); t.label:SetWidth(tw - 10); t.label:SetText(d.label) + t.value = W.Text(t, 20, T.text, W.NUM, "CENTER"); t.value:SetPoint("TOP", t.label, "BOTTOM", 0, -3); t.value:SetWidth(tw - 10) + if ns.Paper() then W.Bold(t.value) end + t.sub = W.Text(t, 10, T.dim, nil, "CENTER"); t.sub:SetPoint("BOTTOM", 0, 6) + t.def = d + t.stat = d.stat and ns.FindStat(d.stat == "computed:kills" and "Enemies killed" or d.stat) + t:SetScript("OnClick", function(self) + if self.stat then ns.ShowStatDetail(self.stat) elseif d.page then ns.ShowPage(d.page) end + end) + W.Tip(t, d.label, d.page and "Click to open the Achievements page." or "Click for its last 30 days, best day and every character.") + p.tiles[i] = t + end + + -- the lifetime line + local y = 84 + GAP + 92 + GAP + local chartH = math.floor((CH - y - GAP) * 0.52) + local act = ctx.Panel(p, "Lifetime activity", "timeline", 0, y, lw, chartH, "Your total kills over the last 30 days, ending at today's lifetime total.") + p.line = LineChart(act.body, act.bw, act.bh, 30) + p.killStat = ns.FindStat("Enemies killed") + Link(act, "View details", function() if p.killStat then ns.ShowStatDetail(p.killStat) end end) + + -- recent milestones + local my = y + chartH + GAP + local ms = ctx.Panel(p, "Recent milestones", "trophy", 0, my, lw, CH - my, "Your latest Journal moments: first kills, bosses, levels and personal bests.") + p.milestones = RowList(ms.body, ms.bw, ms.bh, math.max(3, math.floor(ms.bh / 42))) + Link(ms, "View all", function() ns.ShowPage("journal") end) + + -- highlights and recent activity + local hh = math.floor((CH - GAP) * 0.56) + local hl = ctx.Panel(p, "Highlights", "star", rx, 0, rw, hh, "Your best moments: records and best days.") + p.highlights = RowList(hl.body, hl.bw, hl.bh, math.max(3, math.min(6, math.floor(hl.bh / 54)))) + Link(hl, "Records", function() ns.ShowPage("records") end) + local ra = ctx.Panel(p, "Recent activity", "clock", rx, hh + GAP, rw, CH - hh - GAP, "Quests, items, levels and Journal moments, newest first.") + local per = math.max(3, math.floor((ra.bh - 30) / 44)) + p.activity = RowList(ra.body, ra.bw, ra.bh - 30, per) + p.page, p.per = 1, per + local prev = W.FlatButton(ra.body, "<", 28, 22, "Newer", "Newer entries.") + prev:SetPoint("BOTTOMLEFT", 4, 2) + local nextB = W.FlatButton(ra.body, ">", 28, 22, "Older", "Older entries.") + nextB:SetPoint("BOTTOMRIGHT", -4, 2) + p.pageText = W.Text(ra.body, 11, T.text, nil, "CENTER"); p.pageText:SetPoint("BOTTOM", 0, 6) + prev:SetScript("OnClick", function() p.page = math.max(1, p.page - 1); ns.RefreshWindow() end) + nextB:SetScript("OnClick", function() p.page = p.page + 1; ns.RefreshWindow() end) + + function p:Update(view, base, sess) + local ch = ns.char + if SetPortraitTexture then pcall(SetPortraitTexture, self.portrait, "player") end + self.heroName:SetText(UnitName("player") or "") + local className = UnitClass and select(1, UnitClass("player")) or "" + local faction = UnitFactionGroup and select(1, UnitFactionGroup("player")) or "" + self.heroLine:SetText(string.format("Level %d · %s · %s", N(UnitLevel("player")), tostring(className or ""), tostring(faction or ""))) + self.heroScore:SetText("Adventurer score " .. Int((ns.Score(ch)))) + for _, t in ipairs(self.tiles) do + t.value:SetText(t.def.value(view)) + t.sub:SetText(ctx.RangeName()) + end + local series = ns.CumulativeSeries(ch, function(d) return N(d.kills_npc) + N(d.kills_pvp) end, ns.Kills(ch), 30) + local vals, labels = {}, {} + for i, e in ipairs(series) do vals[i] = e.total; labels[i] = ctx.DayLabel(e.d) end + self.line:Set(vals, labels, Int) + self.milestones:Set(ns.OverviewMilestones(ch, #self.milestones.rows), "Your Journal fills in as you play.") + local hl = {} + for _, h in ipairs(ns.OverviewHighlights(ch, #self.highlights.rows)) do + hl[#hl + 1] = { icon = h.icon, title = h.label .. ": " .. h.value, sub = h.source, at = h.at, note = h.at and date("%b %d, %Y", h.at) or "" } + end + self.highlights:Set(hl, "Records appear here as you set them.") + local all = ns.OverviewActivity(ch, 200) + local pages = math.max(1, math.ceil(#all / self.per)) + self.page = math.min(self.page, pages) + local slice = {} + for i = (self.page - 1) * self.per + 1, math.min(#all, self.page * self.per) do slice[#slice + 1] = all[i] end + self.activity:Set(slice, "Quests, items and levels appear here as you play.") + self.pageText:SetText(self.page .. " / " .. pages) + end + return p +end + +-- ============================================================ Stats Explorer overview +local function BuildExplorer(ctx) + local W, T = ns.W, ns.THEME + local Int = ns.FormatInt + local M = W.MEDIA .. "framed\\" + local CW, CH, GAP = ctx.CW, ctx.CH, ctx.GAP + local p = ctx.NewPage("dashboard") + local pinH = 56 + local bodyH = CH - pinH - GAP + local lw = math.floor((CW - GAP) * 0.5) + local rw = CW - lw - GAP + local rx = lw + GAP + + -- the lifetime score + local sh = math.min(210, math.floor(bodyH * 0.42)) + local sc = ctx.Panel(p, "Total lifetime score", "star", 0, 0, lw, sh, "Your Adventurer score: levels, kills, quests, bosses, exploration and more. /lts score shows how it is made.") + p.emblem = sc.body:CreateTexture(nil, "ARTWORK"); p.emblem:SetSize(96, 96); p.emblem:SetPoint("LEFT", 10, 12); p.emblem:SetTexture(M .. "emblem") + p.score = W.Text(sc.body, 40, T.text, W.NUM); p.score:SetPoint("LEFT", p.emblem, "RIGHT", 18, 10) + if ns.Paper() then W.Bold(p.score) end + p.scoreSub = W.Text(sc.body, 15, T.dim); p.scoreSub:SetPoint("TOPLEFT", p.score, "BOTTOMLEFT", 2, -4) + p.motto = W.Text(sc.body, 13, T.text, nil, "CENTER"); p.motto:SetPoint("BOTTOM", 0, 10); p.motto:SetWidth(sc.bw - 40) + local dv = sc.body:CreateTexture(nil, "ARTWORK"); dv:SetSize(sc.bw - 60, 9); dv:SetPoint("BOTTOM", 0, 2); dv:SetTexture(M .. "divider") + dv:SetVertexColor(T.edge[1], T.edge[2], T.edge[3], 0.7) + sc.body:EnableMouse(true) + sc.body:SetScript("OnMouseUp", function() local st = ns.FindStat("Adventurer score") if st then ns.ShowStatDetail(st) end end) + + -- recent activity, as a timeline + local ra = ctx.Panel(p, "Recent activity", "clock", 0, sh + GAP, lw, bodyH - sh - GAP, "Quests, items, levels and Journal moments, newest first.") + p.activity = RowList(ra.body, ra.bw, ra.bh, math.max(3, math.floor(ra.bh / 48)), true) + Link(ra, "View all", function() ns.ShowPage("journal") end) + + -- a card for each part of the adventure + local ch4 = math.floor((bodyH - GAP * 3) / 4) + p.cards = {} + for i = 1, 4 do + local cy = (i - 1) * (ch4 + GAP) + local b = CreateFrame("Button", nil, p) + b:SetPoint("TOPLEFT", rx, -cy); b:SetSize(rw, ch4) + local bg = W.Panel(b, T.tile, T.edge); bg:SetAllPoints() + b.crest = b:CreateTexture(nil, "ARTWORK"); b.crest:SetSize(46, 46); b.crest:SetPoint("TOPLEFT", 12, -8); b.crest:SetTexture(M .. "crest") + b.rim = b:CreateTexture(nil, "OVERLAY"); b.rim:SetAllPoints(b.crest); b.rim:SetTexture(M .. "crest_rim") + b.glyph = b:CreateTexture(nil, "OVERLAY", nil, 2); b.glyph:SetSize(22, 22); b.glyph:SetPoint("CENTER", b.crest, "CENTER", 0, 3) + b.title = W.Text(b, 16, T.text); b.title:SetPoint("LEFT", b.crest, "RIGHT", 12, 4) + if ns.Paper() then W.Bold(b.title) end + b.chev = W.Text(b, 18, T.dim, nil, "RIGHT"); b.chev:SetPoint("TOPRIGHT", -14, -18); b.chev:SetText(">") + b.stats = {} + local sw = (rw - 24) / 3 + for k = 1, 3 do + local v = W.Text(b, 16, T.text, W.NUM); v:SetPoint("BOTTOMLEFT", 12 + (k - 1) * sw, 24); v:SetWidth(sw - 8); v:SetJustifyH("LEFT") + if ns.Paper() then W.Bold(v) end + local l = W.Text(b, 10, T.dim); l:SetPoint("TOPLEFT", v, "BOTTOMLEFT", 0, -2); l:SetWidth(sw - 8); l:SetJustifyH("LEFT") + if k > 1 then local sep = W.Line(b); sep:SetPoint("BOTTOMLEFT", 12 + (k - 1) * sw - 6, 10); sep:SetSize(1, 34); sep:SetAlpha(0.4) end + b.stats[k] = { v = v, l = l } + end + b:SetScript("OnClick", function(self) if self.page then ns.ShowPage(self.page) end end) + W.Tip(b, function() return b.title:GetText() or "" end, "Click to open the page.") + p.cards[i] = b + end + + -- pinned statistics along the bottom + local strip = W.Panel(p, T.tile, T.edge) + strip:SetPoint("TOPLEFT", 0, -(bodyH + GAP)); strip:SetSize(CW, pinH) + local pl = W.Text(strip, 14, T.text); pl:SetPoint("LEFT", 16, 0); pl:SetText("Pinned stats") + if ns.Paper() then W.Bold(pl) end + local gear = W.FlatButton(strip, "Pins", 54, 26, "Manage pins", "Choose which statistics are pinned here.") + gear:SetPoint("RIGHT", -10, 0); gear:SetScript("OnClick", function() if ctx.OpenPins then ctx.OpenPins() end end) + p.pins = {} + local px0, pw = 150, (CW - 150 - 80) / 4 + for i = 1, 4 do + local b = CreateFrame("Button", nil, strip) + b:SetPoint("LEFT", px0 + (i - 1) * pw, 0); b:SetSize(pw - 10, pinH - 8) + b.icon = W.Icon(b, "star", 24, T.amber); b.icon:SetPoint("LEFT", 6, 0) + b.value = W.Text(b, 15, T.text, W.NUM); b.value:SetPoint("TOPLEFT", b.icon, "TOPRIGHT", 10, 4); b.value:SetWidth(pw - 60); b.value:SetJustifyH("LEFT") + if ns.Paper() then W.Bold(b.value) end + b.label = W.Text(b, 10, T.dim); b.label:SetPoint("TOPLEFT", b.value, "BOTTOMLEFT", 0, -2); b.label:SetWidth(pw - 60); b.label:SetJustifyH("LEFT") + if i > 1 then local sep = W.Line(strip); sep:SetPoint("LEFT", px0 + (i - 1) * pw - 8, 0); sep:SetSize(1, pinH - 18); sep:SetAlpha(0.4) end + b:SetScript("OnClick", function(self) if self.stat then ns.ShowStatDetail(self.stat) end end) + p.pins[i] = b + end + + function p:Update(view, base, sess) + local ch = ns.char + local score = ns.Score(ch) + self.score:SetText(Int(score)) + self.scoreSub:SetText("Lifetime") + self.motto:SetText('"' .. ns.ScoreMotto(score) .. '"') + local list = ns.OverviewActivity(ch, #self.activity.rows) + self.activity:Set(list, "Quests, items and levels appear here as you play.") + for i, card in ipairs(ns.ExplorerCards(view)) do + local b = self.cards[i] + b.page = card.page + b.title:SetText(card.title) + b.crest:SetVertexColor(card.color[1], card.color[2], card.color[3], 1) + b.glyph:SetTexture(W.MEDIA .. "icons\\" .. card.icon) + b.glyph:SetVertexColor(1, 0.92, 0.7) + for k, s in ipairs(card.stats) do b.stats[k].v:SetText(s[1]); b.stats[k].l:SetText(s[2]) end + end + -- your Dashboard pins; until you pin some, four headline statistics + local _, byID = ns.DashboardPinCatalog() + local list = {} + for _, id in ipairs(ns.DashboardPins()) do + local pin = byID[id] + if pin and pin.stat then list[#list + 1] = { stat = pin.stat, icon = pin.icon } end + end + if #list == 0 then + for _, d in ipairs({ { "Damage done", "sword" }, { "Enemies killed", "skull" }, { "Quests completed", "scroll" }, { "Gold earned", "coin" } }) do + local st = ns.FindStat(d[1]) + if st then list[#list + 1] = { stat = st, icon = d[2] } end + end + end + for i, b in ipairs(self.pins) do + local pin = list[i] + b:SetShown(pin ~= nil) + if pin then + local st = pin.stat + b.stat = st + local v = ns.StatValue(st, view) + b.value:SetText(ns.FormatStat(st, v)) + b.label:SetText(st.label) + if pin.icon then b.icon:SetTexture(W.MEDIA .. "icons\\" .. pin.icon) end + end + end + end + return p +end + +function ns.BuildFramedOverview(ctx) + if ns.Explorer() then return BuildExplorer(ctx) end + return BuildLedger(ctx) +end diff --git a/README.md b/README.md index 5e9a194..c892dd9 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,18 @@ Get the 1.24.0 prerelease archive, `LifeTimeStats-1.24.0-forever.zip`, from the ## The window -**Adventurer's Notebook** (default from 1.21) turns the window into an adventurer's tome: a single hand-made sheet of aged parchment with torn edges and an inked frame. Six chapter tabs run down the side: **Hero** (Overview, Characters, Compare), **Deeds** (Travels, Battles, Deaths, Purse & Pack, Company), **Quests** (Adventures, Dungeon Tome, Life on the Road), **Legends** (Records, Feats & Firsts, Honours, Rolls of Note), **Chronicle** (Journal, Days) and **Lore** (How it works). The margin of each page lists that chapter's pages as tags, with Today below them. Each tab reopens the page you last read in it. Values are inked in your class colour. Every page has its own ink sketch in the margin (a compass on the Overview, a skull for Deaths, a backpack for Purse & Pack, crossed swords for Battles, and more). Earned achievements are stamped with a wax seal showing their tier, and a pinned Dashboard statistic is sealed once its goal is reached. The other skins (Forever Journal, Odometer, Blizzard, ElvUI, Tukui, EllesmereUI) are still in Settings; changing skin needs a /reload. +**Lifetime Stats** (the default from 1.25) frames the window as a tome: +- **The frame:** a dark wooden frame with gold corners and a title plaque around clean parchment. +- **Navigation:** a menu of pages down the left, a search box, and dropdowns for the character (this one or all of them) and the time range. +- **The overview:** your character, four headline counters (kills, quests, achievement points, gold), a lifetime activity line, recent milestones from your Journal, highlights (your biggest hit, best boss DPS, best gold and quest days, longest kill streak) and recent activity, a page at a time. + +**Stats Explorer** is the same frame with a dark wooden menu and a Session / Daily / Weekly / Monthly / Lifetime bar. Its overview shows: +- your lifetime score with its motto; +- recent activity as a timeline; +- a card each for Combat, Exploration, Progression and Collections, which open their pages; +- your pinned statistics along the bottom. + +**Adventurer's Notebook** (the default from 1.21 to 1.24) turns the window into an adventurer's tome: a single hand-made sheet of aged parchment with torn edges and an inked frame. Six chapter tabs run down the side: **Hero** (Overview, Characters, Compare), **Deeds** (Travels, Battles, Deaths, Purse & Pack, Company), **Quests** (Adventures, Dungeon Tome, Life on the Road), **Legends** (Records, Feats & Firsts, Honours, Rolls of Note), **Chronicle** (Journal, Days) and **Lore** (How it works). The margin of each page lists that chapter's pages as tags, with Today below them. Each tab reopens the page you last read in it. Values are inked in your class colour. Every page has its own ink sketch in the margin (a compass on the Overview, a skull for Deaths, a backpack for Purse & Pack, crossed swords for Battles, and more). Earned achievements are stamped with a wax seal showing their tier, and a pinned Dashboard statistic is sealed once its goal is reached. The other skins (Stats Explorer, Adventurer's Notebook, Forever Journal, Odometer, Blizzard, ElvUI, Tukui, EllesmereUI) are in Settings; changing skin needs a /reload. A Warcraft-style adventurer's journal (`/lts`) with gold trim, warm page panels, chapter accents and ledger counters. The accent colour can follow your **class colour**. diff --git a/Stats.lua b/Stats.lua index a0b2a5b..2281fc8 100644 --- a/Stats.lua +++ b/Stats.lua @@ -29,7 +29,7 @@ end ns.FormatTime = Time -- Coin letter colours: the game's gold/silver/copper, inked darker on the notebook's paper. -local function Paper() return ns.Notebook and ns.Notebook() end +local function Paper() return ns.Paper and ns.Paper() end local function MG() return Paper() and "|cff7a5c00" or "|cffffd100" end local function MS() return Paper() and "|cff55555f" or "|cffc7c7cf" end local function MC() return Paper() and "|cff8a4416" or "|cffeda55f" end diff --git a/Themes.lua b/Themes.lua index a3953a5..1da8d25 100644 --- a/Themes.lua +++ b/Themes.lua @@ -13,6 +13,16 @@ local ARIALN, FRIZ = "Fonts\\ARIALN.TTF", "Fonts\\FRIZQT__.TTF" -- Each theme: palette, fonts and a short description for the settings button. ns.THEMES = { + { id = "ledger", name = "Lifetime Stats", desc = "A framed tome: dark wood and gold around clean parchment, a menu of pages down the left, highlights and recent activity on the overview.", + bg = hex("dccbaa"), tile = hex("eadcbd", 0.55), tileHi = hex("d2bf98"), edge = hex("6b5233", 0.75), + text = hex("24190f"), dim = hex("4c3c29"), amber = hex("2c5a48"), + cream2 = hex("7a6a4c"), rust = hex("9c3a24"), teal = hex("3d7563"), font = FRIZ, num = FRIZ, + journal = { gold = hex("33281c"), trim = hex("6b5233"), top = hex("e8dab9"), base = hex("dccbaa"), tab = hex("cdb88f"), page = hex("e4d5b3") } }, + { id = "explorer", name = "Stats Explorer", desc = "The framed tome with a dark wooden menu, a lifetime score with its motto, a card for each part of your adventure and your pinned statistics along the bottom.", + bg = hex("dccbaa"), tile = hex("eadcbd", 0.55), tileHi = hex("d2bf98"), edge = hex("6b5233", 0.75), + text = hex("24190f"), dim = hex("4c3c29"), amber = hex("2c5a48"), + cream2 = hex("7a6a4c"), rust = hex("9c3a24"), teal = hex("3d7563"), font = FRIZ, num = FRIZ, + journal = { gold = hex("33281c"), trim = hex("6b5233"), top = hex("e8dab9"), base = hex("dccbaa"), tab = hex("cdb88f"), page = hex("e4d5b3") } }, { id = "notebook", name = "Adventurer's Notebook", desc = "An adventurer's notebook: parchment pages, ink, a spiral binding and tabs down the side. Made for roleplayers and RPG fans.", bg = hex("d6c095"), tile = hex("e2cfa3", 0.30), tileHi = hex("cdb487"), edge = hex("33281c", 0.85), text = hex("1f150c"), dim = hex("3e3020"), amber = hex("6e2610"), @@ -59,7 +69,7 @@ function ns.DetectUI() if Loaded("EllesmereUI") or type(_G.EllesmereUI) == "table" and _G.EllesmereUI.ELLESMERE_GREEN then return "ellesmere" end if Loaded("ElvUI") then return "elvui" end if Loaded("Tukui") then return "tukui" end - return "notebook" + return "ledger" end -- Live colours / font from the UI addon itself, if loaded. Every read is guarded. @@ -161,12 +171,18 @@ function ns.ThemeName(id) if id == "auto" then return "Auto (" .. (ns.THEME_BY_ID[ns.DetectUI()] or {}).name .. ")" end return (ns.THEME_BY_ID[id] or ns.THEME_BY_ID.notebook).name end -ns.THEME_ORDER = { "auto", "notebook", "forever", "odometer", "blizzard", "elvui", "tukui", "ellesmere" } +ns.THEME_ORDER = { "auto", "ledger", "explorer", "notebook", "forever", "odometer", "blizzard", "elvui", "tukui", "ellesmere" } -- Skins drawn as a journal (mixed-case titles, inked numbers, banner shading): Forever Journal -- and the Adventurer's Notebook. ns.Notebook() is the notebook alone (its own window frame). -function ns.JournalSkin() return ns.themeId == "forever" or ns.themeId == "notebook" end +function ns.JournalSkin() return ns.themeId == "forever" or ns.Paper() end function ns.Notebook() return ns.themeId == "notebook" end +-- The two framed tomes (Lifetime Stats and Stats Explorer) share a window frame. +function ns.Framed() return ns.themeId == "ledger" or ns.themeId == "explorer" end +function ns.Ledger() return ns.themeId == "ledger" end +function ns.Explorer() return ns.themeId == "explorer" end +-- Parchment skins: dark ink on paper, so text sizes, ink and tooltips follow the paper rules. +function ns.Paper() return ns.themeId == "notebook" or ns.themeId == "ledger" or ns.themeId == "explorer" end -- EllesmereUI skinning API: register once; the getters feed the EllesmereUI theme. if type(_G.EllesmereUI) == "table" and type(_G.EllesmereUI.RegisterSkin) == "function" then diff --git a/UI.lua b/UI.lua index 2c911e3..9972137 100644 --- a/UI.lua +++ b/UI.lua @@ -38,7 +38,9 @@ function ns.WindowSizeFor(mode, uiW, uiH, scale, book) end local function ComputeLayout() local s = ns.settings and ns.settings.window or {} - local book = ns.Notebook and ns.Notebook() + -- the framed skins put their title on a plaque over the top rail, so the header row sits lower + HEADER_H = (ns.Framed and ns.Framed()) and 62 or 44 + local book = (ns.Notebook and ns.Notebook()) or (ns.Framed and ns.Framed()) WIN_W, WIN_H = ns.WindowSizeFor(s.size, UIParent:GetWidth(), UIParent:GetHeight(), s.scale or 1, book) Derive() end @@ -400,12 +402,12 @@ local function CreateStatDetail() local banner = W.Fill(dlg, T.tile) banner:SetPoint("TOPLEFT", 1, -1); banner:SetPoint("TOPRIGHT", -1, -1); banner:SetHeight(52) if ink then W.Shade(banner, ink.base, ink.top) end - if ns.Notebook() then banner:SetAlpha(0.35) end + if ns.Paper() then banner:SetAlpha(0.35) end local rule = W.Line(dlg, ink and ink.trim or nil) rule:SetPoint("TOPLEFT", 1, -53); rule:SetPoint("TOPRIGHT", -1, -53); rule:SetHeight(1) layer.title = W.Text(dlg, 16, ink and ink.gold or T.amber) layer.title:SetPoint("TOPLEFT", 14, -10); layer.title:SetPoint("RIGHT", -44, 0); layer.title:SetJustifyH("LEFT") - if ns.Notebook() then W.Bold(layer.title, T.amber) end + if ns.Paper() then W.Bold(layer.title, T.amber) end layer.home = W.Text(dlg, 11, T.dim) layer.home:SetPoint("TOPLEFT", 14, -32); layer.home:SetPoint("RIGHT", -44, 0); layer.home:SetJustifyH("LEFT") @@ -432,7 +434,7 @@ local function CreateStatDetail() lab:SetPoint("TOPLEFT", 14 + col * fw, -112 - row * 44); lab:SetWidth(fw - 10); lab:SetJustifyH("LEFT") local val = W.Text(dlg, 15, T.amber, W.NUM) val:SetPoint("TOPLEFT", lab, "BOTTOMLEFT", 0, -3); val:SetWidth(fw - 10); val:SetJustifyH("LEFT"); val:SetWordWrap(false) - if ns.Notebook() then W.Bold(val, T.amber) end + if ns.Paper() then W.Bold(val, T.amber) end layer.facts[i] = { lab = lab, val = val } end @@ -490,13 +492,13 @@ function ns.ShowStatDetail(st) end for i, f in ipairs(L.facts) do local d = facts[i] or { "", "" } - f.lab:SetText(ns.Notebook() and W.SmallCaps(d[1]) or d[1]:upper()) + f.lab:SetText(ns.Paper() and W.SmallCaps(d[1]) or d[1]:upper()) f.val:SetText(d[2]) end -- the 30-day chart (counters only) if h.series then - L.chartTitle:SetText(ns.Notebook() and W.SmallCaps("Last 30 days") or "LAST 30 DAYS") + L.chartTitle:SetText(ns.Paper() and W.SmallCaps("Last 30 days") or "LAST 30 DAYS") local vals, labels = {}, {} for i, e in ipairs(h.series) do vals[i] = { e.v or 0 }; labels[i] = DayLabel(e.d) end L.chart:Set(vals, { C.amber }, labels, { labels[1], labels[15], "Today" }, F, { st.label }, true) @@ -540,6 +542,16 @@ local function OpenDashboardPinPicker() end local function BuildDashboard() + -- the framed skins draw their own overview (Overview.lua) + if ns.Framed() and ns.BuildFramedOverview then + return ns.BuildFramedOverview({ + NewPage = NewPage, Panel = Panel, CW = CW, CH = CH, GAP = GAP, DayLabel = DayLabel, + OpenPins = OpenDashboardPinPicker, + RangeName = function() + return ({ today = "Today", session = "This session", week = "Last 7 days", month = "Last 30 days" })[Settings().range] or "Lifetime" + end, + }) + end local p = NewPage("dashboard") KpiRow(p, { { id = "computed:steps", label = "Steps taken", icon = "steps", value = ns.Steps, tip = "Distance on foot divided by a 0.75 m stride.", @@ -1275,10 +1287,11 @@ local function AchTile(parent, w, h) local ic = lit and T.amber or T.dim self.icon:SetVertexColor(ic[1], ic[2], ic[3], lit and 1 or 0.6) self.name:SetText(def.name .. (lit and (" " .. ns.TIER_NAMES[st.tier]) or "")) - if self.seal then - self.seal.text:SetText(lit and ns.TIER_NAMES[st.tier] or "") - self.seal:SetShown(lit) - self.seal:SetAlpha(done and 1 or 0.8) + local seal = rawget(self, "seal") + if seal then + seal.text:SetText(lit and ns.TIER_NAMES[st.tier] or "") + seal:SetShown(lit) + seal:SetAlpha(done and 1 or 0.8) end local nc = done and T.amber or T.text self.name:SetTextColor(nc[1], nc[2], nc[3]) @@ -2063,6 +2076,7 @@ function ns.ShowPage(id) local col = sel and (ink and ink.gold or T.amber) or T.text b.text:SetTextColor(col[1], col[2], col[3]) b.icon:SetVertexColor(sel and T.amber[1] or T.dim[1], sel and T.amber[2] or T.dim[2], sel and T.amber[3] or T.dim[3]) + if ns.Framed() and ns.StyleFramedNav then ns.StyleFramedNav(b, sel) end end ns.RefreshWindow() end @@ -2116,7 +2130,8 @@ local function BuildSectionBar() local book = ns.Notebook() local bar = CreateFrame("Frame", nil, win) bar:SetSize(SECTION_TAB_W, SECTION_TABS * (SECTION_TAB_H + SECTION_GAP)) - bar:SetPoint("TOPLEFT", win, "TOPRIGHT", book and 34 or 2, -(HEADER_H + PAD)) + local outside = book and 34 or (ns.Framed() and 30 or 2) -- past the parchment or the wooden frame + bar:SetPoint("TOPLEFT", win, "TOPRIGHT", outside, -(HEADER_H + PAD)) bar:SetFrameLevel((win:GetFrameLevel() or 1) + 1) bar.tabs = {} for i = 1, SECTION_TABS do @@ -2150,7 +2165,7 @@ local function BuildSectionBar() end bar.book = book -- keep the tabs on screen when the window is dragged against the right edge - if win.SetClampRectInsets then pcall(win.SetClampRectInsets, win, 0, -((book and 34 or 2) + SECTION_TAB_W), 0, 0) end + if win.SetClampRectInsets then pcall(win.SetClampRectInsets, win, 0, -(outside + SECTION_TAB_W), 0, 0) end bar:Hide() win.sectionBar = bar end @@ -2228,7 +2243,7 @@ local function CreateWindow() end) local hbg = W.Fill(head, T.tile); hbg:SetAllPoints() if ink then W.Shade(hbg, ink.base, ink.top) end - if ns.Notebook() then hbg:SetAlpha(0) end -- the parchment sheet shows through + if ns.Paper() then hbg:SetAlpha(0) end -- the parchment shows through local rule = W.Fill(head, trim, "ARTWORK"); rule:SetPoint("BOTTOMLEFT"); rule:SetPoint("BOTTOMRIGHT"); rule:SetHeight(2) local logo = head:CreateTexture(nil, "ARTWORK"); logo:SetSize(28, 28); logo:SetPoint("LEFT", 10, 0); logo:SetTexture(W.MEDIA .. "icon") local t1 = W.Text(head, 18, ink and ink.gold or T.amber); t1:SetPoint("LEFT", logo, "RIGHT", 8, 0); t1:SetText("LifeTime") @@ -2297,12 +2312,13 @@ local function CreateWindow() { id = "account", label = "Account", tip = "Every character on this account that has logged in with LifeTimeStats. Hover a value to see each character's part." }, }, function(id) Settings().scope = id; ns.InvalidateAccount(); ns.RefreshWindow() end) win.scopeSeg:SetPoint("RIGHT", win.rangeSeg, "LEFT", -8, 0) + win.headParts = { logo = logo, t1 = t1, t2 = t2, rule = rule, sb = sb, close = close, portrait = portrait, ring = ring, gear = gear } -- sidebar --------------------------------------------------------- local side = CreateFrame("Frame", nil, win) side:SetPoint("TOPLEFT", 1, -HEADER_H - 1); side:SetPoint("BOTTOMLEFT", 1, FOOTER_H) side:SetWidth(SIDEBAR_W - 1) - if ink and not ns.Notebook() then + if ink and not ns.Paper() then local spine = W.Fill(side, ink.base); spine:SetAllPoints() W.Shade(spine, ink.base, ink.top) end @@ -2326,6 +2342,7 @@ local function CreateWindow() local kb = W.Panel(b, T.bg) kb:SetSize(16, 16); kb:SetPoint("RIGHT", -10, 0) local kt = W.Text(kb, 9, T.dim); kt:SetPoint("CENTER"); kt:SetText(cat.key) + b.kb = kb b.badgeBg = W.Fill(b, T.amber, "OVERLAY"); b.badgeBg:SetSize(14, 12); b.badgeBg:SetPoint("CENTER", b.icon, "TOPRIGHT", 2, -1); b.badgeBg:Hide() b.badge = W.Text(b, 9, T.bg, W.NUM); b.badge:SetPoint("CENTER", b.badgeBg, "CENTER", 0, 0); b.badge:SetDrawLayer("OVERLAY", 7) b.id = cat.id @@ -2367,6 +2384,7 @@ local function CreateWindow() end if ns.Notebook() and ns.BuildNotebookFrame then ns.BuildNotebookFrame(win, side, { HEADER_H = HEADER_H, FOOTER_H = FOOTER_H, SIDEBAR_W = SIDEBAR_W, PAD = PAD, CW = CW, CH = CH }) end + if ns.Framed() and ns.BuildFramedSkin then ns.BuildFramedSkin(win, side, head, { HEADER_H = HEADER_H, FOOTER_H = FOOTER_H, SIDEBAR_W = SIDEBAR_W, PAD = PAD, CW = CW, CH = CH }) end -- section tabs down the right side --------------------------------- BuildSectionBar() @@ -2382,7 +2400,7 @@ local function CreateWindow() foot:SetPoint("BOTTOMLEFT", 1, 1); foot:SetPoint("BOTTOMRIGHT", -1, 1); foot:SetHeight(FOOTER_H) local fbg = W.Fill(foot, T.tile); fbg:SetAllPoints() if ink then W.Shade(fbg, ink.base, ink.top) end - if ns.Notebook() then fbg:SetAlpha(0) end + if ns.Paper() then fbg:SetAlpha(0) end local ftop = W.Line(foot); ftop:SetPoint("TOPLEFT"); ftop:SetPoint("TOPRIGHT"); ftop:SetHeight(1) win.footer = W.Text(foot, 10, T.dim); win.footer:SetPoint("LEFT", 10, 0) local restore = W.FlatButton(foot, "Restore", 64, 18, nil, "Merge a stats backup or preview a full character restore.") diff --git a/Widgets.lua b/Widgets.lua index bb04077..e305564 100644 --- a/Widgets.lua +++ b/Widgets.lua @@ -67,14 +67,14 @@ function W.SmallCaps(text) return tostring(text or ""):upper() end -- names all pass through here. On the dark skins colours are left alone. local INK_MAX = 0.34 -- brightest luminance allowed on paper function W.InkRGB(r, g, b) - if not (ns.Notebook and ns.Notebook()) or type(r) ~= "number" then return r, g, b end + if not (ns.Paper and ns.Paper()) or type(r) ~= "number" then return r, g, b end local lum = 0.299 * r + 0.587 * (g or 0) + 0.114 * (b or 0) if lum <= INK_MAX then return r, g, b end local k = INK_MAX / lum return r * k, (g or 0) * k, (b or 0) * k end function W.InkCodes(text) - if type(text) ~= "string" or not (ns.Notebook and ns.Notebook()) or not text:find("|c", 1, true) then return text end + if type(text) ~= "string" or not (ns.Paper and ns.Paper()) or not text:find("|c", 1, true) then return text end return (text:gsub("|c(%x%x)(%x%x)(%x%x)(%x%x)", function(a, rr, gg, bb) local r, g, b = W.InkRGB(tonumber(rr, 16) / 255, tonumber(gg, 16) / 255, tonumber(bb, 16) / 255) return string.format("|c%s%02x%02x%02x", a, math.floor(r * 255 + 0.5), math.floor(g * 255 + 0.5), math.floor(b * 255 + 0.5)) @@ -85,6 +85,7 @@ local function InkFontString(fs) local setText, setColor = fs.SetText, fs.SetTextColor if type(setText) == "function" then fs.SetText = function(self, t) + if rawget(self, "noInk") then return setText(self, t) end setText(self, W.InkCodes(t)) -- single-line text that is too long shrinks a little instead of ending in "..." local canWrap = self.CanWordWrap or self.GetWordWrap @@ -97,7 +98,7 @@ local function InkFontString(fs) end if type(setColor) == "function" then fs.SetTextColor = function(self, r, g, b, a) - r, g, b = W.InkRGB(r, g, b) + if not rawget(self, "noInk") then r, g, b = W.InkRGB(r, g, b) end return setColor(self, r, g, b, a) end end @@ -114,7 +115,7 @@ end function W.Text(parent, size, c, font, justify) local fs = parent:CreateFontString(nil, "OVERLAY") size = size or 12 - if ns.Notebook and ns.Notebook() then + if ns.Paper and ns.Paper() then size = W.PaperSize(size) if fs.SetShadowOffset then fs:SetShadowOffset(0, 0) end InkFontString(fs) @@ -145,7 +146,7 @@ end -- dark ink for paper) tooltips use light parchment colours instead. local TIP_LIGHT = { amber = { 1, 0.82, 0.38 }, text = { 0.96, 0.92, 0.84 }, dim = { 0.78, 0.72, 0.62 } } function ns.TipColor(name, wrap) - local c = (ns.Notebook and ns.Notebook()) and TIP_LIGHT[name] or T[name] or TIP_LIGHT.text + local c = (ns.Paper and ns.Paper()) and TIP_LIGHT[name] or T[name] or TIP_LIGHT.text return c[1], c[2], c[3], wrap end @@ -246,7 +247,8 @@ end -- ------------------------------------------------------------ card -- Card titles are upper case, except in the Forever Journal skin. function ns.CardTitle(s) - if ns.Notebook and ns.Notebook() then return W.SmallCaps(s) end + if ns.Framed and ns.Framed() then return tostring(s or "") end -- the framed tomes use title case + if ns.Paper and ns.Paper() then return W.SmallCaps(s) end return ns.JournalSkin() and s or tostring(s):upper() end @@ -265,7 +267,7 @@ function W.Card(parent, title, icon, x, y, w, h, tip) local rule = W.Line(head); rule:SetPoint("BOTTOMLEFT"); rule:SetPoint("BOTTOMRIGHT"); rule:SetHeight(1) local ic = W.Icon(head, icon or "star", 14, journal and W.JOURNAL.gold or nil) ic:SetPoint("LEFT", 9, 0) - local book = ns.Notebook and ns.Notebook() + local book = ns.Paper and ns.Paper() f.title = W.Text(head, book and 12 or (journal and 13 or 12), journal and W.JOURNAL.gold or T.text) f.title:SetPoint("LEFT", ic, "RIGHT", 8, 0) f.title:SetText(ns.CardTitle(title)) @@ -326,7 +328,7 @@ function W.Odometer(parent, x, y, w, h, label, icon, tip, allowFormatted) wash:SetPoint("TOPLEFT", 1, -2); wash:SetPoint("BOTTOMRIGHT", -1, 1) W.Shade(wash, W.JOURNAL.base, W.JOURNAL.top) number = W.Text(f, 23, T.amber, W.NUM, "LEFT") - if ns.Notebook() then W.Bold(number, T.amber) end + if ns.Paper() then W.Bold(number, T.amber) end number:SetPoint("TOPLEFT", 12, -23) number:SetPoint("RIGHT", f.icon, "LEFT", -6, 0) else @@ -727,7 +729,7 @@ function W.Table(body, bw, bh, cols, onClick, emptyText) c.w = (i == #cols) and (width - x) or c[2] x = x + c.w end - local book = ns.Notebook and ns.Notebook() + local book = ns.Paper and ns.Paper() local head = W.Fill(f, book and W.JOURNAL.base or { 0x1d / 255, 0x1f / 255, 0x23 / 255, 1 }, "BACKGROUND", book and 0.55 or nil) head:SetPoint("TOPLEFT"); head:SetSize(width, HH) f.heads = {} diff --git a/scripts/make_framed_textures.py b/scripts/make_framed_textures.py new file mode 100644 index 0000000..e10ce83 --- /dev/null +++ b/scripts/make_framed_textures.py @@ -0,0 +1,183 @@ +"""Draw the textures of the framed tome skins, Lifetime Stats and Stats Explorer (original artwork). + +Run: python scripts/make_framed_textures.py (needs Pillow) +Writes Media/framed/*.tga, all power-of-two 32-bit TGA: + parchment 1024x1024 clean aged parchment for the window's interior + wood 256x256 dark wood for the Stats Explorer menu + edge_h 512x32 dark wood frame rail with a gold inner line (top; flipped for the bottom) + edge_v 32x512 the same, upright (left; flipped for the right) + corner 64x64 gold corner ornament (top-left; flipped for the others) + plaque 512x128 the title plaque over the top edge + emblem 128x128 gold compass star + crest 128x128 white shield (tinted per card) and crest_rim, its gold rim + navsel 256x32 menu selection, pointed on the right (white, tinted) + divider 256x16 an ornamental rule with a diamond (white, tinted) +""" +import math +import random +from pathlib import Path + +from PIL import Image, ImageDraw, ImageFilter + +OUT = Path(__file__).resolve().parent.parent / "Media" / "framed" +OUT.mkdir(parents=True, exist_ok=True) +random.seed(2026) + +GOLD = (201, 160, 84, 255) +GOLD_D = (122, 88, 38, 255) +GOLD_L = (238, 210, 140, 255) + + +def save(img, name): + img.save(OUT / (name + ".tga")) + print("wrote", name, img.size) + + +def noise(w, h, cells_x, cells_y, blur): + small = Image.new("L", (cells_x, cells_y)) + small.putdata([random.randint(0, 255) for _ in range(cells_x * cells_y)]) + return small.resize((w, h), Image.BICUBIC).filter(ImageFilter.GaussianBlur(blur)) + + +# ---------------------------------------------------------------- parchment +N = 1024 +coarse, mid, fine = noise(N, N, 14, 14, 26), noise(N, N, 60, 60, 4), noise(N, N, 300, 300, 0.7) +img = Image.new("RGBA", (N, N)) +px = img.load() +cp, mp, fp = coarse.load(), mid.load(), fine.load() +for y in range(N): + for x in range(N): + k = (cp[x, y] - 128) * 0.12 + (mp[x, y] - 128) * 0.05 + (fp[x, y] - 128) * 0.05 + dx, dy = (x - N / 2) / (N / 2), (y - N / 2) / (N / 2) + k -= ((dx * dx + dy * dy) ** 1.4) * 34 + px[x, y] = (max(0, min(255, int(226 + k))), max(0, min(255, int(208 + k * 0.97))), max(0, min(255, int(168 + k * 0.9))), 255) +save(img, "parchment") + +# ---------------------------------------------------------------- dark wood +def wood(w, h, horizontal=True): + grain = noise(w, h, 6 if horizontal else 90, 90 if horizontal else 6, 1.2) + streak = noise(w, h, 3 if horizontal else 40, 40 if horizontal else 3, 2) + out = Image.new("RGBA", (w, h)) + o, g, s = out.load(), grain.load(), streak.load() + for y in range(h): + for x in range(w): + k = (g[x, y] - 128) * 0.18 + (s[x, y] - 128) * 0.12 + o[x, y] = (max(0, min(255, int(58 + k))), max(0, min(255, int(40 + k * 0.8))), max(0, min(255, int(26 + k * 0.6))), 255) + return out + + +save(wood(256, 256, horizontal=True), "wood") + + +def rail(w, h, horizontal): + """A frame rail: wood, a dark outer edge, a bevel and a gold line on the inner side.""" + out = wood(w, h, horizontal) + d = ImageDraw.Draw(out) + across = h if horizontal else w + for i in range(across): + # inner side is the far side (bottom for a horizontal rail, right for an upright one) + t = i / (across - 1) + shade = int(-50 + 70 * min(1, t * 1.6)) + if horizontal: + for x in range(w): + r, g, b, a = out.getpixel((x, i)) + out.putpixel((x, i), (max(0, min(255, r + shade)), max(0, min(255, g + shade)), max(0, min(255, b + shade)), a)) + else: + for y in range(h): + r, g, b, a = out.getpixel((i, y)) + out.putpixel((i, y), (max(0, min(255, r + shade)), max(0, min(255, g + shade)), max(0, min(255, b + shade)), a)) + if horizontal: + d.line([(0, h - 6), (w, h - 6)], fill=GOLD_D, width=3) + d.line([(0, h - 6), (w, h - 6)], fill=GOLD, width=1) + d.line([(0, h - 2), (w, h - 2)], fill=(30, 20, 12, 255), width=2) + d.line([(0, 1), (w, 1)], fill=(20, 14, 8, 255), width=2) + else: + d.line([(w - 6, 0), (w - 6, h)], fill=GOLD_D, width=3) + d.line([(w - 6, 0), (w - 6, h)], fill=GOLD, width=1) + d.line([(w - 2, 0), (w - 2, h)], fill=(30, 20, 12, 255), width=2) + d.line([(1, 0), (1, h)], fill=(20, 14, 8, 255), width=2) + return out + + +save(rail(512, 32, True), "edge_h") +save(rail(32, 512, False), "edge_v") + +# ---------------------------------------------------------------- gold corner +S = 64 +img = Image.new("RGBA", (S * 4, S * 4), (0, 0, 0, 0)) +d = ImageDraw.Draw(img) +k = 4 +d.polygon([(0, 0), (S * k * 0.62, 0), (S * k * 0.62, 18 * k / 4 * 4), (18 * k, 18 * k), (18 * k, S * k * 0.62), (0, S * k * 0.62)], fill=GOLD_D) +d.polygon([(6 * k, 6 * k), (S * k * 0.56, 6 * k), (S * k * 0.56, 13 * k), (13 * k, 13 * k), (13 * k, S * k * 0.56), (6 * k, S * k * 0.56)], fill=GOLD) +for cx, cy in ((S * k * 0.62, 9 * k), (9 * k, S * k * 0.62)): + d.ellipse((cx - 5 * k, cy - 5 * k, cx + 5 * k, cy + 5 * k), fill=GOLD, outline=GOLD_D, width=k) +d.ellipse((16 * k, 16 * k, 30 * k, 30 * k), fill=GOLD_L, outline=GOLD_D, width=k * 2) +d.polygon([(23 * k, 18 * k), (27 * k, 23 * k), (23 * k, 28 * k), (19 * k, 23 * k)], fill=GOLD_D) +save(img.resize((S, S), Image.LANCZOS), "corner") + +# ---------------------------------------------------------------- title plaque +W, H = 512, 128 +big = Image.new("RGBA", (W * 2, H * 2), (0, 0, 0, 0)) +d = ImageDraw.Draw(big) +body = [(70, 40), (W * 2 - 70, 40), (W * 2 - 20, H), (W * 2 - 70, H * 2 - 40), (70, H * 2 - 40), (20, H)] +d.polygon(body, fill=(44, 30, 20, 255)) +inner = [(84, 52), (W * 2 - 84, 52), (W * 2 - 40, H), (W * 2 - 84, H * 2 - 52), (84, H * 2 - 52), (40, H)] +d.line(body + [body[0]], fill=GOLD_D, width=10) +d.line(body + [body[0]], fill=GOLD, width=4) +d.line(inner + [inner[0]], fill=GOLD_D, width=3) +grain = wood(W * 2, H * 2) +mask = Image.new("L", (W * 2, H * 2), 0) +ImageDraw.Draw(mask).polygon(inner, fill=90) +big.paste(grain, (0, 0), mask) +for sx in (1, -1): + cx = W if sx == 1 else W + for i in range(3): + x0 = 40 + i * 14 if sx == 1 else W * 2 - 40 - i * 14 + d.line([(x0, H - 30 + i * 6), (x0 + sx * 8, H), (x0, H + 30 - i * 6)], fill=GOLD, width=4) +save(big.resize((W, H), Image.LANCZOS), "plaque") + +# ---------------------------------------------------------------- compass emblem +S = 128 +big = Image.new("RGBA", (S * 4, S * 4), (0, 0, 0, 0)) +d = ImageDraw.Draw(big) +c = S * 2 +d.ellipse((c - 150, c - 150, c + 150, c + 150), outline=GOLD_D, width=22) +d.ellipse((c - 150, c - 150, c + 150, c + 150), outline=GOLD, width=10) +for i in range(8): + a = i * math.pi / 4 - math.pi / 2 + long = 240 if i % 2 == 0 else 160 + tip = (c + math.cos(a) * long, c + math.sin(a) * long) + l = (c + math.cos(a - 0.32) * 46, c + math.sin(a - 0.32) * 46) + r = (c + math.cos(a + 0.32) * 46, c + math.sin(a + 0.32) * 46) + d.polygon([tip, l, (c, c)], fill=GOLD_L if i % 2 == 0 else GOLD) + d.polygon([tip, r, (c, c)], fill=GOLD_D) +d.ellipse((c - 34, c - 34, c + 34, c + 34), fill=(46, 92, 76, 255), outline=GOLD, width=10) +save(big.resize((S, S), Image.LANCZOS), "emblem") + +# ---------------------------------------------------------------- crest (shield) and its rim +S = 128 +shield = [(14, 10), (114, 10), (114, 70), (64, 120), (14, 70)] +def shape(scale=4): + return [(x * scale, y * scale) for x, y in shield] +big = Image.new("RGBA", (S * 4, S * 4), (0, 0, 0, 0)) +ImageDraw.Draw(big).polygon(shape(), fill=(255, 255, 255, 255)) +save(big.resize((S, S), Image.LANCZOS), "crest") +big = Image.new("RGBA", (S * 4, S * 4), (0, 0, 0, 0)) +d = ImageDraw.Draw(big) +d.line(shape() + [shape()[0]], fill=GOLD_D, width=26) +d.line(shape() + [shape()[0]], fill=GOLD, width=12) +save(big.resize((S, S), Image.LANCZOS), "crest_rim") + +# ---------------------------------------------------------------- menu selection and divider +big = Image.new("RGBA", (1024, 128), (0, 0, 0, 0)) +ImageDraw.Draw(big).polygon([(0, 0), (960, 0), (1020, 64), (960, 127), (0, 127)], fill=(255, 255, 255, 255)) +save(big.resize((256, 32), Image.LANCZOS), "navsel") +big = Image.new("RGBA", (1024, 64), (0, 0, 0, 0)) +d = ImageDraw.Draw(big) +d.line([(40, 32), (440, 32)], fill=(255, 255, 255, 255), width=4) +d.line([(584, 32), (984, 32)], fill=(255, 255, 255, 255), width=4) +d.polygon([(512, 8), (536, 32), (512, 56), (488, 32)], outline=(255, 255, 255, 255), width=5) +d.polygon([(512, 22), (522, 32), (512, 42), (502, 32)], fill=(255, 255, 255, 255)) +for x in (440, 584): + d.ellipse((x - 6, 26, x + 6, 38), fill=(255, 255, 255, 255)) +save(big.resize((256, 16), Image.LANCZOS), "divider") diff --git a/tests/framed.py b/tests/framed.py new file mode 100644 index 0000000..8fd788b --- /dev/null +++ b/tests/framed.py @@ -0,0 +1,200 @@ +"""Offline tests for the framed tome skins (Lifetime Stats, the default, and Stats Explorer): +frame, plaque, header controls, menu, both overview pages and their data.""" + +from pathlib import Path + +from lupa import lua51 +from PIL import Image + +ROOT = Path(__file__).resolve().parent.parent + +for name in ("parchment", "wood", "edge_h", "edge_v", "corner", "plaque", "emblem", "crest", "crest_rim", "navsel", "divider"): + path = ROOT / "Media" / "framed" / (name + ".tga") + assert path.exists(), path + im = Image.open(path) + w, h = im.size + assert w & (w - 1) == 0 and h & (h - 1) == 0, (name, im.size) + assert im.mode == "RGBA", (name, im.mode) +print("textures ok") + +COMMON = r''' +local checks = 0 +function eq(got, expected, msg) + checks = checks + 1 + if got ~= expected then error(msg .. ": got " .. tostring(got) .. ", expected " .. tostring(expected), 2) end +end +local function fire(event, ...) local f = ns.frame; f.scripts.OnEvent(f, event, ...) end +fire("ADDON_LOADED", "LifeTimeStats") +fire("PLAYER_LOGIN") +fire("PLAYER_ENTERING_WORLD", true, false) +NOW = NOW + 11; RunTimers() +''' + + +def load(): + lua = lua51.LuaRuntime(unpack_returned_tuples=True) + lua.execute((ROOT / "tests/harness.lua").read_text(encoding="utf-8")) + lua.execute("ns = {}") + for name in (ROOT / "LifeTimeStats.toc").read_text(encoding="utf-8").splitlines(): + name = name.strip() + if name.endswith(".lua"): + chunk = lua.eval("function(src, name) return assert(loadstring(src, name)) end")( + (ROOT / name).read_text(encoding="utf-8"), name + ) + chunk("LifeTimeStats", lua.globals().ns) + return lua + + +# ---------------------------------------------------------------- data helpers and the default skin +lua = load() +print("ledger:", lua.execute(COMMON + r''' +-- data +local now = time() +eq(ns.Ago(now - 30, now), "just now", "seconds ago") +eq(ns.Ago(now - 300, now), "5m ago", "minutes ago") +eq(ns.Ago(now - 7200, now), "2h ago", "hours ago") +eq(ns.Ago(now - 86400, now), "1 day ago", "one day") +eq(ns.Ago(now - 86400 * 6, now), "6 days ago", "days") +eq(ns.ScoreMotto(0), "Every road starts with a single step.", "first motto") +eq(ns.ScoreMotto(2500), "A long road, well traveled.", "a long road") +eq(ns.ScoreMotto(99999), "A legend, written one step at a time.", "the last motto") + +local ch = ns.char +ch.journal = { + { now - 86400 * 6, "Reached level 10 in Mulgore", 10, zone = "Mulgore" }, + { now - 86400 * 2, "Killed Hogger for the first time.", 10, kind = "boss", zone = "Elwynn Forest" }, +} +ch.quests = { { t = now - 3600, n = "The Hunt Begins", l = 10 }, { t = now - 86400 * 3, n = "Rite of Strength", l = 9 } } +ch.items = { { t = now - 600, n = "Swift Windsteed", q = 4, src = "boss" }, { t = now - 60, n = "Linen Cloth", q = 1 } } +local ms = ns.OverviewMilestones(ch, 5) +eq(#ms, 2, "two milestones") +eq(ms[1].title, "Killed Hogger for the first time.", "newest milestone first") +eq(ms[1].icon:find("Dragon", 1, true) ~= nil, true, "boss icon") +eq(ms[2].icon:find("SurgeOfLight", 1, true) ~= nil, true, "level-up icon") +eq(ms[1].sub, "Elwynn Forest · level 10", "where and when") +local act = ns.OverviewActivity(ch, 10) +eq(#act, 5, "quests, a good item and the Journal (grey items left out)") +eq(act[1].title, "Obtained Swift Windsteed", "newest first") +eq(act[2].title, "Completed a quest", "quests in the feed") +for i = 2, #act do eq(act[i - 1].at >= act[i].at, true, "sorted newest first") end + +ch.r.max_hit, ch.r.max_hit_what = 1234, "Wrath" +ch.rh = { { k = "max_hit", v = 1234, at = now - 86400, d = "max", w = "Wrath" } } +ch.days[date("%Y%m%d", now - 86400 * 4)] = { money_in = 50000, quests_done = 7, kills_npc = 3 } +ch.days[date("%Y%m%d")] = { kills_npc = 2 } +local hl = ns.OverviewHighlights(ch, 5) +eq(hl[1].label, "Biggest hit", "biggest hit first") +eq(hl[1].source, "Wrath", "with its source") +eq(hl[1].at, now - 86400, "and when") +local labels = {} +for _, h in ipairs(hl) do labels[h.label] = h end +eq(labels["Most gold in a day"] ~= nil, true, "best gold day") +eq(labels["Most quests in a day"].value, "7", "best quest day") +eq(labels["Best DPS on a boss"], nil, "missing records are left out") + +ch.c.kills_npc = 105 +local series = ns.CumulativeSeries(ch, function(d) return (d.kills_npc or 0) end, 105, 30) +eq(#series, 30, "30 days") +eq(series[30].total, 105, "ends at today's total") +eq(series[29].total, 103, "yesterday was before today's kills") +eq(series[1].total, 100, "a month ago, before both days") + +-- the default skin +eq(ns.DetectUI(), "ledger", "Lifetime Stats is the default") +ns.ToggleWindow() +eq(ns.themeId, "ledger", "applied") +eq(ns.Framed() and ns.Paper() and ns.Ledger(), true, "a framed paper skin") +local win = LifeTimeStatsWindow +local fr = rawget(win, "framed") +eq(fr ~= nil, true, "frame built") +eq(fr.title:GetText(), "Lifetime Stats", "plaque title") +eq(#fr.corners, 4, "four gold corners") +eq(rawget(win, "notebook"), nil, "no notebook frame") +-- header controls +local scope, range = win.scopeSeg, win.rangeSeg +eq(scope.text:GetText(), "Malikor", "character dropdown shows the character") +eq(range.text:GetText(), "All time", "range dropdown") +range.scripts.OnClick(range) +eq(range.menu:IsShown(), true, "menu opens") +range.rows[3].scripts.OnClick(range.rows[3]) +eq(ns.settings.range, "today", "picking Today") +eq(range.menu:IsShown(), false, "menu closes") +eq(range.text:GetText(), "Today", "dropdown shows the choice") +scope.rows[2].scripts.OnClick(scope.rows[2]) +eq(ns.settings.scope, "account", "all characters") +eq(scope.text:GetText(), "All characters", "dropdown shows all characters") +scope.rows[1].scripts.OnClick(scope.rows[1]); range.rows[1].scripts.OnClick(range.rows[1]) +-- menu +ns.ShowPage("combat") +local selCount = 0 +for _, b in ipairs(win.navButtons) do if b.sel:IsShown() then selCount = selCount + 1; eq(b.id, "combat", "the open page is selected") end end +eq(selCount, 1, "one selected entry") +-- the overview +ns.ShowPage("dashboard") +local p = ns.Page("dashboard") +eq(p.heroName:GetText(), "Malikor", "hero name") +eq(p.tiles[1].value:GetText(), ns.FormatInt(ns.Kills(ch)), "kills tile") +eq(p.tiles[1].sub:GetText(), "Lifetime", "range under the counters") +eq(p.milestones.rows[1].title:GetText(), "Killed Hogger for the first time.", "milestones listed") +eq(p.highlights.rows[1].title:GetText():find("Biggest hit", 1, true) ~= nil, true, "highlights listed") +eq(p.activity.rows[1].title:GetText(), "Obtained Swift Windsteed", "activity listed") +eq(p.pageText:GetText(), "1 / " .. math.max(1, math.ceil(#ns.OverviewActivity(ch, 200) / p.per)), "pager") +-- every page renders in this skin +for _, cdef in ipairs(ns.CATEGORIES) do ns.ShowPage(cdef.id) end +eq(#ns.errors, 0, "no handler errors: " .. table.concat(ns.errors, " | ")) +return checks +''')) + +# ---------------------------------------------------------------- Stats Explorer +lua = load() +print("explorer:", lua.execute(COMMON + r''' +ns.settings.theme = "explorer" +ns.ToggleWindow() +eq(ns.themeId, "explorer", "applied") +eq(ns.Explorer() and ns.Framed(), true, "explorer is framed") +local win = LifeTimeStatsWindow +eq(rawget(win, "framed").title:GetText(), "Stats Explorer", "plaque title") +-- segmented time range +local seg = win.rangeSeg +eq(#seg.buttons, 5, "five ranges") +eq(seg.buttons[2].text:GetText(), "Daily", "daily") +seg.buttons[3].scripts.OnClick(seg.buttons[3]) +eq(ns.settings.range, "week", "weekly picked") +seg.buttons[5].scripts.OnClick(seg.buttons[5]) +eq(ns.settings.range, "lifetime", "lifetime picked") +eq(rawget(win.navButtons[1].text, "noInk"), true, "menu text stays light on the wood") +eq(win.todayBox:IsShown(), false, "no Today box: pinned stats sit at the bottom") +-- overview +ns.ShowPage("dashboard") +local p = ns.Page("dashboard") +eq(p.score:GetText(), ns.FormatInt((ns.Score(ns.char))), "lifetime score") +eq(p.motto:GetText():sub(1, 1), '"', "the motto is quoted") +eq(#p.cards, 4, "four cards") +eq(p.cards[1].title:GetText(), "Combat", "combat card") +eq(p.cards[4].title:GetText(), "Collections", "collections card") +eq(p.cards[3].stats[1].v:GetText():find("^Level") ~= nil, true, "progression shows the level") +p.cards[2].scripts.OnClick(p.cards[2]) +eq(ns.activePage, "travel", "the exploration card opens Travel") +ns.ShowPage("dashboard") +local shown = 0 +for _, b in ipairs(p.pins) do if b:IsShown() then shown = shown + 1 end end +eq(shown > 0, true, "pinned statistics shown") +for _, cdef in ipairs(ns.CATEGORIES) do ns.ShowPage(cdef.id) end +eq(#ns.errors, 0, "no handler errors: " .. table.concat(ns.errors, " | ")) +return checks +''')) + +# ---------------------------------------------------------------- framed skins fill the screen too +lua = load() +lua.execute("UIParent.wdt = 1920; UIParent.h = 1080") +print("fill:", lua.execute(COMMON + r''' +ns.settings.window.size = "fill"; ns.settings.window.scale = 1 +ns.ToggleWindow() +local w, h = ns.WindowSize() +eq(w > 1140 and w + 30 + 164 <= 1920, true, "fill width leaves room for the frame and tabs") +eq(h + 60 <= 1080, true, "fill height leaves room for the plaque") +for _, cdef in ipairs(ns.CATEGORIES) do ns.ShowPage(cdef.id) end +eq(#ns.errors, 0, "no handler errors: " .. table.concat(ns.errors, " | ")) +return checks +''')) +print("FRAMED PASS") diff --git a/tests/journal.py b/tests/journal.py index 67707db..0d4e5bf 100644 --- a/tests/journal.py +++ b/tests/journal.py @@ -47,7 +47,7 @@ fire("PLAYER_LOGIN") fire("PLAYER_ENTERING_WORLD", true, false) eq(ns.settings.theme, "auto", "new installs use Auto") -eq(ns.DetectUI(), "notebook", "Auto uses the Adventurer's Notebook without a UI replacement") +eq(ns.DetectUI(), "ledger", "Auto uses Lifetime Stats without a UI replacement") local loaded = { Tukui = true, ElvUI = true, EllesmereUI = true } C_AddOns = { IsAddOnLoaded = function(name) return loaded[name] end } eq(ns.DetectUI(), "ellesmere", "Auto keeps EllesmereUI precedence") diff --git a/tests/notebook.py b/tests/notebook.py index 95d59aa..3f10b71 100644 --- a/tests/notebook.py +++ b/tests/notebook.py @@ -43,7 +43,8 @@ NOW = NOW + 11; RunTimers() eq(ns.settings.theme, "auto", "new installs use Auto") -eq(ns.DetectUI(), "notebook", "Auto picks the notebook without a UI addon") +eq(ns.DetectUI(), "ledger", "Auto picks Lifetime Stats without a UI addon") +ns.settings.theme = "notebook" -- this suite checks the notebook, which is chosen in Settings ns.ToggleWindow() eq(ns.themeId, "notebook", "notebook applied") eq(ns.Notebook(), true, "ns.Notebook") @@ -143,7 +144,7 @@ local function lum(r, g, b) return 0.299 * r + 0.587 * g + 0.114 * b end local r, g, b = W.InkRGB(1, 0.7, 0.22) eq(r, 1, "dark skins keep bright colours") -ns.settings.theme = "auto" +ns.settings.theme = "notebook" ns.ApplyTheme() eq(ns.Notebook(), true, "back on the notebook") r, g, b = W.InkRGB(1, 0.7, 0.22) diff --git a/tests/sections.py b/tests/sections.py index 01fbe32..98efa37 100644 --- a/tests/sections.py +++ b/tests/sections.py @@ -101,7 +101,7 @@ for _, d in ipairs(p.table.data) do if d.header then heads = heads + 1 end end eq(heads, #groups, "a heading row per section") eq(p.table.data[1].header, true, "the table starts with a heading") -eq(bar.tabs[1].text:GetText(), ns.W.SmallCaps(groups[1].name), "first tab names the first section") +eq(bar.tabs[1].text:GetText(), ns.Notebook() and ns.W.SmallCaps(groups[1].name) or groups[1].name, "first tab names the first section") eq(bar.tabs[1].def.active, true, "first section active at the top") eq(bar.tabs[#groups + 1]:IsShown(), false, "spare tabs hidden") diff --git a/tests/statdetail.py b/tests/statdetail.py index db80309..3880396 100644 --- a/tests/statdetail.py +++ b/tests/statdetail.py @@ -57,7 +57,7 @@ eq(h.bestEver.v, 99, "best day on file, beyond the chart") eq(h.bestEver.d, day(35), "best day's date") eq(h.daysOnFile, 5, "days on file with any") -eq(h.home, "Travels › Getting around", "where the statistic lives") +eq(h.home, "Travel › Getting around", "where the statistic lives") -- ------------------------------------------------------------ every character ns.db.chars["Hex-Forever"] = { c = { jumps = 800 }, r = {}, t = {}, un = {}, days = {}, meta = { name = "Hex", class = "WARLOCK" } } @@ -157,13 +157,24 @@ ns.ShowPage("dashboard") local dash = ns.Page("dashboard") layer:Hide() -local jumpTile -for _, t in ipairs(dash.kpis) do if rawget(t, "stat") == st then jumpTile = t end end -eq(jumpTile ~= nil, true, "the jumps tile knows its statistic") -jumpTile.scripts.OnMouseUp(jumpTile, "LeftButton") -eq(layer:IsShown() and layer.stat == st, true, "clicking a tile opens its card") +-- the overview of the default skin (Lifetime Stats): its counters open their statistic +local killTile +for _, t in ipairs(dash.tiles) do if rawget(t, "stat") and t.stat.label == "Enemies killed" then killTile = t end end +eq(killTile ~= nil, true, "the kills tile knows its statistic") +killTile.scripts.OnClick(killTile) +eq(layer:IsShown() and layer.stat == killTile.stat, true, "clicking a tile opens its card") layer:Hide() -jumpTile.scripts.OnMouseUp(jumpTile, "RightButton") + +-- the page tiles of the other skins open theirs too (left-click only) +ns.ShowPage("combat") +local combat = ns.Page("combat") +local hitTile +for _, t in ipairs(combat.kpis) do if rawget(t, "stat") then hitTile = t end end +eq(hitTile ~= nil, true, "a page tile knows its statistic") +hitTile.scripts.OnMouseUp(hitTile, "LeftButton") +eq(layer:IsShown() and layer.stat == hitTile.stat, true, "clicking a page tile opens its card") +layer:Hide() +hitTile.scripts.OnMouseUp(hitTile, "RightButton") eq(layer:IsShown(), false, "right-click does not open it") -- every statistic on every page opens without an error