Repository navigation
Expand file tree
/
Copy pathApply.lua
More file actions
876 lines (768 loc) · 36.8 KB
/
Copy pathApply.lua
File metadata and controls
876 lines (768 loc) · 36.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
local ADDON, ns = ...
-- Applying the settings: build, lay out, assign, route the keys, hide the
-- game's bars.
--
-- === The order here is the rule ===
--
-- The bar frame first, then the buttons, then the slots, then the keys. The
-- reverse order is not merely awkward, it does not work: a key cannot be bound
-- to a button that does not exist, and a slot cannot be assigned to a button
-- with no bar.
--
-- All of it out of combat. In combat applying does nothing at all: half the
-- work done in combat is worse than none, because the other half arrives at an
-- unknown time.
local Apply = {}
ns.Apply = Apply
--============================================================================
-- Keys
--============================================================================
-- The buttons we routed keys to. Needed for the restore: the override is
-- cleared with one call on the owner, but the label on a button has to be
-- wiped one by one.
local bound = {}
--- Route the player's keys to a bar's buttons.
--
-- === What an override is and why ===
--
-- A binding belongs to a SLOT: "1" presses the first slot of the main bar. The
-- game does not know our buttons, and without routing "1" would keep pressing
-- the game's hidden button - the spell would fire while the glow, the cooldown
-- and the press feedback stayed on a button nobody can see.
--
-- The routing is done with an OVERRIDE rather than by editing the player's
-- bindings: switch the module off and they get their bindings untouched. An
-- override belongs to an owner - our bar frame - and is cleared from it whole.
--
-- @param key string bar key
-- @param settings table bar settings
-- @return number how many keys were routed
function Apply.Bind(key, settings)
local frame = ns.Build.frames[key]
local list = ns.Build.buttons[key]
if type(frame) ~= "table" or type(list) ~= "table" then return 0 end
if type(settings) ~= "table" then return 0 end
if ns.Build.InCombat() then return 0 end
if type(_G.ClearOverrideBindings) == "function" then
pcall(_G.ClearOverrideBindings, frame)
end
if type(_G.SetOverrideBindingClick) ~= "function" then return 0 end
if type(_G.GetBindingKey) ~= "function" then return 0 end
local taken = 0
for i = 1, 12 do
local button = list[i]
if button then
local action = ns.Bind.For(key, i)
local name = ns.Bind.ButtonName(key, i)
local said = nil
if action and name then
-- Keys from BOTH places.
--
-- The button's own binding - "CLICK <button>:LeftButton" -
-- is what this addon writes now, and it needs no override
-- at all: the game sends the press straight to the button.
-- Any number of keys may point at it, which is how one
-- button answers to a key named differently in each of the
-- player's keyboard layouts.
--
-- The action slot's binding is what the player already had
-- before this addon, shared with the game's own bar. That
-- one does need an override, or the press goes to the
-- game's hidden button instead of ours.
local keys = {}
local click = ns.Bind.ClickName(name)
if click then
local okClick, a, b = pcall(_G.GetBindingKey, click)
if okClick then
for _, stroke in ipairs({ a, b }) do
if type(stroke) == "string" and stroke ~= "" then
keys[#keys + 1] = { stroke = stroke,
override = false }
end
end
end
end
local ok, first, second = pcall(_G.GetBindingKey, action)
if ok then
for _, stroke in ipairs({ first, second }) do
if type(stroke) == "string" and stroke ~= "" then
keys[#keys + 1] = { stroke = stroke,
override = true }
end
end
end
do
for _, entry in ipairs(keys) do
local stroke = entry.stroke
if entry.override then
-- NOT a priority binding.
--
-- Bartender4 passes false here, and what the
-- argument decides is who wins when the player
-- has that key bound elsewhere too. A priority
-- override takes the key away from everything
-- else, the game's own uses included, and the
-- player has no way to see why it stopped doing
-- what it used to.
--
-- There was an alias loop here, binding the key
-- under Cyrillic names as well. It was built on
-- a wrong reading of how the engine names keys:
-- the game's own bindings-cache.wtf holds ASCII
-- names only, and neither Bartender4 nor
-- LibActionButton-1.0 has a line about keyboard
-- layouts. Names the engine never uses can only
-- add ways to fail.
-- A PRIORITY override.
--
-- The key is very often still bound to the
-- game's own button for the same slot - that is
-- what the player had before us, and it stays in
-- their bindings. A non-priority override loses
-- to it, the press goes to the game's button,
-- and ours does nothing.
--
-- Bartender4 passes false here and does not
-- suffer for it, because it takes the game's
-- bars away entirely. We leave them in place.
--
-- Every name the engine can give this PLACE on
-- the keyboard, not only the one it is stored
-- under: the binding itself holds exactly what
-- the engine reported when the key was pressed,
-- which answers in one layout, and the overrides
-- are ours and cost nothing to carry in the
-- rest.
local names = ns.Keys.Aliases(stroke)
for at = 1, #names do
pcall(_G.SetOverrideBindingClick, frame,
true, names[at], name, "LeftButton")
end
end
-- Every key on the label, not the first.
--
-- A button may answer to several now - that is the
-- point of the change - and a label showing one of
-- them tells the player their other key did not
-- take, which was the old complaint in reverse.
--
-- Each is shortened BEFORE being joined: the game's
-- abbreviator takes one key name, and handing it a
-- list would leave the list unshortened.
local short = stroke
if type(_G.GetBindingText) == "function" then
local okText, brief =
pcall(_G.GetBindingText, stroke, "KEY_")
if okText and type(brief) == "string" then
short = brief
end
end
said = said and (said .. ", " .. short) or short
taken = taken + 1
end
end
end
button.rackBinding = said
bound[button] = said and true or nil
-- The label is written here as well as remembered.
--
-- Binding by hovering runs this SHORT pass on purpose - a full
-- apply on every keypress lost presses - so the repaint that
-- would otherwise write the label does not run. Without this the
-- player presses a key, the binding is made, and the button goes
-- on showing nothing until something else repaints it.
--
-- Shown as well as set: the label comes from the game's template
-- now, and the game keeps its own hidden until its own code puts
-- a binding on it. That code is off our buttons.
local label = button.rackHotkey
if type(label) == "table" then
pcall(label.SetText, label, said or "")
pcall(label.Show, label)
end
end
end
return taken
end
--============================================================================
-- The game's bars
--============================================================================
-- The game's bars we hid. The key is the frame itself.
--
-- The same rule as for the decorative art in the core: ONLY WHAT IS OURS MAY
-- BE RESTORED. The player hides a bar by switching the module on; we may show
-- it again precisely because we hid it ourselves.
--
-- The record lives beside the object: a field on the game's bar taints it.
local hidden = setmetatable({}, { __mode = "k" })
-- Every game bar the addon ever touches. Their names live in Core/Frames.lua,
-- with the rest of the knowledge about foreign frames.
local GAME_BARS = {
"main", "bottomleft", "bottomright", "right", "left", "pet", "stance",
}
Apply.GAME_BARS = GAME_BARS
-- Which of the game's bars yields to which of ours.
--
-- The five main ones always yield: ours replace them, and both on screen would
-- be two rows of the same spells. Pet and stance only when our bar is on:
-- hiding the game's without putting ours up would take the player's buttons
-- away and give nothing back.
local OWNED_BY = {
pet = "pet",
stance = "stance",
}
--- Which of the game's bars are hidden under these settings.
--
-- Pure, and the only place this is decided. When restoring, the whole list is
-- returned: everything ever hidden has to come back, including what was hidden
-- under other settings.
--
-- @param wanted any whether we are hiding
-- @param settings table|nil module settings
-- @return table array of group names
function Apply.Groups(wanted, settings)
if not wanted then return GAME_BARS end
local list = {}
for i = 1, #GAME_BARS do
local group = GAME_BARS[i]
local owner = OWNED_BY[group]
local own = owner and type(settings) == "table" and settings[owner]
if owner == nil or (type(own) == "table" and own.enabled == true) then
list[#list + 1] = group
end
end
return list
end
-- Whose parent we restored and to what. The key is the frame itself, the
-- record beside it: a field on a game frame taints it.
local rescued = setmetatable({}, { __mode = "k" })
--- Carry out from under the bars being hidden what must not be hidden.
--
-- === What for ===
--
-- The "leave vehicle" button is a child of the main bar. Hiding the main bar
-- hides with it the only way to dismount: the player stays in the saddle with
-- no exit button, and only a relog brings it back. We do not draw an exit
-- button of our own and should not - the game draws it and knows when it is
-- needed.
--
-- === Why only a parent change and not one SetPoint ===
--
-- The button is protected, and setting its place would be refused. Nor is it
-- needed: its anchor point stays as it was - to the main bar, which has not
-- gone anywhere but merely moved to a hidden parent, keeping its place. So the
-- button stays exactly where the game put it.
--
-- @param wanted any whether the bars are being hidden
-- @return number how many frames were touched
function Apply.KeepLoose(wanted)
if ns.Build.InCombat() then return 0 end
local touched = 0
local loose = ns.Frames.Resolve(ns.Frames.LOOSE)
for i = 1, #loose do
local frame = loose[i]
if type(frame.GetParent) == "function" then
if wanted then
if rescued[frame] == nil then
local okParent, parent = pcall(frame.GetParent, frame)
if okParent and type(parent) == "table"
and parent ~= _G.UIParent then
if pcall(frame.SetParent, frame, _G.UIParent) then
rescued[frame] = parent
touched = touched + 1
end
end
end
elseif rescued[frame] then
pcall(frame.SetParent, frame, rescued[frame])
rescued[frame] = nil
touched = touched + 1
end
end
end
return touched
end
--- Hide the game's bars or bring them back.
--
-- Hidden through the parent frame rather than by calling Hide: the bar is
-- protected and Hide on it is forbidden. Reparenting to a hidden frame is the
-- technique everyone uses, and it is not protected.
--
-- @param wanted boolean whether to hide
-- @param settings table|nil module settings
-- @return number how many bars were touched
function Apply.HideGameBars(wanted, settings)
if ns.Build.InCombat() then return 0 end
local touched = 0
for _, group in ipairs(Apply.Groups(wanted, settings)) do
local found = ns.Frames.Bar(group)
do
for i = 1, #found do
local frame = found[i]
if type(frame) == "table" then
if wanted then
if not hidden[frame] then
local okHide = pcall(frame.SetParent, frame,
ns.Apply.Hider())
if okHide then
hidden[frame] = true
touched = touched + 1
end
end
elseif hidden[frame] then
pcall(frame.SetParent, frame, _G.UIParent)
hidden[frame] = nil
touched = touched + 1
end
end
end
end
end
return touched
end
-- The frame hidden bars move into. Created once: a second one in its place
-- would lose what the first already holds.
local hider
--- The hidden host frame.
-- @return table|nil
function Apply.Hider()
if hider then return hider end
if type(CreateFrame) ~= "function" then return nil end
local ok, frame = pcall(CreateFrame, "Frame", "RackHider",
_G.UIParent)
if not ok or type(frame) ~= "table" then return nil end
pcall(frame.Hide, frame)
hider = frame
return hider
end
--============================================================================
-- Mover
--============================================================================
-- Default bar positions.
--
-- The numbers are not arbitrary: the bars stand where the player is used to
-- seeing them in the game itself - the main one above the bottom of the
-- screen, the rest in rows above it and columns to the right. A default the
-- player did not choose has to be what they have already seen, and a first
-- impression of "it landed in the wrong place" costs more than any saving.
local WHERE = {
main = { point = "BOTTOM", x = 0, y = 40 },
bottomleft = { point = "BOTTOM", x = 0, y = 84 },
bottomright = { point = "BOTTOM", x = 0, y = 128 },
right = { point = "RIGHT", x = -44, y = 0 },
left = { point = "RIGHT", x = -88, y = 0 },
-- Bars beyond the game's five stand in a column on the left: they have no
-- native place at all, and covering someone else's is the worst default.
page2 = { point = "LEFT", x = 44, y = 0 },
page7 = { point = "LEFT", x = 88, y = 0 },
page8 = { point = "LEFT", x = 132, y = 0 },
page9 = { point = "LEFT", x = 176, y = 0 },
page10 = { point = "LEFT", x = 220, y = 0 },
-- Pet and stance: left of the main bar and above it - where the game keeps
-- them, and where the eye looks for them.
pet = { point = "BOTTOM", x = -260, y = 84 },
stance = { point = "BOTTOM", x = -260, y = 128 },
-- Foreign bars. Their defaults are where the game keeps these things:
-- status bars above the bottom of the screen, bags and micro menu in the
-- lower right corner, the extra action button above the middle. They used
-- to have no defaults at all and landed IN THE CENTRE OF THE SCREEN, one on
-- top of another: the first thing a player saw on enabling the experience
-- bar was the experience bar across their face.
experience = { point = "BOTTOM", x = 0, y = 4 },
reputation = { point = "BOTTOM", x = 0, y = 22 },
bags = { point = "BOTTOMRIGHT", x = -8, y = 8 },
micro = { point = "BOTTOMRIGHT", x = -8, y = 44 },
totems = { point = "BOTTOM", x = 300, y = 84 },
-- The queue eye goes where the game keeps it: by the top right corner,
-- under the minimap. A player who enables the bar has to see it in its old
-- place, not in the middle of the screen.
queue = { point = "TOPRIGHT", x = -200, y = -24 },
vehicle = { point = "BOTTOM", x = 300, y = 150 },
extra = { point = "BOTTOM", x = 0, y = 200 },
-- The gryphons stand AROUND the main bar: they are drawn for its edges and
-- have no sense anywhere else. Seven below it - the art is taller than a
-- button, and their bottom edges would not meet otherwise.
gryphons = { point = "BOTTOM", x = 0, y = 33 },
}
--- The default position of this bar.
--
-- A function of its own because two callers ask: applying the settings, and
-- the mover when the player asks for the bar to be put back. Two lists of
-- defaults would drift at the eleventh bar, and drift silently.
--
-- @param key any bar key
-- @return table anchor point and offsets
function Apply.Where(key)
return WHERE[key] or { point = "CENTER", x = 0, y = 0 }
end
--============================================================================
-- Scale and alpha
--============================================================================
--- Apply a bar's scale and alpha.
--
-- === Why a function of its own and not part of the layout ===
--
-- Scale and alpha used to be set by the layout (ns.Build.Layout), and a layout
-- exists only for a bar of OUR OWN buttons: foreign ones are either laid out on
-- our grid (Borrow.Lay) or not laid out at all (Borrow.ParkAll, Art.Lay).
--
-- Because of that, for bags, the micro menu, the experience and reputation
-- bars, the totem bar, the vehicle exit button and the gryphons, two sliders -
-- "Bar Scale" and "Bar Alpha" - did EXACTLY NOTHING. A slider that moves while
-- nothing changes on screen reads as a broken addon, and it is right.
--
-- The numbers are the same and computed by the same code as for our own bars:
-- the scale limits and the fade rule live in ns.Layout, and a second place
-- computing them would drift from the first.
--
-- @param frame any the bar frame
-- @param own any bar settings
-- @return boolean whether anything was touched
function Apply.Dress(frame, own)
if type(frame) ~= "table" or type(own) ~= "table" then return false end
local scale = ns.Layout.Clamp(own.scale, 0.5, 2, 1)
pcall(frame.SetScale, frame, scale)
-- Alpha goes through Layout.FadeAlpha rather than a plain number: a bar
-- set to fade must already be faded right after the settings are applied,
-- not from the moment the mouse first leaves it.
pcall(frame.SetAlpha, frame, ns.Layout.FadeAlpha(own, false))
Apply.Depth(frame, own)
return true
end
--============================================================================
-- Who sits above whom
--============================================================================
-- The strata the player may choose.
--
-- The engine has more, and above these are three others: dialogs, tooltips,
-- fullscreen frames. They are deliberately absent - an action bar placed above
-- the options window covers the button used to get it out of there.
local STRATA = { "BACKGROUND", "LOW", "MEDIUM", "HIGH" }
Apply.STRATA = STRATA
local KNOWN = {}
for i = 1, #STRATA do KNOWN[STRATA[i]] = true end
-- Level limits within a stratum.
local DEEPEST, HIGHEST = 0, 50
Apply.HIGHEST = HIGHEST
--- A stratum fit to apply.
--
-- Pure. An unknown name means the ordinary stratum rather than a refusal: it
-- comes out of a saved file that gets hand-edited, and a bar with no stratum
-- is placed by the engine wherever it pleases.
--
-- @param name any
-- @return string
function Apply.Strata(name)
if KNOWN[name] then return name end
return "MEDIUM"
end
--- A level within a stratum, fit to apply.
--
-- @param value any
-- @return number
function Apply.Level(value)
local said = tonumber(value)
if said == nil then return 2 end
said = math.floor(said)
if said < DEEPEST then return DEEPEST end
if said > HIGHEST then return HIGHEST end
return said
end
--- Put a bar on its own stratum.
--
-- === Why this is a setting ===
--
-- Most often for the artwork. The gryphons stand AROUND the action bar, and
-- where exactly is decided not by their place on screen but by who is above
-- whom: drawn over the buttons they cover the outermost ones; under the
-- buttons they hide behind them. There is no right answer - it depends on the
-- sizes the player chose.
--
-- But it exists for EVERY bar, not for the artwork alone. Action bars get
-- placed overlapping - bags over the micro menu, a narrow status bar over a
-- wide one - and the order they are drawn in otherwise depends on which one
-- the player enabled first. That is not an answer anybody can explain.
--
-- @param frame any the bar frame
-- @param own any bar settings
-- @return boolean whether anything was touched
function Apply.Depth(frame, own)
if type(frame) ~= "table" or type(own) ~= "table" then return false end
pcall(frame.SetFrameStrata, frame, Apply.Strata(own.strata))
pcall(frame.SetFrameLevel, frame, Apply.Level(own.level))
return true
end
--============================================================================
-- Fading bars
--============================================================================
--- Whether clicks pass through a bar's buttons.
--
-- === When this is wanted ===
--
-- A bar standing over the game world intercepts clicks: the player aims at the
-- ground behind it and hits a button. For a bar nobody presses - and such bars
-- exist: a row kept for its keys - that is pure interference.
--
-- The mouse is disabled ON THE BUTTONS, not on the bar frame: the frame has no
-- mouse at all, so there is nothing to disable there. That is also why this
-- setting exists only for bars with OUR OWN buttons: foreign buttons have an
-- owner, and we have no right to take the mouse from it - it lives by it.
--
-- Tooltips and mouseover fading go away with this, and cannot not: both learn
-- about the mouse from the button itself.
--
-- @param key any bar key
-- @param own any bar settings
-- @return number how many buttons were touched
function Apply.Through(key, own)
local list = ns.Build.buttons[key]
if type(list) ~= "table" or type(own) ~= "table" then return 0 end
local through = own.clickThrough == true
local many = 0
for i = 1, #list do
local button = list[i]
if type(button) == "table" and type(button.EnableMouse) == "function" then
if pcall(button.EnableMouse, button, not through) then
many = many + 1
end
end
end
return many
end
--- Recompute a bar's alpha under the mouse.
--
-- Called from a button: the mouse arrives on a button while what fades is the
-- bar it belongs to. Alpha is not protected and therefore works in combat.
--
-- @param key any bar key
-- @param over any whether the mouse is on the bar
-- @return boolean whether the bar was touched
function Apply.Fade(key, over)
local frame = type(key) == "string" and ns.Build.frames[key] or nil
if type(frame) ~= "table" then return false end
local own = ns.Bars.BarSettings(key)
if type(own) ~= "table" then return false end
return pcall(frame.SetAlpha, frame, ns.Layout.FadeAlpha(own, over)) or false
end
--============================================================================
-- All at once
--============================================================================
--- Apply the settings in full.
--
-- @param settings table module settings
-- @return number how many bars were built
function Apply.All(settings)
if type(settings) ~= "table" then return 0 end
if ns.Build.InCombat() then return 0 end
local on = settings.enabled == true
-- The rescue comes before the hiding: the vehicle exit button has to leave
-- the main bar BEFORE the bar moves to the hidden parent, or we would hide
-- it along with the bar for a moment - and that moment lasts until the next
-- apply.
Apply.KeepLoose(on)
Apply.HideGameBars(on, settings)
-- An open flyout is closed: it hangs ON A BUTTON, and the buttons are
-- about to be rearranged, re-dressed and possibly removed. A flyout left
-- where a removed button was hangs in empty space.
ns.Flyout.Shut()
-- A sign for the neighbours: we are drawing the action bars now.
--
-- What it is for. Dark themes and interface suites configure the GAME'S
-- bars - rightly, until somebody replaces them. Having replaced them, we
-- leave such an addon with a settings section that changes nothing: the
-- bars it governs are no longer on screen. Reading this sign, a neighbour
-- can stand down and tell the player where the settings went.
--
-- The sign is only read, and only this way: no requests, no calls, no
-- subscriptions. An addon that knows nothing about us works as before.
_G.RackActive = on and true or nil
local built = 0
for i = 1, #ns.Bars.BARS do
local entry = ns.Bars.BARS[i]
local own = settings[entry.key]
if on and type(own) == "table" and own.enabled then
local frame = ns.Build.Frame(entry.key)
-- Foreign buttons: the game makes them and we have nothing to make
-- them with. We take what it shows and lay it out on our grid
-- (Borrow.lua).
if frame and entry.kind == "borrowed" then
-- A ready container is moved whole. Taking it apart into
-- buttons breaks its own layout: that code keeps running and
-- drops, not finding its buttons.
local whole = entry.whole
and ns.Frames.Resolve(ns.Frames.PARKED[entry.whole])
or {}
-- The backpack that opens every bag. The hook is installed once
-- and asks the setting itself on every press.
--
-- It stands BEFORE the container is resolved rather than inside
-- that branch: everyone has a backpack, while the container is
-- not on every build, and the setting must not depend on
-- whether it was found.
if entry.key == "bags" then ns.Borrow.WatchBackpack() end
if whole[1] then
ns.Borrow.ParkAll(entry.key, whole)
else
ns.Borrow.Lay(entry.key,
ns.Borrow.For(entry.source), own)
end
-- Show BEFORE the visibility rules, not after. Details where
-- this is written for a bar of our own buttons.
pcall(frame.Show, frame)
ns.Build.Drivers(entry.key, own)
Apply.Dress(frame, own)
ns.Mover.Place(frame, own.position, Apply.Where(entry.key))
built = built + 1
-- A whole foreign frame: its internal layout, our place.
elseif frame and entry.kind == "parked" then
local found = ns.Frames.Resolve(ns.Frames.PARKED[entry.source])
-- ALL that were found, not the first. On this client two frames
-- from one list can exist at once - the experience bar is the
-- example - and the guess that "a list is one thing under
-- different names" cost the player two bars on screen.
if found[1] then
local _, wide = ns.Borrow.ParkAll(entry.key, found,
entry.resize and own.width or nil)
-- The width the bar turned out to have is written into the
-- settings - once, while it is still zero. Zero is a
-- correct default: a status bar's own width differs across
-- builds. As a reading it is useless - the player opens the
-- slider and sees zero for a bar that is six hundred pixels
-- wide on screen.
if entry.resize and wide and wide > 0
and (tonumber(own.width) or 0) <= 0 then
own.width = math.floor(wide)
end
pcall(frame.Show, frame)
ns.Build.Drivers(entry.key, own)
Apply.Dress(frame, own)
ns.Mover.Place(frame, own.position, Apply.Where(entry.key))
built = built + 1
else
-- There was nothing to park: this frame does not exist in
-- the client.
--
-- The bar is then SILENCED rather than left empty. Empty,
-- it would still get a handle in edit mode - a label in the
-- middle of the screen with nothing behind it - and the
-- player would be moving something that does not exist.
ns.Build.Silence(entry.key)
end
-- A pair of artwork pieces: left to the left edge, right to the
-- right, with the distance the player chose between them (Art.lua).
elseif frame and entry.kind == "art" then
if ns.Art.Lay(entry.key, own) > 0 then
pcall(frame.Show, frame)
ns.Build.Drivers(entry.key, own)
Apply.Dress(frame, own)
ns.Mover.Place(frame, own.position, Apply.Where(entry.key))
built = built + 1
else
ns.Build.Silence(entry.key)
end
elseif frame then
-- How many buttons to create. Twelve only for an action bar:
-- the pet has ten, the stance bar likewise, and the two spare
-- ones would be empty forever because there is no eleventh
-- ability.
local many = ns.Paint.Numeric(own.count) or 12
many = math.floor(many)
if many < 1 then many = 1 end
if many > 12 then many = 12 end
for index = 1, many do
ns.Build.Button(entry.key, index)
end
-- What a button fires on is the game's setting, changed in its
-- window and not in ours: re-read on every apply.
for index = 1, many do
ns.Build.Clicks(ns.Build.buttons[entry.key][index])
end
ns.Build.Layout(entry.key, own)
ns.Build.Assign(entry.key, own)
-- Where this bar's flyouts open. Computed from its place on
-- screen: a bar at the bottom opens upwards, one at the top
-- downwards. Stands BEFORE the repaint: the repaint draws the
-- arrow and needs the direction ready.
ns.Flyout.Aim(entry.key)
-- The bar is shown BEFORE it is given the visibility rules.
--
-- === Why the order decides everything here ===
--
-- The visibility rules are evaluated by the engine: it looks at
-- the condition and shows or hides the bar itself - in combat
-- too, where our code has no reach.
--
-- Regression: Show stood AFTER the rules were handed over, and
-- that cancelled all of them. The engine applied a rule the
-- moment it got it - hiding the bar if so told - and the next
-- line of ours showed it again. "Always hide" hid nothing;
-- "hide with no target" only started working at the next target
-- change.
--
-- Now it is the other way round: we say "the bar is in place"
-- and the rule has the last word. That is the whole point of
-- handing the rules to the engine.
pcall(frame.Show, frame)
ns.Build.Drivers(entry.key, own)
-- Cast modifiers come from the SHARED settings rather than the
-- bar's: a target modifier is a property of the player's hand.
ns.Build.Casting(entry.key, settings)
-- Mouseover and auto-assist are the BAR's settings: a player
-- keeps heals on one bar and attacks on another, and wants the
-- former under the mouse.
ns.Build.Targeting(entry.key, own, settings)
Apply.Bind(entry.key, own)
-- Click-through. After the rules are handed over, not before:
-- the mouse is disabled on the button, and the button was still
-- being given its rules.
Apply.Through(entry.key, own)
-- Label font. Before the repaint, not after: the repaint puts
-- text into the labels, and the engine will measure it with
-- whatever font we set.
--
-- The shared settings go in too: the size and outline belong to
-- the bar, the face is one for all of them.
ns.Build.Lettering(entry.key, own, settings)
if entry.kind == "pet" then
ns.Pet.Bar(ns.Build.buttons[entry.key], own)
elseif entry.kind == "stance" then
ns.Stance.Bar(ns.Build.buttons[entry.key], own)
else
ns.Paint.Bar(ns.Build.buttons[entry.key], own)
end
-- The bar's place is set here rather than at creation: before
-- it is enabled there is nothing to place, and a bar with no
-- buttons would take up someone else's spot with its corner.
--
-- Button look: ours, the game's or a foreign skin
-- (Skinning.lua). After the repaint, not before: the repaint
-- sets the icon, the look decides how it is cropped and framed.
ns.Skinning.Bar(entry.key, ns.Build.buttons[entry.key], own)
-- Stratum and level. Scale and alpha on our own bars are set by
-- the layout; the stratum is common to every bar at once.
Apply.Depth(frame, own)
ns.Mover.Place(frame, own.position, Apply.Where(entry.key))
built = built + 1
end
else
-- Not merely hidden: the bar also loses its key overrides and its
-- right to show itself. A hidden bar with a live visibility
-- condition surfaces again on its own, and with a live override it
-- holds the player's keys while promising to give them back.
ns.Build.Silence(entry.key)
-- And what is foreign goes back to the game. A disabled bag bar
-- that kept the bags takes them off the screen entirely: the game
-- no longer knows about them, and there is nothing to open the
-- backpack with.
if entry.kind == "borrowed" or entry.kind == "parked"
or entry.kind == "art" then
ns.Borrow.Release(entry.key)
end
end
end
-- The grid is redrawn along with everything else: its step is dragged on a
-- slider during edit mode, and a player dragging a slider with no response
-- on screen is dragging it blind.
ns.Grid.Refresh()
return built
end