Quantcast

A number of enhancements and minor bug fixes

James Whitehead II [03-28-10 - 17:41]
A number of enhancements and minor bug fixes

  * Added a 'ping' sound that can be played when you've arrived at your destination.  The sound will be played when you're within the 'arrival distance', as set under the "Waypoint Arrow" configuration.  This is also where the option can be found.
  * Enabled dual positioning for world map coordinates, hopefully the placement now works properly.
  * Added a function TomTom:WaypointExists(c, z, x, y, desc) which returns true or false
  * Fixed POI integration (from what I tested)
  * Added an 'automatic objectives waypoint' setting that will automatically set waypoints to your closest quest objective.  I'm not sure how useful this will be, it's disabled by default.
Filename
Media/PingLicense.txt
Media/ping.mp3
TomTom.lua
TomTom_Config.lua
TomTom_POIIntegration.lua
diff --git a/Media/PingLicense.txt b/Media/PingLicense.txt
new file mode 100644
index 0000000..55ff370
--- /dev/null
+++ b/Media/PingLicense.txt
@@ -0,0 +1 @@
+The sound file included in this directory is 'ping.mp3' from BristolStories on freesound.org.  More information about the audio file can be obtained at: http://www.freesound.org/samplesViewSingle.php?id=51702
diff --git a/Media/ping.mp3 b/Media/ping.mp3
new file mode 100644
index 0000000..8c78931
Binary files /dev/null and b/Media/ping.mp3 differ
diff --git a/TomTom.lua b/TomTom.lua
index 78806fe..aa3fccf 100755
--- a/TomTom.lua
+++ b/TomTom.lua
@@ -90,6 +90,7 @@ function TomTom:ADDON_LOADED(event, addon)
 					title_scale = 1,
 					title_alpha = 1,
 					setclosest = true,
+                    enablePing = false,
 				},
 				minimap = {
 					enable = true,
@@ -123,6 +124,7 @@ function TomTom:ADDON_LOADED(event, addon)
                 poi = {
                     enable = true,
                     modifier = "C",
+                    setClosest = false,
                 },
 			},
 		}
@@ -233,6 +235,17 @@ function TomTom:ZoneChanged()
 	self:ShowHideCoordBlock()
 end

+-- Hook some global functions so we know when the world map size changes
+local mapSizedUp = not (WORLDMAP_SETTINGS.size == WORLDMAP_WINDOWED_SIZE);
+hooksecurefunc("WorldMap_ToggleSizeUp", function()
+    mapSizedUp = true
+    TomTom:ShowHideWorldCoords()
+end)
+hooksecurefunc("WorldMap_ToggleSizeDown", function()
+    mapSizedUp = false
+    TomTom:ShowHideWorldCoords()
+end)
+
 function TomTom:ShowHideWorldCoords()
 	-- Bail out if we're not supposed to be showing this frame
 	if self.profile.mapcoords.playerenable or self.db.profile.mapcoords.cursorenable then
@@ -240,15 +253,19 @@ function TomTom:ShowHideWorldCoords()
 		if not TomTomWorldFrame then
 			TomTomWorldFrame = CreateFrame("Frame", nil, WorldMapFrame)
 			TomTomWorldFrame.Player = TomTomWorldFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
-			TomTomWorldFrame.Player:SetPoint("RIGHT", WorldMapPositioningGuide, "BOTTOM", -15, 2)
-
 			TomTomWorldFrame.Cursor = TomTomWorldFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
-			TomTomWorldFrame.Cursor:SetPoint("LEFT", WorldMapPositioningGuide, "BOTTOM", 15, 2)
-
 			TomTomWorldFrame:SetScript("OnUpdate", WorldMap_OnUpdate)
 		end

-		TomTomWorldFrame.Player:Hide()
+        if mapSizedUp then
+            TomTomWorldFrame.Player:SetPoint("RIGHT", WorldMapPositioningGuide, "BOTTOM", -15, 15)
+            TomTomWorldFrame.Cursor:SetPoint("LEFT", WorldMapPositioningGuide, "BOTTOM", 15, 15)
+        else
+            TomTomWorldFrame.Player:SetPoint("RIGHT", WorldMapPositioningGuide, "BOTTOM", -40, 2)
+            TomTomWorldFrame.Cursor:SetPoint("LEFT", WorldMapPositioningGuide, "BOTTOM", -15, 2)
+        end
+
+        TomTomWorldFrame.Player:Hide()
 		TomTomWorldFrame.Cursor:Hide()

 		if self.profile.mapcoords.playerenable then
@@ -655,6 +672,12 @@ local function _both_clear_distance(event, uid, range, distance, lastdistance)
 	end
 end

