-
Notifications
You must be signed in to change notification settings - Fork 4
/
Utilities.lua
661 lines (607 loc) · 20.4 KB
/
Utilities.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
local RUF = RUF or LibStub('AceAddon-3.0'):GetAddon('RUF')
local LSM = LibStub('LibSharedMedia-3.0')
local _, ns = ...
local oUF = ns.oUF
function RUF:Print_Self(message) -- Send a message to your default chat window.
ChatFrame1:AddMessage("|c5500DBBDRaeli's Unit Frames|r: " .. format(message))
end
function RUF:PopUp(name, message, button1value, button2value, acceptfunc)
StaticPopupDialogs[name] = {
text = message,
button1 = button1value,
button2 = button2value,
OnAccept = acceptfunc, --function()
--GreetTheWorld()
--ReloadUI()
--end,
timeout = 0,
whileDead = true,
hideOnEscape = false,
showAlert = true,
preferredIndex = 3, -- avoid some UI taint, see http://www.wowace.com/announcements/how-to-avoid-some-ui-taint/
}
end
function RUF:IconTextureTrim(trim, w, h)
local left, right, top, bottom = 0, 1, 0, 1 -- default without trim
if trim then left = 0.05; right = 0.95; top = 0.05; bottom = 0.95 end
if w > h then -- rectangular with width greater than height
local crop = (bottom - top) * (w - h)/ w / 2 -- aspect ratio to reduce height by
top = top + crop; bottom = bottom - crop
elseif h > w then -- rectangular with height greater than width
local crop = (right - left) * (h - w)/ h / 2 -- aspect ratio to reduce height by
left = left + crop; right = right - crop
end
return left, right, top, bottom
end
function RUF:copyTable(src, dest)
if type(dest) ~= 'table' then dest = {} end
if type(src) == 'table' then
for k, v in pairs(src) do
if type(v) == 'table' then
-- try to index the key first so that the metatable creates the defaults, if set, and use that table
v = RUF:copyTable(v, dest[k])
end
--if dest[k] then
--else
dest[k] = v
--end
end
end
return dest
end
function RUF:Short(value, format)
if type(value) == 'number' then
local fmt
local gsub
if value >= 1000000000 or value <= -1000000000 then
fmt = '%.1fB'
value = value / 1000000000
elseif value >= 10000000 or value <= -10000000 then
fmt = '%.1fM'
value = value / 1000000
elseif value >= 1000000 or value <= -1000000 then
fmt = '%.2fM'
value = value / 1000000
elseif value >= 100000 or value <= -100000 then
fmt = '%.0fK'
value = value / 1000
elseif value >= 10000 or value <= -10000 then
fmt = '%.1fK'
value = value / 1000
elseif value >= 1000 or value <= -1000 then
gsub = string.gsub(value, '^(-?%d+)(%d%d%d)', '%1,%2')
else
fmt = '%d'
value = math.floor(value + 0.5)
end
if format then
if gsub then
return gsub
else
return fmt:format(value)
end
end
return fmt, value
else
local fmt_a, fmt_b
local a, b = value:match('^(%d+)/(%d+)$')
if a then
a, b = tonumber(a), tonumber(b)
if a >= 1000000000 or a <= -1000000000 then
fmt_a = '%.1fB'
a = a / 1000000000
elseif a >= 10000000 or a <= -10000000 then
fmt_a = '%.1fM'
a = a / 1000000
elseif a >= 1000000 or a <= -1000000 then
fmt_a = '%.2fM'
a = a / 1000000
elseif a >= 100000 or a <= -100000 then
fmt_a = '%.0fK'
a = a / 1000
elseif a >= 10000 or a <= -10000 then
fmt_a = '%.1fK'
a = a / 1000
elseif a >= 1000 or a <= -1000 then
fmt_a = '%s'
a = string.gsub(a, '^(-?%d+)(%d%d%d)', '%1,%2')
end
if b >= 1000000000 or b <= -1000000000 then
fmt_b = '%.1fB'
b = b / 1000000000
elseif b >= 10000000 or b <= -10000000 then
fmt_b = '%.1fM'
b = b / 1000000
elseif b >= 1000000 or b <= -1000000 then
fmt_b = '%.2fM'
b = b / 1000000
elseif b >= 100000 or b <= -100000 then
fmt_b = '%.0fK'
b = b / 1000
elseif b >= 10000 or b <= -10000 then
fmt_b = '%.1fK'
b = b / 1000
elseif b >= 1000 or b <= -1000 then
fmt_b = '%s'
b = string.gsub(b, '^(-?%d+)(%d%d%d)', '%1,%2')
end
local fmt = ('%s/%s'):format(fmt_a, fmt_b)
if format then
return fmt:format(a, b)
end
return fmt, a, b
else
return value
end
end
end
function RUF:Round(number, digits)
local mantissa = 10^(digits or 0)
local norm = number * mantissa + 0.5
local norm_floor = math.floor(norm)
if norm == norm_floor and (norm_floor % 2) == 1 then
return (norm_floor - 1) / mantissa
end
return norm_floor / mantissa
end
function RUF:Percent(x, y)
if y ~= 0 then
return Round(x / y * 100, 1)
end
return 0
end
function RUF:ColorsAndPercent(a, b, ...)
if(a <= 0 or b == 0) then
return nil, ...
elseif(a >= b) then
return nil, select(select('#', ...) - 2, ...)
end
local num = select('#', ...) / 3
local segment, relperc = math.modf((a / b) * (num - 1))
return relperc, select((segment * 3) + 1, ...)
end
function RUF:ColorGradient(...)
local relperc, r1, g1, b1, r2, g2, b2 = RUF:ColorsAndPercent(...)
if(relperc) then
return r1 + (r2 - r1) * relperc, g1 + (g2 - g1) * relperc, b1 + (b2 - b1) * relperc
else
return r1, g1, b1
end
end
function RUF:HSLtoRGB(h, s, l)
if s == 0 then return l, l, l end
local function to(p, q, t)
if t < 0 then t = t + 1 end
if t > 1 then t = t - 1 end
if t < .16667 then return p + (q - p) * 6 * t end
if t < .5 then return q end
if t < .66667 then return p + (q - p) * (.66667 - t) * 6 end
return p
end
local q = l < .5 and l * (1 + s) or l + s - l * s
local p = 2 * l - q
return to(p, q, h + .33334), to(p, q, h), to(p, q, h - .33334)
end
function RUF:RGBtoHSL(r, g, b)
local max, min = math.max(r, g, b), math.min(r, g, b)
local t = max + min
local d = max - min
local h, s, l
if t == 0 then return 0, 0, 0 end
l = t / 2
s = l > .5 and d / (2 - t) or d / t
if max == r then
h = (g - b) / d + (g < b and 6 or 0)
elseif max == g then
h = (b - r) / d + 2
elseif max == b then
h = (r - g) / d + 4
end
h = h * 0.16667
return h, s, l
end
local firstH, firstS, firstL = RUF:RGBtoHSL(255/255, 151/255, 3/255)
local secondH, secondS, secondL = RUF:RGBtoHSL(RUF:HSLtoRGB( ((firstH * 360) + 67) / 360, firstS, firstL))
function RUF:UpdateRainbow()
firstH = firstH + (1/360)
secondH = secondH + (1/360)
if firstH > 1 then
firstH = 1/360
end
if secondH > 1 then
secondH = 1/360
end
end
function RUF:GetRainbow()
local a,b,c = RUF:HSLtoRGB(firstH, firstS, firstL)
local x,y,z = RUF:HSLtoRGB(secondH, secondS, secondL)
return a,b,c,x,y,z
end
local function AlphaAnimationDataUpdate(self)
local parent = self:GetParent()
self:GetParent().Alpha.current = parent:GetAlpha()
end
function RUF.AnimateAlpha(self, to, duration)
self.Alpha.current = self:GetAlpha()
self.Alpha.target = to or 1
if not self.Animator then
local animationGroup = self:CreateAnimationGroup()
self.Animator = animationGroup
local animation = animationGroup:CreateAnimation('Alpha')
self.Animator.animation = animation
end
local animationGroup = self.Animator
local animation = self.Animator.animation
if animationGroup:IsPlaying() then animationGroup:Stop() end
animation:SetFromAlpha(self.Alpha.current)
animation:SetToAlpha(self.Alpha.target)
animation:SetDuration(duration)
animationGroup:Play()
animationGroup:SetToFinalAlpha(true)
animationGroup:SetScript('OnUpdate', AlphaAnimationDataUpdate)
end
function RUF:FrameIsDependentOnFrame(frame, otherFrame)
if (frame and otherFrame) then
if frame == otherFrame then
return true
end
local points = frame:GetNumPoints()
for i = 1, points do
local point, parent, relative, x, y = frame:GetPoint(i)
if RUF:FrameIsDependentOnFrame(parent, otherFrame) then
return true
end
end
end
end
function RUF:CanAttach(frame, otherFrame)
if not(frame and otherFrame) then
return
elseif frame:GetNumPoints() == 0 or otherFrame:GetNumPoints() == 0 then
return
elseif frame:GetWidth() == 0 or frame:GetHeight() == 0 or otherFrame:GetWidth() == 0 or otherFrame:GetHeight() == 0 then
return
elseif RUF:FrameIsDependentOnFrame(otherFrame, frame) then
return
end
return true
end
function RUF.GetIndicatorAnchorFrame(self, unit, indicator)
-- TODO: Anchor to element (health, power)
local AnchorFrame = 'Frame'
if RUF.db.profile.unit[unit].Frame.Indicators[indicator].Position.AnchorFrame == 'Frame' then
AnchorFrame = self:GetName()
else
AnchorFrame = self:GetName() .. '.' .. RUF.db.profile.unit[unit].Frame.Indicators[indicator].Position.AnchorFrame .. 'Indicator'
if not _G[AnchorFrame] then
AnchorFrame = self:GetName()
end
end
return AnchorFrame
end
function RUF.GetLevelColor(self, level, unit)
if level <= 0 then level = 500 end
local color = GetQuestDifficultyColor(level)
local index = 4
if color.font == 'QuestDifficulty_Impossible' then
index = 0
elseif color.font == 'QuestDifficulty_VeryDifficult' then
index = 1
elseif color.font == 'QuestDifficulty_Difficult' then
index = 2
elseif color.font == 'QuestDifficulty_Standard' then
index = 3
elseif color.font == 'QuestDifficulty_Trivial' then
index = 4
end
if RUF.IsRetail() and unit then
if UnitIsWildBattlePet(unit) or UnitIsBattlePetCompanion(unit) then
local petLevel = UnitBattlePetLevel(unit)
if petLevel < 9 then
index = 4
elseif petLevel < 17 then
index = 3
elseif petLevel < 21 then
index = 2
elseif petLevel < 24 then
index = 1
else
index = 0
end
end
end
local r, g, b = unpack(RUF.db.profile.Appearance.Colors.DifficultyColors[index])
return r, g, b
end
function RUF.ReturnTextColors(self, unit, tag, cur, max, test) -- Get Text Colors
local r, g, b = unpack(RUF.db.profile.Appearance.Text[tag].Color.BaseColor)
local _, class = UnitClass(unit)
if not class then class = 'PRIEST' end
if not cur then
cur = UnitHealth(unit)
end
if not max then
max = UnitHealthMax(unit)
end
if RUF.db.profile.Appearance.Text[tag].Color.Percentage and RUF.db.profile.Appearance.Text[tag].Color.PercentageAtMax and cur == max then -- If we want to show gradient colors at max health, and we're at max health.
r, g, b = RUF:ColorGradient(cur, max, unpack(RUF.db.profile.Appearance.Text[tag].Color.PercentageGradient))
elseif RUF.db.profile.Appearance.Text[tag].Color.Percentage and cur < max and cur > 0 then -- If we want to show gradient colors and we're not at max health.
r, g, b = RUF:ColorGradient(cur, max, unpack(RUF.db.profile.Appearance.Text[tag].Color.PercentageGradient))
elseif RUF.db.profile.Appearance.Text[tag].Color.Class and UnitIsPlayer(unit) then -- If we want to show class colors.
r, g, b = unpack(RUF.db.profile.Appearance.Colors.ClassColors[class])
elseif RUF.db.profile.Appearance.Text[tag].Color.Reaction then -- If we want to show unit reaction colors
if UnitPlayerControlled(unit) and not UnitCanAttack(unit, 'player') and not UnitIsPlayer(unit) then -- If the unit is an allied pet then show as blue.
r, g, b = unpack(RUF.db.profile.Appearance.Colors.ReactionColors[10])
elseif UnitReaction(unit, 'player') then -- If the unit is an offline party member, possibly others too?
r, g, b = unpack(RUF.db.profile.Appearance.Colors.ReactionColors[UnitReaction(unit, 'player')])
elseif UnitInParty(unit) then
r, g, b = unpack(RUF.db.profile.Appearance.Colors.ReactionColors[5]) -- So Reaction Works when Party member is in a different zone and UnitReaction returns nil
else
r, g, b = unpack(RUF.db.profile.Appearance.Text[tag].Color.BaseColor)
end
elseif RUF.db.profile.Appearance.Text[tag].Color.Level then
local level = UnitLevel(unit)
if level <= 0 then level = 500 end
r, g, b = RUF:GetLevelColor(level, unit)
elseif RUF.db.profile.Appearance.Text[tag].Color.PowerType then -- Color by UnitPower (Mana, Rage, etc.)
if tag == 'CurMana' or tag == 'ManaPerc' or tag == 'CurManaPerc' then
r, g, b = unpack(RUF.db.profile.Appearance.Colors.PowerColors[0])
else
local pType, pToken, altr, altg, altb = UnitPowerType(unit)
r, g, b = unpack(RUF.db.profile.Appearance.Colors.PowerColors[pType])
end
else -- If none of that matches, show the base colour
r, g, b = unpack(RUF.db.profile.Appearance.Text[tag].Color.BaseColor)
end
return r, g, b
end
function RUF.TogglePartyChildrenGroupStatus()
RUF.TogglePartyChildren('partypet')
RUF.TogglePartyChildren('partytarget')
end
function RUF.TogglePartyChildren(childUnit) -- TODO: Implement this better.
if InCombatLockdown() then return end
local unitFrame
local showRaid = RUF.db.profile.unit[childUnit].showRaid or false
local enable = RUF.db.profile.unit[childUnit].Enabled or false
local numFrames = 4
if RUF.db.profile.unit.party.showPlayer then -- Use party setting, if we don'y have 5 party units, we don't have 5 party targets.
numFrames = 5
end
local shouldShow = false
if IsInRaid() then
if showRaid and enable then
shouldShow = true
else
shouldShow = false
end
elseif IsInGroup() then
if enable then
shouldShow = true
else
shouldShow = false
end
else
shouldShow = false
end
for i = 1,5 do
if childUnit == 'partypet' then
unitFrame = _G['oUF_RUF_PartyPet' .. i]
elseif childUnit == 'partytarget' then
unitFrame = _G['oUF_RUF_Party' .. i .. 'Target']
end
if shouldShow then
if not unitFrame:IsEnabled() then
if numFrames < 5 then
if i < 5 then
unitFrame:Enable()
else
unitFrame:Disable()
end
else
unitFrame:Enable()
end
elseif numFrames < 5 then
if i == 5 then
unitFrame:Disable()
end
end
else
unitFrame:Disable()
end
end
end
function RUF.RefreshTextElements(singleFrame, groupFrame, header, groupNum)
if not singleFrame then singleFrame = 'none' end
if not groupFrame then groupFrame = 'none' end
if not header then header = 'none' end
local currentUnit, unitFrame, profileReference
if header ~= 'none' then
currentUnit = header .. 'UnitButton' .. groupNum
elseif groupFrame ~= 'none' then
currentUnit = groupFrame .. groupNum
elseif singleFrame ~= 'none' then
currentUnit = singleFrame
else
return
end
unitFrame = _G['oUF_RUF_' .. currentUnit]
local profileTexts = {}
for k, v in pairs(RUF.db.profile.unit[unitFrame.frame].Frame.Text) do
if v ~= '' then
table.insert(profileTexts, k)
end
end
local existingTexts = { unitFrame.Text:GetChildren() }
for old = 1, #existingTexts do
local currentText = existingTexts[old]
local currentTextName = currentText:GetName()
for new = 1, #profileTexts do
local newTextName = 'oUF_RUF_' .. currentUnit .. '.Text.' .. profileTexts[new]
local exists = false
if currentTextName == newTextName then
currentText:Show()
break
end
if exists == false then
currentText:Hide()
unitFrame:Untag(currentText)
end
end
end
for new = 1, #profileTexts do
local currentTextName = 'oUF_RUF_' .. currentUnit .. '.Text.' .. profileTexts[new]
if not _G[currentTextName] then
RUF.CreateTextArea(unitFrame, unitFrame.frame, profileTexts[new])
RUF.SetTextPoints(unitFrame, unitFrame.frame, profileTexts[new])
end
end
end
function RUF.PixelScale()
local RUFParent = _G["RUF_PetBattleFrameHider"]
if RUF.db.global.pixelScale then
RUFParent:SetIgnoreParentScale(true)
local screenHeight = select(2,GetPhysicalScreenSize())
local pixelSize = GetScreenHeight() / screenHeight
local gamePixelSize = UIParent:GetEffectiveScale() * pixelSize
local compareHeight = (768 / gamePixelSize) - screenHeight
if math.abs(compareHeight) < 1 then
RUFParent:SetScale(gamePixelSize)
end
if not RUF.PixelScaleMonitor then
local monitor = CreateFrame('frame')
monitor:RegisterEvent('UI_SCALE_CHANGED')
monitor:RegisterEvent('DISPLAY_SIZE_CHANGED')
monitor:SetScript('OnEvent', RUF.PixelScale)
RUF.PixelScaleMonitor = monitor
end
else
RUFParent:SetIgnoreParentScale(false)
RUFParent:SetScale(1)
if RUF.PixelScaleMonitor then
RUF.PixelScaleMonitor:UnregisterAllEvents()
RUF.PixelScaleMonitor:SetScript('OnEvent', nil)
RUF.PixelScaleMonitor = nil
end
end
end
function RUF.ToggleFrameLock(status)
local frames = RUF.frameList.frames
local groupFrames = RUF.frameList.groupFrames
local headers = RUF.frameList.headers
if status == false then
for i = 1, #frames do
local anchorFrom1, anchorFrame1, anchorTo1, x1, y1, anchorFrom2, anchorFrame2, anchorTo2, x2, y2, x3, y3
local frameName = _G['oUF_RUF_' .. frames[i]]
local profile = string.lower(frames[i])
frameName:SetMovable(true)
frameName:SetScript('OnMouseDown', function()
frameName:StartMoving()
anchorFrom1, anchorFrame1, anchorTo1, x1, y1 = frameName:GetPoint() end)
frameName:SetScript('OnMouseUp', function()
anchorFrom2, anchorFrame2, anchorTo2, x2, y2 = frameName:GetPoint()
frameName:StopMovingOrSizing()
x3 = x2-x1
y3 = y2-y1
RUF.db.profile.unit[profile].Frame.Position.x = RUF.db.profile.unit[profile].Frame.Position.x + x3
RUF.db.profile.unit[profile].Frame.Position.y = RUF.db.profile.unit[profile].Frame.Position.y + y3
frameName:ClearAllPoints()
frameName:SetPoint(
RUF.db.profile.unit[profile].Frame.Position.AnchorFrom,
RUF.db.profile.unit[profile].Frame.Position.AnchorFrame,
RUF.db.profile.unit[profile].Frame.Position.AnchorTo,
RUF.db.profile.unit[profile].Frame.Position.x,
RUF.db.profile.unit[profile].Frame.Position.y)
LibStub('AceConfigRegistry-3.0'):NotifyChange('RUF') end)
end
for i = 1, #groupFrames do
local anchorFrom1, anchorFrame1, anchorTo1, x1, y1, anchorFrom2, anchorFrame2, anchorTo2, x2, y2, x3, y3
local frameName = _G['oUF_RUF_' .. groupFrames[i] .. '1']
if groupFrames[i]:match('Target') then
frameName = _G['oUF_RUF_' .. groupFrames[i]:gsub('Target','') .. '1' .. 'Target']
end
local profile = string.lower(groupFrames[i])
frameName:SetMovable(true)
frameName:SetScript('OnMouseDown', function()
frameName:StartMoving()
anchorFrom1, anchorFrame1, anchorTo1, x1, y1 = frameName:GetPoint() end)
frameName:SetScript('OnMouseUp', function()
anchorFrom2, anchorFrame2, anchorTo2, x2, y2 = frameName:GetPoint()
frameName:StopMovingOrSizing()
x3 = x2-x1
y3 = y2-y1
RUF.db.profile.unit[profile].Frame.Position.x = RUF.db.profile.unit[profile].Frame.Position.x + x3
RUF.db.profile.unit[profile].Frame.Position.y = RUF.db.profile.unit[profile].Frame.Position.y + y3
frameName:ClearAllPoints()
frameName:SetPoint(
RUF.db.profile.unit[profile].Frame.Position.AnchorFrom,
RUF.db.profile.unit[profile].Frame.Position.AnchorFrame,
RUF.db.profile.unit[profile].Frame.Position.AnchorTo,
RUF.db.profile.unit[profile].Frame.Position.x,
RUF.db.profile.unit[profile].Frame.Position.y)
LibStub('AceConfigRegistry-3.0'):NotifyChange('RUF') end)
end
for i = 1, #headers do
local anchorFrom1, anchorFrame1, anchorTo1, x1, y1, anchorFrom2, anchorFrame2, anchorTo2, x2, y2, x3, y3
local frameName = _G['oUF_RUF_' .. headers[i]]
local MoveBG = frameName.MoveBG
local profile = string.lower(headers[i])
MoveBG:Show()
frameName:SetMovable(true)
MoveBG:SetMovable(true)
MoveBG:SetScript('OnMouseDown', function(MoveBG)
frameName:StartMoving()
MoveBG:StartMoving()
anchorFrom1, anchorFrame1, anchorTo1, x1, y1 = frameName:GetPoint() end)
MoveBG:SetScript('OnMouseUp', function(MoveBG)
anchorFrom2, anchorFrame2, anchorTo2, x2, y2 = frameName:GetPoint()
frameName:StopMovingOrSizing()
MoveBG:StopMovingOrSizing()
x3 = x2-x1
y3 = y2-y1
RUF.db.profile.unit[profile].Frame.Position.x = RUF.db.profile.unit[profile].Frame.Position.x + x3
RUF.db.profile.unit[profile].Frame.Position.y = RUF.db.profile.unit[profile].Frame.Position.y + y3
frameName:ClearAllPoints()
frameName:SetPoint(
RUF.db.profile.unit[profile].Frame.Position.AnchorFrom,
RUF.db.profile.unit[profile].Frame.Position.AnchorFrame,
RUF.db.profile.unit[profile].Frame.Position.AnchorTo,
RUF.db.profile.unit[profile].Frame.Position.x,
RUF.db.profile.unit[profile].Frame.Position.y)
LibStub('AceConfigRegistry-3.0'):NotifyChange('RUF') end)
end
else -- lock
for i = 1, #frames do
local frameName = 'oUF_RUF_' .. frames[i]
if _G[frameName] then
local profile = string.lower(frames[i])
_G[frameName]:SetMovable(false)
_G[frameName]:SetScript('OnMouseDown', nil)
_G[frameName]:SetScript('OnMouseUp', nil)
end
end
for i = 1, #groupFrames do
local frameName = 'oUF_RUF_' .. groupFrames[i] .. '1'
if groupFrames[i]:match('Target') then
frameName = _G['oUF_RUF_' .. groupFrames[i]:gsub('Target','') .. '1' .. 'Target']
end
if _G[frameName] then
local profile = string.lower(groupFrames[i])
_G[frameName]:SetMovable(false)
_G[frameName]:SetScript('OnMouseDown', nil)
_G[frameName]:SetScript('OnMouseUp', nil)
end
end
for i = 1, #headers do
local frameName = 'oUF_RUF_' .. headers[i]
if _G[frameName] then
local MoveBG = _G[frameName .. '.MoveBG']
MoveBG:Hide()
MoveBG:SetMovable(false)
_G[frameName]:SetMovable(false)
MoveBG:SetScript('OnMouseDown', nil)
MoveBG:SetScript('OnMouseUp', nil)
end
end
end
end