-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhudtracker.lua
986 lines (786 loc) · 33.3 KB
/
hudtracker.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
--[[
HUDTracker
The on-screen hud-tracker
--]]
HUDTracker = {}
-- UI references, these should really be in Private but it is easier to work with them like this.
local FRAME = Component.GetFrame('Tracker')
local SLIDER = FRAME:GetChild('Slider')
local LIST = FRAME:GetChild('List')
local SCROLLER = nil
local TOOLTIP_ITEM = nil
-- Private variables
local Private = {
lastUpdate = 0,
minUpdateCB = nil,
testMode = false,
testEntries = {},
entries = {},
hideFrameCB = nil,
previouslyVisible = false,
}
Private.hideFrameCB = Callback2.Create()
Private.hideFrameCB:Bind(function() FRAME:Show(false) end)
-- The table of magic numbers.
local DimensionOptions = {
ScrollerSpacing = 8,
ScrollerSliderMarginVisible = 5,
ScrollerSliderMarginHidden = 5,
EntryDimsWidth = '100%',
EntryDimsHeight = '32',
plateLeftOverlap = 4, -- Plate is offset by the size of the icon subtracted by this value, in order to have the icon overlap the edge of the plate
plateHeightBorderReduction = 2, -- Plate height is reduced by 2 times this value, in order to free up space for the top and bottom borders.
textAutoSizeHeightIncrease = 20, --
}
-- Blueprint for the HUDTracker Entries
local bp_ENTRY = [[
<Group name='EntryGroup' dimensions='width:100%; height:32;'>
<!-- Plate -->
<FocusBox name='plate' dimensions='width:100%-30; height:28; left:30; top:2;'>
<StillArt name='bg' dimensions='width:100%-2.2; height:99%-2;' style='texture:colors; region:white; tint:#000000; alpha:0.7;'/>
<Border name='outer' dimensions='dock:fill' class='Tracker_PlateBorder'/>
<Border name='shade' dimensions='dock:fill' class='ButtonFade'/>
</FocusBox>
<!-- Box -->
<Group name='box' dimensions='width:32; height:32; left:0; top:0;'>
<StillArt name='bg' dimensions='width:96%; height:96%;' style='texture:colors; region:white; tint:#000000; alpha:1;'/>
<StillArt name='backplate' dimensions='width:99%; height:99%;' style='texture:ItemPlate; region:Square;'/>
<Border name='outer' dimensions='dock:fill;' class='ButtonBorder'/>
<Border name='shade' dimensions='width:0;height:0;' class='ButtonFade'/>
<Group name='icon' dimensions='dock:fill;' style='fixed-bounds:true; valign:center;'/>
</Group>
<!-- Text -->
<Group name='text' dimensions='width:100%-32; height:28; left:32; top:2;'>
<!-- Stack -->
<Text name='stack' dimensions='width:10%; height:100%-2; top:0; left:5%;' class='Tracker_Text'/>
<!-- Title -->
<Text name='title' dimensions='width:80%; height:100%-2; top:0; left:20%;' class='Tracker_Text'/>
</Group>
</Group>
]]
--[[
HUDTracker.GetFrame()
Returns a reference to the Tracker Frame.
--]]
function HUDTracker.GetFrame()
return FRAME
end
--[[
HUDTracker.Setup()
Performs OnOptionsLoaded tasks.
--]]
function HUDTracker.Setup()
-- Scroller
SCROLLER = RowScroller.Create(LIST)
SCROLLER:SetSlider(SLIDER)
SCROLLER:SetSliderMargin(DimensionOptions.ScrollerSliderMarginVisible, DimensionOptions.ScrollerSliderMarginHidden)
SCROLLER:SetSpacing(DimensionOptions.ScrollerSpacing)
SCROLLER:ShowSlider(Options['HUDTracker']['DisplaySlider'] and 'auto' or false)
SCROLLER:SetScrollStep(Options['HUDTracker']['EntrySize'] + DimensionOptions.ScrollerSpacing)
-- Tooltip
TOOLTIP_ITEM = LIB_ITEMS.CreateToolTip(FRAME)
TOOLTIP_ITEM.GROUP:Show(false)
-- Apply width/height frame options
InterfaceOptions.ChangeFrameWidth(FRAME, Options['HUDTracker']['Frame']['Width'])
InterfaceOptions.ChangeFrameHeight(FRAME, Options['HUDTracker']['Frame']['Height'])
SCROLLER:UpdateSize()
end
--[[
HUDTracker.Enable()
Called when HUDTracker is Enabled in the Options, populates the HUDTracker.
--]]
function HUDTracker.Enable()
-- Build
HUDTracker.Rebuild()
-- Fnter fakemode if in options
if State.inOptions then
HUDTracker.EnterFakeMode()
end
HUDTracker.UpdateVisibility()
end
--[[
HUDTracker.Disable()
Called when HUDTracker is Disabled in the Options, cleans up.
--]]
function HUDTracker.Disable()
-- Exit fakemode if in
if HUDTracker.IsInFakeMode() then
HUDTracker.ExitFakeMode()
end
-- Hide tooltip if is currently being displayed
if State.tooltipActive then
Tooltip.Show(false)
TOOLTIP_ITEM.GROUP:Show(false)
end
-- Clear
SCROLLER:Reset()
Private.entries = {}
HUDTracker.UpdateVisibility()
end
--[[
HUDTracker.OnOptionChange(id, value)
Called by Options when a HUDTracker Option is changed.
Used to rebuild the HUDTracker so that it is always displayed as per the configuration, as well as to handle enable-disable. Calls InterfaceOptions functions to handle changing of the size of the Frame itself (might want to move some of that to Options later)
--]]
function HUDTracker.OnOptionChange(id, value)
if id == 'HUDTracker_Enabled' then
-- Enabled
if value then
HUDTracker.Enable()
-- Disabled
else
HUDTracker.Disable()
end
elseif id == 'HUDTracker_Frame_Width'
then
Debug.Log('Updating HUDTracker Frame Width')
InterfaceOptions.ChangeFrameWidth(FRAME, value)
SCROLLER:UpdateSize()
elseif id == 'HUDTracker_Frame_Height'
then
InterfaceOptions.ChangeFrameHeight(FRAME, value)
SCROLLER:UpdateSize()
elseif id == 'HUDTracker_DisplaySlider'
then
SCROLLER:ShowSlider(Options['HUDTracker']['DisplaySlider'] and 'auto' or false)
-- For general options we rebuild the tracker
else
-- Entry Size
if id == 'HUDTracker_EntrySize' then
SCROLLER:SetScrollStep(Options['HUDTracker']['EntrySize'] + DimensionOptions.ScrollerSpacing)
end
-- Rebuild tracker
HUDTracker.Rebuild()
end
end
function HUDTracker.OnDisplayOptions()
if Options['HUDTracker']['Enabled'] then
if State.inOptions then
HUDTracker.EnterFakeMode()
else
HUDTracker.ExitFakeMode()
end
end
end
--[[
HUDTracker.OnTrackerNew(args)
Called when Tracker has added a new item.
Updates the HUDTracker to reflect the new state, creating an entry if applicable.
--]]
function HUDTracker.OnTrackerNew(args)
args.event = 'HUDTracker.OnTrackerNew'
--Debug.Event(args)
local loot = Tracker.GetLootById(args.lootId)
if HUDTracker.IsInFakeMode() then
if Private.testEntries[args.lootId] then
loot = Private.testEntries[args.lootId]
end
end
if not loot then return end
if Options['Blacklist']['HUDTracker'][tostring(loot:GetTypeId())] then
return
end
if Filtering.Filter(loot, Options['HUDTracker']) then
-- Hide tooltip if is currently being displayed, whilst we are modifying stuff.
if State.tooltipActive then
Tooltip.Show(false)
TOOLTIP_ITEM.GROUP:Show(false)
end
-- Check for existing row
local ENTRY = Private.entries[tostring(loot:GetTypeId())]
-- If there is an existing entry
if ENTRY then
--Debug.Table('OnTrackerNew found existing entry: ' , ENTRY)
-- Retrieve existing stackInfo
local stackInfo = ENTRY.stackInfo
-- Add this new loot to the stack
stackInfo.quantity = stackInfo.quantity + loot:GetQuantity()
stackInfo.count = stackInfo.count + 1
stackInfo.ids[loot:GetId()] = {quantity=loot:GetQuantity()}
-- Update entry
Private.UpdateEntry(ENTRY)
-- There is not an existing row, create a completely new one
else
-- Create entry
ENTRY = Private.CreateEntry(loot)
-- Get the index of each entry in the rowscroller
local indexList = {}
for typeId, ENTRY_OTHER in pairs(Private.entries) do
local index = ENTRY_OTHER.ROW:GetIdx()
indexList[index] = ENTRY_OTHER
end
-- Determine which index our new entry should have
local ourEntryIndex = nil
for index, ENTRY_OTHER in pairs(indexList) do
if HUDTrackerSort(ENTRY, ENTRY_OTHER) then
ourEntryIndex = index
break
end
end
-- Insert entry as row
local ROW = SCROLLER:AddRow(ENTRY.GROUP, ourEntryIndex)
-- Save a row reference
ENTRY.ROW = ROW
-- Store entry
Private.entries[tostring(loot:GetTypeId())] = ENTRY
-- Fade in effect
if Options['HUDTracker']['FadeEntry']['Enabled'] then
ENTRY.GROUP:ParamTo("alpha", 1.0, Options['HUDTracker']['FadeEntry']['FadeIn']['Duration'], Options['HUDTracker']['FadeEntry']['FadeIn']['Animation'])
end
end
end
HUDTracker.UpdateVisibility()
end
--[[
HUDTracker.OnTrackerUpdate(args)
Called when Tracker thinks an item was looted.
Updates the HUDTracker to reflect the new state, removing an entry if applicable.
--]]
function HUDTracker.OnTrackerLooted(args)
local loot = Tracker.GetLootById(args.lootId)
if not loot then return end
-- Check for existing row
local ENTRY = Private.entries[tostring(loot:GetTypeId())]
-- If there is an existing entry
if ENTRY then
-- Retrieve existing stackInfo
local stackInfo = ENTRY.stackInfo
-- Check that this loot is actually in this stack
if stackInfo.ids[loot:GetId()] then
-- Hide tooltip if is currently being displayed, whilst we are modifying stuff.
if State.tooltipActive then
Tooltip.Show(false)
TOOLTIP_ITEM.GROUP:Show(false)
end
-- If this is a stacked entry, we update it
if stackInfo.count > 1 then
-- Remove this loot from the stack
stackInfo.quantity = stackInfo.quantity - stackInfo.ids[loot:GetId()].quantity
stackInfo.count = stackInfo.count - 1
stackInfo.ids[loot:GetId()] = nil
-- Update entry
Private.UpdateEntry(ENTRY)
-- Otherwise, just remove
else
-- Fade out effect
if Options['HUDTracker']['FadeEntry']['Enabled'] then
-- Start fade out effect
ENTRY.GROUP:ParamTo("alpha", 0.0, Options['HUDTracker']['FadeEntry']['FadeOut']['Duration'], Options['HUDTracker']['FadeEntry']['FadeOut']['Animation'])
end
-- Removal
Private.entries[tostring(loot:GetTypeId())] = nil
if Options['HUDTracker']['FadeEntry']['Enabled'] then
callback(function()
if ENTRY then
if ENTRY.GROUP and Component.IsWidget(ENTRY.GROUP) then Component.RemoveWidget(ENTRY.GROUP) end
if ENTRY.ROW and ENTRY.ROW.Remove then ENTRY.ROW:Remove() end
ENTRY = nil
end
end, nil, Options['HUDTracker']['FadeEntry']['FadeOut']['Duration'])
else -- I really shouldn't be repeating myself, but...
Component.RemoveWidget(ENTRY.GROUP)
ENTRY.ROW:Remove()
ENTRY = nil
end
end
end
end
HUDTracker.UpdateVisibility()
end
--[[
HUDTracker.OnTrackerRemove(args)
Called when Tracker has removed an item.
Updates the HUDTracker to reflect the new state.
--]]
function HUDTracker.OnTrackerRemove(args)
args.event = 'HUDTracker.OnTrackerRemove'
--Debug.Event(args)
--Debug.Table('HUDTracker Private.entries', Private.entries)
for typeId, ENTRY in pairs(Private.entries) do
local stackInfo = ENTRY.stackInfo
--Debug.Table('Entry ' .. tostring(typeId) .. ' stackInfo', stackInfo)
--Debug.Log('stackInfo.ids[args.lootId] : ' .. tostring(stackInfo.ids[args.lootId]))
if stackInfo.ids[args.lootId] then
-- Hide tooltip if is currently being displayed, whilst we are modifying stuff.
if State.tooltipActive then
Tooltip.Show(false)
TOOLTIP_ITEM.GROUP:Show(false)
end
-- If this is a stacked entry, we update it
if stackInfo.count > 1 then
-- Remove this loot from the stack
stackInfo.quantity = stackInfo.quantity - stackInfo.ids[args.lootId].quantity
stackInfo.count = stackInfo.count - 1
stackInfo.ids[args.lootId] = nil
-- Update entry
Private.UpdateEntry(ENTRY)
-- Otherwise, just remove
else
-- Fade out effect
if Options['HUDTracker']['FadeEntry']['Enabled'] then
-- Start fade out effect
ENTRY.GROUP:ParamTo("alpha", 0.0, Options['HUDTracker']['FadeEntry']['FadeOut']['Duration'], Options['HUDTracker']['FadeEntry']['FadeOut']['Animation'])
end
-- Removal
Private.entries[typeId] = nil
if Options['HUDTracker']['FadeEntry']['Enabled'] then
callback(function()
if ENTRY then
if ENTRY.GROUP and Component.IsWidget(ENTRY.GROUP) then Component.RemoveWidget(ENTRY.GROUP) end
if ENTRY.ROW and ENTRY.ROW.Remove then ENTRY.ROW:Remove() end
ENTRY = nil
end
end, nil, Options['HUDTracker']['FadeEntry']['FadeOut']['Duration'])
else -- I really shouldn't be repeating myself, but...
Component.RemoveWidget(ENTRY.GROUP)
ENTRY.ROW:Remove()
ENTRY = nil
end
end
-- Exit
break
end
end
HUDTracker.UpdateVisibility()
end
--[[
HUDTracker.Rebuild(args)
Rebuilds the HUDTracker entries, removing them and recreating entries for available loot.
Primarily used when Options are changed.
--]]
function HUDTracker.Rebuild(args)
args = args or {}
args.event = 'HUDTracker.Rebuild'
--Debug.Event(args)
-- Only update and show tracker if enabled
if Options['HUDTracker']['Enabled'] then
--Debug.Log('HUDTracker Update called and HUDTracker is enabled')
-- Stop scroller updates whilst we update
SCROLLER:LockUpdates()
-- Exit fake mode if in
local shouldReFake = false
if HUDTracker.IsInFakeMode() then
shouldReFake = true
HUDTracker.ExitFakeMode()
end
-- Clear
for typeId, ENTRY in pairs(Private.entries) do
ENTRY = nil
Private.entries[typeId] = nil
end
SCROLLER:Reset()
-- Get loot
local trackedLoot = Tracker.GetAvailableLoot()
-- Populate
if not _table.empty(trackedLoot) then
for i, loot in ipairs(trackedLoot) do
HUDTracker.OnTrackerNew({lootId = loot:GetId()})
end
end
-- Restore scroller updates
SCROLLER:UnlockUpdates()
-- Update visibility
HUDTracker.UpdateVisibility()
-- What we just did fucked up the fake mode, so reset
if shouldReFake then
HUDTracker.EnterFakeMode()
end
end
end
--[[
HUDTracker.UpdateVisibility()
Reads current state, determines and updates the visibility of the HUDTracker.
--]]
function HUDTracker.UpdateVisibility()
-- Fade callbacks
if Private.hideFrameCB:Pending() then Private.hideFrameCB:Cancel() end
-- Tracker enabled, check if should be displayed
if Options['HUDTracker']['Enabled'] then
-- Should we display the tracker?
--Debug.Log('Should we display the Tracker?')
--Debug.Log('Options Tracker Visibility == '..Options['HUDTracker']['Visibility'])
--Debug.Log('State.hud == '..tostring(State.hud))
--Debug.Log('State.cursor == '..tostring(State.cursor))
--Debug.Log('State.sin == '..tostring(State.sin))
--Debug.Log('State.inOptions == '..tostring(State.inOptions))
if SCROLLER:GetRowCount() > 0 and (
(Options['HUDTracker']['Visibility'] == HUDTrackerVisibilityOptions.Always)
or (Options['HUDTracker']['Visibility'] == HUDTrackerVisibilityOptions.HUD and State.hud)
or (Options['HUDTracker']['Visibility'] == HUDTrackerVisibilityOptions.MouseMode and State.cursor and State.hud)
or (Options['HUDTracker']['Visibility'] == HUDTrackerVisibilityOptions.SinMode and State.sin and State.hud)
or (State.inOptions)
)
then
--Debug.Log('Yes, display the tracker')
-- Yes, display tracker
-- Fade in effect
if Options['HUDTracker']['FadeFrame']['Enabled'] and not Private.previouslyVisible then
FRAME:SetParam("alpha", 0.0)
FRAME:ParamTo("alpha", 1.0, Options['HUDTracker']['FadeFrame']['FadeIn']['Duration'], Options['HUDTracker']['FadeFrame']['FadeIn']['Animation'])
FRAME:Show(true)
-- Instant show if no fade
else
FRAME:Show(true)
end
-- Remember state
Private.previouslyVisible = true
else
--Debug.Log('No, hide the tracker')
-- No, hide the tracker
-- Fade out effect
if Options['HUDTracker']['FadeFrame']['Enabled'] and Private.previouslyVisible then
FRAME:ParamTo("alpha", 0.0, Options['HUDTracker']['FadeFrame']['FadeOut']['Duration'], Options['HUDTracker']['FadeFrame']['FadeOut']['Animation'])
Private.hideFrameCB:Schedule(Options['HUDTracker']['FadeFrame']['FadeOut']['Duration'])
-- Instant hide if no fade
else
FRAME:Show(false)
end
-- Remember state
Private.previouslyVisible = false
-- Ensure no tooltip is displayed
TOOLTIP_ITEM.GROUP:Show(false)
Tooltip.Show(false)
State.tooltipActive = false
end
-- Tracker not enabled, so do nothing but make sure it's hidden.
else
--Debug.Log('Tracker not enabled, hide')
-- Hide tracker
FRAME:Show(false)
-- Remember state
Private.previouslyVisible = false
-- Ensure no tooltip is displayed
TOOLTIP_ITEM.GROUP:Show(false)
Tooltip.Show(false)
State.tooltipActive = false
end
end
--[[
HUDTracker.UpdateTooltip(lootId)
Returns updated item tooltip widget matching the provided lootId.
--]]
function HUDTracker.UpdateTooltip(lootId)
-- Get info
--Debug.Log('UpdateTrackerTooltip called for lootId '..tostring(lootId))
local loot = Tracker.GetLootById(lootId)
if HUDTracker.IsInFakeMode() then
if Private.testEntries[lootId] then
loot = Private.testEntries[lootId]
end
end
if loot == nil or loot == false then Debug.Error('UpdateTrackerTooltip unable to get identified item') end
-- Setup Tooltip
TOOLTIP_ITEM:DisplayInfo(loot.itemInfo)
TOOLTIP_ITEM.GROUP:SetDims('top:0; left:0; width:200; height:200')
-- Add compare info
local compare_info = LIB_ITEMS.GetMatchingEquippedItemInfo(loot.itemInfo)
if compare_info then
TOOLTIP_ITEM:CompareAgainst(compare_info)
end
-- Return Tooltip
local tip_args = TOOLTIP_ITEM:GetBounds()
tip_args.frame_color = loot:GetColor()
return TOOLTIP_ITEM.GROUP, tip_args
end
function HUDTracker.IsInFakeMode()
return Private.testMode
end
function HUDTracker.ExitFakeMode()
Debug.Log("HUDTracker.ExitFakeMode()")
for key, value in pairs(Private.testEntries) do
HUDTracker.OnTrackerRemove({lootId=key})
Private.testEntries[key] = nil
end
Private.testMode = false
HUDTracker.UpdateVisibility()
end
function HUDTracker.EnterFakeMode()
Debug.Log("HUDTracker.EnterFakeMode()")
--if Private.testMode then HUDTracker.ExitFakeMode() HUDTracker.EnterFakeMode() return end
Private.testMode = true
-- Make
local fakeData = {
{entityId=-1, targetInfo={entityId=-1, itemTypeId=125917}},
{entityId=-2, targetInfo={entityId=-2, itemTypeId=123219}},
{entityId=-3, targetInfo={entityId=-3, itemTypeId=123384}},
{entityId=-4, targetInfo={entityId=-4, itemTypeId=123818}},
{entityId=-5, targetInfo={entityId=-5, itemTypeId=123874}},
}
-- Generate them
for index, lootData in ipairs(fakeData) do
lootData.itemInfo = Game.GetItemInfoByType(lootData.targetInfo.itemTypeId)
local loot = Loot.Create(lootData.entityId, lootData.targetInfo, lootData.itemInfo)
--[[
-- Create entry
local ENTRY = Private.CreateEntry(loot)
-- Get the index of each entry in the rowscroller
local indexList = {}
for typeId, ENTRY_OTHER in pairs(Private.entries) do
local index = ENTRY_OTHER.ROW:GetIdx()
indexList[index] = ENTRY_OTHER
end
-- Determine which index our new entry should have
local ourEntryIndex = nil
for index, ENTRY_OTHER in pairs(indexList) do
if HUDTrackerSort(ENTRY, ENTRY_OTHER) then
ourEntryIndex = index
break
end
end
-- Insert entry as row
local ROW = SCROLLER:AddRow(ENTRY.GROUP, ourEntryIndex)
-- Save a row reference
ENTRY.ROW = ROW
-- Store entry
Private.entries[tostring(loot:GetTypeId())] = ENTRY
--]]
-- Store test entry
Private.testEntries[tostring(loot:GetId())] = loot
HUDTracker.OnTrackerNew({lootId = loot:GetId()})
end
HUDTracker.UpdateVisibility()
end
function Private.CreateEntry(loot, stackInfo)
-- Handle arguments
stackInfo = stackInfo or {quantity = loot:GetQuantity(), count = 1, ids = {[loot:GetId()] = {quantity = loot:GetQuantity()}}, sortProfile = {itemLevel = loot:GetItemLevel(), requiredLevel = loot:GetRequiredLevel(), rarityValue = loot:GetRarityValue(), name=loot:GetName()}}
--Debug.Table('Private.CreatEntry stackInfo', stackInfo)
-- Create
local GROUP = Component.CreateWidget(bp_ENTRY, LIST)
-- Setup entry
local ENTRY = {
PARENT = LIST,
GROUP = GROUP,
PLATE = GROUP:GetChild('plate'),
BOX = GROUP:GetChild('box'),
TEXT = GROUP:GetChild('text'),
stackInfo = stackInfo,
}
ENTRY.STACK = ENTRY.TEXT:GetChild('stack')
ENTRY.TITLE = ENTRY.TEXT:GetChild('title')
-- Setup plate tooltip tag
ENTRY.PLATE:SetTag(loot:GetId())
-- Setup plate tooltip events
if Options['HUDTracker']['Tooltip']['Enabled'] then
ENTRY.PLATE:BindEvent('OnMouseEnter', function(args)
TOOLTIP_ITEM.GROUP:Show(true)
Tooltip.Show(HUDTracker.UpdateTooltip(args.widget:GetTag()))
State.tooltipActive = true
end)
ENTRY.PLATE:BindEvent('OnMouseLeave', function(args)
TOOLTIP_ITEM.GROUP:Show(false)
Tooltip.Show(false)
State.tooltipActive = false
end)
end
-- Setup plate right click menu
if Options['HUDTracker']['ContextMenu']['Enabled'] then
local ShowContextMenu = function(args)
-- Get loot
local lootId = args.widget:GetTag()
local loot = Tracker.GetLootById(lootId)
if not loot then
Debug.Warn('HUDTracker Context Menu could not get loot.')
return
end
local MENU = ContextMenu.Create()
MENU:BindOnRequest(function(MENU, id)
if id == 'root' then
-- Personal Waypoint
MENU:AddButton({id='self_waypoint', label_key='SET_WAYPOINT'})
-- Squad Waypoint (Platoons?)
if State.isSquadLeader then
MENU:AddButton({id='squad_waypoint', label_key='SET_SQUAD_WAYPOINT'})
end
-- Append item link to Chat
MENU:AddButton({id='add_item_link', label_key='ADD_ITEM_LINK'})
-- Append coord link to Chat
MENU:AddButton({id='add_coord_link', label=Lokii.GetString('UI_HUDTracker_AddCoordinatesLink')})
-- Debug
if Options['Debug']['Enabled'] then
MENU:AddButton({id='debug_remove', label=Lokii.GetString('UI_HUDTracker_DebugRemove')})
end
end
end)
MENU:BindOnSelect(function(args)
if args.menu == 'root' then
-- Waypoints
local lootPos = loot:GetPos()
if args.id == 'self_waypoint' then
Component.GenerateEvent('MY_PERSONAL_WAYPOINT_SET', {x=lootPos.x, y=lootPos.y, z=lootPos.z+1})
elseif args.id == 'squad_waypoint' then
Squad.SetWayPoint(lootPos.x, lootPos.y, lootPos.z+1)
-- Append item link to Chat
elseif args.id == 'add_item_link' then
loot:AppendToChat()
-- Append coord link to Chat
elseif args.id == 'add_coord_link' then
loot:AppendCoordToChat()
-- Debug - Remove
elseif args.id == 'debug_remove' then
Tracker.Remove(lootId)
end
end
end)
MENU:Show()
end
ENTRY.PLATE:BindEvent('OnMouseDown', ShowContextMenu)
ENTRY.PLATE:BindEvent('OnRightMouse', ShowContextMenu)
end
-- Setup plate colors
local lootColor = loot:GetColor()
ENTRY.PLATE:GetChild('outer'):SetParam('tint', lootColor)
ENTRY.PLATE:GetChild('shade'):SetParam('tint', lootColor)
-- Setup box colors
ENTRY.BOX:GetChild('outer'):SetParam('tint', lootColor)
ENTRY.BOX:GetChild('shade'):SetParam('tint', lootColor)
-- Setup box
ENTRY.BOX:GetChild('backplate'):SetParam('tint', lootColor)
-- Setup icon
local ICON_PARENT = ENTRY.BOX:GetChild('icon')
ENTRY.ICON = loot:GetMultiArt(ICON_PARENT, Options['HUDTracker']['ForceWebIcons'])
-- Setup stack
if stackInfo then
-- We want to see the count if it is higher than 1
-- OR if the quantity is higher than 1 (we want to see that it is 3 crystite on the ground).
-- Since quantity can not be lower then count (quantity is either 1 or higher, there are no half items), we only check quantity here
local stackText = ''
if stackInfo.quantity > 1 then
stackText = tostring(stackInfo.count)
end
-- Add in quantity if it is of interest
if stackInfo.quantity > stackInfo.count then
stackText = stackText .. ' (' .. tostring(stackInfo.quantity) .. ')'
end
ENTRY.STACK:SetText(stackText)
end
-- Setup title
ENTRY.TITLE:SetText(GetHUDTrackerTitle(loot))
Private.SetEntrySize(ENTRY)
Private.SetEntryFont(ENTRY)
Private.SetEntryVisibility(ENTRY)
return ENTRY
end
function Private.UpdateEntry(ENTRY)
local stackInfo = ENTRY.stackInfo
-- Ensure tag is up to date
if not stackInfo.ids[ENTRY.PLATE:GetTag()] then
local key, val = next(stackInfo.ids)
ENTRY.PLATE:SetTag(key)
end
-- Update stack
if stackInfo then
-- We want to see the count if it is higher than 1
-- OR if the quantity is higher than 1 (we want to see that it is 3 crystite on the ground).
-- Since quantity can not be lower then count (quantity is either 1 or higher, there are no half items), we only check quantity here
local stackText = ''
if stackInfo.quantity > 1 then
stackText = tostring(stackInfo.count)
end
-- Add in quantity if it is of interest
if stackInfo.quantity > stackInfo.count then
stackText = stackText .. ' (' .. tostring(stackInfo.quantity) .. ')'
end
ENTRY.STACK:SetText(stackText)
end
end
function Private.SetEntrySize(ENTRY)
-- Get height from options
local sizeAsNumber = tonumber(Options['HUDTracker']['EntrySize'])
local sizeAsText = tostring(sizeAsNumber)
-- Entry
ENTRY.GROUP:SetDims('width:100%; height:'..sizeAsText..';')
-- Plate
local plateLeftOffset = tostring(0) -- tostring(sizeAsNumber - DimensionOptions.plateLeftOverlap) -- (width of box - px for overlap)
local plateHeightReduced = tostring(sizeAsText - (2*DimensionOptions.plateHeightBorderReduction)); -- 2 top and 2 bot to free up space for the bottom borders of the plate
ENTRY.PLATE:SetDims('width:100%-'..plateLeftOffset..'; height:'..plateHeightReduced..';top:'..tostring(DimensionOptions.plateHeightBorderReduction)..';left:'..plateLeftOffset)
-- Box (affecting Icon)
local boxDimms = 'width:'..sizeAsText..'; height:'..sizeAsText..';' .. 'left:0; top:0;'
ENTRY.BOX:SetDims(boxDimms)
-- Text
local textDimms = 'width:100%-'..sizeAsText..'; height:'..plateHeightReduced..';top:'..tostring(DimensionOptions.plateHeightBorderReduction)..';left:'..sizeAsText
ENTRY.TEXT:SetDims(textDimms)
end
function Private.SetEntryFont(ENTRY)
local fontType = tostring(Options['HUDTracker']['EntryFontType'])
local fontSize = tostring(Options['HUDTracker']['EntryFontSize'])
local suffix = ''
if fontType == OptionsFontTypes.Wide then
suffix = 'B'
end
local font = fontType .. '_' .. fontSize..suffix
ENTRY.TITLE:SetFont(font)
end
function Private.SetEntryVisibility(ENTRY)
-- Text Visibility
ENTRY.STACK:Show(true)
ENTRY.TITLE:Show(true)
-- Plate
local plateMode = Options['HUDTracker']['PlateMode']
ENTRY.PLATE:GetChild('bg'):Show( (plateMode ~= HUDTrackerPlateModeOptions.None ) )
ENTRY.PLATE:GetChild('outer'):Show( (plateMode == HUDTrackerPlateModeOptions.Decorated) )
ENTRY.PLATE:GetChild('shade'):Show( (plateMode == HUDTrackerPlateModeOptions.Decorated) )
-- Icon Box
local boxMode = Options['HUDTracker']['IconMode']
ENTRY.BOX:GetChild('bg'):Show( ( boxMode == HUDTrackerIconModeOptions.Decorated
or boxMode == HUDTrackerIconModeOptions.Simple) )
ENTRY.BOX:GetChild('backplate'):Show( ( boxMode == HUDTrackerIconModeOptions.Decorated
or boxMode == HUDTrackerIconModeOptions.Simple) )
ENTRY.BOX:GetChild('outer'):Show( (boxMode == HUDTrackerIconModeOptions.Decorated) )
ENTRY.BOX:GetChild('shade'):Show( (boxMode == HUDTrackerIconModeOptions.Decorated) )
ENTRY.BOX:GetChild('icon'):Show( boxMode ~= HUDTrackerIconModeOptions.None)
end
-- Gets filtered display name of loot from options
function GetHUDTrackerTitle(loot)
local categoryKey, rarityKey = Filtering.GetFilteringOptionsKeys(loot, Options['HUDTracker']['Filtering'])
local formatString = Options['HUDTracker']['Filtering'][categoryKey][rarityKey]['HUDTrackerTitle']
return tostring(Messages.TextFilters(formatString, {loot=loot}), true)
end
-- Return true if lootA should come before lootB
function HUDTrackerSort(lootA, lootB)
--Debug.Log('************** HUDTrackerSort *********** ')
-- Handle nil values
if lootA == nil and lootB == nil then
--Debug.Log('A and B are nil, result: false')
return false
end
if lootA == nil then
--Debug.Log('A is nil, result: false')
return false
end
if lootB == nil then
--Debug.Log('B is nil, result: true')
return true
end
-- Non Nil Results
--Debug.Log('A: '..tostring(lootA:ToString())..' | Rarity:'..tostring(lootA:GetRarityValue()) .. ' | ItemLevel:' .. tostring(lootA:GetItemLevel()))
--Debug.Log('B: '..tostring(lootB:ToString())..' | Rarity:'..tostring(lootB:GetRarityValue()) .. ' | ItemLevel:' .. tostring(lootB:GetItemLevel()))
lootA = lootA.stackInfo.sortProfile
lootB = lootB.stackInfo.sortProfile
-- Rarer items first
local rarityA = lootA.rarityValue
local rarityB = lootB.rarityValue
if rarityA ~= rarityB then
--Debug.Log('Prioritizing rarity')
--Debug.Log('A: Rarity ' .. tostring(rarityA))
--Debug.Log('B: Rarity ' .. tostring(rarityB))
--Debug.Log('A before B? : ' .. tostring((rarityA > rarityB)))
return (rarityA > rarityB)
end
-- Better items second
local ilvlA = lootA.itemLevel
local ilvlB = lootB.itemLevel
if ilvlA ~= ilvlB then
--Debug.Log('Prioritizing ItemLevel')
--Debug.Log('A: ItemLevel ' .. tostring(ilvlA))
--Debug.Log('B: ItemLevel ' .. tostring(ilvlB))
--Debug.Log('A before B? : ' .. tostring((ilvlA > ilvlB)))
return (ilvlA > ilvlB)
end
-- Alphabetic third
--Debug.Log('Prioritizing alphabetic')
return (lootA.name < lootB.name)
end
-- Fix text size
function AutosizeText(TEXT)
TEXT:SetDims('top:_; height:'..(TEXT:GetTextDims().height+DimensionOptions.textAutoSizeHeightIncrease))
end