Repository navigation
Expand file tree
/
Copy pathOptions.lua
More file actions
340 lines (317 loc) · 17.9 KB
/
Copy pathOptions.lua
File metadata and controls
340 lines (317 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
-- LifeTimeStats - settings panel (Options > AddOns > LifeTimeStats)
-- Copyright (C) 2026 Malikor. Licensed under GPL-3.0-or-later (see LICENSE).
local _, ns = ...
local T = ns.THEME
local panel, category
StaticPopupDialogs["LIFETIMESTATS_RESET_CHAR"] = {
text = "Erase ALL lifetime stats for %s?\n\nThis cannot be undone. Make a Backup first if you might want them back.",
button1 = "Erase",
button2 = CANCEL or "Cancel",
OnAccept = function()
local rec = ns.NewCharRecord()
rec.meta.name, rec.meta.realm = ns.char.meta.name, ns.char.meta.realm
rec.meta.rev = (ns.char.meta.rev or 0) + 1
ns.db.chars[ns.charKey] = rec
LifeTimeStatsCharDB.data = rec
ns.char = rec
ns.ResetSession()
ns.Print("Lifetime stats for this character erased.")
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
StaticPopupDialogs["LIFETIMESTATS_RELOAD"] = {
text = "LifeTimeStats: the new theme applies after reloading the interface. Reload now?",
button1 = RELOADUI or "Reload",
button2 = LATER or "Later",
OnAccept = function() ReloadUI() end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
-- ------------------------------------------------------------ themed controls
local W
-- Rows are laid out on a 34-pixel grid and stretched by K, so every description has room for
-- two full lines instead of being cut off with "...".
local K = 1.3
local function Y(n) return math.floor(n * K + 0.5) end
local ROW_H = Y(34)
-- Toggle row: square box, label, a description of up to two lines. The whole row is clickable.
local function Toggle(parent, x, y, w, label, desc, get, set)
local r = CreateFrame("Button", nil, parent)
r:SetPoint("TOPLEFT", x, -Y(y)); r:SetSize(w, ROW_H)
r.hl = W.Fill(r, T.tileHi); r.hl:SetAllPoints(); r.hl:Hide()
local box = W.Panel(r, T.bg, T.edge); box:SetSize(14, 14); box:SetPoint("TOPLEFT", 6, -4)
local fill = W.Fill(box, T.amber, "ARTWORK"); fill:SetPoint("TOPLEFT", 3, -3); fill:SetPoint("BOTTOMRIGHT", -3, 3)
local l = W.Text(r, 12, T.text); l:SetPoint("TOPLEFT", 28, -4); l:SetText(label)
local d = W.Text(r, 10, T.dim); d:SetPoint("TOPLEFT", 28, -20); d:SetPoint("RIGHT", -4, 0); d:SetJustifyH("LEFT")
d:SetJustifyV("TOP"); d:SetWordWrap(true); if d.SetMaxLines then d:SetMaxLines(2) end
d:SetText(desc)
function r:Sync() fill:SetShown(get() and true or false) end
r:SetScript("OnClick", function(self) set(not get()); self:Sync() end)
r:SetScript("OnEnter", function() r.hl:Show() end)
r:SetScript("OnLeave", function() r.hl:Hide() end)
W.Tip(r, label, desc) -- the full text, in case a long description is still cut
r:Sync()
return r
end
-- Label on the left, control on the right.
local function RowLabel(parent, x, y, label, desc)
local l = W.Text(parent, 12, T.text); l:SetPoint("TOPLEFT", x + 6, -Y(y) - 4); l:SetText(label)
if desc then
local d = W.Text(parent, 10, T.dim); d:SetPoint("TOPLEFT", x + 6, -Y(y) - 20); d:SetText(desc)
return l, d
end
return l
end
-- Arrow cycler: ‹ value ›
local function Cycler(parent, w, getText, step, tip)
local f = W.Panel(parent, T.bg)
f:SetSize(w, 22)
local t = W.Text(f, 11, T.text); t:SetPoint("CENTER")
-- long values ("Auto (Adventurer's Notebook)") shrink to fit between the arrows
local function Fit(text)
t:SetText(text)
for size = 11, 8, -1 do
pcall(t.SetFont, t, W.FONT, size, "")
if (t:GetStringWidth() or 0) <= w - 46 then break end
end
end
local function Arrow(sym, dir, point)
local b = CreateFrame("Button", nil, f)
b:SetSize(22, 22); b:SetPoint(point)
local a = W.Text(b, 14, T.amber); a:SetPoint("CENTER"); a:SetText(sym)
b:SetScript("OnClick", function() step(dir); Fit(getText()) end)
b:SetScript("OnEnter", function() a:SetTextColor(T.text[1], T.text[2], T.text[3]) end)
b:SetScript("OnLeave", function() a:SetTextColor(T.amber[1], T.amber[2], T.amber[3]) end)
end
Arrow("<", -1, "LEFT"); Arrow(">", 1, "RIGHT")
f:EnableMouse(true)
f:SetScript("OnMouseUp", function() step(1); Fit(getText()) end)
if tip then W.Tip(f, tip[1], tip[2]) end
function f:Sync() Fit(getText()) end
f:Sync()
return f
end
-- Flat horizontal slider.
local function FlatSlider(parent, w, minV, maxV, stepV, get, set, fmt)
local s = CreateFrame("Slider", nil, parent)
s:SetOrientation("HORIZONTAL"); s:SetSize(w, 16)
s:SetMinMaxValues(minV, maxV); s:SetValueStep(stepV)
if s.SetObeyStepOnDrag then s:SetObeyStepOnDrag(true) end
local track = W.Fill(s, T.edge, "BACKGROUND"); track:SetPoint("LEFT"); track:SetPoint("RIGHT"); track:SetHeight(2)
local on = W.Fill(s, T.amber, "BORDER"); on:SetPoint("LEFT"); on:SetHeight(2)
s:SetThumbTexture(W.WHITE)
local th = s:GetThumbTexture()
if th then th:SetSize(8, 14); th:SetVertexColor(T.amber[1], T.amber[2], T.amber[3]) end
local val = W.Text(parent, 11, T.amber, W.NUM, "RIGHT"); val:SetPoint("LEFT", s, "RIGHT", 10, 0)
local function Show(v)
val:SetText(fmt(v))
on:SetWidth(math.max(1, (v - minV) / (maxV - minV) * w))
end
s:SetValue(get()); Show(get())
s:SetScript("OnValueChanged", function(_, v)
v = math.floor(v / stepV + 0.5) * stepV
set(v); Show(v)
end)
s:EnableMouseWheel(true)
s:SetScript("OnMouseWheel", function(self, d) self:SetValue(self:GetValue() + d * stepV) end)
function s:Sync() self:SetValue(get()); Show(get()) end
return s
end
local function Button(parent, label, w, tip, fn, danger)
local b = W.FlatButton(parent, label, w, 24, label, tip)
if danger then b.text:SetTextColor(W.C.rust[1], W.C.rust[2], W.C.rust[3]); W.Color(b.edge, W.C.rust) end
b:SetScript("OnClick", fn)
return b
end
-- Small colour chips showing a theme's palette.
local function Swatches(parent)
local f = CreateFrame("Frame", nil, parent)
f:SetSize(5 * 14 + 4 * 3, 12)
f.chips = {}
for i = 1, 5 do
local c = W.Panel(f, T.bg, { 0, 0, 0, 1 }); c:SetSize(14, 12); c:SetPoint("LEFT", (i - 1) * 17, 0)
f.chips[i] = c
end
function f:Show(id)
local t = ns.THEME_BY_ID[id] or ns.THEME_BY_ID.forever
local list = { t.bg, t.tile, t.text, t.amber, t.rust }
for i, c in ipairs(self.chips) do local col = list[i] c:SetBackdropColor(col[1], col[2], col[3], 1) end
end
return f
end
-- ------------------------------------------------------------ panel
function ns.CreateOptions()
W = ns.W
local S = ns.settings
panel = CreateFrame("Frame")
panel.name = "LifeTimeStats"
ns.optionsPanel = panel
local CW = 620
-- 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.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")
panel.sheet = sheet
end
local sf = CreateFrame("ScrollFrame", nil, panel)
sf:SetPoint("TOPLEFT", 4, -4); sf:SetPoint("BOTTOMRIGHT", -4, 4)
local c = CreateFrame("Frame", nil, sf)
c:SetSize(CW, Y(740))
sf:SetScrollChild(c)
sf:EnableMouseWheel(true)
sf:SetScript("OnMouseWheel", function(self, d)
local maxS = math.max(0, c:GetHeight() - self:GetHeight())
self:SetVerticalScroll(math.max(0, math.min(maxS, self:GetVerticalScroll() - d * 40)))
end)
-- header ----------------------------------------------------------
local hb = W.Panel(c, T.tile); hb:SetPoint("TOPLEFT", 0, 0); hb:SetSize(CW, 52)
local rule = W.Fill(hb, T.amber, "ARTWORK"); rule:SetPoint("BOTTOMLEFT"); rule:SetPoint("BOTTOMRIGHT"); rule:SetHeight(2)
local logo = hb:CreateTexture(nil, "ARTWORK"); logo:SetSize(32, 32); logo:SetPoint("LEFT", 10, 0); logo:SetTexture(W.MEDIA .. "icon")
local t1 = W.Text(hb, 18, T.amber); t1:SetPoint("TOPLEFT", logo, "TOPRIGHT", 10, 1); t1:SetText("LifeTime")
local t2 = W.Text(hb, 18, T.text); t2:SetPoint("LEFT", t1, "RIGHT", 0, 0); t2:SetText("Stats")
local ver = W.Text(hb, 11, T.dim); ver:SetPoint("LEFT", t2, "RIGHT", 8, -1); ver:SetText("v" .. ns.VERSION)
local sub = W.Text(hb, 11, T.dim); sub:SetPoint("BOTTOMLEFT", logo, "BOTTOMRIGHT", 10, 0); sub:SetText("Lifetime statistics for your character · /lts opens the window")
local open = Button(hb, "Open window", 110, "Open the LifeTimeStats window.", function() ns.ToggleWindow() end)
open:SetPoint("RIGHT", -10, 0)
local colW, gap, y0 = (CW - 10) / 2, 10, 62
local L, R = 0, colW + gap
local rows = {}
local function Track(r) rows[#rows + 1] = r return r end
-- APPEARANCE (left) -----------------------------------------------
local ap = W.Card(c, "Appearance", "dashboard", L, y0, colW, Y(296))
local b = ap.body
RowLabel(b, 0, 0, "Theme", "Applies after /reload")
local sw = Swatches(b); sw:SetPoint("TOPLEFT", 6, -Y(36) - 2)
local reload = Button(b, "Reload now", 90, "Reload the interface to apply the new theme.", function() ReloadUI() end)
reload:SetPoint("TOPRIGHT", -2, -Y(30)); reload:Hide()
local function ThemeId()
local theme = S.theme or "auto"
return theme == "auto" and ns.DetectUI() or theme
end
local themeCyc = Cycler(b, 174, function() return ns.ThemeName(S.theme or "auto") end, function(dir)
local i = 1
for k, id in ipairs(ns.THEME_ORDER) do if id == (S.theme or "auto") then i = k end end
S.theme = ns.THEME_ORDER[(i - 1 + dir) % #ns.THEME_ORDER + 1]
sw:Show(ThemeId()); reload:SetShown(ThemeId() ~= ns.themeId or S.theme ~= ns.themeChosen)
end, { "Theme", function()
local t = ns.THEME_BY_ID[ThemeId()] or ns.THEME_BY_ID.forever
return "Auto follows EllesmereUI, ElvUI or Tukui when loaded. On the stock UI, Auto uses Forever Journal.\n\n" .. t.name .. " — " .. t.desc
end })
themeCyc:SetPoint("TOPRIGHT", -2, -2)
sw:Show(ThemeId())
ns.themeChosen = S.theme
Track(Toggle(b, 0, 56, ap.bw, "Class colour accent", "Use your class colour for numbers and charts. Applies after /reload.",
function() return S.classColor end, function(v) S.classColor = v; reload:Show() end))
RowLabel(b, 0, 98, "Window size", "Fill screen shows more rows; applies after /reload")
local sizeSeg = W.Segmented(b, {
{ id = "normal", label = "Normal", tip = "1140 x 740, scaled to fit your screen." },
{ id = "fill", label = "Fill screen", tip = "As large as your screen allows: taller tables and wider pages. Window scale still makes the text bigger or smaller." },
}, function(id) ns.SetWindowSize(id); sizeSeg:Select(S.window.size or "normal") end)
sizeSeg:SetPoint("TOPRIGHT", -2, -Y(98))
sizeSeg:Select(S.window.size or "normal")
sizeSeg.Sync = function(self) self:Select(S.window.size or "normal") end
Track(sizeSeg)
RowLabel(b, 0, 132, "Window scale")
local sl = FlatSlider(b, 130, 0.6, 1.6, 0.05, function() return S.window.scale or 1 end,
function(v) S.window.scale = math.floor(v * 100 + 0.5) / 100; ns.ApplyWindowSettings() end, function(v) return string.format("%d%%", v * 100 + 0.5) end)
sl:SetPoint("TOPRIGHT", -52, -Y(134))
Track(sl)
Track(Toggle(b, 0, 168, ap.bw, "Lock window", "Stop the window from being dragged.",
function() return S.lockWindow end, function(v) S.lockWindow = v end))
Track(Toggle(b, 0, 202, ap.bw, "Minimap button", "Left-click opens the window, right-click opens settings.",
function() return not S.minimap.hide end, function(v) S.minimap.hide = not v; ns.UpdateMinimapButton() end))
-- SCREENSHOTS (left) ----------------------------------------------
local ss = W.Card(c, "Screenshots", "star", L, y0 + Y(306), colW, Y(150))
b = ss.body
Track(Toggle(b, 0, 0, ss.bw, "On level-up", "A moment after each new level.",
function() return S.shotLevel end, function(v) S.shotLevel = v end))
Track(Toggle(b, 0, 34, ss.bw, "On first boss kill", "The first time you kill each dungeon or raid boss.",
function() return S.shotBoss end, function(v) S.shotBoss = v end))
Track(Toggle(b, 0, 68, ss.bw, "On achievement", "When you earn a LifeTimeStats achievement tier.",
function() return S.shotAch end, function(v) S.shotAch = v end))
-- CHAT & DISPLAY (right) ------------------------------------------
local cd = W.Card(c, "Chat and display", "social", R, y0, colW, Y(298))
b = cd.body
Track(Toggle(b, 0, 0, cd.bw, "Session column", "Show how much each value grew this session.",
function() return S.showSession end, function(v) S.showSession = v; ns.RefreshWindow() end))
Track(Toggle(b, 0, 34, cd.bw, "Last-session recap at login", "A chat line with your last session's highlights, and a summary window after sessions of 10+ minutes (/lts summary shows it any time).",
function() return S.recap end, function(v) S.recap = v; S.recapWindow = v end))
Track(Toggle(b, 0, 68, cd.bw, "Level-up line", "How long the level took and your time online.",
function() return S.levelMsg end, function(v) S.levelMsg = v end))
Track(Toggle(b, 0, 102, cd.bw, "Kill counts and item sources on tooltips", "How often you killed, fought and were hurt by a creature, and where you got an item (boss, quest, vendor...).",
function() return S.tooltipKills end, function(v) S.tooltipKills = v; S.itemTooltips = v end))
Track(Toggle(b, 0, 136, cd.bw, "Milestones in chat", "A line when counters pass 100, 1,000, 10,000...",
function() return S.milestones end, function(v) S.milestones = v end))
Track(Toggle(b, 0, 170, cd.bw, "Record new highs in the journal", "Add meaningful new records to your local adventure chronicle; no live chat spam.",
function() return S.recordMoments end, function(v) S.recordMoments = v end))
RowLabel(b, 0, 205, "Achievement alerts", nil)
local alerts = W.Segmented(b, {
{ id = "off", label = "Off", tip = "Only a 'new' count on the sidebar." },
{ id = "chat", label = "Chat", tip = "A chat line." },
{ id = "toast", label = "Toast", tip = "A small pop-up you can click to open the page." },
{ id = "both", label = "Both", tip = "Chat line and toast." },
}, function(id) S.achAnnounce = id; alerts:Select(id) end)
alerts:SetPoint("TOPLEFT", 6, -Y(225))
alerts:Select(S.achAnnounce or "off")
alerts.Sync = function(self) self:Select(S.achAnnounce or "off") end
Track(alerts)
-- TRACKING (right) ------------------------------------------------
-- below Chat and display (298 tall), so the alerts row is not covered
local tr = W.Card(c, "Tracking and title", "records", R, y0 + Y(308), colW, Y(114))
b = tr.body
Track(Toggle(b, 0, 0, tr.bw, "Count pet and guardian damage", "Include your pet's damage, kills and misses.",
function() return S.countPet end, function(v) S.countPet = v end))
RowLabel(b, 0, 40, "Title", "Shown by your name")
local titleCyc = Cycler(b, 160, function() return ns.TitledName() end, function(dir)
ns.CycleTitle(dir); if ns.RefreshWindow then ns.RefreshWindow() end
end, { "Title", "Cycle through the titles you have earned (or none)." })
titleCyc:SetPoint("TOPRIGHT", -2, -Y(40) - 2)
Track(titleCyc)
-- DATA (full width) -----------------------------------------------
local da = W.Card(c, "Your data", "chest", 0, y0 + Y(466), CW, 160)
b = da.body
local info = W.Text(b, 12, T.text); info:SetPoint("TOPLEFT", 6, -2)
local note = W.Text(b, 10, T.dim); note:SetPoint("TOPLEFT", 6, -24); note:SetPoint("RIGHT", -6, 0); note:SetJustifyH("LEFT"); note:SetWordWrap(true)
note:SetText("Stored twice (account file and character file), so one lost SavedVariables file does not wipe your totals. Backups are plain text.")
local bw2, bx = (da.bw - 5 * 8) / 6, 0
local function Btn(label, tip, fn, danger)
local x = Button(b, label, bw2, tip, fn, danger)
x:SetPoint("BOTTOMLEFT", bx, 4); bx = bx + bw2 + 8
end
Btn("Backup", "Copyable text backup of this character.", function() ns.ShowExport() end)
Btn("Restore", "Merge a stats-only backup or preview a full character restore.", function() ns.ShowImport() end)
Btn("Character sheet", "A text summary to paste anywhere.", function() ns.ShowSheet() end)
Btn("Reset session", "Zero the session column. Lifetime values stay.", function() ns.ResetSession(); ns.Print("Session counters reset.") end)
Btn("Reset window", "Centre the window and fit it to your screen.", function() ns.ResetWindow(); sl:Sync() end)
Btn("Erase character", "Erase every lifetime value for this character. Asks first.", function() StaticPopup_Show("LIFETIMESTATS_RESET_CHAR", ns.charKey) end, true)
panel:SetScript("OnShow", function()
local kb = (ns.RecordSize and ns.RecordSize(ns.char) or 0) / 1024
local days = 0
for _ in pairs(ns.char.days) do days = days + 1 end
info:SetText(string.format("%s%d|r statistics · %s%d|r character%s · %s%.0f KB|r for this character · %s%d|r day%s of history",
ns.GOLD, ns.CountStats(), ns.GOLD, ns.CharCount(), ns.CharCount() == 1 and "" or "s", ns.GOLD, kb, ns.GOLD, days, days == 1 and "" or "s"))
for _, r in ipairs(rows) do if r.Sync then r:Sync() end end
themeCyc:Sync(); sw:Show(ThemeId())
end)
if Settings and Settings.RegisterCanvasLayoutCategory then
category = Settings.RegisterCanvasLayoutCategory(panel, "LifeTimeStats")
Settings.RegisterAddOnCategory(category)
elseif InterfaceOptions_AddCategory then
InterfaceOptions_AddCategory(panel)
end
end
function ns.OpenOptions()
if category and Settings and Settings.OpenToCategory then
Settings.OpenToCategory(category:GetID())
elseif InterfaceOptionsFrame_OpenToCategory then
InterfaceOptionsFrame_OpenToCategory(panel)
InterfaceOptionsFrame_OpenToCategory(panel)
end
end