Quantcast

* Added a slash command to set a waypoint at the current location /wayb, /wayback (contributed by Lamalas)

James Whitehead II [12-21-08 - 20:34]
* Added a slash command to set a waypoint at the current location /wayb, /wayback (contributed by Lamalas)
* Added a slash command to set the crazy arrow to the closet waypoint in the current zone /cway, /closestway (contributed by Lamalas)
* Added an option that will automatically set the crazy arrow destination to the closest waypoint in your current zone
* Added TomTom:IsValidWaypoint(uid) to test if a given UID is currently valid
Filename
TomTom.lua
TomTom_Config.lua
TomTom_CrazyArrow.lua
TomTom_Waypoints.lua
diff --git a/TomTom.lua b/TomTom.lua
index 08c8656..bb42551 100755
--- a/TomTom.lua
+++ b/TomTom.lua
@@ -88,6 +88,7 @@ function TomTom:ADDON_LOADED(event, addon)
 					title_height = 0,
 					title_scale = 1,
 					title_alpha = 1,
+					setclosest = true,
 				},
 				minimap = {
 					enable = true,
@@ -919,6 +920,39 @@ for cidx,c in ipairs{GetMapContinents()} do
 	end
 end

+function TomTom:SetClosestWaypoint()
+	local c,z,x,y = Astrolabe:GetCurrentPlayerPosition()
+	local zone = TomTom:GetMapFile(c, z)
+	local closest_uid = nil
+	local closest_dist = nil
+	if waypoints[zone] then
+		for uid in pairs(waypoints[zone]) do
+			local dist,x,y = TomTom:GetDistanceToWaypoint(uid)
+			if (dist and closest_dist == nil) or (dist and dist < closest_dist) then
+				closest_dist = dist
+				closest_uid = uid
+			end
+		end
+	end
+	if closest_dist then
+		local data = waypoints[closest_uid]
+		TomTom:SetCrazyArrow(closest_uid, TomTom.profile.arrow.arrival, data.title)
+	end
+end
+
+SLASH_TOMTOM_CLOSEST_WAYPOINT1 = "/cway"
+SLASH_TOMTOM_CLOSEST_WAYPOINT2 = "/closestway"
+SlashCmdList["TOMTOM_CLOSEST_WAYPOINT"] = function(msg)
+	TomTom:SetClosestWaypoint()
+end
+
+SLASH_TOMTOM_WAYBACK1 = "/wayb"
+SLASH_TOMTOM_WAYBACK2 = "/wayback"
+SlashCmdList["TOMTOM_WAYBACK"] = function(msg)
+	local backc,backz,backx,backy = Astrolabe:GetCurrentPlayerPosition()
+	TomTom:AddZWaypoint(backc, backz, backx*100, backy*100, L["Wayback"])
+end
+
 SLASH_TOMTOM_WAY1 = "/way"
 SLASH_TOMTOM_WAY2 = "/tway"
 SLASH_TOMTOM_WAY3 = "/tomtomway"
diff --git a/TomTom_Config.lua b/TomTom_Config.lua
index 12d84ef..801c54d 100644
--- a/TomTom_Config.lua
+++ b/TomTom_Config.lua
@@ -201,8 +201,16 @@ local function createconfig()
 				width = "double",
 				arg = "arrow.noclick",
 			},
-			heredistance = {
+			setclosest = {
 				order = 8,
+				type = "toggle",
+				name = L["Automatically set to next closest waypoint"],
+				desc = L["When the current waypoint is cleared (either by the user or automatically) and this option is set, TomTom will automatically set the closest waypoint in the current zone as active waypoint."],
+				width = "double",
+				arg = "arrow.setclosest",
+			},
+			heredistance = {
+				order = 9,
 				type = "range",
 				name = L["\"Arrival Distance\""],
 				desc = L["This setting will control the distance at which the waypoint arrow switches to a downwards arrow, indicating you have arrived at your destination"],
@@ -212,7 +220,7 @@ local function createconfig()
 			display = {
 				type = "group",
 				name = L["Arrow display"],
-				order = 9,
+				order = 10,
 				inline = true,
 				args = {
 					help = {
diff --git a/TomTom_CrazyArrow.lua b/TomTom_CrazyArrow.lua
index aed19d0..8ca2606 100644
--- a/TomTom_CrazyArrow.lua
+++ b/TomTom_CrazyArrow.lua
@@ -137,7 +137,19 @@ local function OnUpdate(self, elapsed)
 	end

 	local dist,x,y = TomTom:GetDistanceToWaypoint(active_point)
+
+	-- The only time we cannot calculate the distance is when the waypoint
+	-- is on another continent, or we are in an instance
 	if not dist or IsInInstance() then
+		if not TomTom:IsValidWaypoint(active_point) then
+			active_point = nil
+			-- Change the crazy arrow to point at the closest waypoint
+			if TomTom.profile.arrow.setclosest then
+				TomTom:SetClosestWaypoint()
+				return
+			end
+		end
+
 		self:Hide()
 		return
 	end
@@ -286,6 +298,10 @@ local dropdown_info = {
 			text = L["Clear waypoint from crazy arrow"],
 			func = function()
 				active_point = nil
+				if TomTom.profile.arrow.setclosest then
+					TomTom:SetClosestWaypoint()
+					return
+				end
 			end,
 		},
 		{
diff --git a/TomTom_Waypoints.lua b/TomTom_Waypoints.lua
index 2e6a191..5ec0919 100644
--- a/TomTom_Waypoints.lua
+++ b/TomTom_Waypoints.lua
@@ -188,6 +188,11 @@ function TomTom:SetWaypoint(c, z, x, y, callbacks, show_minimap, show_world)
 	return point.uid
 end

+function TomTom:IsValidWaypoint(uid)
+	local obj = resolveuid(uid, false)
+	return obj and true or false
+end
+
 function TomTom:HideWaypoint(uid, minimap, worldmap)
 	local point = resolveuid(uid)
 	if point then
@@ -214,6 +219,7 @@ function TomTom:ShowWaypoint(uid)
 	end
 end

+-- This function removes the waypoint from the active set
 function TomTom:ClearWaypoint(uid)
 	local point = resolveuid(uid, true)
 	if point then