-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTomTom_POIIntegration.lua
226 lines (189 loc) · 6.89 KB
/
TomTom_POIIntegration.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
225
226
local addonName, addon = ...
local astrolabe = addon.astrolabe
local enableClicks = true -- True if waypoint-clicking is enabled to set points
local enableClosest = true -- True if 'Automatic' quest waypoints are enabled
local modifier -- A string representing click-modifiers "CAS", etc.
local modTbl = {
C = IsControlKeyDown,
A = IsAltKeyDown,
S = IsShiftKeyDown,
}
local L = TomTomLocals
-- This function and the related events/hooks are used to automatically
-- update the crazy arrow to the closest quest waypoint.
local lastWaypoint
local scanning -- This function is not re-entrant, stop that
local function getQIDFromIndex(questIndex)
return (select(8, GetQuestLogTitle(questIndex)))
end
local function ObjectivesChanged()
-- This function should only run if enableClosest is set
if not enableClosest then
return
end
-- This function may be called while we are processing this function
-- so stop that from happening.
if scanning then
return
else
scanning = true
end
local map, floor = GetCurrentMapAreaID()
local floors = astrolabe:GetNumFloors(map)
floor = (floors == 0 and 0 or 1)
local px, py = GetPlayerMapPosition("player")
-- Bail out if we can't get the player's position
if not px or not py or px <= 0 or py <= 0 then
scanning = false
return
end
-- THIS CVAR MUST BE CHANGED BACK!
local cvar = GetCVarBool("questPOI")
SetCVar("questPOI", 1)
local closest
local closestdist = math.huge
-- This function relies on the above CVar being set, and updates the icon
-- position information so it can be queries via the API
QuestPOIUpdateIcons()
-- Scan through every quest that is tracked, and find the closest one
local watchIndex = 1
while true do
local questIndex = GetQuestIndexForWatch(watchIndex)
if not questIndex then
break
end
local qid = getQIDFromIndex(questIndex)
local completed, x, y, objective = QuestPOIGetIconInfo(qid)
if x and y then
local dist, xd, yd = astrolabe:ComputeDistance(map, floor, px, py, map, floor, x, y)
if dist < closestdist then
closest = watchIndex
closestdist = dist
end
end
watchIndex = watchIndex + 1
end
if closest then
local questIndex = GetQuestIndexForWatch(closest)
local title = GetQuestLogTitle(questIndex)
local qid = getQIDFromIndex(questIndex)
local completed, x, y, objective = QuestPOIGetIconInfo(qid)
if completed then
title = "Turn in: " .. title
end
local setWaypoint = true
if lastWaypoint then
-- This is a hack that relies on the UID format, do not use this
-- in your addons, please.
local pm, pf, px, py = unpack(lastWaypoint)
if map == pm and floor == pf and x == px and y == py and lastWaypoint.title == title then
-- This is the same waypoint, do nothing
setWaypoint = false
else
-- This is a new waypoint, clear the previous one
TomTom:RemoveWaypoint(lastWaypoint)
end
end
if setWaypoint then
-- Set the new waypoint
lastWaypoint = TomTom:AddMFWaypoint(map, floor, x, y, {
title = title,
persistent = false,
arrivaldistance = TomTom.profile.poi.arrival,
})
-- Check and see if the Crazy arrow is empty, and use it if so
if TomTom:IsCrazyArrowEmpty() then
TomTom:SetCrazyArrow(lastWaypoint, TomTom.profile.poi.arrival, title)
end
end
else
-- No closest waypoint was found, so remove one if its already set
if lastWaypoint then
TomTom:RemoveWaypoint(lastWaypoint)
lastWaypoint = nil
end
end
SetCVar("questPOI", cvar and 1 or 0)
scanning = false
end
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("QUEST_POI_UPDATE")
eventFrame:RegisterEvent("QUEST_LOG_UPDATE")
eventFrame:SetScript("OnEvent", function(self, event, ...)
if event == "QUEST_POI_UPDATE" then
ObjectivesChanged()
elseif event == "QUEST_LOG_UPDATE" then
ObjectivesChanged()
end
end)
local poiclickwaypoints = {}
local function poi_OnClick(self, button)
if not enableClicks then
return
end
if button == "RightButton" then
for i = 1, #modifier do
local mod = modifier:sub(i, i)
local func = modTbl[mod]
if not func() then
return
end
end
else
return
end
-- Run our logic, and set a waypoint for this button
local m, f = GetCurrentMapAreaID()
local questIndex = self.quest and self.quest.questLogIndex
if not questIndex and self.questId then
-- Lookup the questIndex for the given questId
for idx = 1, GetNumQuestLogEntries(), 1 do
local qid = getQIDFromIndex(idx)
if qid == self.questId then
questIndex = idx
end
end
end
if not questIndex and self.index then
questIndex = GetQuestIndexForWatch(self.index)
end
local title = GetQuestLogTitle(questIndex)
local qid = getQIDFromIndex(questIndex)
local completed, x, y, objective = QuestPOIGetIconInfo(qid)
if completed then
title = "Turn in: " .. title
end
if not x or not y then
-- No coordinate information for this quest/objective
local header = "|cFF33FF99TomTom|r"
print(L["%s: No coordinate information found for '%s' at this map level"]:format(header, title))
return
end
local key = TomTom:GetKeyArgs(m, f, x, y, title)
local alreadySet = false
if poiclickwaypoints[key] then
local uid = poiclickwaypoints[key]
-- Check to see if it has been removed by the user
if TomTom:IsValidWaypoint(uid) then
alreadySet = true
end
end
if not alreadySet then
local uid = TomTom:AddMFWaypoint(m, f, x, y, {
title = title,
arrivaldistance = TomTom.profile.poi.arrival,
})
poiclickwaypoints[key] = uid
end
end
function TomTom:EnableDisablePOIIntegration()
enableClicks= TomTom.profile.poi.enable
modifier = TomTom.profile.poi.modifier
enableClosest = TomTom.profile.poi.setClosest
if not enableClosest and lastWaypoint then
TomTom:RemoveWaypoint(lastWaypoint)
lastWaypoint = nil
elseif enableClosest then
ObjectivesChanged()
end
end