forked from Nnoggie/MythicDungeonTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AceGUIWidget-MethodDungeonToolsPullButton.lua
1288 lines (1163 loc) · 53.6 KB
/
AceGUIWidget-MethodDungeonToolsPullButton.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 = "MethodDungeonToolsPullButton", 1
local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
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 = MethodDungeonTools.main_frame.sidePanel.pullButtonsScrollFrame
local buttonList = MethodDungeonTools.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 = MethodDungeonTools.main_frame.sidePanel.newPullButton
if addNewPullButton.frame:IsMouseOver(2) then
local maxPulls = #MethodDungeonTools: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 = #MethodDungeonTools: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 = #MethodDungeonTools: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(MethodDungeonTools.main_frame.sidePanel.pullButtonsScrollFrame.frame) then return end
if(IsControlKeyDown())then
if (mouseButton == "LeftButton") then
--print("CTRL+MouseButton:Left")
if not MethodDungeonTools.U.contains(MethodDungeonTools:GetSelection(), self.index) then
tinsert(MethodDungeonTools:GetSelection(), self.index)
MethodDungeonTools:SetMapSublevel(self.index)
MethodDungeonTools:SetSelectionToPull(MethodDungeonTools:GetSelection())
--print(#MethodDungeonTools:GetSelection())
else
MethodDungeonTools.U.iremove_if(MethodDungeonTools:GetSelection(), function(entry)
return entry == self.index
end)
self:ClearPick()
--print(#MethodDungeonTools:GetSelection())
end
end
elseif(IsShiftKeyDown()) then
if (mouseButton == "LeftButton") then
--print("SHIFT+MouseButton:Left")
local selection = MethodDungeonTools: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 MethodDungeonTools.U.contains(selection, i) then
tinsert(selection, i)
end
end
MethodDungeonTools:SetMapSublevel(self.index)
MethodDungeonTools:SetSelectionToPull(selection)
--print(#selection)
elseif (mouseButton == "RightButton") then
local maxPulls = #MethodDungeonTools:GetCurrentPreset().value.pulls
if maxPulls>1 then
MethodDungeonTools:DeletePull(self.index)
end
end
else
MethodDungeonTools:EnsureDBTables()
if(mouseButton == "RightButton") then
-- Add current pull to selection, if not already selected
if not MethodDungeonTools.U.contains(MethodDungeonTools:GetSelection(), self.index) then
if #MethodDungeonTools:GetSelection() == 1 then
MethodDungeonTools:SetSelectionToPull(self.index)
else
tinsert(MethodDungeonTools:GetSelection(), self.index)
self:Pick()
end
end
-- Backup color for every selected pull
for _, pullIdx in ipairs(MethodDungeonTools:GetSelection()) do
local button = MethodDungeonTools:GetPullButton(pullIdx)
if button then
button:BackupColor()
end
end
if #MethodDungeonTools:GetSelection() > 1 then
L_EasyMenu(self.multiselectMenu,MethodDungeonTools.main_frame.sidePanel.optionsDropDown, "cursor", 0 , -15, "MENU")
else
MethodDungeonTools:SetMapSublevel(self.index)
MethodDungeonTools:SetSelectionToPull(self.index)
L_EasyMenu(self.menu,MethodDungeonTools.main_frame.sidePanel.optionsDropDown, "cursor", 0 , -15, "MENU")
end
else
--normal click
MethodDungeonTools:GetCurrentPreset().value.selection = { self.index }
--print(#MethodDungeonTools:GetCurrentPreset().value.selection)
MethodDungeonTools:SetMapSublevel(self.index)
MethodDungeonTools:SetSelectionToPull(self.index)
end
end
end
function self.callbacks.OnEnter()
MethodDungeonTools.pullTooltip:SetPoint("TOPRIGHT",self.frame,"TOPLEFT",0,0)
MethodDungeonTools.pullTooltip:SetPoint("BOTTOMRIGHT",self.frame,"TOPLEFT",-250,-(4+MethodDungeonTools.pullTooltip.myHeight))
local tooltipBottom = MethodDungeonTools.pullTooltip:GetBottom()
local mainFrameBottom = MethodDungeonTools.main_frame:GetBottom()
if tooltipBottom<mainFrameBottom then
MethodDungeonTools.pullTooltip:SetPoint("TOPRIGHT",self.frame,"BOTTOMLEFT",0,(4+MethodDungeonTools.pullTooltip.myHeight))
MethodDungeonTools.pullTooltip:SetPoint("BOTTOMRIGHT",self.frame,"BOTTOMLEFT",-250,-4)
end
self.entered = true
MethodDungeonTools:ActivatePullTooltip(self.index)
self.frame:SetScript("OnUpdate", self:CreateUpdateFunction())
--progressbar
if MethodDungeonTools.ProgressBarResetTimer then MethodDungeonTools.ProgressBarResetTimer:Cancel() end
local currentForces = MethodDungeonTools:CountForces(self.index)
local db = MethodDungeonTools:GetDB()
local teeming = MethodDungeonTools:IsCurrentPresetTeeming()
MethodDungeonTools:Progressbar_SetValue(MethodDungeonTools.main_frame.sidePanel.ProgressBar,currentForces,teeming and MethodDungeonTools.dungeonTotalCount[db.currentDungeonIdx].teeming or MethodDungeonTools.dungeonTotalCount[db.currentDungeonIdx].normal)
end
function self.callbacks.OnLeave()
MethodDungeonTools.pullTooltip.Model:Hide()
MethodDungeonTools.pullTooltip.topString:Hide()
self.entered = false
self.frame:SetScript("OnUpdate", nil)
MethodDungeonTools:UpdatePullTooltip(MethodDungeonTools.pullTooltip)
MethodDungeonTools.pullTooltip:Hide()
MethodDungeonTools.ProgressBarResetTimer = C_Timer.NewTimer(0.35, function()
MethodDungeonTools: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 = "Move up",
notCheckable = 1,
func = function()
MethodDungeonTools:MovePullUp(self.index)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools:GetPulls())
end
end
})
end
if self.index<self.maxPulls then
tinsert(self.menu, {
text = "Move down",
notCheckable = 1,
func = function()
MethodDungeonTools:MovePullDown(self.index)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools: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 = "Insert before",
notCheckable = 1,
func = function()
MethodDungeonTools:PresetsAddPull(self.index)
MethodDungeonTools:ReloadPullButtons()
MethodDungeonTools:SetSelectionToPull(self.index)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools:GetPulls())
end
end
})
tinsert(self.menu, {
text = "Insert after",
notCheckable = 1,
func = function()
MethodDungeonTools:PresetsAddPull(self.index + 1)
MethodDungeonTools:ReloadPullButtons()
MethodDungeonTools:SetSelectionToPull(self.index + 1)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools:GetPulls())
end
end
})
if self.index ~= 1 then
tinsert(self.menu, {
text = "Merge up",
notCheckable = 1,
func = function()
local newIndex = MethodDungeonTools:PresetsMergePulls(self.index, self.index - 1)
MethodDungeonTools:ReloadPullButtons()
MethodDungeonTools:SetSelectionToPull(newIndex)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools:GetPulls())
end
end
})
end
if self.index < self.maxPulls then
tinsert(self.menu, {
text = "Merge down",
notCheckable = 1,
func = function()
local newIndex = MethodDungeonTools:PresetsMergePulls(self.index, self.index + 1)
MethodDungeonTools:ReloadPullButtons()
MethodDungeonTools:SetSelectionToPull(newIndex)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools: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
local function swatchFunc()
local r,g,b = ColorPickerFrame:GetColorRGB()
local colorHex = MethodDungeonTools:RGBToHex(r,g,b)
if colorHex == "228b22" then
r,g,b = 2*r,2*g,2*b
ColorPickerFrame:SetColorRGB(r,g,b)
end
MethodDungeonTools:DungeonEnemies_SetPullColor(self.index,r,g,b)
MethodDungeonTools:UpdatePullButtonColor(self.index, r, g, b)
MethodDungeonTools:DungeonEnemies_UpdateBlipColors(self.index,r,g,b)
L_CloseDropDownMenus()
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_QueueColorUpdate()
end
end
local function cancelFunc()
self:RevertColor()
MethodDungeonTools:DungeonEnemies_SetPullColor(self.index, self.color.r, self.color.g, self.color.b)
MethodDungeonTools:UpdatePullButtonColor(self.index, self.color.r, self.color.g, self.color.b)
MethodDungeonTools:DungeonEnemies_UpdateBlipColors(self.index, self.color.r, self.color.g, self.color.b)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_QueueColorUpdate()
end
end
tinsert(self.menu, {
text = "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 = "Reset Color",
notCheckable = 1,
func = function()
local r,g,b = 34/255,139/255,34/255
MethodDungeonTools:DungeonEnemies_SetPullColor(self.index,r,g,b)
MethodDungeonTools:UpdatePullButtonColor(self.index, r, g, b)
MethodDungeonTools:DungeonEnemies_UpdateBlipColors(self.index,r,g,b)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools:GetPulls())
end
end
})
tinsert(self.menu, {
text = " ",
notClickable = 1,
notCheckable = 1,
func = nil
})
tinsert(self.menu, {
text = "Clear",
notCheckable = 1,
func = function()
MethodDungeonTools:ClearPull(self.index)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools:GetPulls())
end
end
})
tinsert(self.menu, {
text = "Clear Preset",
notCheckable = 1,
func = function() MethodDungeonTools:OpenClearPresetDialog() end
})
if self.maxPulls > 1 then
tinsert(self.menu, {
text = "Delete",
notCheckable = 1,
func = function()
MethodDungeonTools:DeletePull(self.index)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools:GetPulls())
end
end
})
tinsert(self.menu, {
text = " ",
notClickable = 1,
notCheckable = 1,
func = nil
})
end
tinsert(self.menu, {
text = "Close",
notCheckable = 1,
--func = MethodDungeonTools.main_frame.sidePanel.optionsDropDown:Hide()
func = nil
})
-- Multiselect drop down menu
self.multiselectMenu = {}
tinsert(self.multiselectMenu, {
text = "Insert before",
notCheckable = 1,
func = function()
MethodDungeonTools.U.do_if(MethodDungeonTools:GetSelection(), {
condition = function(entry)
return entry >= self.index
end,
update = function(t, key)
t[key] = t[key] + 1
end
})
MethodDungeonTools:PresetsAddPull(self.index)
MethodDungeonTools:ReloadPullButtons()
MethodDungeonTools:SetSelectionToPull(self.index)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools:GetPulls())
end
end
})
tinsert(self.multiselectMenu, {
text = "Insert after",
notCheckable = 1,
func = function()
MethodDungeonTools.U.do_if(MethodDungeonTools:GetSelection(), {
condition = function(entry)
return entry > self.index
end,
update = function(t, key)
t[key] = t[key] + 1
end
})
MethodDungeonTools:PresetsAddPull(self.index + 1)
MethodDungeonTools:ReloadPullButtons()
MethodDungeonTools:SetSelectionToPull(self.index + 1)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools:GetPulls())
end
end
})
tinsert(self.multiselectMenu, {
text = "Merge",
notCheckable = 1,
func = function()
local selected_pulls = MethodDungeonTools.U.copy(MethodDungeonTools:GetSelection())
-- Assure, that the destination is always the last selected_pull, to copy it's options at last
MethodDungeonTools.U.iremove_if(selected_pulls, function(pullIdx)
return pullIdx == self.index
end)
if not MethodDungeonTools.U.contains(selected_pulls, self.index) then
tinsert(selected_pulls, self.index)
end
local newIndex = MethodDungeonTools:PresetsMergePulls(selected_pulls, self.index)
MethodDungeonTools:ReloadPullButtons()
MethodDungeonTools:GetCurrentPreset().value.selection = { newIndex }
MethodDungeonTools:SetSelectionToPull(newIndex)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools:GetPulls())
end
end
})
tinsert(self.multiselectMenu, {
text = " ",
notClickable = 1,
notCheckable = 1,
func = nil
})
local function swatchMultiFunc()
local r,g,b = ColorPickerFrame:GetColorRGB()
local colorHex = MethodDungeonTools: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 MethodDungeonTools.U.contains(MethodDungeonTools:GetSelection(), self.index) then
tinsert(MethodDungeonTools:GetSelection(), self.index)
self:Pick()
end
for _, pullIdx in ipairs(MethodDungeonTools:GetSelection()) do
MethodDungeonTools:DungeonEnemies_SetPullColor(pullIdx,r,g,b)
MethodDungeonTools:UpdatePullButtonColor(pullIdx, r, g, b)
MethodDungeonTools:DungeonEnemies_UpdateBlipColors(pullIdx,r,g,b)
end
L_CloseDropDownMenus()
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_QueueColorUpdate()
end
end
local function cancelMultiFunc()
if not MethodDungeonTools.U.contains(MethodDungeonTools:GetSelection(), self.index) then
tinsert(MethodDungeonTools:GetSelection(), self.index)
self:Pick()
end
for _, pullIdx in ipairs(MethodDungeonTools:GetSelection()) do
local button = MethodDungeonTools:GetPullButton(pullIdx)
if button then
button:RevertColor()
local color = {
r = button.color.r,
g = button.color.g,
b = button.color.b
}
MethodDungeonTools:DungeonEnemies_SetPullColor(pullIdx, color.r, color.g, color.b)
MethodDungeonTools:UpdatePullButtonColor(pullIdx, color.r, color.g, color.b)
MethodDungeonTools:DungeonEnemies_UpdateBlipColors(pullIdx, color.r, color.g, color.b)
end
end
self:RevertColor()
MethodDungeonTools:DungeonEnemies_SetPullColor(self.index, self.color.r, self.color.g, self.color.b)
MethodDungeonTools:UpdatePullButtonColor(self.index, self.color.r, self.color.g, self.color.b)
MethodDungeonTools:DungeonEnemies_UpdateBlipColors(self.index, self.color.r, self.color.g, self.color.b)
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_QueueColorUpdate()
end
end
tinsert(self.multiselectMenu, {
text = "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 = "Reset Color",
notCheckable = 1,
func = function()
local r,g,b = 34/255,139/255,34/255
if not MethodDungeonTools.U.contains(MethodDungeonTools:GetSelection(), self.index) then
tinsert(MethodDungeonTools:GetSelection(), self.index)
self:Pick()
end
for _, pullIdx in ipairs(MethodDungeonTools:GetSelection()) do
MethodDungeonTools:DungeonEnemies_SetPullColor(pullIdx,r,g,b)
MethodDungeonTools:UpdatePullButtonColor(pullIdx, r, g, b)
MethodDungeonTools:DungeonEnemies_UpdateBlipColors(pullIdx,r,g,b)
L_CloseDropDownMenus()
end
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools: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 = "Clear",
notCheckable = 1,
func = function()
if not MethodDungeonTools.U.contains(MethodDungeonTools:GetSelection(), self.index) then
tinsert(MethodDungeonTools:GetSelection(), self.index)
self:Pick()
end
for _, pullIdx in ipairs(MethodDungeonTools:GetSelection()) do
MethodDungeonTools:ClearPull(pullIdx)
end
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools:GetPulls())
end
end
})
tinsert(self.multiselectMenu, {
text = "Clear Preset",
notCheckable = 1,
func = function() MethodDungeonTools:OpenClearPresetDialog() end
})
if self.maxPulls > 1 then
tinsert(self.multiselectMenu, {
text = "Delete",
notCheckable = 1,
func = function()
local addPull = false
local button = MethodDungeonTools:GetFirstNotSelectedPullButton(self.index, "UP")
if not button then
button = MethodDungeonTools:GetFirstNotSelectedPullButton(self.index, "DOWN")
if not button then
addPull = true
button = 1
end
end
local removed_pulls = {}
for _, pullIdx in pairs(MethodDungeonTools.GetSelection()) do
local offset = MethodDungeonTools.U.count_if(removed_pulls, function(entry)
return entry < pullIdx
end)
MethodDungeonTools:DeletePull(pullIdx - offset)
tinsert(removed_pulls, pullIdx)
end
MethodDungeonTools.GetCurrentPreset().value.selection = {}
if not addPull then
local offset = MethodDungeonTools.U.count_if(removed_pulls, function(entry)
return entry < button
end)
MethodDungeonTools:SetSelectionToPull(button - offset)
else
MethodDungeonTools:AddPull(1)
MethodDungeonTools:SetSelectionToPull(1)
end
if MethodDungeonTools.liveSessionActive and MethodDungeonTools:GetCurrentPreset().uid == MethodDungeonTools.livePresetUID then
MethodDungeonTools:LiveSession_SendPulls(MethodDungeonTools:GetPulls())
end
end
})
end
tinsert(self.multiselectMenu, {
text = " ",
notClickable = 1,
notCheckable = 1,
func = nil
})
tinsert(self.multiselectMenu, {
text = "Close",
notCheckable = 1,
func = MethodDungeonTools.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 = MethodDungeonTools.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
MethodDungeonTools:UpdatePullTooltip(MethodDungeonTools.pullTooltip)
end
if self.dragging then
if MethodDungeonTools.pullTooltip:IsShown() then
MethodDungeonTools.pullTooltip:Hide()
end
local scroll_hover = self.scroll_hover
local scrollFrame = MethodDungeonTools.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 = MethodDungeonTools.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 = MethodDungeonTools: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 = MethodDungeonTools.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 = MethodDungeonTools: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)
MethodDungeonTools:Show_DropIndicator(button, pos)
self.elapsed = 0
end
end
end
end
return self.updateFunction
end,
["Drag"] = function(self)
local sidePanel = MethodDungeonTools.main_frame.sidePanel
local uiscale, scale = UIParent:GetScale(), self.frame:GetEffectiveScale()
local x, w = self.frame:GetLeft(), self.frame:GetWidth()
local _, y = GetCursorPosition()
MethodDungeonTools.pullTooltip:Hide()
if #MethodDungeonTools:GetSelection() > 1 then
if not MethodDungeonTools.U.contains(MethodDungeonTools:GetSelection(), self.index) then
for _, pullIdx in pairs(MethodDungeonTools:GetSelection()) do
sidePanel.newPullButtons[pullIdx]:ClearPick()
end
MethodDungeonTools:GetCurrentPreset().value.currentPull = self.index
MethodDungeonTools:GetCurrentPreset().value.selection = { self.index }
self:Pick()
end
local selected_pulls = MethodDungeonTools.U.copy(MethodDungeonTools:GetSelection())
table.sort(selected_pulls)
for _, pullIdx in ipairs(selected_pulls) do
if pullIdx ~= self.index then
sidePanel.newPullButtons[pullIdx]:Disable()
sidePanel.newPullButtons[pullIdx].dragging = true
end
end
end
self.dragging = true
self.frame:StartMoving()
self.frame:ClearAllPoints()
self.frame.temp = {
parent = self.frame:GetParent(),
strata = self.frame:GetFrameStrata()
}
self.frame:SetParent(UIParent)
self.frame:SetFrameStrata("FULLSCREEN_DIALOG")
self.frame:SetPoint("Center", UIParent, "BOTTOMLEFT", (x+w/2)*scale/uiscale, y/uiscale)
self.frame:SetScript("OnUpdate", self:CreateUpdateFunction())
end,
["Drop"] = function(self)
local insertID, button, pos = GetDropTarget()
if not insertID then
insertID = self.maxPulls
pos = "TOP"
end
self.frame:StopMovingOrSizing()
self.dragging = false
self.frame:SetScript("OnUpdate", nil)
if self.dragging then
self.frame:SetParent(self.frame.temp.parent)
self.frame:SetFrameStrata(self.frame.temp.strata)
self.frame.temp = nil
end
if pos == "BOTTOM" then
insertID = insertID + 1
end
if #MethodDungeonTools:GetSelection() > 1 then
local sidePanel = MethodDungeonTools.main_frame.sidePanel
local selected_pulls = MethodDungeonTools.U.copy(MethodDungeonTools:GetSelection())
local new_pulls = {}
local progressed_pulls = {}
table.sort(selected_pulls)
for _, pullIdx in ipairs(selected_pulls) do
sidePanel.newPullButtons[pullIdx].dragging = false
self.dragging = false
end
--print("insert id", insertID)
for offset, pullIdx in ipairs(selected_pulls) do