Quantcast

Major update to TomTom, everything except CrazyTaxi queuing "works"

James Whitehead Ii [03-22-08 - 15:26]
Major update to TomTom, everything except CrazyTaxi queuing "works"
Filename
TomTom.lua
TomTom_Config.lua
TomTom_CrazyArrow.lua
TomTom_Waypoints.lua
diff --git a/TomTom.lua b/TomTom.lua
index 94276c3..f4a5050 100755
--- a/TomTom.lua
+++ b/TomTom.lua
@@ -76,8 +76,8 @@ function TomTom:ADDON_LOADED(event, addon)
 				},
 				worldmap = {
 					enable = true,
-					otherzone = true,
 					tooltip = true,
+					otherzone = true,
 					clickcreate = true,
 				},
 				comm = {
@@ -117,6 +117,7 @@ function TomTom:ADDON_LOADED(event, addon)
 		self:RegisterEvent("CHAT_MSG_ADDON")

 		self:ReloadOptions()
+		self:ReloadWaypoints()
 	end
 end

@@ -126,17 +127,37 @@ function TomTom:ReloadOptions()

 	self:ShowHideWorldCoords()
 	self:ShowHideCoordBlock()
+	self:ShowHideCrazyArrow()

 end

 function TomTom:ReloadWaypoints()
-end
+	-- Hide any waypoints that might be currently set
+	for uid,point in pairs(waypoints) do
+		self:ClearWaypoint(uid)
+	end

+	waypoints = {}
+	self.waypoints = self.waydb.profile

+	local pc,pz = self:GetCurrentCZ()
+
+	for zone,data in pairs(self.waypoints) do
+		local c,z = self:GetCZ(zone)
+		local same = (c == pc) and (z == pz)
+		local minimap = self.profile.minimap.otherzone or same
+		local world = self.profile.worldmap.otherzone or same
+		for idx,waypoint in ipairs(data) do
+			local coord,title = waypoint:match("^(%d+):(.*)$")
+			local x,y = self:GetXY(coord)
+			self:AddZWaypoint(c, z, x*100, y*100, desc, false, minimap, world)
+		end
+	end
+end

 function TomTom:ShowHideWorldCoords()
 	-- Bail out if we're not supposed to be showing this frame
-	if self.db.profile.mapcoords.playerenable or self.db.profile.mapcoords.cursorenable then
+	if self.profile.mapcoords.playerenable or self.db.profile.mapcoords.cursorenable then
 		-- Create the frame if it doesn't exist
 		if not TomTomWorldFrame then
 			TomTomWorldFrame = CreateFrame("Frame", nil, WorldMapFrame)
@@ -152,11 +173,11 @@ function TomTom:ShowHideWorldCoords()
 		TomTomWorldFrame.Player:Hide()
 		TomTomWorldFrame.Cursor:Hide()

-		if self.db.profile.mapcoords.playerenable then
+		if self.profile.mapcoords.playerenable then
 			TomTomWorldFrame.Player:Show()
 		end

-		if self.db.profile.mapcoords.cursorenable then
+		if self.profile.mapcoords.cursorenable then
 			TomTomWorldFrame.Cursor:Show()
 		end

@@ -169,7 +190,7 @@ end

 function TomTom:ShowHideCoordBlock()
 	-- Bail out if we're not supposed to be showing this frame
-	if self.db.profile.block.enable then
+	if self.profile.block.enable then
 		-- Create the frame if it doesn't exist
 		if not TomTomBlock then
 			-- Create the coordinate display
@@ -209,7 +230,7 @@ function TomTom:ShowHideCoordBlock()
 		-- Show the frame
 		TomTomBlock:Show()

-		local opt = self.db.profile.block
+		local opt = self.profile.block

 		-- Update the backdrop color, and border color
 		TomTomBlock:SetBackdropColor(unpack(opt.bgcolor))
@@ -267,6 +288,21 @@ end
 --  Dropdown menu code
 -------------------------------------------------------------------]]--

