diff --git a/TomTom.lua b/TomTom.lua index b4b66ab..34e3d5d 100755 --- a/TomTom.lua +++ b/TomTom.lua @@ -1,6 +1,29 @@ ---[[--------------------------------------------------------------------------------- +--[[-------------------------------------------------------------------------- TomTom by Cladhaire <cladhaire@gmail.com> -----------------------------------------------------------------------------------]] +----------------------------------------------------------------------------]] + +-- Create the addon object +TomTom = {} + +function TomTom:Initialize() +end + +function TomTom:Enable() +end + + + + + + + + + + + + + + -- Simple localisation table for messages local L = setmetatable({ diff --git a/TomTom.toc b/TomTom.toc index d8b704c..f00afa5 100755 --- a/TomTom.toc +++ b/TomTom.toc @@ -7,3 +7,5 @@ Dongle.lua Astrolabe\Load.xml TomTom.lua +TomTom_Waypoints.lua +TomTom_Zones.lua \ No newline at end of file diff --git a/TomTom_Minimap.lua b/TomTom_Minimap.lua deleted file mode 100644 index a568ff3..0000000 --- a/TomTom_Minimap.lua +++ /dev/null @@ -1,127 +0,0 @@ -local MinimapPoint = {} - --- Import Astrolabe -local Astrolabe = DongleStub("Astrolabe-0.4") - --- Create tooltip -if not self.tooltip then - self.tooltip = CreateFrame("GameTooltip", "TomTomTooltip", nil, "GameTooltipTemplate") -end - -local OnEnter,OnLeave,OnClick,OnUpdate -local Tooltip_OnUpdate - -function MinimapPoint:New(c,z,x,y,title,note) - if not self.pool then self.pool = {} end - - -- Try to acquire an icon from the frame pool - local point = table.remove(self.pool) - - if not point then - point = CreateFrame("Button", nil, Minimap) - point:SetHeight(12) - point:SetWidth(12) - point:RegisterForClicks("RightButtonUp") - - point.icon = point:CreateTexture() - point.icon:SetTexture("Interface\\Minimap\\ObjectIcons") - point.icon:SetTexCoord(0.5, 0.75, 0, 0.25) - point.icon:SetAllPoints() - - -- Add the behavior scripts - point:SetScript("OnEnter", OnEnter) - point:SetScript("OnLeave", OnLeave) - point:SetScript("OnUpdate", OnUpdate) - point:SetScript("OnClick", OnClick) - - point.arrow = CreateFrame("Model", nil, point) - point.arrow:SetHeight(140.8) - point.arrow:SetWidth(140.8) - point.arrow:SetPoint("CENTER", Minimap, "CENTER", 0, 0) - point.arrow:SetModel("Interface\\Minimap\\Rotating-MinimapArrow.mdx") - point.arrow:SetModelScale(.600000023841879) - point.arrow:Hide() - - -- Copy all methods into the table - for k,v in pairs(self) do - point[k] = v - end - end - - -- Set the data for this waypoint - point.c = c - point.z = z - point.x = x - point.y = y - point.title = title - point.note = note - - -- Use Astrolabe to place the waypoint - -- TODO: Place the waypoint via astrolabe - - return point -end - -function MinimapPoint:Arrive() -end - -function MinimapPoint:Clear() -end - -do - function OnEnter(self, motion) - local tooltip = TomTomTooltip - tooltip:SetParent(self) - tooltip:SetOwner(self, "ANCHOR_CURSOR") - - -- Display the title, and add the note if it exists - tooltip:SetTitle(title or "TomTom Waypoint") - tooltip:AddLine(self.note or "No note for this waypoint") - - local dist,x,y = Astrolabe:GetDistanceToIcon(self) - - tooltip:AddLine(format("%.2f, %.2f", self.x, self.y), 1, 1, 1) - tooltip:AddLine(("%s yards away"):format(math.floor(dist)), 1, 1 ,1) - tooltip:AddLine(TomTom:GetZoneText(self.zone), 0.7, 0.7, 0.7) - tooltip:Show() - tooltip:SetScript("OnUpdate", Tooltip_OnUpdate) - end - - function OnLeave(self, motion) - TomTomTooltip:Hide() - end - - function OnClick(self, button, down) - --TODO: Implement dropdown - end - - function OnUpdate(self, elapsed) - local edge = Astrolabe:IsIconOnEdge(self) - - if edge and not self.arrow:IsShown() then - self.arrow:Show() - self.icon:Hide() - self.edge = true - elseif not edge and not self.icon:IsShown() then - self.icon:Show() - self.arrow:Hide() - self.edge = false - end - - local dist,x,y = Astrolabe:GetDistanceToIcon(self) - local cleardist = TomTom.profile.options.cleardist - - if dist <= cleardist then - self:Arrive() - end - end - - local count = 0 - function Tooltip_OnUpdate(self, elapsed) - count = count + elapsed - if count >= 0.1 then - local dist,x,y = Astrolabe:GetDistanceToIcon(self:GetParent()) - TomTomTooltipTextLeft4:SetText(("%s yards away"):format(math.floor(dist)), 1, 1, 1) - end - end -end diff --git a/TomTom_Waypoints.lua b/TomTom_Waypoints.lua new file mode 100644 index 0000000..ffd1056 --- /dev/null +++ b/TomTom_Waypoints.lua @@ -0,0 +1,180 @@ +--[[--------------------------------------------------------------------------------- + TomTom by Cladhaire <cladhaire@gmail.com> +----------------------------------------------------------------------------------]] + +local Waypoint = {} +TomTom.Waypoint = Waypoint + +-- Import Astrolabe for locations +local Astrolabe = DongleStub("Astrolabe-0.4") + +-- Create a tooltip for use throughout this section +local tooltip = CreateFrame("GameTooltip", "TomTomTooltip", nil, "GameTooltipTemplate") + +-- Create a local table used as a pool +local pool = {} + +-- Local declarations +local OnEnter,OnLeave,OnClick,OnUpdate,Tooltip_OnUpdate + +-- Local default distance in yards +local DEFAULT_DISTANCE = 10 + +-- Waypoint:New(c,z,x,y,title,note,distance,callback) +-- c (number) - The continent on which to place the waypoint +-- z (number) - The zone on which to place the waypoint +-- x (number) - The x coordinate +-- y (number) - The y coordinate +-- title (string) - A title for the waypoint +-- note (string) - A description or note for this waypoint +-- distance (number) - Arrival distance (in yards) +-- callback (function) - A function to be called when the player is distance +-- yards from the waypoint. +-- +-- Creates a new waypoint object at the given coordinate, with the supplied +-- title and note. Returns a waypoint object. When +function Waypoint:New(c,z,x,y,distance,title,note) + if not self.pool then self.pool = {} end + + -- Try to acquire a waypoint from the frame pool + local point = table.remove(self.pool) + + if not point then + point = CreateFrame("Button", nil, Minimap) + point:SetHeight(12) + point:SetWidth(12) + point:RegisterForClicks("RightButtonUp") + + -- Create the actual texture attached for the minimap icon + point.icon = point:CreateTexture() + point.icon:SetTexture("Interface\\Minimap\\ObjectIcons") + point.icon:SetTexCoord(0.5, 0.75, 0, 0.25) + point.icon:SetAllPoints() + + -- Create the world map point, and associated texture + point.world = CreateFrame("Button", nil, WorldMapButton) + point.world:SetHeight(12) + point.world:SetWidth(12) + point:RegisterForClicks("RightButtonUp") + point:SetNormalTexture("Interface\\Minimap\\ObjectIcons") + point:GetNormalTexture():SetTExCoords(0.5, 0.75, 0, 0.25) + + -- Create the minimap model + point.arrow = CreateFrame("Model", nil, point) + point.arrow:SetHeight(140.8) + point.arrow:SetWidth(140.8) + point.arrow:SetPoint("CENTER", Minimap, "CENTER", 0, 0) + point.arrow:SetModel("Interface\\Minimap\\Rotating-MinimapArrow.mdx") + point.arrow:SetModelScale(.600000023841879) + point.arrow:Hide() + + -- Add the behavior scripts + point:SetScript("OnEnter", OnEnter) + point:SetScript("OnLeave", OnLeave) + point:SetScript("OnUpdate", OnUpdate) + point:SetScript("OnClick", OnClick) + + -- Copy all methods into the table + for k,v in pairs(Waypoint) do + Waypoint[k] = v + end + end + + -- Set the data for this waypoint + point.c = c + point.z = z + point.x = x + point.y = y + point.title = title + point.note = note + point.distance = distance or DEFAULT_DISTANCE + point.callback = callback + + -- Use Astrolabe to place the waypoint + -- TODO: Place the waypoint via astrolabe + + return point +end + +-- Waypoint:Clear() +-- +-- Clears and releases a waypoint without notification. +function Waypoint:Clear() + self.c = nil + self.z = nil + self.x = nil + self.y = nil + self.title = nil + self.note = nil + self.distance = nil + self.callback = nil + + self.icon:Hide() + self.arrow:Hide() + self.world:Hide() + + -- Add the waypoint back into the frame pool + table.insert(pool, self) + + -- TODO: Remove from Astrolabe +end + +do + function OnEnter(self, motion) + tooltip:SetParent(self) + tooltip:SetOwner(self, "ANCHOR_CURSOR") + + -- Display the title, and add the note if it exists + tooltip:SetTitle(title or "TomTom Waypoint") + tooltip:AddLine(self.note or "No note for this waypoint") + + local dist,x,y = Astrolabe:GetDistanceToIcon(self) + + tooltip:AddLine(format("%.2f, %.2f", self.x, self.y), 1, 1, 1) + tooltip:AddLine(("%s yards away"):format(math.floor(dist)), 1, 1 ,1) + tooltip:AddLine(TomTom:GetZoneText(self.zone), 0.7, 0.7, 0.7) + tooltip:Show() + tooltip:SetScript("OnUpdate", Tooltip_OnUpdate) + end + + function OnLeave(self, motion) + tooltip:Hide() + end + + function OnClick(self, button, down) + --TODO: Implement dropdown + end + + function OnUpdate(self, elapsed) + local edge = Astrolabe:IsIconOnEdge(self) + + if edge and not self.arrow:IsShown() then + self.arrow:Show() + self.icon:Hide() + self.edge = true + elseif not edge and not self.icon:IsShown() then + self.icon:Show() + self.arrow:Hide() + self.edge = false + end + + local dist,x,y = Astrolabe:GetDistanceToIcon(self) + local cleardist = TomTom.profile.options.cleardist + + if dist <= self.distance then + if self.callback then + self.callback(self) + self:Clear() + end + end + end + + local count = 0 + function Tooltip_OnUpdate(self, elapsed) + count = count + elapsed + if count >= 0.1 then + local dist,x,y = Astrolabe:GetDistanceToIcon(self:GetParent()) + TomTomTooltipTextLeft4:SetText(("%s yards away"):format(math.floor(dist)), 1, 1, 1) + end + end +end diff --git a/TomTom_Zones.lua b/TomTom_Zones.lua new file mode 100644 index 0000000..f7b2712 --- /dev/null +++ b/TomTom_Zones.lua @@ -0,0 +1,102 @@ +--[[-------------------------------------------------------------------------- + TomTom by Cladhaire <cladhaire@gmail.com> +----------------------------------------------------------------------------]] + +local tokens = { + -- Kalimdor + ["Ashenvale"] = "ASHE", + ["Azshara"] = "AZSH", + ["Azuremyst Isle"] = "AZUR", + ["Bloodmyst Isle"] = "BLOO", + ["Darkshore"] = "DARK", + ["Darnassus"] = "DARN", + ["Durotar"] = "DURO", + ["Dustwallow Marsh"] = "DUST", + ["Felwood"] = "FELW", + ["Feralas"] = "FERA", + ["Moonglade"] = "MOON", + ["Mulgore"] = "MULG", + ["Orgrimmar"] = "ORGR", + ["Silithus"] = "SILI", + ["Stonetalon Mountains"] = "STON", + ["Tanaris"] = "TANA", + ["Teldrassil"] = "TELD", + ["The Barrens"] = "BARR", + ["The Exodar"] = "EXOD", + ["Thousand Needles"] = "1KNE", + ["Thunder Bluff"] = "THUN", + ["Un'Goro Crater"] = "UNGO", + ["Winterspring"] = "WINT", + -- Eastern Kingdoms + ["Alterac Mountains"] = "ALTE", + ["Arathi Highlands"] = "ARAT", + ["Badlands"] = "BADL", + ["Blasted Lands"] = "BLAS", + ["Burning Steppes"] = "BURN", + ["Deadwind Pass"] = "DWPA", + ["Dun Morogh"] = "DUNM", + ["Duskwood"] = "DUSK", + ["Eastern Plaguelands"] = "EPLA", + ["Elwynn Forest"] = "ELWY", + ["Eversong Woods"] = "EVSO", + ["Ghostlands"] = "GHOL", + ["Hillsbrad Foothills"] = "HILLF", + ["Ironforge"] = "IFGE", + ["Loch Modan"] = "LCHM", + ["Redridge Mountains"] = "REMT", + ["Searing Gorge"] = "SGOR", + ["Silvermoon City"] = "SILC", + ["Silverpine Forest"] = "SILF", + ["Stormwind City"] = "STOC", + ["Stranglethorn Vale"] = "STVA", + ["Swamp of Sorrows"] = "SWOS", + ["The Hinterlands"] = "HINT", + ["Tirisfal Glades"] = "TGLAD", + ["Undercity"] = "UCIT", + ["Western Plaguelands"] = "WPLA", + ["Westfall"] = "WFAL", + ["Wetlands"] = "WETL", + -- Outlands + ["Blade's Edge Mountains"] = "BLEM", + ["Hellfire Peninsula"] = "HFPE", + ["Nagrand"] = "NAGR", + ["Netherstorm"] = "NETH", + ["Shadowmoon Valley"] = "SHVA", + ["Shattrath City"] = "SHAT", + ["Terokkar Forest"] = "TERF", + ["Zangarmarsh"] = "ZANG", +} + +-- Generate a lookup table from token to continent zone +local zones = {} +for c in pairs{GetMapContinents()} do + zones[c] = {GetMapZones(c)} + for idx,zone in ipairs(zones[c]) do + local token = tokens[zone] + zones[token] = format("%d,%d", c, zone) + end + zones[c] = nil +end + +-- TomTom:GetZoneToken(name) +-- name (string) - The name of a zone as returned from GetMapZones() +-- +-- Converts a zone name into a locale-independent token. Inspiration from +-- Gatherer_ZoneTokens. +function TomTom:GetZoneToken(name) + local token = tokens[name] + if not token then + error(format("Could not find token for zone name '%s'.", name)) + end + + return tokens[name] +end + +-- c,z = TomTom:GetZoneNumbers(name) +-- name (string) - The name of an in-game zone +-- +-- Converts a zone name into a continent,zone pair usable by Astrolabe +function TomTom:GetZoneNumber(name) + local token = self:GetZoneToken(name) + return strsplit(",", zones[token]) +end