+local function _both_ping_arrival(event, uid, range, distance, lastdistance)
+    if TomTom.profile.arrow.enablePing then
+        PlaySoundFile("Interface\\AddOns\\TomTom\\Media\\ping.mp3")
+    end
+end
+
 local function _remove(event, uid)
 	local data = waypoints[uid]
 	local key = string.format("%d:%s", data.coord, data.title or "")
@@ -737,10 +760,23 @@ function TomTom:AddZWaypoint(c, z, x, y, desc, persistent, minimap, world, custo
 	end

 	local cleardistance = self.profile.persistence.cleardistance
-	if cleardistance > 0 then
-		callbacks.distance[cleardistance] = _both_clear_distance
+    local arrivaldistance = self.profile.arrow.arrival
+
+    if cleardistance == arrivaldistance then
+        callbacks.distance[cleardistance] = function(...)
+            _both_clear_distance(...);
+            _both_ping_arrival(...);
+        end
+    else
+        if cleardistance > 0 then
+            callbacks.distance[cleardistance] = _both_clear_distance
+        end
+        if arrivaldistance > 0 then
+            callbacks.distance[arrivaldistance] = _both_ping_arrival
+        end
 	end

+
 	-- Default values
 	if persistent == nil then persistent = self.profile.persistence.savewaypoints end
 	if minimap == nil then minimap = self.profile.minimap.enable end
@@ -799,6 +835,26 @@ function TomTom:AddZWaypoint(c, z, x, y, desc, persistent, minimap, world, custo
 	return uid
 end

+function TomTom:WaypointExists(c, z, x, y, desc)
+    local coord = self:GetCoord(x / 100, y / 100)
+    local zone = self:GetMapFile(c, z)
+
+    if not zone then
+        return
+    end
+
+    if waypoints[zone] then
+        for uid in pairs(waypoints[zone]) do
+            local data = waypoints[uid]
+            if data.title == desc then
+                return true
+            else
+                return false
+            end
+        end
+    end
+end
+
 function TomTom:SetCustomWaypoint(c,z,x,y,callback,minimap,world, silent)
 	return self:AddZWaypoint(c, z, x, y, desc, false, minimap, world, callback, silent)
 end
diff --git a/TomTom_Config.lua b/TomTom_Config.lua
index f8b3015..c3dadef 100644
--- a/TomTom_Config.lua
+++ b/TomTom_Config.lua
@@ -219,6 +219,14 @@ local function createconfig()
 				min = 0, max = 150, step = 5,
 				arg = "arrow.arrival",
 			},
+            enablePing = {
+                order = 9.5,
+                type = "toggle",
+                name = L["Play a sound when arriving at a waypoint"],
+                desc = L["When you 'arrive' at a waypoint (this distance is controlled by the 'Arrival Distance' setting in this group) a sound can be played to indicate this.  You can enable or disable this sound using this setting."],
+                width = "double",
+                arg = "arrow.enablePing",
+            },
 			display = {
 				type = "group",
 				name = L["Arrow display"],
@@ -604,7 +612,7 @@ local function createconfig()
 			},
 			corpse_arrow = {
 				type = "toggle",
-				order = 5,
+				order = 6,
 				name = L["Automatically set a waypoint when I die"],
 				desc = L["TomTom can automatically set a waypoint when you die, guiding you back to your corpse"],
 				width = "double",
@@ -629,7 +637,7 @@ local function createconfig()
 			enable = {
 				order = 2,
 				type = "toggle",
-				name = L["Enable quest objective integration"],
+				name = L["Enable quest objective click integration"],
 				desc = L["Enables the setting of waypoints when modified-clicking on quest objectives"],
 				width = "double",
 				arg = "poi.enable",
@@ -650,6 +658,14 @@ local function createconfig()
 				},
 				arg = "poi.modifier",
 			},
+            enableClosest = {
+				order = 4,
+				type = "toggle",
+				name = L["Enable automatic quest objective waypoints"],
+				desc = L["Enables the automatic setting of quest objective waypoints based on which objective is closest to your current location.  This setting WILL override the setting of manual waypoints."],
+				width = "double",
+				arg = "poi.setClosest",
+			},
 		},
 	} -- End POI Integration settings

diff --git a/TomTom_POIIntegration.lua b/TomTom_POIIntegration.lua
index 4ebdb89..325476b 100644
--- a/TomTom_POIIntegration.lua
+++ b/TomTom_POIIntegration.lua
@@ -1,3 +1,7 @@
+local hookEnabled = true;
+local modifier;
+local watchframeHookEnabled = false;
+
 local function POIAnchorToCoord(poiframe)
     local point, relto, relpoint, x, y = poiframe:GetPoint()
     local frame = WorldMapDetailFrame
