-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcore.lua
More file actions
2595 lines (2442 loc) · 55.9 KB
/
core.lua
File metadata and controls
2595 lines (2442 loc) · 55.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
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
ThatsMyBis = LibStub("AceAddon-3.0"):NewAddon("ThatsMyBis", "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0")
local LibAceSerializer = LibStub:GetLibrary("AceSerializer-3.0")
local libc = LibStub:GetLibrary("LibCompress")
local frame = CreateFrame( "Frame" )
local AceGUI = LibStub("AceGUI-3.0")
local TMBIcon = LibStub("LibDBIcon-1.0")
local classColorsTable = {
"\124cFFC79C6E",
"\124cFFF58CBA",
"\124cFF0070DE",
"\124cFFABD473",
"\124cFFFF7D0A",
"\124cFFFFF569",
"\124cFFFFFFFF",
"\124cFF9482C9",
"\124cFF69CCF0",
"\124cFFC41E3A"
}
local classToID = {
Warrior = 1,
Paladin = 2,
Shaman = 3,
Hunter = 4,
Druid = 5,
Rogue = 6,
Priest = 7,
Warlock = 8,
Mage = 9,
["Death Knight"] = 10
}
local rankColorsTable = {
S = "\124cFF02F3FF",
A = "\124cFF20FF00",
B = "\124cFFF7FF00",
C = "\124cFFFF8800",
D = "\124cFFFF0078",
F = "\124cFFFF0000",
N = "\124cFFFF0000"
}
local rankColorsTableConvert = {
"S",
"A",
"B",
"C",
"D",
"F",
"N"
}
local altColor = "\124cFFb8b8b8"
local origChatFrame_OnHyperlinkShow = ChatFrame_OnHyperlinkShow
local statusEnableText = "TMB Tooltips is currently: Disabled"
local currentPlayer = UnitName("player")
local TMBLDB = LibStub("LibDataBroker-1.1"):NewDataObject("TMBTooltips", {
type = "data source",
text = "TMB Tooltips",
icon = "Interface\\Icons\\inv_misc_note_01",
OnClick = function(self,button,down)
if button == "LeftButton" then
if ItemListsDB.enabled then
statusEnableText = "TMB Tooltips is currently: Disabled"
ItemListsDB.enabled = false
else
statusEnableText = "TMB Tooltips is currently: Enabled"
ItemListsDB.enabled = true
end
ThatsMyBis:Print(statusEnableText)
elseif button == "RightButton" then
popupConfig()
end
end,
OnTooltipShow = function(tooltip) -- Icon tooltip
tooltip:AddLine("That's My BIS Tooltips")
tooltip:AddLine("Revision : 106-Wrath") -- EDIT TOC and PKMETA
tooltip:AddLine("Left click : Enable/Disable display")
tooltip:AddLine("Right click: Open config")
tooltip:AddLine("Hold Alt : Change tooltip display")
tooltip:AddLine("Chat CMD : /tmb")
tooltip:AddLine("Database ID: " .. ItemListsDB.itemNotes.ID)
end,
})
function showSync()
if syncShown then
return
end
syncShown = true
syncFrame = AceGUI:Create("Frame")
syncFrame:SetTitle("Sync TMB Data")
syncFrame.sizer_se:Hide()
syncFrame.sizer_s:Hide()
syncFrame.sizer_e:Hide()
syncFrame:SetWidth(270)
syncFrame:SetHeight(160)
syncFrame:SetLayout("Flow")
syncFrame:SetStatusText("Ready")
local targetField = AceGUI:Create("EditBox")
targetField:SetLabel("Who do you want to send data to?")
targetField:DisableButton(true)
syncFrame:AddChild(targetField)
local SyncButton = AceGUI:Create("Button")
SyncButton:SetText("Sync")
syncFrame:AddChild(SyncButton)
SyncButton:SetCallback("OnClick", function (obj, button, down)
-- Start sync operation
ThatsMyBis:SendComm(targetField:GetText(), "RTS", ItemListsDB.itemNotes.ID)
end)
syncFrame:SetCallback("OnClose",
function(widget)
AceGUI:Release(widget)
syncShown = false
end
)
end
local function newConfigPanel()
if configShown then
return
end
configShown = true
syncFrame = AceGUI:Create("Frame")
syncFrame:SetTitle("Thats my bis Tooltips")
syncFrame.sizer_se:Hide()
syncFrame.sizer_s:Hide()
syncFrame.sizer_e:Hide()
syncFrame:SetWidth(600)
syncFrame:SetHeight(500)
syncFrame:SetCallback("OnClose",
function(widget)
AceGUI:Release(widget)
configShown = false
end
)
end
function popupConfig()
if frameShown then
return
end
frameShown = true
popup = AceGUI:Create("Frame")
popup:SetTitle("Thats My BIS Tooltips")
popup:SetStatusText(statusEnableText)
popup.sizer_se:Hide()
popup.sizer_s:Hide()
popup.sizer_e:Hide()
popup:SetWidth(600)
popup:SetHeight(370)
local checkboxGroup = AceGUI:Create("SimpleGroup")
checkboxGroup:SetRelativeWidth(0.4)
local textboxGroup = AceGUI:Create("SimpleGroup")
textboxGroup:SetRelativeWidth(0.6)
local checkLabel = AceGUI:Create("Label")
checkLabel:SetText("Tooltip display settings")
checkboxGroup:AddChild(checkLabel)
local check1 = AceGUI:Create("CheckBox")
check1:SetLabel("Show Priority Note")
check1:SetValue(ItemListsDB.displayPrioNote)
checkboxGroup:AddChild(check1)
--[[ local check6 = AceGUI:Create("CheckBox")
check6:SetLabel("Guild Note")
check6:SetValue(ItemListsDB.displayGuildNote)
checkboxGroup:AddChild(check6) ]]
local check2 = AceGUI:Create("CheckBox")
check2:SetLabel("Show Ranks")
check2:SetValue(ItemListsDB.displayRank)
checkboxGroup:AddChild(check2)
local check3 = AceGUI:Create("CheckBox")
check3:SetLabel("Show Wishlists")
check3:SetValue(ItemListsDB.displayWishes)
checkboxGroup:AddChild(check3)
local check4 = AceGUI:Create("CheckBox")
check4:SetLabel("Show Priolists")
check4:SetValue(ItemListsDB.displayPrios)
checkboxGroup:AddChild(check4)
local check5 = AceGUI:Create("CheckBox")
check5:SetLabel("Color alt's gray")
check5:SetValue(ItemListsDB.displayAlts)
checkboxGroup:AddChild(check5)
local check7 = AceGUI:Create("CheckBox")
check7:SetLabel("Hide received wishes")
check7:SetValue(ItemListsDB.hideReceivedWishes)
checkboxGroup:AddChild(check7)
local check8 = AceGUI:Create("CheckBox")
check8:SetLabel("Hide received prios")
check8:SetValue(ItemListsDB.hideReceivedPrios)
checkboxGroup:AddChild(check8)
local check9 = AceGUI:Create("CheckBox")
check9:SetLabel("Always show received")
check9:SetValue(ItemListsDB.forceReceivedList)
checkboxGroup:AddChild(check9)
local check10 = AceGUI:Create("CheckBox")
check10:SetLabel("Disable when not in raid")
check10:SetValue(ItemListsDB.onlyInRaid)
checkboxGroup:AddChild(check10)
local check11 = AceGUI:Create("CheckBox")
check11:SetLabel("Exclude non-raid members")
check11:SetValue(ItemListsDB.onlyRaidMembers)
checkboxGroup:AddChild(check11)
local check12 = AceGUI:Create("CheckBox")
check12:SetLabel("Show Offspec Tag")
check12:SetValue(ItemListsDB.displayOS)
checkboxGroup:AddChild(check12)
-- END OF CHECKBOXES
local slider1 = AceGUI:Create("Slider")
slider1:SetValue(ItemListsDB.maxNames)
slider1:SetSliderValues(1,10,1)
slider1:SetLabel("How many names to display")
slider1:SetRelativeWidth(1)
textboxGroup:AddChild(slider1)
inputfield = AceGUI:Create("MultiLineEditBox")
inputfield:SetLabel("Paste CSV here")
inputfield:SetNumLines(12)
inputfield:SetWidth(320)
local textBuffer, i, lastPaste = {}, 0, 0
local pasted = ""
inputfield.editBox:SetScript("OnShow", function(obj)
obj:SetText("")
pasted = ""
end)
local function clearBuffer(obj1)
obj1:SetScript('OnUpdate', nil)
pasted = strtrim(table.concat(textBuffer))
inputfield.editBox:ClearFocus()
end
inputfield.editBox:SetScript('OnChar', function(obj2, c)
if lastPaste ~= GetTime() then
textBuffer, i, lastPaste = {}, 0, GetTime()
obj2:SetScript('OnUpdate', clearBuffer)
end
i = i + 1
textBuffer[i] = c
end)
inputfield.editBox:SetMaxBytes(2500)
inputfield.editBox:SetScript("OnMouseUp", nil);
inputfield:DisableButton(true)
textboxGroup:AddChild(inputfield)
local parseData = AceGUI:Create("Button")
parseData:SetText("Save CSV Data")
textboxGroup:AddChild(parseData)
popup:SetLayout("Flow")
popup:AddChild(checkboxGroup)
popup:AddChild(textboxGroup)
check1:SetCallback("OnValueChanged", function(obj, evt, val)
ItemListsDB.displayPrioNote = check1:GetValue()
end)
check2:SetCallback("OnValueChanged", function(obj, evt, val)
ItemListsDB.displayRank = check2:GetValue()
end)
check3:SetCallback("OnValueChanged", function(obj, evt, val)
ItemListsDB.displayWishes = check3:GetValue()
end)
check4:SetCallback("OnValueChanged", function(obj, evt, val)
ItemListsDB.displayPrios = check4:GetValue()
end)
check5:SetCallback("OnValueChanged", function(obj, evt, val)
ItemListsDB.displayAlts = check5:GetValue()
end)
--[[ check6:SetCallback("OnValueChanged", function(obj, evt, val)
ItemListsDB.displayGuildNote = check6:GetValue()
end) ]]
check7:SetCallback("OnValueChanged", function(obj, evt, val)
ItemListsDB.hideReceivedWishes = check7:GetValue()
end)
check8:SetCallback("OnValueChanged", function(obj, evt, val)
ItemListsDB.hideReceivedPrios = check8:GetValue()
end)
check9:SetCallback("OnValueChanged", function(obj, evt, val)
ItemListsDB.forceReceivedList = check9:GetValue()
end)
check10:SetCallback("OnValueChanged", function(obj, evt, val)
ItemListsDB.onlyInRaid = check10:GetValue()
end)
check11:SetCallback("OnValueChanged", function(obj, evt, val)
ItemListsDB.onlyRaidMembers = check11:GetValue()
end)
check12:SetCallback("OnValueChanged", function(obj, evt, val)
ItemListsDB.displayOS = check12:GetValue()
end)
slider1:SetCallback("OnMouseUp", function(slid)
ItemListsDB.maxNames = slid:GetValue()
end)
parseData:SetCallback("OnClick", function (obj, button, down)
--message(pasted)
if pasted == "" then return end
obj:SetText(ParseText(pasted))
inputfield:SetText("")
end)
popup:SetCallback("OnClose",
function(widget)
AceGUI:Release(widget)
frameShown = false
end
)
end
function ThatsMyBis:OnInitialize() --Fires when the addon is being set up.
self.db = LibStub("AceDB-3.0"):New("TMBDB", { profile = { minimap = { hide = false, }, }, })
TMBIcon:Register("TMBTooltips", TMBLDB, self.db.profile.minimap)
self:RegisterChatCommand("tmb", "ChatCommands")
self:RegisterComm("TMBSync", ThatsMyBis:OnCommReceived())
end
function ThatsMyBis:OnEnable() --Fires when the addon loads, makes sure there is a db to look at.
if ItemListsDB == nil then ItemListsDB = {} end
if ItemListsDB.itemNotes == nil then ItemListsDB.itemNotes = {} end
if ItemListsDB.enabled == nil then ItemListsDB.enabled = true end
if ItemListsDB.displayPrioNote == nil then ItemListsDB.displayPrioNote = true end
if ItemListsDB.displayGuildNote == nil then ItemListsDB.displayGuildNote = true end
if ItemListsDB.displayRank == nil then ItemListsDB.displayRank = true end
if ItemListsDB.displayWishes == nil then ItemListsDB.displayWishes = true end
if ItemListsDB.displayPrios == nil then ItemListsDB.displayPrios = true end
if ItemListsDB.displayAlts == nil then ItemListsDB.displayAlts = true end
if ItemListsDB.maxNames == nil then ItemListsDB.maxNames = 3 end
if ItemListsDB.hideReceivedWishes == nil then ItemListsDB.hideReceivedWishes = false end
if ItemListsDB.hideReceivedPrios == nil then ItemListsDB.hideReceivedPrios = false end
if ItemListsDB.forceReceivedList == nil then ItemListsDB.forceReceivedList = false end
if ItemListsDB.onlyInRaid == nil then ItemListsDB.onlyInRaid = false end
if ItemListsDB.onlyRaidMembers == nil then ItemListsDB.onlyRaidMembers = false end
if ItemListsDB.itemNotes.ID == nil then ItemListsDB.itemNotes.ID = 0 end
if ItemListsDB.showMemberNotess == nil then ItemListsDB.showMemberNotes = false end
if ItemListsDB.displayOS == nil then ItemListsDB.displayOS = true end
if ItemListsDB.lootTableTest == nil then ItemListsDB.lootTableTest = {} end
if ItemListsDB.enabled then
statusEnableText = "TMB Tooltips is currently: Enabled"
end
self:RegisterEvent("CHAT_MSG_LOOT", "HandleEvent")
end
local function exportLootTable()
local exportString = "dateTime,player,itemID,itemName\n"
for k,v in pairs(ItemListsDB.lootTableTest) do
exportString = exportString .. k .. ","
for garbage,data in pairs(v) do
exportString = exportString .. data .. ","
end
exportString = exportString:sub(1, #exportString - 1) .. "\n"
end
inputfield:SetText(exportString)
inputfield:SetFocus()
inputfield:HighlightText()
end
function ThatsMyBis:HandleEvent(self, event, ...)
local tempLootEntry = {}
--local zone = GetRealZoneText();
local itemLink = string.match(event,"|%x+|Hitem:.-|h.-|h|r")
local itemId, itemName, quality = ParseItemIdOrLink(itemLink)
local LootersName = string.match(event,"%u%l+")
if (LootersName == "You") then
LootersName = UnitName("player");
end
tempLootEntry = {LootersName, itemId, itemName}
if quality and quality >= 6 then
ItemListsDB.lootTableTest[GetServerTime()] = tempLootEntry
ThatsMyBis:Print(GetServerTime(), LootersName, itemId, itemName)
end
end
function ThatsMyBis:ChatCommands(arg)
if arg == "" then
popupConfig()
elseif arg == "minimap" then
self.db.profile.minimap.hide = not self.db.profile.minimap.hide
if self.db.profile.minimap.hide then
TMBIcon:Hide("TMBTooltips")
else
TMBIcon:Show("TMBTooltips")
end
elseif arg == "toggle" then
if ItemListsDB.enabled then
statusEnableText = "TMB Tooltips is currently: Disabled"
ItemListsDB.enabled = false
else
statusEnableText = "TMB Tooltips is currently: Enabled"
ItemListsDB.enabled = true
end
ThatsMyBis:Print(statusEnableText)
elseif arg == "sync" then
showSync()
elseif arg == "test" then
exportLootTable()
elseif arg == "notes" then
ItemListsDB.showMemberNotes = not ItemListsDB.showMemberNotes
else
ThatsMyBis:Print("Thats my BIS command arguments\nminimap - toggle minimap icon\ntoggle - enable/disable function\nno argument - open config\nanything else - show this text")
end
end
local function ModifyItemTooltip( tt ) -- Function for modifying the tooltip
if not ItemListsDB.enabled then return end
if ItemListsDB.onlyInRaid then
if not IsInRaid() then return end
end
local itemName, itemLink = tt:GetItem()
if not itemName then return end
local itemID = select( 1, GetItemInfoInstant( itemName ) )
if itemID == nil then
itemID = tonumber( string.match( itemLink, "item:?(%d+):" ) )
if itemID == nil then
return
end
end
if itemID == 18423 then
itemID = 18422
elseif itemID == 19003 then
itemID = 19002
elseif itemID == 32386 then
itemID = 32385
end
local itemNotes = ItemListsDB.itemNotes[itemID]
if itemNotes == nil then return end -- Item not in DB, escape out of function.
if IsAltKeyDown() == false then --Display something different if alt is held down.
-- %%%%%%%%%%%%%%%%% PRIO NOTES
if ItemListsDB.displayPrioNote or ItemListsDB.displayRank then
local rankData = ""
local rankColorSelect = itemNotes.rank
if (tonumber(rankColorSelect) ~= nil) then
rankColorSelect = rankColorsTableConvert[tonumber(rankColorSelect)]
end
local itemPrioNotes = itemNotes.prioNote or ""
if not ItemListsDB.displayPrioNote then itemPrioNotes = "" end
if itemPrioNotes ~= "" then itemPrioNotes = itemPrioNotes .. " | " end
if ItemListsDB.displayRank and (itemNotes.rank ~= "" and itemNotes.rank ~= nil) then
rankData = "\124cFFD97025Rank: " .. rankColorsTable[rankColorSelect]..itemNotes.rank
end
if rankData ~= "" or itemPrioNotes ~= "" then
tt:AddLine("Prio Notes:")
tt:AddLine("\124cFFFFFFFF" .. itemPrioNotes .. rankData)
else
end
end
-- %%%%%%%%%%%%%%%%% GUILD NOTES
if ItemListsDB.displayGuildNote then
local itemGuildNotes = itemNotes.guildNote
if itemGuildNotes ~= nil and itemGuildNotes ~= "" then
tt:AddLine("Guild Notes:")
tt:AddLine("\124cFFFFFFFF" .. itemGuildNotes )
end
end
-- %%%%%%%%%%%%%%%%% WISHLIST
if ItemListsDB.displayWishes then
local itemWishes = {}
local wishlistString = ""
local smallestKey = 0
local smallestWish = {}
local keyIndex = 1
local totalHiddenWishes = 0
local totalReceivedWishes = 0
if itemNotes.wishlist ~= nil then
for k,v in pairs(itemNotes.wishlist) do
add = false
if ItemListsDB.onlyRaidMembers then
if UnitInRaid(v.character_name) ~= nil then
add = true
end
else
add = true
end
if itemNotes.received ~= null and ItemListsDB.hideReceivedWishes then
for key,value in pairs(itemNotes.received) do
if value.character_name == v.character_name then
add = false
totalReceivedWishes = totalReceivedWishes + 1
end
end
end
if add == true then
itemWishes[keyIndex] = v
keyIndex = keyIndex + 1
else
totalHiddenWishes = totalHiddenWishes + 1
end
end
-- Construct the string to be displayed
for i = 1,ItemListsDB.maxNames,1 do
local smallestOrder = 99999
for k,v in pairs(itemWishes) do
if v.sort_order <= smallestOrder then
smallestKey = k
smallestOrder = v.sort_order
end
end
smallestWish = table.remove(itemWishes,smallestKey)
if smallestWish == nil then break end
local altStatus = ""
local linebreaker = " "
local noteHolder = ""
local OSText = ""
if ItemListsDB.showMemberNotes then
if smallestWish.character_note ~= nil then
noteHolder = " {"..smallestWish.character_note.."} "
end
end
if i % 5 == 0 then linebreaker = "\n" end
if ItemListsDB.displayAlts and smallestWish.character_is_alt == 1 then altStatus = altColor end
if ItemListsDB.displayOS and smallestWish.is_offspec == 1 then OSText = "-OS" end
wishlistString = wishlistString .. classColorsTable[ smallestWish.character_class ] .. smallestWish.character_name .. altStatus .. "[" .. smallestWish.sort_order .. OSText .. "]\124r" .. noteHolder .. linebreaker
end
local optionalString = ""
if totalHiddenWishes-totalReceivedWishes > 0 then
optionalString = optionalString .. totalHiddenWishes-totalReceivedWishes .. " Hidden "
end
if totalReceivedWishes > 0 then
optionalString = optionalString .. totalReceivedWishes .. " Received "
end
if optionalString ~= "" then
tt:AddLine("\124cFFFF8000" .. "Wishes: ( ".. optionalString .. ")" )
else
tt:AddLine("\124cFFFF8000" .. "Wishes:")
end
tt:AddLine( wishlistString )
end
end
-- %%%%%%%%%%%%%%%%% PRIOS
if ItemListsDB.displayPrios then
local itemPrios = {}
local prioListString = ""
local smallestPrioKey = 0
local smallestPrio = {}
local totalHiddenPrios = 0
local totalReceivedPrios = 0
keyIndex = 1
if itemNotes.priolist ~= nil then
for k,v in pairs(itemNotes.priolist) do
add = false
if ItemListsDB.onlyRaidMembers then
if UnitInRaid(v.character_name) ~= nil then
add = true
end
else
add = true
end
if itemNotes.received ~= null and ItemListsDB.hideReceivedPrios then
for key,value in pairs(itemNotes.received) do
if value.character_name == v.character_name then
add = false
totalReceivedPrios = totalReceivedPrios + 1
end
end
end
if add == true then
itemPrios[keyIndex] = v
keyIndex = keyIndex + 1
else
totalHiddenPrios = totalHiddenPrios + 1
end
end
-- Construct the string to be displayed
for i = 1,ItemListsDB.maxNames,1 do
local smallestPrioOrder = 99999
for k,v in pairs(itemPrios) do
if v.sort_order <= smallestPrioOrder then
smallestPrioKey = k
smallestPrioOrder = v.sort_order
end
end
smallestPrio = table.remove(itemPrios,smallestPrioKey)
if smallestPrio == nil then break end
local altStatus = ""
local linebreaker = " "
local noteHolder = ""
local OSText = ""
if ItemListsDB.showMemberNotes then
if smallestPrio.character_note ~= nil then
noteHolder = " {"..smallestPrio.character_note.."} "
end
end
if i % 5 == 0 then linebreaker = "\n" end
if ItemListsDB.displayAlts and smallestPrio.character_is_alt == 1 then altStatus = altColor end
if ItemListsDB.displayOS and smallestPrio.is_offspec == 1 then OSText = "-OS" end
prioListString = prioListString .. classColorsTable[ smallestPrio.character_class ] .. smallestPrio.character_name .. altStatus .. "[" .. smallestPrio.sort_order .. OSText .. "]\124r" .. noteHolder .. linebreaker
end
optionalString = ""
if totalHiddenPrios-totalReceivedPrios > 0 then
optionalString = optionalString .. totalHiddenPrios-totalReceivedPrios .. " Hidden "
end
if totalReceivedPrios > 0 then
optionalString = optionalString .. totalReceivedPrios .. " Received "
end
if optionalString ~= "" then
tt:AddLine("\124cFFFF8000" .. "Prios: ( ".. optionalString .. ")" )
else
tt:AddLine("\124cFFFF8000" .. "Prios:")
end
tt:AddLine( prioListString )
end
end
if ItemListsDB.forceReceivedList == true then
recievedLogic(itemNotes,tt)
end
else
recievedLogic(itemNotes,tt)
end
end
function recievedLogic(inputData,tt)
local itemReceived = inputData.received
local receivedString = ""
if itemReceived ~= nil then
tt:AddLine("Received item:")
-- Construct the string to be displayed
for k,v in pairs(itemReceived) do
if k > ItemListsDB.maxNames then break end
local altStatus = ""
if ItemListsDB.displayAlts and v.character_is_alt == 1 then altStatus = "[Alt]" end
local OSText = ""
if ItemListsDB.displayOS and v.is_offspec == 1 then OSText = "\124cFFFFFFFF[OS]" end
receivedString = receivedString .. altStatus.. OSText .. classColorsTable[ v.character_class ] .. v.character_name .. " "
end
tt:AddLine( receivedString )
end
end
-- //TODO: Affects more than the static item frame. Need to look into this later
--[[ ChatFrame_OnHyperlinkShow = function(...) -- Hook into the static item info window, not the tooltip.
local chatFrame, link, text, button = ...
local result = origChatFrame_OnHyperlinkShow(...)
ShowUIPanel(ItemRefTooltip)
if (not ItemRefTooltip:IsVisible()) then
ItemRefTooltip:SetOwner(UIParent, "ANCHOR_PRESERVE")
end
ModifyItemTooltip(ItemRefTooltip)
ItemRefTooltip:Show(); ItemRefTooltip:Show()
--return result
end ]]
local function InitFrame() --Starts the listener for tooltips
GameTooltip:HookScript( "OnTooltipSetItem", ModifyItemTooltip )
end
function ParseText(input)
if input == nil then return "NoData" end
local headers = {
--All export
"type,raid_group_name,member_name,character_name,character_class,character_is_alt,character_inactive_at,character_note,sort_order,item_name,item_id,is_offspec,note,received_at,import_id,item_note,item_prio_note,item_tier,item_tier_label,created_at,updated_at,",
-- Tailored tmb export
"type,character_name,character_class,character_is_alt,character_inactive_at,character_note,sort_order,item_id,is_offspec,received_at,item_prio_note,item_tier_label,"
}
local parsedLines = {}
local parsedEntries = {}
for line in input:gmatch("([^\n]*)\n?") do -- Extract the lines into seperate entries in an array.
table.insert(parsedLines, line..",")
end
if (not(parsedLines[1] == headers[1] or parsedLines[1] == headers[2])) then return "Wrong CSV header" end -- Validate the header
local headerData = {}
for lineKey,line in pairs(parsedLines) do
entry = {}
if lineKey == 1 then
headerData = ParseCSVLine(parsedLines[lineKey])
else
for key,value in pairs(ParseCSVLine(line)) do
if key == 1 and value == "item_note" then
end
entry[ headerData[key] ] = value
end
table.insert(parsedEntries, entry)
end
end
table.remove(parsedEntries) -- Pop of the malformed last entry.
local noteTable = {}
for k,e in pairs(parsedEntries) do
local tempTable = {}
local tempCharTable = {}
local checkToken = {}
local currentItemID = nil
if e.character_inactive_at == "" then
currentItemID = tonumber(e.item_id)
checkToken = tokens[currentItemID]
if checkToken ~= nil then currentItemID = checkToken end
tempTable = noteTable[ currentItemID ] --Try and load the item element
if tempTable == nil then noteTable[ currentItemID ] = {} end -- Make an array because this is the first time the item is seen
if e.received_at ~= "" then
e.type = "received"
end
if e.type == "wishlist" then
tempCharTable.character_class = classToID[e.character_class]
tempCharTable.character_name = e.character_name
tempCharTable.sort_order = tonumber(e.sort_order)
tempCharTable.character_is_alt = tonumber(e.character_is_alt)
tempCharTable.is_offspec = tonumber(e.is_offspec)
if ItemListsDB.showMemberNotes then
tempCharTable.character_note = e.character_note
end
if tempTable ~= nil then tempTable = tempTable.wishlist end -- Look at the wishlist element if it exist then load it
if tempTable == nil then --If the loaded item is nil then its the first wish for this item so just save it directly
tempTable = {}
table.insert(tempTable,tempCharTable)
else -- Else insert it into the old one before saving.
table.insert(tempTable,tempCharTable)
end
noteTable[currentItemID].wishlist = tempTable
elseif e.type == "prio" then
tempCharTable.character_class = classToID[e.character_class]
tempCharTable.character_name = e.character_name
tempCharTable.sort_order = tonumber(e.sort_order)
tempCharTable.character_is_alt = tonumber(e.character_is_alt)
tempCharTable.is_offspec = tonumber(e.is_offspec)
if ItemListsDB.showMemberNotes then
tempCharTable.character_note = e.character_note
end
if tempTable ~= nil then tempTable = tempTable.priolist end -- Look at the priolist element if it exist then load it
if tempTable == nil then --If the loaded item is nil then its the first wish for this item so just save it directly
tempTable = {}
table.insert(tempTable,tempCharTable)
else -- Else insert it into the old one before saving.
table.insert(tempTable,tempCharTable)
end
noteTable[currentItemID].priolist = tempTable
elseif e.type == "received" then
local skip = false
if noteTable[currentItemID].received ~= nil then
-- Search the array to check for duplicates
for reKey,reEnt in pairs(noteTable[currentItemID].received) do
if reEnt.character_name == e.character_name then
skip = true
break
end
end
end
if not skip then
tempCharTable.character_class = classToID[e.character_class]
tempCharTable.character_name = e.character_name
tempCharTable.character_is_alt = tonumber(e.character_is_alt)
tempCharTable.is_offspec = tonumber(e.is_offspec)
if tempTable ~= nil then tempTable = tempTable.received end -- Look at the recieved element if it exist then load it
if tempTable == nil then --If the loaded item is nil then its the first wish for this item so just save it directly
tempTable = {}
table.insert(tempTable,tempCharTable)
else -- Else insert it into the old one before saving.
table.insert(tempTable,tempCharTable)
end
noteTable[currentItemID].received = tempTable
end
elseif e.type == "item_note" then
noteTable[currentItemID].prioNote = e.item_prio_note
noteTable[currentItemID].guildNote = e.item_note
noteTable[currentItemID].rank = e.item_tier_label
end
end
--
end
local checksum = ""
local serializedTable = LibAceSerializer:Serialize(noteTable)
checksum = libc:fcs16init()
checksum = libc:fcs16update(checksum,serializedTable)
checksum = libc:fcs16final(checksum)
ThatsMyBis:Print("Added data: "..checksum)
noteTable["ID"] = checksum
ItemListsDB["itemNotes"] = noteTable -- Add it to peristent storage
return "Success, data saved"
end
function ParseCSVLine (line,sep)
local res = {}
local pos = 1
sep = sep or ','
while true do
local c = string.sub(line,pos,pos)
if (c == "") then break end
if (c == '"') then
-- quoted value (ignore separator within)
local txt = ""
repeat
local startp,endp = string.find(line,'^%b""',pos)
txt = txt..string.sub(line,startp+1,endp-1)
pos = endp + 1
c = string.sub(line,pos,pos)
if (c == '"') then txt = txt..'"' end
-- check first char AFTER quoted string, if it is another
-- quoted string without separator, then temp it
-- this is the way to "escape" the quote char in a quote. example:
-- value1,"blub""blip""boing",value3 will result in blub"blip"boing for the middle
until (c ~= '"')
table.insert(res,txt)
assert(c == sep or c == "")
pos = pos + 1
else
-- no quotes used, just look for the first separator
local startp,endp = string.find(line,sep,pos)
if (startp) then
table.insert(res,string.sub(line,pos,startp-1))
pos = endp + 1
else
-- no separator found -> use rest of string and terminate
table.insert(res,string.sub(line,pos))
break
end
end
end
return res
end
function ThatsMyBis:OnCommReceived(prefix, serializedMsg, distri, sender)
if prefix == "TMBSync" then
if sender ~= currentPlayer then
if syncShown then
local decompress = libc:Decompress(serializedMsg)
local valid, command, data = LibAceSerializer:Deserialize(decompress)
if valid then
if command == "INFO" then
ThatsMyBis:Print(data)
syncFrame:SetStatusText("Ready")
elseif command == "RTS" then
--Someone is asking if we're ready to recieve, check their id against ours.
if ItemListsDB.itemNotes.ID == data then
ThatsMyBis:SendComm(sender,"INFO", currentPlayer .. " already have this data")
else
ThatsMyBis:SendComm(sender,"RTR","Please donate if you like this addon")
end
elseif command == "RTR" then
--Sender is ready to recieve, Transmit data.
ThatsMyBis:Print("Sending data to " .. sender)
ThatsMyBis:SendComm(sender, "INFO", "You are about to receive TMB data from ".. currentPlayer)
ThatsMyBis:SendComm(sender, "DBID", ItemListsDB.itemNotes.ID)
ThatsMyBis:SendComm(sender, "TABLES", ItemListsDB.itemNotes)
elseif command == "TABLES" then
ItemListsDB.itemNotes = data
ThatsMyBis:Print("ID " .. ItemListsDB.itemNotes.ID .. " have been imported, remember to exit the game gracefully or reload to save it.")
ThatsMyBis:SendComm(sender, "INFO", currentPlayer .. " is now on ID " .. ItemListsDB.itemNotes.ID )
elseif command == "DBID" then
ItemListsDB.itemNotes.ID = data
end
else
ThatsMyBis:Print("Received invalid data, make sure you're all running the latest version.")
end
else
ThatsMyBis:Print(sender .." is trying to send you data, however sync window is not open. Do /tmb sync and have them re-send")
ThatsMyBis:SendComm(sender,"INFO", currentPlayer .." does not have sync window open. Try again")
end
end
end
end
function ThatsMyBis:SendComm(target, command, data )
local serialized = nil
if data then
serialized = LibAceSerializer:Serialize(command, data)
compressed = libc:Compress(serialized)
end
if target == "PARTY" then
ThatsMyBis:SendCommMessage("TMBSync", compressed, target, "BULK",ThatsMyBis.commCallback)
elseif target == "RAID" then
ThatsMyBis:SendCommMessage("TMBSync", compressed, target, "BULK",ThatsMyBis.commCallback)
elseif target == "GUILD" then
ThatsMyBis:SendCommMessage("TMBSync", compressed, target, "BULK",ThatsMyBis.commCallback)
else
ThatsMyBis:SendCommMessage("TMBSync", compressed, "WHISPER", target, "BULK",ThatsMyBis.commCallback)
end
end
function ThatsMyBis:commCallback(num,total)
--syncFrame:SetStatusText("Sending: ".. math.floor(tonumber(num)/1000) .. " of ".. math.floor(tonumber(total)/1000) .. " total")
syncFrame:SetStatusText("Sending: ".. math.floor(tonumber(num)/tonumber(total)*100).."%")
--ThatsMyBis:Print(num,total)
end
function ParseItemIdOrLink(item_link_or_id)
local itemName, itemLink, quality, _, _, class, subclass, _, equipSlot, texture, _, ClassID, SubClassID = GetItemInfo(item_link_or_id)
if itemLink then
--local itemName = string.sub(string.match(itemLink,"%[.+%]"), 2, -2)
local itemString = string.match(itemLink, "item[%-?%d:]+");
local itemId=string.match(itemString,"%d+");
return itemId,itemName,quality
else
return nil
end
end