forked from DennisRas/WeeklyKnowledge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChecklist.lua
More file actions
892 lines (838 loc) · 37.1 KB
/
Checklist.lua
File metadata and controls
892 lines (838 loc) · 37.1 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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
---@type string
local addonName = select(1, ...)
---@class WK_Addon
local addon = select(2, ...)
---@class WK_Checklist
local Checklist = {}
addon.Checklist = Checklist
local Constants = addon.Constants
local Utils = addon.Utils
local UI = addon.UI
local Data = addon.Data
function Checklist:ToggleWindow()
if not self.window then return end
if self.window:IsVisible() then
self.window:Hide()
else
self.window:Show()
end
Data.db.global.checklist.open = self.window:IsVisible()
self:Render()
end
function Checklist:Render()
local character = Data:GetCharacter()
local dataColumns = self:GetColumns()
local tableWidth = 0
local tableHeight = 0
---@type WK_TableData
local tableData = {
columns = {},
rows = {}
}
if not self.window then
local frameName = addonName .. "ChecklistWindow"
self.window = CreateFrame("Frame", frameName, UIParent)
self.window:SetSize(500, 500)
self.window:SetFrameStrata("MEDIUM")
self.window:SetFrameLevel(8100)
self.window:SetToplevel(true)
self.window:SetClampedToScreen(true)
self.window:SetMovable(true)
self.window:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 8, -8)
self.window:SetUserPlaced(true)
self.window:RegisterForDrag("LeftButton")
self.window:EnableMouse(true)
self.window:SetScript("OnDragStart", function() self.window:StartMoving() end)
self.window:SetScript("OnDragStop", function() self.window:StopMovingOrSizing() end)
Utils:SetBackgroundColor(self.window, Data.db.global.checklist.windowBackgroundColor.r, Data.db.global.checklist.windowBackgroundColor.g, Data.db.global.checklist.windowBackgroundColor.b, Data.db.global.checklist.windowBackgroundColor.a)
self.window.border = CreateFrame("Frame", "$parentBorder", self.window, "BackdropTemplate")
self.window.border:SetPoint("TOPLEFT", self.window, "TOPLEFT", -3, 3)
self.window.border:SetPoint("BOTTOMRIGHT", self.window, "BOTTOMRIGHT", 3, -3)
self.window.border:SetBackdrop({edgeFile = "Interface/Tooltips/UI-Tooltip-Border", edgeSize = 16, insets = {left = 4, right = 4, top = 4, bottom = 4}})
self.window.border:SetBackdropBorderColor(0, 0, 0, .5)
self.window.border:Show()
self.window.titlebar = CreateFrame("Frame", "$parentTitle", self.window)
self.window.titlebar:SetPoint("TOPLEFT", self.window, "TOPLEFT")
self.window.titlebar:SetPoint("TOPRIGHT", self.window, "TOPRIGHT")
self.window.titlebar:SetHeight(Constants.TITLEBAR_HEIGHT)
self.window.titlebar:RegisterForDrag("LeftButton")
self.window.titlebar:EnableMouse(true)
self.window.titlebar:SetScript("OnDragStart", function() self.window:StartMoving() end)
self.window.titlebar:SetScript("OnDragStop", function() self.window:StopMovingOrSizing() end)
Utils:SetBackgroundColor(self.window.titlebar, 0, 0, 0, 0.5)
self.window.titlebar.icon = self.window.titlebar:CreateTexture("$parentIcon", "ARTWORK")
self.window.titlebar.icon:SetPoint("LEFT", self.window.titlebar, "LEFT", 6, 0)
self.window.titlebar.icon:SetSize(20, 20)
self.window.titlebar.icon:SetTexture("Interface/AddOns/WeeklyKnowledge/Media/Icon.blp")
self.window.titlebar.title = self.window.titlebar:CreateFontString("$parentText", "OVERLAY")
self.window.titlebar.title:SetFontObject("SystemFont_Med2")
self.window.titlebar.title:SetPoint("LEFT", self.window.titlebar, 28, 0)
self.window.titlebar.title:SetJustifyH("LEFT")
self.window.titlebar.title:SetJustifyV("MIDDLE")
self.window.titlebar.title:SetText("Checklist")
self.window.textbox = self.window:CreateFontString("$parentTextbox", "ARTWORK")
self.window.textbox:SetFontObject("SystemFont_Med1")
self.window.textbox:SetPoint("TOPLEFT", self.window, "TOPLEFT", 20, -Constants.TITLEBAR_HEIGHT - 20)
self.window.textbox:SetPoint("BOTTOMRIGHT", self.window, "BOTTOMRIGHT", -20, 20)
self.window.textbox:SetJustifyH("CENTER")
self.window.textbox:SetJustifyV("MIDDLE")
self.window.textbox:Hide()
do -- Close Button
self.window.titlebar.closeButton = CreateFrame("Button", "$parentCloseButton", self.window.titlebar)
self.window.titlebar.closeButton:SetSize(Constants.TITLEBAR_HEIGHT, Constants.TITLEBAR_HEIGHT)
self.window.titlebar.closeButton:SetPoint("RIGHT", self.window.titlebar, "RIGHT", 0, 0)
self.window.titlebar.closeButton:SetScript("OnClick", function() self:ToggleWindow() end)
self.window.titlebar.closeButton:SetScript("OnEnter", function()
self.window.titlebar.closeButton.Icon:SetVertexColor(1, 1, 1, 1)
Utils:SetBackgroundColor(self.window.titlebar.closeButton, 1, 0, 0, 0.2)
GameTooltip:SetOwner(self.window.titlebar.closeButton, "ANCHOR_TOP")
GameTooltip:SetText("Close the window", 1, 1, 1, 1, true);
GameTooltip:Show()
end)
self.window.titlebar.closeButton:SetScript("OnLeave", function()
self.window.titlebar.closeButton.Icon:SetVertexColor(0.7, 0.7, 0.7, 1)
Utils:SetBackgroundColor(self.window.titlebar.closeButton, 1, 1, 1, 0)
GameTooltip:Hide()
end)
self.window.titlebar.closeButton.Icon = self.window.titlebar:CreateTexture("$parentIcon", "ARTWORK")
self.window.titlebar.closeButton.Icon:SetPoint("CENTER", self.window.titlebar.closeButton, "CENTER")
self.window.titlebar.closeButton.Icon:SetSize(10, 10)
self.window.titlebar.closeButton.Icon:SetTexture("Interface/AddOns/WeeklyKnowledge/Media/Icon_Close.blp")
self.window.titlebar.closeButton.Icon:SetVertexColor(0.7, 0.7, 0.7, 1)
end
do -- Settings Button
self.window.titlebar.SettingsButton = CreateFrame("DropdownButton", "$parentSettingsButton", self.window.titlebar)
self.window.titlebar.SettingsButton:SetPoint("RIGHT", self.window.titlebar.closeButton, "LEFT", 0, 0)
self.window.titlebar.SettingsButton:SetSize(Constants.TITLEBAR_HEIGHT, Constants.TITLEBAR_HEIGHT)
self.window.titlebar.SettingsButton:SetScript("OnEnter", function()
self.window.titlebar.SettingsButton.Icon:SetVertexColor(0.9, 0.9, 0.9, 1)
Utils:SetBackgroundColor(self.window.titlebar.SettingsButton, 1, 1, 1, 0.05)
---@diagnostic disable-next-line: param-type-mismatch
GameTooltip:SetOwner(self.window.titlebar.SettingsButton, "ANCHOR_TOP")
GameTooltip:SetText("Settings", 1, 1, 1, 1, true);
GameTooltip:AddLine("Let's customize things a bit", NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
GameTooltip:Show()
end)
self.window.titlebar.SettingsButton:SetScript("OnLeave", function()
self.window.titlebar.SettingsButton.Icon:SetVertexColor(0.7, 0.7, 0.7, 1)
Utils:SetBackgroundColor(self.window.titlebar.SettingsButton, 1, 1, 1, 0)
GameTooltip:Hide()
end)
self.window.titlebar.SettingsButton:SetupMenu(function(_, rootMenu)
rootMenu:CreateCheckbox(
"Hide in combat",
function() return Data.db.global.checklist.hideInCombat end,
function()
Data.db.global.checklist.hideInCombat = not Data.db.global.checklist.hideInCombat
self:Render()
end
)
rootMenu:CreateCheckbox(
"Hide in dungeons",
function() return Data.db.global.checklist.hideInDungeons end,
function()
Data.db.global.checklist.hideInDungeons = not Data.db.global.checklist.hideInDungeons
self:Render()
end
)
rootMenu:CreateCheckbox(
"Hide completed objectives",
function() return Data.db.global.checklist.hideCompletedObjectives end,
function()
Data.db.global.checklist.hideCompletedObjectives = not Data.db.global.checklist.hideCompletedObjectives
self:Render()
end
)
local hideAllUniques = rootMenu:CreateCheckbox(
"Hide all Uniques",
function() return Data.db.global.checklist.hideUniqueObjectives end,
function()
Data.db.global.checklist.hideUniqueObjectives = not Data.db.global.checklist.hideUniqueObjectives
self:Render()
end
)
hideAllUniques:SetTooltip(function(tooltip, elementDescription)
GameTooltip_SetTitle(tooltip, MenuUtil.GetElementText(elementDescription));
GameTooltip_AddNormalLine(tooltip, "Hide all objectives from the Uniques category.");
end)
local hideVendorUniques = rootMenu:CreateCheckbox(
"Hide vendor Uniques",
function() return Data.db.global.checklist.hideUniqueVendorObjectives end,
function()
Data.db.global.checklist.hideUniqueVendorObjectives = not Data.db.global.checklist.hideUniqueVendorObjectives
self:Render()
end
)
hideVendorUniques:SetTooltip(function(tooltip, elementDescription)
GameTooltip_SetTitle(tooltip, MenuUtil.GetElementText(elementDescription));
GameTooltip_AddNormalLine(tooltip, "Hide Uniques that are purchased from a vendor.");
end)
local hideCatchUp = rootMenu:CreateCheckbox(
"Hide Catch-Up objectives",
function() return Data.db.global.checklist.hideCatchUpObjectives end,
function()
Data.db.global.checklist.hideCatchUpObjectives = not Data.db.global.checklist.hideCatchUpObjectives
self:Render()
end
)
hideCatchUp:SetTooltip(function(tooltip, elementDescription)
GameTooltip_SetTitle(tooltip, MenuUtil.GetElementText(elementDescription));
GameTooltip_AddNormalLine(tooltip, "Hide all objectives from the Catch-Up category.");
end)
rootMenu:CreateTitle("Window")
local windowScale = rootMenu:CreateButton("Scaling")
for i = 80, 200, 10 do
windowScale:CreateRadio(
i .. "%",
function() return Data.db.global.checklist.windowScale == i end,
function(data)
Data.db.global.checklist.windowScale = data
self:Render()
end,
i
)
end
local colorInfo = {
r = Data.db.global.checklist.windowBackgroundColor.r,
g = Data.db.global.checklist.windowBackgroundColor.g,
b = Data.db.global.checklist.windowBackgroundColor.b,
opacity = Data.db.global.checklist.windowBackgroundColor.a,
swatchFunc = function()
local r, g, b = ColorPickerFrame:GetColorRGB();
local a = ColorPickerFrame:GetColorAlpha();
if r then
Data.db.global.checklist.windowBackgroundColor.r = r
Data.db.global.checklist.windowBackgroundColor.g = g
Data.db.global.checklist.windowBackgroundColor.b = b
if a then
Data.db.global.checklist.windowBackgroundColor.a = a
end
Utils:SetBackgroundColor(self.window, Data.db.global.checklist.windowBackgroundColor.r, Data.db.global.checklist.windowBackgroundColor.g, Data.db.global.checklist.windowBackgroundColor.b, Data.db.global.checklist.windowBackgroundColor.a)
end
end,
opacityFunc = function() end,
cancelFunc = function(color)
if color.r then
Data.db.global.checklist.windowBackgroundColor.r = color.r
Data.db.global.checklist.windowBackgroundColor.g = color.g
Data.db.global.checklist.windowBackgroundColor.b = color.b
if color.a then
Data.db.global.checklist.windowBackgroundColor.a = color.a
end
Utils:SetBackgroundColor(self.window, Data.db.global.checklist.windowBackgroundColor.r, Data.db.global.checklist.windowBackgroundColor.g, Data.db.global.checklist.windowBackgroundColor.b, Data.db.global.checklist.windowBackgroundColor.a)
end
end,
hasOpacity = 1,
}
rootMenu:CreateColorSwatch(
"Background color",
function()
ColorPickerFrame:SetupColorPickerAndShow(colorInfo)
end,
colorInfo
)
rootMenu:CreateCheckbox(
"Show the border",
function() return Data.db.global.checklist.windowBorder end,
function()
Data.db.global.checklist.windowBorder = not Data.db.global.checklist.windowBorder
self:Render()
end
)
-- rootMenu:CreateCheckbox(
-- "Show the title bar",
-- function() return Data.db.global.checklist.windowTitlebar end,
-- function()
-- Data.db.global.checklist.windowTitlebar = not Data.db.global.checklist.windowTitlebar
-- self:Render()
-- end
-- )
end)
self.window.titlebar.SettingsButton.Icon = self.window.titlebar:CreateTexture(self.window.titlebar.SettingsButton:GetName() .. "Icon", "ARTWORK")
self.window.titlebar.SettingsButton.Icon:SetPoint("CENTER", self.window.titlebar.SettingsButton, "CENTER")
self.window.titlebar.SettingsButton.Icon:SetSize(12, 12)
self.window.titlebar.SettingsButton.Icon:SetTexture("Interface/AddOns/WeeklyKnowledge/Media/Icon_Settings.blp")
self.window.titlebar.SettingsButton.Icon:SetVertexColor(0.7, 0.7, 0.7, 1)
end
do -- Columns Button
self.window.titlebar.ColumnsButton = CreateFrame("DropdownButton", "$parentColumnsButton", self.window.titlebar)
self.window.titlebar.ColumnsButton:SetPoint("RIGHT", self.window.titlebar.SettingsButton, "LEFT", 0, 0)
self.window.titlebar.ColumnsButton:SetSize(Constants.TITLEBAR_HEIGHT, Constants.TITLEBAR_HEIGHT)
self.window.titlebar.ColumnsButton:SetScript("OnEnter", function()
self.window.titlebar.ColumnsButton.Icon:SetVertexColor(0.9, 0.9, 0.9, 1)
Utils:SetBackgroundColor(self.window.titlebar.ColumnsButton, 1, 1, 1, 0.05)
---@diagnostic disable-next-line: param-type-mismatch
GameTooltip:SetOwner(self.window.titlebar.ColumnsButton, "ANCHOR_TOP")
GameTooltip:SetText("Columns", 1, 1, 1, 1, true);
GameTooltip:AddLine("Enable/Disable table columns.", NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
GameTooltip:Show()
end)
self.window.titlebar.ColumnsButton:SetScript("OnLeave", function()
self.window.titlebar.ColumnsButton.Icon:SetVertexColor(0.7, 0.7, 0.7, 1)
Utils:SetBackgroundColor(self.window.titlebar.ColumnsButton, 1, 1, 1, 0)
GameTooltip:Hide()
end)
self.window.titlebar.ColumnsButton:SetupMenu(function(_, rootMenu)
local hidden = Data.db.global.checklist.hiddenColumns
Utils:TableForEach(self:GetColumns(true), function(column)
if not column.toggleHidden then return end
rootMenu:CreateCheckbox(
column.name,
function() return not hidden[column.name] end,
function(columnName)
hidden[columnName] = not hidden[columnName]
self:Render()
end,
column.name
)
end)
end)
self.window.titlebar.ColumnsButton.Icon = self.window.titlebar:CreateTexture(self.window.titlebar.ColumnsButton:GetName() .. "Icon", "ARTWORK")
self.window.titlebar.ColumnsButton.Icon:SetPoint("CENTER", self.window.titlebar.ColumnsButton, "CENTER")
self.window.titlebar.ColumnsButton.Icon:SetSize(12, 12)
self.window.titlebar.ColumnsButton.Icon:SetTexture("Interface/AddOns/WeeklyKnowledge/Media/Icon_Columns.blp")
self.window.titlebar.ColumnsButton.Icon:SetVertexColor(0.7, 0.7, 0.7, 1)
end
do -- Toggle Button
self.window.titlebar.toggleButton = CreateFrame("Button", "$parentToggleButton", self.window.titlebar)
self.window.titlebar.toggleButton:SetPoint("RIGHT", self.window.titlebar.ColumnsButton, "LEFT", 0, 0)
self.window.titlebar.toggleButton:SetSize(Constants.TITLEBAR_HEIGHT, Constants.TITLEBAR_HEIGHT)
self.window.titlebar.toggleButton:SetScript("OnClick", function()
Data.db.global.checklist.hideTable = not Data.db.global.checklist.hideTable
self:Render()
end)
self.window.titlebar.toggleButton:SetScript("OnEnter", function()
self.window.titlebar.toggleButton.Icon:SetVertexColor(0.9, 0.9, 0.9, 1)
Utils:SetBackgroundColor(self.window.titlebar.toggleButton, 1, 1, 1, 0.05)
GameTooltip:SetOwner(self.window.titlebar.toggleButton, "ANCHOR_TOP")
GameTooltip:SetText("Toggle objectives", 1, 1, 1, 1, true)
GameTooltip:AddLine("Expand/Collapse the list.", NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
GameTooltip:Show()
end)
self.window.titlebar.toggleButton:SetScript("OnLeave", function()
self.window.titlebar.toggleButton.Icon:SetVertexColor(0.7, 0.7, 0.7, 1)
Utils:SetBackgroundColor(self.window.titlebar.toggleButton, 1, 1, 1, 0)
GameTooltip:Hide()
end)
self.window.titlebar.toggleButton.Icon = self.window.titlebar:CreateTexture("$parentIcon", "ARTWORK")
self.window.titlebar.toggleButton.Icon:SetPoint("CENTER", self.window.titlebar.toggleButton, "CENTER")
self.window.titlebar.toggleButton.Icon:SetSize(16, 16)
self.window.titlebar.toggleButton.Icon:SetTexture("Interface/AddOns/WeeklyKnowledge/Media/Icon_Toggle.blp")
self.window.titlebar.toggleButton.Icon:SetVertexColor(0.7, 0.7, 0.7, 1)
end
self.window.table = UI:CreateTableFrame({
header = {
enabled = true,
sticky = true,
height = Constants.TABLE_HEADER_HEIGHT,
},
rows = {
height = Constants.TABLE_ROW_HEIGHT,
highlight = false,
striped = true
},
cells = {
padding = Constants.TABLE_CELL_PADDING,
highlight = true
},
})
self.window.table:SetParent(self.window)
self.window.table:SetPoint("TOPLEFT", self.window, "TOPLEFT", 0, -Constants.TITLEBAR_HEIGHT)
self.window.table:SetPoint("BOTTOMRIGHT", self.window, "BOTTOMRIGHT", 0, 0)
end
if not character then
self.window:Hide()
return
end
-- Quick hotfix to avoid excessive rendering
if (not self.window:IsVisible() and not Data.db.global.checklist.open) or (Data.cache.inCombat and Data.db.global.checklist.hideInCombat) then
self.window:Hide()
return
end
do -- Table Column config
Utils:TableForEach(dataColumns, function(dataColumn)
---@type WK_TableDataColumn
local column = {
width = dataColumn.width,
align = dataColumn.align or "LEFT",
}
table.insert(tableData.columns, column)
tableWidth = tableWidth + dataColumn.width
end)
end
do -- Table Header row
---@type WK_TableDataRow
local row = {columns = {}}
Utils:TableForEach(dataColumns, function(dataColumn)
---@type WK_TableDataCell
local cell = {
text = NORMAL_FONT_COLOR:WrapTextInColorCode(dataColumn.name),
onEnter = dataColumn.onEnter,
onLeave = dataColumn.onLeave,
}
table.insert(row.columns, cell)
end)
table.insert(tableData.rows, row)
tableHeight = tableHeight + self.window.table.config.header.height
end
local weeklyProgress = Data:GetWeeklyProgress()
local rows = 0
local profCount = 0
do -- Table data
Utils:TableForEach(character.professions, function(characterProfession)
local profession = Utils:TableGet(Data.Professions, "skillLineID", characterProfession.skillLineID)
if not profession then return end
local objectives = Utils:TableFilter(Data.Objectives, function(objective)
return objective.professionID == profession.skillLineID
end)
Utils:TableForEach(objectives, function(objective)
-- Hide Darkmoon objectives
if objective.typeID == Enum.WK_Objectives.DarkmoonQuest then
if not Data.cache.isDarkmoonOpen then
return
end
end
-- Hide Uniques if enabled
if objective.typeID == Enum.WK_Objectives.Unique then
if Data.db.global.checklist.hideUniqueObjectives then
return
elseif Data.db.global.checklist.hideUniqueVendorObjectives and objective.requires and Utils:TableCount(objective.requires) > 0 then
return
end
end
-- Hide Catch-Up if enabled
if objective.typeID == Enum.WK_Objectives.CatchUp then
if Data.db.global.checklist.hideCatchUpObjectives then
return
end
end
local item = {
id = objective.itemID,
name = "",
link = "",
texture = "",
}
if objective.itemID then
local itemName, itemLink, _, _, _, _, _, _, _, itemTexture = C_Item.GetItemInfo(objective.itemID)
if itemName then
item.name = itemName
item.link = itemLink
item.texture = itemTexture
end
end
local progress = Utils:TableFind(weeklyProgress, function(progress)
return progress.objective == objective and progress.character == character
end)
if not progress then return end
-- local progress = {
-- completed = 0,
-- total = 0,
-- points = 0,
-- pointsTotal = 0,
-- }
-- if objective.quests then
-- local limit = 0
-- for _, questID in ipairs(objective.quests) do
-- progress.questsTotal = progress.questsTotal + 1
-- progress.pointsEarnedTotal = progress.pointsTotal + objective.points
-- if objective.limit and progress.questsTotal > objective.limit then
-- progress.pointsTotal = objective.limit * objective.points
-- progress.questsTotal = objective.limit
-- end
-- if character.completed[questID] then
-- progress.questsCompleted = progress.questsCompleted + 1
-- progress.pointsEarned = progress.points + objective.points
-- end
-- end
-- end
if progress.questsTotal > 0 and progress.questsCompleted == progress.questsTotal and Data.db.global.checklist.hideCompletedObjectives then
return
end
---@type WK_TableDataRow
local row = {columns = {}}
Utils:TableForEach(dataColumns, function(dataColumn)
local cellData = {
character = character,
characterProfession = characterProfession,
dataProfession = profession,
objective = objective,
progress = progress,
item = item
}
---@type WK_TableDataCell
local cell = dataColumn.cell(cellData)
table.insert(row.columns, cell)
end)
table.insert(tableData.rows, row)
tableHeight = tableHeight + self.window.table.config.rows.height
rows = rows + 1
end)
profCount = profCount + 1
end)
end
local windowWidth = tableWidth
local windowHeight = Constants.TITLEBAR_HEIGHT
local minWindowWidth = 200
local maxWindowHeight = 300
if Data.db.global.checklist.hideTable then
self.window.table:Hide()
self.window.textbox:Hide()
else
if rows == 0 then
windowHeight = 100
self.window.textbox:Show()
self.window.table:Hide()
else
windowHeight = windowHeight + tableHeight
self.window.textbox:Hide()
self.window.table:Show()
end
end
if rows == 0 then
windowWidth = 500
end
windowHeight = math.min(windowHeight, maxWindowHeight)
windowWidth = math.max(windowWidth, minWindowWidth)
self.window.textbox:SetText(profCount == 0 and "It does not look like you have any TWW professions." or "Good job! You are done :-)\nMake sure to take a look at your Patron Orders!")
self.window:SetShown(Data.db.global.checklist.open)
self.window.border:SetShown(Data.db.global.checklist.windowBorder)
self.window.titlebar:SetShown(Data.db.global.checklist.windowTitlebar)
-- self.window.titlebar.title:SetShown(windowWidth > minWindowWidth)
self.window.table:SetData(tableData)
self.window:SetWidth(windowWidth)
self.window:SetHeight(windowHeight + 2)
self.window:SetClampRectInsets(self.window:GetWidth() / 2, self.window:GetWidth() / -2, 0, self.window:GetHeight() / 2)
self.window:SetScale(Data.db.global.checklist.windowScale / 100)
if Data.cache.inCombat and Data.db.global.checklist.hideInCombat then
self.window:Hide()
end
end
function Checklist:GetColumns(unfiltered)
local hidden = Data.db.global.checklist.hiddenColumns
local columns = {
{
name = "Objective",
width = 260,
cell = function(data)
local text = ""
local link = data.item.link
local canShare = false
if data.item.id and data.item.id > 0 and data.item.link then
text = data.item.link
canShare = true
if data.item.texture then
text = "|T" .. data.item.texture .. ":0|t " .. data.item.link
end
else
text = "Quest"
local questTooltipData = C_TooltipInfo.GetHyperlink("quest:" .. data.objective.quests[1] .. ":-1")
if questTooltipData and questTooltipData.lines and questTooltipData.lines[1] and questTooltipData.lines[1].leftText then
-- link = format("|cffffff00|Hquest:%d:70|h[%s]|h|r", data.objective.quests[1], questTooltipData.lines[1].leftText) -- Isn't working
link = "quest:" .. data.objective.quests[1] .. ":-1"
text = WrapTextInColorCode(format("%s [%s]", CreateAtlasMarkup("questlog-questtypeicon-Recurring", 14, 14), questTooltipData.lines[1].leftText), "ffffff00")
end
end
return {
text = text,
onEnter = function(columnFrame)
GameTooltip:SetOwner(columnFrame, "ANCHOR_RIGHT")
if link and strlen(link) > 0 then
GameTooltip:SetHyperlink(link)
if canShare then
GameTooltip:AddLine(" ")
GameTooltip:AddLine("<Shift Click to Link to Chat>", GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b)
end
end
GameTooltip:Show()
end,
onLeave = function()
GameTooltip:Hide()
end,
onClick = function()
if link and strlen(link) > 0 and canShare then
if IsModifiedClick("CHATLINK") then
if not ChatEdit_InsertLink(link) then
ChatFrame_OpenChat(link);
end
end
end
end,
}
end,
},
{
name = "Profession",
width = 100,
toggleHidden = true,
cell = function(data)
return {
text = data.dataProfession.name,
}
end,
},
{
name = "Category",
width = 80,
toggleHidden = true,
cell = function(data)
local objectiveType = Utils:TableGet(Data.ObjectiveTypes, "id", data.objective.typeID)
if not objectiveType then
return {
text = "?"
}
end
return {
text = objectiveType.name,
onEnter = function(cellFrame)
GameTooltip:SetOwner(cellFrame, "ANCHOR_RIGHT")
GameTooltip:SetText(objectiveType.name, 1, 1, 1);
GameTooltip:AddLine(objectiveType.description, nil, nil, nil, true)
GameTooltip:Show()
end,
onLeave = function()
GameTooltip:Hide()
end,
}
end,
},
{
name = "Location",
width = 100,
toggleHidden = true,
cell = function(data)
local text = " "
if data.objective then
local loc = data.objective.loc
if loc and loc.m then
if Data.cache.mapInfo[loc.m] then
text = Data.cache.mapInfo[loc.m].name
else
local mapInfo = C_Map.GetMapInfo(loc.m)
if mapInfo then
Data.cache.mapInfo[loc.m] = mapInfo
text = mapInfo.name
end
end
end
end
return {
text = text,
}
end,
},
-- {
-- name = "Repeat",
-- width = 60,
-- toggleHidden = true,
-- cell = function(data)
-- local objective = Data:GetObjective(data.objective.objectiveID)
-- return {
-- text = objective.repeatable,
-- }
-- end,
-- },
{
name = "Progress",
width = 70,
align = "CENTER",
toggleHidden = true,
cell = function(data)
local result = format("%d / %d", data.progress.questsCompleted, data.progress.questsTotal)
if data.progress.questsTotal == 0 then
result = ""
elseif data.progress.questsCompleted == data.progress.questsTotal then
result = GREEN_FONT_COLOR:WrapTextInColorCode(result)
end
return {
text = result,
}
end,
},
{
name = "Points",
width = 70,
align = "CENTER",
toggleHidden = true,
cell = function(data)
local result = format("%d / %d", data.progress.pointsEarned, data.progress.pointsTotal)
if data.progress.questsTotal == 0 then
result = ""
elseif data.progress.pointsEarned == data.progress.pointsTotal then
result = GREEN_FONT_COLOR:WrapTextInColorCode(result)
end
return {
text = result,
}
end,
},
{
name = "",
width = 50,
align = "CENTER",
cell = function(data)
local loc = data.objective.loc
local requires = data.objective.requires
local TomTom = _G["TomTom"]
if data.objective then
local mapInfo = nil
local point = nil
if loc and loc.m then
mapInfo = C_Map.GetMapInfo(loc.m)
end
if mapInfo then
point = UiMapPoint.CreateFromCoordinates(loc.m, loc.x / 100, loc.y / 100)
end
return {
text = CreateAtlasMarkup("Waypoint-MapPin-Tracked", 20, 20, -4),
onEnter = function(columnFrame)
local showTooltip = function()
GameTooltip:SetOwner(columnFrame, "ANCHOR_RIGHT")
GameTooltip:SetText("Do you know de wey?", 1, 1, 1)
if loc and loc.hint then
GameTooltip:AddLine(loc.hint, nil, nil, nil, true)
end
if mapInfo then
GameTooltip:AddLine(" ")
GameTooltip:AddDoubleLine("Location:", mapInfo.name, nil, nil, nil, 1, 1, 1)
end
if loc and loc.x then
if not mapInfo then
GameTooltip:AddLine(" ")
end
GameTooltip:AddDoubleLine("Coordinates:", format("%.1f / %.1f", loc.x, loc.y), nil, nil, nil, 1, 1, 1)
end
if requires and Utils:TableCount(requires) > 0 then
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Requirements:")
Utils:TableForEach(requires, function(req)
local leftText = " "
local rightText = format("x%d", req.amount)
local completed = false
if req.type == "item" then
local _, itemLink, _, _, _, _, _, _, _, itemTexture = C_Item.GetItemInfo(req.id)
local itemCount = C_Item.GetItemCount(req.id)
leftText = format("%s %s", CreateSimpleTextureMarkup(itemTexture or [[Interface\Icons\INV_Misc_QuestionMark]]), itemLink or "Loading...")
if itemCount then
rightText = format("%d / %d", itemCount, req.amount)
if itemCount >= req.amount then
completed = true
end
end
end
if req.type == "currency" then
local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(req.id)
if currencyInfo then
local _, _, _, hex = C_Item.GetItemQualityColor(currencyInfo.quality)
leftText = format("%s |c%s%s|r", CreateSimpleTextureMarkup(currencyInfo.iconFileID or [[Interface\Icons\INV_Misc_QuestionMark]]), hex, currencyInfo.name)
rightText = format("%d / %d", currencyInfo.quantity, req.amount)
if currencyInfo.quantity >= req.amount then
completed = true
end
end
end
if req.type == "quest" then
leftText = req.name
if not req.match or req.match == "all" then
local numCompleted = 0
completed = true
for _, questID in ipairs(req.quests) do
if not C_QuestLog.IsQuestFlaggedCompleted(questID) then
completed = false
else
numCompleted = numCompleted + 1
end
end
rightText = format("%d / %d", numCompleted, #req.quests)
else
for _, questID in ipairs(req.quests) do
if C_QuestLog.IsQuestFlaggedCompleted(questID) then
completed = true
end
end
rightText = format("%d / %d", completed and 1 or 0, 1)
end
end
if req.type == "renown" then
local renownInfo = C_MajorFactions.GetMajorFactionData(req.id)
local renownLevel = C_MajorFactions.GetCurrentRenownLevel(req.id) or 0
if renownInfo and renownLevel > 0 then
leftText = renownInfo.name
rightText = format("%d / %d", renownLevel, req.amount)
if renownLevel >= req.amount then
completed = true
end
end
end
GameTooltip:AddDoubleLine(leftText, format("%s %s", rightText, CreateAtlasMarkup(completed and "common-icon-checkmark" or "common-icon-redx", 13, 13)), 1, 1, 1, 1, 1, 1)
end)
end
if point then
if C_Map.CanSetUserWaypointOnMap(loc.m) or TomTom then
GameTooltip:AddLine(" ")
end
if C_Map.CanSetUserWaypointOnMap(loc.m) then
GameTooltip:AddLine("<Click to place a pin on the map>", GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b)
GameTooltip:AddLine("<Shift click to share pin in chat>", GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b)
end
if TomTom then
GameTooltip:AddLine("<Alt click to place a TomTom waypoint>", GREEN_FONT_COLOR.r, GREEN_FONT_COLOR.g, GREEN_FONT_COLOR.b)
end
end
GameTooltip:Show()
end
if requires and Utils:TableCount(requires) > 0 then
Utils:TableForEach(requires, function(req)
if req.type == "item" then
Data.cache.items[req.id] = Item:CreateFromItemID(req.id)
Data.cache.items[req.id]:ContinueOnItemLoad(showTooltip)
end
end)
end
showTooltip()
end,
onLeave = function()
GameTooltip:Hide()
end,
onClick = function()
if point then
if IsAltKeyDown() and TomTom then
local text = "Objective"
if data.item.id and data.item.id > 0 and data.item.link then
text = data.item.link
if data.item.texture then
text = "|T" .. data.item.texture .. ":0|t " .. data.item.link
end
else
text = "Quest"
local questTooltipData = C_TooltipInfo.GetHyperlink("quest:" .. data.objective.quests[1] .. ":-1")
if questTooltipData and questTooltipData.lines and questTooltipData.lines[1] and questTooltipData.lines[1].leftText then
text = WrapTextInColorCode(format("%s [%s]", CreateAtlasMarkup("questlog-questtypeicon-Recurring", 14, 14), questTooltipData.lines[1].leftText), "ffffff00")
end
end
TomTom:AddWaypoint(loc.m, loc.x / 100, loc.y / 100, {title = text, from = addonName})
elseif C_Map.CanSetUserWaypointOnMap(loc.m) then
if IsModifiedClick("CHATLINK") then
local hyperlink = format("|cffffff00|Hworldmap:%d:%d:%d|h[%s]|h|r", loc.m, loc.x * 100, loc.y * 100, MAP_PIN_HYPERLINK)
if not ChatEdit_InsertLink(hyperlink) then
ChatFrame_OpenChat(hyperlink);
end
else
C_Map.SetUserWaypoint(point)
C_SuperTrack.SetSuperTrackedUserWaypoint(true)
end
end
end
end,
}
end
end,
},
}
if unfiltered then
return columns
end
local filteredColumns = Utils:TableFilter(columns, function(column)
return not hidden[column.name]
end)
return filteredColumns
end