-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovable.lua
224 lines (197 loc) · 5.95 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
local _, mUI = ...
local LSM = LibStub("LibSharedMedia-3.0")
local playerColor = mUI:GetClassColor("player")
local font = LSM:Fetch("font", "Outfit Bold")
local movers = {}
local locked = true
local grid = CreateFrame("Frame", "MangoGrid", UIParent, "BackdropTemplate")
grid:SetAllPoints()
grid:SetBackdrop({
bgFile = [[Interface\AddOns\MangoUI\Media\Borders\mangobasic.tga]],
})
grid:SetBackdropColor(0, 0, 0, 0.3)
grid:SetFrameStrata("BACKGROUND")
grid:Hide()
local w, h = GetPhysicalScreenSize()
for i = 0, w do
if i == w / 2 then
local l = grid:CreateTexture(nil, "BACKGROUND")
l:SetColorTexture(playerColor.r, playerColor.g, playerColor.b, 1)
l:SetPoint("TOPLEFT", i, 0)
l:SetPoint("BOTTOMLEFT", i, 0)
elseif i % 20 == 0 then
local l = grid:CreateTexture(nil, "BACKGROUND")
l:SetColorTexture(0.8, 0.8, 0.8, 0.3)
l:SetPoint("TOPLEFT", i, 0)
l:SetPoint("BOTTOMLEFT", i, 0)
end
end
for i = 0, h do
if i == h / 2 then
local l = grid:CreateTexture(nil, "BACKGROUND")
l:SetColorTexture(playerColor.r, playerColor.g, playerColor.b, 1)
l:SetPoint("BOTTOMLEFT", 0, i)
l:SetPoint("BOTTOMRIGHT", 0, i)
elseif i % 20 == 0 then
local l = grid:CreateTexture(nil, "BACKGROUND")
l:SetColorTexture(0.8, 0.8, 0.8, 0.3)
l:SetPoint("BOTTOMLEFT", 0, i)
l:SetPoint("BOTTOMRIGHT", 0, i)
end
end
local moveManager = CreateFrame("Frame", "MangoMoveManager", grid, "BackdropTemplate")
moveManager:SetSize(250, 60)
moveManager:SetPoint("TOPLEFT", 30, -30)
moveManager:SetBackdrop({
bgFile = [[Interface\AddOns\MangoUI\Media\Borders\mangobasic.tga]],
edgeFile = [[Interface\AddOns\MangoUI\Media\Borders\mangobasic.tga]],
edgeSize = 2
})
moveManager:SetBackdropColor(0, 0, 0, 0.65)
moveManager:SetBackdropBorderColor(0.33, 0.33, 0.33, 1)
moveManager:SetFrameStrata("DIALOG")
moveManager:SetClampedToScreen(true)
local hideBtn = CreateFrame("Button", "MangoHideMovable", moveManager, "BackdropTemplate")
hideBtn:SetSize(80, 25)
hideBtn:SetPoint("CENTER", moveManager, "CENTER")
hideBtn:SetBackdrop({
bgFile = [[Interface\AddOns\MangoUI\Media\Borders\mangobasic.tga]],
edgeFile = [[Interface\AddOns\MangoUI\Media\Borders\mangobasic.tga]],
edgeSize = 2
})
hideBtn:SetBackdropColor(0, 0, 0, 1)
hideBtn:SetBackdropBorderColor(0.33, 0.33, 0.33, 1)
hideBtn:SetScript("OnClick", function()
mUI:ToggleMovable()
end)
local label = hideBtn:CreateFontString(nil, "OVERLAY")
label:SetPoint("CENTER")
label:SetJustifyH("CENTER")
label:SetFont(font, 14, "OUTLINE")
label:SetText("Hide")
label:SetTextColor(0.8, 0.8, 0.8, 1)
hideBtn.label = label
local function PrettifyName(name)
name = name:gsub("_", " ")
name = name:lower()
name = name:gsub("^%l", string.upper)
return name
end
-- Returns x & y pos of a frame relative to its parent
local function GetPos(frame)
if not frame or not frame:GetParent() then
return 0, 0
end
local frameX, frameY = frame:GetCenter()
local parentX, parentY = frame:GetParent():GetCenter()
local oX = Round((frameX or 0) - (parentX or 0))
local oY = Round((frameY or 0) - (parentY or 0))
return oX, oY
end
local function updateInfo(self)
if self.info then
local x, y = GetPos(self)
self.info:SetText("X: " .. x .. " Y: " .. y)
end
end
local function savePoint(mover)
local x, y = GetPos(mover)
mover.callback(x, y)
end
local function OnEnter(self)
self:SetBackdropBorderColor(playerColor.r, playerColor.g, playerColor.b, 1)
self:EnableKeyboard(true)
self:SetPropagateKeyboardInput(false)
self:SetScript("OnKeyDown", function(self, key)
self:StartMoving()
self.frame:ClearAllPoints()
self.frame:SetAllPoints(self)
if key == "UP" then
self:AdjustPointsOffset(0, 1)
savePoint(self)
elseif key == "DOWN" then
self:AdjustPointsOffset(0, -1)
savePoint(self)
elseif key == "LEFT" then
self:AdjustPointsOffset(-1, 0)
savePoint(self)
elseif key == "RIGHT" then
self:AdjustPointsOffset(1, 0)
savePoint(self)
end
self:StopMovingOrSizing()
end)
end
local function OnLeave(self)
self:SetBackdropBorderColor(0, 0, 0, 1)
self:EnableKeyboard(false)
self:SetPropagateKeyboardInput(true)
self:SetScript("OnKeyDown", nil)
end
local function OnMouseDown(self)
self:StartMoving()
self.frame:ClearAllPoints()
self.frame:SetAllPoints(self)
end
local function OnMouseUp(self)
self:StopMovingOrSizing()
savePoint(self)
end
function mUI:AddMover(frame, name, callback)
local mover = CreateFrame("Frame", nil, grid, "BackdropTemplate")
mover:SetAllPoints(frame)
mover:SetBackdrop({
bgFile = [[Interface\AddOns\MangoUI\Media\Borders\mangobasic.tga]],
edgeFile = [[Interface\AddOns\MangoUI\Media\Borders\mangobasic.tga]],
edgeSize = 1
})
mover:SetBackdropColor(0, 0, 0, 0.8)
mover:SetBackdropBorderColor(0, 0, 0, 1)
mover:SetFrameStrata("DIALOG")
mover:SetMovable(true)
mover:SetClampedToScreen(true)
mover:SetScript("OnMouseDown", OnMouseDown)
mover:SetScript("OnMouseUp", OnMouseUp)
mover:SetScript("OnEnter", OnEnter)
mover:SetScript("OnLeave", OnLeave)
mover:SetScript("OnUpdate", updateInfo)
local label = mover:CreateFontString(nil, "OVERLAY")
label:SetPoint("LEFT", mover, "TOPLEFT", 6, 0)
label:SetJustifyH("LEFT")
label:SetFont(font, 14, "OUTLINE")
label:SetText(PrettifyName(name))
label:SetTextColor(playerColor.r, playerColor.g, playerColor.b, 1)
mover.label = label
local info = mover:CreateFontString(nil, "OVERLAY")
info:SetPoint("CENTER")
info:SetJustifyH("CENTER")
info:SetFont(font, 12, "OUTLINE")
local x, y = GetPos(mover)
info:SetText("X: " .. x .. " Y: " .. y)
info:SetTextColor(1, 1, 1, 1)
mover.info = info
mover.frame = frame
mover.callback = callback or function() return end
mover:Hide()
movers[name] = mover
end
local function frameUnlock(frame)
frame:Show()
end
local function frameLock(frame)
frame:Hide()
end
function mUI:ToggleMovable()
for _, frame in pairs(movers) do
if locked then
frameUnlock(frame)
grid:Show()
else
frameLock(frame)
grid:Hide()
end
end
locked = not locked
end
SLASH_MANGOMOVE1, SLASH_MANGOMOVE2 = "/mangomove", "/mmove"
SlashCmdList["MANGOMOVE"] = mUI.ToggleMovable