Repository navigation
Expand file tree
/
Copy pathUI_HUD.lua
More file actions
753 lines (668 loc) · 29.6 KB
/
Copy pathUI_HUD.lua
File metadata and controls
753 lines (668 loc) · 29.6 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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
--[[---------------------------------------------------------------------------
Solaryn's Expedition — route tracker (on-screen HUD).
A compact, always-on-screen view of the guide, in the spirit of the
client's objective tracker:
[map] ROUTE 3/8 [rebuild][shelve][>>][x][-]
====------------------------------- (progress strip)
| (arrow) Kobold Camp Cleanup 220 yd |
| Elwynn Forest |
| * Kobold Vermin: 4/8 |
UP NEXT ------------------------------------------------
* 4. A Threat Within · Hand in 410 yd
* 5. Westfall Plots 1.2 mi
The header drags it (unless locked) and opens the panel on click. The
arrow points at the current stop relative to the way you're facing. It
can only do that while you and the stop are on the same map, because map
coordinates are the one space where "north" is certain.
Rebuilt on route/quest events; distance and arrow refresh on a light
ticker while shown.
-----------------------------------------------------------------------------]]
local ADDON_NAME = ...
local ns = _G.SolarynExpedition
ns.HUD = {}
local HUD = ns.HUD
local Widgets = ns.Widgets
local Theme = Widgets.Theme
local WIDTH = 268
local HEADER_H = 24 -- header bar
local STRIP_H = 2 -- progress strip under it
local OBJ_LINE_H = 14
local ROW_H = 18
local MAX_OBJECTIVE_LINES = 4
local MAX_UPCOMING = 6
local TICK = 0.2
HUD.HEADER_H = HEADER_H + STRIP_H -- height when collapsed
-- Key Bindings > AddOns: "Use quest item" clicks the first item button.
_G.BINDING_HEADER_SOLARYNEXPEDITION = "Solaryn's Expedition"
_G["BINDING_NAME_CLICK SolarynExpeditionQuestItemButton1:LeftButton"] = "Use quest item (guided quest)"
local MAX_ITEM_BUTTONS = 3
local itemButtons = {}
local itemsPending = false -- an update waiting for combat to end
local frame, header, body
local titleText, countText, skipButton, stopButton, collapseButton, rebuildButton
local shelveButton, restoreButton
local arrow, stopTitle, stopWhere, distText, objectiveLines = nil, nil, nil, nil, {}
local upcomingRows = {}
local currentBlock, startButton, accentBar, upNext, progress, bodyBg, headerBg
local built = false
local function S() return ns.Settings() end
local function dimColor(fs)
fs:SetTextColor(ns.Colors.dim.r, ns.Colors.dim.g, ns.Colors.dim.b)
end
---------------------------------------------------------------------------
-- Direction
---------------------------------------------------------------------------
--- Angle (radians, counter-clockwise from straight ahead) from the player to
--- a stop, or nil when it can't be known. Map coordinates run east (+x) and
--- south (+y); GetPlayerFacing is 0 for north, increasing counter-clockwise,
--- so the bearing to (dx, dy) is atan2(-dx, -dy).
function HUD.RelativeAngle(stop)
if not stop or not stop.uiMapID or not stop.x then return nil end
if type(_G.GetPlayerFacing) ~= "function" then return nil end
local facing = ns.SafeNum(_G.GetPlayerFacing())
if not facing then return nil end
local pos = ns:PlayerPosition(stop.uiMapID)
if not pos then return nil end
local dx, dy = stop.x - pos.x, stop.y - pos.y
-- Maps aren't square in yards; scale so the angle is true on the ground.
if ns.Has.mapWorldSize then
local w, h = ns.Try("C_Map", "GetMapWorldSize", stop.uiMapID)
w, h = ns.SafeNum(w), ns.SafeNum(h)
if w and h and w > 0 and h > 0 then dx, dy = dx * w, dy * h end
end
if dx == 0 and dy == 0 then return 0 end
return math.atan2(-dx, -dy) - facing
end
---------------------------------------------------------------------------
-- Construction
---------------------------------------------------------------------------
local ICONS = {
collapse = "Interface\\Buttons\\UI-MinusButton-Up",
expand = "Interface\\Buttons\\UI-PlusButton-Up",
stop = "Interface\\Buttons\\UI-GroupLoot-Pass-Up",
skip = "Interface\\Buttons\\UI-SpellbookIcon-NextPage-Up",
shelve = "Interface\\Icons\\INV_Misc_Bag_08",
restore = "Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up",
rebuild = "Interface\\Buttons\\UI-RefreshButton",
map = "Interface\\Icons\\INV_Misc_Map_01",
disc = "Interface\\CHARACTERFRAME\\TempPortraitAlphaMask",
}
--- A 16px header button showing a stock icon, dimmed until hovered.
local function smallButton(parent, texture, tip, onClick, crop)
local b = CreateFrame("Button", nil, parent)
b:SetSize(16, 16)
local icon = b:CreateTexture(nil, "ARTWORK")
icon:SetSize(crop and 12 or 15, crop and 12 or 15)
icon:SetPoint("CENTER")
icon:SetTexture(texture)
if crop then icon:SetTexCoord(0.1, 0.9, 0.1, 0.9) end
icon:SetVertexColor(0.85, 0.78, 0.62)
b.icon = icon
local hl = b:CreateTexture(nil, "HIGHLIGHT")
hl:SetAllPoints()
hl:SetColorTexture(1, 0.85, 0.45, 0.18)
b:SetScript("OnClick", onClick)
Widgets:TooltipLines(b, tip, {})
return b
end
local function buildUpcomingRow(i)
local row = CreateFrame("Button", nil, body)
row:SetHeight(ROW_H)
row:RegisterForClicks("LeftButtonUp")
row.alt = Widgets:Fill(row, "BACKGROUND", Theme.rowAlt)
row.alt:SetAllPoints()
local hl = Widgets:Fill(row, "HIGHLIGHT", Theme.rowHover)
hl:SetAllPoints()
row.dot = Widgets:Fill(row, "ARTWORK", 1, 1, 1, 1)
row.dot:SetSize(5, 5)
row.dot:SetPoint("LEFT", 12, 0)
row.dist = Widgets:Line(row, "", "GameFontHighlightSmall", "RIGHT")
row.dist:SetPoint("RIGHT", -8, 0)
row.dist:SetWidth(56)
dimColor(row.dist)
row.text = Widgets:Line(row, "", "GameFontHighlightSmall")
row.text:SetPoint("LEFT", 24, 0)
row.text:SetPoint("RIGHT", row.dist, "LEFT", -4, 0)
row:SetScript("OnClick", function(self)
if IsShiftKeyDown() and self.stop and self.stop.questID then
ns.Route:Shelve(self.stop.questID)
elseif self.index then
ns.Route:Guide(self.index)
end
end)
row:SetScript("OnEnter", function(self)
local st = self.stop
if not st then return end
Widgets:ShowTooltip(self, st.title or "?", {
st.kind == "turnin" and "Hand in" or "Objective",
ns:MapName(st.uiMapID),
"",
"Click: guide from this stop",
"Shift-click: shelve this quest",
})
end)
row:SetScript("OnLeave", function() GameTooltip:Hide() end)
row:Hide()
upcomingRows[i] = row
return row
end
local function buildObjectiveLine(i)
local fs = Widgets:Line(currentBlock, "", "GameFontHighlightSmall")
fs:SetPoint("TOPLEFT", stopWhere, "BOTTOMLEFT", 9, -4 - (i - 1) * OBJ_LINE_H)
fs:SetPoint("TOPRIGHT", currentBlock, "TOPRIGHT", -8, -4 - (i - 1) * OBJ_LINE_H)
fs:Hide()
-- (anchored to the where-line, which never moves)
local bullet = Widgets:Fill(currentBlock, "ARTWORK", 1, 1, 1, 1)
bullet:SetSize(4, 4)
bullet:SetPoint("RIGHT", fs, "LEFT", -5, 0)
bullet:Hide()
fs.bullet = bullet
objectiveLines[i] = fs
return fs
end
local function build()
frame = CreateFrame("Frame", "SolarynExpeditionHUD", UIParent)
frame:SetSize(WIDTH, 60)
frame:SetFrameStrata("LOW")
frame:SetClampedToScreen(true)
frame:SetMovable(true)
frame:Hide()
Widgets.RestorePosition(frame, "hudPoint", { "RIGHT", -60, 120 })
local hb = Theme.hudBg
bodyBg = Widgets:Chrome(frame, { bg = { hb[1], hb[2], hb[3], 0.75 }, hairline = false, bracketSize = 7 })
-- Header: drag handle, click to open the panel.
header = CreateFrame("Button", nil, frame)
header:SetPoint("TOPLEFT", 1, -1)
header:SetPoint("TOPRIGHT", -1, -1)
header:SetHeight(HEADER_H - 1)
header:RegisterForDrag("LeftButton")
header:RegisterForClicks("LeftButtonUp")
header:SetScript("OnDragStart", function()
if not S().hudLocked then frame:StartMoving() end
end)
header:SetScript("OnDragStop", function()
frame:StopMovingOrSizing()
Widgets.SavePosition(frame, "hudPoint")
HUD:UpdateItems() -- move the item buttons along
end)
header:SetScript("OnClick", function() ns.Panel:Toggle(true); ns.Panel:SetTab("route") end)
Widgets:TooltipLines(header, "Route tracker", {
"Click: open the Route tab",
"Drag: move (lock it in options)",
})
headerBg = Widgets:Fill(header, "BACKGROUND", Theme.titleBg)
headerBg:SetAllPoints()
local sheen = Widgets:Fill(header, "BORDER", Theme.titleSheen)
sheen:SetPoint("TOPLEFT", 0, 0)
sheen:SetPoint("TOPRIGHT", 0, 0)
sheen:SetHeight(math.floor(HEADER_H / 2))
local mapIcon = header:CreateTexture(nil, "ARTWORK")
mapIcon:SetSize(14, 14)
mapIcon:SetPoint("LEFT", 6, 0)
mapIcon:SetTexture(ICONS.map)
mapIcon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
collapseButton = smallButton(header, ICONS.collapse, "Collapse / expand", function()
S().hudCollapsed = not S().hudCollapsed
HUD:Refresh()
end)
collapseButton:SetPoint("RIGHT", -4, 0)
stopButton = smallButton(header, ICONS.stop, "Stop guiding", function() ns.Route:StopGuiding() end)
stopButton:SetPoint("RIGHT", collapseButton, "LEFT", -1, 0)
skipButton = smallButton(header, ICONS.skip, "Skip this stop", function() ns.Route:Advance("skipped") end)
skipButton:SetPoint("RIGHT", stopButton, "LEFT", -1, 0)
-- Shelve the current stop's quest (kept off the route until restored).
shelveButton = smallButton(header, ICONS.shelve, "Shelve this quest", function()
local st = ns.Route:Next()
if st and st.questID then ns.Route:Shelve(st.questID) end
end, true)
Widgets:TooltipLines(shelveButton, "Shelve this quest",
{ "Leave it off the route until you restore it.", "Remembered across reloads." })
shelveButton:SetPoint("RIGHT", skipButton, "LEFT", -1, 0)
-- Only shown while something is shelved: puts everything back.
restoreButton = smallButton(header, ICONS.restore, "Restore shelved quests", function()
ns.Route:UnshelveAll()
end)
restoreButton:SetScript("OnEnter", function(self)
local lines = {}
for _, e in ipairs(ns.Route:ShelvedList()) do table.insert(lines, e.title) end
table.insert(lines, "")
table.insert(lines, "Click: put them all back on the route")
Widgets:ShowTooltip(self, "Shelved quests", lines)
end)
restoreButton:SetPoint("RIGHT", shelveButton, "LEFT", -1, 0)
-- Rebuild on demand (the route also rebuilds itself on quest changes).
rebuildButton = smallButton(header, ICONS.rebuild, "Rebuild route", function() HUD:RebuildRoute() end)
Widgets:TooltipLines(rebuildButton, "Rebuild route",
{ "Re-plan the remaining stops from where you are.", "Stops you've finished stay done." })
rebuildButton:SetPoint("RIGHT", restoreButton, "LEFT", -1, 0)
titleText = Widgets:Line(header, "ROUTE", "GameFontNormalSmall")
titleText:SetPoint("LEFT", mapIcon, "RIGHT", 5, 0)
countText = Widgets:Line(header, "", "GameFontHighlightSmall")
countText:SetPoint("LEFT", titleText, "RIGHT", 6, 0)
dimColor(countText)
-- How far along the route you are: a thin gold strip under the header.
progress = Widgets:ProgressBar(frame, STRIP_H, ns.Colors.accent)
progress:SetPoint("TOPLEFT", 1, -HEADER_H)
progress:SetPoint("TOPRIGHT", -1, -HEADER_H)
body = CreateFrame("Frame", nil, frame)
body:SetPoint("TOPLEFT", 0, -(HEADER_H + STRIP_H))
body:SetPoint("TOPRIGHT", 0, -(HEADER_H + STRIP_H))
body:SetHeight(40)
-- Current stop: a card with the arrow on a dark disc, the distance on
-- the right and the objectives underneath. Click to re-point the waypoint.
currentBlock = CreateFrame("Button", nil, body)
currentBlock:SetPoint("TOPLEFT", 6, -6)
currentBlock:SetPoint("TOPRIGHT", -6, -6)
currentBlock:RegisterForClicks("LeftButtonUp")
currentBlock:SetScript("OnClick", function()
local st = ns.Route:Next()
if st then ns.Route:SetWaypointTo(st) end
end)
Widgets:TooltipLines(currentBlock, "Current stop", { "Click: set the waypoint here again" })
local cardBg = Widgets:Fill(currentBlock, "BACKGROUND", 1, 0.9, 0.7, 0.04)
cardBg:SetAllPoints()
Widgets:Border(currentBlock, Theme.cardEdge, 0, "BORDER")
accentBar = Widgets:Fill(currentBlock, "ARTWORK", 1, 1, 1, 1)
accentBar:SetWidth(2)
accentBar:SetPoint("TOPLEFT", 0, 0)
accentBar:SetPoint("BOTTOMLEFT", 0, 0)
local chl = Widgets:Fill(currentBlock, "HIGHLIGHT", Theme.rowHover)
chl:SetAllPoints()
local disc = currentBlock:CreateTexture(nil, "ARTWORK")
disc:SetSize(32, 32)
disc:SetPoint("TOPLEFT", 8, -6)
disc:SetTexture(ICONS.disc)
disc:SetVertexColor(0, 0, 0, 0.6)
arrow = currentBlock:CreateTexture(nil, "OVERLAY")
arrow:SetSize(26, 26)
arrow:SetPoint("CENTER", disc, "CENTER", 0, 0)
arrow:SetTexture("Interface\\Minimap\\MinimapArrow")
distText = Widgets:Line(currentBlock, "", "GameFontHighlight", "RIGHT")
distText:SetPoint("TOPRIGHT", -8, -7)
distText:SetWidth(72)
stopTitle = Widgets:Line(currentBlock, "", "GameFontNormal")
stopTitle:SetPoint("TOPLEFT", 48, -7)
stopTitle:SetPoint("RIGHT", distText, "LEFT", -4, 0)
stopWhere = Widgets:Line(currentBlock, "", "GameFontHighlightSmall")
stopWhere:SetPoint("TOPLEFT", stopTitle, "BOTTOMLEFT", 0, -2)
stopWhere:SetPoint("TOPRIGHT", currentBlock, "TOPRIGHT", -8, -23)
dimColor(stopWhere)
for i = 1, MAX_OBJECTIVE_LINES do buildObjectiveLine(i) end
-- "Up next" heading over the upcoming stops.
upNext = Widgets:Line(body, "UP NEXT", "GameFontDisableSmall")
local upRule = Widgets:Fill(body, "ARTWORK", Theme.divider)
upRule:SetHeight(1)
upRule:SetPoint("LEFT", upNext, "RIGHT", 6, 0)
upRule:SetPoint("RIGHT", body, "RIGHT", -8, 0)
upNext.rule = upRule
for i = 1, MAX_UPCOMING do buildUpcomingRow(i) end
-- Shown when a route exists but the guide isn't running (hudAlways).
startButton = Widgets:Button(body, "Start guide", 120, 22, function() ns.Route:Guide() end, "primary")
startButton:SetPoint("TOP", 0, -8)
startButton:Hide()
-- Live distance and arrow.
local elapsedSince = 0
frame:SetScript("OnUpdate", function(_, elapsed)
elapsedSince = elapsedSince + (elapsed or 0)
if elapsedSince < TICK then return end
elapsedSince = 0
HUD:UpdateLive()
end)
built = true
end
---------------------------------------------------------------------------
-- Quest item buttons
---------------------------------------------------------------------------
-- Using an item is a protected action, so these are SecureActionButtons:
-- their item, visibility and position can only change out of combat. They
-- are parented to UIParent (not the tracker) so the tracker itself never
-- becomes protected and can still update during fights; they're placed
-- beside it by screen coordinates instead of being anchored to it.
local function inCombat()
return type(_G.InCombatLockdown) == "function" and _G.InCombatLockdown()
end
local function itemIcon(itemID)
local ci = _G.C_Item
if type(ci) == "table" and type(ci.GetItemIconByID) == "function" then return ci.GetItemIconByID(itemID) end
if type(_G.GetItemIcon) == "function" then return _G.GetItemIcon(itemID) end
return "Interface\\Icons\\INV_Misc_QuestionMark"
end
local function itemCount(itemID)
local ci = _G.C_Item
if type(ci) == "table" and type(ci.GetItemCount) == "function" then return ci.GetItemCount(itemID) end
return type(_G.GetItemCount) == "function" and _G.GetItemCount(itemID) or 0
end
local function itemCooldown(itemID)
local cc = _G.C_Container
if type(cc) == "table" and type(cc.GetItemCooldown) == "function" then return cc.GetItemCooldown(itemID) end
if type(_G.GetItemCooldown) == "function" then return _G.GetItemCooldown(itemID) end
end
local function buildItemButton(i)
local size = i == 1 and 36 or 30
local b = CreateFrame("Button", "SolarynExpeditionQuestItemButton" .. i, UIParent, "SecureActionButtonTemplate")
b:SetSize(size, size)
b:SetFrameStrata("MEDIUM")
-- Secure buttons act on key-down or key-up depending on this CVar;
-- registering only the matching one makes clicks and keybinds work
-- (and never fire twice) on old and new clients alike.
local down = type(_G.GetCVarBool) == "function" and _G.GetCVarBool("ActionButtonUseKeyDown")
b:RegisterForClicks(down and "AnyDown" or "AnyUp")
b:SetAttribute("type", "item")
local border = Widgets:Fill(b, "BACKGROUND", 0, 0, 0, 0.9)
border:SetPoint("TOPLEFT", -1, 1)
border:SetPoint("BOTTOMRIGHT", 1, -1)
b.icon = b:CreateTexture(nil, "ARTWORK")
b.icon:SetAllPoints()
b.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
local hl = b:CreateTexture(nil, "HIGHLIGHT")
hl:SetAllPoints()
hl:SetColorTexture(1, 1, 1, 0.2)
b.count = Widgets:Text(b, "", "NumberFontNormal", "RIGHT")
b.count:SetPoint("BOTTOMRIGHT", -2, 2)
b.hotkey = Widgets:Text(b, "", "NumberFontNormalSmallGray", "RIGHT")
b.hotkey:SetPoint("TOPRIGHT", -2, -2)
b.cooldown = CreateFrame("Cooldown", nil, b, "CooldownFrameTemplate")
b.cooldown:SetAllPoints()
b:SetScript("OnEnter", function(self)
if not self.itemID then return end
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
if GameTooltip.SetItemByID then
GameTooltip:SetItemByID(self.itemID)
elseif GameTooltip.SetHyperlink then
GameTooltip:SetHyperlink("item:" .. self.itemID)
end
if self.questTitle then
GameTooltip:AddLine("For: " .. self.questTitle, ns.Colors.accent.r, ns.Colors.accent.g, ns.Colors.accent.b)
end
GameTooltip:Show()
end)
b:SetScript("OnLeave", function() GameTooltip:Hide() end)
b:Hide()
itemButtons[i] = b
return b
end
--- Cooldowns and counts can update any time, even in combat.
local function updateItemCooldowns()
for _, b in ipairs(itemButtons) do
if b.itemID and b:IsShown() then
local n = itemCount(b.itemID) or 0
b.count:SetText(n > 1 and tostring(n) or "")
local start, duration, enable = itemCooldown(b.itemID)
if start and duration and b.cooldown.SetCooldown then
b.cooldown:SetCooldown(start, duration, enable)
end
end
end
end
--- Items for the guided quests: the current stop's quest first, then the
--- upcoming ones shown in the tracker, one button per distinct item.
local function wantedItems()
local out, seenItem, seenQuest = {}, {}, {}
if not frame or not frame:IsShown() or not S().questItemButtons then return out end
local state = ns.Route:Get()
if not state.guiding then return out end
local stops = state.stops or {}
local bag = ns.QuestData:BagQuestItems()
local last = math.min(#stops, (state.current or 1) + (ns.SafeNum(S().hudUpcoming) or 3))
for i = state.current or 1, last do
local st = stops[i]
if st and st.questID and not seenQuest[st.questID] then
seenQuest[st.questID] = true
local it = ns.QuestData:QuestItem(st.questID, bag)
if it and not seenItem[it.itemID] and itemCount(it.itemID) ~= 0 then
seenItem[it.itemID] = true
it.questTitle = st.title
table.insert(out, it)
if #out >= MAX_ITEM_BUTTONS then break end
end
end
end
return out
end
--- Point the item buttons at the right items and park them left of the
--- tracker. Deferred until combat ends when called during combat.
function HUD:UpdateItems()
if not built then return end
if inCombat() then
itemsPending = true
updateItemCooldowns()
return
end
itemsPending = false
local items = wantedItems()
-- Screen position of the tracker's top-left, in UIParent units.
local left, top = frame:GetLeft(), frame:GetTop()
local scale = (frame:GetEffectiveScale() or 1) / (UIParent:GetEffectiveScale() or 1)
local y = (top or 0) * scale
for i = 1, MAX_ITEM_BUTTONS do
local b = itemButtons[i] or buildItemButton(i)
local it = items[i]
if it and left and top then
b.itemID, b.questTitle = it.itemID, it.questTitle
b:SetAttribute("item", "item:" .. it.itemID)
b.icon:SetTexture(itemIcon(it.itemID))
local key = i == 1 and type(_G.GetBindingKey) == "function"
and _G.GetBindingKey("CLICK SolarynExpeditionQuestItemButton1:LeftButton")
b.hotkey:SetText(key or "")
b:ClearAllPoints()
b:SetPoint("TOPRIGHT", UIParent, "BOTTOMLEFT", left * scale - 6, y)
y = y - b:GetHeight() - 6
b:Show()
else
b.itemID, b.questTitle = nil, nil
b:SetAttribute("item", nil)
b:Hide()
end
end
updateItemCooldowns()
end
function HUD:GetItemButton(i) return itemButtons[i] end
---------------------------------------------------------------------------
-- Rendering
---------------------------------------------------------------------------
--- Should the tracker be on screen right now?
function HUD:ShouldShow()
local s = S()
if not s.hud then return false end
local state = ns.Route:Get()
local stops = state.stops or {}
if #stops == 0 or (state.current or 1) > #stops then return false end
return state.guiding and true or (s.hudAlways and true or false)
end
--- Distance text and arrow for the current stop (cheap; runs on the ticker).
function HUD:UpdateLive()
if not built or not frame:IsShown() then return end
local stop = ns.Route:IsGuiding() and ns.Route:Next()
if not stop then return end
local d = ns.Route:DistanceTo(stop)
local where = ns:MapName(stop.uiMapID)
local radius = tonumber(ns.Settings().areaRadius) or 0
local inArea = stop.area and d and radius > 0 and d <= radius
if inArea then
stopWhere:SetText(where .. " · " .. Widgets.Colorize("in the area", ns.Colors.accent))
distText:SetText(Widgets.Colorize("here", ns.Colors.good))
else
stopWhere:SetText(where)
distText:SetText(d and ns:FormatDistance(d) or "")
end
local angle = not inArea and HUD.RelativeAngle(stop) or nil
if angle then
arrow:SetRotation(angle)
arrow:SetVertexColor(1, 0.86, 0.40, 1)
arrow:Show()
else
-- Different map, or already in the search area: no useful direction.
arrow:SetRotation(0)
arrow:SetVertexColor(0.5, 0.5, 0.5, 0.5)
end
for _, row in ipairs(upcomingRows) do
if row:IsShown() and row.stop then
local ud = ns.Route:DistanceTo(row.stop)
row.dist:SetText(ud and ns:FormatDistance(ud) or "")
end
end
end
--- What to show under the current stop: list of { text, colour }.
local function objectiveTexts(stop)
if stop.kind == "turnin" then
return { { text = Widgets.Colorize("Hand in" .. (stop.npcName and (" to " .. stop.npcName) or " this quest"),
ns.Colors.turnin), color = ns.Colors.turnin } }
end
local out = {}
for _, o in ipairs(ns.QuestData:PendingObjectives(stop.questID)) do
local text = o.text or ""
if not text:find("%d+/%d+") and (o.numRequired or 0) > 1 then
text = string.format("%s: %d/%d", text, o.numFulfilled or 0, o.numRequired)
end
table.insert(out, { text = text, color = ns.Colors.quest })
end
if #out == 0 then table.insert(out, { text = "In progress", color = ns.Colors.dim }) end
return out
end
--- Background opacity from settings, applied to the body and header.
local function applyOpacity(s)
local a = math.max(0, math.min(1, ns.SafeNum(s.hudOpacity) or 0.75))
local hb, tb = Theme.hudBg, Theme.titleBg
bodyBg:SetColorTexture(hb[1], hb[2], hb[3], a)
headerBg:SetColorTexture(tb[1], tb[2], tb[3], math.min(1, a + 0.15))
end
function HUD:Refresh()
if not built then return end
if not self:ShouldShow() then
frame:Hide()
self:UpdateItems()
return
end
local s = S()
frame:SetScale(math.max(0.5, math.min(2, ns.SafeNum(s.hudScale) or 1)))
applyOpacity(s)
local state = ns.Route:Get()
local stops = state.stops or {}
local cur = math.min(state.current or 1, #stops)
local guiding = state.guiding and true or false
countText:SetText(string.format("%d/%d", cur, #stops))
titleText:SetText(guiding and "ROUTE" or "ROUTE " .. Widgets.Colorize("paused", ns.Colors.dim))
progress:SetValue(#stops > 0 and (cur - 1) / #stops or 0)
if guiding then skipButton:Show(); stopButton:Show() else skipButton:Hide(); stopButton:Hide() end
if #stops > 0 then shelveButton:Show() else shelveButton:Hide() end
if #ns.Route:ShelvedList() > 0 then restoreButton:Show() else restoreButton:Hide() end
collapseButton.icon:SetTexture(s.hudCollapsed and ICONS.expand or ICONS.collapse)
local height = HUD.HEADER_H
if s.hudCollapsed then
body:Hide()
else
body:Show()
local y = 6
if guiding then
startButton:Hide()
currentBlock:Show()
local stop = stops[cur]
local c = stop.kind == "turnin" and ns.Colors.turnin or ns.Colors.quest
stopTitle:SetText(stop.title or ("Quest " .. tostring(stop.questID)))
stopTitle:SetTextColor(ns.Colors.accent.r, ns.Colors.accent.g, ns.Colors.accent.b)
accentBar:SetColorTexture(c.r, c.g, c.b, 1)
local texts = objectiveTexts(stop)
local caution = stop.kind ~= "turnin" and ns.CautionText(stop.questLevel)
if caution then table.insert(texts, 1, { text = caution, color = ns.Colors.warn }) end
for i, fs in ipairs(objectiveLines) do
local t = texts[i]
if t then
fs:SetText(t.text); fs:Show()
fs.bullet:SetColorTexture(t.color.r, t.color.g, t.color.b, 1); fs.bullet:Show()
else
fs:Hide(); fs.bullet:Hide()
end
end
local lines = math.min(#texts, MAX_OBJECTIVE_LINES)
local blockH = math.max(44, 7 + 14 + 2 + 12 + 4 + lines * OBJ_LINE_H + 6)
currentBlock:SetHeight(blockH)
y = y + blockH + 8
else
currentBlock:Hide()
startButton:Show()
y = y + 36
end
-- Upcoming stops (after the current one; all of them when paused).
local want = math.max(0, math.min(MAX_UPCOMING, ns.SafeNum(s.hudUpcoming) or 3))
local first = guiding and cur + 1 or cur
local any = want > 0 and stops[first] ~= nil
if any then
upNext:ClearAllPoints()
upNext:SetPoint("TOPLEFT", body, "TOPLEFT", 10, -y)
upNext:Show(); upNext.rule:Show()
y = y + 14
else
upNext:Hide(); upNext.rule:Hide()
end
local shown = 0
for i, row in ipairs(upcomingRows) do
local idx = first + i - 1
local st = stops[idx]
if i <= want and st then
row.index, row.stop = idx, st
local caution = ns.LevelCaution(st.questLevel)
local kind = st.kind == "turnin" and (" · " .. Widgets.Colorize("Hand in", ns.Colors.turnin))
or (caution and (" " .. Widgets.Colorize("(!)", ns.Colors.warn)))
or ""
local dc = st.kind == "turnin" and ns.Colors.turnin or caution and ns.Colors.warn or ns.Colors.quest
row.dot:SetColorTexture(dc.r, dc.g, dc.b, 1)
row.text:SetText(string.format("%d. %s%s", idx, st.title or "?", kind))
if i % 2 == 0 then row.alt:Show() else row.alt:Hide() end
row:ClearAllPoints()
row:SetPoint("TOPLEFT", body, "TOPLEFT", 1, -y)
row:SetPoint("TOPRIGHT", body, "TOPRIGHT", -1, -y)
row:Show()
y = y + ROW_H
shown = shown + 1
else
row.index, row.stop = nil, nil
row:Hide()
end
end
y = y + 6
body:SetHeight(y)
height = height + y
end
frame:SetHeight(height)
frame:Show()
self:UpdateLive()
self:UpdateItems()
end
--- Rebuild now (the tracker's refresh button).
function HUD:RebuildRoute()
local state = ns.Route:Build()
ns.Route:StampFingerprint()
local n = #(state.stops or {})
if n == 0 then
ns:Print("no route — no quests in your log with a known location.")
else
local nxt = ns.Route:Next()
ns:Print("route rebuilt: %d stops%s", n, nxt and (" · next: " .. ns:Truncate(nxt.title or "?", 30)) or "")
end
end
function HUD:GetRebuildButton() return rebuildButton end
function HUD:GetShelveButton() return shelveButton end
function HUD:GetRestoreButton() return restoreButton end
function HUD:GetFrame() return frame end
---------------------------------------------------------------------------
-- Lifecycle
---------------------------------------------------------------------------
function HUD:Initialize()
if not built then build() end
end
function HUD:OnLogin()
HUD:Refresh()
end
local function onChanged()
ns:Debounce("hud", 0.1, function() HUD:Refresh() end)
end
ns:RegisterEvent("route_changed", onChanged, HUD)
ns:RegisterEvent("BAG_UPDATE", onChanged, HUD)
ns:RegisterEvent("BAG_UPDATE_COOLDOWN", function() updateItemCooldowns() end, HUD)
ns:RegisterEvent("PLAYER_REGEN_ENABLED", function()
if itemsPending then HUD:UpdateItems() end
end, HUD)
ns:RegisterEvent("QUEST_LOG_UPDATE", onChanged, HUD)
ns:RegisterEvent("ZONE_CHANGED_NEW_AREA", onChanged, HUD)
ns:RegisterModule("HUD", HUD)
return HUD