-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.lua
More file actions
1647 lines (1499 loc) · 50.8 KB
/
Copy pathUI.lua
File metadata and controls
1647 lines (1499 loc) · 50.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local _, Addon = ...
local L = Addon.L
local TWO_PI = math.pi * 2
local POINTER_ANGLE = math.pi / 2
local SLOT_RADIUS = 118
local SLOT_SIZE = 86
local MAX_SLOTS = 5
local TRACKING_BORDER_CROP = 0.625
local MINIMAP_RADIUS = 5
local KEYSTONE_ITEM_ID = 180653
local WHEEL_TEXTURE = "Interface\\AddOns\\KeystoneWheel\\Media\\WheelBackdrop.tga"
local RESULT_TITLE_Y_OFFSET = -12
local MINIMAP_SHAPES = {
ROUND = { true, true, true, true },
SQUARE = { false, false, false, false },
["CORNER-TOPLEFT"] = { false, false, false, true },
["CORNER-TOPRIGHT"] = { false, false, true, false },
["CORNER-BOTTOMLEFT"] = { false, true, false, false },
["CORNER-BOTTOMRIGHT"] = { true, false, false, false },
["SIDE-LEFT"] = { false, true, false, true },
["SIDE-RIGHT"] = { true, false, true, false },
["SIDE-TOP"] = { false, false, true, true },
["SIDE-BOTTOM"] = { true, true, false, false },
["TRICORNER-TOPLEFT"] = { false, true, true, true },
["TRICORNER-TOPRIGHT"] = { true, false, true, true },
["TRICORNER-BOTTOMLEFT"] = { true, true, false, true },
["TRICORNER-BOTTOMRIGHT"] = { true, true, true, false },
}
local PALETTE = {
{ 0.25, 0.82, 0.58 },
{ 1.00, 0.67, 0.22 },
{ 0.94, 0.38, 0.57 },
{ 0.25, 0.73, 0.92 },
{ 0.68, 0.48, 0.94 },
}
local SOURCE_SHORT = {
self = L.SOURCE_SHORT_SELF,
addon = L.SOURCE_SHORT_ADDON,
lib = L.SOURCE_SHORT_LIB,
chat = L.SOURCE_SHORT_CHAT,
manual = L.SOURCE_SHORT_MANUAL,
}
local function SetTooltip(widget, title, body)
widget:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(title, 1, 0.82, 0.3)
if body then
GameTooltip:AddLine(body, 0.86, 0.86, 0.86, true)
end
GameTooltip:Show()
end)
widget:SetScript("OnLeave", GameTooltip_Hide)
end
local function CreateButton(parent, text, width)
local button = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate")
button:SetSize(width, 24)
button:SetText(text)
return button
end
local function CreateCheckbox(parent, text)
local checkbox = CreateFrame("CheckButton", nil, parent, "UICheckButtonTemplate")
local label = checkbox.Text or checkbox.text
if not label then
label = checkbox:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
label:SetPoint("LEFT", checkbox, "RIGHT", 2, 0)
end
label:SetText(text)
checkbox.label = label
return checkbox
end
local function SetClassColor(fontString, classFile)
local color = classFile and RAID_CLASS_COLORS[classFile]
if color then
fontString:SetTextColor(color.r, color.g, color.b)
else
fontString:SetTextColor(1, 0.93, 0.78)
end
end
local function IsSafeNumber(value)
return type(value) == "number" and (not issecretvalue or not issecretvalue(value))
end
function Addon:UpdateMinimapButtonPosition()
local button = self.minimapButton
if not button then
return
end
local angle = math.rad(self.db.minimapAngle or 225)
local x, y = math.cos(angle), math.sin(angle)
local quadrant = 1
if x < 0 then
quadrant = quadrant + 1
end
if y > 0 then
quadrant = quadrant + 2
end
local shape = GetMinimapShape and GetMinimapShape() or "ROUND"
local shapeData = MINIMAP_SHAPES[shape] or MINIMAP_SHAPES.ROUND
local width = (Minimap:GetWidth() / 2) + MINIMAP_RADIUS
local height = (Minimap:GetHeight() / 2) + MINIMAP_RADIUS
if shapeData[quadrant] then
x, y = x * width, y * height
else
local diagonalWidth = math.sqrt(2 * width * width) - 10
local diagonalHeight = math.sqrt(2 * height * height) - 10
x = math.max(-width, math.min(x * diagonalWidth, width))
y = math.max(-height, math.min(y * diagonalHeight, height))
end
button:ClearAllPoints()
button:SetPoint("CENTER", Minimap, "CENTER", x, y)
end
function Addon:CreateMinimapButton()
if self.minimapButton then
return
end
if self.db.minimapAngle == nil then
self.db.minimapAngle = 225
end
local button = CreateFrame("Button", "KeystoneWheelMinimapButton", Minimap)
button:SetSize(31, 31)
button:SetFrameStrata("MEDIUM")
button:SetFrameLevel(Minimap:GetFrameLevel() + 8)
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
button:RegisterForDrag("LeftButton")
button:SetHighlightTexture(136477)
self.minimapButton = button
local border = button:CreateTexture(nil, "OVERLAY")
border:SetSize(50, 50)
border:SetTexture(136430)
border:SetPoint("TOPLEFT", button, "TOPLEFT")
local background = button:CreateTexture(nil, "BACKGROUND")
background:SetSize(24, 24)
background:SetTexture(136467)
background:SetPoint("CENTER")
local icon = button:CreateTexture(nil, "ARTWORK")
icon:SetSize(18, 18)
icon:SetPoint("CENTER")
icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
button.icon = icon
local iconLabel = button:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
iconLabel:SetPoint("CENTER", icon, "CENTER", 0, 0)
iconLabel:SetText("KW")
iconLabel:SetTextColor(1, 0.78, 0.2)
iconLabel:SetShadowOffset(1, -1)
button.iconLabel = iconLabel
local function ApplyKeystoneIcon()
local iconFileID = C_Item and C_Item.GetItemIconByID and C_Item.GetItemIconByID(KEYSTONE_ITEM_ID)
if type(iconFileID) == "number" and iconFileID > 0 then
icon:SetTexture(iconFileID)
icon:SetVertexColor(1, 1, 1, 1)
iconLabel:Hide()
return true
end
icon:SetColorTexture(0.16, 0.09, 0.24, 1)
iconLabel:Show()
return false
end
if not ApplyKeystoneIcon() then
if C_Item and C_Item.RequestLoadItemDataByID then
C_Item.RequestLoadItemDataByID(KEYSTONE_ITEM_ID)
end
if Item and Item.CreateFromItemID then
Item:CreateFromItemID(KEYSTONE_ITEM_ID):ContinueOnItemLoad(function()
if button and button.icon then
ApplyKeystoneIcon()
end
end)
end
end
local count = button:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
count:SetPoint("BOTTOMRIGHT", button, "BOTTOMRIGHT", 1, -1)
count:SetTextColor(1, 0.78, 0.2)
count:SetShadowOffset(1, -1)
count:Hide()
button.count = count
button:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:AddLine("KeystoneWheel", 1, 0.82, 0.3)
GameTooltip:AddLine(L.OPEN_WHEEL, 0.9, 0.9, 0.9)
GameTooltip:AddLine(L.REFRESH_KEYS, 0.9, 0.9, 0.9)
GameTooltip:AddLine(L.DRAG_POSITION, 0.62, 0.72, 0.86)
GameTooltip:Show()
end)
button:SetScript("OnLeave", GameTooltip_Hide)
button:SetScript("OnClick", function(self, mouseButton)
if self.wasDragged then
return
end
if mouseButton == "RightButton" then
Addon:RequestAll(true)
else
Addon:ToggleUI()
end
end)
button:SetScript("OnMouseDown", function(self)
self.icon:SetTexCoord(0.12, 0.88, 0.12, 0.88)
end)
button:SetScript("OnMouseUp", function(self)
self.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
end)
button:SetScript("OnDragStart", function(self)
self:LockHighlight()
self.wasDragged = false
GameTooltip:Hide()
self:SetScript("OnUpdate", function(dragButton)
local minimapX, minimapY = Minimap:GetCenter()
local cursorX, cursorY = GetCursorPosition()
local scale = Minimap:GetEffectiveScale()
cursorX, cursorY = cursorX / scale, cursorY / scale
Addon.db.minimapAngle = math.deg(math.atan2(cursorY - minimapY, cursorX - minimapX)) % 360
dragButton.wasDragged = true
Addon:UpdateMinimapButtonPosition()
end)
end)
button:SetScript("OnDragStop", function(self)
self:SetScript("OnUpdate", nil)
self:UnlockHighlight()
C_Timer.After(0, function()
self.wasDragged = false
end)
end)
self:UpdateMinimapButtonPosition()
button:Show()
end
function Addon:CreateAddonCompartmentEntry()
if self.compartmentRegistered or not AddonCompartmentFrame then
return
end
local icon = C_Item and C_Item.GetItemIconByID and C_Item.GetItemIconByID(KEYSTONE_ITEM_ID)
AddonCompartmentFrame:RegisterAddon({
text = "KeystoneWheel",
icon = icon or 134400,
registerForAnyClick = true,
notCheckable = true,
func = function(first, second)
local buttonName
if type(second) == "table" then
buttonName = second.buttonName
elseif type(second) == "string" then
buttonName = second
elseif type(first) == "table" then
buttonName = first.buttonName
elseif first == "LeftButton" or first == "RightButton" then
buttonName = first
end
if buttonName == "RightButton" then
Addon:RequestAll(true)
else
Addon:ToggleUI()
end
end,
funcOnEnter = function()
GameTooltip:SetOwner(AddonCompartmentFrame, "ANCHOR_LEFT")
GameTooltip:AddLine("KeystoneWheel", 1, 0.82, 0.3)
GameTooltip:AddLine(L.OPEN_WHEEL, 0.9, 0.9, 0.9)
GameTooltip:AddLine(L.REFRESH_KEYS, 0.9, 0.9, 0.9)
GameTooltip:Show()
end,
funcOnLeave = function()
GameTooltip:Hide()
end,
})
self.compartmentRegistered = true
end
function Addon:ShowRerollVotePrompt(sender, voteID, required)
local displayName = Ambiguate(sender, "short") or sender
StaticPopup_Show("KEYSTONEWHEEL_REROLL_VOTE", displayName, required, {
voteID = voteID,
})
end
StaticPopupDialogs.KEYSTONEWHEEL_REROLL_VOTE = {
text = L.REROLL_VOTE_POPUP,
button1 = L.ACCEPT,
button2 = L.DECLINE,
OnAccept = function(_, data)
if data and data.voteID then
Addon:SendRerollVoteYes(data.voteID)
end
end,
timeout = 12,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
function Addon:CreateSlot(parent, index)
local slot = CreateFrame("Button", nil, parent, "BackdropTemplate")
slot:SetSize(SLOT_SIZE, SLOT_SIZE)
slot:SetFrameLevel(parent:GetFrameLevel() + 3)
slot:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
edgeSize = 2,
})
slot:RegisterForClicks("LeftButtonUp", "RightButtonUp")
local color = PALETTE[index]
slot.color = color
slot:SetBackdropColor(color[1] * 0.12, color[2] * 0.12, color[3] * 0.12, 0.96)
slot:SetBackdropBorderColor(color[1], color[2], color[3], 0.78)
slot.icon = slot:CreateTexture(nil, "ARTWORK")
slot.icon:SetSize(42, 42)
slot.icon:SetPoint("TOP", 0, -5)
slot.icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
slot.iconShade = slot:CreateTexture(nil, "OVERLAY")
slot.iconShade:SetAllPoints(slot.icon)
slot.iconShade:SetColorTexture(0, 0, 0, 0.13)
slot.player = slot:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
slot.player:SetPoint("TOPLEFT", slot, "TOPLEFT", 4, -50)
slot.player:SetPoint("TOPRIGHT", slot, "TOPRIGHT", -4, -50)
slot.player:SetJustifyH("CENTER")
slot.player:SetWordWrap(false)
if slot.player.SetMaxLines then
slot.player:SetMaxLines(1)
end
slot.key = slot:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
slot.key:SetPoint("TOPLEFT", slot.player, "BOTTOMLEFT", 0, -2)
slot.key:SetPoint("BOTTOMRIGHT", slot, "BOTTOMRIGHT", -4, 5)
slot.key:SetJustifyH("CENTER")
slot.key:SetJustifyV("TOP")
slot.key:SetWordWrap(true)
if slot.key.SetMaxLines then
slot.key:SetMaxLines(2)
end
slot.levelBadge = CreateFrame("Frame", nil, slot, "BackdropTemplate")
slot.levelBadge:SetSize(31, 20)
slot.levelBadge:SetPoint("TOPLEFT", slot, "TOPLEFT", 3, -3)
slot.levelBadge:SetFrameLevel(slot:GetFrameLevel() + 2)
slot.levelBadge:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
edgeSize = 1,
})
slot.levelBadge:SetBackdropColor(0.025, 0.03, 0.04, 0.96)
slot.levelBadge:SetBackdropBorderColor(1, 0.72, 0.18, 0.95)
slot.level = slot.levelBadge:CreateFontString(nil, "OVERLAY", "GameFontNormal")
slot.level:SetPoint("CENTER", 0, 0)
slot.level:SetTextColor(1, 0.84, 0.3)
slot.level:SetShadowOffset(1, -1)
slot.source = slot:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
slot.source:SetPoint("BOTTOMRIGHT", slot.icon, "BOTTOMRIGHT", -1, 1)
slot.source:SetTextColor(1, 0.9, 0.62)
slot.flash = slot:CreateTexture(nil, "OVERLAY")
slot.flash:SetAllPoints()
slot.flash:SetColorTexture(1, 0.78, 0.18, 0)
slot.ignoreOverlay = slot:CreateTexture(nil, "OVERLAY", nil, 5)
slot.ignoreOverlay:SetAllPoints()
slot.ignoreOverlay:SetColorTexture(0.12, 0.01, 0.015, 0.72)
slot.ignoreOverlay:Hide()
slot.ignoreText = slot:CreateFontString(nil, "OVERLAY", "GameFontNormal")
slot.ignoreText:SetDrawLayer("OVERLAY", 6)
slot.ignoreText:SetPoint("CENTER")
slot.ignoreText:SetText(L.IGNORED)
slot.ignoreText:SetTextColor(1, 0.34, 0.3)
slot.ignoreText:Hide()
slot:SetScript("OnEnter", function(self)
local entry = self.entry
if not entry then
return
end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
local classColor = entry.classFile and RAID_CLASS_COLORS[entry.classFile]
GameTooltip:AddLine(entry.displayName, classColor and classColor.r or 1, classColor and classColor.g or 0.9, classColor and classColor.b or 0.7)
GameTooltip:AddLine(("+%d %s"):format(entry.level, entry.dungeonName), 1, 1, 1)
GameTooltip:AddLine(L.SOURCE_LINE:format(Addon:GetSourceLabel(entry.source)), 0.65, 0.8, 1)
if entry.rating and entry.rating > 0 then
GameTooltip:AddLine(L.RATING_LINE:format(entry.rating), 0.76, 0.76, 0.76)
end
if Addon.db.noRepeat and entry.drawn and not entry.ignored then
GameTooltip:AddLine(L.ALREADY_DRAWN, 0.5, 0.72, 1)
end
GameTooltip:AddLine(
entry.ignored and L.ALLOW_KEY or L.IGNORE_KEY,
entry.ignored and 0.45 or 0.72,
entry.ignored and 1 or 0.72,
entry.ignored and 0.45 or 0.72
)
if entry.source == "chat" or entry.source == "manual" then
GameTooltip:AddLine(L.REMOVE_KEY, 0.55, 0.55, 0.55)
end
GameTooltip:Show()
end)
slot:SetScript("OnLeave", GameTooltip_Hide)
slot:SetScript("OnClick", function(self, button)
if button == "LeftButton" and self.entry then
Addon:ToggleKeyIgnored(self.entry)
elseif button == "RightButton" and self.entry then
Addon:RemoveFallback(self.entry.id, self.entry.source)
end
end)
slot:Hide()
return slot
end
function Addon:CreateCenterButton(parent)
local button = CreateFrame("Button", nil, parent)
button:SetSize(106, 106)
button:SetPoint("CENTER")
button:SetFrameLevel(parent:GetFrameLevel() + 5)
button.shadow = button:CreateTexture(nil, "BACKGROUND")
button.shadow:SetTexture("Interface\\Minimap\\UI-Minimap-Background")
button.shadow:SetSize(86, 86)
button.shadow:SetPoint("CENTER")
button.shadow:SetVertexColor(0.02, 0.025, 0.04, 0.98)
button.text = button:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
button.text:SetPoint("CENTER", 0, 2)
button.text:SetText(L.SPIN)
button.text:SetTextColor(1, 0.82, 0.3)
button.subtext = button:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
button.subtext:SetPoint("TOP", button.text, "BOTTOM", 0, -3)
button.subtext:SetText(L.CLICK)
button.subtext:SetTextColor(0.75, 0.75, 0.78)
button:SetScript("OnClick", function()
Addon:Spin()
end)
button:SetScript("OnEnter", function(self)
if self:IsEnabled() then
self.text:SetTextColor(1, 0.91, 0.42)
self.subtext:SetTextColor(0.9, 0.9, 0.94)
end
if self.permissionReason or self.interactionHint then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(self.permissionReason and L.PERMISSION_TITLE or L.SEALED_TITLE, 1, 0.82, 0.3)
GameTooltip:AddLine(self.permissionReason or self.interactionHint, 0.9, 0.9, 0.9, true)
GameTooltip:Show()
end
end)
button:SetScript("OnLeave", function(self)
self.text:SetTextColor(1, 0.82, 0.3)
self.subtext:SetTextColor(0.75, 0.75, 0.78)
GameTooltip_Hide()
end)
return button
end
function Addon:ApplyUIScale()
if not self.frame then
return
end
local scale = tonumber(self.db.uiScale) or 1
scale = math.max(0.75, math.min(scale, 1.15))
self.db.uiScale = scale
self.frame:SetScale(scale)
end
function Addon:CreateOptionsUI(parent)
local options = CreateFrame("Frame", "KeystoneWheelOptionsFrame", parent, "BasicFrameTemplateWithInset")
options:SetSize(380, 360)
options:SetPoint("CENTER", parent, "CENTER", 0, 0)
options:SetFrameLevel(parent:GetFrameLevel() + 30)
options:EnableMouse(true)
options:Hide()
if options.TitleText then
options.TitleText:SetText(L.OPTIONS_TITLE)
end
self.optionsFrame = options
local section = options:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
section:SetPoint("TOPLEFT", 22, -42)
section:SetText(L.GAME_RULES)
section:SetTextColor(0.58, 0.68, 0.82)
local function AddOption(text, y, key, tooltip)
local checkbox = CreateCheckbox(options, text)
checkbox:SetPoint("TOPLEFT", 20, y)
checkbox:SetChecked(Addon.db[key])
checkbox:SetScript("OnClick", function(self)
Addon.db[key] = self:GetChecked() and true or false
Addon:RefreshUI()
end)
SetTooltip(checkbox, text, tooltip)
return checkbox
end
self.noRepeatCheckbox = AddOption(
L.NO_REPEAT_OPTION,
-56,
"noRepeat",
L.NO_REPEAT_TOOLTIP
)
self.fateLockCheckbox = AddOption(
L.FATE_OPTION,
-88,
"fateLock",
L.FATE_TOOLTIP
)
self.leaderOnlyCheckbox = AddOption(
L.LEADER_OPTION,
-120,
"leaderOnly",
L.LEADER_TOOLTIP
)
self.reducedMotionCheckbox = AddOption(
L.REDUCED_MOTION_OPTION,
-152,
"reducedMotion",
L.REDUCED_MOTION_TOOLTIP
)
self.minimapCheckbox = AddOption(
L.MINIMAP_OPTION,
-184,
"showMinimap",
L.MINIMAP_TOOLTIP
)
self.minimapCheckbox:SetScript("OnClick", function(self)
Addon.db.showMinimap = self:GetChecked() and true or false
if Addon.minimapButton then
Addon.minimapButton:SetShown(Addon.db.showMinimap)
end
end)
local displaySection = options:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
displaySection:SetPoint("TOPLEFT", 22, -229)
displaySection:SetText(L.DISPLAY)
displaySection:SetTextColor(0.58, 0.68, 0.82)
local scaleValue = options:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
scaleValue:SetPoint("TOPRIGHT", -24, -229)
self.scaleValueText = scaleValue
local scaleSlider = CreateFrame("Slider", "KeystoneWheelScaleSlider", options, "OptionsSliderTemplate")
scaleSlider:SetPoint("TOPLEFT", 30, -252)
scaleSlider:SetPoint("TOPRIGHT", -30, -252)
scaleSlider:SetMinMaxValues(0.75, 1.15)
scaleSlider:SetValueStep(0.05)
if scaleSlider.SetObeyStepOnDrag then
scaleSlider:SetObeyStepOnDrag(true)
end
local sliderName = scaleSlider:GetName()
local low = scaleSlider.Low or _G[sliderName .. "Low"]
local high = scaleSlider.High or _G[sliderName .. "High"]
local text = scaleSlider.Text or _G[sliderName .. "Text"]
if low then
low:SetText("75%")
end
if high then
high:SetText("115%")
end
if text then
text:SetText(L.WINDOW_SCALE)
end
scaleSlider:SetScript("OnValueChanged", function(_, value)
value = math.floor((value * 20) + 0.5) / 20
Addon.db.uiScale = value
scaleValue:SetText(("%d%%"):format(math.floor((value * 100) + 0.5)))
Addon:ApplyUIScale()
end)
scaleSlider:SetValue(self.db.uiScale)
self.scaleSlider = scaleSlider
local clearHistory = CreateButton(options, L.RESET_HISTORY, 150)
clearHistory:SetPoint("BOTTOMLEFT", 22, 38)
clearHistory:SetScript("OnClick", function()
Addon:ClearResultHistory()
end)
SetTooltip(clearHistory, L.RESET_HISTORY, L.RESET_HISTORY_TOOLTIP)
local compartmentNote = options:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
compartmentNote:SetPoint("BOTTOMRIGHT", -22, 45)
compartmentNote:SetWidth(165)
compartmentNote:SetJustifyH("RIGHT")
compartmentNote:SetText(L.COMPARTMENT_NOTE)
end
function Addon:ToggleOptions()
if not self.optionsFrame then
return
end
local shouldShow = not self.optionsFrame:IsShown()
if shouldShow then
self.noRepeatCheckbox:SetChecked(self.db.noRepeat)
self.fateLockCheckbox:SetChecked(self.db.fateLock)
self.leaderOnlyCheckbox:SetChecked(self.db.leaderOnly)
self.reducedMotionCheckbox:SetChecked(self.db.reducedMotion)
self.minimapCheckbox:SetChecked(self.db.showMinimap)
self.scaleSlider:SetValue(self.db.uiScale)
end
self.optionsFrame:SetShown(shouldShow)
end
function Addon:CreateUI()
local frame = CreateFrame("Frame", "KeystoneWheelFrame", UIParent, "BasicFrameTemplateWithInset")
frame:SetSize(550, 640)
frame:SetFrameStrata("DIALOG")
frame:SetClampedToScreen(true)
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
local point, _, relativePoint, x, y = self:GetPoint(1)
Addon.db.position = { point = point, relativePoint = relativePoint, x = x, y = y }
end)
frame:SetScript("OnShow", function()
Addon:RefreshUI()
Addon:RequestAll(false)
end)
frame:SetScript("OnUpdate", function(_, elapsed)
Addon:OnUIUpdate(elapsed)
end)
frame:Hide()
self.frame = frame
UISpecialFrames[#UISpecialFrames + 1] = frame:GetName()
if self.db.position then
local position = self.db.position
frame:SetPoint(position.point or "CENTER", UIParent, position.relativePoint or "CENTER", position.x or 0, position.y or 0)
else
frame:SetPoint("CENTER")
end
self:ApplyUIScale()
if frame.TitleText then
frame.TitleText:SetText("KeystoneWheel")
end
local optionsButton = CreateFrame("Button", nil, frame)
optionsButton:SetSize(19, 19)
optionsButton:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -31, -3)
optionsButton:RegisterForClicks("LeftButtonUp")
local optionsIcon = optionsButton:CreateTexture(nil, "ARTWORK")
optionsIcon:SetPoint("CENTER")
optionsIcon:SetSize(17, 17)
optionsIcon:SetTexture("Interface\\Buttons\\UI-OptionsButton")
optionsButton.icon = optionsIcon
local optionsHighlight = optionsButton:CreateTexture(nil, "HIGHLIGHT")
optionsHighlight:SetAllPoints(optionsIcon)
optionsHighlight:SetTexture("Interface\\Buttons\\UI-OptionsButton")
optionsHighlight:SetBlendMode("ADD")
optionsHighlight:SetAlpha(0.45)
optionsButton:SetScript("OnMouseDown", function(self)
self.icon:ClearAllPoints()
self.icon:SetPoint("CENTER", 1, -1)
end)
optionsButton:SetScript("OnMouseUp", function(self)
self.icon:ClearAllPoints()
self.icon:SetPoint("CENTER")
end)
optionsButton:SetScript("OnClick", function()
Addon:ToggleOptions()
end)
SetTooltip(optionsButton, L.OPTIONS, L.OPTIONS_TOOLTIP)
self.optionsButton = optionsButton
local flavor = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
flavor:SetPoint("TOP", 0, -34)
flavor:SetText(L.FLAVOR)
flavor:SetTextColor(0.75, 0.76, 0.82)
local refreshButton = CreateButton(frame, L.REFRESH, 112)
refreshButton:SetPoint("TOPLEFT", 22, -53)
refreshButton:SetScript("OnClick", function()
Addon:RequestAll(true)
end)
SetTooltip(refreshButton, L.REFRESH, L.REFRESH_TOOLTIP)
local askButton = CreateButton(frame, L.ASK_CHAT, 122)
askButton:SetPoint("LEFT", refreshButton, "RIGHT", 7, 0)
askButton:SetScript("OnClick", function()
Addon:AskForLinks()
end)
SetTooltip(askButton, L.CHAT_FALLBACK, L.CHAT_FALLBACK_TOOLTIP)
local announceCheckbox = CreateCheckbox(frame, L.ANNOUNCE_RESULT)
announceCheckbox:SetPoint("TOPLEFT", 286, -51)
announceCheckbox:SetChecked(self.db.announce)
announceCheckbox:SetScript("OnClick", function(self)
Addon.db.announce = self:GetChecked() and true or false
end)
self.announceCheckbox = announceCheckbox
local soundCheckbox = CreateCheckbox(frame, L.SOUND)
soundCheckbox:SetPoint("TOPLEFT", 438, -51)
soundCheckbox:SetChecked(self.db.sound)
soundCheckbox:SetScript("OnClick", function(self)
Addon.db.sound = self:GetChecked() and true or false
end)
self.soundCheckbox = soundCheckbox
local status = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
status:SetPoint("TOP", 0, -90)
status:SetWidth(500)
status:SetJustifyH("CENTER")
self.statusText = status
local statusHitbox = CreateFrame("Button", nil, frame)
statusHitbox:SetSize(500, 18)
statusHitbox:SetPoint("CENTER", status, "CENTER")
statusHitbox:SetScript("OnClick", function()
Addon:RequestWheelStates()
end)
statusHitbox:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:AddLine(L.SYNC_TITLE, 1, 0.82, 0.3)
local details, ownCount = Addon:GetSyncDetails()
GameTooltip:AddLine(L.YOU_HAVE_KEYS:format(ownCount), 0.35, 1, 0.55)
if #details == 0 then
GameTooltip:AddLine(L.NO_SYNC_PEER, 0.72, 0.72, 0.76, true)
else
for _, detail in ipairs(details) do
local metadata = {}
if detail.version then
metadata[#metadata + 1] = "v" .. detail.version
end
if detail.transport then
metadata[#metadata + 1] = detail.transport
end
local suffix = #metadata > 0 and (" (" .. table.concat(metadata, ", ") .. ")") or ""
GameTooltip:AddLine(
detail.hasState
and L.PEER_HAS_KEYS:format(detail.name, detail.count, suffix)
or L.PEER_WAITING_STATE:format(detail.name, suffix),
detail.matches and 0.35 or 1,
detail.matches and 1 or 0.42,
detail.matches and 0.55 or 0.3
)
end
end
GameTooltip:AddLine(L.REFRESH_SYNC, 0.58, 0.68, 0.82)
GameTooltip:Show()
end)
statusHitbox:SetScript("OnLeave", GameTooltip_Hide)
self.statusHitbox = statusHitbox
local wheel = CreateFrame("Frame", nil, frame)
wheel:SetSize(510, 350)
wheel:SetPoint("TOP", 0, -112)
wheel:SetFrameLevel(frame:GetFrameLevel() + 1)
self.wheel = wheel
local wheelHub = CreateFrame("Frame", nil, wheel)
wheelHub:SetSize(338, 338)
wheelHub:SetPoint("CENTER")
wheelHub:SetFrameLevel(wheel:GetFrameLevel() + 1)
self.wheelHub = wheelHub
local wheelBackground = wheelHub:CreateTexture(nil, "BACKGROUND")
wheelBackground:SetTexture(WHEEL_TEXTURE)
wheelBackground:SetAllPoints()
self.wheelBackground = wheelBackground
local pointer = wheelHub:CreateFontString(nil, "OVERLAY", "GameFontNormalHuge")
pointer:SetPoint("TOP", wheelHub, "TOP", 0, 10)
pointer:SetText("V")
pointer:SetTextColor(1, 0.76, 0.18)
pointer:SetShadowOffset(2, -2)
self.pointer = pointer
self.slots = {}
for index = 1, MAX_SLOTS do
self.slots[index] = self:CreateSlot(wheel, index)
end
self.centerButton = self:CreateCenterButton(wheelHub)
local resultFrame = CreateFrame("Frame", nil, frame, "BackdropTemplate")
resultFrame:SetSize(506, 50)
resultFrame:SetPoint("TOP", 0, -468)
resultFrame:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
edgeSize = 1,
})
resultFrame:SetBackdropColor(0.045, 0.05, 0.07, 0.96)
resultFrame:SetBackdropBorderColor(0.28, 0.35, 0.48, 0.8)
self.resultFrame = resultFrame
local portButton = CreateFrame(
"Button",
"KeystoneWheelPortButton",
resultFrame,
"InsecureActionButtonTemplate,BackdropTemplate"
)
portButton:SetSize(84, 32)
portButton:SetPoint("RIGHT", -9, 0)
portButton:RegisterForClicks("AnyDown", "AnyUp")
portButton:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
edgeSize = 1,
})
portButton:SetBackdropColor(0.10, 0.13, 0.17, 0.98)
portButton:SetBackdropBorderColor(0.42, 0.66, 0.92, 0.9)
local portIcon = portButton:CreateTexture(nil, "ARTWORK")
portIcon:SetSize(22, 22)
portIcon:SetPoint("LEFT", 5, 0)
portIcon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
portButton.icon = portIcon
local portCooldown = CreateFrame("Cooldown", nil, portButton, "CooldownFrameTemplate")
portCooldown:SetAllPoints(portIcon)
portCooldown:SetDrawEdge(false)
portButton.cooldown = portCooldown
self.portCooldown = portCooldown
local portText = portButton:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
portText:SetPoint("LEFT", portIcon, "RIGHT", 5, 0)
portText:SetPoint("RIGHT", -5, 0)
portText:SetJustifyH("CENTER")
portText:SetText(L.PORT)
portButton.text = portText
portButton:SetScript("OnEnter", function(self)
Addon:ShowPortTooltip(self)
if self:IsEnabled() then
self:SetBackdropBorderColor(1, 0.76, 0.22, 1)
end
end)
portButton:SetScript("OnLeave", function(self)
GameTooltip_Hide()
self:SetBackdropBorderColor(0.42, 0.66, 0.92, 0.9)
end)
portButton:Hide()
self.portButton = portButton
local resultTitle = resultFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
resultTitle:SetPoint("TOPLEFT", 8, RESULT_TITLE_Y_OFFSET)
resultTitle:SetPoint("TOPRIGHT", resultFrame, "TOPRIGHT", -8, RESULT_TITLE_Y_OFFSET)
resultTitle:SetJustifyH("CENTER")
resultTitle:SetText(L.READY_TITLE)
resultTitle:SetTextColor(0.58, 0.68, 0.82)
self.resultTitle = resultTitle
local resultText = resultFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
resultText:SetPoint("TOPLEFT", resultTitle, "BOTTOMLEFT", 0, -3)
resultText:SetPoint("TOPRIGHT", resultTitle, "BOTTOMRIGHT", 0, -3)
resultText:SetJustifyH("CENTER")
resultText:SetText(L.READY_BODY)
self.resultText = resultText
local historyBar = CreateFrame("Button", nil, frame)
historyBar:SetSize(506, 12)
historyBar:SetPoint("TOP", resultFrame, "BOTTOM", 0, -2)
local historyText = historyBar:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
historyText:SetPoint("LEFT", 4, 0)
historyText:SetPoint("RIGHT", -20, 0)
historyText:SetJustifyH("CENTER")
historyText:SetWordWrap(false)
if historyText.SetMaxLines then
historyText:SetMaxLines(1)
end
historyBar.text = historyText
self.historyBar = historyBar
self.historyText = historyText
local historyClear = CreateFrame("Button", nil, historyBar, "UIPanelCloseButton")
historyClear:SetSize(17, 17)
historyClear:SetPoint("RIGHT", 0, 0)
historyClear:SetScript("OnClick", function()
Addon:ClearResultHistory()
end)
SetTooltip(historyClear, L.CLEAR_HISTORY, L.RESET_HISTORY_TOOLTIP)
historyBar.clearButton = historyClear
historyBar:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:AddLine(L.LAST_DRAWS, 1, 0.82, 0.3)
if #Addon.db.history == 0 then
GameTooltip:AddLine(L.NO_HISTORY, 0.72, 0.72, 0.76)
else
for index, entry in ipairs(Addon.db.history) do
GameTooltip:AddLine(L.HISTORY_TOOLTIP_LINE:format(
index,
entry.level or 0,
entry.dungeonName or ("Dungeon " .. tostring(entry.mapID or "?")),
entry.displayName or "?"
), 0.86, 0.86, 0.9)
end
end
GameTooltip:Show()
end)
historyBar:SetScript("OnLeave", GameTooltip_Hide)
local manualLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
manualLabel:SetPoint("TOPLEFT", 22, -535)
manualLabel:SetText(L.MANUAL_FALLBACK)
manualLabel:SetTextColor(0.58, 0.68, 0.82)
local nameEdit = CreateFrame("EditBox", nil, frame, "InputBoxTemplate")
nameEdit:SetSize(105, 25)
nameEdit:SetPoint("TOPLEFT", 22, -554)
nameEdit:SetAutoFocus(false)
nameEdit:SetMaxLetters(48)
self.nameEdit = nameEdit
local namePlaceholder = frame:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
namePlaceholder:SetPoint("LEFT", nameEdit, "LEFT", 7, 0)
namePlaceholder:SetText(L.PLAYER)
local linkEdit = CreateFrame("EditBox", nil, frame, "InputBoxTemplate")
linkEdit:SetSize(282, 25)
linkEdit:SetPoint("LEFT", nameEdit, "RIGHT", 8, 0)
linkEdit:SetAutoFocus(false)
self.linkEdit = linkEdit
local linkPlaceholder = frame:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
linkPlaceholder:SetPoint("LEFT", linkEdit, "LEFT", 7, 0)
linkPlaceholder:SetText(L.KEYSTONE_PLACEHOLDER)
local function UpdatePlaceholder(editBox, placeholder)
placeholder:SetShown(editBox:GetText() == "" and not editBox:HasFocus())
end
nameEdit:SetScript("OnTextChanged", function(self)
UpdatePlaceholder(self, namePlaceholder)
end)
nameEdit:SetScript("OnEditFocusGained", function()
namePlaceholder:Hide()
end)
nameEdit:SetScript("OnEditFocusLost", function(self)
UpdatePlaceholder(self, namePlaceholder)
end)
linkEdit:SetScript("OnTextChanged", function(self)
UpdatePlaceholder(self, linkPlaceholder)
end)
linkEdit:SetScript("OnEditFocusGained", function()
linkPlaceholder:Hide()
end)
linkEdit:SetScript("OnEditFocusLost", function(self)
UpdatePlaceholder(self, linkPlaceholder)
end)
local addButton = CreateButton(frame, L.ADD, 92)
addButton:SetPoint("LEFT", linkEdit, "RIGHT", 8, 0)
addButton:SetScript("OnClick", function()
local ok, errorMessage = Addon:AddManualKey(nameEdit:GetText(), linkEdit:GetText())
if ok then
linkEdit:SetText("")
Addon:Print(L.KEY_ADDED)
else
Addon:Print(errorMessage)
end
end)
linkEdit:SetScript("OnEnterPressed", function(self)
addButton:Click()
self:ClearFocus()
end)
nameEdit:SetScript("OnEscapePressed", nameEdit.ClearFocus)
linkEdit:SetScript("OnEscapePressed", linkEdit.ClearFocus)
if ChatEdit_InsertLink then
hooksecurefunc("ChatEdit_InsertLink", function(link)
if linkEdit:IsVisible() and linkEdit:HasFocus()
and (not issecretvalue or not issecretvalue(link)) and type(link) == "string" then
linkEdit:Insert(link)
end
end)
end
local footer = frame:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
footer:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT", 22, 19)
footer:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -22, 19)
footer:SetJustifyH("CENTER")
footer:SetText(L.FOOTER)
self.confetti = {}
for index = 1, 28 do
local particle = {
texture = frame:CreateTexture(nil, "OVERLAY", nil, 7),