forked from stpain/guildbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.lua
4303 lines (3766 loc) · 175 KB
/
Core.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
--[==[
Copyright ©2020 Samuel Thomas Pain
The contents of this addon, excluding third-party resources, are
copyrighted to their authors with all rights reserved.
This addon is free to use and the authors hereby grants you the following rights:
1. You may make modifications to this addon for private use only, you
may not publicize any portion of this addon.
2. Do not modify the name of this addon, including the addon folders.
3. This copyright notice shall be included in all copies or substantial
portions of the Software.
All rights not explicitly addressed in this license are reserved by
the copyright holders.
]==]--
--[[
code logic
1 addon loaded = create saved vars
2 play entering world = get player info (faction,race etc)
3 load
scan player professions
scan talents
scan inventory
check privacy
send calendar data
send tradeskill recipes
]]
local addonName, Guildbook = ...
Guildbook.addonLoaded = false
local AceComm = LibStub:GetLibrary("AceComm-3.0")
local LibDeflate = LibStub:GetLibrary("LibDeflate")
local LibSerialize = LibStub:GetLibrary("LibSerialize")
local LCI = LibStub:GetLibrary("LibCraftInfo-1.0")
---------------------------------------------------------------------------------------------------------------------------------------------------------------
--variables
---------------------------------------------------------------------------------------------------------------------------------------------------------------
local locale = GetLocale()
local L = Guildbook.Locales
Guildbook.lastProfTransmit = GetTime()
Guildbook.FONT_COLOUR = '|cff0070DE'
Guildbook.ContextMenu_Separator = "|TInterface/COMMON/UI-TooltipDivider:8:150|t"
Guildbook.ContextMenu_Separator_Wide = "|TInterface/COMMON/UI-TooltipDivider:8:250|t"
Guildbook.PlayerMixin = nil
Guildbook.COMMS_DELAY = 0.0
Guildbook.COMM_LOCK_COOLDOWN = 20.0
Guildbook.GUILD_NAME = nil;
Guildbook.Colours = {
Blue = CreateColor(0.1, 0.58, 0.92, 1),
Orange = CreateColor(0.79, 0.6, 0.15, 1),
Yellow = CreateColor(1.0, 0.82, 0, 1),
LightRed = CreateColor(216/255,69/255,75/255),
BlizzBlue = CreateColor(0,191/255,243/255),
}
for class, t in pairs(Guildbook.Data.Class) do
Guildbook.Colours[class] = CreateColor(t.RGB[1], t.RGB[2], t.RGB[3], 1)
end
---------------------------------------------------------------------------------------------------------------------------------------------------------------
--slash commands
---------------------------------------------------------------------------------------------------------------------------------------------------------------
SLASH_GUILDBOOK1 = '/guildbook'
SLASH_GUILDBOOK2 = '/gbk'
SLASH_GUILDBOOK3 = '/gb'
SlashCmdList['GUILDBOOK'] = function(msg)
--print("["..msg.."]")
if msg == 'open' then
GuildbookUI:Show()
elseif GuildbookUI[msg] then
GuildbookUI:OpenTo(msg)
elseif msg == "version" and Guildbook.version then
Guildbook:PrintMessage(Guildbook.version)
elseif msg == "test" then
end
end
--init, this sets the saved var stuff
--pew, this will trigger a guild roster scan, this creates the db entries for each character and checks them for errors
--load, if the roster scan is successful this will be called and continue loading the addon, this will scan the client character for prof info etc
---------------------------------------------------------------------------------------------------------------------------------------------------------------
--init, this will setup the saved variables first
---------------------------------------------------------------------------------------------------------------------------------------------------------------
function Guildbook:Init()
-- get this open first if debug is on
if GUILDBOOK_GLOBAL and GUILDBOOK_GLOBAL.Debug == true then
Guildbook.DebuggerWindow:Show()
Guildbook.DEBUG('func', 'init', 'debug active')
else
Guildbook.DebuggerWindow:Hide()
end
if GUILDBOOK_GLOBAL then
GuildbookOptionsDebugCB:SetChecked(GUILDBOOK_GLOBAL.Debug and GUILDBOOK_GLOBAL.Debug or false)
end
--register comms
AceComm:Embed(self)
self:RegisterComm('Guildbook', 'ON_COMMS_RECEIVED')
-- this enables us to prevent character model capturing until the player is fully loaded
Guildbook.LoadTime = GetTime()
Guildbook.DEBUG('func', 'init', tostring('Load time '..date("%T")))
-- grab version number
self.version = tonumber(GetAddOnMetadata('Guildbook', "Version"))
self:SendVersionData()
-- this makes the bank/calendar legacy features work
if not self.GuildFrame then
self.GuildFrame = {
--"GuildBankFrame",
"GuildCalendarFrame",
}
end
--self:SetupGuildBankFrame()
self:SetupGuildCalendarFrame()
--create stored variable tables
if GUILDBOOK_GLOBAL == nil or GUILDBOOK_GLOBAL == {} then
GUILDBOOK_GLOBAL = self.Data.DefaultGlobalSettings
Guildbook.DEBUG('func', 'init', 'created global saved variable table')
else
Guildbook.DEBUG('func', 'init', 'global variables exists')
end
if GUILDBOOK_CHARACTER == nil or GUILDBOOK_CHARACTER == {} then
GUILDBOOK_CHARACTER = self.Data.DefaultCharacterSettings
Guildbook.DEBUG('func', 'init', 'created character saved variable table')
else
Guildbook.DEBUG('func', 'init', 'character variables exists')
end
if not GUILDBOOK_GLOBAL.GuildRosterCache then
GUILDBOOK_GLOBAL.GuildRosterCache = {}
Guildbook.DEBUG('func', 'init', 'created guild roster cache')
else
Guildbook.DEBUG('func', 'init', 'guild roster cache exists')
end
if not GUILDBOOK_GLOBAL.Calendar then
GUILDBOOK_GLOBAL.Calendar = {}
Guildbook.DEBUG('func', 'init', 'created global calendar table')
else
Guildbook.DEBUG('func', 'init', 'global calendar table exists')
end
if not GUILDBOOK_GLOBAL.CalendarDeleted then
GUILDBOOK_GLOBAL.CalendarDeleted = {}
Guildbook.DEBUG('func', 'init', 'created global calendar deleted events table')
else
Guildbook.DEBUG('func', 'init', 'global calendar deleted events table exists')
end
if not GUILDBOOK_GLOBAL.LastCalendarTransmit then
GUILDBOOK_GLOBAL.LastCalendarTransmit = GetServerTime()
end
if not GUILDBOOK_GLOBAL.LastCalendarDeletedTransmit then
GUILDBOOK_GLOBAL.LastCalendarDeletedTransmit = GetServerTime()
end
if not GUILDBOOK_GLOBAL["myCharacters"] then
GUILDBOOK_GLOBAL["myCharacters"] = {}
end
if not GUILDBOOK_GLOBAL["myCharacters"][UnitGUID("player")] then
GUILDBOOK_GLOBAL["myCharacters"][UnitGUID("player")] = false;
end
if not GUILDBOOK_GLOBAL['CommsDelay'] then
GUILDBOOK_GLOBAL['CommsDelay'] = 1.0
end
Guildbook.CommsDelaySlider:SetValue(GUILDBOOK_GLOBAL['CommsDelay'])
self.COMMS_DELAY = GUILDBOOK_GLOBAL['CommsDelay']
if not GUILDBOOK_GLOBAL.config then
local lowestRank = GuildControlGetRankName(GuildControlGetNumRanks())
GUILDBOOK_GLOBAL.config = {
privacy = {
shareInventoryMinRank = lowestRank,
shareTalentsMinRank = lowestRank,
shareProfileMinRank = lowestRank,
},
modifyDefaultGuildRoster = true,
showTooltipTradeskills = true,
showTooltipTradeskillsRecipes = true,
showTooltipTradeskillsRecipesForCharacter = false,
showMinimapButton = true,
showMinimapCalendarButton = true,
showTooltipCharacterInfo = true,
showTooltipMainCharacter = true,
showTooltipMainSpec = true,
showTooltipProfessions = true,
parsePublicNotes = false,
showInfoMessages = true,
blockCommsDuringCombat = false,
blockCommsDuringInstance = false,
}
Guildbook.DEBUG('func', 'init', "created default config table")
end
if GUILDBOOK_GLOBAL.config.showInfoMessages == nil then
GUILDBOOK_GLOBAL.config.showInfoMessages = true
Guildbook.DEBUG('func', 'init', "no info message value, adding as true")
GuildbookOptionsShowInfoMessages:SetChecked(true)
end
if GUILDBOOK_GLOBAL.config.blockCommsDuringCombat == nil then
GUILDBOOK_GLOBAL.config.blockCommsDuringCombat = true;
Guildbook.DEBUG('func', 'init', "no blockCommsDuringCombat, adding as true")
GuildbookOptionsBlockCommsDuringCombat:SetChecked(true)
end
if GUILDBOOK_GLOBAL.config.blockCommsDuringInstance == nil then
GUILDBOOK_GLOBAL.config.blockCommsDuringInstance = true;
Guildbook.DEBUG('func', 'init', "no blockCommsDuringInstance, adding as true")
GuildbookOptionsBlockCommsDuringInstance:SetChecked(true)
end
local config = GUILDBOOK_GLOBAL.config
GuildbookOptionsTooltipTradeskill:SetChecked(config.showTooltipTradeskills and config.showTooltipTradeskills or false)
GuildbookOptionsTooltipTradeskillRecipes:SetChecked(config.showTooltipTradeskillsRecipes and config.showTooltipTradeskillsRecipes or false)
GuildbookOptionsTooltipTradeskillRecipesForCharacter:SetChecked(config.showTooltipTradeskillsRecipesForCharacter and config.showTooltipTradeskillsRecipesForCharacter or false)
GuildbookOptionsShowMinimapButton:SetChecked(config.showMinimapButton)
GuildbookOptionsShowMinimapCalendarButton:SetChecked(config.showMinimapCalendarButton)
GuildbookOptionsTooltipInfo:SetChecked(config.showTooltipCharacterInfo)
GuildbookOptionsTooltipInfoMainSpec:SetChecked(config.showTooltipMainSpec)
GuildbookOptionsTooltipInfoProfessions:SetChecked(config.showTooltipProfessions)
GuildbookOptionsTooltipInfoMainCharacter:SetChecked(config.showTooltipMainCharacter)
GuildbookOptionsShowInfoMessages:SetChecked(config.showInfoMessages)
GuildbookOptionsBlockCommsDuringCombat:SetChecked(config.blockCommsDuringCombat)
GuildbookOptionsBlockCommsDuringInstance:SetChecked(config.blockCommsDuringInstance)
if config.showTooltipCharacterInfo == false then
GuildbookOptionsTooltipInfoMainSpec:Disable()
GuildbookOptionsTooltipInfoProfessions:Disable()
GuildbookOptionsTooltipInfoMainCharacter:Disable()
else
GuildbookOptionsTooltipInfoMainSpec:Enable()
GuildbookOptionsTooltipInfoProfessions:Enable()
GuildbookOptionsTooltipInfoMainCharacter:Enable()
end
GameTooltip:HookScript("OnTooltipSetItem", function(self)
if not GUILDBOOK_GLOBAL then
return;
end
local name, link = GameTooltip:GetItem()
local character = Guildbook:GetCharacterFromCache(UnitGUID("player"))
if not character then
return;
end
if link then
local itemID = GetItemInfoInstant(link)
if itemID then
if GUILDBOOK_GLOBAL.config and GUILDBOOK_GLOBAL.config.showTooltipTradeskills and Guildbook.tradeskillRecipes then
local headerAdded = false;
local profs = {}
for k, recipe in ipairs(Guildbook.tradeskillRecipes) do
if recipe.reagents then
for id, _ in pairs(recipe.reagents) do
if id == itemID then
if headerAdded == false then
--self:AddLine(" ")
self:AddLine(Guildbook.ContextMenu_Separator_Wide)
self:AddLine(L["TOOLTIP_ITEM_RECIPE_HEADER"])
headerAdded = true;
end
if not profs[recipe.profession] then
profs[recipe.profession] = true
if GUILDBOOK_GLOBAL.config.showTooltipTradeskillsRecipes then
self:AddLine(" ")
end
self:AddLine(Guildbook.Data.Profession[recipe.profession].FontStringIconMEDIUM.." "..recipe.profession)
end
if GUILDBOOK_GLOBAL.config.showTooltipTradeskillsRecipesForCharacter then
if character.Profession1 and (character.Profession1 == recipe.profession) then
self:AddLine(recipe.name, 1,1,1,1)
elseif character.Profession2 and (character.Profession2 == recipe.profession) then
self:AddLine(recipe.name, 1,1,1,1)
end
else
if GUILDBOOK_GLOBAL.config.showTooltipTradeskillsRecipes then
self:AddLine(recipe.name, 1,1,1,1)
end
end
end
end
end
end
if headerAdded == true then
self:AddLine(Guildbook.ContextMenu_Separator_Wide)
--self:AddLine(" ")
end
end
end
-- this is for my own personal benefit remove for releases
-- local gold = select(11, GetItemInfo(link))
-- self:AddLine(GetCoinTextureString(gold))
end
end)
local tooltipIcon = CreateFrame("FRAME", "GuildbookTooltipIcon")
tooltipIcon:SetSize(1,1)
tooltipIcon.icon = tooltipIcon:CreateTexture(nil, "BACKGROUND")
tooltipIcon.icon:SetAllPoints()
-- hook the tooltip for guild characters
GameTooltip:HookScript('OnTooltipSetUnit', function(self)
if not GUILDBOOK_GLOBAL then
return;
end
if GUILDBOOK_GLOBAL.config.showTooltipCharacterInfo == false then
return;
end
local _, unit = self:GetUnit()
local guid = unit and UnitGUID(unit) or nil
if guid and guid:find('Player') then
local character = Guildbook:GetCharacterFromCache(guid)
if not character then
return;
end
self:AddLine(" ")
self:AddLine('Guildbook:', 0.00, 0.44, 0.87, 1)
if GUILDBOOK_GLOBAL.config.showTooltipMainSpec == true then
if character.MainSpec then
local icon = Guildbook:GetClassSpecAtlasName(character.Class, character.MainSpec)
local iconString = CreateAtlasMarkup(icon, 24,24)
self:AddLine(iconString.. " |cffffffff"..character.MainSpec)
end
end
if GUILDBOOK_GLOBAL.config.showTooltipProfessions == true then
if character.Profession1 ~= '-' and Guildbook.Data.Profession[character.Profession1] then
self:AddDoubleLine(character.Profession1, character.Profession1Level, 1,1,1,1,1,1,1,1)
end
if character.Profession2 ~= '-' and Guildbook.Data.Profession[character.Profession2] then
self:AddDoubleLine(character.Profession2, character.Profession2Level, 1,1,1,1,1,1,1,1)
end
end
--self:AddTexture(Guildbook.Data.Class[character.Class].Icon,{width = 36, height = 36})
if 1 == 1 then
if character.profile and character.profile.realBio then
--self:AddLine(" ")
self:AddLine(Guildbook.Colours.Orange:WrapTextInColorCode(character.profile.realBio), 1,1,1,true)
end
end
if GUILDBOOK_GLOBAL.config.showTooltipMainCharacter == true then
if character.MainCharacter then
local main = Guildbook:GetCharacterFromCache(character.MainCharacter)
if main then
C_Timer.After(0.1, function()
self:AppendText(" ["..Guildbook.Colours[main.Class]:WrapTextInColorCode(main.Name).."]")
end)
end
end
end
end
end)
end
function Guildbook:PLAYER_ENTERING_WORLD()
Guildbook.DEBUG("event", "PLAYER_ENTERING_WORLD", "")
if not GUILDBOOK_GLOBAL then
Guildbook.DEBUG("func", "PEW", "GUILDBOOK_GLOBAL is nil or false")
return;
end
-- store some info, used for character models, faction textures etc
self.player = {
faction = nil,
race = nil,
}
C_Timer.After(1.0, function()
if not Guildbook.PlayerMixin then
Guildbook.PlayerMixin = PlayerLocation:CreateFromGUID(UnitGUID('player'))
else
Guildbook.PlayerMixin:SetGUID(UnitGUID('player'))
end
if Guildbook.PlayerMixin:IsValid() then
local name = C_PlayerInfo.GetName(Guildbook.PlayerMixin)
-- double check mixin
if not name then
return
end
local raceID = C_PlayerInfo.GetRace(Guildbook.PlayerMixin)
self.player.race = C_CreatureInfo.GetRaceInfo(raceID).clientFileString:upper()
self.player.faction = C_CreatureInfo.GetFactionInfo(raceID).groupTag
end
end)
GuildRoster() -- this will trigger a roster scan but we set addonLoaded as false at top of file to skip the auto roster scan so this is first scan
C_Timer.After(3.0, function()
local guildName = self:GetGuildName()
if not guildName then
Guildbook.DEBUG("event", "PEW", "not in a guild or no guild name")
return -- if not in a guild just exit for now, all saved vars have been created and the player race/faction stored for the session
end
self:ScanGuildRoster(function()
Guildbook:Load() -- once the roster has been scanned continue to load, its a bit meh but it means we get a full roster scan before loading
end)
end)
self.EventFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
end
--[[
working on reducing the chat spam i've noticed during the addon loading
so far ive adjust the character data by removing profession info
talents no longer send updates as this broke privacy rules
]]
function Guildbook:Load()
Guildbook.DEBUG("func", "Load", "loading addon")
--- update the per character saved var with current data, THESE CALLS DO NOT SEND ANY COMMS
self:GetPaperDollStats()
self:GetCharacterTalentInfo("primary")
-- this will make sure rank changes are handled, just set any privacy rule to the lowest rank if its wrong
self:CheckPrivacyRankSettings()
-- scan for prof data and update online guild members, THIS DOES SEND COMMS including prof name, level, spec and the secondary prof levels but NOT RECIPE DATA
self:GetCharacterProfessions()
local ldb = LibStub("LibDataBroker-1.1")
self.MinimapButton = ldb:NewDataObject('GuildbookMinimapIcon', {
type = "data source",
icon = 134068,
OnClick = function(self, button)
if button == "RightButton" then
if InterfaceOptionsFrame:IsVisible() then
InterfaceOptionsFrame:Hide()
else
InterfaceOptionsFrame_OpenToCategory(addonName)
InterfaceOptionsFrame_OpenToCategory(addonName)
end
elseif button == 'MiddleButton' then
ToggleFriendsFrame(3)
elseif button == "LeftButton" then
if GuildbookUI then
if GuildbookUI:IsVisible() then
GuildbookUI:Hide()
else
GuildbookUI:Show()
end
end
end
end,
OnTooltipShow = function(tooltip)
if not tooltip or not tooltip.AddLine then return end
tooltip:AddLine(tostring('|cff0070DE'..addonName))
tooltip:AddDoubleLine(L["MINIMAP_TOOLTIP_LEFTCLICK"])
tooltip:AddDoubleLine(L["MINIMAP_TOOLTIP_LEFTCLICK_SHIFT"])
tooltip:AddDoubleLine(L["MINIMAP_TOOLTIP_RIGHTCLICK"])
tooltip:AddDoubleLine(L["MINIMAP_TOOLTIP_MIDDLECLICK"])
end,
})
self.MinimapIcon = LibStub("LibDBIcon-1.0")
if not GUILDBOOK_GLOBAL['MinimapButton'] then GUILDBOOK_GLOBAL['MinimapButton'] = {} end
self.MinimapIcon:Register('GuildbookMinimapIcon', self.MinimapButton, GUILDBOOK_GLOBAL['MinimapButton'])
self.MinimapCalendarButton = ldb:NewDataObject('GuildbookMinimapCalendarIcon', {
type = "data source",
icon = 134939,
OnClick = function(self, button)
if button == "RightButton" then
if self.flyout and self.flyout:IsVisible() then
self.flyout:Hide()
end
if self.flyout then
self.flyout.delayTimer = 2.0;
self.flyout:Show()
GameTooltip:Hide()
GameTooltip_SetDefaultAnchor(GameTooltip, UIParent)
end
else
GuildbookUI:OpenTo("calendar")
Guildbook.GuildFrame.GuildCalendarFrame:ClearAllPoints()
Guildbook.GuildFrame.GuildCalendarFrame:SetParent(GuildbookUI.calendar)
Guildbook.GuildFrame.GuildCalendarFrame:SetPoint("TOPLEFT", 0, -26) --this has button above the frame so lower it a bit
Guildbook.GuildFrame.GuildCalendarFrame:SetPoint("BOTTOMRIGHT", -2, 0)
Guildbook.GuildFrame.GuildCalendarFrame:Show()
Guildbook.GuildFrame.GuildCalendarFrame.EventFrame:ClearAllPoints()
Guildbook.GuildFrame.GuildCalendarFrame.EventFrame:SetPoint('TOPLEFT', GuildbookUI.calendar, 'TOPRIGHT', 4, 50)
Guildbook.GuildFrame.GuildCalendarFrame.EventFrame:SetPoint('BOTTOMRIGHT', GuildbookUI.calendar, 'BOTTOMRIGHT', 254, 0)
end
end,
OnTooltipShow = function(tooltip)
if not tooltip or not tooltip.AddLine then return end
local now = date('*t')
tooltip:AddLine('Guildbook')
tooltip:AddLine(string.format("%s %s %s", now.day, Guildbook.Data.Months[now.month], now.year), 1,1,1,1)
tooltip:AddLine(L["MINIMAP_CALENDAR_RIGHTCLICK"], 0.1, 0.58, 0.92, 1)
-- get events for next 7 days
local upcomingEvents = Guildbook:GetCalendarEvents(time(now), 7)
if upcomingEvents and next(upcomingEvents) then
tooltip:AddLine(' ')
tooltip:AddLine(L['Events'])
for k, event in ipairs(upcomingEvents) do
tooltip:AddDoubleLine(event.title, string.format("%s %s", event.date.day, Guildbook.Data.Months[event.date.month]), 1,1,1,1,1,1,1,1)
end
end
end,
})
self.MinimapCalendarIcon = LibStub("LibDBIcon-1.0")
if not GUILDBOOK_GLOBAL['MinimapCalendarButton'] then GUILDBOOK_GLOBAL['MinimapCalendarButton'] = {} end
self.MinimapCalendarIcon:Register('GuildbookMinimapCalendarIcon', self.MinimapCalendarButton, GUILDBOOK_GLOBAL['MinimapCalendarButton'])
local minimapCalendarButton = _G['LibDBIcon10_GuildbookMinimapCalendarIcon']
for i = 1, minimapCalendarButton:GetNumRegions() do
local region = select(i, minimapCalendarButton:GetRegions())
if (region:GetObjectType() == 'Texture') then
region:Hide()
end
end
-- modify the minimap icon to match the blizz calendar button
minimapCalendarButton:SetSize(44,44)
minimapCalendarButton:SetNormalTexture("Interface\\Calendar\\UI-Calendar-Button")
minimapCalendarButton:GetNormalTexture():SetTexCoord(0.0, 0.390625, 0.0, 0.78125)
minimapCalendarButton:SetPushedTexture("Interface\\Calendar\\UI-Calendar-Button")
minimapCalendarButton:GetPushedTexture():SetTexCoord(0.5, 0.890625, 0.0, 0.78125)
minimapCalendarButton:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight", "ADD")
minimapCalendarButton.DateText = minimapCalendarButton:CreateFontString(nil, 'OVERLAY', 'GameFontBlack')
minimapCalendarButton.DateText:SetPoint('CENTER', -1, -1)
minimapCalendarButton.DateText:SetText(date('*t').day)
-- setup a ticker to update the date, kinda overkill maybe ?
C_Timer.NewTicker(1, function()
minimapCalendarButton.DateText:SetText(date('*t').day)
end)
-- force the size to be bigger, maybe not worth it but maybe
-- minimapCalendarButton:SetScript("OnUpdate", function(self)
-- self:SetSize(44,44)
-- end)
minimapCalendarButton.flyout = GuildbookMinimapCalendarDropdown
minimapCalendarButton.flyout:SetParent(minimapCalendarButton)
minimapCalendarButton.flyout:ClearAllPoints()
minimapCalendarButton.flyout:SetPoint("TOPRIGHT", -5, -5)
minimapCalendarButton.menu = {
{
text = L["CHAT"],
func = function()
GuildbookUI:OpenTo("chat")
end,
},
{
text = L["ROSTER"],
func = function()
GuildbookUI:OpenTo("roster")
end,
},
{
text = L["TRADESKILLS"],
func = function()
GuildbookUI:OpenTo("tradeskills")
end,
},
{
text = L["OPEN_PROFILE"],
func = function()
GuildbookUI:Show()
GuildbookUI:OpenTo("profiles")
GuildbookUI.profiles:LoadCharacter("player")
end,
},
{
text = L["OPTIONS"],
func = function()
InterfaceOptionsFrame_OpenToCategory(addonName)
InterfaceOptionsFrame_OpenToCategory(addonName)
end,
},
}
local config = GUILDBOOK_GLOBAL.config
GuildbookOptionsModifyDefaultGuildRoster:SetChecked(config.modifyDefaultGuildRoster == true and true or false)
if config.modifyDefaultGuildRoster == true then
self:ModBlizzUI()
end
if config.showMinimapButton == false then
self.MinimapIcon:Hide('GuildbookMinimapIcon')
Guildbook.DEBUG('func', "Load", 'minimap icon saved var setting: false, hiding minimap button')
end
if config.showMinimapCalendarButton == false then
self.MinimapCalendarIcon:Hide('GuildbookMinimapCalendarIcon')
Guildbook.DEBUG('func', "Load", 'minimap calendar icon saved var setting: false, hiding minimap calendar button')
end
Guildbook:SendPrivacyInfo(nil, "GUILD")
Guildbook.DEBUG("func", "Load", "sending privacy settings")
---initiate the tradeskill recipe/item request process - this isnt a great method and i plan to change this by using another addon to hold the data
self.recipeIdsQueried, self.craftIdsQueried = {}, {}
C_Timer.After(4, function()
-- check the extra addon SV
if not GUILDBOOK_TSDB then
GUILDBOOK_TSDB = {}
end
if not GUILDBOOK_TSDB.recipeItems then
GUILDBOOK_TSDB.recipeItems = {}
Guildbook.DEBUG('tsdb', 'init', "created guildbook tradeskill database for items recipes")
end
if not GUILDBOOK_TSDB.enchantItems then
GUILDBOOK_TSDB.enchantItems = {}
Guildbook.DEBUG('tsdb', 'init', "created guildbook tradeskill database for enchanting recipes")
end
self:RequestTradeskillData()
Guildbook.DEBUG("func", "Load", [[requesting tradeskill recipe\item data]])
end)
---request calendar data, using a 4s stagger to allow all comms to send
C_Timer.After(2, function()
Guildbook:SendGuildCalendarEvents()
Guildbook.DEBUG("func", "Load", "send calendar events")
end)
C_Timer.After(6, function()
Guildbook:SendGuildCalendarDeletedEvents()
Guildbook.DEBUG("func", "Load", "send deleted calendar events")
end)
C_Timer.After(10, function()
Guildbook:RequestGuildCalendarEvents()
Guildbook.DEBUG("func", "Load", "requested calendar events")
end)
C_Timer.After(14, function()
Guildbook:RequestGuildCalendarDeletedEvents()
Guildbook.DEBUG("func", "Load", "requested deleted calendar events")
end)
--TODO: update this to new db comms
---check and send profession recipe data
local prof1 = self:GetCharacterInfo(UnitGUID("player"), "Profession1")
if Guildbook.Data.Profession[prof1] then
if GUILDBOOK_CHARACTER[prof1] then
C_Timer.After(18, function()
self:DB_SendCharacterData(UnitGUID("player"), prof1, GUILDBOOK_CHARACTER[prof1], "GUILD", nil, "NORMAL")
Guildbook.DEBUG("func", "Load", string.format("send prof recipes for %s", prof1))
end)
end
end
local prof2 = self:GetCharacterInfo(UnitGUID("player"), "Profession2")
if Guildbook.Data.Profession[prof2] then
if GUILDBOOK_CHARACTER[prof2] then
C_Timer.After(22, function()
self:DB_SendCharacterData(UnitGUID("player"), prof2, GUILDBOOK_CHARACTER[prof2], "GUILD", nil, "NORMAL")
Guildbook.DEBUG("func", "Load", string.format("send prof recipes for %s", prof2))
end)
end
end
if GUILDBOOK_GLOBAL.showUpdateNews == nil then
GUILDBOOK_GLOBAL.showUpdateNews = true;
end
if GUILDBOOK_GLOBAL.showUpdateNews == true then
StaticPopup_Show('GuildbookUpdates', self.version)
end
self.addonLoaded = true
self.GUILD_NAME = self:GetGuildName()
--GUILDBOOK_GLOBAL.guildBankRemoved = nil
-- quick clean up
if GUILDBOOK_TSDB and GUILDBOOK_TSDB.enchantItems then
for _, recipe in pairs(GUILDBOOK_TSDB.enchantItems) do
recipe.charactersWithRecipe = nil
end
end
if GUILDBOOK_TSDB and GUILDBOOK_TSDB.recipeItems then
for _, recipe in pairs(GUILDBOOK_TSDB.recipeItems) do
recipe.charactersWithRecipe = nil
end
end
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- functions
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
local localProfNames = tInvert(Guildbook.ProfessionNames[locale])
---return the english name for a profession
---@param prof string the profession to convert back to english
---@return any
function Guildbook:GetEnglishProf(prof)
local id = localProfNames[prof]
if id then
return Guildbook.ProfessionNames.enUS[id]
end
end
---return the localized name of a profession
---@param prof string the profession to localize
---@return any
function Guildbook:GetLocaleProf(prof)
for id, name in pairs(self.ProfessionNames["enUS"]) do
if name == prof then
return self.ProfessionNames[locale][id]
end
end
return prof;
end
---return the atlas name for the specified class and spec, this function will handle any differences between Guildbook and the in game atlas names
---@param class string the characters class, or the class to use for the atlas
---@param spec string the characters spec, or the spec to use for the atlas
---@return string atlas the string for the atlas to use
function Guildbook:GetClassSpecAtlasName(class, spec)
-- if none then
-- --Mobile-MechanicIcon-Slowing questlegendaryturnin Icon-Death
-- end
local c, s = class, spec
if class == "SHAMAN" then
if spec == "Warden" then
c = "WARRIOR"
s = "Protection"
end
elseif class == "DEATHKNIGHT" then
if spec == "Frost (Tank)" then
s = "Frost"
end
else
if spec == "Bear" then
s = "Guardian"
elseif spec == "Cat" then
s = "Feral"
elseif spec == "Beast Master" or spec == "BeastMaster" then
s = "BeastMastery"
elseif spec == "Combat" then
s = "Outlaw"
end
end
if c == nil and s == nil then
return "questlegendaryturnin"
end
return string.format("GarrMission_ClassIcon-%s-%s", c, s)
end
function Guildbook.CapitalizeString(s)
if type(s) == "string" then
return string.gsub(s, '^%a', string.upper)
end
end
function Guildbook:MakeFrameMoveable(frame)
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
end
--- return the players guild name if they belong to one
function Guildbook:GetGuildName()
if IsInGuild() and GetGuildInfo("player") then
local guildName, _, _, _ = GetGuildInfo('player')
return guildName
end
end
--- print a message
-- @param msg string the message to print
function Guildbook:PrintMessage(msg)
if not GUILDBOOK_GLOBAL then
return;
end
if not GUILDBOOK_GLOBAL.config then
return;
end
if GUILDBOOK_GLOBAL.config.showInfoMessages == true then
print(string.format('[%sGuildbook|r] %s', Guildbook.FONT_COLOUR, msg))
end
end
local helperIcons = 1
---create and return a yellow 'i' icon with a mouseover tooltip
---@param parent any global frame name or string frame name
---@param relTo any global frame name or string frame name
---@param anchor string anchor point
---@param relPoint string anchor point
---@param x number x offset
---@param y number y offset
---@param tooltiptext string text to display in tooltip
---@return ... frame the icon frame
function Guildbook:CreateHelperIcon(parent, anchor, relTo, relPoint, x, y, tooltiptext)
local f = CreateFrame('FRAME', tostring('GuildbookHelperIcons'..helperIcons), parent)
f:SetPoint(anchor, relTo, relPoint, x, y)
f:SetSize(20, 20)
f.texture = f:CreateTexture('$parentTexture', 'ARTWORK')
f.texture:SetAllPoints(f)
f.texture:SetTexture(374216)
f:SetScript('OnEnter', function(self)
GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT')
GameTooltip:AddLine(tooltiptext)
GameTooltip:Show()
end)
f:SetScript('OnLeave', function(self)
GameTooltip_SetDefaultAnchor(GameTooltip, UIParent)
end)
helperIcons = helperIcons + 1
return f
end
---format number to 2dp for character stat data/display
---@param num number the number value to format
---@return ... number the formatted number or 1
function Guildbook:FormatNumberForCharacterStats(num)
if type(num) == 'number' then
local trimmed = string.format("%.2f", num)
return tonumber(trimmed)
else
return 1
end
end
---get guild calendar events between given range
---@param start number the number representing the start date/time as returned by time()
---@param duration number the duration of the range, expressed as number of days
---@return table events table of events
function Guildbook:GetCalendarEvents(start, duration)
if type(self.GUILD_NAME) ~= "string" then
return
end
local events = {}
local today = date('*t')
local finish = (time(today) + (60*60*24*duration))
if GUILDBOOK_GLOBAL and GUILDBOOK_GLOBAL['Calendar'] and GUILDBOOK_GLOBAL['Calendar'][guildName] then
for k, event in pairs(GUILDBOOK_GLOBAL['Calendar'][guildName]) do
--local eventTimeStamp = time(event.date)
if time(event.date) >= start and time(event.date) <= finish then
table.insert(events, event)
Guildbook.DEBUG('func', 'Guildbook:GetCalendarEvents', 'found: '..event.title)
end
--end
end
end
return events
end
local spellSchools = {
[2] = 'Holy',
[3] = 'Fire',
[4] = 'Nature',
[5] = 'Frost',
[6] = 'Shadow',
[7] = 'Arcane',
}
local statIDs = {
[1] = 'Strength',
[2] = 'Agility',
[3] = 'Stamina',
[4] = 'Intellect',
[5] = 'Spirit',
}
function Guildbook:GetPaperDollStats()
if GUILDBOOK_CHARACTER then
GUILDBOOK_CHARACTER['PaperDollStats'] = {}
local numSkills = GetNumSkillLines();
local skillIndex = 0;
local currentHeader = nil;
for i = 1, numSkills do
local skillName = select(1, GetSkillLineInfo(i));
local isHeader = select(2, GetSkillLineInfo(i));
if isHeader ~= nil and isHeader then
currentHeader = skillName;
else
if (currentHeader == "Weapon Skills" and skillName == 'Defense') then
skillIndex = i;
break;
end
end
end
local baseDef, modDef;
if (skillIndex > 0) then
baseDef = select(4, GetSkillLineInfo(skillIndex));
modDef = select(6, GetSkillLineInfo(skillIndex));
else
baseDef, modDef = UnitDefense('player')
end
local posBuff = 0;
local negBuff = 0;
if ( modDef > 0 ) then
posBuff = modDef;
elseif ( modDef < 0 ) then
negBuff = modDef;
end
GUILDBOOK_CHARACTER['PaperDollStats'].Defence = {
Base = self:FormatNumberForCharacterStats(baseDef),
Mod = self:FormatNumberForCharacterStats(modDef),
}
local baseArmor, effectiveArmor, armr, posBuff, negBuff = UnitArmor('player');
GUILDBOOK_CHARACTER['PaperDollStats'].Armor = self:FormatNumberForCharacterStats(baseArmor)
GUILDBOOK_CHARACTER['PaperDollStats'].Block = self:FormatNumberForCharacterStats(GetBlockChance());
GUILDBOOK_CHARACTER['PaperDollStats'].Parry = self:FormatNumberForCharacterStats(GetParryChance());
GUILDBOOK_CHARACTER['PaperDollStats'].ShieldBlock = self:FormatNumberForCharacterStats(GetShieldBlock());
GUILDBOOK_CHARACTER['PaperDollStats'].Dodge = self:FormatNumberForCharacterStats(GetDodgeChance());
--local expertise, offhandExpertise, rangedExpertise = GetExpertise();
GUILDBOOK_CHARACTER['PaperDollStats'].Expertise = self:FormatNumberForCharacterStats(GetExpertise()); --will display mainhand expertise but it stores offhand expertise as well, need to find a way to access it
--local base, casting = GetManaRegen();
--to work with all versions we have to adjust the values we get
if WOW_PROJECT_ID == WOW_PROJECT_CLASSIC then
GUILDBOOK_CHARACTER['PaperDollStats'].SpellHit = self:FormatNumberForCharacterStats(GetSpellHitModifier());
GUILDBOOK_CHARACTER['PaperDollStats'].MeleeHit = self:FormatNumberForCharacterStats(GetHitModifier());
GUILDBOOK_CHARACTER['PaperDollStats'].RangedHit = self:FormatNumberForCharacterStats(GetHitModifier());
elseif WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC then
GUILDBOOK_CHARACTER['PaperDollStats'].SpellHit = self:FormatNumberForCharacterStats(GetCombatRatingBonus(CR_HIT_SPELL) + GetSpellHitModifier());
GUILDBOOK_CHARACTER['PaperDollStats'].MeleeHit = self:FormatNumberForCharacterStats(GetCombatRatingBonus(CR_HIT_MELEE) + GetHitModifier());
GUILDBOOK_CHARACTER['PaperDollStats'].RangedHit = self:FormatNumberForCharacterStats(GetCombatRatingBonus(CR_HIT_RANGED));
else
end
GUILDBOOK_CHARACTER['PaperDollStats'].RangedCrit = self:FormatNumberForCharacterStats(GetRangedCritChance());
GUILDBOOK_CHARACTER['PaperDollStats'].MeleeCrit = self:FormatNumberForCharacterStats(GetCritChance());
GUILDBOOK_CHARACTER['PaperDollStats'].Haste = self:FormatNumberForCharacterStats(GetHaste());
local base, casting = GetManaRegen()
GUILDBOOK_CHARACTER['PaperDollStats'].ManaRegen = base and self:FormatNumberForCharacterStats(base) or 0;
GUILDBOOK_CHARACTER['PaperDollStats'].ManaRegenCasting = casting and self:FormatNumberForCharacterStats(casting) or 0;
local minCrit = 100
for id, school in pairs(spellSchools) do
if GetSpellCritChance(id) < minCrit then
minCrit = GetSpellCritChance(id)
end
GUILDBOOK_CHARACTER['PaperDollStats']['SpellDmg'..school] = self:FormatNumberForCharacterStats(GetSpellBonusDamage(id));
GUILDBOOK_CHARACTER['PaperDollStats']['SpellCrit'..school] = self:FormatNumberForCharacterStats(GetSpellCritChance(id));
end
GUILDBOOK_CHARACTER['PaperDollStats'].SpellCrit = self:FormatNumberForCharacterStats(minCrit)
GUILDBOOK_CHARACTER['PaperDollStats'].HealingBonus = self:FormatNumberForCharacterStats(GetSpellBonusHealing());
local lowDmg, hiDmg, offlowDmg, offhiDmg, posBuff, negBuff, percentmod = UnitDamage("player");
local mainSpeed, offSpeed = UnitAttackSpeed("player");
local mlow = (lowDmg + posBuff + negBuff) * percentmod
local mhigh = (hiDmg + posBuff + negBuff) * percentmod
local olow = (offlowDmg + posBuff + negBuff) * percentmod
local ohigh = (offhiDmg + posBuff + negBuff) * percentmod
if mainSpeed < 1 then mainSpeed = 1 end
if mlow < 1 then mlow = 1 end
if mhigh < 1 then mhigh = 1 end
if olow < 1 then olow = 1 end
if ohigh < 1 then ohigh = 1 end
if offSpeed then
if offSpeed < 1 then
offSpeed = 1
end
GUILDBOOK_CHARACTER['PaperDollStats'].MeleeDmgOH = self:FormatNumberForCharacterStats((olow + ohigh) / 2.0)
GUILDBOOK_CHARACTER['PaperDollStats'].MeleeDpsOH = self:FormatNumberForCharacterStats(((olow + ohigh) / 2.0) / offSpeed)
else
--offSpeed = 1