-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.lua
More file actions
211 lines (173 loc) · 6.23 KB
/
Copy pathcore.lua
File metadata and controls
211 lines (173 loc) · 6.23 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
local addonName, ns = ...
-- Global table for saving positions
WoWUI_DB = WoWUI_DB or {}
local WoWUI = CreateFrame("Frame")
ns.WoWUI = WoWUI
ns.WoWUI.actionBars = {}
ns.WoWUI.unitFrames = {}
local movableFrames = {}
WoWUI:RegisterEvent("ADDON_LOADED")
WoWUI:SetScript("OnEvent", function(self, event, loadedAddon)
if loadedAddon == addonName then
WoWUI_DB.positions = WoWUI_DB.positions or {}
self:UnregisterEvent("ADDON_LOADED")
-- Restore saved positions now that the DB is loaded
for _, frame in ipairs(movableFrames) do
local name = frame.dbKey
if WoWUI_DB.positions[name] then
local pos = WoWUI_DB.positions[name]
frame:ClearAllPoints()
frame:SetPoint(pos[1], UIParent, pos[2], pos[3], pos[4])
end
end
end
end)
-- Movability system
local unlocked = false
function WoWUI:RegisterMovable(frame, name)
frame.dbKey = name
table.insert(movableFrames, frame)
local mover = CreateFrame("Frame", nil, frame, "BackdropTemplate")
mover:SetAllPoints(frame)
mover:SetFrameStrata("TOOLTIP")
mover:EnableMouse(true)
mover:RegisterForDrag("LeftButton")
mover:SetScript("OnDragStart", function(self)
frame:StartMoving()
end)
mover:SetScript("OnDragStop", function(self)
frame:StopMovingOrSizing()
local point, _, relativePoint, x, y = frame:GetPoint()
WoWUI_DB.positions[frame.dbKey] = { point, relativePoint, x, y }
end)
-- Simple background to show it's unlocked
local tex = mover:CreateTexture(nil, "BACKGROUND")
tex:SetAllPoints()
tex:SetColorTexture(0, 1, 0, 0.4)
local text = mover:CreateFontString(nil, "OVERLAY", "GameFontNormal")
text:SetPoint("CENTER")
text:SetText(name)
mover:Hide()
frame.mover = mover
-- If the frame is registered after ADDON_LOADED has fired, try to load it now
if WoWUI_DB and WoWUI_DB.positions and WoWUI_DB.positions[name] then
local pos = WoWUI_DB.positions[name]
frame:ClearAllPoints()
frame:SetPoint(pos[1], UIParent, pos[2], pos[3], pos[4])
end
end
SLASH_WOWUI1 = "/wowui"
SlashCmdList["WOWUI"] = function(msg)
if msg == "unlock" then
unlocked = true
for _, frame in ipairs(movableFrames) do
frame:SetMovable(true)
frame:SetUserPlaced(true)
frame.mover:Show()
end
print("WoWUI: Frames unlocked.")
elseif msg == "lock" then
unlocked = false
for _, frame in ipairs(movableFrames) do
frame:SetMovable(false)
frame.mover:Hide()
end
print("WoWUI: Frames locked.")
else
print("WoWUI Commands:")
print(" /wowui unlock - Unlock frames to move them")
print(" /wowui lock - Lock frames")
end
end
-- Keybinding System
local keybindMode = false
local function UpdateKeybindOverlay(btn)
if not btn.keybindOverlay then
local overlay = CreateFrame("Button", nil, btn, "BackdropTemplate")
overlay:SetAllPoints(btn)
overlay:SetFrameStrata("DIALOG")
overlay:EnableMouse(true)
overlay:EnableKeyboard(true)
overlay:RegisterForClicks("AnyDown")
local tex = overlay:CreateTexture(nil, "OVERLAY")
tex:SetAllPoints()
tex:SetColorTexture(0, 1, 0, 0.4)
tex:Hide()
overlay:SetScript("OnEnter", function(self)
tex:Show()
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:SetText("Hover to bind\nPress ESC to close\nPress Backspace/Delete to clear")
GameTooltip:Show()
end)
overlay:SetScript("OnLeave", function(self)
tex:Hide()
GameTooltip:Hide()
end)
local function assignBind(key)
if key == "ESCAPE" then
ns.WoWUI:ToggleKeybindMode()
return
end
if key == "BACKSPACE" or key == "DELETE" then
btn:ClearBindings()
print("WoWUI: Cleared bindings for " .. (btn:GetName() or "button"))
return
end
if key == "LSHIFT" or key == "RSHIFT" or key == "LCTRL" or key == "RCTRL" or key == "LALT" or key == "RALT" or key == "LMETA" or key == "RMETA" then
return -- Wait for actual key
end
local modifier = ""
if IsShiftKeyDown() then modifier = modifier .. "SHIFT-" end
if IsControlKeyDown() then modifier = modifier .. "CTRL-" end
if IsAltKeyDown() then modifier = modifier .. "ALT-" end
local bindKey = modifier .. key
btn:SetKey(bindKey)
SaveBindings(GetCurrentBindingSet())
print("WoWUI: Bound " .. bindKey .. " to " .. (btn:GetName() or "button"))
end
overlay:SetScript("OnKeyDown", function(self, key)
assignBind(key)
end)
overlay:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" or button == "RightButton" then
return
end
local bindKey = button
if button == "MiddleButton" then bindKey = "BUTTON3" end
local btnNum = button:match("Button(%d+)")
if btnNum then
bindKey = "BUTTON" .. btnNum
end
assignBind(bindKey)
end)
overlay:SetScript("OnMouseWheel", function(self, delta)
local bindKey = delta > 0 and "MOUSEWHEELUP" or "MOUSEWHEELDOWN"
assignBind(bindKey)
end)
btn.keybindOverlay = overlay
end
if keybindMode then
btn.keybindOverlay:Show()
else
btn.keybindOverlay:Hide()
end
end
function ns.WoWUI:ToggleKeybindMode()
keybindMode = not keybindMode
if keybindMode then
print("WoWUI: Keybind mode ENABLED. Hover over buttons to bind. Press ESC to exit.")
else
print("WoWUI: Keybind mode DISABLED.")
end
for _, bar in ipairs(ns.WoWUI.actionBars) do
if bar.buttons then
for _, btn in ipairs(bar.buttons) do
UpdateKeybindOverlay(btn)
end
end
end
end
SLASH_WOWUIKBIND1 = "/kbind"
SlashCmdList["WOWUIKBIND"] = function(msg)
ns.WoWUI:ToggleKeybindMode()
end