+StaticPopupDialogs["TOMTOM_REMOVE_ALL_CONFIRM"] = {
+	text = L["Are you sure you would like to remove ALL TomTom waypoints?"],
+	button1 = L["Yes"],
+	button2 = L["No"],
+	OnAccept = function()
+		for uid,point in pairs(waypoints) do
+			TomTom.waydb:ResetProfile()
+		end
+		TomTom:ReloadWaypoints()
+	end,
+	timeout = 30,
+	whileDead = 1,
+	hideOnEscape = 1,
+}
+
 local dropdown_info = {
 	-- Define level one elements here
 	[1] = {
@@ -283,6 +319,56 @@ local dropdown_info = {
 				--TomTom:PrintF("Removing waypoint %0.2f, %0.2f in %s", data.x, data.y, data.zone)
 			end,
 		},
+		{ -- Remove all waypoints from this zone
+			text = L["Remove all waypoints from this zone"],
+			func = function()
+				local uid = TomTom.dropdown.uid
+				local data = waypoints[uid]
+				for uid in pairs(waypoints[data.zone]) do
+					TomTom:RemoveWaypoint(uid)
+				end
+			end,
+		},
+		{ -- Remove ALL waypoints
+			text = L["Remove all waypoints"],
+			func = function()
+				StaticPopup_Show("TOMTOM_REMOVE_ALL_CONFIRM")
+			end,
+		},
+		{ -- Save this waypoint
+			text = L["Save this waypoint between sessions"],
+			checked = function()
+				return TomTom:UIDIsSaved(TomTom.dropdown.uid)
+			end,
+			func = function()
+				-- Check to see if it's already saved
+				local uid = TomTom.dropdown.uid
+				if TomTom:UIDIsSaved(uid) then
+					local data = waypoints[uid]
+					if data then
+						local key = string.format("%d:%s", data.coord, data.title or "")
+						local zone = data.zone
+						local sv = TomTom.waypoints[zone]
+
+						-- Find the entry in the saved variable
+						for idx,entry in ipairs(sv) do
+							if entry == key then
+								table.remove(sv, idx)
+								return
+							end
+						end
+					end
+				else
+					local data = waypoints[uid]
+					if data then
+						local key = string.format("%d:%s", data.coord, data.title or "")
+						local zone = data.zone
+						local sv = TomTom.waypoints[zone]
+						table.insert(sv, key)
+					end
+				end
+			end,
+		},
 	}
 }

@@ -302,10 +388,35 @@ local function init_dropdown(level)

 	-- Add the buttons to the menu
 	for idx,entry in ipairs(info) do
+		if type(entry.checked) == "function" then
+			-- Make this button dynamic
+			local new = {}
+			for k,v in pairs(entry) do new[k] = v end
+			new.checked = new.checked()
+			entry = new
+		end
 		UIDropDownMenu_AddButton(entry, level)
 	end
 end

+function TomTom:UIDIsSaved(uid)
+	local data = waypoints[uid]
+	if data then
+		local key = string.format("%d:%s", data.coord, data.title or "")
+		local zone = data.zone
+		local sv = TomTom.waypoints[zone]
+
+		-- Find the entry in the saved variable
+		for idx,entry in ipairs(sv) do
+			if entry == key then
+				return true
+			end
+		end
+	end
+	return false
+end
+
+
 --[[-------------------------------------------------------------------
 --  Define callback functions
 -------------------------------------------------------------------]]--
@@ -345,42 +456,79 @@ local function _both_tooltip_update(event, tooltip, uid, dist)
 end

 local function _both_clear_distance(event, uid, range, distance, lastdistance)
-	self:RemoveWaypoint(uid)
+	TomTom:RemoveWaypoint(uid)
 end

-local function _both_remove(event, uid)
+local function _remove(event, uid)
 	local data = waypoints[uid]
