-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovable.lua
493 lines (397 loc) · 13.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
local ADDON_NAME, ns = ...
local oUF = ns.oUF or oUF
assert(oUF, "oUF_Freebgrid was unable to locate oUF install.")
-- This is a stripped and modified oUF MovableFrames to fit my needs.
-- freebaser
local _DB
local round = function(n)
return math.floor(n * 1e5 + .5) / 1e5
end
local getPoint = function(obj)
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 UIS = UIParent:GetEffectiveScale()
local OS = obj:GetEffectiveScale()
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',
point, 'UIParent', round(x * UIS / OS), round(y * UIS / OS)
)
end
local saveDefaultPosition = function(anchor)
local style, identifier = "Freebgrid", anchor:GetName()
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
_DB.__INITIAL[style][identifier] = getPoint(anchor)
end
end
local savePosition = function(anchor)
local style, identifier = "Freebgrid", anchor:GetName()
if(not _DB[style]) then _DB[style] = {} end
_DB[style][identifier] = getPoint(anchor)
end
local setframe
do
local OnDragStart = function(self)
saveDefaultPosition(self)
self:StartMoving()
self:ClearAllPoints()
end
local OnDragStop = function(self)
self:StopMovingOrSizing()
savePosition(self)
end
setframe = function(frame)
frame:SetHeight(ns.db.height)
frame:SetWidth(ns.db.width)
frame:SetFrameStrata"TOOLTIP"
frame:SetBackdrop({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background";})
frame:EnableMouse(true)
frame:SetMovable(true)
frame:SetClampedToScreen(true)
frame:RegisterForDrag"LeftButton"
frame:SetBackdropBorderColor(0, .9, 0)
frame:SetBackdropColor(0, .9, 0)
frame:Hide()
frame:SetScript("OnDragStart", OnDragStart)
frame:SetScript("OnDragStop", OnDragStop)
frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
frame.name:SetPoint"CENTER"
frame.name:SetJustifyH"CENTER"
frame.name:SetFont(GameFontNormal:GetFont(), 12)
frame.name:SetTextColor(1, 1, 1)
return frame
end
end
local anchorpool = {}
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 anchor
for _, frame in next, anchorpool do
if frame:GetName() == identifier then
anchor = frame
end
end
if not anchor then return end
local scale = anchor:GetScale()
local SetPoint = getmetatable(anchor).__index.SetPoint;
(anchor):ClearAllPoints();
local point, parentName, x, y = string.split('\031', _DB.__INITIAL[style][identifier])
SetPoint(anchor, point, parentName, point, x / scale, y / scale)
-- We don't need this anymore
_DB.__INITIAL[style][identifier] = nil
if(not next(_DB.__INITIAL[style])) then
_DB[style] = nil
end
end
local function restorePosition(anchor)
local style, identifier = "Freebgrid", anchor:GetName()
-- We've not saved any custom position for this style.
if(not _DB[style] or not _DB[style][identifier]) then return end
local scale = anchor:GetScale()
local SetPoint = getmetatable(anchor).__index.SetPoint;
-- Hah, a spot you have to use semi-colon!
-- Guess I've never experienced that as these are usually wrapped in do end
-- statements.
(anchor).SetPoint = restorePosition;
(anchor):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 = string.split('\031', _DB[style][identifier])
SetPoint(anchor, point, parentName, point, x / scale, y / scale)
end
function ns:Anchors()
local raidframe = CreateFrame("Frame", "oUF_FreebgridRaidFrame", UIParent)
setframe(raidframe)
raidframe.ident = "Raid"
raidframe.name:SetText("Raid")
raidframe:SetPoint("LEFT", UIParent, "LEFT", 8, 0)
anchorpool["oUF_FreebgridRaidFrame"] = raidframe
local petframe = CreateFrame("Frame", "oUF_FreebgridPetFrame", UIParent)
setframe(petframe)
petframe.ident = "Pet"
petframe.name:SetText("Pet")
petframe:SetPoint("LEFT", UIParent, "LEFT", 250, 0)
anchorpool["oUF_FreebgridPetFrame"] = petframe
local mtframe = CreateFrame("Frame", "oUF_FreebgridMTFrame", UIParent)
setframe(mtframe)
mtframe.ident = "MT"
mtframe.name:SetText("MT")
mtframe:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 8, -60)
anchorpool["oUF_FreebgridMTFrame"] = mtframe
for _, frame in next, anchorpool do
restorePosition(frame)
end
end
do
local frame = CreateFrame"Frame"
frame:RegisterEvent"ADDON_LOADED"
frame:SetScript("OnEvent", function(self, event, addon)
if addon ~= ADDON_NAME then return end
if ns.db and ns.db.omfChar then
_DB = Freebgridomf2Char or {}
Freebgridomf2Char = _DB
else
_DB = Freebgridomf2 or {}
Freebgridomf2 = _DB
end
self:UnregisterEvent"ADDON_LOADED"
end)
end
do
local opt = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer)
opt:Hide()
opt.parent = ADDON_NAME
opt.name = "oUF: MovableFrames"
opt:SetScript("OnShow", function(self)
local title = self:CreateFontString(nil, 'ARTWORK', 'GameFontNormalLarge')
title:SetPoint('TOPLEFT', 16, -16)
title:SetText'oUF: MovableFrames'
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:SetText('Type /freeb to toggle frame anchors.')
local scroll = CreateFrame("ScrollFrame", nil, self)
scroll:SetPoint('TOPLEFT', subtitle, 'BOTTOMLEFT', 0, -8)
scroll:SetPoint("BOTTOMRIGHT", 0, 4)
local scrollchild = CreateFrame("Frame", nil, self)
scrollchild:SetPoint"LEFT"
scrollchild:SetHeight(scroll:GetHeight())
scrollchild:SetWidth(scroll:GetWidth())
scroll:SetScrollChild(scrollchild)
scroll:UpdateScrollChildRect()
scroll:EnableMouseWheel(true)
local slider = CreateFrame("Slider", nil, scroll)
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)
scroll.value = slider:GetValue()
_DB[self.style][self.ident] = nil
if(not next(_DB[self.style])) then
_DB[self.style] = nil
end
restoreDefaultPosition(self.style, self.ident)
return createOrUpdateMadnessOfGodIhateGUIs()
end
local OnEnter = function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip:SetText(DELETE)
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)
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', -30, 0)
local title = box:CreateFontString(nil, 'ARTWORK', 'GameFontHighlightSmall')
title:SetPoint('BOTTOMLEFT', box, 'TOPLEFT', 8, 0)
box.title = title
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)
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)
local anchor = row:CreateFontString(nil, nil, 'GameFontHighlight')
anchor:SetPoint('RIGHT', -10, 0)
anchor:SetPoint('TOP', 0, -4)
anchor:SetPoint'BOTTOM'
anchor:SetJustifyH'RIGHT'
row.anchor = anchor
local label = row:CreateFontString(nil, nil, 'GameFontHighlight')
label:SetPoint('LEFT', 10, 0)
label:SetPoint('RIGHT', anchor)
label:SetPoint('TOP', 0, -4)
label:SetPoint'BOTTOM'
label:SetJustifyH'LEFT'
row.label = label
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 = string.split('\031', points)
row.anchor:SetFormattedText('%11s %4s %4s', point, x, y)
row.label:SetText(anchorpool[unit].ident)
row.delete.style = style
row.delete.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
local height = slideHeight - scroll:GetHeight()
if(height > 0) then
slider:SetMinMaxValues(0, height)
else
slider:SetMinMaxValues(0, 0)
end
slider:SetValue(scroll.value or 0)
end
slider:SetWidth(16)
slider:SetPoint("TOPRIGHT", -8, -24)
slider:SetPoint("BOTTOMRIGHT", -8, 24)
local up = CreateFrame("Button", nil, slider)
up:SetPoint("BOTTOM", slider, "TOP")
up:SetWidth(16)
up:SetHeight(16)
up:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Up")
up:SetPushedTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Down")
up:SetDisabledTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Disabled")
up:SetHighlightTexture("Interface\\Buttons\\UI-ScrollBar-ScrollUpButton-Highlight")
up:GetNormalTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetPushedTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetDisabledTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetHighlightTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
up:GetHighlightTexture():SetBlendMode("ADD")
up:SetScript("OnClick", function(self)
local box = self:GetParent()
box:SetValue(box:GetValue() - box:GetHeight()/2)
end)
local down = CreateFrame("Button", nil, slider)
down:SetPoint("TOP", slider, "BOTTOM")
down:SetWidth(16)
down:SetHeight(16)
down:SetNormalTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up")
down:SetPushedTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Down")
down:SetDisabledTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Disabled")
down:SetHighlightTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Highlight")
down:GetNormalTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetPushedTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetDisabledTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetHighlightTexture():SetTexCoord(1/4, 3/4, 1/4, 3/4)
down:GetHighlightTexture():SetBlendMode("ADD")
down:SetScript("OnClick", function(self)
local box = self:GetParent()
box:SetValue(box:GetValue() + box:GetHeight()/2)
end)
slider:SetThumbTexture("Interface\\Buttons\\UI-ScrollBar-Knob")
local thumb = slider:GetThumbTexture()
thumb:SetWidth(16)
thumb:SetHeight(24)
thumb:SetTexCoord(1/4, 3/4, 1/8, 7/8)
slider:SetScript("OnValueChanged", function(self, val, ...)
local min, max = self:GetMinMaxValues()
if(val == min) then up:Disable() else up:Enable() end
if(val == max) then down:Disable() else down:Enable() end
scroll.value = val
scroll:SetVerticalScroll(val)
scrollchild:SetPoint('TOP', 0, val)
end)
opt:SetScript("OnShow", function()
return createOrUpdateMadnessOfGodIhateGUIs()
end)
return createOrUpdateMadnessOfGodIhateGUIs()
end)
ns.movableopt = opt
end
local _LOCK
function ns:Movable()
if(InCombatLockdown()) then return end
if(not _LOCK) then
for k, frame in next, anchorpool do
frame:Show()
end
_LOCK = true
else
for k, frame in next, anchorpool do
frame:Hide()
end
_LOCK = nil
end
end
Freebgrid_NS = ns