Quantcast

* Added LDB data feed for coordinates

James Whitehead II [12-13-08 - 13:09]
* Added LDB data feed for coordinates
* Added LDB data feed for crazy arrow, requires iconR, iconG, iconB, and iconCoords support
* Added options to enable/disable the above feeds within TomTom
* Updated Astrolabe to get rid of an error that can occur when logging in
Filename
TomTom.lua
TomTom.toc
TomTom_Config.lua
TomTom_CrazyArrow.lua
libs/Astrolabe/Astrolabe.lua
libs/LibDataBroker-1.1/LibDataBroker-1.1.lua
diff --git a/TomTom.lua b/TomTom.lua
index 550033b..f97b9f3 100755
--- a/TomTom.lua
+++ b/TomTom.lua
@@ -5,6 +5,7 @@
 -- Simple localization table for messages
 local L = TomTomLocals
 local Astrolabe = DongleStub("Astrolabe-0.4")
+local ldb = LibStub("LibDataBroker-1.1")

 -- Speed up minimap updates
 Astrolabe.MinimapUpdateTime = 0.1
@@ -110,6 +111,10 @@ function TomTom:ADDON_LOADED(event, addon)
 					cleardistance = 10,
 					savewaypoints = true,
 				},
+				feeds = {
+					coords = false,
+					arrow = false,
+				},
 			},
 		}

@@ -143,6 +148,32 @@ function TomTom:ADDON_LOADED(event, addon)

 		self:ReloadOptions()
 		self:ReloadWaypoints()
+
+		if self.db.profile.feeds.coords then
+			-- Create a data feed for coordinates
+			local feed_coords = ldb:NewDataObject("TomTom_Coords", {
+				type = "data source",
+				icon = "Interface\\Icons\\INV_Misc_Map_01",
+				text = "",
+			})
+
+			local coordFeedFrame = CreateFrame("Frame")
+			local throttle, counter = 0.5, 0
+			coordFeedFrame:SetScript("OnUpdate", function(self, elapsed)
+				counter = counter + elapsed
+				if counter < throttle then
+					return
+				end
+
+				counter = 0
+				local c,z,x,y = Astrolabe:GetCurrentPlayerPosition()
+				local opt = TomTom.db.profile
+
+				if x and y then
+					feed_coords.text = string.format("%s", RoundCoords(x, y, opt.block.accuracy))
+				end
+			end)
+		end
 	end
 end

diff --git a/TomTom.toc b/TomTom.toc
index bf8f2af..d52fa40 100755
--- a/TomTom.toc
+++ b/TomTom.toc
@@ -18,6 +18,7 @@ libs\AceConfig-3.0\AceConfig-3.0.xml
 libs\AceEvent-3.0\AceEvent-3.0.xml
 libs\AceDB-3.0\AceDB-3.0.xml
 libs\AceDBOptions-3.0\AceDBOptions-3.0.xml
+libs\LibDataBroker-1.1\LibDataBroker-1.1.lua

 Localization.enUS.lua
 Localization.deDE.lua
diff --git a/TomTom_Config.lua b/TomTom_Config.lua
index bb42cc7..609a6a7 100644
--- a/TomTom_Config.lua
+++ b/TomTom_Config.lua
@@ -477,6 +477,36 @@ local function createconfig()
 		},
 	} -- End world map options

