-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOptions.lua
More file actions
315 lines (278 loc) · 10.7 KB
/
Options.lua
File metadata and controls
315 lines (278 loc) · 10.7 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
local addonName, addon = ...
local ANCHOR_POINTS = {
"TOPLEFT", "TOP", "TOPRIGHT",
"LEFT", "CENTER", "RIGHT",
"BOTTOMLEFT", "BOTTOM", "BOTTOMRIGHT",
}
local SLIDER_WIDTH = 300
local DROPDOWN_WIDTH = 150
local function ResolveFrameName(frame)
local name = frame.GetName and frame:GetName()
if name then return name end
local parent = frame.GetParent and frame:GetParent()
if parent then
for key, child in pairs(parent) do
if child == frame then
return (ResolveFrameName(parent) or "") .. "." .. key
end
end
end
return nil
end
local function FindNamedAncestor(frame)
while frame do
local name = frame:GetName()
if name then return frame, name end
frame = frame:GetParent()
end
return nil, nil
end
-- Sorta like WeakAuras picker
local function CreateFramePicker(onFramePicked, onCancel)
local picker = CreateFrame("Frame")
local highlight = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
highlight:SetFrameStrata("TOOLTIP")
highlight:SetBackdrop({
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 12,
insets = { left = 0, right = 0, top = 0, bottom = 0 },
})
highlight:SetBackdropBorderColor(0, 1, 0)
highlight:Hide()
local active = false
local currentFocus
local function StopPicking()
active = false
picker:SetScript("OnUpdate", nil)
highlight:Hide()
GameTooltip:Hide()
ResetCursor()
end
function picker:Start()
active = true
currentFocus = nil
SetCursor("CAST_CURSOR")
picker:SetScript("OnUpdate", function()
if not active then return end
if IsMouseButtonDown("RightButton") then
StopPicking()
if onCancel then onCancel() end
return
end
if IsMouseButtonDown("LeftButton") and currentFocus then
local _, name = FindNamedAncestor(currentFocus)
if name then
StopPicking()
onFramePicked(name)
else
print("|cFFFF6600TotemFrameRelocation:|r No named frame found.")
StopPicking()
if onCancel then onCancel() end
end
return
end
local focus = GetMouseFocus and GetMouseFocus() or (GetMouseFoci and GetMouseFoci()[1])
if focus and focus ~= WorldFrame then
-- Find nearest named ancestor.
local namedFrame, namedName = FindNamedAncestor(focus)
if namedFrame then
currentFocus = namedFrame
highlight:ClearAllPoints()
highlight:SetPoint("BOTTOMLEFT", namedFrame, "BOTTOMLEFT", -4, -4)
highlight:SetPoint("TOPRIGHT", namedFrame, "TOPRIGHT", 4, 4)
highlight:Show()
GameTooltip:SetOwner(namedFrame, "ANCHOR_CURSOR")
GameTooltip:SetText(namedName)
GameTooltip:Show()
else
currentFocus = nil
highlight:Hide()
GameTooltip:Hide()
end
else
currentFocus = nil
highlight:Hide()
GameTooltip:Hide()
end
end)
end
return picker
end
local function CreateSettingsPanel()
local panel = CreateFrame("Frame")
panel:SetSize(400, 400)
panel:Hide()
local db = addon.db
local yOffset = -10
local title = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", panel, "TOPLEFT", 10, yOffset)
title:SetText("Totem Frame Relocation")
yOffset = yOffset - 30
local frameLabel = panel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
frameLabel:SetPoint("TOPLEFT", panel, "TOPLEFT", 10, yOffset)
frameLabel:SetText("Parent Frame:")
local frameNameText = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
frameNameText:SetPoint("LEFT", frameLabel, "RIGHT", 8, 0)
frameNameText:SetWidth(120)
frameNameText:SetWordWrap(false)
frameNameText:SetText(db.parentFrameName or "None")
local picker
local pickButton = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
pickButton:SetSize(120, 22)
pickButton:SetPoint("LEFT", frameNameText, "RIGHT", 10, 0)
pickButton:SetText("Select Frame")
pickButton:SetScript("OnClick", function()
local function reopenSettings()
Settings.OpenToCategory(addon.settingsCategory:GetID())
end
picker = picker or CreateFramePicker(function(name)
db.parentFrameName = name
frameNameText:SetText(name)
addon:ApplySettings()
reopenSettings()
end, reopenSettings)
HideUIPanel(SettingsPanel)
picker:Start()
end)
local clearButton = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
clearButton:SetSize(60, 22)
clearButton:SetPoint("LEFT", pickButton, "RIGHT", 4, 0)
clearButton:SetText("Clear")
clearButton:SetScript("OnClick", function()
db.parentFrameName = nil
frameNameText:SetText("None")
addon:ApplySettings()
end)
yOffset = yOffset - 30
local parentAnchorLabel = panel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
parentAnchorLabel:SetPoint("TOPLEFT", panel, "TOPLEFT", 10, yOffset)
parentAnchorLabel:SetText("Parent Anchor:")
local parentAnchorDD = CreateFrame("DropdownButton", nil, panel, "WowStyle1DropdownTemplate")
parentAnchorDD:SetPoint("LEFT", parentAnchorLabel, "RIGHT", 8, 0)
parentAnchorDD:SetWidth(DROPDOWN_WIDTH)
parentAnchorDD:SetupMenu(function(_, rootDescription)
for _, point in ipairs(ANCHOR_POINTS) do
rootDescription:CreateRadio(point, function(p) return p == db.parentAnchor end, function()
db.parentAnchor = point
addon:ApplySettings()
end, point)
end
end)
yOffset = yOffset - 40
local totemAnchorLabel = panel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
totemAnchorLabel:SetPoint("TOPLEFT", panel, "TOPLEFT", 10, yOffset)
totemAnchorLabel:SetText("Totem Frame Anchor:")
local totemAnchorDD = CreateFrame("DropdownButton", nil, panel, "WowStyle1DropdownTemplate")
totemAnchorDD:SetPoint("LEFT", totemAnchorLabel, "RIGHT", 8, 0)
totemAnchorDD:SetWidth(DROPDOWN_WIDTH)
totemAnchorDD:SetupMenu(function(_, rootDescription)
for _, point in ipairs(ANCHOR_POINTS) do
rootDescription:CreateRadio(point, function(p) return p == db.totemFrameAnchor end, function()
db.totemFrameAnchor = point
addon:ApplySettings()
end, point)
end
end)
yOffset = yOffset - 40
local xSlider = CreateFrame("Slider", addonName .. "XOffsetSlider", panel, "OptionsSliderTemplate")
xSlider:SetPoint("TOPLEFT", panel, "TOPLEFT", 14, yOffset)
xSlider:SetWidth(SLIDER_WIDTH)
xSlider:SetMinMaxValues(-250, 250)
xSlider:SetValueStep(1)
xSlider:SetObeyStepOnDrag(true)
xSlider:SetValue(db.xOffset)
xSlider.Low:SetText("-250")
xSlider.High:SetText("250")
xSlider.Text:SetText("X Offset")
local xBox = CreateFrame("EditBox", nil, panel, "InputBoxTemplate")
xBox:SetSize(50, 20)
xBox:SetPoint("LEFT", xSlider, "RIGHT", 10, 0)
xBox:SetAutoFocus(false)
xBox:SetNumeric(false)
xBox:SetText(tostring(db.xOffset))
xSlider:SetScript("OnValueChanged", function(self, value, userInput)
if userInput then
local v = math.floor(value + 0.5)
db.xOffset = v
xBox:SetText(tostring(v))
addon:ApplySettings()
end
end)
xBox:SetScript("OnEnterPressed", function(self)
local v = tonumber(self:GetText())
if v then
v = math.floor(math.max(-250, math.min(250, v)) + 0.5)
db.xOffset = v
xSlider:SetValue(v)
self:SetText(tostring(v))
addon:ApplySettings()
else
self:SetText(tostring(db.xOffset))
end
self:ClearFocus()
end)
yOffset = yOffset - 50
local ySlider = CreateFrame("Slider", addonName .. "YOffsetSlider", panel, "OptionsSliderTemplate")
ySlider:SetPoint("TOPLEFT", panel, "TOPLEFT", 14, yOffset)
ySlider:SetWidth(SLIDER_WIDTH)
ySlider:SetMinMaxValues(-250, 250)
ySlider:SetValueStep(1)
ySlider:SetObeyStepOnDrag(true)
ySlider:SetValue(db.yOffset)
ySlider.Low:SetText("-250")
ySlider.High:SetText("250")
ySlider.Text:SetText("Y Offset")
local yBox = CreateFrame("EditBox", nil, panel, "InputBoxTemplate")
yBox:SetSize(50, 20)
yBox:SetPoint("LEFT", ySlider, "RIGHT", 10, 0)
yBox:SetAutoFocus(false)
yBox:SetNumeric(false)
yBox:SetText(tostring(db.yOffset))
ySlider:SetScript("OnValueChanged", function(self, value, userInput)
if userInput then
local v = math.floor(value + 0.5)
db.yOffset = v
yBox:SetText(tostring(v))
addon:ApplySettings()
end
end)
yBox:SetScript("OnEnterPressed", function(self)
local v = tonumber(self:GetText())
if v then
v = math.floor(math.max(-250, math.min(250, v)) + 0.5)
db.yOffset = v
ySlider:SetValue(v)
self:SetText(tostring(v))
addon:ApplySettings()
else
self:SetText(tostring(db.yOffset))
end
self:ClearFocus()
end)
yOffset = yOffset - 50
local maskCheckbox = CreateFrame("CheckButton", nil, panel, "UICheckButtonTemplate")
maskCheckbox:SetPoint("TOPLEFT", panel, "TOPLEFT", 10, yOffset)
maskCheckbox.Text:SetText(" Square Totem Icons")
maskCheckbox.Text:SetFontObject("GameFontNormal")
maskCheckbox:SetChecked(db.useSquareMask)
maskCheckbox:HookScript("OnClick", function(self)
db.useSquareMask = self:GetChecked()
addon:ApplySettings()
end)
return panel
end
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:SetScript("OnEvent", function(_, event, arg1)
if event == "ADDON_LOADED" and arg1 == addonName then
local panel = CreateSettingsPanel()
local category = Settings.RegisterCanvasLayoutCategory(panel, "Totem Frame Relocation")
Settings.RegisterAddOnCategory(category)
addon.settingsCategory = category
SLASH_TOTEMFRAMERELOCATE1 = "/totemframe"
SlashCmdList["TOTEMFRAMERELOCATE"] = function()
Settings.OpenToCategory(category:GetID())
end
eventFrame:UnregisterEvent("ADDON_LOADED")
end
end)