-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProxyKeys.lua
More file actions
228 lines (191 loc) · 6.2 KB
/
ProxyKeys.lua
File metadata and controls
228 lines (191 loc) · 6.2 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
local function HighlightSpaceButton(btn)
if spaceHighlight and spaceHighlight ~= btn then
RemoveHighlight(spaceHighlight)
end
if btn then
ApplyHighlight(btn)
end
spaceHighlight = btn
end
local function ClearSpaceHighlight()
if spaceHighlight then
RemoveHighlight(spaceHighlight)
end
spaceHighlight = nil
end
local function ClearAllButtonHighlights()
for i = 1, 10 do
local b = _G["QuestTitleButton"..i]
if b then
RemoveHighlight(b)
end
end
end
local function EnableOverride(frame)
-- Create a secure frame for the action that is being overridden
local secureFrame = CreateFrame("Frame", "DialogKeyWrathSecureFrame", UIParent)
secureFrame:SetAttribute("type", "button")
secureFrame:SetAttribute("text", "SecureFrame")
secureFrame:SetAttribute("width", 100)
secureFrame:SetAttribute("height", 100)
-- Set the secure frame as the target for the keybinding
local keybinding = _G["QuestFrameRewardButton"]:GetKeybinding()
keybinding:SetTarget(secureFrame)
-- Redirect the keybinding to the secure frame
keybinding:SetScript("OnPress", function()
secureFrame:Fire()
end)
-- Highlight the secure frame
HighlightSpaceButton(secureFrame)
end
local function DisableOverride(frame)
-- Remove the secure frame
if secureFrame then
secureFrame:Hide()
secureFrame:Release()
secureFrame = nil
end
-- Remove the keybinding target
local keybinding = _G["QuestFrameRewardButton"]:GetKeybinding()
keybinding:SetTarget(nil)
-- Remove the keybinding script
keybinding:SetScript("OnPress", nil)
end
-- Enable the override mechanic when the quest frame is visible
local function EnableOverrideOnQuestFrameShow()
local questFrame = _G.QuestFrame
if questFrame then
EnableOverride(questFrame)
end
end
-- Disable the override mechanic when the quest frame is hidden
local function DisableOverrideOnQuestFrameHide()
local questFrame = _G.QuestFrame
if questFrame then
DisableOverride(questFrame)
end
end
-- Update the override state when the user enters or exits combat
local function UpdateOverrideState()
local player = _G.Player
if player then
if player.InCombat then
DisableOverride(player.QuestFrame)
else
EnableOverride(player.QuestFrame)
end
end
end
-- Register the events for the override mechanic
local function RegisterEvents()
-- Register the quest frame show and hide events
_G.QuestFrame:Hide()
_G.QuestFrame:Show()
_G.QuestFrame:Hide()
-- Register the combat enter and exit events
local player = _G.Player
if player then
player.EnterCombat:Register()
player.LeaveCombat:Register()
end
end
-- Initialize the override mechanic
local function InitializeOverride()
-- Create the secure frames for the quest rewards
EnableOverride(QuestFrameRewardButton)
-- Register the events for the override mechanic
RegisterEvents()
end
-- Cleanup the override mechanic
local function CleanupOverride()
-- Remove the secure frames for the quest rewards
DisableOverride(QuestFrameRewardButton)
-- Unregister the events for the override mechanic
UnregisterEvents()
end
-- Update the override state when the user enters or exits combat
UpdateOverrideState()
-- Initialize the override mechanic
InitializeOverride()
-- Cleanup the override mechanic when the addon is unloaded
local function Unload()
CleanupOverride()
end
-- Export the functions for the override mechanic
local function EnableOverride(frame)
-- Create a secure frame for the action that is being overridden
local secureFrame = CreateFrame("Frame", "DialogKeyWrathSecureFrame", UIParent)
secureFrame:SetAttribute("type", "button")
secureFrame:SetAttribute("text", "SecureFrame")
secureFrame:SetAttribute("width", 100)
secureFrame:SetAttribute("height", 100)
-- Set the secure frame as the target for the keybinding
local keybinding = _G["QuestTitleButton1"]:GetKeybinding()
keybinding:SetTarget(secureFrame)
-- Redirect the keybinding to the secure frame
keybinding:SetScript("OnPress", function()
secureFrame:Fire()
end)
-- Highlight the secure frame
HighlightSpaceButton(secureFrame)
end
local function DisableOverride(frame)
-- Remove the secure frame
if secureFrame then
secureFrame:Hide()
secureFrame:Release()
secureFrame = nil
end
-- Remove the keybinding target
local keybinding = _G["QuestTitleButton1"]:GetKeybinding()
keybinding:SetTarget(nil)
-- Remove the keybinding script
keybinding:SetScript("OnPress", nil)
end
-- Export the functions for the override mechanic
local function UpdateOverrideState()
local player = _G.Player
if player then
if player.InCombat then
DisableOverride(player.QuestFrame)
else
EnableOverride(player.QuestFrame)
end
end
end
local function RegisterEvents()
-- Register the quest frame show and hide events
_G.QuestFrame:Hide()
_G.QuestFrame:Show()
_G.QuestFrame:Hide()
-- Register the combat enter and exit events
local player = _G.Player
if player then
player.EnterCombat:Register()
player.LeaveCombat:Register()
end
end
local function UnregisterEvents()
-- Unregister the quest frame show and hide events
_G.QuestFrame:Hide()
_G.QuestFrame:Show()
-- Unregister the combat enter and exit events
local player = _G.Player
if player then
player.EnterCombat:Unregister()
player.LeaveCombat:Unregister()
end
end
-- Export the functions for the override mechanic
local function InitializeOverride()
-- Create the secure frames for the quest rewards
EnableOverride(QuestFrameRewardButton)
-- Register the events for the override mechanic
RegisterEvents()
end
local function CleanupOverride()
-- Remove the secure frames for the quest rewards
DisableOverride(QuestFrameRewardButton)
-- Unregister the events for the override mechanic
UnregisterEvents()
end