-
Notifications
You must be signed in to change notification settings - Fork 4
/
movable.lua
945 lines (765 loc) · 23.7 KB
/
movable.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
local _NAME, _NS = ...
local oUF = _NS.oUF or oUF
assert(oUF, "oUF_MovableFrames was unable to locate oUF install.")
-- The DB is organized as the following:
-- {
-- Lily = {
-- player = "CENTER\031UIParent\0310\031-621\0310.8",
-- }
--}
local _DB
local _DBNAME = C_AddOns.GetAddOnMetadata(_NAME, 'X-SavedVariables')
local _LOCK
local _TITLE = C_AddOns.GetAddOnMetadata(_NAME, 'title')
local _CATEGORY
local _BACKDROP = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background";
}
-- I could use the title field in the TOC, but people tend to put color and
-- other shit there, so we'll just use the folder name:
local slashGlobal = _NAME:gsub('%s+', '_'):gsub('[^%a%d_]+', ''):upper()
slashGlobal = slashGlobal .. '_OMF'
local print_fmt = string.format('|cff33ff99%s:|r', _TITLE)
local print = function(...)
return print(print_fmt, ...)
end
local backdropPool = {}
local getPoint = function(obj, anchor)
if(not anchor) then
local UIx, UIy = UIParent:GetCenter()
local Ox, Oy = obj:GetCenter()
-- Frame doesn't really have a positon yet.
if(not Ox) then return end
local OS = obj:GetScale()
Ox, Oy = Ox * OS, Oy * OS
local UIWidth, UIHeight = UIParent:GetRight(), UIParent:GetTop()
local LEFT = UIWidth / 3
local RIGHT = UIWidth * 2 / 3
local point, x, y
if(Ox >= RIGHT) then
point = 'RIGHT'
x = obj:GetRight() - UIWidth
elseif(Ox <= LEFT) then
point = 'LEFT'
x = obj:GetLeft()
else
x = Ox - UIx
end
local BOTTOM = UIHeight / 3
local TOP = UIHeight * 2 / 3
if(Oy >= TOP) then
point = 'TOP' .. (point or '')
y = obj:GetTop() - UIHeight
elseif(Oy <= BOTTOM) then
point = 'BOTTOM' .. (point or '')
y = obj:GetBottom()
else
if(not point) then point = 'CENTER' end
y = Oy - UIy
end
return string.format(
'%s\031%s\031%d\031%d\031%.3f',
point, 'UIParent', x, y, OS
)
else
local point, parent, _, x, y = anchor:GetPoint()
return string.format(
'%s\031%s\031%d\031%d\031%.3f',
point, 'UIParent', x, y, obj:GetScale()
)
end
end
local getObjectInformation = function(obj)
-- This won't be set if we're dealing with oUF <1.3.22. Due to this we're just
-- setting it to Unknown. It will only break if the user has multiple layouts
-- spawning the same unit or change between layouts.
local style = obj.style or 'Unknown'
local identifier = obj:GetName() or obj.unit
-- Are we dealing with header units?
local isHeader
local parent = obj:GetParent()
if(parent) then
if(parent:GetAttribute'initialConfigFunction' and parent.style) then
isHeader = parent
identifier = parent:GetName()
elseif(parent:GetAttribute'oUF-onlyProcessChildren') then
isHeader = parent:GetParent()
identifier = isHeader:GetName()
end
end
return style, identifier, isHeader
end
local restoreDefaultPosition = function(style, identifier)
-- We've not saved any default position for this style.
if(not _DB.__INITIAL or not _DB.__INITIAL[style] or not _DB.__INITIAL[style][identifier]) then return end
local obj, isHeader
for _, frame in next, oUF.objects do
local fStyle, fIdentifier, fIsHeader = getObjectInformation(frame)
if(fStyle == style and fIdentifier == identifier) then
obj = frame
isHeader = fIsHeader
break
end
end
if(obj) then
local target = isHeader or obj
target:ClearAllPoints()
local point, parentName, x, y, scale = string.split('\031', _DB.__INITIAL[style][identifier])
if(not scale) then scale = 1 end
target:_SetScale(scale)
target:_SetPoint(point, parentName, point, x, y)
local backdrop = backdropPool[target]
if(backdrop) then
backdrop:ClearAllPoints()
backdrop:SetAllPoints(target)
end
-- We don't need this anymore
_DB.__INITIAL[style][identifier] = nil
if(not next(_DB.__INITIAL[style])) then
_DB[style] = nil
end
end
end
local function restorePosition(obj)
if(InCombatLockdown()) then return end
local style, identifier, isHeader = getObjectInformation(obj)
-- We've not saved any custom position for this style.
if(not _DB[style] or not _DB[style][identifier]) then return end
local target = isHeader or obj
if(not target._SetPoint) then
target._SetPoint = target.SetPoint
target.SetPoint = restorePosition
target._SetScale = target.SetScale
target.SetScale = restorePosition
end
target:ClearAllPoints()
-- damn it Blizzard, _how_ did you manage to get the input of this function
-- reversed. Any sane person would implement this as: split(str, dlm, lim);
local point, parentName, x, y, scale = string.split('\031', _DB[style][identifier])
if(not scale) then
scale = 1
end
if(scale) then
target:_SetScale(scale)
else
scale = target:GetScale()
end
target:_SetPoint(point, parentName, point, x / scale, y / scale)
end
local restoreCustomPosition = function(style, ident)
for _, obj in next, oUF.objects do
local objStyle, objIdent = getObjectInformation(obj)
if(objStyle == style and objIdent == ident) then
return restorePosition(obj)
end
end
end
local saveDefaultPosition = function(obj)
local style, identifier, isHeader = getObjectInformation(obj)
if(not _DB.__INITIAL) then
_DB.__INITIAL = {}
end
if(not _DB.__INITIAL[style]) then
_DB.__INITIAL[style] = {}
end
if(not _DB.__INITIAL[style][identifier]) then
local point
if(isHeader) then
point = getPoint(isHeader)
else
point = getPoint(obj)
end
_DB.__INITIAL[style][identifier] = point
end
end
local savePosition = function(obj, anchor)
local style, identifier, isHeader = getObjectInformation(obj)
if(not _DB[style]) then _DB[style] = {} end
_DB[style][identifier] = getPoint(isHeader or obj, anchor)
end
local saveCustomPosition = function(style, ident, point, x, y, scale)
-- Shouldn't really be the case, but you never know!
if(not _DB[style]) then _DB[style] = {} end
_DB[style][ident] = string.format(
'%s\031%s\031%d\031%d\031%.3f',
point, 'UIParent', x, y, scale
)
end
-- Attempt to figure out a more sane name to dispaly.
local smartName
do
local nameCache = {}
local validNames = {
'player',
'target',
'focus',
'raid',
'pet',
'party',
'maintank',
'mainassist',
'arena',
}
local rewrite = {
mt = 'maintank',
mtt = 'maintanktarget',
ma = 'mainassist',
mat = 'mainassisttarget',
}
local validName = function(smartName)
-- Not really a valid name, but we'll accept it for simplicities sake.
if(tonumber(smartName)) then
return smartName
end
if(type(smartName) == 'string') then
-- strip away trailing s from pets, but don't touch boss/focus.
smartName = smartName:gsub('([^us])s$', '%1')
if(rewrite[smartName]) then
return rewrite[smartName]
end
for _, v in next, validNames do
if(v == smartName) then
return smartName
end
end
if(
smartName:match'^party%d?$' or
smartName:match'^arena%d?$' or
smartName:match'^boss%d?$' or
smartName:match'^partypet%d?$' or
smartName:match'^raid%d?%d?$' or
smartName:match'%w+target$' or
smartName:match'%w+pet$'
) then
return smartName
end
end
end
local function guessName(...)
local name = validName(select(1, ...))
local n = select('#', ...)
if(n > 1) then
for i=2, n do
local inp = validName(select(i, ...))
if(inp) then
name = (name or '') .. inp
end
end
end
return name
end
local smartString = function(name)
if(nameCache[name]) then
return nameCache[name]
end
-- Here comes the substitute train!
local n = name
:gsub('ToT', 'targettarget')
:gsub('(%l)(%u)', '%1_%2')
:gsub('([%l%u])(%d)', '%1_%2_')
:gsub('Main_', 'Main')
:lower()
n = guessName(string.split('_', n))
if(n) then
nameCache[name] = n
return n
end
return name
end
smartName = function(obj, header)
if(type(obj) == 'string') then
return smartString(obj)
elseif(header) then
return smartString(header:GetName())
else
local name = obj:GetName()
if(name) then
return smartString(name)
end
return obj.unit or '<unknown>'
end
end
end
do
local frame = CreateFrame"Frame"
frame:SetScript("OnEvent", function(self, event)
return self[event](self)
end)
function frame:VARIABLES_LOADED()
-- I honestly don't trust the load order of SVs.
_DB = _G[_DBNAME] or {}
_G[_DBNAME] = _DB
-- Got to catch them all!
for _, obj in next, oUF.objects do
restorePosition(obj)
end
-- Clean up the defaults DB:
if(_DB.__INITIAL) then
for layout, frames in next, _DB.__INITIAL do
if(not _DB[layout]) then
_DB.__INITIAL[layout] = nil
else
for frame in next, frames do
if(not _DB[layout][frame]) then
_DB.__INITIAL[layout][frame] = nil
end
end
end
end
end
oUF:RegisterInitCallback(restorePosition)
self:UnregisterEvent"VARIABLES_LOADED"
end
frame:RegisterEvent"VARIABLES_LOADED"
function frame:PLAYER_REGEN_DISABLED()
if(_LOCK) then
print("Anchors hidden due to combat.")
for k, bdrop in next, backdropPool do
bdrop:Hide()
end
_LOCK = nil
end
end
frame:RegisterEvent"PLAYER_REGEN_DISABLED"
end
local getBackdrop
do
local OnShow = function(self)
return self.name:SetText(smartName(self.obj, self.header))
end
local OnHide = function(self)
if(self.dirtyMinHeight) then
self:SetAttribute('minHeight', nil)
end
if(self.dirtyMinWidth) then
self:SetAttribute('minWidth', nil)
end
end
local OnDragStart = function(self)
saveDefaultPosition(self.obj)
self:StartMoving()
local frame = self.header or self.obj
frame:ClearAllPoints();
frame:SetAllPoints(self);
end
local OnDragStop = function(self)
self:StopMovingOrSizing()
savePosition(self.obj, self)
-- Restore the initial anchoring, so the anchor follows the frame when we
-- edit positions through the UI.
restorePosition(self.obj)
self:ClearAllPoints()
self:SetAllPoints(self.header or self.obj)
end
local OnMouseDown = function(self)
local anchor = self:GetParent()
saveDefaultPosition(anchor.obj)
anchor:StartSizing('BOTTOMRIGHT')
local frame = anchor.header or anchor.obj
frame:ClearAllPoints()
frame:SetAllPoints(anchor)
self:SetButtonState("PUSHED", true)
end
local OnMouseUp = function(self)
local anchor = self:GetParent()
self:SetButtonState("NORMAL", false)
anchor:StopMovingOrSizing()
savePosition(anchor.obj, anchor)
end
local OnSizeChanged = function(self, width, height)
local baseWidth, baseHeight = self.baseWidth, self.baseHeight
local scale = width / baseWidth
-- This is damn tiny!
if(scale <= .3) then
scale = .3
end
self:SetSize(scale * baseWidth, scale * baseHeight)
local target = self. target;
(target._SetScale or target.SetScale) (target, scale)
end
getBackdrop = function(obj, isHeader)
local target = isHeader or obj
if(not target:GetCenter()) then return end
if(backdropPool[target]) then return backdropPool[target] end
local backdrop = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
backdrop:Hide()
backdrop:SetBackdrop(_BACKDROP)
backdrop:SetFrameStrata"TOOLTIP"
backdrop:SetAllPoints(target)
backdrop:EnableMouse(true)
backdrop:SetMovable(true)
backdrop:SetResizable(true)
backdrop:RegisterForDrag"LeftButton"
local name = backdrop:CreateFontString(nil, "OVERLAY", "GameFontNormal")
name:SetPoint"CENTER"
name:SetJustifyH"CENTER"
name:SetFont(GameFontNormal:GetFont(), 12)
name:SetTextColor(1, 1, 1)
local scale = CreateFrame('Button', nil, backdrop)
scale:SetPoint'BOTTOMRIGHT'
scale:SetSize(16, 16)
scale:SetNormalTexture[[Interface\ChatFrame\UI-ChatIM-SizeGrabber-Up]]
scale:SetHighlightTexture[[Interface\ChatFrame\UI-ChatIM-SizeGrabber-Highlight]]
scale:SetPushedTexture[[Interface\ChatFrame\UI-ChatIM-SizeGrabber-Down]]
scale:SetScript('OnMouseDown', OnMouseDown)
scale:SetScript('OnMouseUp', OnMouseUp)
backdrop.name = name
backdrop.obj = obj
backdrop.header = isHeader
backdrop.target = target
backdrop:SetBackdropBorderColor(0, .9, 0)
backdrop:SetBackdropColor(0, .9, 0)
backdrop.baseWidth, backdrop.baseHeight = obj:GetSize()
-- We have to define a minHeight on the header if it doesn't have one. The
-- reason for this is that the header frame will have an height of 0.1 when
-- it doesn't have any frames visible.
if(
isHeader and
(
not isHeader:GetAttribute'minHeight' and math.floor(isHeader:GetHeight()) == 0 or
not isHeader:GetAttribute'minWidth' and math.floor(isHeader:GetWidth()) == 0
)
) then
isHeader:SetHeight(obj:GetHeight())
isHeader:SetWidth(obj:GetWidth())
if(not isHeader:GetAttribute'minHeight') then
isHeader.dirtyMinHeight = true
isHeader:SetAttribute('minHeight', obj:GetHeight())
end
if(not isHeader:GetAttribute'minWidth') then
isHeader.dirtyMinWidth = true
isHeader:SetAttribute('minWidth', obj:GetWidth())
end
elseif(isHeader) then
backdrop.baseWidth, backdrop.baseHeight = isHeader:GetSize()
end
backdrop:SetScript("OnShow", OnShow)
backdrop:SetScript('OnHide', OnHide)
backdrop:SetScript("OnDragStart", OnDragStart)
backdrop:SetScript("OnDragStop", OnDragStop)
backdrop:SetScript('OnSizeChanged', OnSizeChanged)
backdropPool[target] = backdrop
return backdrop
end
end
do
local opt = CreateFrame("Frame")
opt:Hide()
opt.name = _TITLE
opt:SetScript("OnShow", function(self)
local title = self:CreateFontString(nil, 'ARTWORK', 'GameFontNormalLarge')
title:SetPoint('TOPLEFT', 16, -16)
title:SetText(_TITLE)
local subtitle = self:CreateFontString(nil, 'ARTWORK', 'GameFontHighlightSmall')
subtitle:SetHeight(40)
subtitle:SetPoint('TOPLEFT', title, 'BOTTOMLEFT', 0, -8)
subtitle:SetPoint('RIGHT', self, -32, 0)
subtitle:SetNonSpaceWrap(true)
subtitle:SetWordWrap(true)
subtitle:SetJustifyH'LEFT'
subtitle:SetFormattedText('Type %s to toggle frame anchors.', _G['SLASH_' .. slashGlobal .. 1])
local scroll = CreateFrame('ScrollFrame', nil, self, 'UIPanelScrollFrameTemplate')
scroll:SetPoint('TOPLEFT', subtitle, 'BOTTOMLEFT', 0, -8)
scroll:SetPoint("BOTTOMRIGHT", -27, 4)
local scrollchild = CreateFrame("Frame", nil, self)
scrollchild:SetHeight(1)
scrollchild:SetWidth(self:GetWidth() - 18)
scroll:SetScrollChild(scrollchild)
scroll:UpdateScrollChildRect()
scroll:EnableMouseWheel(true)
local backdrop = {
bgFile = [[Interface\ChatFrame\ChatFrameBackground]], tile = true, tileSize = 16,
edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]], edgeSize = 16,
insets = {left = 4, right = 4, top = 4, bottom = 4},
}
local createOrUpdateMadnessOfGodIhateGUIs
local OnClick = function(self)
local row = self:GetParent()
_DB[row.style][row.ident] = nil
if(not next(_DB[row.style])) then
_DB[row.style] = nil
end
restoreDefaultPosition(row.style, row.ident)
return createOrUpdateMadnessOfGodIhateGUIs()
end
local OnEnter = function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip:SetText(DELETE)
end
local handleInput = function(label)
local text = label:GetText()
if(text == '-' or text == '' or text == '.') then
text = 0
end
local num = tonumber(text)
if(label.hasPostfix and not num) then
num = tonumber(text:sub(1,-2))
end
if(label.onlyAboveZero) then
if(not (num > 0)) then
return .01
else
return num
end
end
return num or text
end
local saveRestorePosition = function(row)
saveCustomPosition(
row.style,
row.ident,
handleInput(row.pointLabel),
handleInput(row.xLabel),
handleInput(row.yLabel),
handleInput(row.scaleLabel)
)
restoreCustomPosition(row.style, row.ident)
end
local createEditBox
do
local OnEscapePressed = function(self)
self:SetText(self.oldText)
self:ClearFocus()
saveRestorePosition(self:GetParent())
end
local OnEnterPressed = function(self)
local text = self:GetText()
self:ClearFocus()
saveRestorePosition(self:GetParent())
end
local OnEditFocusGained = function(self)
self.oldText = self:GetText()
if(self.hasPostfix) then
self.oldText = self.oldText:sub(1, -2)
end
self:SetText(self.oldText)
self.newText = nil
end
local OnEditFocusLost = function(self)
local text = self:GetText()
if(text == '-' or text == '' or text == '.') then
if(self.onlyAboveZero) then
text = 0.01
else
text = 0
end
end
self:SetText(string.format(self.numFormat, text))
self.newText = nil
self.oldText = nil
end
local OnTextChanged = function(self, userInput)
if(userInput) then
self.newText = self:GetText()
saveRestorePosition(self:GetParent())
end
end
local OnChar = function(self, key)
local text = self:GetText()
if(
not tonumber(text .. '0') or
(not tonumber(key) and key ~= '-' and key ~= '.') or
(self.onlyAboveZero and key == '-' and not (self:GetNumber() < 0))
) then
local pos = self:GetCursorPosition() - 1
self:SetText(self.newText or self.oldText)
self:SetCursorPosition(pos)
end
self.newText = self:GetText()
end
createEditBox = function(self)
local editbox = CreateFrame('EditBox', nil, self)
editbox:SetWidth(40)
editbox:SetMaxLetters(5)
editbox:SetAutoFocus(false)
editbox:SetFontObject(GameFontHighlight)
editbox:SetPoint('TOP')
editbox:SetPoint('BOTTOM')
editbox:SetScript('OnEscapePressed', OnEscapePressed)
editbox:SetScript('OnEnterPressed', OnEnterPressed)
editbox:SetScript('OnEditFocusGained', OnEditFocusGained)
editbox:SetScript('OnEditFocusLost', OnEditFocusLost)
editbox:SetScript('OnTextChanged', OnTextChanged)
editbox:SetScript('OnChar', OnChar)
return editbox
end
end
function createOrUpdateMadnessOfGodIhateGUIs()
local data = self.data or {}
local slideHeight = 0
local numStyles = 1
for style, styleData in next, _DB do
if(style ~= '__INITIAL') then
if(not data[numStyles]) then
local box = CreateFrame('Frame', nil, scrollchild, "BackdropTemplate")
box:SetBackdrop(backdrop)
box:SetBackdropColor(.1, .1, .1, .5)
box:SetBackdropBorderColor(.3, .3, .3, 1)
if(numStyles == 1) then
box:SetPoint('TOP', 0, -12)
else
box:SetPoint('TOP', data[numStyles - 1], 'BOTTOM', 0, -16)
end
box:SetPoint'LEFT'
box:SetPoint('RIGHT', scroll, 0, 0)
local title = box:CreateFontString(nil, 'ARTWORK', 'GameFontHighlight')
title:SetPoint('BOTTOMLEFT', box, 'TOPLEFT', 8, 0)
box.title = title
if(numStyles == 1) then
local scaleTitle = box:CreateFontString(nil, nil, 'GameFontHighlight')
scaleTitle:SetPoint('BOTTOMRIGHT', box, 'TOPRIGHT', -35, 0)
scaleTitle:SetWidth(40)
scaleTitle:SetText'Scale'
scaleTitle:SetJustifyH'CENTER'
box.scaleTitle = scaleTitle
local yTitle = box:CreateFontString(nil, nil, 'GameFontHighlight')
yTitle:SetPoint('RIGHT', scaleTitle, 'LEFT', -5, 0)
yTitle:SetWidth(40)
yTitle:SetText'Y'
yTitle:SetJustifyH'CENTER'
box.yTitle = yTitle
local xTitle = box:CreateFontString(nil, nil, 'GameFontHighlight')
xTitle:SetPoint('RIGHT', yTitle, 'LEFT', -5, 0)
xTitle:SetWidth(40)
xTitle:SetText'X'
xTitle:SetJustifyH'CENTER'
box.xTitle = xTitle
end
data[numStyles] = box
end
-- Fetch the box and update it
local box = data[numStyles]
box.title:SetText(style)
local rows = box.rows or {}
local numFrames = 1
for unit, points in next, styleData do
if(not rows[numFrames]) then
local row = CreateFrame('Button', nil, box, "BackdropTemplate")
row:SetBackdrop(backdrop)
row:SetBackdropBorderColor(.3, .3, .3)
row:SetBackdropColor(.1, .1, .1, .5)
if(numFrames == 1) then
row:SetPoint('TOP', 0, -8)
else
row:SetPoint('TOP', rows[numFrames-1], 'BOTTOM')
end
row:SetPoint('LEFT', 6, 0)
row:SetPoint('RIGHT', -25, 0)
row:SetHeight(24)
-- Notice how these are anchored right to left. Initially when I
-- implemented these, I swapped X and Y positioning. It was really
-- fun to debug!
local scaleLabel = createEditBox(row)
scaleLabel:SetPoint('RIGHT', -10, 0)
scaleLabel:SetJustifyH'CENTER'
scaleLabel.hasPostfix = true
scaleLabel.onlyAboveZero = true
scaleLabel.numFormat = '%.2fx'
row.scaleLabel = scaleLabel
local yLabel = createEditBox(row)
yLabel:SetPoint('RIGHT', scaleLabel, 'LEFT', -5, 0)
yLabel:SetJustifyH'CENTER'
yLabel.numFormat = '%d'
row.yLabel = yLabel
local xLabel = createEditBox(row)
xLabel:SetPoint('RIGHT', yLabel, 'LEFT', -5, 0)
xLabel:SetJustifyH'CENTER'
xLabel.numFormat = '%d'
row.xLabel = xLabel
local pointLabel = row:CreateFontString(nil, nil, 'GameFontHighlight')
pointLabel:SetPoint('RIGHT', xLabel, 'LEFT', -5, 0)
pointLabel:SetJustifyH'CENTER'
pointLabel:SetText'BOTTOMRIGHT'
pointLabel:SetWidth(pointLabel:GetWidth())
row.pointLabel = pointLabel
local unitLabel= row:CreateFontString(nil, nil, 'GameFontHighlight')
unitLabel:SetPoint('LEFT', 10, 0)
unitLabel:SetJustifyH'LEFT'
row.unitLabel = unitLabel
local delete = CreateFrame("Button", nil, row)
delete:SetWidth(16)
delete:SetHeight(16)
delete:SetPoint('LEFT', row, 'RIGHT')
delete:SetNormalTexture[[Interface\Buttons\UI-Panel-MinimizeButton-Up]]
delete:SetPushedTexture[[Interface\Buttons\UI-Panel-MinimizeButton-Down]]
delete:SetHighlightTexture[[Interface\Buttons\UI-Panel-MinimizeButton-Highlight]]
delete:SetScript("OnClick", OnClick)
delete:SetScript("OnEnter", OnEnter)
delete:SetScript("OnLeave", GameTooltip_Hide)
row.delete = delete
rows[numFrames] = row
end
-- Fetch row and update it:
local row = rows[numFrames]
local point, _, x, y, s = string.split('\031', points)
row.scaleLabel:SetText(string.format('%.2fx', s or 1))
row.xLabel:SetText(x)
row.yLabel:SetText(y)
row.pointLabel:SetText(point)
row.unitLabel:SetText(smartName(unit))
row.style = style
row.ident = unit
row:Show()
numFrames = numFrames + 1
end
box.rows = rows
local height = (numFrames * 24) - 8
slideHeight = slideHeight + height + 16
box:SetHeight(height)
box:Show()
-- Hide left over rows we aren't using:
while(rows[numFrames]) do
rows[numFrames]:Hide()
numFrames = numFrames + 1
end
numStyles = numStyles + 1
end
end
-- Hide left over boxes we aren't using:
while(data[numStyles]) do
data[numStyles]:Hide()
numStyles = numStyles + 1
end
self.data = data
end
opt:SetScript("OnShow", function()
return createOrUpdateMadnessOfGodIhateGUIs()
end)
return createOrUpdateMadnessOfGodIhateGUIs()
end)
_CATEGORY = Settings.RegisterCanvasLayoutCategory(opt, _TITLE)
Settings.RegisterAddOnCategory(_CATEGORY)
end
local slashList = C_AddOns.GetAddOnMetadata(_NAME, 'X-SlashCmdList'):gsub('%s+', '')
local handleCmds = function(...)
for i=1, select('#', ...) do
local cmd = select(i, ...)
_G['SLASH_' ..slashGlobal .. i] = cmd
end
end
handleCmds(string.split(',', slashList))
SlashCmdList[slashGlobal] = function(inp)
if(InCombatLockdown()) then
return print"Frames cannot be moved while in combat. Bailing out."
end
if(inp:match("%S+")) then
Settings.OpenToCategory(_CATEGORY:GetID())
else
if(not _LOCK) then
for k, obj in next, oUF.objects do
if(not obj.disableMovement and not obj.isNamePlate) then
local style, identifier, isHeader = getObjectInformation(obj)
local backdrop = getBackdrop(obj, isHeader)
if(backdrop) then backdrop:Show() end
end
end
_LOCK = true
else
for k, bdrop in next, backdropPool do
bdrop:Hide()
end
_LOCK = nil
end
end
end
-- It's not in your best interest to disconnect me. Someone could get hurt.