forked from LetsTimeIt/DungeonTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AceGUIWidget-DungeonToolsPullButton.lua
1427 lines (1294 loc) · 55.1 KB
/
AceGUIWidget-DungeonToolsPullButton.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local Type, Version = "MDTPullButton", 1
local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
local MDT = MDT
local L = MDT.L
local width,height = 248,32
local maxPortraitCount = 8
local tinsert,SetPortraitToTexture,SetPortraitTextureFromCreatureDisplayID,GetItemQualityColor,MouseIsOver = table.insert,SetPortraitToTexture,SetPortraitTextureFromCreatureDisplayID,GetItemQualityColor,MouseIsOver
local next = next
local dragdrop_overlap = 2000
local function GetDropTarget()
local scrollFrame = MDT.main_frame.sidePanel.pullButtonsScrollFrame
local buttonList = MDT.main_frame.sidePanel.newPullButtons
local id, button, pos, offset
if scrollFrame.frame:IsMouseOver(1, -1, -dragdrop_overlap, dragdrop_overlap) then
-- Find hovered pull
repeat
repeat
id, button = next(buttonList, id)
until not id or not button.dragging and button:IsShown()
if id and button then
offset = (button.frame.height or button.frame:GetHeight() or 32) / 2
pos = (button.frame:IsMouseOver(2, offset, -dragdrop_overlap, dragdrop_overlap) and "TOP")
or (button.frame:IsMouseOver(-offset, -1, -dragdrop_overlap, dragdrop_overlap) and "BOTTOM")
end
until not id or pos
-- Is add new pull hovered?
if not id then
local addNewPullButton = MDT.main_frame.sidePanel.newPullButton
if addNewPullButton.frame:IsMouseOver(2) then
local maxPulls = #MDT:GetCurrentPreset().value.pulls
id = maxPulls
button = buttonList[id]
pos = "BOTTOM"
-- Is the last button dragged?
if button.dragging and id > 1 then
id = id - 1
button = buttonList[id]
pos = "BOTTOM"
end
end
end
-- Is pull over space between add pull button and
-- bottom border of the scroll frame?
local viewheight = scrollFrame.frame.obj.content:GetHeight()
if not id and viewheight < scrollFrame.frame:GetHeight() then
if scrollFrame.frame:IsMouseOver(-viewheight, -1, -dragdrop_overlap, dragdrop_overlap) then
local maxPulls = #MDT:GetCurrentPreset().value.pulls
id = maxPulls
button = buttonList[id]
pos = "BOTTOM"
-- Is the last button dragged?
if button.dragging and id > 1 then
id = id - 1
button = buttonList[id]
pos = "BOTTOM"
end
end
end
end
local scroll_value_min = 25
local scroll_value_max = 975
local scroll_value = scrollFrame.localstatus.scrollvalue
local scroll_frame_height = (scrollFrame.frame.height or scrollFrame.frame:GetHeight())
-- Top Graceful Area
if scrollFrame.frame:IsMouseOver(100, scroll_frame_height+1, -dragdrop_overlap, dragdrop_overlap) and scroll_value < scroll_value_min then
id, button, pos = 1, buttonList[1], "TOP"
if button.dragging then
id, button, pos = 2, buttonList[2], "TOP"
end
end
-- Bottom Graceful Area
if scrollFrame.frame:IsMouseOver(-(scroll_frame_height+1), -100, -dragdrop_overlap, dragdrop_overlap) and scroll_value > scroll_value_max then
local maxPulls = #MDT:GetCurrentPreset().value.pulls
id = maxPulls
button = buttonList[id]
pos = "BOTTOM"
-- Is the last button dragged?
if button.dragging and id > 1 then
id = id - 1
button = buttonList[id]
pos = "BOTTOM"
end
end
-- Seems to be outside of the list
-- drop it back to it's original position
if not id then
repeat
id, button = next(buttonList, id)
until button.dragging
if id > 1 then
id = id - 1
button = buttonList[id]
pos = "BOTTOM"
elseif id == 1 then
id = 2
button = buttonList[id]
pos = "TOP"
end
end
return id, button, pos
end
--Methods
local methods = {
["OnAcquire"] = function(self)
self:SetWidth(width);
self:SetHeight(height);
end,
["Initialize"] = function(self)
self.callbacks = {}
function self.callbacks.OnClickNormal(_, mouseButton)
if not MouseIsOver(MDT.main_frame.sidePanel.pullButtonsScrollFrame.frame) then return end
if(IsControlKeyDown())then
if (mouseButton == "LeftButton") then
--print("CTRL+MouseButton:Left")
if not MDT.U.contains(MDT:GetSelection(), self.index) then
tinsert(MDT:GetSelection(), self.index)
MDT:SetMapSublevel(self.index)
MDT:SetSelectionToPull(MDT:GetSelection())
else
MDT.U.iremove_if(MDT:GetSelection(), function(entry)
return entry == self.index
end)
self:ClearPick()
end
end
elseif(IsShiftKeyDown()) then
if (mouseButton == "LeftButton") then
--print("SHIFT+MouseButton:Left")
local selection = MDT:GetSelection()
local lastPull = selection[#selection]
local step = 1
if self.index <= lastPull then
step = -1
end
for i=lastPull, self.index, step do
if not MDT.U.contains(selection, i) then
tinsert(selection, i)
end
end
MDT:SetMapSublevel(self.index)
MDT:SetSelectionToPull(selection)
--print(#selection)
elseif (mouseButton == "RightButton") then
local maxPulls = #MDT:GetCurrentPreset().value.pulls
if maxPulls>1 then
MDT:DeletePull(self.index)
end
end
else
MDT:EnsureDBTables()
if(mouseButton == "RightButton") then
-- Add current pull to selection, if not already selected
if not MDT.U.contains(MDT:GetSelection(), self.index) then
if #MDT:GetSelection() == 1 then
MDT:SetSelectionToPull(self.index)
else
tinsert(MDT:GetSelection(), self.index)
self:Pick()
end
end
-- Backup color for every selected pull
for _, pullIdx in ipairs(MDT:GetSelection()) do
local button = MDT:GetPullButton(pullIdx)
if button then
button:BackupColor()
end
end
if #MDT:GetSelection() > 1 then
L_EasyMenu(self.multiselectMenu, MDT.main_frame.sidePanel.optionsDropDown, "cursor", 0 , -15, "MENU")
else
MDT:SetMapSublevel(self.index)
MDT:SetSelectionToPull(self.index)
L_EasyMenu(self.menu, MDT.main_frame.sidePanel.optionsDropDown, "cursor", 0 , -15, "MENU")
end
else
--normal click
MDT:GetCurrentPreset().value.selection = { self.index }
MDT:SetMapSublevel(self.index)
MDT:SetSelectionToPull(self.index)
end
end
end
function self.callbacks.OnEnter()
MDT.pullTooltip:SetPoint("TOPRIGHT",self.frame,"TOPLEFT",0,0)
MDT.pullTooltip:SetPoint("BOTTOMRIGHT",self.frame,"TOPLEFT",-250,-(4+ MDT.pullTooltip.myHeight))
local tooltipBottom = MDT.pullTooltip:GetBottom()
local mainFrameBottom = MDT.main_frame:GetBottom()
if tooltipBottom<mainFrameBottom then
MDT.pullTooltip:SetPoint("TOPRIGHT",self.frame,"BOTTOMLEFT",0,(4+ MDT.pullTooltip.myHeight))
MDT.pullTooltip:SetPoint("BOTTOMRIGHT",self.frame,"BOTTOMLEFT",-250,-4)
end
self.entered = true
MDT:ActivatePullTooltip(self.index)
self.frame:SetScript("OnUpdate", self:CreateUpdateFunction())
--progressbar
if MDT.ProgressBarResetTimer then MDT.ProgressBarResetTimer:Cancel() end
local currentForces = MDT:CountForces(self.index)
local db = MDT:GetDB()
local teeming = MDT:IsCurrentPresetTeeming()
MDT:Progressbar_SetValue(MDT.main_frame.sidePanel.ProgressBar,currentForces,teeming and MDT.dungeonTotalCount[db.currentDungeonIdx].teeming or MDT.dungeonTotalCount[db.currentDungeonIdx].normal)
end
function self.callbacks.OnLeave()
MDT.pullTooltip.Model:Hide()
MDT.pullTooltip.topString:Hide()
self.entered = false
self.frame:SetScript("OnUpdate", nil)
MDT:UpdatePullTooltip(MDT.pullTooltip)
MDT.pullTooltip:Hide()
MDT.ProgressBarResetTimer = C_Timer.NewTimer(0.35, function()
MDT:UpdateProgressbar()
end)
end
function self.callbacks.OnDragStart()
self:Drag()
end
function self.callbacks.OnDragStop()
self:Drop()
end
function self.callbacks.OnKeyDown(self, key)
if (key == "ESCAPE") then
--
end
end
-- Normal Dropdown menu
self.menu = {}
if self.index ~= 1 then
tinsert(self.menu, {
text = L["Pull Drop Move up"],
notCheckable = 1,
func = function()
MDT:MovePullUp(self.index)
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
end
})
end
if self.index<self.maxPulls then
tinsert(self.menu, {
text = L["Pull Drop Move down"],
notCheckable = 1,
func = function()
MDT:MovePullDown(self.index)
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
end
})
end
--[[
if self.index ~= 1 or self.index < self.maxPulls then
tinsert(self.menu, {
text = " ",
notClickable = 1,
notCheckable = 1,
func = nil
})
end
]]--
tinsert(self.menu, {
text = L["Pull Drop Insert before"],
notCheckable = 1,
func = function()
MDT:PresetsAddPull(self.index)
MDT:ReloadPullButtons()
MDT:SetSelectionToPull(self.index)
MDT:ColorAllPulls(_, self.index)
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
MDT:DrawAllHulls()
end
})
tinsert(self.menu, {
text = L["Pull Drop Insert after"],
notCheckable = 1,
func = function()
MDT:PresetsAddPull(self.index + 1)
MDT:ReloadPullButtons()
MDT:SetSelectionToPull(self.index + 1)
MDT:ColorAllPulls(_, self.index+1)
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
MDT:DrawAllHulls()
end
})
if self.index ~= 1 then
tinsert(self.menu, {
text = L["Pull Drop Merge up"],
notCheckable = 1,
func = function()
local newIndex = MDT:PresetsMergePulls(self.index, self.index - 1)
MDT:ReloadPullButtons()
MDT:SetSelectionToPull(newIndex)
MDT:ColorAllPulls(_, newIndex)
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
MDT:DrawAllHulls()
end
})
end
if self.index < self.maxPulls then
tinsert(self.menu, {
text = L["Pull Drop Merge down"],
notCheckable = 1,
func = function()
local newIndex = MDT:PresetsMergePulls(self.index, self.index + 1)
MDT:ReloadPullButtons()
MDT:SetSelectionToPull(newIndex)
MDT:ColorAllPulls(_, newIndex)
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
MDT:DrawAllHulls()
end
})
end
if self.index ~= 1 or self.index < self.maxPulls then
tinsert(self.menu, {
text = " ",
notClickable = 1,
notCheckable = 1,
func = nil
})
end
tinsert(self.menu, {
text = L["Pull Drop Color Settings"],
notCheckable = 1,
func = function()
MDT:OpenAutomaticColorsDialog()
end
})
tinsert(self.menu, {
text = L["Pull Drop Colorize Preset"],
notCheckable = 1,
func = function()
local db = MDT:GetDB()
if not db.colorPaletteInfo.autoColoring then
db.colorPaletteInfo.autoColoring = true
MDT.main_frame.AutomaticColorsCheck:SetValue(db.colorPaletteInfo.autoColoring)
MDT.main_frame.AutomaticColorsCheckSidePanel:SetValue(db.colorPaletteInfo.autoColoring)
MDT.main_frame.toggleForceColorBlindMode:SetDisabled(false)
end
MDT:SetPresetColorPaletteInfo()
MDT:ColorAllPulls()
MDT:DrawAllHulls()
end
})
local function swatchFunc()
local r,g,b = ColorPickerFrame:GetColorRGB()
local colorHex = MDT:RGBToHex(r,g,b)
if colorHex == "228b22" then
r,g,b = 2*r,2*g,2*b
ColorPickerFrame:SetColorRGB(r,g,b)
end
MDT:DungeonEnemies_SetPullColor(self.index,r,g,b)
MDT:UpdatePullButtonColor(self.index, r, g, b)
MDT:DungeonEnemies_UpdateBlipColors(self.index,r,g,b)
MDT:DrawAllHulls()
L_CloseDropDownMenus()
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_QueueColorUpdate()
end
end
local function cancelFunc()
self:RevertColor()
MDT:DungeonEnemies_SetPullColor(self.index, self.color.r, self.color.g, self.color.b)
MDT:UpdatePullButtonColor(self.index, self.color.r, self.color.g, self.color.b)
MDT:DungeonEnemies_UpdateBlipColors(self.index, self.color.r, self.color.g, self.color.b)
MDT:DrawAllHulls()
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_QueueColorUpdate()
end
end
tinsert(self.menu, {
text = L["Pull Drop Color"]..": ",
notCheckable = 1,
hasColorSwatch = true,
r = self.color.r,
g = self.color.g,
b = self.color.b,
func = function()
ColorPickerFrame.func = swatchFunc
ColorPickerFrame.opacityFunc = nil
ColorPickerFrame.cancelFunc = cancelFunc
ColorPickerFrame:SetColorRGB(self.color.r, self.color.g, self.color.b)
ColorPickerFrame.hasOpacity = false
ColorPickerFrame.previousValues = {self.color.r, self.color.g, self.color.b}
ColorPickerFrame:Hide() -- Need to run the OnShow
ColorPickerFrame:Show()
L_CloseDropDownMenus()
end,
swatchFunc = swatchFunc,
cancelFunc = cancelFunc,
})
tinsert(self.menu, {
text = L["Pull Drop Reset Color"],
notCheckable = 1,
func = function()
local r,g,b = 34/255,139/255,34/255
MDT:DungeonEnemies_SetPullColor(self.index,r,g,b)
MDT:UpdatePullButtonColor(self.index, r, g, b)
MDT:DungeonEnemies_UpdateBlipColors(self.index,r,g,b)
MDT:DrawAllHulls()
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
end
})
tinsert(self.menu, {
text = " ",
notClickable = 1,
notCheckable = 1,
func = nil
})
tinsert(self.menu, {
text = L["Pull Drop Clear Pull"],
notCheckable = 1,
func = function()
MDT:ClearPull(self.index)
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
end
})
tinsert(self.menu, {
text = L["Pull Drop Reset Preset"],
notCheckable = 1,
func = function() MDT:OpenClearPresetDialog() end
})
if self.maxPulls > 1 then
tinsert(self.menu, {
text = L["Pull Drop Delete"],
notCheckable = 1,
func = function()
MDT:DeletePull(self.index)
MDT:ColorAllPulls(_, self.index)
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
MDT:DrawAllHulls()
end
})
tinsert(self.menu, {
text = " ",
notClickable = 1,
notCheckable = 1,
func = nil
})
end
tinsert(self.menu, {
text = L["Pull Drop Close"],
notCheckable = 1,
--func = MDT.main_frame.sidePanel.optionsDropDown:Hide()
func = nil
})
-- Multiselect drop down menu
self.multiselectMenu = {}
tinsert(self.multiselectMenu, {
text = L["Pull Drop Insert before"],
notCheckable = 1,
func = function()
MDT.U.do_if(MDT:GetSelection(), {
condition = function(entry)
return entry >= self.index
end,
update = function(t, key)
t[key] = t[key] + 1
end
})
MDT:PresetsAddPull(self.index)
MDT:ReloadPullButtons()
MDT:SetSelectionToPull(self.index)
--MDT:UpdateAutomaticColors(self.index)
MDT:ColorAllPulls(_, self.index)
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
MDT:DrawAllHulls()
end
})
tinsert(self.multiselectMenu, {
text = L["Pull Drop Insert after"],
notCheckable = 1,
func = function()
MDT.U.do_if(MDT:GetSelection(), {
condition = function(entry)
return entry > self.index
end,
update = function(t, key)
t[key] = t[key] + 1
end
})
MDT:PresetsAddPull(self.index + 1)
MDT:ReloadPullButtons()
MDT:SetSelectionToPull(self.index + 1)
--MDT:UpdateAutomaticColors(self.index + 1)
MDT:ColorAllPulls(_, self.index+1)
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
MDT:DrawAllHulls()
end
})
tinsert(self.multiselectMenu, {
text = L["Pull Drop Merge"],
notCheckable = 1,
func = function()
local selected_pulls = MDT.U.copy(MDT:GetSelection())
-- Assure, that the destination is always the last selected_pull, to copy it's options at last
MDT.U.iremove_if(selected_pulls, function(pullIdx)
return pullIdx == self.index
end)
if not MDT.U.contains(selected_pulls, self.index) then
tinsert(selected_pulls, self.index)
end
local newIndex = MDT:PresetsMergePulls(selected_pulls, self.index)
MDT:ReloadPullButtons()
MDT:GetCurrentPreset().value.selection = { newIndex }
MDT:SetSelectionToPull(newIndex)
MDT:ColorAllPulls(_, newIndex)
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
MDT:DrawAllHulls()
end
})
tinsert(self.multiselectMenu, {
text = " ",
notClickable = 1,
notCheckable = 1,
func = nil
})
tinsert(self.multiselectMenu, {
text = L["Pull Drop Color Settings"],
notCheckable = 1,
func = function()
MDT:OpenAutomaticColorsDialog()
end
})
tinsert(self.multiselectMenu, {
text = L["Pull Drop Colorize Preset"],
notCheckable = 1,
func = function()
local db = MDT:GetDB()
if not db.colorPaletteInfo.autoColoring then
db.colorPaletteInfo.autoColoring = true
MDT.main_frame.AutomaticColorsCheck:SetValue(db.colorPaletteInfo.autoColoring)
MDT.main_frame.AutomaticColorsCheckSidePanel:SetValue(db.colorPaletteInfo.autoColoring)
MDT.main_frame.toggleForceColorBlindMode:SetDisabled(false)
end
MDT:SetPresetColorPaletteInfo()
MDT:ColorAllPulls()
MDT:DrawAllHulls()
end
})
local function swatchMultiFunc()
local r,g,b = ColorPickerFrame:GetColorRGB()
local colorHex = MDT:RGBToHex(r,g,b)
if colorHex == "228b22" then
r,g,b = 2*r,2*g,2*b
ColorPickerFrame:SetColorRGB(r,g,b)
end
if not MDT.U.contains(MDT:GetSelection(), self.index) then
tinsert(MDT:GetSelection(), self.index)
self:Pick()
end
for _, pullIdx in ipairs(MDT:GetSelection()) do
MDT:DungeonEnemies_SetPullColor(pullIdx,r,g,b)
MDT:UpdatePullButtonColor(pullIdx, r, g, b)
MDT:DungeonEnemies_UpdateBlipColors(pullIdx,r,g,b)
end
MDT:DrawAllHulls()
L_CloseDropDownMenus()
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_QueueColorUpdate()
end
end
local function cancelMultiFunc()
if not MDT.U.contains(MDT:GetSelection(), self.index) then
tinsert(MDT:GetSelection(), self.index)
self:Pick()
end
for _, pullIdx in ipairs(MDT:GetSelection()) do
local button = MDT:GetPullButton(pullIdx)
if button then
button:RevertColor()
local color = {
r = button.color.r,
g = button.color.g,
b = button.color.b
}
MDT:DungeonEnemies_SetPullColor(pullIdx, color.r, color.g, color.b)
MDT:UpdatePullButtonColor(pullIdx, color.r, color.g, color.b)
MDT:DungeonEnemies_UpdateBlipColors(pullIdx, color.r, color.g, color.b)
end
end
self:RevertColor()
MDT:DungeonEnemies_SetPullColor(self.index, self.color.r, self.color.g, self.color.b)
MDT:UpdatePullButtonColor(self.index, self.color.r, self.color.g, self.color.b)
MDT:DungeonEnemies_UpdateBlipColors(self.index, self.color.r, self.color.g, self.color.b)
MDT:DrawAllHulls()
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_QueueColorUpdate()
end
end
tinsert(self.multiselectMenu, {
text = L["Pull Drop Color"]..": ",
notCheckable = 1,
hasColorSwatch = true,
r = self.color.r,
g = self.color.g,
b = self.color.b,
func = function()
ColorPickerFrame.func = swatchMultiFunc
ColorPickerFrame.opacityFunc = nil
ColorPickerFrame.cancelFunc = cancelMultiFunc
ColorPickerFrame:SetColorRGB(self.color.r, self.color.g, self.color.b)
ColorPickerFrame.hasOpacity = false
ColorPickerFrame.previousValues = {self.color.r, self.color.g, self.color.b}
ColorPickerFrame:Hide() -- Need to run the OnShow
ColorPickerFrame:Show()
L_CloseDropDownMenus()
end,
swatchFunc = swatchMultiFunc,
cancelFunc = cancelMultiFunc
})
tinsert(self.multiselectMenu, {
text = L["Pull Drop Reset Color"],
notCheckable = 1,
func = function()
local r,g,b = 34/255,139/255,34/255
if not MDT.U.contains(MDT:GetSelection(), self.index) then
tinsert(MDT:GetSelection(), self.index)
self:Pick()
end
for _, pullIdx in ipairs(MDT:GetSelection()) do
MDT:DungeonEnemies_SetPullColor(pullIdx,r,g,b)
MDT:UpdatePullButtonColor(pullIdx, r, g, b)
MDT:DungeonEnemies_UpdateBlipColors(pullIdx,r,g,b)
L_CloseDropDownMenus()
end
MDT:DrawAllHulls()
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
end
})
if self.index ~= 1 or self.index < self.maxPulls then
tinsert(self.multiselectMenu, {
text = " ",
notClickable = 1,
notCheckable = 1,
func = nil
})
end
tinsert(self.multiselectMenu, {
text = L["Pull Drop Clear"],
notCheckable = 1,
func = function()
if not MDT.U.contains(MDT:GetSelection(), self.index) then
tinsert(MDT:GetSelection(), self.index)
self:Pick()
end
for _, pullIdx in ipairs(MDT:GetSelection()) do
MDT:ClearPull(pullIdx)
end
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
end
})
tinsert(self.multiselectMenu, {
text = L["Pull Drop Reset Preset"],
notCheckable = 1,
func = function() MDT:OpenClearPresetDialog() end
})
if self.maxPulls > 1 then
tinsert(self.multiselectMenu, {
text = L["Pull Drop Delete"],
notCheckable = 1,
func = function()
local addPull = false
local button = MDT:GetFirstNotSelectedPullButton(self.index, "UP")
if not button then
button = MDT:GetFirstNotSelectedPullButton(self.index, "DOWN")
if not button then
addPull = true
button = 1
end
end
local removed_pulls = {}
for _, pullIdx in pairs(MDT.GetSelection()) do
local offset = MDT.U.count_if(removed_pulls, function(entry)
return entry < pullIdx
end)
MDT:DeletePull(pullIdx - offset)
tinsert(removed_pulls, pullIdx)
end
MDT.GetCurrentPreset().value.selection = {}
if not addPull then
local offset = MDT.U.count_if(removed_pulls, function(entry)
return entry < button
end)
MDT:SetSelectionToPull(button - offset)
else
--MDT:AddPull(1) --we handle not deleting all pulls in MDT:DeletePull() instead
MDT:SetSelectionToPull(1)
end
MDT:DrawAllHulls()
if MDT.liveSessionActive and MDT:GetCurrentPreset().uid == MDT.livePresetUID then
MDT:LiveSession_SendPulls(MDT:GetPulls())
end
end
})
end
tinsert(self.multiselectMenu, {
text = " ",
notClickable = 1,
notCheckable = 1,
func = nil
})
tinsert(self.multiselectMenu, {
text = L["Pull Drop Close"],
notCheckable = 1,
func = MDT.main_frame.sidePanel.optionsDropDown:Hide()
})
--Set pullNumber
self.pullNumber:SetText(self.index)
self.pullNumber:Show()
self.frame:SetScript("OnClick", self.callbacks.OnClickNormal);
self.frame:SetScript("OnKeyDown", self.callbacks.OnKeyDown);
self.frame:SetScript("OnEnter", self.callbacks.OnEnter);
self.frame:SetScript("OnLeave", self.callbacks.OnLeave);
self.frame:EnableKeyboard(false);
self.frame:SetMovable(true);
self.frame:RegisterForDrag("LeftButton");
self.frame:SetScript("OnDragStart", self.callbacks.OnDragStart);
self.frame:SetScript("OnDragStop", self.callbacks.OnDragStop);
self:Enable();
self:InitializeScrollHover()
end,
["InitializeScrollHover"] = function(self)
local scrollFrame = MDT.main_frame.sidePanel.pullButtonsScrollFrame
local height = (scrollFrame.frame.height or scrollFrame.frame:GetHeight())
self.scroll_hover = {
height = 100,
offset = 20,
timeout = 0.05,
pulls_per_second = {
min = 2.5,
max = 15
},
top = {},
bottom = {}
}
-- Top
tinsert(self.scroll_hover.top, {
speed = 0.20,
mouseover = {
top = ((self.scroll_hover.height + self.scroll_hover.offset) / 5) - self.scroll_hover.offset,
bottom = height - self.scroll_hover.offset,
left = -dragdrop_overlap,
right = dragdrop_overlap
}
})
tinsert(self.scroll_hover.top, {
speed = 0.4,
mouseover = {
top = 2 * ((self.scroll_hover.height + self.scroll_hover.offset) / 5) - self.scroll_hover.offset,
bottom = height - self.scroll_hover.offset,
left = -dragdrop_overlap,
right = dragdrop_overlap
}
})
tinsert(self.scroll_hover.top, {
speed = 0.6,
mouseover = {
top = 3 * ((self.scroll_hover.height + self.scroll_hover.offset) / 5) - self.scroll_hover.offset,
bottom = height - self.scroll_hover.offset,
left = -dragdrop_overlap,
right = dragdrop_overlap
}
})
tinsert(self.scroll_hover.top, {
speed = 0.8,
mouseover = {
top = 4 * ((self.scroll_hover.height + self.scroll_hover.offset) / 5) - self.scroll_hover.offset,
bottom = height - self.scroll_hover.offset,
left = -dragdrop_overlap,
right = dragdrop_overlap
}
})
-- Bottom
tinsert(self.scroll_hover.bottom, {
speed = 0.2,
mouseover = {
top = self.scroll_hover.offset - height,
bottom = (-(self.scroll_hover.height + self.scroll_hover.offset) / 5) + self.scroll_hover.offset,
left = -dragdrop_overlap,
right = dragdrop_overlap
}
})
tinsert(self.scroll_hover.bottom, {
speed = 0.4,
mouseover = {
top = self.scroll_hover.offset - height,
bottom = 2 * (-(self.scroll_hover.height + self.scroll_hover.offset) / 5) + self.scroll_hover.offset,
left = -dragdrop_overlap,
right = dragdrop_overlap
}
})
tinsert(self.scroll_hover.bottom, {
speed = 0.6,
mouseover = {
top = self.scroll_hover.offset - height,
bottom = 3 * (-(self.scroll_hover.height + self.scroll_hover.offset) / 5) + self.scroll_hover.offset,
left = -dragdrop_overlap,
right = dragdrop_overlap
}
})
tinsert(self.scroll_hover.bottom, {
speed = 0.8,
mouseover = {
top = self.scroll_hover.offset - height,
bottom = 4 * (-(self.scroll_hover.height + self.scroll_hover.offset) / 5) + self.scroll_hover.offset,
left = -dragdrop_overlap,
right = dragdrop_overlap
}
})
end,
["GetScrollSpeed"] = function(self, frame, speedList)
for index, entry in ipairs(speedList) do
local m = entry.mouseover
if frame:IsMouseOver(m.top, m.bottom, m.left, m.right) then
return entry.speed
end
end
return 1
end,
["CreateUpdateFunction"] = function(self)
if not self.updateFunction then
self.updateFunction = function(frame, elapsed)
if self.entered and not self.dragging then
MDT:UpdatePullTooltip(MDT.pullTooltip)
end
if self.dragging then
if MDT.pullTooltip:IsShown() then
MDT.pullTooltip:Hide()
end
local scroll_hover = self.scroll_hover
local scrollFrame = MDT.main_frame.sidePanel.pullButtonsScrollFrame
local height = (scrollFrame.frame.height or scrollFrame.frame:GetHeight())
if scrollFrame.frame:IsMouseOver(scroll_hover.height, height - scroll_hover.offset, -dragdrop_overlap, dragdrop_overlap) then
self.top_hover = (self.top_hover or 0) + elapsed
self.bottom_hover = 0
if self.top_hover > scroll_hover.timeout then
local scroll_speed = self:GetScrollSpeed(scrollFrame.frame, scroll_hover.top)
local scroll_pulls = MDT.U.lerp(scroll_hover.pulls_per_second.min, scroll_hover.pulls_per_second.max, scroll_speed)
local scroll_pixel = scroll_pulls * self.frame:GetHeight()
local scroll_amount = MDT:GetScrollingAmount(scrollFrame, scroll_pixel) * scroll_hover.timeout
local oldvalue = scrollFrame.localstatus.scrollvalue
local newvalue = oldvalue - scroll_amount
if newvalue < 0 then
newvalue = 0
end
scrollFrame.scrollframe.obj:SetScroll(newvalue)
scrollFrame.scrollframe.obj:FixScroll()
self.top_hover = 0
end
elseif scrollFrame.frame:IsMouseOver(scroll_hover.offset - height , -scroll_hover.height, -dragdrop_overlap, dragdrop_overlap) then
self.bottom_hover = (self.bottom_hover or 0) + elapsed
self.top_hover = 0
if self.bottom_hover > scroll_hover.timeout then
local scroll_speed = self:GetScrollSpeed(scrollFrame.frame, scroll_hover.bottom)
local scroll_pulls = MDT.U.lerp(scroll_hover.pulls_per_second.min, scroll_hover.pulls_per_second.max, scroll_speed)
local scroll_pixel = scroll_pulls * self.frame:GetHeight()
local scroll_amount = MDT:GetScrollingAmount(scrollFrame, scroll_pixel) * scroll_hover.timeout
local oldvalue = scrollFrame.localstatus.scrollvalue
local newvalue = oldvalue + scroll_amount
if newvalue > 1000 then
newvalue = 1000
end
scrollFrame.scrollframe.obj:SetScroll(newvalue)
scrollFrame.scrollframe.obj:FixScroll()
-- if FixScroll() messed up
if scrollFrame.localstatus.scrollvalue == oldvalue and newvalue >= 0 and newvalue <= 1000 and oldvalue < 985 then
scrollFrame.scrollframe.obj.scrollbar:SetValue(newvalue)
scrollFrame.scrollframe.obj:SetScroll(newvalue)
end
self.bottom_hover = 0
end
else
self.top_hover = 0
self.bottom_hover = 0
end
self.elapsed = (self.elapsed or 0) + elapsed
if self.elapsed > 0.1 then
local button, pos = select(2, GetDropTarget())
--print("Updating", self.index)
MDT:Show_DropIndicator(button, pos)
self.elapsed = 0
end
end
end
end
return self.updateFunction
end,
["Drag"] = function(self)
local sidePanel = MDT.main_frame.sidePanel
local uiscale, scale = UIParent:GetScale(), self.frame:GetEffectiveScale()
local x, w = self.frame:GetLeft(), self.frame:GetWidth()
local _, y = GetCursorPosition()
MDT.pullTooltip:Hide()
if #MDT:GetSelection() > 1 then
if not MDT.U.contains(MDT:GetSelection(), self.index) then