-
Notifications
You must be signed in to change notification settings - Fork 11
/
core.lua
219 lines (187 loc) · 7.68 KB
/
core.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
DialogKey = LibStub("AceAddon-3.0"):NewAddon("DialogKey", "AceConsole-3.0", "AceTimer-3.0", "AceEvent-3.0")
--[[
Raimond Mildenhall
? Free the Farmhands
? Fetching Wrex
! The Bee Team
! Wendigo Away
\AddOns\DialogKey\main.lua line 638: attempt to index local 'a' (a nil value)
if a.top > b.top then return 1 end
]]
--[[
GossipFrame with quests: nethergarde keep, 2 quests to free spirits and kill bonepickers, do spirit quest - makes second quest the one we want to hit first
* fixed keybinding mode
* added cooldown option
* fixed issues with QuestFrames (some quest givers use QuestFrame, some use GossipFrame)
<< requires a game restart >>
]]
local defaults = { -- Default settings
global = {
keys = {
"SPACE",
},
ignoreDisabledButtons = true,
showGlow = true,
shownBindWarning = false,
additionalButtons = {},
dialogBlacklist = {},
numKeysForGossip = true,
numKeysForQuestRewards = true,
scrollQuests = false,
dontClickSummons = false,
dontClickDuels = false,
dontClickRevives = false,
dontClickReleases = false,
soulstoneRez = true,
keyCooldown = 0.5
}
}
DialogKey.buttons = { -- List of buttons to try and click
"StaticPopup1Button1",
"QuestFrameCompleteButton",
"QuestFrameCompleteQuestButton",
"QuestFrameAcceptButton",
"GossipTitleButton1",
"QuestTitleButton1"
}
DialogKey.scrollFrames = { -- List of quest frames to try and scroll
QuestDetailScrollFrame,
QuestLogPopupDetailFrameScrollFrame,
QuestMapDetailsScrollFrame,
ClassicQuestLogDetailScrollFrame
}
DialogKey.builtinDialogBlacklist = { -- If a confirmation dialog contains one of these strings, don't accept it
"Are you sure you want to go back to Shal'Aran?", -- Seems to bug out and not work if an AddOn clicks the confirm button?
}
function DialogKey:OnInitialize() -- Runs on addon initialization
self.db = LibStub("AceDB-3.0"):New("DialogKeyDB", defaults, true)
self.keybindMode = false
self.keybindIndex = 0
self.recentlyPressed = false
self:RegisterChatCommand("dk", "ChatCommand")
self:RegisterChatCommand("dkey", "ChatCommand")
self:RegisterChatCommand("dialogkey", "ChatCommand")
self:RegisterEvent("GOSSIP_SHOW", function() self:ScheduleTimer(self.EnumerateGossips_Gossip, 0.01) end)
self:RegisterEvent("QUEST_GREETING", function() self:ScheduleTimer(self.EnumerateGossips_Quest, 0.01) end)
self:RegisterEvent("PLAYER_REGEN_ENABLED",function() self:ScheduleTimer(self.DisableQuestScrolling, 0.1) end) -- Since scrolling can't be disabled on closing a scrollframe in combat, wait til the end of combat to try disabling
QuestInfoRewardsFrameQuestInfoItem1:HookScript("OnHide", function() GameTooltip:Hide() end) -- Hide GameTooltip when the quest is finished
for i,frame in pairs(DialogKey.scrollFrames) do
frame:HookScript("OnShow", function() self:ScheduleTimer(self.EnableQuestScrolling, 0.01) end)
frame:HookScript("OnHide", function() self:ScheduleTimer(self.DisableQuestScrolling, 0.1) end)
end
UIParent:HookScript("OnMouseWheel", self.HandleScroll)
UIParent:EnableMouseWheel(false) -- Required since it's enabled upon hooking OnMouseWheel
self.frame = CreateFrame("Frame", "DialogKeyFrame", UIParent)
self.frame:EnableKeyboard(true)
self.frame:SetPropagateKeyboardInput(true)
self.frame:SetFrameStrata("TOOLTIP") -- Ensure we receive keyboard events first
self.frame:SetScript("OnKeyDown", DialogKey.HandleKey)
self.glowFrame = CreateFrame("Frame", "DialogKeyGlow", UIParent)
self.glowFrame:SetPoint("CENTER", 0, 0)
self.glowFrame:SetFrameStrata("TOOLTIP")
self.glowFrame:SetSize(50,50)
self.glowFrame:SetScript("OnUpdate", DialogKey.GlowFrameUpdate)
self.glowFrame:Hide()
self.glowFrame.tex = self.glowFrame:CreateTexture()
self.glowFrame.tex:SetAllPoints()
self.glowFrame.tex:SetColorTexture(1,1,0,0.5)
self:ShowOldKeybindWarning()
self:CreateOptionsFrame()
end
function DialogKey:ChatCommand(input) -- Chat command handler
local args = {strsplit(" ", input:trim())}
if args[1] == "v" or args[1] == "ver" or args[1] == "version" then
DialogKey:Print(GAME_VERSION_LABEL..": |cffffd700"..GetAddOnMetadata("DialogKey","Version").."|r")
elseif args[1] == "add" or args[1] == "a" or args[1] == "watch" then
if args[2] then
DialogKey:WatchFrame(args[2])
else
DialogKey:AddMouseFocus()
end
elseif args[1] == "remove" or args[1] == "r" or args[1] == "unwatch" then
if args[2] then
DialogKey:UnwatchFrame(args[2])
else
DialogKey:RemoveMouseFocus()
end
elseif args[1] == "d" or args[1] == "dbg" or args[1] == "debug" then
DialogKey:ClickButtonsDebug()
else
-- Twice, since the first call only succeeds in opening the options panel itself; the second call opens the correct category
InterfaceOptionsFrame_OpenToCategory(self.options)
InterfaceOptionsFrame_OpenToCategory(self.options)
end
end
function DialogKey:Print(message,msgType) -- Prefixed print function
DEFAULT_CHAT_FRAME:AddMessage("|cffd2b48c[DialogKey]|r "..message.."|r")
end
function DialogKey:ShowOldKeybindWarning() -- Shows a popup warning the user that they've got old VEK binds
if not self.db.global.shownBindWarning then
self.db.global.shownBindWarning = true
local key1 = GetBindingKey("ACCEPTDIALOG")
local key2 = GetBindingKey("ACCEPTDIALOG_CHAT")
-- Treat only having the second key bound as only having the first key bound for simplicity
if key2 and not key1 then
key1 = key2
key2 = nil
end
local str
if key1 then
if key2 then
str = "DialogKey is a replacement of Versatile Enter Key, which is now obsolete.\n\nYour '" .. GetBindingText(key1) .. "' and '" .. GetBindingText(key2) .. "' keys are still bound to Versatile Enter Key actions. You should rebind them to their original actions if they were originally bound to something important!"
else
str = "DialogKey is a replacement of Versatile Enter Key, which is now obsolete.\n\nYour '" .. GetBindingText(key1) .. "' key is still bound to a Versatile Enter Key action. You should rebind it to its original action if it was originally bound to something important!"
end
end
if str then
StaticPopupDialogs["DIALOGKEY_OLDBINDWARNING"] = {
text = str,
button1 = "Open Keybinds",
button2 = OKAY,
timeout = 0,
whileDead = true,
hideOnEscape = true,
OnAccept = function()
KeyBindingFrame_LoadUI()
ShowUIPanel(KeyBindingFrame)
end
}
StaticPopup_Show("DIALOGKEY_OLDBINDWARNING")
end
end
end
-- Misc. Lua functions --
function DialogKey:print_r ( t ) -- Recursively print a table
local print_r_cache={}
local function sub_print_r(t,indent)
if (print_r_cache[tostring(t)]) then
print(indent.."*"..tostring(t))
else
print_r_cache[tostring(t)]=true
if (type(t)=="table") then
for pos,val in pairs(t) do
if (type(val)=="table") then
print(indent.."["..pos.."] => "..tostring(t).." {")
sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
print(indent..string.rep(" ",string.len(pos)+6).."}")
else
print(indent.."["..pos.."] => "..tostring(val))
end
end
else
print(indent..tostring(t))
end
end
end
sub_print_r(t," ")
end
function DialogKey:split(str, sep) -- Splits str along sep
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
string.gsub(str, pattern, function(c) fields[#fields+1] = c end)
return fields
end
function DialogKey:round(num, numDecimalPlaces) -- Round a number to x decimal places
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end