Repository navigation
Expand file tree
/
Copy pathConsumableWheel.lua
More file actions
2361 lines (2245 loc) · 100 KB
/
Copy pathConsumableWheel.lua
File metadata and controls
2361 lines (2245 loc) · 100 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 _, CK = ...
local L = CK.L
-- Module "consumables wheel": a key of its own (Gamepad tab, or the game's key
-- bindings) opens a wheel of consumables from the bags, drawn in the style of
-- the game's own radial menu (Claude Design): as many sections as the page
-- holds items (2 items: two halves, 5: five sections), up to 8 a page, LB /
-- RB turn the pages (up to 3). Food, drink,
-- health and mana potions, healthstone, mana gem, bandages, buff food,
-- elixirs and flasks, scrolls. Its key opens it, the left stick chooses (the
-- choice stays when it goes back to the middle; the right stick is the
-- game's, for its own wheels), A uses, B cancels; the D-pad and the
-- mouse work too. While it is open it takes the sticks, like the game's own
-- wheels: the camera and the character stay still. In the middle of the
-- screen (or placed with the mouse or the D-pad).
--
-- Secure code only acts on keys: A reads the left stick from the game's
-- gamepad state. The choice stays when the stick goes back to the middle:
-- noted by our drawing code out of combat, and in combat by the left
-- stick's direction keys, which the game sends while the wheel is open
-- (its GamePadStickAxisButtons setting, on only then).
--
-- It works in combat: the wheel, its slots and the keys it takes while open
-- are secure frames and snippets run by the game (its restricted
-- environment), so a press does what a click of the player's would. The
-- items in the slots can only change out of combat (a rule of the game): the
-- wheel is filled from the bags then. The pictures (icons, counts, cooldowns,
-- the selection ring) are ours, drawn over it.
--
-- The same wheel also shows the player's own wheels (MyWheels.lua): each has
-- a key of its own, 8 slots on one page, spells, items or macros. The open
-- wheel is the "wheel" attribute: "c" (consumables) or "1" to "8".
--
-- And the party spells' wheels ("p" and the spell's ID): a spell put on a
-- key from the Gamepad tab's Party list opens a small wheel like the game's
-- flyouts (hunter aspects), centred on the button that holds the spell (the
-- spell drawn in its middle): the party's members around it, each always in
-- the same place (you at the bottom, member 1 on the left, then clockwise),
-- only those who are there, their portraits and names. Aimed with the right
-- stick (like the game's flyouts), at the nearest member there; the key
-- held, aimed, let go casts the spell on that member, the target kept (the
-- slot's button has its unit); a short press leaves it open: aim, then A.
-- Drawn by its own frame (`pview`): the big wheel's drawing stays as it is.
local W = {}
CK.ConsumableWheel = W
local SEGMENTS, PAGES = 8, 3
W.MY_MAX = 8
local MAX = SEGMENTS * PAGES
local AIM = 0.5 -- the stick aims past half its course
-- The wheel's art (Claude Design, design/radial/wheel/geometry.json): 512 x
-- 512, its crown from 75 to 213 from the middle. Like the game's radial
-- menu: the icons a little inside the crown's middle, each name beside its
-- icon on the outer side (GameFontNormal, 80 x 40)
local WHEEL_SIZE, ICON_RADIUS, SLOT = 512, 128, 46
local LABEL_W, LABEL_H, LABEL_GAP = 80, 40, 60
-- The section overlays (highlight, veil) cut to their section: { width,
-- height, x, y } with x, y their centre from the wheel's (y up), for section
-- 1 (tools/wheel_textures.py)
local OVERLAY = {
[1] = { 512, 512, 0, 0 },
[2] = { 512, 256, 0, 110 },
[3] = { 512, 256, 0, 130 },
[4] = { 512, 256, 0, 137 },
[5] = { 256, 256, 0, 140 },
[6] = { 256, 256, 0, 142 },
[7] = { 256, 256, 0, 142 },
[8] = { 256, 256, 0, 143 },
}
-- The banner under the wheel, sized for its two lines
local BANNER_W, BANNER_H = 360, 64
-- A party spell's wheel: its members' places (you, then party1 to party4),
-- their direction from the middle: you at the bottom, then clockwise every
-- fifth of a turn (member 1 on the left)
local PARTY_UNITS = { "player", "party1", "party2", "party3", "party4" }
local PARTY_RADIUS, PARTY_SLOT, PARTY_CENTER, PARTY_BASE = 62, 38, 44, 196
-- Each member's health as a ring around their portrait (asked): its size,
-- its arcs (one a 40th of the health), how far it reaches past the portrait
local HP_RING, HP_ARCS = 50, 40
local HP_RING_OUT = (HP_RING - PARTY_SLOT) / 2
local PARTY_DIRS = {}
for i = 1, #PARTY_UNITS do
local a = math.pi + (i - 1) * 2 * math.pi / #PARTY_UNITS
PARTY_DIRS[i] = { math.sin(a), math.cos(a) }
end
W.PARTY_DIRS = PARTY_DIRS
local function isParty(wid) return type(wid) == "string" and wid:sub(1, 1) == "p" end
W.isParty = isParty
-- The right stick's direction keys (sent with the game's
-- GamePadStickAxisButtons setting): letting the stick go casts
local PARTY_STICK_KEYS = "PADRSTICKUP,PADRSTICKDOWN,PADRSTICKLEFT,PADRSTICKRIGHT,"
local STICK_DIR_KEYS = {}
for _, side in ipairs({ "L", "R" }) do
for _, dir in ipairs({ "UP", "DOWN", "LEFT", "RIGHT" }) do STICK_DIR_KEYS["PAD" .. side .. "STICK" .. dir] = true end
end
local TEX = "Interface\\AddOns\\EasyController\\textures\\"
-- Slot `i` of a page of `n`: clockwise from the top, its angle (radians,
-- clockwise from 12 o'clock) and its direction (x right, y up)
local function slotAngle(i, n) return (i - 1) * 2 * math.pi / n end
local function slotDir(i, n)
local a = slotAngle(i, n)
return math.sin(a), math.cos(a)
end
W.slotDir = slotDir
-- The wheel's kinds, in its order
W.CATEGORIES = { "food", "drink", "healthPotion", "manaPotion", "healthstone", "manaGem", "bandage",
"buffFood", "elixir", "scroll" }
local CATEGORY_INDEX = {}
for i, c in ipairs(W.CATEGORIES) do CATEGORY_INDEX[c] = i end
-- Not usable in combat (the game's rule): greyed there
local OUT_OF_COMBAT = { food = true, drink = true, buffFood = true }
local HEALTHSTONES = {}
for _, id in ipairs({ 5512, 19004, 19005, 5511, 19006, 19007, 5509, 19008, 19009, 5510, 19010, 19011, 9421, 19012, 19013 }) do
HEALTHSTONES[id] = true
end
local MANA_GEMS = { [5514] = true, [5513] = true, [8007] = true, [8008] = true }
-- The game's own spells, by ID: their names are in the client's language
local SPELL_FOOD, SPELL_DRINK, SPELL_WELL_FED, SPELL_FIRST_AID = 433, 430, 19705, 746
local function settings() return CK.db.settings.wheel end
---------------------------------------------------------------------------
-- What goes in the wheel
---------------------------------------------------------------------------
local spellNames
local function names()
if not spellNames then
local get = C_Spell and C_Spell.GetSpellName or function(id) return (GetSpellInfo(id)) end
spellNames = { food = get(SPELL_FOOD), drink = get(SPELL_DRINK), wellFed = get(SPELL_WELL_FED),
firstAid = get(SPELL_FIRST_AID) }
end
return spellNames
end
local function secret(v) return issecretvalue ~= nil and issecretvalue(v) or false end
local function tooltipText(id)
if not (C_TooltipInfo and C_TooltipInfo.GetItemByID) then return "" end
local ok, data = pcall(C_TooltipInfo.GetItemByID, id)
local parts = {}
if ok and type(data) == "table" and data.lines then
for _, line in ipairs(data.lines) do
local text = line.leftText
if type(text) == "string" and not secret(text) then parts[#parts + 1] = text end
end
end
return table.concat(parts, "\n"):lower()
end
-- The kind of an item, or nil (not for the wheel)
function W.Category(id)
if HEALTHSTONES[id] then return "healthstone" end
if MANA_GEMS[id] then return "manaGem" end
local _, _, _, _, _, classID, subClassID = C_Item.GetItemInfoInstant(id)
local spell = C_Item.GetItemSpell and C_Item.GetItemSpell(id)
local n = names()
-- Bandages: by their First Aid spell, whatever class the client gives them
if (spell and spell == n.firstAid) or (classID == 0 and subClassID == 7) then return "bandage" end
-- Raw fish and the like: trade goods the game lets you eat or drink
if classID ~= 0 and spell and (spell == n.food or spell == n.drink) then
return spell == n.drink and "drink" or "food"
end
if classID ~= 0 then return nil end
if not spell then return nil end
if subClassID == 4 then return "scroll" end
if subClassID == 2 or subClassID == 3 then return "elixir" end
if subClassID == 5 or spell == n.food or spell == n.drink then
if spell == n.drink then return "drink" end
local text = tooltipText(id)
if n.wellFed and text:find(n.wellFed:lower(), 1, true) then return "buffFood" end
return "food"
end
local text = tooltipText(id)
if text:find((MANA or "mana"):lower(), 1, true) then return "manaPotion" end
if text:find((HEALTH or "health"):lower(), 1, true) then return "healthPotion" end
if subClassID == 1 or subClassID == 13 then return "elixir" end
end
-- Why an item of the bags is not in the wheel (for /ec wheel), or nil
function W.Reason(id)
local cat = W.Category(id)
if not cat then
local _, _, _, _, _, classID, subClassID = C_Item.GetItemInfoInstant(id)
local spell = C_Item.GetItemSpell and C_Item.GetItemSpell(id)
return format("- (class %s/%s, use: %s)", tostring(classID), tostring(subClassID), tostring(spell))
end
if not settings().categories[cat] then return cat .. ": " .. L.WHEEL_DIAG_OFF end
local get = C_Item.GetItemInfo or GetItemInfo
local _, _, _, _, minLevel = get(id)
if minLevel and minLevel > (UnitLevel("player") or 0) then return cat .. ": " .. format(L.WHEEL_DIAG_LEVEL, minLevel) end
return nil, cat
end
---------------------------------------------------------------------------
-- The usable items' wheel (asked, "u"): every item of the bags that can be
-- used, the consumables aside (their own wheel): a sleeping bag, a battle
-- standard, a quest item to use somewhere, a quest's first page... Items
-- one wears (using them from the bags would put them on) left out. Quest
-- items first, then by name; one of each. The player hides some (Wheels >
-- Usable items; the hearthstone by default)
---------------------------------------------------------------------------
local QUEST_CLASS = Enum and Enum.ItemClass and Enum.ItemClass.Questitem or 12
local function questInfo(bag, slot)
local get = C_Container and C_Container.GetContainerItemQuestInfo
local ok, info = pcall(function() return get and get(bag, slot) end)
return ok and type(info) == "table" and info or nil
end
-- An item of the bags this wheel takes, and whether it is a quest's
function W.UsableItem(id, bag, slot)
local _, _, _, _, _, classID = C_Item.GetItemInfoInstant(id)
local equip = C_Item.IsEquippableItem or IsEquippableItem
if equip and equip(id) then return false end
local info = bag and questInfo(bag, slot)
local quest = classID == QUEST_CLASS or (info and (info.isQuestItem or info.questID ~= nil)) or false
local spell = C_Item.GetItemSpell and C_Item.GetItemSpell(id)
-- A quest's first page: used, it opens the quest
local starter = info and info.questID ~= nil and not info.isActive
if not (spell or starter) then return false end
if W.Category(id) then return false end
return true, quest and true or false
end
local function itemName(id)
local name = C_Item.GetItemNameByID and C_Item.GetItemNameByID(id)
if not name then
local get = C_Item.GetItemInfo or GetItemInfo
name = get and get(id)
end
return name
end
-- Every one in the bags, hidden ones too ({ id, quest, name, hidden })
function W:UsableCandidates()
local hidden = settings().usableHidden or {}
local list, seen = {}, {}
for bag = 0, NUM_BAG_SLOTS or 4 do
for slot = 1, C_Container.GetContainerNumSlots(bag) or 0 do
local id = C_Container.GetContainerItemID(bag, slot)
if id and not seen[id] then
seen[id] = true
local ok, usable, quest = pcall(W.UsableItem, id, bag, slot)
if ok and usable then
list[#list + 1] = { id = id, quest = quest, name = itemName(id), hidden = hidden[id] == true }
end
end
end
end
-- (names compared without case or accents: É with the E)
local key = CK.Normalize or string.lower
for _, c in ipairs(list) do c.key = key(c.name or "") end
table.sort(list, function(a, b)
if a.quest ~= b.quest then return a.quest end
if a.key ~= b.key then return a.key < b.key end
return a.id < b.id
end)
return list
end
-- What the wheel shows: those not hidden, as entries
function W:ScanUsable()
local items = {}
-- (turned off: Wheels > Usable items, or the guide)
if settings().usableEnabled == false then return items end
for _, c in ipairs(self:UsableCandidates()) do
if not c.hidden and #items < MAX then
items[#items + 1] = { kind = "item", id = c.id, cat = c.quest and "quest" or "usable" }
end
end
return items
end
-- Shown or hidden in it (out of combat: the wheel is filled again)
function W:SetUsableHidden(id, hide)
local s = settings()
s.usableHidden = s.usableHidden or {}
-- (false, not nil: the hearthstone's default would come back)
s.usableHidden[id] = hide and true or false
self:Fill()
end
---------------------------------------------------------------------------
-- The sticks while the wheel is open, and just after
---------------------------------------------------------------------------
function W:TakeSticks(frame, on)
if frame.EnableGamePadStick then pcall(frame.EnableGamePadStick, frame, on) end
end
-- The stick that aims the wheels (Wheels > Opening, asked): the left one by
-- default, the right one if chosen; a party spell's wheel always the right
-- one ("ck-pstick", its own)
function W.AimRight()
return CK.db ~= nil and settings().aimStick == "right"
end
-- Its name in the texts ("left stick"...)
function W.StickWords()
return W.AimRight() and L.WHEEL_STICK_RIGHT or L.WHEEL_STICK_LEFT
end
-- The stick that aims the open wheel: the one chosen, the right one for a
-- party spell's
local function aimStick(wheel)
if not wheel then return 1 end
return wheel:GetAttribute(isParty(wheel:GetAttribute("wheel")) and "ck-pstick" or "ck-stick") or 1
end
-- How far the stick that aims the wheel is pushed now (0 to 1)
local function aimLength()
local state = C_GamePad and C_GamePad.GetDeviceMappedState and C_GamePad.GetDeviceMappedState()
local stick = state and state.sticks and state.sticks[aimStick(W.frame)]
return stick and stick.len or 0
end
-- After the wheel closes with its stick still pushed, the sticks are kept a
-- moment, so the character doesn't walk off (or stand up from eating): until
-- that stick is let go, at most HOLD_MAX. Players lost the character and the
-- camera for seconds when they kept pushing (to walk on) or another stick or
-- axis of their pad never read as let go: only the aiming stick counts now,
-- and only for a moment.
local HOLD_MAX = 0.4
function W:BuildHold()
local hold = CK.NewFrame("Frame", nil, UIParent)
hold:SetAllPoints(UIParent)
hold:Hide()
hold.elapsed = 0
hold:SetScript("OnGamePadStick", function() end)
hold:SetScript("OnShow", function(self)
self.elapsed = 0
W:TakeSticks(self, true)
end)
hold:SetScript("OnHide", function(self) W:TakeSticks(self, false) end)
hold:SetScript("OnUpdate", function(self, elapsed)
self.elapsed = self.elapsed + elapsed
if self.elapsed > HOLD_MAX or aimLength() < 0.2 then self:Hide() end
end)
self.hold = hold
end
function W:HoldSticks()
if aimLength() >= 0.2 then self.hold:Show() end
end
-- What happened on the last openings and presses, for /ec wheel
local log = {}
function W:Log(what)
local view, wheel = self.view, self.frame
local state = C_GamePad and C_GamePad.GetDeviceMappedState and C_GamePad.GetDeviceMappedState()
local stick = state and state.sticks and state.sticks[aimStick(wheel)]
local taken = view and view.IsGamePadStickEnabled and view:IsGamePadStickEnabled()
local get = C_CVar and C_CVar.GetCVar or GetCVar
local ok, keys = pcall(get, "GamePadStickAxisButtons")
log[#log + 1] = format("%s (%.2f): %s, combat %s, sticks taken %s, stick %.2f, A = %s, aimed %s, stick keys %s",
date("%H:%M:%S"), GetTime(), what, tostring(InCombatLockdown()), tostring(taken), stick and stick.len or 0,
tostring(GetBindingAction("PAD1", true)), tostring(self.aimed), ok and tostring(keys) or "?")
while #log > 16 do table.remove(log, 1) end
end
-- /ec wheel: what is in it, what is not and why
function W:Diagnose()
local wheel = self.frame
CK:Print(L.WHEEL_DIAG, wheel and wheel:GetAttribute("ck-c-total") or 0, wheel and wheel:GetAttribute("ck-c-pages") or 0,
tostring(settings().enabled), tostring(InCombatLockdown()), tostring(self.pending or false))
local hiddenCount = 0
for _, c in ipairs(self:UsableCandidates()) do if c.hidden then hiddenCount = hiddenCount + 1 end end
CK:Print(L.USABLE_DIAG, wheel and wheel:GetAttribute("ck-u-total") or 0, hiddenCount)
local seen = {}
for bag = 0, NUM_BAG_SLOTS or 4 do
for slot = 1, C_Container.GetContainerNumSlots(bag) or 0 do
local id = C_Container.GetContainerItemID(bag, slot)
if id and not seen[id] then
seen[id] = true
local why, cat = W.Reason(id)
local name = C_Item.GetItemNameByID(id) or ("item:" .. id)
if cat then
DEFAULT_CHAT_FRAME:AddMessage(format(" |cff40ff40+|r %s: %s", name, L["WHEEL_CAT_" .. cat:upper()]))
elseif not why:find("^%- %(class 7") and not why:find("^%- %(class [1-9]%d*/") then
DEFAULT_CHAT_FRAME:AddMessage(format(" |cff9d9a8c-|r %s %s", name, why))
end
end
end
end
for _, line in ipairs(log) do DEFAULT_CHAT_FRAME:AddMessage(" |cff9d9a8c" .. line .. "|r") end
end
-- The best first: required level, then item level
-- The best first: required level, then item level. Nil for an item above
-- the player's level (the game won't let it be used)
local function rank(id)
local get = C_Item.GetItemInfo or GetItemInfo
local _, _, _, itemLevel, minLevel = get(id)
if minLevel and minLevel > (UnitLevel("player") or 0) then return nil end
return (minLevel or 0) * 1000 + (itemLevel or 0)
end
-- { id, cat }: the best of each kind, then the other variants (an option),
-- at most 12, each next to its kind
function W:Scan()
local s = settings()
local byKind, seen = {}, {}
for bag = 0, NUM_BAG_SLOTS or 4 do
for slot = 1, C_Container.GetContainerNumSlots(bag) or 0 do
local id = C_Container.GetContainerItemID(bag, slot)
if id and not seen[id] then
seen[id] = true
local cat = W.Category(id)
local value = cat and s.categories[cat] and rank(id)
if value then
byKind[cat] = byKind[cat] or {}
table.insert(byKind[cat], { id = id, cat = cat, rank = value })
end
end
end
end
local items = {}
for _, cat in ipairs(W.CATEGORIES) do
local list = byKind[cat]
if list then
table.sort(list, function(a, b) return a.rank > b.rank end)
if #items < MAX then items[#items + 1] = list[1] end
end
end
if s.variants then
for _, cat in ipairs(W.CATEGORIES) do
for i = 2, #(byKind[cat] or {}) do
if #items < MAX then items[#items + 1] = byKind[cat][i] end
end
end
end
table.sort(items, function(a, b)
if a.cat ~= b.cat then return CATEGORY_INDEX[a.cat] < CATEGORY_INDEX[b.cat] end
return a.rank > b.rank
end)
return items
end
---------------------------------------------------------------------------
-- The secure part. The wheel frame owns the keys it takes while open (A,
-- B, LB / RB, with every modifier a trigger may add); its snippets read the
-- left stick from the game's gamepad state when A is pressed. Each slot
-- direction is a unit vector ("ck-x3", "ck-y3"): the aimed slot is the
-- closest one. Nothing is remembered: the stick back in the middle aims at
-- nothing.
---------------------------------------------------------------------------
local PREFIXES = ",SHIFT-,CTRL-,ALT-,CTRL-SHIFT-,ALT-SHIFT-,ALT-CTRL-,ALT-CTRL-SHIFT-,"
-- A page of the open wheel into the 8 slots' buttons, from the wheel's
-- attributes: "ck-c-2-5" is the consumables wheel ("c"; the player's: "1"
-- to "8"), page 2, slot 5; "-t" its kind (item, spell, macro), "-u" its unit
-- "-n": how many the page holds; the slots' buttons go around the wheel in
-- as many sections ("ck-x5-2": slot 2 of 5's direction). A party spell's
-- wheel: each member's own place ("ck-pdx-2"), nearer the middle; a member
-- who isn't there gets no button
local APPLY_PAGE = [[
local wid = owner:GetAttribute("wheel") or "c"
local party = strsub(wid, 1, 1) == "p"
local key = "ck-" .. wid .. "-" .. (owner:GetAttribute("page") or 1) .. "-"
local n = owner:GetAttribute(key .. "n") or 0
local radius = owner:GetAttribute(party and "ck-pradius" or "ck-radius")
for i = 1, 8 do
local b = owner:GetFrameRef("slot" .. i)
local kind, value = owner:GetAttribute(key .. i .. "-t"), owner:GetAttribute(key .. i)
local unit = owner:GetAttribute(key .. i .. "-u")
b:SetAttribute("type", kind)
b:SetAttribute("item", kind == "item" and value or nil)
b:SetAttribute("spell", kind == "spell" and value or nil)
b:SetAttribute("macro", kind == "macro" and value or nil)
b:SetAttribute("unit", unit)
if kind and i <= n and (not party or UnitExists(unit)) then
local x = owner:GetAttribute(party and ("ck-pdx-" .. i) or ("ck-x" .. n .. "-" .. i))
local y = owner:GetAttribute(party and ("ck-pdy-" .. i) or ("ck-y" .. n .. "-" .. i))
b:ClearAllPoints()
b:SetPoint("CENTER", owner, "CENTER", radius * x, radius * y)
b:Show()
else
b:Hide()
end
end
]]
-- LB / RB: the previous or next page
local PAGE = [[
if not down then return false end
local pages = owner:GetAttribute("ck-" .. (owner:GetAttribute("wheel") or "c") .. "-pages") or 1
if pages < 2 then return false end
owner:SetAttribute("page", ((owner:GetAttribute("page") or 1) - 1 + (button == "LB" and -1 or 1)) % pages + 1)
]] .. APPLY_PAGE .. [[
return false
]]
-- `slot`: the slot the left stick points at now (past half its course), else
-- 0. A party spell's wheel: the right stick, the nearest member there
local AIMED = [[
local slot = 0
local state = GetGamePadState()
local aimWid = owner:GetAttribute("wheel") or "c"
local aimParty = strsub(aimWid, 1, 1) == "p"
local stick = state and state.sticks
and state.sticks[owner:GetAttribute(aimParty and "ck-pstick" or "ck-stick") or 1]
local n = owner:GetAttribute("ck-" .. aimWid .. "-" .. (owner:GetAttribute("page") or 1) .. "-n") or 0
if n > 0 and stick and stick.len and stick.len > ]] .. AIM .. [[ then
local bestDot = -2
for i = 1, n do
if not aimParty then
local dot = stick.x * owner:GetAttribute("ck-x" .. n .. "-" .. i) + stick.y * owner:GetAttribute("ck-y" .. n .. "-" .. i)
if dot > bestDot then slot, bestDot = i, dot end
elseif owner:GetFrameRef("slot" .. i):IsShown() then
local dot = stick.x * owner:GetAttribute("ck-pdx-" .. i) + stick.y * owner:GetAttribute("ck-pdy-" .. i)
if dot > bestDot then slot, bestDot = i, dot end
end
end
end
-- An empty slot (after a page's last item, or left empty in a wheel of
-- the player's): nothing
if slot > 0 and not owner:GetFrameRef("slot" .. slot):IsShown() then slot = 0 end
]]
-- Opening: shown, the sticks taken from the camera and the character (like
-- the game's own wheels), the keys it uses taken while it is open
local SHOW = [[
owner:SetAttribute("page", 1)
]] .. APPLY_PAGE .. [[
owner:Show()
for prefix in gmatch(owner:GetAttribute("ck-prefixes"), "([^,]*),") do
owner:SetBindingClick(true, prefix .. "PAD1", "ControllerKeyboardWheelUse")
owner:SetBindingClick(true, prefix .. "PAD2", "ControllerKeyboardWheelClose")
owner:SetBindingClick(true, prefix .. "PADLSHOULDER", "ControllerKeyboardWheelPage", "LB")
owner:SetBindingClick(true, prefix .. "PADRSHOULDER", "ControllerKeyboardWheelPage", "RB")
end
owner:SetBindingClick(true, "ESCAPE", "ControllerKeyboardWheelClose")
-- A party spell's wheel: the right stick's direction keys, to see it let go
if strsub(owner:GetAttribute("wheel") or "c", 1, 1) == "p" then
owner:SetAttribute("ck-aim", 0)
owner:SetAttribute("ck-aimlen", 0)
for key in gmatch(owner:GetAttribute("ck-pstickkeys"), "([^,]+),") do
owner:SetAttribute("ck-held-" .. key, 0)
owner:SetAttribute("ck-seen-" .. key, nil)
for prefix in gmatch(owner:GetAttribute("ck-prefixes"), "([^,]*),") do
owner:SetBindingClick(true, prefix .. key, "ControllerKeyboardWheelLetGo", key)
end
end
end
]]
local HIDE = [[
owner:Hide()
owner:ClearBindings()
]]
-- A wheel's key (its "ck-wheel"): opens or closes it, on its press (a key
-- bound to it sends a press and a release; a router sends one click on the
-- press, no "down", and its release as a "ckup" click). Another wheel open:
-- this one takes its place. The release: with the hold option (Wheels >
-- Opening), what the stick aims at is used (its slot's button clicked, which
-- closes the wheel), the stick in the middle closes it; else let pass.
-- A party spell's wheel always: the stick in the middle leaves it open (a
-- short press: aim, then A).
--
-- A party spell's wheel opens on its button (its key's "ck-ax", "ck-ay": the
-- button's centre on the screen, else where the wheels go), the wheel frame
-- made small (never pushed back by the screen's edges); the next other wheel
-- puts it back where the wheels go ("ck-home-*", set by Place).
local TOGGLE = [[
local wid = self:GetAttribute("ck-wheel") or "c"
local party = strsub(wid, 1, 1) == "p"
local release = (button and strsub(button, 1, 4) == "ckup") or (not down and self:GetAttribute("ck-down"))
self:SetAttribute("ck-down", down and true or false)
if release then
if owner:GetAttribute("wheel") == wid then owner:SetAttribute("ck-open-held", nil) end
if not ((party or owner:GetAttribute("ck-hold")) and owner:IsShown() and owner:GetAttribute("wheel") == wid) then
return false
end
]] .. AIMED .. [[
if slot < 1 then
if not party then
]] .. HIDE .. [[
end
return false
end
-- Clicked on this release
self:SetAttribute("useOnKeyDown", false)
return "s" .. slot
end
if owner:IsShown() and owner:GetAttribute("wheel") == wid then
]] .. HIDE .. [[
elseif (owner:GetAttribute("ck-" .. wid .. "-total") or 0) > 0 then
local homeP = owner:GetAttribute("ck-home-p") or "CENTER"
if party then
local ax, ay = self:GetAttribute("ck-ax"), self:GetAttribute("ck-ay")
owner:SetWidth(2)
owner:SetHeight(2)
owner:ClearAllPoints()
if ax and ay then
owner:SetPoint("CENTER", "$parent", "BOTTOMLEFT", ax, ay)
else
owner:SetPoint(homeP, "$parent", homeP, owner:GetAttribute("ck-home-x") or 0, owner:GetAttribute("ck-home-y") or 0)
end
owner:SetAttribute("ck-moved", true)
owner:SetAttribute("ck-opener", self:GetName())
elseif owner:GetAttribute("ck-moved") then
owner:SetWidth(owner:GetAttribute("ck-home-w"))
owner:SetHeight(owner:GetAttribute("ck-home-h"))
owner:ClearAllPoints()
owner:SetPoint(homeP, "$parent", homeP, owner:GetAttribute("ck-home-x") or 0, owner:GetAttribute("ck-home-y") or 0)
owner:SetAttribute("ck-moved", nil)
end
owner:SetAttribute("wheel", wid)
-- Its key held (a party spell's wheel): if it is A, B, LB or RB, the
-- wheel's own keys while open, its release goes to them (OPENER_UP)
owner:SetAttribute("ck-open-held", party and true or nil)
owner:SetAttribute("ck-used-down", nil)
]] .. SHOW .. [[
end
return false
]]
-- A: the item the left stick points at; the stick in the middle: nothing
local USE = [[
if not down then return false end
]] .. AIMED .. [[
if slot < 1 then return false end
return "s" .. slot, true
]]
-- A party spell's wheel: the right stick's direction keys (their name comes
-- as the click's button), like the game's flyouts: a flick toward a member
-- and its release (no direction held any more) casts on them. Secure code
-- only sees the stick when the game sends one of those keys, at the edge of
-- their threshold, near the middle: read there, a flick up right gave UP
-- alone, as near to the member up left as to the one up right, and the
-- spell went to the wrong one or nowhere (reported: never on member 3 but
-- with A, which reads the stick held out). So each flick keeps its
-- strongest reading of the stick (any reading out of the middle at all
-- gives a direction), and, if the stick never read out, the directions it
-- went through, but only if they point at one member clearly.
local LET_GO = [[
-- For /ec wheel: each key as it comes, and the stick read then
local seen = GetGamePadState()
local seenStick = seen and seen.sticks and seen.sticks[owner:GetAttribute("ck-pstick") or 2]
owner:SetAttribute("ck-event", format("%s %s %.2f", tostring(button), down and "down" or "up", seenStick and seenStick.len or 0))
local wid = owner:GetAttribute("wheel") or "c"
if not (owner:IsShown() and strsub(wid, 1, 1) == "p" and owner:GetAttribute("ck-held-" .. button)) then
return false
end
local keys = owner:GetAttribute("ck-pstickkeys")
local held = false
for key in gmatch(keys, "([^,]+),") do
if key ~= button and owner:GetAttribute("ck-held-" .. key) == 1 then held = true end
end
if down then
-- A new flick: what it aims at starts afresh
if not held and owner:GetAttribute("ck-held-" .. button) ~= 1 then
owner:SetAttribute("ck-aim", 0)
owner:SetAttribute("ck-aimlen", 0)
for key in gmatch(keys, "([^,]+),") do owner:SetAttribute("ck-seen-" .. key, nil) end
end
owner:SetAttribute("ck-held-" .. button, 1)
owner:SetAttribute("ck-seen-" .. button, 1)
owner:SetAttribute("ck-last", button)
else
owner:SetAttribute("ck-held-" .. button, 0)
end
local state = GetGamePadState()
local stick = state and state.sticks and state.sticks[owner:GetAttribute("ck-pstick") or 2]
local len = stick and stick.len or 0
local strongest = owner:GetAttribute("ck-aimlen") or 0
-- Let go: no direction held any more, or the last one pressed released
-- (the game sends only its release: seen in game (/ec wheel), up right
-- pressed UP then RIGHT, RIGHT came back, UP's release never came, nothing
-- was cast), or one released with the stick not out at the rim (else it
-- rolls round it to another member)
local letGo = not down and (not held or owner:GetAttribute("ck-last") == button or len < 0.9)
-- Two directions to try, each giving the nearest member there: first the
-- stick now, the flick's strongest reading winning (a later one about as
-- strong too: rolling round the rim); then, let go with nothing aimed,
-- the directions the flick went through, when one member is clearly the
-- nearest. (Written out twice over: the game refuses its keyword here.)
for pass = 1, 2 do
local x, y, clear
if pass == 1 then
if len > 0.05 and len >= strongest * 0.8 then x, y = stick.x, stick.y end
elseif letGo and (owner:GetAttribute("ck-aim") or 0) < 1 then
x, y, clear = 0, 0, true
for key in gmatch(keys, "([^,]+),") do
if owner:GetAttribute("ck-seen-" .. key) then
x = x + owner:GetAttribute("ck-kx-" .. key)
y = y + owner:GetAttribute("ck-ky-" .. key)
end
end
if x == 0 and y == 0 then x = nil end
end
if x then
local best, bestDot, second = nil, -100, -100
for i = 1, 5 do
if owner:GetFrameRef("slot" .. i):IsShown() then
local dot = x * owner:GetAttribute("ck-pdx-" .. i) + y * owner:GetAttribute("ck-pdy-" .. i)
if dot > bestDot then
best, second, bestDot = i, bestDot, dot
elseif dot > second then
second = dot
end
end
end
if best and not (clear and bestDot - second < 0.1) then
owner:SetAttribute("ck-aim", best)
if pass == 1 then owner:SetAttribute("ck-aimlen", math.max(len, strongest)) end
end
end
end
if not letGo then return false end
-- Let go: every direction counted released
for key in gmatch(keys, "([^,]+),") do owner:SetAttribute("ck-held-" .. key, 0) end
local slot = owner:GetAttribute("ck-aim") or 0
if slot < 1 or not owner:GetFrameRef("slot" .. slot):IsShown() then return false end
return "s" .. slot, true
]]
-- After a use (A, or a click on a slot): the wheel closes
local DONE = HIDE
local CLOSE = HIDE .. " return false"
-- A party spell's wheel opened by A, B, LB or RB: those are the wheel's keys
-- while it is open, so the release of the key that opened it comes to them
-- (reported: a party spell on A, held, aimed, let go: nothing). Taken as
-- that key's release while none of them was pressed since the opening.
local OPENER_UP = [[
if not (owner:IsShown() and owner:GetAttribute("ck-open-held") and not owner:GetAttribute("ck-used-down")) then
return false
end
owner:SetAttribute("ck-open-held", nil)
]] .. AIMED .. [[
if slot < 1 then return false end
self:SetAttribute("useOnKeyDown", false)
return "s" .. slot, true
]]
local function keyOf(snippet)
return "if not down then " .. OPENER_UP .. " end\n"
.. "self:SetAttribute(\"useOnKeyDown\", true)\nowner:SetAttribute(\"ck-used-down\", true)\n" .. snippet
end
-- A button for the wheel's keys: a secure action button, its OnClick
-- wrapped by the wheel
local function keyButton(name, wheel, pre, post, ...)
local b = CK.NewFrame("Button", name, UIParent, "SecureActionButtonTemplate")
if ... then b:RegisterForClicks(...) else b:RegisterForClicks("AnyDown") end
b:SetAttribute("useOnKeyDown", true)
b:Hide()
SecureHandlerWrapScript(b, "OnClick", wheel, pre, post)
return b
end
local function atlas(texture, name, fallback)
if C_Texture and C_Texture.GetAtlasInfo and C_Texture.GetAtlasInfo(name) then
texture:SetAtlas(name, true)
return true
end
if fallback then fallback(texture) end
end
function W:Build()
if self.frame then return end
local wheel = CK.NewFrame("Frame", "ControllerKeyboardWheel", UIParent, "SecureHandlerBaseTemplate")
wheel:SetSize(WHEEL_SIZE, 600)
wheel:SetFrameStrata("DIALOG")
wheel:Hide()
wheel:SetAttribute("wheel", "c")
wheel:SetAttribute("page", 1)
wheel:SetMovable(true)
wheel:SetClampedToScreen(true)
wheel:EnableMouse(true)
wheel:RegisterForDrag("LeftButton")
wheel:SetScript("OnDragStart", function(self)
if not settings().locked and not InCombatLockdown() then self:StartMoving() end
end)
wheel:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
W:SavePosition()
end)
wheel:SetAttribute("ck-prefixes", PREFIXES)
-- Each slot's direction from the middle, for each number of sections
for n = 1, SEGMENTS do
for i = 1, n do
local x, y = slotDir(i, n)
wheel:SetAttribute("ck-x" .. n .. "-" .. i, x)
wheel:SetAttribute("ck-y" .. n .. "-" .. i, y)
end
end
wheel:SetAttribute("ck-radius", ICON_RADIUS)
-- A party spell's wheel: its members' places, its size
wheel:SetAttribute("ck-pradius", PARTY_RADIUS)
for i, d in ipairs(PARTY_DIRS) do
wheel:SetAttribute("ck-pdx-" .. i, d[1])
wheel:SetAttribute("ck-pdy-" .. i, d[2])
end
wheel:SetAttribute("ck-pstickkeys", PARTY_STICK_KEYS)
-- Each of them: its direction
for key, d in pairs({ PADRSTICKUP = { 0, 1 }, PADRSTICKDOWN = { 0, -1 }, PADRSTICKLEFT = { -1, 0 }, PADRSTICKRIGHT = { 1, 0 } }) do
wheel:SetAttribute("ck-kx-" .. key, d[1])
wheel:SetAttribute("ck-ky-" .. key, d[2])
end
wheel:SetAttribute("ck-home-w", WHEEL_SIZE)
wheel:SetAttribute("ck-home-h", 600)
self.frame = wheel
self:Place()
-- The wheel's key: its press (and a shared paddle key's single click)
local toggle = keyButton("ControllerKeyboardWheelToggle", wheel, TOGGLE, nil, "AnyDown", "AnyUp")
toggle:SetAttribute("ck-wheel", "c")
-- On a release (hold option): the slot aimed at ("s3")
toggle:SetAttribute("type", "click")
self.toggle = toggle
-- The usable items' wheel's key
local usable = keyButton("ControllerKeyboardUsableToggle", wheel, TOGGLE, nil, "AnyDown", "AnyUp")
usable:SetAttribute("ck-wheel", "u")
usable:SetAttribute("type", "click")
self.usableToggle = usable
-- The key of each wheel of the player's
self.myToggles = {}
for n = 1, W.MY_MAX do
local t = keyButton("ControllerKeyboardMyWheel" .. n, wheel, TOGGLE, nil, "AnyDown", "AnyUp")
t:SetAttribute("ck-wheel", tostring(n))
t:SetAttribute("type", "click")
self.myToggles[n] = t
end
-- The party spells' keys: made when a key gets one (PartyToggle)
self.partyToggles = {}
local use = keyButton("ControllerKeyboardWheelUse", wheel, keyOf(USE), DONE, "AnyDown", "AnyUp")
use:SetAttribute("type", "click")
use:HookScript("OnClick", function(_, _, down) if down ~= false then W:Log("A") end end)
self.use = use
local close = keyButton("ControllerKeyboardWheelClose", wheel, keyOf(CLOSE), DONE, "AnyDown", "AnyUp")
close:SetAttribute("type", "click")
-- The stick direction keys: their presses and releases move the choice
local page = keyButton("ControllerKeyboardWheelPage", wheel, keyOf(PAGE), DONE, "AnyDown", "AnyUp")
page:SetAttribute("type", "click")
-- A party spell's wheel: the right stick let go (its direction keys'
-- presses and releases; the cast on a release)
local letGo = keyButton("ControllerKeyboardWheelLetGo", wheel, LET_GO, DONE, "AnyDown", "AnyUp")
letGo:SetAttribute("type", "click")
letGo:SetAttribute("useOnKeyDown", false)
-- For /ec wheel: the stick's keys as the game sent them, and the member
-- aimed (the secure code's own notes, each change told by the game)
wheel:HookScript("OnAttributeChanged", function(_, name, value)
-- (the game gives the attributes' names in lower case)
local lower = type(name) == "string" and name:lower() or ""
if lower == "ck-aim" or lower == "ck-event" or lower:find("^ck%-held%-padrstick") then
W:Log(format("%s = %s", name, tostring(value)))
end
end)
self.letGo = letGo
-- What is drawn: the game's radial menu art, under the slots' buttons
local view = CK.NewFrame("Frame", nil, wheel)
view:SetAllPoints()
self.view = view
-- The sticks: taken by this plain frame of ours while it shows (with the
-- wheel), like the game's own wheels, so the character and the camera
-- don't move (and food can be eaten: not while moving). Turned on each
-- time it shows; its stick script is needed for the game to give it them.
view:SetScript("OnGamePadStick", function() W:Track() end)
-- The wheel in as many sections as the page holds (set when drawn)
local bg = view:CreateTexture(nil, "BACKGROUND")
bg:SetPoint("CENTER")
bg:SetSize(WHEEL_SIZE, WHEEL_SIZE)
bg:SetTexture(TEX .. "ck_wheel_bg_8")
view.bg = bg
-- The aimed section
view.highlight = view:CreateTexture(nil, "BORDER")
view.highlight:Hide()
-- Under the wheel, the game's banner: the aimed item (or what to do);
-- below it, the pages and the help
view.bottom = view:CreateTexture(nil, "BACKGROUND")
view.bottom:SetPoint("TOP", bg, "BOTTOM", 0, 8)
atlas(view.bottom, "gamepad-radial-menu-bottomtext", function(t)
t:SetColorTexture(0, 0, 0, 0.5)
end)
view.bottom:SetSize(BANNER_W, BANNER_H)
view.name = view:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
view.name:SetPoint("TOP", view.bottom, "TOP", 0, -12)
view.name:SetWidth(BANNER_W - 30)
view.name:SetWordWrap(false)
view.count = view:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
view.count:SetPoint("TOP", view.name, "BOTTOM", 0, -4)
view.count:SetWidth(BANNER_W - 30)
view.count:SetWordWrap(false)
view.help = view:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
view.help:SetPoint("TOP", view.bottom, "BOTTOM", 0, -4)
view.pages = view:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
view.pages:SetPoint("TOP", view.help, "BOTTOM", 0, -4)
view:SetScript("OnUpdate", function() W:Track() end)
view:SetScript("OnShow", function()
W:TakeSticks(view, true)
W.hold:Hide()
W:Paint()
W:Log("open")
end)
-- Closed with a stick still pushed: held until it is let go, so the
-- character doesn't walk off (or stand up from eating)
view:SetScript("OnHide", function() W:HoldSticks() end)
-- Closed (its keys let go in its secure code, which our binding hooks
-- don't see): the replaced buttons it held back are bound again
wheel:HookScript("OnHide", function()
C_Timer.After(0, function()
if not InCombatLockdown() and CK.Mapping then CK.Mapping:Repair() end
-- A party spell's wheel closed: the frame back where the wheels
-- go, the stick's direction keys given back
if not wheel:IsShown() then
W:Unmove()
if not InCombatLockdown() then W:SyncStickKeys() end
end
end)
end)
self:BuildHold()
self.segments, self.buttons = {}, {}
for i = 1, SEGMENTS do
local ix, iy = slotDir(i, SEGMENTS)
ix, iy = ICON_RADIUS * ix, ICON_RADIUS * iy
local seg = {}
-- The grey veil over a section that can't be used
seg.disabled = view:CreateTexture(nil, "ARTWORK", nil, 2)
seg.disabled:Hide()
-- The item: a round slot of the gamepad bar's, its name further out
-- (both placed for the page's count when drawn)
seg.slot = CK.Paddles:CreateSlot(view, SLOT)
seg.slot:SetPoint("CENTER", bg, "CENTER", ix, iy)
seg.slot:Hide()
seg.label = view:CreateFontString(nil, "OVERLAY", "GameFontNormal")
seg.label:SetSize(LABEL_W, LABEL_H)
seg.label:SetJustifyH("CENTER")
seg.label:SetJustifyV("MIDDLE")
seg.label:SetWordWrap(true)
self.segments[i] = seg
-- The slot's own secure button: clicked by a stick, A, the key ("s3"),
-- or the mouse
local b = CK.NewFrame("Button", "ControllerKeyboardWheelSlot" .. i, wheel, "SecureActionButtonTemplate")
b:SetSize(SLOT + 14, SLOT + 14)
-- On the wheel frame (the background's center): a protected frame can't
-- be anchored to a texture
b:SetPoint("CENTER", wheel, "CENTER", ix, iy)
b:RegisterForClicks("AnyUp")
b:SetAttribute("useOnKeyDown", false)
b:SetScript("OnEnter", function(self)
local entry = W:PageItems()[i]
if not entry then return end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
if entry.party then
GameTooltip:SetUnit(entry.unit)
elseif entry.kind == "item" then
GameTooltip:SetItemByID(entry.id)
elseif entry.kind == "spell" and GameTooltip.SetSpellByID then
GameTooltip:SetSpellByID(entry.id)
else
GameTooltip:SetText(W.EntryName(entry), 1, 1, 1)
end
GameTooltip:Show()
end)
b:SetScript("OnLeave", function() GameTooltip:Hide() end)
SecureHandlerWrapScript(b, "OnClick", wheel, "return nil, true", DONE)
b:HookScript("OnClick", function()
-- For /ec wheel: the member a party spell went to
local unit = W.isParty(wheel:GetAttribute("wheel")) and b:GetAttribute("unit")
W:Log("use " .. i .. (unit and (" on " .. unit) or ""))
if unit then W.castAt = GetTime() end
W:NoteMeal(i)
end)
b:Hide()
SecureHandlerSetFrameRef(wheel, "slot" .. i, b)
use:SetAttribute("*clickbutton-s" .. i, b)
letGo:SetAttribute("*clickbutton-s" .. i, b)
close:SetAttribute("*clickbutton-s" .. i, b)
page:SetAttribute("*clickbutton-s" .. i, b)
self.toggle:SetAttribute("*clickbutton-s" .. i, b)
for _, t in ipairs(self.myToggles) do t:SetAttribute("*clickbutton-s" .. i, b) end
self.buttons[i] = b
end
self:BuildParty(wheel)
end
-- A party spell's wheel's drawing, over the wheel (the big wheel's drawing
-- hidden meanwhile): a round base like the game's flyouts, the spell in the
-- middle, the members there around it, the aimed one pointed at like the
-- game's flyouts do; above it, a banner: the spell, the member aimed (or
-- what to do), the help
function W:BuildParty(wheel)
local pv = CK.NewFrame("Frame", nil, wheel)
pv:SetPoint("CENTER")
pv:SetSize(PARTY_BASE, PARTY_BASE)
pv:Hide()
self.pview = pv
pv.base = pv:CreateTexture(nil, "BACKGROUND")
pv.base:SetPoint("CENTER")
pv.base:SetSize(PARTY_BASE, PARTY_BASE)