-	local sv = self.db.profile.waypoints[data.zone]
+	local key = string.format("%d:%s", data.coord, data.title or "")
+	local zone = data.zone
+	local sv = TomTom.waypoints[zone]

 	-- Find the entry in the saved variable
 	for idx,entry in ipairs(sv) do
-		if entry.uid == uid then
+		if entry == key then
 			table.remove(sv, idx)
 			break
 		end
 	end
+
+	-- Remove this entry from the waypoints table
+	waypoints[uid] = nil
+	if waypoints[zone] then
+		waypoints[zone][uid] = nil
+	end
 end

 local function noop() end

--- TODO: Make this not suck
-function TomTom:AddWaypoint(x, y, desc, persistent, noWorld)
+function TomTom:GetCurrentCZ()
 	local oc,oz = Astrolabe:GetCurrentPlayerPosition()
 	SetMapToCurrentZone()
 	local c,z = Astrolabe:GetCurrentPlayerPosition()
 	if oc and oz then
 		SetMapZoom(oc,oz)
 	end
+	return c,z
+end
+
+function TomTom:RemoveWaypoint(uid)
+	local data = waypoints[uid]
+	self:ClearWaypoint(uid)
+
+	if data then
+		local key = string.format("%d:%s", data.coord, data.title or "")
+		local zone = data.zone
+		local sv = TomTom.waypoints[zone]
+
+		-- Find the entry in the saved variable
+		for idx,entry in ipairs(sv) do
+			if entry == key then
+				table.remove(sv, idx)
+				break
+			end
+		end
+	end
+	-- Remove this entry from the waypoints table
+	waypoints[uid] = nil
+	if waypoints[zone] then
+		waypoints[zone][uid] = nil
+	end
+end
+
+-- TODO: Make this not suck
+function TomTom:AddWaypoint(x, y, desc, persistent, minimap, world)
+	local c,z = self:GetCurrentCZ()

 	if not c or not z or c < 1 then
 		--self:Print("Cannot find a valid zone to place the coordinates")
 		return
 	end

-	return self:AddZWaypoint(c, z, x, y, desc, persistent, noWorld)
+	return self:AddZWaypoint(c, z, x, y, desc, persistent, minimap, world)
 end

-function TomTom:AddZWaypoint(c, z, x, y, desc, persistent, noWorld)
+function TomTom:AddZWaypoint(c, z, x, y, desc, persistent, minimap, world)
 	local callbacks = {
 		minimap = {
 			onclick = _both_onclick,
@@ -392,21 +540,23 @@ function TomTom:AddZWaypoint(c, z, x, y, desc, persistent, noWorld)
 			tooltip_show = _world_tooltip_show,
 			tooltip_update = _both_tooltip_show,
 		},
+		remove = _remove,
 		distance = {},
 	}

-	if persistent == nil then
-		persistent = self.db.profile.persistence.savewaypoints
-	end
-
+	-- Default values
+	if persistent == nil then persistent = self.profile.persistence.savewaypoints end
+	if minimap == nil then minimap = true end
+	if world == nil then world = true end
+
 	if not persistent then
-		local cleardistance = self.db.profile.persistence.cleardistance
+		local cleardistance = self.profile.persistence.cleardistance
 		callbacks.distance[cleardistance] = _both_clear_distance
 		callbacks.distance[cleardistance+1] = noop
 	end

-	local uid = self:SetWaypoint(c,z,x/100,y/100, callbacks, (not noWorld))
-	self:SetCrazyArrow(uid, self.db.profile.arrow.arrival, desc)
+	local uid = self:SetWaypoint(c,z,x/100,y/100, callbacks, minimap, world)
+	self:SetCrazyArrow(uid, self.profile.arrow.arrival, desc)

 	local coord = self:GetCoord(x / 100, y / 100)
 	local zone = self:GetMapFile(c, z)
@@ -419,10 +569,16 @@ function TomTom:AddZWaypoint(c, z, x, y, desc, persistent, noWorld)
 		zone = zone,
 	}