@@ -20,8 +24,36 @@ local modTbl = {
     S = IsShiftKeyDown,
 }

-local hookEnabled = true;
-local modifier;
+local function findQuestFrameFromQuestIndex(questId)
+    -- Try to find the correct quest frame
+    for i = 1, MAX_NUM_QUESTS do
+        local questFrame = _G["WorldMapQuestFrame"..i];
+        if ( not questFrame ) then
+            break
+        elseif ( questFrame.questId == questId ) then
+            return questFrame
+        end
+    end
+end
+
+local function setQuestWaypoint(self)
+    local c, z = GetCurrentMapContinent(), GetCurrentMapZone();
+    local x, y = POIAnchorToCoord(self)
+
+    local qid = self.questId
+
+    local title;
+    if self.quest and self.quest.questLogIndex then
+        title = GetQuestLogTitle(self.quest.questLogIndex)
+    elseif self.questLogIndex then
+        title = GetQuestLogTitle(self.questLogIndex)
+    else
+        title = "Quest #" .. qid .. " POI"
+    end
+
+    local uid = TomTom:AddZWaypoint(c, z, x, y, title)
+    return uid
+end

 -- desc, persistent, minimap, world, custom_callbacks, silent, crazy)
 local function poi_OnClick(self, button)
@@ -44,26 +76,16 @@ local function poi_OnClick(self, button)
     end

     if self.parentName == "WatchFrameLines" then
-        local questFrame = _G["WorldMapQuestFrame"..self.questLogIndex];
-        local selected = WorldMapQuestScrollChildFrame.selected
-        local poiIcon = selected.poiIcon;
-        self = poiIcon
-    end
-
-    local c, z = GetCurrentMapContinent(), GetCurrentMapZone();
-    local x, y = POIAnchorToCoord(self)
-
-    local qid = self.questId
-
-    local title;
-    if self.quest.questLogIndex then
-        title = GetQuestLogTitle(self.quest.questLogIndex)
-    else
-        title = "Quest #" .. qid .. " POI"
+        local questFrame = findQuestFrameFromQuestIndex(self.questId)
+        if not questFrame then
+            return
+        else
+            self = questFrame.poiIcon
+        end
     end
-
-    local uid = TomTom:AddZWaypoint(c, z, x, y, title)
-end
+
+    return setQuestWaypoint(self)
+ end

 local hooked = {}
 hooksecurefunc("QuestPOI_DisplayButton", function(parentName, buttonType, buttonIndex, questId)
@@ -77,7 +99,47 @@ hooksecurefunc("QuestPOI_DisplayButton", function(parentName, buttonType, button
       end
 end)

+-- This code will enable auto-tracking of closest quest objectives.  To
+-- accomplish this, it hooks the WatchFrame_Update function, and when it
+-- is called, it sets a waypoint to the closest quest id.
+local function updateClosestPOI()
+    local questIndex = GetQuestIndexForWatch(1);
+    if ( questIndex ) then
+        local title, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily, questID = GetQuestLogTitle(questIndex);
+        local requiredMoney = GetQuestLogRequiredMoney(questIndex);
+        numObjectives = GetNumQuestLeaderBoards(questIndex);
+        if ( isComplete and isComplete < 0 ) then
+            isComplete = false;
+        elseif ( numObjectives == 0 and playerMoney >= requiredMoney ) then
+            isComplete = true;
+        end
+
+        -- check filters
+        local filterOK = true;
+        if ( isComplete and bit.band(WATCHFRAME_FILTER_TYPE, WATCHFRAME_FILTER_COMPLETED_QUESTS) ~= WATCHFRAME_FILTER_COMPLETED_QUESTS ) then
+            filterOK = false;
+        elseif ( bit.band(WATCHFRAME_FILTER_TYPE, WATCHFRAME_FILTER_REMOTE_ZONES) ~= WATCHFRAME_FILTER_REMOTE_ZONES and not LOCAL_MAP_QUESTS[questID] ) then
+            filterOK = false;
+        end
+
+        if filterOK then
+            -- Set a waypoint for this POI, it should be the higehst
+            local questFrame = findQuestFrameFromQuestIndex(questID)
+            if questFrame then
+                setQuestWaypoint(questFrame.poiIcon)
+            end
+        end
+    end
+end
+
+hooksecurefunc("WatchFrame_Update", function()
+    if watchframeHookEnabled then
+        updateClosestPOI()
+    end
+end)
+
 function TomTom:EnableDisablePOIIntegration()
     hookEnabled = TomTom.profile.poi.enable
     modifier = TomTom.profile.poi.modifier
+    watchframeHookEnabled = TomTom.profile.poi.setClosest
 end