-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.lua
More file actions
1698 lines (1377 loc) · 62.9 KB
/
core.lua
File metadata and controls
1698 lines (1377 loc) · 62.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
local ADDON_NAME, _ = ...
local _G = getfenv(0)
local LibStub = _G.LibStub
local BrokerGarrison = LibStub('AceAddon-3.0'):NewAddon(ADDON_NAME, 'AceConsole-3.0', "AceHook-3.0", 'AceEvent-3.0', 'AceTimer-3.0', "LibSink-2.0")
local Garrison = BrokerGarrison
_G["BrokerGarrison"] = {}
Garrison.versionString = GetAddOnMetadata(ADDON_NAME, "Version");
Garrison.cleanName = "Broker Garrison"
Garrison.detachframe = {}
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local LDBIcon = ldb and LibStub("LibDBIcon-1.0")
local L = LibStub:GetLibrary("AceLocale-3.0"):GetLocale(ADDON_NAME)
local LibQTip = LibStub('LibQTip-1.0')
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local Toast, ToastVersion = LibStub("LibToast-1.0")
local LSM = LibStub:GetLibrary("LibSharedMedia-3.0")
-- LUA
local math, string, table, print, pairs, ipairs, unpack = _G.math, _G.string, _G.table, _G.print, _G.pairs, _G.ipairs, _G.unpack
local tonumber, strupper, select, time = _G.tonumber, _G.strupper, _G.select, _G.time
-- Blizzard
local BreakUpLargeNumbers, C_Garrison, GetCurrencyInfo = _G.BreakUpLargeNumbers, _G.C_Garrison, _G.GetCurrencyInfo
-- UI Elements
local InterfaceOptionsFrameAddOns, UIParentLoadAddOn, GarrisonLandingPage = _G.InterfaceOptionsFrameAddOns, _G.UIParentLoadAddOn, _G.GarrisonLandingPage
local GarrisonMissionFrame, GarrisonLandingPageMinimapButton = _G.GarrisonMissionFrame, _G.GarrisonLandingPageMinimapButton
-- UI Functions
local ShowUIPanel, HideUIPanel, CreateFont, PlaySoundFile = _G.ShowUIPanel, _G.HideUIPanel, _G.CreateFont, _G.PlaySoundFile
-- UI Hooks
local OptionsListButtonToggle_OnClick = _G.OptionsListButtonToggle_OnClick
local garrisonDb, configDb, globalDb, DEFAULT_FONT, colors, tooltipFunctions
-- Constants
local TYPE_BUILDING = "building"
local TYPE_MISSION = "mission"
local TYPE_SHIPMENT = "shipment"
local TYPE_ORDERHALL = "orderhall"
Garrison.TYPE_BUILDING = TYPE_BUILDING
Garrison.TYPE_MISSION = TYPE_MISSION
Garrison.TYPE_SHIPMENT = TYPE_SHIPMENT
Garrison.TYPE_ORDERHALL = TYPE_ORDERHALL
Garrison.ADDON_WOD = 6
Garrison.ADDON_LEGION = 7
local addonInitialized = false
local delayedInit = false
local dependencyLoaded = false
local CONFIG_VERSION = 3
local timers = {}
Garrison.timers = timers
local atlas = {}
Garrison.atlas = atlas
local iconCache = {}
Garrison.iconCache = iconCache
local patternCache = {}
Garrison.patternCache = patternCache
local notificationQueue = {}
Garrison.notificationQueue = notificationQueue
local notificationQueueEnabled = false
-- LE_FOLLOWER_TYPE_SHIPYARD_6_2
-- LE_FOLLOWER_TYPE_GARRISON_7_0
-- LE_FOLLOWER_TYPE_GARRISON_6_0
Garrison.data = {}
-- Garrison Functions
local debugPrint, pairsByKeys, formatRealmPlayer, tableSize, getColoredString, getColoredUnitName, formattedSeconds, getIconString
local TOAST_MISSION_COMPLETE = "BrokerGarrisonMissionComplete"
local TOAST_BUILDING_COMPLETE = "BrokerGarrisonBuildingComplete"
local TOAST_SHIPMENT_COMPLETE = "BrokerGarrisonShipmentComplete"
local TOAST_SUMMARY = "BrokerGarrisonSummary"
local DB_DEFAULTS = {
profile = {
general = {
mission = {
ldbTemplate = "M1",
hideCharactersWithoutMissions = true,
ldbLabelText = L["Garrison: Missions"],
showOnlyCurrentRealm = false,
collapseOtherCharsOnLogin = false,
compactTooltip = false,
showFollowers = false,
showRewards = true,
showRewardsAmount = false,
showRewardsXP = false,
},
building = {
hideBuildingWithoutShipments = false,
hideHeader = false,
ldbTemplate = "B1",
ldbLabelText = L["Garrison: Buildings"],
showOnlyCurrentRealm = false,
collapseOtherCharsOnLogin = false,
compactTooltip = false,
},
orderhall = {
hideHeader = false,
showOnlyCurrentRealm = false,
hideInactiveTalents = true,
collapseOtherCharsOnLogin = false,
compactTooltip = false,
ldbLabelText = L["Orderhall"],
ldbTemplate = "A3",
},
hideGarrisonMinimapButton = false,
highAccuracy = true,
showSeconds = true,
updateInCombat = true,
legacyEnabled = true,
},
tooltip = {
building = {
sort = {
[1] = {
value = "b.canActivate",
ascending = true,
},
[2] = {
value = "b.isBuilding",
ascending = false,
},
[3] = {
value = "b.shipmentsReady",
ascending = false,
},
[4] = {
value = "b.shipmentCapacity",
ascending = false,
},
[5] = {
value = "b.name",
ascending = true,
},
['*'] = {
value = "-",
ascending = false,
},
},
group = {
[1] = {
value = "b.size",
ascending = true,
},
},
},
mission = {
sort = {
[1] = {
value = "m.timeLeft",
ascending = true,
},
[2] = {
value = "m.level",
ascending = false,
},
[3] = {
value = "m.name",
ascending = true,
},
['*'] = {
value = "-",
ascending = false,
},
},
group = {
[1] = {
value = "m.followerType",
ascending = true,
},
},
},
orderhall = {
sort = {
[1] = {
value = "tier",
ascending = true,
},
[2] = {
value = "uiOrder",
ascending = false,
},
}
}
},
notification = {
sink = {},
general = {
disableInParty = true,
disableInRaid = true,
disableInPvP = true,
},
mission = {
enabled = true,
repeatOnLoad = false,
toastEnabled = true,
toastPersistent = false,
hideBlizzardNotification = true,
hideMinimapPulse = false,
compactToast = false,
notificationQueueEnabled = true,
},
building = {
enabled = true,
repeatOnLoad = false,
toastEnabled = true,
toastPersistent = false,
hideBlizzardNotification = true,
hideMinimapPulse = false,
compactToast = false,
notificationQueueEnabled = true,
},
shipment = {
enabled = true,
repeatOnLoad = false,
toastEnabled = true,
toastPersistent = false,
hideBlizzardNotification = true,
hideMinimapPulse = false,
compactToast = false,
notificationQueueEnabled = true,
},
},
display = {
scale = 1,
autoHideDelay = 0.25,
iconSize = 16,
fontSize = 12,
showIcon = true,
backgroundAlpha = 255,
},
minimap = {
load = false,
mission = {},
building = {},
orderhall = {},
},
debugPrint = false,
},
global = {
data = {}
}
}
-- Player info
local charInfo = {
playerName = UnitName("player"),
playerClass = select(2, UnitClass("player")),
playerFaction = UnitFactionGroup("player"),
realmName = GetRealmName(),
}
Garrison.charInfo = charInfo
local location = {
garrisonMapName = _G.GetMapNameByID(976),
zoneName = nil,
inGarrison = nil,
inOrderHall = nil,
}
Garrison.location = location
Garrison.legacyGarrisonEnabled = true
-- LDB init
local ldb_object_mission = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject(ADDON_NAME .. "Mission",
{
type = "data source",
label = L["Garrison: Missions"],
icon = "Interface\\Icons\\Inv_Garrison_Resource",
text = L["Garrison: Missions"],
})
local ldb_object_building = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject(ADDON_NAME .. "Building",
{
type = "data source",
label = L["Garrison: Buildings"],
icon = "Interface\\Icons\\Inv_Garrison_Resource",
text = L["Garrison: Buildings"],
})
local ldb_object_orderhall = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject(ADDON_NAME .. "Orderhall",
{
type = "data source",
label = L["Garrison: Orderhall"],
icon = "Interface\\Icons\\Inv_Garrison_Resource",
text = L["Garrison: Orderhall"],
})
function Garrison:OnDependencyLoaded()
if not dependencyLoaded then
dependencyLoaded = true
GarrisonLandingPage = _G.GarrisonLandingPage
GarrisonMissionFrame = _G.GarrisonMissionFrame
debugPrint("DependencyLoaded")
Garrison:ScheduleTimer("RegisterEvents", 5)
self:Hook("GarrisonCapacitiveDisplayFrame_Update", true)
end
end
function Garrison:RegisterEvents()
debugPrint("RegisterEvents")
local fullUpdateRet = Garrison:FullUpdateBuilding(TYPE_BUILDING)
Garrison:FullUpdateTalents()
Garrison:FullUpdateShipments()
-- needed?
--Garrison:FullUpdateCategories()
timers.ldb_update = Garrison:ScheduleRepeatingTimer("LDBUpdate", 1)
timers.notify_update = Garrison:ScheduleRepeatingTimer("QuickUpdate", 5)
timers.icon_update = Garrison:ScheduleRepeatingTimer("SlowUpdate", 30)
self:RegisterEvent("GARRISON_BUILDING_PLACED", "BuildingUpdate")
self:RegisterEvent("GARRISON_BUILDING_REMOVED", "BuildingUpdate")
self:RegisterEvent("GARRISON_BUILDING_UPDATE", "BuildingUpdate")
self:RegisterEvent("GARRISON_BUILDING_ACTIVATED", "BuildingUpdate")
self:RegisterEvent("GARRISON_UPDATE", "BuildingUpdate")
self:RegisterEvent("SHIPMENT_UPDATE", "ShipmentStatusUpdate")
Garrison:CheckInvasionAvailable()
Garrison:CheckBuildingInfo()
Garrison:CheckNumBonusRollQuests()
end
function Garrison:LoadDependencies()
if not GarrisonMissionFrame or not GarrisonLandingPage then
debugPrint("Loading Blizzard_GarrisonUI...")
--UIParentLoadAddOn("Blizzard_OrderHallUI");
if UIParentLoadAddOn("Blizzard_GarrisonUI") then
Garrison:OnDependencyLoaded()
end
end
if not dependencyLoaded and _G.IsAddOnLoaded("Blizzard_GarrisonUI") then
Garrison:OnDependencyLoaded()
end
end
-- Helper Functions
local function toastCallback(callbackType, mouseButton, buttonDown, payload)
local missionData = payload[1]
if callbackType == "primary" then
debugPrint("OK: " .. payload[1].name)
end
if callbackType == "secondary" then
debugPrint("Dismiss: " .. payload[1].name)
--missionData.notification = 2 -- Mission dismissed, never show again
missionData.notificationDismissed = true
end
end
local function toastSummary(toast, text, notificationType)
if configDb.notification[notificationType].toastPersistent then
toast:MakePersistent()
end
toast:SetTitle((L["%s - Summary"]):format(Garrison.NotificationTitle[notificationType]))
toast:SetFormattedText(text)
toast:SetIconTexture(Garrison.Icon[notificationType])
end
local function toastMissionComplete(toast, text, missionData)
if configDb.notification.mission.toastPersistent then
toast:MakePersistent()
end
toast:SetTitle(L["Mission complete"])
toast:SetFormattedText(getColoredString(text, colors.green))
if ToastVersion >= 8 and missionData.typeAtlas then
toast:SetIconAtlas(missionData.typeAtlas)
else
toast:SetIconTexture([[Interface\Icons\Inv_Garrison_Resource]])
end
if configDb.notification.mission.extendedToast then
toast:SetPrimaryCallback(_G.OKAY, toastCallback)
toast:SetSecondaryCallback(L["Dismiss"], toastCallback)
toast:SetPayload(missionData)
end
end
local function toastBuildingComplete(toast, text, buildingData)
if configDb.notification.building.toastPersistent then
toast:MakePersistent()
end
toast:SetTitle(L["Building complete"])
toast:SetFormattedText(getColoredString(text, colors.green))
toast:SetIconTexture(Garrison.GetIconPath(buildingData.icon))
if configDb.notification.building.extendedToast then
toast:SetPrimaryCallback(_G.OKAY, toastCallback)
toast:SetSecondaryCallback(L["Dismiss"], toastCallback)
toast:SetPayload(buildingData)
end
end
local function toastShipmentComplete(toast, text, shipmentData)
if configDb.notification.shipment.toastPersistent then
toast:MakePersistent()
end
toast:SetTitle(L["Garrison: Shipment complete"])
toast:SetFormattedText(getColoredString(text, colors.green))
toast:SetIconTexture(Garrison.GetIconPath(shipmentData.texture))
if configDb.notification.shipment.extendedToast then
toast:SetPrimaryCallback(_G.OKAY, toastCallback)
toast:SetSecondaryCallback(L["Dismiss"], toastCallback)
toast:SetPayload(shipmentData)
end
end
function Garrison:HandleNotificationQueue()
if notificationQueue ~= nil and notificationQueue.lastUpdate and (time() - notificationQueue.lastUpdate) > 5 then
-- send notification queue and delete
local notificationCopy = notificationQueue
notificationQueue = nil
for notificationType, data in pairs(notificationCopy.data) do
local toastEnabled = configDb.notification[notificationType].toastEnabled
local toastText = ""
for key, value in pairs(data) do
toastText = toastText .. ("%s: %s\n"):format(key, getColoredString(value, colors.white))
debugPrint(("[%s] HandleNotificationQueue (%s): %s"):format(notificationType, key, value))
end
if toastEnabled then
Toast:Spawn(TOAST_SUMMARY, toastText, notificationType)
end
end
end
end
function Garrison:AddNotificationToQueue(notificationType, paramCharInfo)
local key = formatRealmPlayer(paramCharInfo, true)
if notificationQueue == nil or notificationQueue.data == nil then
notificationQueue = {
firstUpdate = time(),
data = {}
}
end
notificationQueue.lastUpdate = time()
if notificationQueue.data[notificationType] == nil then
notificationQueue.data[notificationType] = {}
end
if notificationQueue.data[notificationType][key] == nil then
notificationQueue.data[notificationType][key] = 1
else
notificationQueue.data[notificationType][key] = notificationQueue.data[notificationType][key] + 1
end
debugPrint(("[%s] AddNotificationToQueue (%s): %s"):format(notificationType, key, notificationQueue.data[notificationType][key]))
end
function Garrison:SendNotification(paramCharInfo, data, notificationType)
local retVal = false
local playerNotificationEnabled = globalDb.data[paramCharInfo.realmName][paramCharInfo.playerName].notificationEnabled
local notificationQueueEnabled = configDb.notification[notificationType].notificationQueueEnabled
local repeatOnLoad = configDb.notification[notificationType].repeatOnLoad
if delayedInit then
if configDb.notification[notificationType].enabled and (playerNotificationEnabled == nil or playerNotificationEnabled) then
if (not data.notification or
(data.notification == 0) or
(not addonInitialized and (repeatOnLoad or notificationQueueEnabled) and not data.notificationDismissed) or
(notificationType == TYPE_SHIPMENT and (not data.notificationValue or data.shipmentsReadyEstimate > data.notificationValue))) then
--debugPrint(("%s: %s > %s"):format(data.name, tostring(data.shipmentsReadyEstimate), tostring(data.notificationValue)))
if not Garrison:DisableInInstance() then
local notificationText, toastName, toastText, soundName, toastEnabled, playSound, notificationTitle
if configDb.notification[notificationType].compactToast then
toastText = ("%s\n%s"):format(formatRealmPlayer(paramCharInfo, true), data.name)
else
toastText = ("%s\n\n%s"):format(formatRealmPlayer(paramCharInfo, true), data.name)
end
toastEnabled = configDb.notification[notificationType].toastEnabled
playSound = configDb.notification[notificationType].playSound
soundName = configDb.notification[notificationType].soundName or "None"
if (notificationType == TYPE_MISSION) then
notificationText = (L["Mission complete (%s): %s"]):format(formatRealmPlayer(paramCharInfo, false), data.name)
toastName = TOAST_MISSION_COMPLETE
elseif (notificationType == TYPE_BUILDING) then
notificationText = (L["Building complete (%s): %s"]):format(formatRealmPlayer(paramCharInfo, false), data.name)
toastName = TOAST_BUILDING_COMPLETE
elseif (notificationType == TYPE_SHIPMENT) then
if configDb.notification[notificationType].compactToast then
toastText = ("%s\n%s (%s / %s)"):format(formatRealmPlayer(paramCharInfo, true), data.name, data.shipmentsReadyEstimate, data.shipmentsTotal)
else
toastText = ("%s\n\n%s (%s / %s)"):format(formatRealmPlayer(paramCharInfo, true), data.name, data.shipmentsReadyEstimate, data.shipmentsTotal)
end
notificationText = (L["Shipment complete (%s): %s (%s / %s)"]):format(formatRealmPlayer(paramCharInfo, false), data.name, data.shipmentsReadyEstimate, data.shipmentsTotal)
toastName = TOAST_SHIPMENT_COMPLETE
data.notificationValue = data.shipmentsReadyEstimate
end
if not addonInitialized and notificationQueueEnabled then
-- don't display notifications, just save them and prepare for later output
Garrison:AddNotificationToQueue(notificationType, paramCharInfo, notificationTitle)
else
Garrison.fireEvent(notificationType, paramCharInfo, data)
debugPrint(notificationText)
self:Pour(notificationText, colors.green.r, colors.green.g, colors.green.b)
if toastEnabled then
Toast:Spawn(toastName, toastText, data)
end
if playSound then
PlaySoundFile(LSM:Fetch("sound", soundName))
end
end
data.notification = 1
retVal = true
else
debugPrint(("Notifaction (%s) hidden (%s)"):format(data.name, notificationType))
end
end
end
end
return retVal
end
function Garrison:GetPlayerMissionCount(paramCharInfo, missionCount, missions)
local now = time()
local numMissionsPlayer = tableSize(missions)
if numMissionsPlayer > 0 then
missionCount.total = missionCount.total + numMissionsPlayer
for missionID, missionData in pairs(missions) do
-- 09.10.2016, Don't count disabled missions
if Garrison.IsValidMission(missionData) then
local timeLeft = missionData.duration - (now - missionData.start)
-- Do mission handling while we are at it
if (timeLeft < 0 and missionData.start == -1) then
-- Detect completed mission
-- Deprecated - should be detected on finished event
local parsedTimeLeft = string.match(missionData.timeLeft, Garrison.COMPLETED_PATTERN)
if (parsedTimeLeft == "0") then
-- 1 * 0 found in string -> assuming mission complete
missionData.start = 0
end
end
-- Count
if missionData.start > 0 then
if (timeLeft <= 0) then
missionCount.complete = missionCount.complete + 1
missionData.statusComplete = true
else
if missionCount.nextTime == -1 or timeLeft < missionCount.nextTime then
missionCount.nextTime = timeLeft
missionCount.nextData = missionData
missionCount.nextChar = paramCharInfo
end
missionCount.inProgress = missionCount.inProgress + 1
end
else
if missionData.start == 0 then
missionCount.complete = missionCount.complete + 1
missionData.statusComplete = true
else
missionCount.inProgress = missionCount.inProgress + 1
end
end
missionData.missionState = missionData.statusComplete and Garrison.STATE_MISSION_COMPLETE or Garrison.STATE_MISSION_INPROGRESS
missionData.timeLeftCalc = math.max(0, timeLeft)
if (timeLeft < 0 and missionData.start >= 0) then
Garrison:SendNotification(paramCharInfo, missionData, TYPE_MISSION)
end
end
end
end
end
function Garrison:DoShipmentMagic(shipmentData, paramCharInfo)
local now = time()
local shipmentsReady, shipmentsInProgress, shipmentsAvailable
local timeLeftNext = 0
local timeLeftTotal = 0
local shipmentsAvailable = shipmentData.shipmentCapacity
if shipmentData and shipmentData.shipmentsTotal and shipmentData.creationTime then
local timeDiff = (now - shipmentData.creationTime)
local shipmentsReadyByTime = 0
if shipmentData.duration and shipmentData.duration > 0 then
shipmentsReadyByTime = math.floor(timeDiff / shipmentData.duration)
end
--if isCurrentChar(paramCharInfo) then
-- shipmentsReady = shipmentData.shipmentsReady
--else
-- Only for other chars
shipmentsReady = math.min(shipmentData.shipmentsReady + shipmentsReadyByTime, shipmentData.shipmentsTotal)
--end
shipmentsInProgress = shipmentData.shipmentsTotal - shipmentsReady
shipmentsAvailable = math.max(0, shipmentData.shipmentCapacity - shipmentData.shipmentsTotal) -- thanks blizzard, api returns total > capacity sometimes.
timeLeftNext = shipmentData.duration - timeDiff
if shipmentsInProgress == 0 then
timeLeftNext = 0
else
timeLeftNext = timeLeftNext + (shipmentData.duration * shipmentsReadyByTime)
timeLeftTotal = timeLeftNext + (shipmentData.duration * (shipmentsInProgress - 1))
end
return shipmentsReady, shipmentsInProgress, shipmentsAvailable, timeLeftNext, timeLeftTotal
else
return 0, 0, shipmentsAvailable, 0, 0
end
end
function Garrison:GetPlayerBuildingCount(paramCharInfo, buildingCount, buildings)
local now = time()
local numBuildingsPlayer = tableSize(buildings)
if numBuildingsPlayer > 0 then
buildingCount.building.total = buildingCount.building.total + numBuildingsPlayer
for plotID, buildingData in pairs(buildings) do
if buildingData.isBuilding or buildingData.canActivate then
-- Check for building complete
local timeLeft = buildingData.buildTime - (now - buildingData.timeStart)
if buildingData.canActivate or timeLeft < 0 then
Garrison:SendNotification(paramCharInfo, buildingData, TYPE_BUILDING)
buildingCount.building.complete = buildingCount.building.complete + 1
buildingData.canActivate = true
buildingData.buildingState = Garrison.STATE_BUILDING_COMPLETE
else
buildingCount.building.building = buildingCount.building.building + 1
buildingData.buildingState = Garrison.STATE_BUILDING_BUILDING
end
else
buildingCount.building.active = buildingCount.building.active + 1
buildingData.buildingState = Garrison.STATE_BUILDING_ACTIVE
local shipmentData = buildingData.shipment
-- Check for work orders
if shipmentData and shipmentData.name and shipmentData.shipmentsTotal then
local shipmentsReady, shipmentsInProgress, shipmentsAvailable, timeLeftNext = Garrison:DoShipmentMagic(shipmentData, paramCharInfo)
shipmentData.shipmentsReadyEstimate = shipmentsReady
shipmentData.shipmentsInProgress = shipmentsInProgress
shipmentData.shipmentsAvailable = shipmentsAvailable
if shipmentData.shipmentsReadyEstimate > 0 then
Garrison:SendNotification(paramCharInfo, shipmentData, TYPE_SHIPMENT)
end
if shipmentData.notificationValue and shipmentData.shipmentsReadyEstimate < shipmentData.notificationValue then
shipmentData.notificationValue = shipmentData.shipmentsReadyEstimate
end
buildingCount.shipment.inProgress = buildingCount.shipment.inProgress + shipmentsInProgress
buildingCount.shipment.ready = buildingCount.shipment.ready + shipmentsReady
buildingCount.shipment.total = buildingCount.shipment.total + shipmentData.shipmentsTotal
buildingCount.shipment.available = buildingCount.shipment.available + shipmentsAvailable
if timeLeftNext > 0 and (buildingCount.shipment.nextTime == -1 or timeLeftNext < buildingCount.shipment.nextTime) then
--debugPrint(("Update %s (%s)"):format(timeLeftNext, paramCharInfo.playerName))
buildingCount.shipment.nextTime = timeLeftNext
buildingCount.shipment.nextData = shipmentData
buildingCount.shipment.nextChar = paramCharInfo
end
elseif shipmentData and shipmentData.name then
buildingCount.shipment.available = buildingCount.shipment.available + shipmentData.shipmentCapacity
end
end
end
end
end
function Garrison:GetPlayerOrderhallCount(paramCharInfo, orderhallCount, categories, talents)
local now = time()
local numCategoriesPlayer = tableSize(categories)
if numCategoriesPlayer > 0 then
orderhallCount.category.total = orderhallCount.category.total + numCategoriesPlayer
end
local numTalentsPlayer = tableSize(talents)
local tiersAvailable = 0
if numTalentsPlayer > 0 then
for _, talentData in pairs(talents) do
--debugPrint(("%s: %s"):format(talentData.name, talentData.talentAvailability))
if Garrison.CheckOrderTalentAvailability(talentData.talentAvailability, 0) then
tiersAvailable = tiersAvailable + 1
end
end
orderhallCount.talent.tiersAvailable = tiersAvailable
orderhallCount.talent.total = orderhallCount.talent.total + numTalentsPlayer
end
--debugPrint(("%s => %s / %s / %s"):format(paramCharInfo.playerName, numCategoriesPlayer, numTalentsPlayer, tiersAvailable))
end
function Garrison:GetOrderhallCount(paramCharInfo)
local orderhallCount = {
category = {
total = 0,
inProgress = 0,
complete = 0,
},
talent = {
total = 0,
inProgress = 0,
complete = 0,
tiersAvailable = 0,
}
}
local orderhallCountCurrent
if paramCharInfo then
Garrison:GetPlayerOrderhallCount(paramCharInfo, orderhallCount, globalDb.data[paramCharInfo.realmName][paramCharInfo.playerName].categories, globalDb.data[paramCharInfo.realmName][paramCharInfo.playerName].talents)
--missionCountCurrent = missionCount
else
Garrison:GetPlayerOrderhallCount(charInfo, orderhallCount, globalDb.data[charInfo.realmName][charInfo.playerName].categories, globalDb.data[charInfo.realmName][charInfo.playerName].talents)
orderhallCountCurrent = Garrison.deepcopy(orderhallCount, nil)
for realmName, realmData in pairs(globalDb.data) do
for playerName, playerData in pairs(realmData) do
-- don't count/show disabled characters
if playerData.ldbEnabled == nil or playerData.ldbEnabled then
if not Garrison.isCurrentChar(playerData.info) then
Garrison:GetPlayerOrderhallCount(playerData.info, orderhallCount, playerData.categories, playerData.talents)
end
end
end
end
end
return orderhallCount, orderhallCountCurrent
end
function Garrison:GetMissionCount(paramCharInfo)
local missionCount = {
total = 0,
inProgress = 0,
complete = 0,
nextTime = -1,
nextName = nil,
nextChar = nil,
}
local missionCountCurrent = nil
if paramCharInfo then
Garrison:GetPlayerMissionCount(paramCharInfo, missionCount, globalDb.data[paramCharInfo.realmName][paramCharInfo.playerName].missions)
--missionCountCurrent = missionCount
else
Garrison:GetPlayerMissionCount(charInfo, missionCount, globalDb.data[charInfo.realmName][charInfo.playerName].missions)
missionCountCurrent = Garrison.deepcopy(missionCount, nil)
for realmName, realmData in pairs(globalDb.data) do
for playerName, playerData in pairs(realmData) do
-- don't count/show disabled characters
if playerData.ldbEnabled == nil or playerData.ldbEnabled then
if not Garrison.isCurrentChar(playerData.info) then
Garrison:GetPlayerMissionCount(playerData.info, missionCount, playerData.missions)
end
end
end
end
end
return missionCount, missionCountCurrent
end
function Garrison:GetBuildingCount(paramCharInfo)
local buildingCount = {
building = {
total = 0,
building = 0,
complete = 0,
active = 0,
},
shipment = {
inProgress = 0,
ready = 0,
total = 0,
available = 0,
nextTime = -1,
nextName = nil,
nextChar = nil,
}
}
local buildingCountCurrent
if Garrison.IsEnabled(TYPE_BUILDING, Garrison.ADDON_WOD) then
if paramCharInfo then
Garrison:GetPlayerBuildingCount(paramCharInfo, buildingCount, globalDb.data[paramCharInfo.realmName][paramCharInfo.playerName].buildings)
--buildingCountCurrent = buildingCount
else
Garrison:GetPlayerBuildingCount(charInfo, buildingCount, globalDb.data[charInfo.realmName][charInfo.playerName].buildings)
buildingCountCurrent = Garrison.deepcopy(buildingCount, nil)
for realmName, realmData in pairs(globalDb.data) do
for playerName, playerData in pairs(realmData) do
-- don't count/show disabled characters
if playerData.ldbEnabled == nil or playerData.ldbEnabled then
if not Garrison.isCurrentChar(playerData.info) then
Garrison:GetPlayerBuildingCount(playerData.info, buildingCount, playerData.buildings)
end
end
end
end
end
end
return buildingCount, buildingCountCurrent
end
function Garrison:UpdateConfig()
if GarrisonLandingPageMinimapButton then
if GarrisonLandingPageMinimapButton:IsShown() then
if configDb.general.hideGarrisonMinimapButton then
GarrisonLandingPageMinimapButton:Hide()
end
else
if not configDb.general.hideGarrisonMinimapButton then
GarrisonLandingPageMinimapButton:Show()
end
end
end
if LDBIcon and configDb.minimap.load then
if configDb.minimap.mission.hide then
LDBIcon:Hide("BrokerGarrisonLDBMission")
else
LDBIcon:Show("BrokerGarrisonLDBMission")
end
if configDb.minimap.building.hide then
LDBIcon:Hide("BrokerGarrisonLDBBuilding")
else
LDBIcon:Show("BrokerGarrisonLDBBuilding")
end
end
end
local updater
local tooltipRegistry = {}
local DrawTooltip
do
local NUM_TOOLTIP_COLUMNS = {
[TYPE_BUILDING] = 5,
[TYPE_MISSION] = 5,
[TYPE_ORDERHALL] = 6,
}
local ALIGNMENT_TOOLTIP_COLUMNS = {}
local LDB_anchor
local tooltipType
local tooltip
local locked = false
local tooltipTypeNew
local last_update = 0
updater = _G.CreateFrame("Frame", nil, _G.UIParent)
updater:SetScript("OnUpdate",
function(self, elapsed)
last_update = last_update + elapsed
if last_update < 0.1 then
return
end
--tooltipRegistry[TYPE_BUILDING].tooltip
if tooltip and tooltipType then
--debugPrint("onupdate tooltip: "..tooltipType)
if tooltip:IsMouseOver() or (LDB_anchor and LDB_anchor:IsMouseOver()) then
--debugPrint("mouseover")
self.elapsed = (self.elapsed or 0) + last_update
if (configDb.general.highAccuracy and self.elapsed >= 1) or self.elapsed > 30 then
--debugPrint("redraw")
self.elapsed = 0
DrawTooltip(LDB_anchor, tooltipType)
end
end
end
last_update = 0
end)
local function ExpandButton_OnMouseUp(tooltip_cell, param, button)
local realm_and_character, paramType = unpack(param)
local realm, character_name = (":"):split(realm_and_character, 2)
if paramType == TYPE_MISSION then
globalDb.data[realm][character_name].missionsExpanded = not globalDb.data[realm][character_name].missionsExpanded
elseif paramType == TYPE_BUILDING then
globalDb.data[realm][character_name].buildingsExpanded = not globalDb.data[realm][character_name].buildingsExpanded
elseif paramType == TYPE_ORDERHALL then
globalDb.data[realm][character_name].orderhallExpanded = not globalDb.data[realm][character_name].orderhallExpanded
end
DrawTooltip(tooltipRegistry[paramType].anchor, paramType)
end
local function ExpandButton_OnMouseDown(tooltip_cell, param, button)
--local is_expanded, paramType = unpack(param)
--local line, column = tooltip_cell:GetPosition()
--tooltip:SetCell(line, column, is_expanded and Garrison.ICON_CLOSE_DOWN or Garrison.ICON_OPEN_DOWN)
end
local function Tooltip_OnRelease_Mission(arg)
tooltipRegistry[TYPE_MISSION].tooltip = nil
tooltipRegistry[TYPE_MISSION].anchor = nil
if tooltipType and tooltipType == TYPE_MISSION then
LDB_anchor = nil
tooltipType = nil
--elseif tooltipType and tooltipType == TYPE_BUILDING then
elseif tooltipType and (tooltipType ~= TYPE_MISSION) then