+	if not waypoints[zone] then
+		waypoints[zone] = {}
+	end
+
+	waypoints[zone][uid] = true
+
 	-- If this is a persistent waypoint, then add it to the waypoints table
 	if persistent then
-		local data = string.format("%d:%s", coord, title or "")
-		table.insert(self.db.profile.waypoints[zone], data)
+		local data = string.format("%d:%s", coord, desc or "")
+		table.insert(self.waypoints[zone], data)
 	end
 end

diff --git a/TomTom_Config.lua b/TomTom_Config.lua
index 2b138aa..ad19cfe 100644
--- a/TomTom_Config.lua
+++ b/TomTom_Config.lua
@@ -34,6 +34,10 @@ local function createconfig()
 			TomTom:ShowHideCoordBlock()
 		elseif ns == "mapcoords" then
 			TomTom:ShowHideWorldCoords()
+		elseif ns == "arrow" then
+			TomTom:ShowHideCrazyArrow()
+		elseif opt == "otherzone" then
+			TomTom:ReloadWaypoints()
 		end
 	end

@@ -41,6 +45,7 @@ local function createconfig()

 	options.args.coordblock = {
 		type = "group",
+		order = 2,
 		name = L["Coordinate Block"],
 		desc = L["Options that alter the coordinate block"],
 		get = get,
@@ -122,6 +127,7 @@ local function createconfig()

 	options.args.crazytaxi = {
 		type = "group",
+		order = 3,
 		name = L["Waypoint Arrow"],
 		get = get,
 		set = set,
@@ -202,6 +208,7 @@ local function createconfig()

 	options.args.minimap = {
 		type = "group",
+		order = 4,
 		name = L["Minimap"],
 		get = get,
 		set = set,
@@ -238,6 +245,7 @@ local function createconfig()

 	options.args.worldmap = {
 		type = "group",
+		order = 5,
 		name = L["World Map"],
 		get = get,
 		set = set,
@@ -329,10 +337,12 @@ local function createconfig()

 	options.args.general = {
 		type = "group",
+		order = 1,
 		name = L["General Options"],
 		get = get,
 		set = set,
 		args = {
+			--[[
 			comm = {
 				type = "toggle",
 				order = 1,
@@ -347,10 +357,12 @@ local function createconfig()
 				width = "double",
 				arg = "comm.prompt",
 			},
+			--]]
 			persistence = {
 				type = "toggle",
 				order = 3,
-				name = L["Save waypoints in between sessions"],
+				name = L["Save new waypoints until I remove them"],
+				desc = L["This option will not remove any waypoints that are currently set to persist, but only effects new waypoints that get set"],
 				width = "double",
 				arg = "persistence.savewaypoints",
 			},
@@ -367,7 +379,8 @@ local function createconfig()

 	options.args.profile = {
 		type = "group",
-		name = L["Profile options"],
+		order = 6,
+		name = L["Profile Options"],
 		args = {
 			desc = {
 				order = 1,
diff --git a/TomTom_CrazyArrow.lua b/TomTom_CrazyArrow.lua
index a26e7ce..a0566f0 100644
--- a/TomTom_CrazyArrow.lua
+++ b/TomTom_CrazyArrow.lua
@@ -215,4 +215,17 @@ local function OnUpdate(self, elapsed)
 	end
 end

+function TomTom:ShowHideCrazyArrow()
+	if self.profile.arrow.enable then
+		wayframe:Show()
+		if self.profile.arrow.showtta then
+			tta:Show()
+		else
+			tta:Hide()
+		end
+	else
+		wayframe:Hide()
+	end
+end
+
 wayframe:SetScript("OnUpdate", OnUpdate)
diff --git a/TomTom_Waypoints.lua b/TomTom_Waypoints.lua
index 87a783b..abc85f7 100644
--- a/TomTom_Waypoints.lua
+++ b/TomTom_Waypoints.lua
@@ -61,7 +61,7 @@ local Minimap_OnEnter,Minimap_OnLeave,Minimap_OnUpdate,Minimap_OnClick,Minimap_O
 local Arrow_OnUpdate
 local World_OnEnter,World_OnLeave,World_OnClick,World_OnEvent

-function TomTom:SetWaypoint(c, z, x, y, callbacks, world)
+function TomTom:SetWaypoint(c, z, x, y, callbacks, show_minimap, show_world)
 	-- Try to acquire a waypoint from the frame pool
 	local point = table.remove(pool)

@@ -116,7 +116,8 @@ function TomTom:SetWaypoint(c, z, x, y, callbacks, world)
 	point.z = z
 	point.x = x
 	point.y = y
-	point.world = world
+	point.show_world = show_world
+	point.show_minimap = show_minimap
 	point.callbacks = callbacks
 	point.worldmap.callbacks = callbacks and callbacks.world
 	point.minimap.callbacks = callbacks and callbacks.minimap
@@ -139,26 +140,36 @@ function TomTom:SetWaypoint(c, z, x, y, callbacks, world)

 	-- Place the waypoint
 	Astrolabe:PlaceIconOnMinimap(point.minimap, c, z, x, y)
-	if point.world then
+
+	if show_world then
 		Astrolabe:PlaceIconOnWorldMap(WorldMapDetailFrame, point.worldmap, c, z, x, y)
 	end

+	if not show_minimap then
+		-- Hide the minimap icon/arrow if minimap is off
+		point.minimap:EnableMouse(false)
+		point.minimap.icon:Hide()
+		point.minimap.arrow:Hide()
+		point.minimap:SetScript("OnUpdate", nil)
+	else
+		point.minimap:EnableMouse(true)
+		point.minimap:SetScript("OnUpdate", Minimap_OnUpdate)
+		Minimap_OnUpdate(point.minimap, 5.0)
+	end
+
 	point.uid = getuid(point)
 	return point.uid
 end

-function TomTom:RemoveWaypoint(uid)
+function TomTom:ClearWaypoint(uid)
 	local point = resolveuid(uid, true)
-	Astrolabe:RemoveIconFromMinimap(point.minimap)
-	point.minimap:Hide()
-	point.worldmap:Hide()
-	table.insert(pool, point)
-
-	if point.callbacks and point.callbacks.remove then
-		point.callbacks.remove("remove", uid)
+	if point then
+		Astrolabe:RemoveIconFromMinimap(point.minimap)
+		point.minimap:Hide()
+		point.worldmap:Hide()
+		table.insert(pool, point)
+		point.uid = nil
 	end
-
-	point.uid = nil
 end

 function TomTom:GetDistanceToWaypoint(uid)
@@ -253,11 +264,8 @@ do

 		if edge then
 			-- Check to see if this is a transition
-			if not data.edge then
-				self.icon:Hide()
-				self.arrow:Show()
-				data.edge = true
-			end
+			self.icon:Hide()
+			self.arrow:Show()

 			-- Rotate the icon, as required
 			local angle = Astrolabe:GetDirectionToIcon(self)
@@ -271,10 +279,9 @@ do
 			local sin,cos = math.sin(angle) * square_half, math.cos(angle) * square_half
 			self.arrow:SetTexCoord(0.5-sin, 0.5+cos, 0.5+cos, 0.5+sin, 0.5-cos, 0.5-sin, 0.5+sin, 0.5-cos)

-		elseif data.edge then
+		else
 			self.icon:Show()
 			self.arrow:Hide()
-			data.edge = nil
 		end

 		if callbacks and callbacks.distance then
@@ -335,13 +342,15 @@ do
 			end

 			local data = self.point
-			if data.world then
+			if data.worldmap and data.show_world then
 				local x,y = Astrolabe:PlaceIconOnWorldMap(WorldMapDetailFrame, self, data.c, data.z, data.x, data.y)
 				if (x and y and (0 < x and x <= 1) and (0 < y and y <= 1)) then
 					self:Show()
 				else
 					self:Hide()
 				end
+			else
+				self:Hide()
 			end
 		end
 	end