Quantcast

Much safer method of determining quest coords

James Whitehead II [12-01-10 - 18:25]
Much safer method of determining quest coords

Now the map does not need to be opened at all, and things seem to
function properly. The arrow also is capable of updating when the
closest quest POI changes.
Filename
TomTomLite.lua
diff --git a/TomTomLite.lua b/TomTomLite.lua
index 52f2edf..580d179 100644
--- a/TomTomLite.lua
+++ b/TomTomLite.lua
@@ -19,6 +19,9 @@ function addon:Initialize()
     self:RegisterEvent("QUEST_POI_UPDATE", "ObjectivesChanged")
     self:RegisterEvent("QUEST_LOG_UPDATE", "ObjectivesChanged")
     self:RegisterMessage("TOMTOMLITE_WAYPOINT_ADDED")
+    hooksecurefunc("WatchFrame_Update", function()
+        addon:ObjectivesChanged()
+    end)
 end

 function addon:CreateCrazyArrow(name, parent)
@@ -88,6 +91,11 @@ function addon:CreateCrazyArrow(name, parent)
 end

 function addon:AddWaypoint(map, floor, x, y, opt)
+    assert(type(map) == "number")
+    assert(type(floor) == "number")
+    assert(type(x) == "number")
+    assert(type(y) == "number")
+
     local waypoint = {map, floor, x, y}
     if type(opt) == "table" then
         for k, v in pairs(opt) do
@@ -104,7 +112,7 @@ end
 function addon:TOMTOMLITE_WAYPOINT_ADDED(msg, waypoint, ...)
     local zone, floor, x, y = unpack(waypoint)
     local lzone = self.mapdata:MapLocalize(zone)
-    self:Printf("Added a waypoint at (%.2f, %.2f) in %s", x * 100, y * 100, lzone)
+    --self:Printf("Added a waypoint at (%.2f, %.2f) in %s", x * 100, y * 100, lzone)

     self.arrow.waypoint = waypoint
     self.arrow.title:SetText(waypoint.title or L["Unknown waypoint"])
@@ -154,14 +162,18 @@ function addon:Scan()
     end

     local title = GetQuestLogTitle(questIndex)
-
-    ShowUIPanel(WorldMapFrame)
-    HideUIPanel(WorldMapFrame)
+    local qid = select(9, GetQuestLogTitle(questIndex))
+
+    QuestPOIUpdateIcons()
+    local completed, x, y, objective = QuestPOIGetIconInfo(qid)
+    local map, floor = GetCurrentMapAreaID()

-    local frame = findQuestFrameFromQuestIndex(questIndex)
-    if frame then
-        local map, floor, x, y = POIAnchorToCoord(frame.poiIcon)
+    if not floor then floor = 0 end
+    if completed then
+        title = "Turn in: " .. title
+    end
+
+    if x and y and map and floor then
         self:AddWaypoint(map, floor, x, y, {title = title})
     end
 end
-