Repository navigation
Expand file tree
/
Copy pathSettingsWindow.lua
More file actions
414 lines (381 loc) · 20.4 KB
/
Copy pathSettingsWindow.lua
File metadata and controls
414 lines (381 loc) · 20.4 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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
-- NodeSight's own pages in the sparkle window's list, above the sparkles: General, the
-- Herb/Ore Switch and Collecting, each in two columns. One window for every setting, and
-- nothing written into the game's Options list (rows changed from addon code there break
-- its dropdowns in combat).
--
-- Sections: Parts, The Switch line, The pages, In the window.
local _, ns = ...
local ipairs, floor, max = ipairs, math.floor, math.max
local refreshing -- the page is being filled in: its sliders' moves aren't changes
---------------------------------------------------------------------------
-- Parts
---------------------------------------------------------------------------
-- Frames are made with no parent, then SetParent (the gamepad UI hooks CreateFrame).
local function New(kind, parent, template)
local frame = CreateFrame(kind, nil, nil, template)
frame:SetParent(parent)
return frame
end
local function Label(parent, text, font)
local label = parent:CreateFontString(nil, "ARTWORK", font or "GameFontNormal")
label:SetText(text)
return label
end
local function Tooltip(frame, title, text)
frame:HookScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(title)
if text then GameTooltip:AddLine(text, 1, 1, 1, true) end
GameTooltip:Show()
end)
frame:HookScript("OnLeave", function() GameTooltip:Hide() end)
end
-- What a setting does when it changes (beyond saving it). The switch reads its other settings each tick.
local AFTER = {
switchFinders = function() ns.SwitchReset() ns.UpdateSwitch() end,
minimapButton = function() if ns.MinimapButtonChanged then ns.MinimapButtonChanged() end end,
collect = function() ns.UpdateCollect() end,
collectMap = function() ns.RefreshNodePins() end,
}
for _, key in ipairs({ "collectMinimap", "collectPicture", "collectShape", "collectSize", "collectOpacity", "collectSkill", "collectOreRings" }) do
AFTER[key] = function() ns.RefreshNodePins() end
end
local function Set(key, value)
if key == "own" then
ns.SetOwnSettings(value)
ns.AskReload()
return ns.RefreshSparkleWindow()
end
ns.db[key] = value
if AFTER[key] then AFTER[key]() end
ns.RefreshSparkleWindow()
end
local COLUMN = 150 -- where a row's control starts, after its label
-- The columns, and how wide their words go. A slider row with its value is about 380 wide,
-- so the right column starts past the left one's widest ("100 % (233 yd)").
local LEFT, RIGHT, WIDE = 16, 400, 340
-- A gold label on the left, a control at COLUMN.
local function Row(text, control, tip)
local label = Label(control, text)
label:SetWidth(COLUMN - 8)
label:SetJustifyH("LEFT")
label:SetPoint("LEFT", control, "LEFT", -COLUMN, 0)
local hover = New("Frame", control)
hover:SetPoint("TOPLEFT", label, "TOPLEFT", 0, 4)
hover:SetPoint("BOTTOMRIGHT", label, "BOTTOMRIGHT", 0, -4)
hover:EnableMouse(true)
Tooltip(hover, text, tip)
control.label, control.hover, control.inRow = label, hover, true
return label
end
-- A checkbox right of its words, as in Blizzard's options; its words click it too.
local function Checkbox(column, key, text, tip)
local box = New("CheckButton", column.page, "MinimalCheckboxTemplate")
box:SetSize(26, 26)
box:SetScript("OnClick", function(self)
PlaySound(self:GetChecked() and SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON or SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF)
Set(key, self:GetChecked() == true)
end)
Row(text, box, tip)
box.hover:SetScript("OnMouseDown", function() box:Click() end)
box.key, box.kind = key, "box"
Tooltip(box, text, tip)
column[#column + 1] = box
return box
end
-- label(value) is the text right of the slider.
local function Slider(column, key, text, low, high, step, tip, label)
local slider = New("Frame", column.page, "MinimalSliderWithSteppersTemplate")
slider:SetWidth(110)
local right = MinimalSliderWithSteppersMixin.Label.Right
slider:Init(low, low, high, (high - low) / step, { [right] = CreateMinimalSliderFormatter(right, label) })
slider:RegisterCallback(MinimalSliderWithSteppersMixin.Event.OnValueChanged, function(_, value)
if not refreshing then Set(key, floor(value / step + 0.5) * step) end
end, slider)
Row(text, slider, tip)
for _, part in ipairs({ slider.Slider, slider.Back, slider.Forward }) do Tooltip(part, text, tip) end
slider.key, slider.kind = key, "slider"
column[#column + 1] = slider
return slider
end
local function Header(column, text)
local header = New("Frame", column.page)
header:SetSize(WIDE, 22)
header.height, header.gap = 30, 4
header.text = Label(header, text, "GameFontNormalLarge")
header.text:SetPoint("LEFT")
local line = header:CreateTexture(nil, "ARTWORK")
line:SetColorTexture(1, 1, 1, 1)
line:SetGradient("HORIZONTAL", CreateColor(1, 0.82, 0, 0.67), CreateColor(1, 0.82, 0, 0)) -- (the logo's gold, fading out)
line:SetHeight(1)
line:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 0, 2)
line:SetPoint("TOPRIGHT", header, "BOTTOMRIGHT", 0, 2)
column[#column + 1] = header
return header
end
-- Places a column's shown parts top to bottom, each part's own gap above it.
local function Stack(column)
local y = column.top
for _, part in ipairs(column) do
if part:IsShown() then
y = y - (part.gap or 0)
part:ClearAllPoints()
if part.tall then -- (rows of boxes: placed by their top)
part:SetPoint("TOPLEFT", column.page, "TOPLEFT", column.x, y)
else
part:SetPoint("LEFT", column.page, "TOPLEFT", part.inRow and column.x + COLUMN or column.x, y - 13)
end
y = y - (part.height or 32)
end
end
end
---------------------------------------------------------------------------
-- The Switch line
---------------------------------------------------------------------------
-- What the switch is doing right now, worked out again twice a second while the page shows.
local FIND = { herbs = 2383, ore = 2580 } -- Find Herbs, Find Minerals
local GREEN, GRAY, RED = "ff80ff80", "ff9d9d9d", "ffff6060"
local function SwitchLine()
local db, switch = ns.db, ns.switch
if not db.switchFinders then return GRAY, "Switch is off." end
if switch.stopped then return RED, "Stopped after an error until you /reload." end
if switch.stoppedUntil and GetTime() < switch.stoppedUntil then
return RED, "Paused for a minute: the last two switches didn't work."
end
local kind = ns.Finders()
if not kind then return GRAY, "Turn on Find Herbs or Find Minerals to start." end
local now = ("Now: %s."):format(C_Spell.GetSpellName(FIND[kind]) or kind)
if not ns.SwitchAllowed() then return GRAY, now .. " Not switching here (Where, Only while mounted)." end
local goal, unit = ns.SwitchGoal()
if not goal then return GREEN, now .. " Open the minimap once to measure the distance." end
local left = max(0, goal - (switch.way or 0))
if unit == "s" then return GREEN, ("%s Next switch after about %d s of moving."):format(now, floor(left + 0.5)) end
return GREEN, ("%s Next switch in about %d yd."):format(now, floor(left + 0.5))
end
---------------------------------------------------------------------------
-- The pages
---------------------------------------------------------------------------
local function Percent(value)
local yards = ns.SwitchDistance(value)
if yards then return ("%d %% (%d yd)"):format(value, floor(yards + 0.5)) end
return ("%d %%"):format(value)
end
local function Yards(value) return ("%d yd"):format(value) end
local function Seconds(value) return ("%d s"):format(value) end
local function YardsOrOff(value) return value == 0 and "Off" or Yards(value) end
local function SecondsOrOff(value) return value == 0 and "Off" or Seconds(value) end
-- General: NodeSight's own settings.
local function GeneralColumns(column, _, page)
-- The page's title alone on top with a gray line under it, then each column headed.
page.about = Label(page, "NodeSight's own settings. The sparkles have their pages below Sparkles.", "GameFontDisableSmall")
page.about:SetPoint("TOPLEFT", LEFT, -38)
column.top = -56
Header(column, "Options")
Checkbox(column, "skillLine", "Required skill in tooltips",
"Shows the skill a herb or ore needs in its tooltip when your mouse is on it in the world, and on herb and ore items.")
Checkbox(column, "popups", "Popups",
"NodeSight's popups: when Enable Interact Key is off, and when the game needs a restart after an update. They wait until a fight is over. Off: none at all.")
Checkbox(column, "minimapButton", "Minimap button",
"NodeSight's button on the minimap: left click opens these settings, Shift left click the sparkles, right click turns all sparkles on or off, Shift right click the Herb/Ore Switch.")
Checkbox(column, "own", "Settings for this character only",
"This character keeps its own NodeSight settings. Untick it to use the settings your other characters share. It offers a reload to switch.")
Checkbox(column, "stoneBackground", "Stone background", "Blizzard's stone texture behind this window, warmed to the logo's brown. Off: plain brown.")
end
-- The Herb/Ore Switch: its line and box over both columns, then When, Switch in and the
-- thanks on the left, Pauses on the right (its header level with When's).
local function SwitchColumns(column, right, page)
page.line = Label(page, "", "GameFontHighlightSmall")
page.line:SetPoint("TOPLEFT", column.x, -38)
page.line:SetWidth(2 * WIDE)
page.line:SetJustifyH("LEFT")
column.top = -50
page.finders = Checkbox(column, "switchFinders", "Switch between herbs and ore",
"Switches between Find Herbs and Find Minerals as you travel. You need both trained and one active to start.")
Header(column, "When")
local measure = New("DropdownButton", page, "WowStyle1DropdownTemplate")
measure:SetWidth(168)
measure:SetupMenu(function(_, root)
for i, name in ipairs(ns.SWITCH_MEASURES) do
root:CreateRadio(name, function() return ns.db.switchMeasure == i end, function() Set("switchMeasure", i) end)
end
end)
Row("Measure distance in", measure,
"How the distance between switches is measured: percent of what your minimap shows (it changes with the zoom), yards, or seconds on the move.")
measure.key, measure.kind = "switchMeasure", "dropdown"
column[#column + 1] = measure
local yards, seconds = ns.SWITCH_RANGES.switchDistanceYards, ns.SWITCH_RANGES.switchSeconds
page.percent = Slider(column, "switchPercent", "Distance", 20, 100, 5,
"How far you go between switches, in percent of what your minimap shows: farther when zoomed out or outdoors.", Percent)
page.yards = Slider(column, "switchDistanceYards", "Distance", yards[1], yards[2], yards[3],
"How far you go between switches, in yards.", Yards)
page.seconds = Slider(column, "switchSeconds", "Time", seconds[1], seconds[2], seconds[3],
"How long you move between switches, in seconds. Time standing still doesn't count.", Seconds)
Checkbox(column, "switchMounted", "Only while mounted", "Switches only while you ride a mount. Travel Form and Ghost Wolf don't count.")
Header(column, "Switch in")
local where = New("Frame", page)
where:SetSize(WIDE, 64)
where.height, where.parts = 70, { page = where }
for i, area in ipairs({ { "switchWorld", "Open world", "the open world" }, { "switchDungeons", "Dungeons", "a dungeon" },
{ "switchRaids", "Raids", "a raid" }, { "switchBattlegrounds", "Battlegrounds", "a battleground" } }) do
local box = Checkbox(where.parts, area[1], area[2], ("Switches while you're in %s."):format(area[3]))
-- Two to a row: each name with its box right after it.
box.label:SetWidth(100)
box.label:ClearAllPoints()
box.label:SetPoint("LEFT", box, "LEFT", -104, 0)
box:SetPoint("TOPLEFT", where, "TOPLEFT", (i - 1) % 2 * 170 + 104, -floor((i - 1) / 2) * 32)
end
where.boxes, where.tall = where.parts, true
column[#column + 1] = where
local thanks = Label(page, "Thanks to tester617 for the Switch page", "GameFontDisableSmall")
thanks.gap, thanks.height = 4, 20
column[#column + 1] = thanks
column = right
column.top = -82 -- (under the box)
Header(column, "Pauses")
Checkbox(column, "switchPauseBusy", "Pause while casting, looting or with something on the cursor",
"Switching pauses while you cast, gather or loot, and while a spell waits for a target or something is on your cursor.").height = 42
Slider(column, "switchEnemyYards", "Enemy targeted within", 0, 60, 1,
"Switching pauses while you target a living enemy this close, and for a second after you mouse over one. Distances are rough: the game doesn't give exact ones.", YardsOrOff)
Checkbox(column, "switchPauseStealth", "Pause while stealthed", "Switching pauses while you're stealthed.")
Slider(column, "switchAfterCast", "After your own spells", 0, 10, 1,
"Switching pauses this long after your own spells end, and after you dismount, so the switch's global cooldown doesn't get in your way.", SecondsOrOff)
-- The line, twice a second while the page shows.
local elapsed = 0
page:SetScript("OnUpdate", function(_, dt)
elapsed = elapsed + dt
if elapsed < 0.5 then return end
elapsed = 0
local color, text = SwitchLine()
page.line:SetText(("|c%s%s|r"):format(color, text))
end)
end
-- A dropdown of choices (their words, in order) saved as the choice's number.
local function Dropdown(column, key, text, choices, tip)
local dropdown = New("DropdownButton", column.page, "WowStyle1DropdownTemplate")
dropdown:SetWidth(168)
dropdown:SetupMenu(function(_, root)
for i, name in ipairs(choices) do
root:CreateRadio(name, function() return ns.db[key] == i end, function() Set(key, i) end)
end
end)
Row(text, dropdown, tip)
dropdown.key, dropdown.kind = key, "dropdown"
column[#column + 1] = dropdown
return dropdown
end
local function Percent100(value) return ("%d %%"):format(value) end
local function Whole(value) return ("%d"):format(value) end
-- Collecting: its boxes and the map symbols' look on the left, the places remembered and
-- Forget all on the right.
local function CollectColumns(column, places, page)
page.about = Label(page, "Remembers where you gather herbs and ore and marks the places on your world map.", "GameFontDisableSmall")
page.about:SetPoint("TOPLEFT", LEFT, -38)
page.about:SetWidth(2 * WIDE)
page.about:SetJustifyH("LEFT")
column.top, places.top = -56, -56
Header(column, "Collecting")
Checkbox(column, "collect", "Remember where I gather",
"Remembers each place you gather a herb or ore. Off: nothing new is remembered and the world map shows no marks; the places remembered are kept.")
Checkbox(column, "collectMap", "World map marks",
"A small herb or ore symbol on the world map for each place you gathered at. Put your mouse on one to see what it was.")
Checkbox(column, "collectMinimap", "Minimap marks",
"The same symbols on the minimap for the places near you. They let the mouse through to the game's own dots.")
Header(column, "Symbols")
local size, opacity = ns.COLLECT_RANGES.collectSize, ns.COLLECT_RANGES.collectOpacity
Dropdown(column, "collectPicture", "Picture", ns.COLLECT_PICTURES,
"Each node's own item icon, or one plain icon for herbs and one for ore.")
Dropdown(column, "collectShape", "Shape", ns.COLLECT_SHAPES, "The symbols' shape, on the world map and the minimap.")
Slider(column, "collectSize", "Size", size[1], size[2], size[3], "How big the symbols are, on the world map and the minimap.", Whole)
Slider(column, "collectOpacity", "Minimap opacity", opacity[1], opacity[2], opacity[3],
"How much of a minimap symbol shows. Lower lets the game's dot under it show through. On the world map they're solid.", Percent100)
Dropdown(column, "collectSkill", "Skill colors", ns.COLLECT_SKILL_LOOKS,
"How a symbol shows your skill. Red when too low: red if you can't gather it yet. Colored ring and Colored gem: the profession window's skill-up colors, from red to gray. Colored ring needs a gold ring shape.")
Checkbox(column, "collectOreRings", "High visibility tin and iron",
"Tin gets a green ring and iron a rust one, so they're easy to tell apart. Needs a gold ring shape.")
local future = Label(page, "Collecting is new and will be improved in future updates.", "GameFontDisableSmall")
future.gap, future.height = 4, 20
column[#column + 1] = future
local thanks = Label(page, "Thanks to Urfoks for Collecting", "GameFontDisableSmall")
thanks.gap, thanks.height = 4, 20
column[#column + 1] = thanks
Header(places, "Remembered places")
page.count = Label(page, "", "GameFontHighlight")
page.count.height = 28
places[#places + 1] = page.count
page.forget = New("Button", page, "UIPanelButtonTemplate")
page.forget:SetSize(128, 22)
page.forget:SetText("Forget all")
page.forget:SetScript("OnClick", function() ns.AskForget() end)
Tooltip(page.forget, "Forget all", "Forgets every place NodeSight remembered, for all your characters. It asks first.")
places[#places + 1] = page.forget
end
-- A page's title and its two columns, filled by fill(left, right, page).
local function Page(page, title, fill)
local left = { page = page, x = LEFT, top = -50 }
local right = { page = page, x = RIGHT, top = -50 }
page.title = Label(page, title, "GameFontHighlightLarge")
page.title:SetPoint("TOPLEFT", LEFT, -14)
fill(left, right, page)
page.columns, page.parts = { left, right }, {}
for _, column in ipairs(page.columns) do
for _, part in ipairs(column) do page.parts[#page.parts + 1] = part end
end
end
local function BuildGeneral(page) Page(page, GENERAL, GeneralColumns) end
local function BuildCollect(page) Page(page, "Collecting (Beta)", CollectColumns) end
local function BuildSwitch(page)
Page(page, "Herb/Ore Switch", SwitchColumns)
for _, part in ipairs(page.parts) do
if part ~= page.finders then part.switch = true end
end
end
---------------------------------------------------------------------------
-- In the window
---------------------------------------------------------------------------
local function RefreshPart(part)
local key = part.key
if not key then return end
if part.kind == "box" then
part:SetChecked(key == "own" and ns.OwnSettings() or ns.db[key] == true)
elseif part.kind == "slider" then
part:SetValue(ns.db[key])
elseif part.kind == "dropdown" then
part:GenerateMenu()
end
end
local function Refresh(page)
refreshing = true
for _, part in ipairs(page.parts) do
RefreshPart(part)
for _, box in ipairs(part.boxes or {}) do RefreshPart(box) end
end
-- The Switch: everything under its box only while it's on, and one distance slider.
if page.line then
local on = ns.db.switchFinders == true
for _, part in ipairs(page.parts) do
if part.switch then part:SetShown(on) end
end
local measure = ns.db.switchMeasure
for i, slider in ipairs({ page.percent, page.yards, page.seconds }) do slider:SetShown(on and measure == i) end
local color, text = SwitchLine()
page.line:SetText(("|c%s%s|r"):format(color, text))
end
if page.count then
local all, herbs, ore = ns.NodeCount()
page.count:SetText(("%d herbs, %d ore"):format(herbs, ore))
page.forget:SetEnabled(all > 0)
end
for _, column in ipairs(page.columns) do Stack(column) end
refreshing = false
end
ns.WINDOW_PAGES = {
{ key = "nodesight", name = GENERAL, build = BuildGeneral, refresh = Refresh },
{ key = "switch", name = "Herb/Ore Switch", build = BuildSwitch, refresh = Refresh },
{ key = "collect", name = "Collecting (Beta)", build = BuildCollect, refresh = Refresh },
}
ns.WindowSet = Set -- what the page's controls do, by key
function ns.ShowSettingsWindow() ns.ShowSparkleWindow("nodesight") end
-- The window is open on NodeSight's own page.
function ns.SettingsWindowShown() return ns.SparkleWindowShown() and ns.SparkleWindowPage() == "nodesight" end
function ns.HideSettingsWindow() ns.HideSparkleWindow() end
function ns.RefreshSettingsWindow() ns.RefreshSparkleWindow() end