+	-- LDB Data Feeds
+	options.args.feeds = {
+		type = "group",
+		order = 8,
+		name = L["Data Feed Options"],
+		get = get,
+		set = set,
+		args = {
+			help = {
+				order = 1,
+				type = "description",
+				name = L["TomTom is capable of providing data sources via LibDataBroker, which allows them to be displayed in any LDB compatible display.  These options enable or disable the individual feeds, but will only take effect after a reboot."],
+			},
+			coords = {
+				type = "toggle",
+				order = 2,
+				name = L["Provide a LDB data source for coordinates"],
+				width = "double",
+				arg = "feeds.coords",
+			},
+			arrow = {
+				type = "toggle",
+				order = 3,
+				name = L["Provide a LDB data source for the crazy-arrow"],
+				width = "double",
+				arg = "feeds.arrow",
+			}
+		},
+	}
+
 	options.args.general = {
 		type = "group",
 		order = 1,
@@ -602,6 +632,11 @@ local function createBlizzOptions()
 	config:RegisterOptionsTable("TomTom-Worldmap", options.args.worldmap)
 	dialog:AddToBlizOptions("TomTom-Worldmap", options.args.worldmap.name, "TomTom")

+	-- World Map Options
+	config:RegisterOptionsTable("TomTom-Feeds", options.args.feeds)
+	dialog:AddToBlizOptions("TomTom-Feeds", options.args.feeds.name, "TomTom")
+
+
 	-- Profile Options
 	local p_options = options.args.profile.args.options
 	local w_options = options.args.profile.args.waypoints
diff --git a/TomTom_CrazyArrow.lua b/TomTom_CrazyArrow.lua
index 698a0da..059dd8b 100644
--- a/TomTom_CrazyArrow.lua
+++ b/TomTom_CrazyArrow.lua
@@ -9,6 +9,7 @@
 local Astrolabe = DongleStub("Astrolabe-0.4")
 local sformat = string.format
 local L = TomTomLocals
+local ldb = LibStub("LibDataBroker-1.1")

 local GetPlayerBearing
 function GetPlayerBearing()
@@ -110,11 +111,11 @@ wayframe.arrow:SetAllPoints()
 local active_point, arrive_distance, showDownArrow, point_title

 function TomTom:SetCrazyArrow(uid, dist, title)
-	if self.profile.arrow.enable then
-		active_point = uid
-		arrive_distance = dist
-		point_title = title
+	active_point = uid
+	arrive_distance = dist
+	point_title = title

+	if self.profile.arrow.enable then
 		wayframe.title:SetText(title or "Unknown waypoint")
 		wayframe:Show()
 	end
@@ -355,3 +356,86 @@ wayframe:SetScript("OnClick", function(self, button)
 		ToggleDropDownMenu(1, nil, TomTom.dropdown, "cursor", 0, 0)
 	end
 end)
+
+local function getCoords(column, row)
+	local xstart = (column * 56) / 512
+	local ystart = (row * 42) / 512
+	local xend = ((column + 1) * 56) / 512
+	local yend = ((row + 1) * 42) / 512
+	return xstart, xend, ystart, yend
+end
+
+local texcoords = setmetatable({}, {__index = function(t, k)
+	local col,row = k:match("(%d):(%d)")
+	local obj = {getCoords(col, row)}
+	rawset(t, k, obj)
+	return obj
+end})
+
+wayframe:RegisterEvent("ADDON_LOADED")
+wayframe:SetScript("OnEvent", function(self, event, arg1, ...)
+	if arg1 == "TomTom" then
+		if TomTom.db.profile.feeds.arrow then
+			-- Create a data feed for coordinates
+			local feed_crazy = ldb:NewDataObject("TomTom_CrazyArrow", {
+				type = "data source",
+				icon = "Interface\\Addons\\TomTom\\Images\\Arrow",
+				text = "Crazy",
+				iconR = 1,
+				iconG = 1,
+				iconB = 1,
+				iconCoords = {0, 1, 0, 1},
+				OnTooltipShow = function(tooltip)
+					local dist = TomTom:GetDistanceToWaypoint(active_point)
+					if dist then
+						tooltip:AddLine(point_title or L["Unknown waypoint"])
+						tooltip:AddLine(sformat(L["%d yards"], dist), 1, 1, 1)
+					end
+				end,
+			})
+
+			local crazyFeedFrame = CreateFrame("Frame")
+			local throttle = 0.5
+			local counter = 0
+			crazyFeedFrame:SetScript("OnUpdate", function(self, elapsed)
+				counter = counter + elapsed
+				if counter < throttle then
+					return
+				end
+
+				counter = 0
+
+				local angle = TomTom:GetDirectionToWaypoint(active_point)
+				local player = GetPlayerBearing()
+				if not angle or not player then
+					feed_crazy.iconCoords = texcoords["1:1"]
+					feed_crazy.iconR = 0.2
+					feed_crazy.iconG = 1.0
+					feed_crazy.iconB = 0.2
+					feed_crazy.text = "No waypoint"
+					return
+				end
+
+				angle = angle - player
+
+				local perc = math.abs((math.pi - math.abs(angle)) / math.pi)
+
+				local gr,gg,gb = unpack(TomTom.db.profile.arrow.goodcolor)
+				local mr,mg,mb = unpack(TomTom.db.profile.arrow.middlecolor)
+				local br,bg,bb = unpack(TomTom.db.profile.arrow.badcolor)
+				local r,g,b = ColorGradient(perc, br, bg, bb, mr, mg, mb, gr, gg, gb)
+				feed_crazy.iconR = r
+				feed_crazy.iconG = g
+				feed_crazy.iconB = b
+
+				cell = floor(angle / twopi * 108 + 0.5) % 108
+				local column = cell % 9
+				local row = floor(cell / 9)
+
+				local key = column .. ":" .. row
+				feed_crazy.iconCoords = texcoords[key]
+				feed_crazy.text = point_title or "Unknown waypoint"
+			end)
+		end
+	end
+end)
diff --git a/libs/Astrolabe/Astrolabe.lua b/libs/Astrolabe/Astrolabe.lua
index 0628aa4..76d555d 100644
--- a/libs/Astrolabe/Astrolabe.lua
+++ b/libs/Astrolabe/Astrolabe.lua
@@ -1,7 +1,7 @@
 --[[
 Name: Astrolabe
-Revision: $Rev: 95 $
-$Date: 2008-12-03 22:44:26 +0000 (Wed, 03 Dec 2008) $
+Revision: $Rev: 98 $
+$Date: 2008-12-04 08:54:58 +0000 (Thu, 04 Dec 2008) $
 Author(s): Esamynn (esamynn at wowinterface.com)
 Inspired By: Gatherer by Norganna
              MapLibrary by Kristofer Karlsson (krka at kth.se)
@@ -42,7 +42,7 @@ Note:
 -- DO NOT MAKE CHANGES TO THIS LIBRARY WITHOUT FIRST CHANGING THE LIBRARY_VERSION_MAJOR
 -- STRING (to something unique) OR ELSE YOU MAY BREAK OTHER ADDONS THAT USE THIS LIBRARY!!!
 local LIBRARY_VERSION_MAJOR = "Astrolabe-0.4"
-local LIBRARY_VERSION_MINOR = tonumber(string.match("$Revision: 95 $", "(%d+)") or 1)
+local LIBRARY_VERSION_MINOR = tonumber(string.match("$Revision: 98 $", "(%d+)") or 1)

 if not DongleStub then error(LIBRARY_VERSION_MAJOR .. " requires DongleStub.") end
 if not DongleStub:IsNewerVersion(LIBRARY_VERSION_MAJOR, LIBRARY_VERSION_MINOR) then return end
@@ -104,6 +104,7 @@ local sqrt = math.sqrt;
 local min = math.min
 local max = math.max
 local yield = coroutine.yield
+local next = next
 local GetFramerate = GetFramerate


@@ -446,7 +447,20 @@ function Astrolabe:PlaceIconOnMinimap( icon, continent, zone, xPos, yPos )
 	argcheck(xPos, 5, "number");
 	argcheck(yPos, 6, "number");

-	local lC, lZ, lx, ly = unpack(self.LastPlayerPosition);
+	-- if the positining system is currently active, just use the player position used by the last incremental (or full) update
+	-- otherwise, make sure we base our calculations off of the most recent player position
+	local lC, lZ, lx, ly;
+	if ( self.processingFrame:IsShown() ) then
+		lC, lZ, lx, ly = unpack(self.LastPlayerPosition);
+	else
+		lC, lZ, lx, ly = self:GetCurrentPlayerPosition();
+		local lastPosition = self.LastPlayerPosition;
+		lastPosition[1] = lC;
+		lastPosition[2] = lZ;
+		lastPosition[3] = lx;
+		lastPosition[4] = ly;
+	end
+
 	local dist, xDist, yDist = self:ComputeDistance(lC, lZ, lx, ly, continent, zone, xPos, yPos);
 	if not ( dist ) then
 		--icon's position has no meaningful position relative to the player's current location
@@ -460,20 +474,6 @@ function Astrolabe:PlaceIconOnMinimap( icon, continent, zone, xPos, yPos )
 		self.MinimapIconCount = self.MinimapIconCount + 1
 	end

-	-- We know this icon's position is valid, so we need to make sure the icon placement
-	-- system is active.  We call this here so that if this is the first icon being added to
-	-- an empty buffer, the full recalc will not completely redo the work done by this function
-	-- because the icon has not yet actually been placed in the buffer.
-	--
-	-- Note: if the update system was inactive, then the LastPlayerPosition used to calculate the icon's
-	-- data earlier in this function was out of date, and will be updated by this show, thus we need to redo
-	-- the distance calculations
-	if not ( self.processingFrame:IsShown() ) then
-		self.processingFrame:Show()
-		lC, lZ, lx, ly = unpack(self.LastPlayerPosition);
-		dist, xDist, yDist = self:ComputeDistance(lC, lZ, lx, ly, continent, zone, xPos, yPos);
-	end
-
 	AddedOrUpdatedIcons[icon] = iconData
 	iconData.continent = continent;
 	iconData.zone = zone;
@@ -496,6 +496,9 @@ function Astrolabe:PlaceIconOnMinimap( icon, continent, zone, xPos, yPos )
 	placeIconOnMinimap(map, map:GetZoom(), map:GetWidth(), map:GetHeight(), icon, dist, xDist, yDist);
 	icon:Show()

+	-- We know this icon's position is valid, so we need to make sure the icon placement system is active.
+	self.processingFrame:Show()
+
 	return 0;
 end

@@ -922,8 +925,12 @@ function Astrolabe:OnShow( frame )
 		return
 	end

-	-- re-calculate minimap icon positions
-	self:CalculateMinimapIconPositions(true);
+	-- re-calculate minimap icon positions (if needed)
+	if ( next(self.MinimapIcons) ) then
+		self:CalculateMinimapIconPositions(true);
+	else
+		resetIncrementalUpdate = true;
+	end

 	if ( self.MinimapIconCount <= 0 ) then
 		-- no icons left to manage
diff --git a/libs/LibDataBroker-1.1/LibDataBroker-1.1.lua b/libs/LibDataBroker-1.1/LibDataBroker-1.1.lua
new file mode 100644
index 0000000..364602e
--- /dev/null
+++ b/libs/LibDataBroker-1.1/LibDataBroker-1.1.lua
@@ -0,0 +1,66 @@
+
+assert(LibStub, "LibDataBroker-1.1 requires LibStub")
+assert(LibStub:GetLibrary("CallbackHandler-1.0", true), "LibDataBroker-1.1 requires CallbackHandler-1.0")
+
+local lib, oldminor = LibStub:NewLibrary("LibDataBroker-1.1", 3)
+if not lib then return end
+oldminor = oldminor or 0
+
+
+lib.callbacks = lib.callbacks or LibStub:GetLibrary("CallbackHandler-1.0"):New(lib)
+lib.attributestorage, lib.namestorage, lib.proxystorage = lib.attributestorage or {}, lib.namestorage or {}, lib.proxystorage or {}
+local attributestorage, namestorage, callbacks = lib.attributestorage, lib.namestorage, lib.callbacks
+
+if oldminor < 2 then
+	lib.domt = {
+		__metatable = "access denied",
+		__index = function(self, key) return attributestorage[self] and attributestorage[self][key] end,
+	}
+end
+
+if oldminor < 3 then
+	lib.domt.__newindex = function(self, key, value)
+		if not attributestorage[self] then attributestorage[self] = {} end
+		if attributestorage[self][key] == value then return end
+		attributestorage[self][key] = value
+		local name = namestorage[self]
+		if not name then return end
+		callbacks:Fire("LibDataBroker_AttributeChanged", name, key, value, self)
+		callbacks:Fire("LibDataBroker_AttributeChanged_"..name, name, key, value, self)
+		callbacks:Fire("LibDataBroker_AttributeChanged_"..name.."_"..key, name, key, value, self)
+		callbacks:Fire("LibDataBroker_AttributeChanged__"..key, name, key, value, self)
+	end
+end
+
+if oldminor < 2 then
+	function lib:NewDataObject(name, dataobj)
+		if self.proxystorage[name] then return end
+
+		if dataobj then
+			assert(type(dataobj) == "table", "Invalid dataobj, must be nil or a table")
+			self.attributestorage[dataobj] = {}
+			for i,v in pairs(dataobj) do
+				self.attributestorage[dataobj][i] = v
+				dataobj[i] = nil
+			end
+		end
+		dataobj = setmetatable(dataobj or {}, self.domt)
+		self.proxystorage[name], self.namestorage[dataobj] = dataobj, name
+		self.callbacks:Fire("LibDataBroker_DataObjectCreated", name, dataobj)
+		return dataobj
+	end
+end
+
+if oldminor < 1 then
+	function lib:DataObjectIterator()
+		return pairs(self.proxystorage)
+	end
+
+	function lib:GetDataObjectByName(dataobjectname)
+		return self.proxystorage[dataobjectname]
+	end
+
+	function lib:GetNameByDataObject(dataobject)
+		return self.namestorage[dataobject]
+	end
+end