This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGatherPanel.lua
2075 lines (1793 loc) · 63.2 KB
/
GatherPanel.lua
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
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, addon = ...;
local LibDD = LibStub:GetLibrary("LibUIDropDownMenu-4.0");
local L = addon;
-- Testing Types
---@enum ItemGoalType
local ITEM_GOAL_TYPES = {
min = "min",
max = "max",
}
---@enum ItemType
local ITEM_TYPE = {
item = "ITEM",
group = "GROUP"
}
addon.EntryTypes = ITEM_TYPE;
---@class Item
---@field parent integer | nil
---@field type ItemType
---@field id integer
---@field name string
---@field displayName string
---@field professionQuality number
---@field itemQuality number
---@field itemTexture string
---@field goalType ItemGoalType
---@field itemCount integer
---@field itemCountTmp integer
---@field goal integer
---@field min integer
---@field max integer
---@field progressPercentage number
---@field progressPercentageMax number
---@field isCollapsed boolean
---@field tracked boolean
---@field tracker integer The index of the tracker entry.
---@field betterItem Item
---@field scrollIndex integer
GATHERPANEL_ITEMBAR_HEIGHT = 26;
GATHERPANEL_NUM_ITEMS_DISPLAYED = 15;
GATHERPANEL_NUM_TRACKERS_ENABLED = 0;
GATHERPANEL_NUM_TRACKERS_CREATED = 0;
GATHERPANEL_LOADED = false;
GATHERPANEL_ITEMLISTS = {};
GATHERPANEL_ITEM_LIST_SELECTION = nil;
GATHERPANEL_VERSION = nil;
CURRENT_GATHERPANEL_VERSION = nil
-- setup localization
local function L_Default(L, key)
return key;
end
setmetatable(L.T, { __index=L_Default });
GATHERPANEL_L = L.T;
local sortedHierarchy = {};
addon.sortedHierarchy = sortedHierarchy;
local defaultGroup = {
name = L.T["UNCATEGORIZED"],
type = "GROUP",
parent = nil,
isCollapsed = false,
};
---@param realm string
---@param characterName string
local function GetItemlistId(realm, characterName)
return realm .. ":" .. characterName;
end
function addon:GetOptionName(enum, value, prefix)
for key, val in pairs(enum) do
if val == value then
return L[prefix .. "_" .. key];
end
end
return L.T["NOT_FOUND"]
end
local function compareByQualityAndName(a, b)
if a.element.type ~= "ITEM" or b.element.type ~= "ITEM" then
return false;
end
if a.element.itemQuality ~= b.element.itemQuality
and a.element.itemQuality ~= nil and b.element.itemQuality ~= nil then
return a.element.itemQuality > b.element.itemQuality
end
if a.element.name ~= b.element.name
and a.element.name ~= nil and b.element.name ~= nil then
return a.element.name < b.element.name;
end
if a.element.professionQuality ~= b.element.professionQuality
and a.element.professionQuality ~= nil and b.element.professionQuality ~= nil then
return a.element.professionQuality > b.element.professionQuality
end
return false;
end
local function traverse(tab, objectId, object, depth)
table.insert(tab, {
id = objectId,
level = depth
});
if object.children ~= nil then
-- sort the children by quality, then by name
local sorted = {};
for childId, child in pairs(object.children) do
table.insert(sorted, {
id = childId,
element = child,
});
end
table.sort(sorted, compareByQualityAndName)
for _, e in ipairs(sorted) do
traverse(tab, e.id, e.element, depth + 1);
end
end
end
local function flatToHierarchy(objects)
-- Uncatogorized Group
local elements = {
[0] = {
children = {}
}
};
local roots = {
[0] = elements[0]
};
local keys = {};
for objectId, object in pairs(objects) do
table.insert(keys, objectId);
end
table.sort(keys);
-- populate elements list
for _, objectId in ipairs(keys) do
if objects[objectId].type == nil then
objects[objectId].type = "ITEM";
end
elements[objectId] = objects[objectId]
elements[objectId]["children"] = nil;
end
for objectId, object in pairs(objects) do
local element = elements[objectId];
if object.parent == nil then
object.parent = 0;
end
if object.parent == 0 and object["type"] == "GROUP" then
roots[objectId] = element;
else
local parent = elements[object.parent];
if parent == nil then
parent = elements[0]
object.parent = 0;
end
if parent.children == nil then
parent.children = {};
end
parent.children[objectId] = element;
end
end
-- now sort the groups according to their name.
local groupIds = {};
for groupId, group in pairs(roots) do
table.insert(groupIds, groupId);
end
local function compareByName(a, b)
-- skip comparisons with virtual object
if a == 0 or b == 0 then
return false;
end
return objects[a]["name"] < objects[b]["name"]
end
table.sort(groupIds, compareByName);
local linearized = {};
for i, groupId in ipairs(groupIds) do
traverse(linearized, groupId, roots[groupId], 0);
end
return linearized;
end
---@param itemListId string
local function decodeItemListId(itemListId)
local t = {};
for str in string.gmatch(itemListId, "([^:]+)") do
table.insert(t, str)
end
local realm = t[1];
local characterName = t[2]
return realm, characterName;
end
---@return table<integer, Item>
function GatherPanel_GetItemList()
if GATHERPANEL_CURRENT_ITEM_LIST == nil then
return {}
end
return GATHERPANEL_CURRENT_ITEM_LIST;
end
local function getItemlist()
return GatherPanel_GetItemList();
end
function addon.getItemlist()
return GatherPanel_GetItemList();
end
function addon.getGroups()
local entries = GatherPanel_GetItemList();
local sortedEntryKeys = addon.sortedHierarchy;
local groups = {};
local currentGroup = nil;
for i = 1, #sortedEntryKeys, 1 do
local entryKey = sortedEntryKeys[i].id;
local entry;
if entryKey == 0 then
entry = {
type = "GROUP",
name = addon.T["DEFAULT_GROUP"],
id = 0,
};
else
entry = entries[entryKey];
end
if entry.type == "GROUP" then
if currentGroup ~= nil then
table.insert(groups, currentGroup);
end
currentGroup = {
groupData = entry,
id = entryKey,
entries = {},
};
elseif entry.type == "ITEM" and entry.tracked then
table.insert(currentGroup.entries, entry);
end
end
if currentGroup ~= nil then
table.insert(groups, currentGroup)
end
return groups;
end
local function iterSortedItemList()
local index = 1;
local elements = getItemlist();
return function()
while index <= #sortedHierarchy do
local elementKey = sortedHierarchy[index].id;
index = index + 1;
if elementKey ~= 0 then
return elementKey, elements[elementKey]
end
end
return nil
end
end
local function setItemList()
if GATHERPANEL_ITEM_LIST_SELECTION == GetItemlistId("X-Internal", "Combined") then
local itemList = {};
for realm, characterTable in pairs(GATHERPANEL_ITEMLISTS) do
if realm == GetRealmName() then
for _, itemTable in pairs(characterTable) do
for itemId, item in pairs(itemTable) do
-- skip other types then ITEM in the combined list
if item.type == "ITEM" then
if itemList[itemId] ~= nil then
itemList[itemId]["min"] = itemList[itemId]["min"] + item["min"];
itemList[itemId]["max"] = itemList[itemId]["max"] + item["max"];
else
itemList[itemId] = {};
for k, v in pairs(item) do
itemList[itemId][k] = v;
end
end
end
end
end
end
end
GATHERPANEL_CURRENT_ITEM_LIST = itemList;
return;
elseif GATHERPANEL_ITEM_LIST_SELECTION ~= nil then
local realm, characterName = decodeItemListId(GATHERPANEL_ITEM_LIST_SELECTION);
if GATHERPANEL_ITEMLISTS[realm] ~= nil and GATHERPANEL_ITEMLISTS[realm][characterName] ~= nil then
GATHERPANEL_CURRENT_ITEM_LIST = GATHERPANEL_ITEMLISTS[realm][characterName];
return;
end
end
-- Fallback to personal list. generate if not exists.
local realm = GetRealmName();
local characterName = UnitName("player");
GATHERPANEL_ITEM_LIST_SELECTION = GetItemlistId(realm, characterName);
if GATHERPANEL_ITEMLISTS[realm] == nil then
GATHERPANEL_ITEMLISTS[realm] = {};
end
if GATHERPANEL_ITEMLISTS[realm][characterName] == nil then
GATHERPANEL_ITEMLISTS[realm][characterName] = {};
end
GATHERPANEL_CURRENT_ITEM_LIST = GATHERPANEL_ITEMLISTS[realm][characterName];
end
StaticPopupDialogs["GATHERPANEL_CREATE_GROUP"] = {
text = "New Group",
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = function(self)
GatherPanel_CreateGroup(self.editBox:GetText());
end,
OnShow = function(self)
self.editBox:SetFocus();
end,
OnHide = function(self)
self.editBox:SetText("");
end,
EditBoxOnEnterPressed = function(self)
local parent = self:GetParent();
GatherPanel_CreateGroup(self:GetText());
parent:Hide();
end,
EditBoxOnEscapePressed = function(self)
self:GetParent():Hide();
end,
hideOnEscape = 1,
hasEditBox = 1
}
StaticPopupDialogs["GATHERPANEL_GROUP_EDIT_NAME"] = {
text = "Rename Group '%s'",
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = function(self, group)
GatherPanel_EditGroup(group, self.editBox:GetText());
end,
OnShow = function(self, group)
self.editBox:SetText(group.name);
self.editBox:SetFocus();
end,
OnHide = function(self)
self.editBox:SetText("");
end,
EditBoxOnEnterPressed = function(self, group)
local parent = self:GetParent();
GatherPanel_EditGroup(group, self:GetText());
parent:Hide();
end,
EditBoxOnEscapePressed = function(self)
self:GetParent():Hide();
end,
hideOnEscape = 1,
hasEditBox = 1
}
local function SelectParentGroup(self, parentId)
local item = _G["ItemDetailFrame"].item;
item.parent = parentId;
GatherPanel_InitializeSortedItemList();
GatherPanel_UpdateItems(false);
GatherPanel_UpdatePanel();
end
local function SetParent(self, parentId)
local parent = getItemlist()[parentId];
if parent then
GatherPanel_Panel2.Inset.ParentDropDown.parentId = parentId;
LibDD:UIDropDownMenu_SetText(GatherPanel_Panel2.Inset.ParentDropDown, parent.name);
else
GatherPanel_Panel2.Inset.ParentDropDown.parentId = 0;
LibDD:UIDropDownMenu_SetText(GatherPanel_Panel2.Inset.ParentDropDown, defaultGroup.name);
end
LibDD:UIDropDownMenu_SetWidth(GatherPanel_Panel2.Inset.ParentDropDown, 120);
end
local function SelectItemlist(self, itemListId)
GATHERPANEL_ITEM_LIST_SELECTION = itemListId;
-- Check if id exists. gets reset if not.
setItemList();
if GATHERPANEL_ITEM_LIST_SELECTION == GetItemlistId("X-Internal", "Combined") then
-- disable all item list manipulations
GatherPanel_NewItem_CreateButton:Disable();
ItemDetailFrame.MinQuantityInput:Disable();
ItemDetailFrame.MaxQuantityInput:Disable();
ItemDetailDeleteButton:Disable()
else
GatherPanel_NewItem_CreateButton:Enable();
ItemDetailFrame.MinQuantityInput:Enable();
ItemDetailFrame.MaxQuantityInput:Enable();
ItemDetailDeleteButton:Enable();
end
local realm, characterName = decodeItemListId(GATHERPANEL_ITEM_LIST_SELECTION);
if GATHERPANEL_ITEM_LIST_SELECTION == GetItemlistId("X-Internal", "Combined") then
LibDD:UIDropDownMenu_SetText(GatherPanel_Panel1.ListSelection, L.T["COMBINED"]);
else
LibDD:UIDropDownMenu_SetText(GatherPanel_Panel1.ListSelection, characterName);
end
LibDD:CloseDropDownMenus();
GatherPanel_InitializeSortedItemList();
GatherPanel_ReloadTracker();
GatherPanel_UpdateItems(false);
GatherPanel_UpdatePanel(true);
addon.ObjectiveTracker:FullUpdate();
end
---@param item Item
local function trackItem(_, item)
GatherPanel_TrackItem(item);
end
---@param item Item
local function group_ShowEditPopup(_, item)
StaticPopup_Show("GATHERPANEL_GROUP_EDIT_NAME", item.name, nil, item);
end
function GatherPanel_ItemDetailDeleteButton_OnClick(frame)
local itemID = frame:GetParent().item.id;
for i, item in pairs(getItemlist()) do
if (item.id == itemID) then
getItemlist()[i] = nil;
addon.Sounds:PlayCheckBoxSelect();
frame:GetParent().item = nil;
GatherPanel_InitializeSortedItemList();
GatherPanel_UpdateItems(false);
GatherPanel_UpdatePanelItems();
HideParentPanel(frame);
addon.ObjectiveTracker:FullUpdate();
return;
end
end
end
local function rearrangeTrackers()
local newTracker = 0;
for i, item in pairs(getItemlist()) do
if (item.tracker) then
newTracker = newTracker + 1;
item.tracker = newTracker;
local tracker = _G["GatherPanel_Tracker" .. newTracker];
tracker.icon = item.itemTexture;
tracker.item = item;
tracker.AnimValue = item.progressPercentageMax * 100;
tracker.Bar.Icon:SetTexture(item.itemTexture);
if (item.goal <= item.itemCount) then
tracker.Bar.CheckMarkTexture:Show();
else
tracker.Bar.CheckMarkTexture:Hide();
end
end
end
end
local function entrySetTracked(entry, tracked)
if tracked then
if not entry.tracked then
GatherPanel_CreateTrackerForItem(entry);
end
else
if entry.tracked then
entry.tracked = false;
entry.tracker = nil;
rearrangeTrackers();
_G["GatherPanel_Tracker" .. GATHERPANEL_NUM_TRACKERS_ENABLED]:Hide();
GATHERPANEL_NUM_TRACKERS_ENABLED = GATHERPANEL_NUM_TRACKERS_ENABLED - 1;
end
end
end
---@param itemKey integer
function GatherPanel_Context_ItemDelete(_, itemKey)
local items = getItemlist();
items[itemKey] = nil;
addon.Sounds:PlayCheckBoxSelect();
GatherPanel_InitializeSortedItemList();
GatherPanel_UpdateItems(false);
GatherPanel_UpdatePanelItems();
end
local function trackGroup(_, itemKey, track)
local groupFound = false;
local entries = getItemlist() or {};
for i = 1, #addon.sortedHierarchy, 1 do
local entryKey = addon.sortedHierarchy[i].id;
local entry = entries[entryKey];
if addon.sortedHierarchy[i].id == itemKey then
groupFound = true;
else
if groupFound then
if entry.type == "ITEM" then
entrySetTracked(entry, track);
else
break;
end
end
end
end
GatherPanel_UpdateItems(false);
GatherPanel_UpdatePanel();
GatherPanel_ReloadTracker();
addon.ObjectiveTracker:FullUpdate();
end
addon.trackGroup = trackGroup;
local function initDropdownOptions_TrackerBarContext(frame)
local info = LibDD:UIDropDownMenu_CreateInfo();
info.text = L.T["UNTRACK"];
info.func = trackItem;
info.notCheckable = true;
---@type Item
info.arg1 = frame:GetParent().item;
LibDD:UIDropDownMenu_AddButton(info);
end
local function initDropdownOptions_GroupEdit(frame)
local info = LibDD:UIDropDownMenu_CreateInfo();
info.text = L.T["CHANGE_NAME"];
info.func = group_ShowEditPopup;
---@type Item
info.arg1 = frame:GetParent().item;
info.notCheckable = true;
LibDD:UIDropDownMenu_AddButton(info);
info = LibDD:UIDropDownMenu_CreateInfo();
info.text = L.T["REMOVE_GROUP"];
info.func = GatherPanel_Context_ItemDelete;
info.notCheckable = true;
---@type integer
info.arg1 = frame:GetParent().itemKey;
LibDD:UIDropDownMenu_AddButton(info);
info = LibDD:UIDropDownMenu_CreateInfo();
info.text = L.T["GROUP_TRACK"];
info.func = trackGroup;
info.notCheckable = true;
---@type integer
info.arg1 = frame:GetParent().itemKey;
info.arg2 = true;
LibDD:UIDropDownMenu_AddButton(info);
info = LibDD:UIDropDownMenu_CreateInfo();
info.text = L.T["GROUP_UNTRACK"];
info.func = trackGroup;
info.notCheckable = true;
---@type integer
info.arg1 = frame:GetParent().itemKey;
info.arg2 = false;
LibDD:UIDropDownMenu_AddButton(info);
end
local function InitParentSelectionOptions_DetailFrame(_)
local defaultGroupInfo = LibDD:UIDropDownMenu_CreateInfo();
defaultGroupInfo.text = defaultGroup.name;
defaultGroupInfo.isNotRadio = false;
defaultGroupInfo.func = SelectParentGroup;
defaultGroupInfo.arg1 = 0;
if not _G["ItemDetailFrame"].item or _G["ItemDetailFrame"].item.parent == 0 then
defaultGroupInfo.checked = 1
else
defaultGroupInfo.checked = nil;
end
LibDD:UIDropDownMenu_AddButton(defaultGroupInfo);
for itemId, item in iterSortedItemList() do
local info = LibDD:UIDropDownMenu_CreateInfo();
if item.type == "GROUP" then
info.text = item.name;
info.isNotRadio = false;
info.func = SelectParentGroup;
info.arg1 = itemId;
if _G["ItemDetailFrame"].item and _G["ItemDetailFrame"].item.parent == itemId then
info.checked = 1
else
info.checked = nil;
end
LibDD:UIDropDownMenu_AddButton(info);
end
end
end
local function InitParentSelectionOptions_CreateFrame(_)
local defaultGroupInfo = LibDD:UIDropDownMenu_CreateInfo();
defaultGroupInfo.text = defaultGroup.name;
defaultGroupInfo.isNotRadio = false;
defaultGroupInfo.func = SetParent;
defaultGroupInfo.arg1 = 0;
if not GatherPanel_Panel2.Inset.ParentDropDown.parentId or GatherPanel_Panel2.Inset.ParentDropDown.parentId == 0 then
defaultGroupInfo.checked = 1
else
defaultGroupInfo.checked = nil;
end
LibDD:UIDropDownMenu_AddButton(defaultGroupInfo);
for itemId, item in iterSortedItemList() do
local info = LibDD:UIDropDownMenu_CreateInfo();
if item.type == "GROUP" then
info.text = item.name;
info.isNotRadio = false;
info.func = SetParent;
info.arg1 = itemId;
if GatherPanel_Panel2.Inset.ParentDropDown.parentId == itemId then
info.checked = 1
else
info.checked = nil;
end
LibDD:UIDropDownMenu_AddButton(info);
end
end
end
local function InitListOptions(_)
local info = LibDD:UIDropDownMenu_CreateInfo();
info.keepShownOnClick = 1;
info.text = L.T["COMBINED"];
info.isNotRadio = false;
info.func = SelectItemlist;
info.tooltipTitle = L.T["COMBINED"];
local itemListId = GetItemlistId("X-Internal", "Combined");
info.arg1 = itemListId;
if GATHERPANEL_ITEM_LIST_SELECTION == itemListId then
info.checked = 1
else
info.checked = nil;
end
LibDD:UIDropDownMenu_AddButton(info);
for realm, characterTable in pairs(GATHERPANEL_ITEMLISTS) do
if realm == GetRealmName() then
local characterKeys = {};
for characterName, character in pairs(characterTable) do
table.insert(characterKeys, characterName);
end
table.sort(characterKeys);
for i, characterName in ipairs(characterKeys) do
local itemListId = GetItemlistId(realm, characterName)
info.text = characterName;
info.isNotRadio = false;
info.func = SelectItemlist;
info.arg1 = itemListId;
if GATHERPANEL_ITEM_LIST_SELECTION == itemListId then
info.checked = 1
else
info.checked = nil;
end
LibDD:UIDropDownMenu_AddButton(info);
end
end
end
end
function GatherPanel_OnShow()
addon.Sounds:PlayProfessionWindowOpen();
GatherPanel_UpdateItems(false);
GatherPanel_UpdatePanel();
end
function GatherPanel_OnHide()
addon.Sounds:PlayProfessionWindowClose();
end
function GatherPanel_Tracker_OnLoad()
SlashCmdList["GATHERPANEL_TRACKER"] = GatherPanel_ToggleTracker;
SLASH_GATHERPANEL_TRACKER1 = "/gpt";
end
function GatherPanel_ToggleTracker()
addon.Variables.user.trackerVisible = not addon.Variables.user.trackerVisible;
-- Hide Tracker
GatherPanel_Tracker_Update();
-- Check UI Toggle
GatherPanel_UpdatePanel();
end
function GatherPanel_TrackAll()
for itemId, item in pairs(getItemlist()) do
item.tracked = true;
end
GatherPanel_ReloadTracker();
end
function GatherPanel_OnLoad(frame)
addon.Frame = frame
function addon.Frame:ExpandGroup(group)
group.isCollapsed = false
GatherPanel_UpdatePanelItems()
end
function addon.Frame:ScrollToEntry(entry)
FauxScrollFrame_SetOffset(_G["GatherFrameScrollFrame"], entry.scrollIndex)
GatherPanel_UpdatePanel()
end
SlashCmdList["GATHERPANEL"] = function(msg)
local _, _, cmd, args = string.find(msg, "%s?(%w+)%s?(.*)");
if cmd == "trackall" then
GatherPanel_TrackAll();
elseif cmd == "tracker" then
GatherPanel_ToggleTracker();
elseif cmd == nil then
frame:SetShown(not frame:IsShown());
elseif cmd == "options" then
addon.Settings.Open();
else
print("GatherPanel Chat Commands:");
print("/gp - Open Gather Panel");
print("/gp trackall - Track all items from the current item list");
print("/gp tracker - Toggle Tracker");
print("/gp options - Open Settings");
end
end
SLASH_GATHERPANEL1 = "/gp";
local container = _G["GatherPanelInset"];
for i = 1, GATHERPANEL_NUM_ITEMS_DISPLAYED, 1 do
local bar = CreateFrame("Button", "GatherBar" .. i, container, "GatherBarTemplate");
bar.Context = LibDD:Create_UIDropDownMenu(nil, bar);
bar.Context:SetAllPoints();
bar.Context:Hide();
if i == 1 then
bar:SetPoint("TOPRIGHT", -10, -6);
else
bar:SetPoint("TOPRIGHT", "GatherBar" .. (i - 1), "BOTTOMRIGHT", 0, -3);
end
_G["GatherBar" .. i].id = i;
_G["GatherBar" .. i]:SetPoint("LEFT", "GatherPanelInset", "LEFT", 10, 0);
_G["GatherBar" .. i .. "ItemName"]:SetPoint("LEFT", "GatherBar" .. i, "LEFT", 10, 0);
_G["GatherBar" .. i .. "ItemName"]:SetPoint("RIGHT", "GatherBar" .. i .. "ItemBar", "LEFT", -3, 0);
_G["GatherBar" .. i .. "ItemBarHighlight1"]:SetPoint("TOPLEFT", "GatherBar" .. i, "TOPLEFT", -2, 4);
_G["GatherBar" .. i .. "ItemBarHighlight1"]:SetPoint("BOTTOMRIGHT", "GatherBar" .. i, "BOTTOMRIGHT", -10, -4);
end
_G['ItemDetailDeleteButton']:SetText(L.T["REMOVE_FROM_LIST"]);
PanelTemplates_SetNumTabs(_G['GatherPanel'], 2);
PanelTemplates_SetTab(_G['GatherPanel'], 1);
ItemDetailFrame.ParentDropDown = LibDD:Create_UIDropDownMenu(nil, ItemDetailFrame);
ItemDetailFrame.ParentDropDown:SetPoint("TOPLEFT", ItemDetailFrame.MinQuantityInput, "BOTTOMLEFT", -22, -17);
ItemDetailFrame.ParentDropDown.Label = ItemDetailFrame.ParentDropDown:CreateFontString(nil, "ARTWORK", "GameFontNormal");
ItemDetailFrame.ParentDropDown.Label:SetText(addon.T["GROUP"]);
ItemDetailFrame.ParentDropDown.Label:SetPoint("BOTTOMLEFT", ItemDetailFrame.ParentDropDown, "TOPLEFT", 13, 0);
GatherPanel_Panel1.ListSelection = LibDD:Create_UIDropDownMenu(nil, GatherPanel_Panel1);
GatherPanel_Panel1.ListSelection:SetPoint("TOPLEFT", GatherPanel_Panel1, 50, -26);
GatherPanel_Panel2.Inset.ParentDropDown = LibDD:Create_UIDropDownMenu(nil, GatherPanel_Panel2.Inset);
GatherPanel_Panel2.Inset.ParentDropDown:SetPoint("TOPLEFT", GatherPanel_Panel2.Inset.MinQuantityInput, "BOTTOMLEFT", -20, -16);
GatherPanel_Panel2.Inset.ParentDropDown.Label = GatherPanel_Panel2.Inset.ParentDropDown:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall");
GatherPanel_Panel2.Inset.ParentDropDown.Label:SetText(addon.T["GROUP"]);
GatherPanel_Panel2.Inset.ParentDropDown.Label:SetPoint("BOTTOMLEFT", GatherPanel_Panel2.Inset.ParentDropDown, "TOPLEFT", 20, 0);
end
function GatherPanel_InitializeSortedItemList()
--[[
Items can have parents (which are categories or items, e.g. for recipe tracking).
Rearrange items into the groups in a linear fashion, i.e. span up a tree.
]] --
local items = getItemlist();
sortedHierarchy = {};
local linearizedHierarchy = flatToHierarchy(items);
for _, element in ipairs(linearizedHierarchy) do
table.insert(sortedHierarchy, element);
end
addon.sortedHierarchy = sortedHierarchy;
end
---@param item Item
function GatherPanel_InitItem(item)
local itemCount = 0;
local locale = GetLocale();
if item.updated == nil then
item.updated = 0;
end
if item.name == nil or item.name == "" or item.itemTexture == nil or item.itemQuality == nil or item.locale ~= locale then
-- retry, sometimes heavy load
item.name, _, item.itemQuality, _, _, _, _, _, _, item.itemTexture, _ = GetItemInfo(item.id);
item.locale = locale;
end
item.name = item.name or "";
item.professionQuality = C_TradeSkillUI.GetItemReagentQualityByItemInfo(item.id);
if item.professionQuality then
local professionQualityIcon = Professions.GetIconForQuality(item.professionQuality, true);
local professionQualityMarkup = CreateAtlasMarkup(professionQualityIcon, 16, 16);
item.displayName = item.name .. " " .. professionQualityMarkup;
-- item.displayName = string.format(
-- "%s (%s)",
-- item.name,
-- string.format(
-- addon.T["PROFESSION_QUALITY_MARKUP"], item.professionQuality
-- )
-- );
else
item.displayName = item.name;
end
local characterItemCount = 0;
if IsAddOnLoaded("DataStore_Containers") then
-- only load count from character who is owner of the list, i.e. what is this character missing
local dataStore = _G["DataStore"];
local _, selectedCharacter = decodeItemListId(GATHERPANEL_ITEM_LIST_SELECTION);
for characterName, character in pairs(dataStore:GetCharacters()) do
if (characterName == selectedCharacter and characterName ~= UnitName("player")) then
local bagCount, bankCount, voidCount, reagentBankCount = dataStore:GetContainerItemCount(character, item.id);
characterItemCount = bagCount + bankCount + voidCount + reagentBankCount;
end
end
end
if addon.Variables.user.includeCurrentCharacter then
characterItemCount = characterItemCount + GetItemCount(item.id, true)
end
item.itemCount = characterItemCount;
if addon.Variables.user.includeAllFromRealm then
if IsAddOnLoaded("Altoholic") then
local altoholic = _G["Altoholic"]
item.itemCount = altoholic:GetItemCount(item.id)
else
if IsAddOnLoaded("DataStore_Containers") then
for characterName, character in pairs(DataStore:GetCharacters()) do
if (characterName ~= UnitName("player")) then
local bagCount, bankCount, voidCount, reagentBankCount = DataStore:GetContainerItemCount(character, item.id);
itemCount = itemCount + bagCount + bankCount + voidCount + reagentBankCount;
end
end
end
item.itemCount = itemCount + characterItemCount;
end
end
if addon.Variables.user.cumulateLowerQuality and item.betterItem then
item.itemCount = item.itemCount + item.betterItem.itemCount;
end
if item.itemCountTmp == nil then
item.itemCountTmp = item.itemCount;
end
local goal = 0;
if (item.min > 0) then
if (item.itemCount < item.min) then
item.goal = item.min;
item.goalType = 'min';
else
item.goal = item.max;
item.goalType = 'max';
end
else
item.goal = item.max
item.goalType = 'max';
end
item.progressPercentage = item.goal > 0 and item.itemCount / item.goal or 1;
if item.max == nil then
item.max = item.min;
end
item.progressPercentageMax = item.max > 0 and item.itemCount / item.max or 1;
item.progressPercentageInteger = math.floor(item.progressPercentage * 100);
end
---@param animate boolean
function GatherPanel_UpdateItems(animate)
local entries = getItemlist();
local locale = GetLocale();
local lastItem = nil;
for i = 1, #addon.sortedHierarchy, 1 do
local entryKey = addon.sortedHierarchy[i].id;
if entryKey ~= 0 then
local entry = entries[addon.sortedHierarchy[i].id];
if entry then
entry.betterItem = nil;
entry.lowerItem = nil;
end
end
end
for i = 1, #addon.sortedHierarchy, 1 do
local entryKey = addon.sortedHierarchy[i].id;
local entry = entryKey == 0 and {
type = "GROUP",
tracked = false,
id = 0,
} or entries[entryKey];
if entry.type == "ITEM" then
if lastItem then
if lastItem.name == entry.name then
entry.betterItem = lastItem;
lastItem.lowerItem = entry;
end
end
local oldCount = entry.itemCount or 0;
GatherPanel_InitItem(entry);
local quantityChanged = oldCount ~= entry.itemCount;
if entry.tracked and quantityChanged then
if (entry.tracker) then
GatherPanel_Tracker_UpdateItem(entry, animate);
end
end
if quantityChanged then
if oldCount < entry.itemCount and oldCount < entry.goal then
addon.ObjectiveTracker:UpdateItem(entry, oldCount);
if entry.itemCount >= entry.goal then
addon.ObjectiveMessage:Add(addon.T["GATHERING_OBJECTIVE_COMPLETE"]);
end
local displayName = entry.name;
if entry.professionQuality then
displayName = string.format(
"%s (%s)",
displayName,
string.format(
addon.T["PROFESSION_QUALITY_MARKUP"], entry.professionQuality
)
);
end
local collectedMsg = string.format(
"%s: %i/%i", displayName, math.min(entry.goal, entry.itemCount), entry.goal
);
addon.ObjectiveMessage:Add(collectedMsg);
else
addon.ObjectiveTracker:FullUpdate();
end
end
lastItem = entry;
end
end
end
local function renderItemGroup(itemRow, group, level, initDropdowns)