diff --git a/TomTom.lua b/TomTom.lua index 351a7fd..3c49ba2 100755 --- a/TomTom.lua +++ b/TomTom.lua @@ -12,27 +12,27 @@ local lmd = LibStub("LibMapData-1.0") -- Create the addon object TomTom = { - events = {}, - eventFrame = CreateFrame("Frame"), - RegisterEvent = function(self, event, method) - self.eventFrame:RegisterEvent(event) - self.events[event] = method or event - end, - UnregisterEvent = function(self, event) - self.eventFrame:UnregisterEvent(event) - self.events[event] = nil - end, - version = GetAddOnMetadata("TomTom", "Version") + events = {}, + eventFrame = CreateFrame("Frame"), + RegisterEvent = function(self, event, method) + self.eventFrame:RegisterEvent(event) + self.events[event] = method or event + end, + UnregisterEvent = function(self, event) + self.eventFrame:UnregisterEvent(event) + self.events[event] = nil + end, + version = GetAddOnMetadata("TomTom", "Version") } if TomTom.version == "wowi:revision" then TomTom.version = "SVN" end if TomTom.version == "@project-version@" then TomTom.version = "SCM" end TomTom.eventFrame:SetScript("OnEvent", function(self, event, ...) - local method = TomTom.events[event] - if method and TomTom[method] then - TomTom[method](TomTom, event, ...) - end + local method = TomTom.events[event] + if method and TomTom[method] then + TomTom[method](TomTom, event, ...) + end end) TomTom:RegisterEvent("ADDON_LOADED") @@ -48,158 +48,158 @@ local RoundCoords local waypoints = {} function TomTom:ADDON_LOADED(event, addon) - if addon == "TomTom" then - self:UnregisterEvent("ADDON_LOADED") - self.defaults = { - profile = { - general = { - confirmremoveall = true, - announce = false, - corpse_arrow = true, - }, - block = { - enable = true, - accuracy = 2, - bordercolor = {1, 0.8, 0, 0.8}, - bgcolor = {0, 0, 0, 0.4}, - lock = false, - height = 30, - width = 100, - fontsize = 12, + if addon == "TomTom" then + self:UnregisterEvent("ADDON_LOADED") + self.defaults = { + profile = { + general = { + confirmremoveall = true, + announce = false, + corpse_arrow = true, + }, + block = { + enable = true, + accuracy = 2, + bordercolor = {1, 0.8, 0, 0.8}, + bgcolor = {0, 0, 0, 0.4}, + lock = false, + height = 30, + width = 100, + fontsize = 12, throttle = 0.2, - }, - mapcoords = { - playerenable = true, - playeraccuracy = 2, - cursorenable = true, - cursoraccuracy = 2, - }, - arrow = { - enable = true, - goodcolor = {0, 1, 0}, - badcolor = {1, 0, 0}, - middlecolor = {1, 1, 0}, - arrival = 15, - lock = false, - noclick = false, - showtta = true, - autoqueue = true, - menu = true, - scale = 1.0, - alpha = 1.0, - title_width = 0, - title_height = 0, - title_scale = 1, - title_alpha = 1, - setclosest = true, + }, + mapcoords = { + playerenable = true, + playeraccuracy = 2, + cursorenable = true, + cursoraccuracy = 2, + }, + arrow = { + enable = true, + goodcolor = {0, 1, 0}, + badcolor = {1, 0, 0}, + middlecolor = {1, 1, 0}, + arrival = 15, + lock = false, + noclick = false, + showtta = true, + autoqueue = true, + menu = true, + scale = 1.0, + alpha = 1.0, + title_width = 0, + title_height = 0, + title_scale = 1, + title_alpha = 1, + setclosest = true, enablePing = false, - }, - minimap = { - enable = true, - otherzone = true, - tooltip = true, - menu = true, - }, - worldmap = { - enable = true, - tooltip = true, - otherzone = true, - clickcreate = true, - menu = true, - create_modifier = "C", - }, - comm = { - enable = true, - prompt = false, - }, - persistence = { - cleardistance = 10, - savewaypoints = true, - }, - feeds = { - coords = false, - coords_throttle = 0.3, - coords_accuracy = 2, - arrow = false, - arrow_throttle = 0.1, - }, + }, + minimap = { + enable = true, + otherzone = true, + tooltip = true, + menu = true, + }, + worldmap = { + enable = true, + tooltip = true, + otherzone = true, + clickcreate = true, + menu = true, + create_modifier = "C", + }, + comm = { + enable = true, + prompt = false, + }, + persistence = { + cleardistance = 10, + savewaypoints = true, + }, + feeds = { + coords = false, + coords_throttle = 0.3, + coords_accuracy = 2, + arrow = false, + arrow_throttle = 0.1, + }, poi = { enable = true, modifier = "C", setClosest = false, arrival = 0, }, - }, - } + }, + } - self.waydefaults = { + self.waydefaults = { global = { converted = { ["*"] = {}, }, }, - profile = { - ["*"] = {}, - }, - } - - self.db = LibStub("AceDB-3.0"):New("TomTomDB", self.defaults, "Default") - self.waydb = LibStub("AceDB-3.0"):New("TomTomWaypointsMF", self.waydefaults) - - self.db.RegisterCallback(self, "OnProfileChanged", "ReloadOptions") - self.db.RegisterCallback(self, "OnProfileCopied", "ReloadOptions") - self.db.RegisterCallback(self, "OnProfileReset", "ReloadOptions") - self.waydb.RegisterCallback(self, "OnProfileChanged", "ReloadWaypoints") - self.waydb.RegisterCallback(self, "OnProfileCopied", "ReloadWaypoints") - self.waydb.RegisterCallback(self, "OnProfileReset", "ReloadWaypoints") - - self.tooltip = CreateFrame("GameTooltip", "TomTomTooltip", nil, "GameTooltipTemplate") + profile = { + ["*"] = {}, + }, + } + + self.db = LibStub("AceDB-3.0"):New("TomTomDB", self.defaults, "Default") + self.waydb = LibStub("AceDB-3.0"):New("TomTomWaypointsMF", self.waydefaults) + + self.db.RegisterCallback(self, "OnProfileChanged", "ReloadOptions") + self.db.RegisterCallback(self, "OnProfileCopied", "ReloadOptions") + self.db.RegisterCallback(self, "OnProfileReset", "ReloadOptions") + self.waydb.RegisterCallback(self, "OnProfileChanged", "ReloadWaypoints") + self.waydb.RegisterCallback(self, "OnProfileCopied", "ReloadWaypoints") + self.waydb.RegisterCallback(self, "OnProfileReset", "ReloadWaypoints") + + self.tooltip = CreateFrame("GameTooltip", "TomTomTooltip", nil, "GameTooltipTemplate") self.tooltip:SetFrameStrata("DIALOG") - self.dropdown = CreateFrame("Frame", "TomTomDropdown", nil, "UIDropDownMenuTemplate") + self.dropdown = CreateFrame("Frame", "TomTomDropdown", nil, "UIDropDownMenuTemplate") -- Both the waypoints and waypointprofile tables are going to contain subtables for each -- of the mapids that might exist. Under these will be a hash of key/waypoint pairs consisting -- of the waypoints for the given map file. - self.waypoints = waypoints - self.waypointprofile = self.waydb.profile + self.waypoints = waypoints + self.waypointprofile = self.waydb.profile - self:RegisterEvent("PLAYER_LEAVING_WORLD") - self:RegisterEvent("CHAT_MSG_ADDON") + self:RegisterEvent("PLAYER_LEAVING_WORLD") + self:RegisterEvent("CHAT_MSG_ADDON") - self:ReloadOptions() - self:ReloadWaypoints() + 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 = "", - }) + 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 = self.db.profile.feeds.coords_throttle, 0 + local coordFeedFrame = CreateFrame("Frame") + local throttle, counter = self.db.profile.feeds.coords_throttle, 0 function TomTom:_privateupdatecoordthrottle(x) throttle = x end - coordFeedFrame:SetScript("OnUpdate", function(self, elapsed) - counter = counter + elapsed - if counter < throttle then - return - end + coordFeedFrame:SetScript("OnUpdate", function(self, elapsed) + counter = counter + elapsed + if counter < throttle then + return + end - counter = 0 + counter = 0 local m, f, x, y = TomTom:GetCurrentPlayerPosition() - if x and y then + if x and y then local opt = TomTom.db.profile.feeds - feed_coords.text = string.format("%s", RoundCoords(x, y, opt.coords_accuracy)) - end - end) - end - end + feed_coords.text = string.format("%s", RoundCoords(x, y, opt.coords_accuracy)) + end + end) + end + end end -- Some utility functions that can pack/unpack data from a waypoint @@ -251,12 +251,12 @@ function TomTom:GetCurrentPlayerPosition() end function TomTom:ReloadOptions() - -- This handles the reloading of all options - self.profile = self.db.profile + -- This handles the reloading of all options + self.profile = self.db.profile - self:ShowHideWorldCoords() - self:ShowHideCoordBlock() - self:ShowHideCrazyArrow() + self:ShowHideWorldCoords() + self:ShowHideCoordBlock() + self:ShowHideCrazyArrow() self:EnableDisablePOIIntegration() end @@ -272,17 +272,17 @@ end function TomTom:ReloadWaypoints() self:ClearAllWaypoints() - waypoints = {} - self.waypoints = waypoints - self.waypointprofile = self.waydb.profile + waypoints = {} + self.waypoints = waypoints + self.waypointprofile = self.waydb.profile local cm, cf, cx, cy = TomTom:GetCurrentPlayerPosition() - for mapId,data in pairs(self.waypointprofile) do - local same = mapId == cm - local minimap = self.profile.minimap.enable and (self.profile.minimap.otherzone or same) - local world = self.profile.worldmap.enable and (self.profile.worldmap.otherzone or same) - for key,waypoint in pairs(data) do + for mapId,data in pairs(self.waypointprofile) do + local same = mapId == cm + local minimap = self.profile.minimap.enable and (self.profile.minimap.otherzone or same) + local world = self.profile.worldmap.enable and (self.profile.worldmap.otherzone or same) + for key,waypoint in pairs(data) do local m,f,x,y = unpack(waypoint) local title = waypoint.title @@ -295,8 +295,8 @@ function TomTom:ReloadWaypoints() callbacks = nil, silent = true, }) - end - end + end + end end function TomTom:UpdateCoordFeedThrottle() @@ -315,15 +315,15 @@ hooksecurefunc("WorldMap_ToggleSizeDown", function() 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 - -- Create the frame if it doesn't exist - if not TomTomWorldFrame then - TomTomWorldFrame = CreateFrame("Frame", nil, WorldMapFrame) - TomTomWorldFrame.Player = TomTomWorldFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall") - TomTomWorldFrame.Cursor = TomTomWorldFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall") - TomTomWorldFrame:SetScript("OnUpdate", WorldMap_OnUpdate) - end + -- Bail out if we're not supposed to be showing this frame + 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) + TomTomWorldFrame.Player = TomTomWorldFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall") + TomTomWorldFrame.Cursor = TomTomWorldFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall") + TomTomWorldFrame:SetScript("OnUpdate", WorldMap_OnUpdate) + end TomTomWorldFrame.Player:ClearAllPoints() TomTomWorldFrame.Cursor:ClearAllPoints() @@ -337,113 +337,113 @@ function TomTom:ShowHideWorldCoords() end TomTomWorldFrame.Player:Hide() - TomTomWorldFrame.Cursor:Hide() + TomTomWorldFrame.Cursor:Hide() - if self.profile.mapcoords.playerenable then - TomTomWorldFrame.Player:Show() - end + if self.profile.mapcoords.playerenable then + TomTomWorldFrame.Player:Show() + end - if self.profile.mapcoords.cursorenable then - TomTomWorldFrame.Cursor:Show() - end + if self.profile.mapcoords.cursorenable then + TomTomWorldFrame.Cursor:Show() + end - -- Show the frame - TomTomWorldFrame:Show() - elseif TomTomWorldFrame then - TomTomWorldFrame:Hide() - end + -- Show the frame + TomTomWorldFrame:Show() + elseif TomTomWorldFrame then + TomTomWorldFrame:Hide() + end end function TomTom:ShowHideCoordBlock() - -- Bail out if we're not supposed to be showing this frame - if self.profile.block.enable then - -- Create the frame if it doesn't exist - if not TomTomBlock then - -- Create the coordinate display - TomTomBlock = CreateFrame("Button", "TomTomBlock", UIParent) - TomTomBlock:SetWidth(120) - TomTomBlock:SetHeight(32) - TomTomBlock:SetToplevel(1) - TomTomBlock:SetFrameStrata("LOW") - TomTomBlock:SetMovable(true) - TomTomBlock:EnableMouse(true) - TomTomBlock:SetClampedToScreen() - TomTomBlock:RegisterForDrag("LeftButton") - TomTomBlock:RegisterForClicks("RightButtonUp") - TomTomBlock:SetPoint("TOP", Minimap, "BOTTOM", -20, -10) - - TomTomBlock.Text = TomTomBlock:CreateFontString(nil, "OVERLAY", "GameFontNormal") - TomTomBlock.Text:SetJustifyH("CENTER") - TomTomBlock.Text:SetPoint("CENTER", 0, 0) - - TomTomBlock:SetBackdrop({ - bgFile = "Interface\\ChatFrame\\ChatFrameBackground", - edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", - edgeSize = 16, - insets = {left = 4, right = 4, top = 4, bottom = 4}, - }) - TomTomBlock:SetBackdropColor(0,0,0,0.4) - TomTomBlock:SetBackdropBorderColor(1,0.8,0,0.8) - - -- Set behavior scripts - TomTomBlock:SetScript("OnUpdate", Block_OnUpdate) - TomTomBlock:SetScript("OnClick", Block_OnClick) - TomTomBlock:SetScript("OnEnter", Block_OnEnter) - TomTomBlock:SetScript("OnLeave", Block_OnLeave) - TomTomBlock:SetScript("OnDragStop", Block_OnDragStop) - TomTomBlock:SetScript("OnDragStart", Block_OnDragStart) - end - -- Show the frame - TomTomBlock:Show() - - local opt = self.profile.block - - -- Update the backdrop color, and border color - TomTomBlock:SetBackdropColor(unpack(opt.bgcolor)) - TomTomBlock:SetBackdropBorderColor(unpack(opt.bordercolor)) - - -- Update the height and width - TomTomBlock:SetHeight(opt.height) - TomTomBlock:SetWidth(opt.width) - - -- Update the font size - local font,height = TomTomBlock.Text:GetFont() - TomTomBlock.Text:SetFont(font, opt.fontsize, select(3, TomTomBlock.Text:GetFont())) - - elseif TomTomBlock then - TomTomBlock:Hide() - end + -- Bail out if we're not supposed to be showing this frame + if self.profile.block.enable then + -- Create the frame if it doesn't exist + if not TomTomBlock then + -- Create the coordinate display + TomTomBlock = CreateFrame("Button", "TomTomBlock", UIParent) + TomTomBlock:SetWidth(120) + TomTomBlock:SetHeight(32) + TomTomBlock:SetToplevel(1) + TomTomBlock:SetFrameStrata("LOW") + TomTomBlock:SetMovable(true) + TomTomBlock:EnableMouse(true) + TomTomBlock:SetClampedToScreen() + TomTomBlock:RegisterForDrag("LeftButton") + TomTomBlock:RegisterForClicks("RightButtonUp") + TomTomBlock:SetPoint("TOP", Minimap, "BOTTOM", -20, -10) + + TomTomBlock.Text = TomTomBlock:CreateFontString(nil, "OVERLAY", "GameFontNormal") + TomTomBlock.Text:SetJustifyH("CENTER") + TomTomBlock.Text:SetPoint("CENTER", 0, 0) + + TomTomBlock:SetBackdrop({ + bgFile = "Interface\\ChatFrame\\ChatFrameBackground", + edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", + edgeSize = 16, + insets = {left = 4, right = 4, top = 4, bottom = 4}, + }) + TomTomBlock:SetBackdropColor(0,0,0,0.4) + TomTomBlock:SetBackdropBorderColor(1,0.8,0,0.8) + + -- Set behavior scripts + TomTomBlock:SetScript("OnUpdate", Block_OnUpdate) + TomTomBlock:SetScript("OnClick", Block_OnClick) + TomTomBlock:SetScript("OnEnter", Block_OnEnter) + TomTomBlock:SetScript("OnLeave", Block_OnLeave) + TomTomBlock:SetScript("OnDragStop", Block_OnDragStop) + TomTomBlock:SetScript("OnDragStart", Block_OnDragStart) + end + -- Show the frame + TomTomBlock:Show() + + local opt = self.profile.block + + -- Update the backdrop color, and border color + TomTomBlock:SetBackdropColor(unpack(opt.bgcolor)) + TomTomBlock:SetBackdropBorderColor(unpack(opt.bordercolor)) + + -- Update the height and width + TomTomBlock:SetHeight(opt.height) + TomTomBlock:SetWidth(opt.width) + + -- Update the font size + local font,height = TomTomBlock.Text:GetFont() + TomTomBlock.Text:SetFont(font, opt.fontsize, select(3, TomTomBlock.Text:GetFont())) + + elseif TomTomBlock then + TomTomBlock:Hide() + end end -- Hook the WorldMap OnClick local world_click_verify = { - ["A"] = function() return IsAltKeyDown() end, - ["C"] = function() return IsControlKeyDown() end, - ["S"] = function() return IsShiftKeyDown() end, + ["A"] = function() return IsAltKeyDown() end, + ["C"] = function() return IsControlKeyDown() end, + ["S"] = function() return IsShiftKeyDown() end, } local origScript = WorldMapButton_OnClick WorldMapButton_OnClick = function(self, ...) - local mouseButton, button = ... - if mouseButton == "RightButton" then - -- Check for all the modifiers that are currently set - for mod in TomTom.db.profile.worldmap.create_modifier:gmatch("[ACS]") do - if not world_click_verify[mod] or not world_click_verify[mod]() then + local mouseButton, button = ... + if mouseButton == "RightButton" then + -- Check for all the modifiers that are currently set + for mod in TomTom.db.profile.worldmap.create_modifier:gmatch("[ACS]") do + if not world_click_verify[mod] or not world_click_verify[mod]() then return origScript and origScript(self, ...) or true - end - end + end + end local m,f = GetCurrentMapAreaID() - local x,y = GetCurrentCursorPosition() + local x,y = GetCurrentCursorPosition() - if not m then - return origScript and origScript(self, ...) or true - end + if not m then + return origScript and origScript(self, ...) or true + end - local uid = TomTom:AddMFWaypoint(m,f,x,y) - else - return origScript and origScript(self, ...) or true - end + local uid = TomTom:AddMFWaypoint(m,f,x,y) + else + return origScript and origScript(self, ...) or true + end end if WorldMapButton:GetScript("OnMouseUp") == origScript then @@ -451,18 +451,18 @@ if WorldMapButton:GetScript("OnMouseUp") == origScript then end local function WaypointCallback(event, arg1, arg2, arg3) - if event == "OnDistanceArrive" then - TomTom:ClearWaypoint(arg1) - elseif event == "OnTooltipShown" then - local tooltip = arg1 - if arg3 then - tooltip:SetText(L["TomTom waypoint"]) - tooltip:AddLine(string.format(L["%s yards away"], math.floor(arg2)), 1, 1 ,1) - tooltip:Show() - else - tooltip.lines[2]:SetFormattedText(L["%s yards away"], math.floor(arg2), 1, 1, 1) - end - end + if event == "OnDistanceArrive" then + TomTom:ClearWaypoint(arg1) + elseif event == "OnTooltipShown" then + local tooltip = arg1 + if arg3 then + tooltip:SetText(L["TomTom waypoint"]) + tooltip:AddLine(string.format(L["%s yards away"], math.floor(arg2)), 1, 1 ,1) + tooltip:Show() + else + tooltip.lines[2]:SetFormattedText(L["%s yards away"], math.floor(arg2), 1, 1, 1) + end + end end --[[------------------------------------------------------------------- @@ -470,265 +470,265 @@ end -------------------------------------------------------------------]]-- 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() - TomTom.waydb:ResetProfile() - TomTom:ReloadWaypoints() - end, - timeout = 30, - whileDead = 1, - hideOnEscape = 1, + text = L["Are you sure you would like to remove ALL TomTom waypoints?"], + button1 = L["Yes"], + button2 = L["No"], + OnAccept = function() + TomTom.waydb:ResetProfile() + TomTom:ReloadWaypoints() + end, + timeout = 30, + whileDead = 1, + hideOnEscape = 1, } local dropdown_info = { - -- Define level one elements here - [1] = { - { -- Title - text = L["Waypoint Options"], - isTitle = 1, - }, - { - -- set as crazy arrow - text = L["Set as waypoint arrow"], - func = function() - local uid = TomTom.dropdown.uid - local data = uid - TomTom:SetCrazyArrow(uid, TomTom.profile.arrow.arrival, data.title or L["TomTom waypoint"]) - end, - }, - { - -- Send waypoint - text = L["Send waypoint to"], - hasArrow = true, - value = "send", - }, - { -- Remove waypoint - text = L["Remove waypoint"], - func = function() - local uid = TomTom.dropdown.uid - local data = uid - TomTom:RemoveWaypoint(uid) - --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 = uid - local mapId = data[1] - for key, waypoint in pairs(waypoints[mapId]) do - TomTom:RemoveWaypoint(waypoint) - end - end, - }, - { -- Remove ALL waypoints - text = L["Remove all waypoints"], - func = function() - if TomTom.db.profile.general.confirmremoveall then - StaticPopup_Show("TOMTOM_REMOVE_ALL_CONFIRM") - else - StaticPopupDialogs["TOMTOM_REMOVE_ALL_CONFIRM"].OnAccept() - return - end - end, - }, - { -- Save this waypoint - text = L["Save this waypoint between sessions"], - checked = function() - return TomTom:UIDIsSaved(TomTom.dropdown.uid) - end, - func = function() - -- Add/remove it from the SV file - local uid = TomTom.dropdown.uid - local data = waypoints[uid] - if data then - local key = TomTom:GetKey(data) - local mapId = data[1] - - if mapId then - if UIDIsSavedTomTom.waypointprofile[mapId][key] then - TomTom.waypointprofile[mapId][key] = nil - else - TomTom.waypointprofile[mapId][key] = data - end - end + -- Define level one elements here + [1] = { + { -- Title + text = L["Waypoint Options"], + isTitle = 1, + }, + { + -- set as crazy arrow + text = L["Set as waypoint arrow"], + func = function() + local uid = TomTom.dropdown.uid + local data = uid + TomTom:SetCrazyArrow(uid, TomTom.profile.arrow.arrival, data.title or L["TomTom waypoint"]) + end, + }, + { + -- Send waypoint + text = L["Send waypoint to"], + hasArrow = true, + value = "send", + }, + { -- Remove waypoint + text = L["Remove waypoint"], + func = function() + local uid = TomTom.dropdown.uid + local data = uid + TomTom:RemoveWaypoint(uid) + --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 = uid + local mapId = data[1] + for key, waypoint in pairs(waypoints[mapId]) do + TomTom:RemoveWaypoint(waypoint) + end +end, + }, + { -- Remove ALL waypoints + text = L["Remove all waypoints"], + func = function() + if TomTom.db.profile.general.confirmremoveall then + StaticPopup_Show("TOMTOM_REMOVE_ALL_CONFIRM") + else + StaticPopupDialogs["TOMTOM_REMOVE_ALL_CONFIRM"].OnAccept() + return + end + end, + }, + { -- Save this waypoint + text = L["Save this waypoint between sessions"], + checked = function() + return TomTom:UIDIsSaved(TomTom.dropdown.uid) + end, + func = function() + -- Add/remove it from the SV file + local uid = TomTom.dropdown.uid + local data = waypoints[uid] + if data then + local key = TomTom:GetKey(data) + local mapId = data[1] + + if mapId then + if UIDIsSavedTomTom.waypointprofile[mapId][key] then + TomTom.waypointprofile[mapId][key] = nil + else + TomTom.waypointprofile[mapId][key] = data + end + end + end + end, +}, + }, + [2] = { + send = { + { + -- Title + text = L["Waypoint communication"], + isTitle = true, + }, + { + -- Party + text = L["Send to party"], + func = function() + TomTom:SendWaypoint(TomTom.dropdown.uid, "PARTY") end - end, - }, - }, - [2] = { - send = { - { - -- Title - text = L["Waypoint communication"], - isTitle = true, - }, - { - -- Party - text = L["Send to party"], - func = function() - TomTom:SendWaypoint(TomTom.dropdown.uid, "PARTY") - end - }, - { - -- Raid - text = L["Send to raid"], - func = function() - TomTom:SendWaypoint(TomTom.dropdown.uid, "RAID") - end - }, - { - -- Battleground - text = L["Send to battleground"], - func = function() - TomTom:SendWaypoint(TomTom.dropdown.uid, "BATTLEGROUND") - end - }, - { - -- Guild - text = L["Send to guild"], - func = function() - TomTom:SendWaypoint(TomTom.dropdown.uid, "GUILD") - end - }, - }, - }, + }, + { + -- Raid + text = L["Send to raid"], + func = function() + TomTom:SendWaypoint(TomTom.dropdown.uid, "RAID") + end + }, + { + -- Battleground + text = L["Send to battleground"], + func = function() + TomTom:SendWaypoint(TomTom.dropdown.uid, "BATTLEGROUND") + end + }, + { + -- Guild + text = L["Send to guild"], + func = function() + TomTom:SendWaypoint(TomTom.dropdown.uid, "GUILD") + end + }, + }, + }, } local function init_dropdown(self, level) - -- Make sure level is set to 1, if not supplied - level = level or 1 - - -- Get the current level from the info table - local info = dropdown_info[level] - - -- If a value has been set, try to find it at the current level - if level > 1 and UIDROPDOWNMENU_MENU_VALUE then - if info[UIDROPDOWNMENU_MENU_VALUE] then - info = info[UIDROPDOWNMENU_MENU_VALUE] - end - end - - -- 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 - else - entry.checked = nil - end - - UIDropDownMenu_AddButton(entry, level) - end + -- Make sure level is set to 1, if not supplied + level = level or 1 + + -- Get the current level from the info table + local info = dropdown_info[level] + + -- If a value has been set, try to find it at the current level + if level > 1 and UIDROPDOWNMENU_MENU_VALUE then + if info[UIDROPDOWNMENU_MENU_VALUE] then + info = info[UIDROPDOWNMENU_MENU_VALUE] + end + end + + -- 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 + else + entry.checked = nil + end + + UIDropDownMenu_AddButton(entry, level) + end end function TomTom:InitializeDropdown(uid) - self.dropdown.uid = uid - UIDropDownMenu_Initialize(self.dropdown, init_dropdown) + self.dropdown.uid = uid + UIDropDownMenu_Initialize(self.dropdown, init_dropdown) end function TomTom:UIDIsSaved(uid) - local data = uid - if data then + local data = uid + if data then local key = TomTom:GetKey(data) local mapId = data[1] if data then return not not TomTom.waypointprofile[mapId][key] end - end - return false + end + return false end function TomTom:SendWaypoint(uid, channel) - local data = uid + local data = uid local m, f, x, y = unpack(data) - local msg = string.format("%d:%d:%f:%f:%s", m, f, x, y, data.title or "") - SendAddonMessage("TOMTOM3", msg, channel) + local msg = string.format("%d:%d:%f:%f:%s", m, f, x, y, data.title or "") + SendAddonMessage("TOMTOM3", msg, channel) end function TomTom:CHAT_MSG_ADDON(event, prefix, data, channel, sender) - if prefix ~= "TOMTOM3" then return end - if sender == UnitName("player") then return end + if prefix ~= "TOMTOM3" then return end + if sender == UnitName("player") then return end - local m,f,x,y,title = string.split(":", data) - if not title:match("%S") then - title = string.format(L["Waypoint from %s"], sender) - end + local m,f,x,y,title = string.split(":", data) + if not title:match("%S") then + title = string.format(L["Waypoint from %s"], sender) + end local zoneName = lmd:MapLocalize(m) - self:AddMFWaypoint(m, f, x, y, {title = title}) - local msg = string.format(L["|cffffff78TomTom|r: Added '%s' (sent from %s) to zone %s"], title, sender, zoneName) - ChatFrame1:AddMessage(msg) + self:AddMFWaypoint(m, f, x, y, {title = title}) + local msg = string.format(L["|cffffff78TomTom|r: Added '%s' (sent from %s) to zone %s"], title, sender, zoneName) + ChatFrame1:AddMessage(msg) end --[[------------------------------------------------------------------- -- Define callback functions -------------------------------------------------------------------]]-- local function _minimap_onclick(event, uid, self, button) - if TomTom.db.profile.minimap.menu then - TomTom:InitializeDropdown(uid) - ToggleDropDownMenu(1, nil, TomTom.dropdown, "cursor", 0, 0) - end + if TomTom.db.profile.minimap.menu then + TomTom:InitializeDropdown(uid) + ToggleDropDownMenu(1, nil, TomTom.dropdown, "cursor", 0, 0) + end end local function _world_onclick(event, uid, self, button) - if TomTom.db.profile.worldmap.menu then - TomTom:InitializeDropdown(uid) - ToggleDropDownMenu(1, nil, TomTom.dropdown, "cursor", 0, 0) - end + if TomTom.db.profile.worldmap.menu then + TomTom:InitializeDropdown(uid) + ToggleDropDownMenu(1, nil, TomTom.dropdown, "cursor", 0, 0) + end end local function _both_tooltip_show(event, tooltip, uid, dist) - local data = uid - - tooltip:SetText(data.title or L["TomTom waypoint"]) - if dist and tonumber(dist) then - tooltip:AddLine(string.format(L["%s yards away"], math.floor(dist)), 1, 1, 1) - else - tooltip:AddLine(L["Unknown distance"]) - end + local data = uid + + tooltip:SetText(data.title or L["TomTom waypoint"]) + if dist and tonumber(dist) then + tooltip:AddLine(string.format(L["%s yards away"], math.floor(dist)), 1, 1, 1) + else + tooltip:AddLine(L["Unknown distance"]) + end local m,f,x,y = unpack(data) local zoneName = lmd:MapLocalize(m) - tooltip:AddLine(string.format(L["%s (%.2f, %.2f)"], zoneName, x*100, y*100), 0.7, 0.7, 0.7) - tooltip:Show() + tooltip:AddLine(string.format(L["%s (%.2f, %.2f)"], zoneName, x*100, y*100), 0.7, 0.7, 0.7) + tooltip:Show() end local function _minimap_tooltip_show(event, tooltip, uid, dist) - if not TomTom.db.profile.minimap.tooltip then - tooltip:Hide() - return - end - return _both_tooltip_show(event, tooltip, uid, dist) + if not TomTom.db.profile.minimap.tooltip then + tooltip:Hide() + return + end + return _both_tooltip_show(event, tooltip, uid, dist) end local function _world_tooltip_show(event, tooltip, uid, dist) - if not TomTom.db.profile.worldmap.tooltip then - tooltip:Hide() - return - end - return _both_tooltip_show(event, tooltip, uid, dist) + if not TomTom.db.profile.worldmap.tooltip then + tooltip:Hide() + return + end + return _both_tooltip_show(event, tooltip, uid, dist) end local function _both_tooltip_update(event, tooltip, uid, dist) - if dist and tonumber(dist) then - tooltip.lines[2]:SetFormattedText(L["%s yards away"], math.floor(dist), 1, 1, 1) - else - tooltip.lines[2]:SetText(L["Unknown distance"]) - end + if dist and tonumber(dist) then + tooltip.lines[2]:SetFormattedText(L["%s yards away"], math.floor(dist), 1, 1, 1) + else + tooltip.lines[2]:SetText(L["Unknown distance"]) + end end local function _both_clear_distance(event, uid, range, distance, lastdistance) - if not UnitOnTaxi("player") then - TomTom:RemoveWaypoint(uid) - end + if not UnitOnTaxi("player") then + TomTom:RemoveWaypoint(uid) + end end local function _both_ping_arrival(event, uid, range, distance, lastdistance) @@ -738,51 +738,51 @@ local function _both_ping_arrival(event, uid, range, distance, lastdistance) end local function _remove(event, uid) - local data = uid + local data = uid local key = TomTom:GetKey(data) local mapId = data[1] - local sv = TomTom.waypointprofile[mapId] + local sv = TomTom.waypointprofile[mapId] if sv and sv[key] then sv[key] = nil end - -- Remove this entry from the waypoints table - if waypoints[mapId] then - waypoints[mapId][key] = nil - end + -- Remove this entry from the waypoints table + if waypoints[mapId] then + waypoints[mapId][key] = nil + end end local function noop() end function TomTom:RemoveWaypoint(uid) - local data = uid - self:ClearWaypoint(uid) + local data = uid + self:ClearWaypoint(uid) local key = TomTom:GetKey(data) local mapId = data[1] - local sv = TomTom.waypointprofile[mapId] + local sv = TomTom.waypointprofile[mapId] if sv and sv[key] then sv[key] = nil end - -- Remove this entry from the waypoints table - if waypoints[mapId] then - waypoints[mapId][key] = nil - end + -- Remove this entry from the waypoints table + if waypoints[mapId] then + waypoints[mapId][key] = nil + end end -- TODO: Make this not suck function TomTom:AddWaypoint(x, y, desc, persistent, minimap, world, silent) - local c,z = GetCurrentMapContinent(), GetCurrentMapZone() + local c,z = GetCurrentMapContinent(), GetCurrentMapZone() - if not c or not z or c < 1 then - --self:Print("Cannot find a valid zone to place the coordinates") - return - end + 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, minimap, world, nil, silent) + return self:AddZWaypoint(c, z, x, y, desc, persistent, minimap, world, nil, silent) end function TomTom:AddZWaypoint(c, z, x, y, desc, persistent, minimap, world, callbacks, silent, crazy) @@ -807,27 +807,27 @@ end function TomTom:AddMFWaypoint(m, f, x, y, opts) opts = opts or {} - local callbacks - if opts.callbacks then - callbacks = opts.callbacks - else - callbacks = { - minimap = { - onclick = _minimap_onclick, - tooltip_show = _minimap_tooltip_show, - tooltip_update = _both_tooltip_update, - }, - world = { - onclick = _world_onclick, - tooltip_show = _world_tooltip_show, - tooltip_update = _both_tooltip_show, - }, - distance = { - }, - } - end - - local cleardistance = self.profile.persistence.cleardistance + local callbacks + if opts.callbacks then + callbacks = opts.callbacks + else + callbacks = { + minimap = { + onclick = _minimap_onclick, + tooltip_show = _minimap_tooltip_show, + tooltip_update = _both_tooltip_update, + }, + world = { + onclick = _world_onclick, + tooltip_show = _world_tooltip_show, + tooltip_update = _both_tooltip_show, + }, + distance = { + }, + } + end + + local cleardistance = self.profile.persistence.cleardistance local arrivaldistance = self.profile.arrow.arrival -- Allow both of these to be overridde by options @@ -850,19 +850,19 @@ function TomTom:AddMFWaypoint(m, f, x, y, opts) if arrivaldistance > 0 then callbacks.distance[arrivaldistance] = _both_ping_arrival end - end + end - -- Default values - if opts.persistent == nil then opts.persistent = self.profile.persistence.savewaypoints end - if opts.minimap == nil then opts.minimap = self.profile.minimap.enable end - if opts.world == nil then opts.world = self.profile.worldmap.enable end - if opts.crazy == nil then opts.crazy = self.profile.arrow.autoqueue end + -- Default values + if opts.persistent == nil then opts.persistent = self.profile.persistence.savewaypoints end + if opts.minimap == nil then opts.minimap = self.profile.minimap.enable end + if opts.world == nil then opts.world = self.profile.worldmap.enable end + if opts.crazy == nil then opts.crazy = self.profile.arrow.autoqueue end local zoneName = lmd:MapLocalize(m) if not astrolabe:GetMapInfo(m) then - return - end + return + end -- Get the default map floor, if necessary if not f then @@ -870,7 +870,7 @@ function TomTom:AddMFWaypoint(m, f, x, y, opts) f = floors == 0 and 0 or 1 end - -- Ensure there isn't already a waypoint at this location + -- Ensure there isn't already a waypoint at this location local key = self:GetKey({m, f, x, y, title = opts.title}) if waypoints[m] and waypoints[m][key] then return waypoints[m][key] @@ -887,28 +887,28 @@ function TomTom:AddMFWaypoint(m, f, x, y, opts) end -- No need to convert x and y because they're already 0-1 instead of 0-100 - self:SetWaypoint(uid, callbacks, opts.minimap, opts.world) - if opts.crazy then - self:SetCrazyArrow(uid, arrivaldistance, opts.title) - end + self:SetWaypoint(uid, callbacks, opts.minimap, opts.world) + if opts.crazy then + self:SetCrazyArrow(uid, arrivaldistance, opts.title) + end waypoints[m] = waypoints[m] or {} waypoints[m][key] = uid - -- If this is a persistent waypoint, then add it to the waypoints table - if opts.persistent then + -- If this is a persistent waypoint, then add it to the waypoints table + if opts.persistent then self.waypointprofile[m][key] = uid - end + end - if not opts.silent and self.profile.general.announce then - local ctxt = RoundCoords(x, y, 2) + if not opts.silent and self.profile.general.announce then + local ctxt = RoundCoords(x, y, 2) local desc = opts.desc and opts.desc or "" local sep = opts.desc and " - " or "" local msg = string.format(L["|cffffff78TomTom:|r Added a waypoint (%s%s%s) in %s"], desc, sep, ctxt, zoneName) - ChatFrame1:AddMessage(msg) - end + ChatFrame1:AddMessage(msg) + end - return uid + return uid end -- Check to see if a given uid/waypoint is actually set somewhere @@ -937,7 +937,7 @@ function TomTom:WaypointExists(c, z, x, y, desc) end function TomTom:SetCustomWaypoint(c,z,x,y,callback,minimap,world,silent) - return self:AddZWaypoint(c, z, x, y, nil, false, minimap, world, callback, silent) + return self:AddZWaypoint(c, z, x, y, nil, false, minimap, world, callback, silent) end function TomTom:SetCustomMFWaypoint(m, f, x, y, opts) @@ -947,52 +947,52 @@ function TomTom:SetCustomMFWaypoint(m, f, x, y, opts) end do - -- Code courtesy ckknight - function GetCurrentCursorPosition() - local x, y = GetCursorPosition() - local left, top = WorldMapDetailFrame:GetLeft(), WorldMapDetailFrame:GetTop() - local width = WorldMapDetailFrame:GetWidth() - local height = WorldMapDetailFrame:GetHeight() - local scale = WorldMapDetailFrame:GetEffectiveScale() - local cx = (x/scale - left) / width - local cy = (top - y/scale) / height - - if cx < 0 or cx > 1 or cy < 0 or cy > 1 then - return nil, nil - end - - return cx, cy - end - - local coord_fmt = "%%.%df, %%.%df" - function RoundCoords(x,y,prec) - local fmt = coord_fmt:format(prec, prec) - return fmt:format(x*100, y*100) - end - - function WorldMap_OnUpdate(self, elapsed) - local m,f,x,y = TomTom:GetCurrentPlayerPosition() - local opt = TomTom.db.profile - - if not x or not y then - self.Player:SetText("Player: ---") - else - self.Player:SetFormattedText("Player: %s", RoundCoords(x, y, opt.mapcoords.playeraccuracy)) - end - - local cX, cY = GetCurrentCursorPosition() - - if not cX or not cY then - self.Cursor:SetText("Cursor: ---") - else - self.Cursor:SetFormattedText("Cursor: %s", RoundCoords(cX, cY, opt.mapcoords.cursoraccuracy)) - end - end + -- Code courtesy ckknight + function GetCurrentCursorPosition() + local x, y = GetCursorPosition() + local left, top = WorldMapDetailFrame:GetLeft(), WorldMapDetailFrame:GetTop() + local width = WorldMapDetailFrame:GetWidth() + local height = WorldMapDetailFrame:GetHeight() + local scale = WorldMapDetailFrame:GetEffectiveScale() + local cx = (x/scale - left) / width + local cy = (top - y/scale) / height + + if cx < 0 or cx > 1 or cy < 0 or cy > 1 then + return nil, nil + end + + return cx, cy + end + + local coord_fmt = "%%.%df, %%.%df" + function RoundCoords(x,y,prec) + local fmt = coord_fmt:format(prec, prec) + return fmt:format(x*100, y*100) + end + + function WorldMap_OnUpdate(self, elapsed) + local m,f,x,y = TomTom:GetCurrentPlayerPosition() + local opt = TomTom.db.profile + + if not x or not y then + self.Player:SetText("Player: ---") + else + self.Player:SetFormattedText("Player: %s", RoundCoords(x, y, opt.mapcoords.playeraccuracy)) + end + + local cX, cY = GetCurrentCursorPosition() + + if not cX or not cY then + self.Cursor:SetText("Cursor: ---") + else + self.Cursor:SetFormattedText("Cursor: %s", RoundCoords(cX, cY, opt.mapcoords.cursoraccuracy)) + end + end end do local bcounter = 0 - function Block_OnUpdate(self, elapsed) + function Block_OnUpdate(self, elapsed) bcounter = bcounter + elapsed if bcounter > TomTom.profile.block.throttle then bcounter = bcounter - TomTom.profile.block.throttle @@ -1009,15 +1009,15 @@ do end end - function Block_OnDragStart(self, button, down) - if not TomTom.db.profile.block.lock then - self:StartMoving() - end - end + function Block_OnDragStart(self, button, down) + if not TomTom.db.profile.block.lock then + self:StartMoving() + end + end - function Block_OnDragStop(self, button, down) - self:StopMovingOrSizing() - end + function Block_OnDragStop(self, button, down) + self:StopMovingOrSizing() + end function Block_OnClick(self, button, down) local m,f,x,y = TomTom:GetCurrentPlayerPosition() @@ -1030,50 +1030,50 @@ do end local function usage() - ChatFrame1:AddMessage(L["|cffffff78TomTom |r/way |cffffff78Usage:|r"]) - ChatFrame1:AddMessage(L["|cffffff78/way <x> <y> [desc]|r - Adds a waypoint at x,y with descrtiption desc"]) - ChatFrame1:AddMessage(L["|cffffff78/way <zone> <x> <y> [desc]|r - Adds a waypoint at x,y in zone with description desc"]) - ChatFrame1:AddMessage(L["|cffffff78/way reset all|r - Resets all waypoints"]) - ChatFrame1:AddMessage(L["|cffffff78/way reset <zone>|r - Resets all waypoints in zone"]) + ChatFrame1:AddMessage(L["|cffffff78TomTom |r/way |cffffff78Usage:|r"]) + ChatFrame1:AddMessage(L["|cffffff78/way <x> <y> [desc]|r - Adds a waypoint at x,y with descrtiption desc"]) + ChatFrame1:AddMessage(L["|cffffff78/way <zone> <x> <y> [desc]|r - Adds a waypoint at x,y in zone with description desc"]) + ChatFrame1:AddMessage(L["|cffffff78/way reset all|r - Resets all waypoints"]) + ChatFrame1:AddMessage(L["|cffffff78/way reset <zone>|r - Resets all waypoints in zone"]) end function TomTom:GetClosestWaypoint() local m,f,x,y = self:GetCurrentPlayerPosition() - local closest_waypoint = nil - local closest_dist = nil - if waypoints[m] then - for key, waypoint in pairs(waypoints[m]) do + local closest_waypoint = nil + local closest_dist = nil + if waypoints[m] then + for key, waypoint in pairs(waypoints[m]) do local dist, x, y = TomTom:GetDistanceToWaypoint(waypoint) - if (dist and closest_dist == nil) or (dist and dist < closest_dist) then - closest_dist = dist - closest_waypoint = waypoint - end - end - end - if closest_dist then - return closest_waypoint - end + if (dist and closest_dist == nil) or (dist and dist < closest_dist) then + closest_dist = dist + closest_waypoint = waypoint + end + end + end + if closest_dist then + return closest_waypoint + end end function TomTom:SetClosestWaypoint() - local uid = self:GetClosestWaypoint() - if uid then - local data = uid - TomTom:SetCrazyArrow(uid, TomTom.profile.arrow.arrival, data.title) - end + local uid = self:GetClosestWaypoint() + if uid then + local data = uid + TomTom:SetCrazyArrow(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() + TomTom:SetClosestWaypoint() end SLASH_TOMTOM_WAYBACK1 = "/wayb" SLASH_TOMTOM_WAYBACK2 = "/wayback" SlashCmdList["TOMTOM_WAYBACK"] = function(msg) - local backm,backf,backx,backy = TomTom:GetCurrentPlayerPosition() - TomTom:AddMFWaypoint(backm, backf, backx, backy, { + local backm,backf,backx,backy = TomTom:GetCurrentPlayerPosition() + TomTom:AddMFWaypoint(backm, backf, backx, backy, { title = L["Wayback"], }) end @@ -1097,47 +1097,47 @@ local rightseparator = "%1" .. (tonumber("1.1") and "." or ",") .. "%2" local function lowergsub(s) return s:lower():gsub("^[%a%d]", "") end SlashCmdList["TOMTOM_WAY"] = function(msg) - msg = msg:gsub("(%d)[%.,] (%d)", "%1 %2"):gsub(wrongseparator, rightseparator) - local tokens = {} - for token in msg:gmatch("%S+") do table.insert(tokens, token) end + msg = msg:gsub("(%d)[%.,] (%d)", "%1 %2"):gsub(wrongseparator, rightseparator) + local tokens = {} + for token in msg:gmatch("%S+") do table.insert(tokens, token) end - -- Lower the first token + -- Lower the first token local ltoken = tokens[1] and tokens[1]:lower() - if ltoken == "reset" then + if ltoken == "reset" then local ltoken2 = tokens[2] and tokens[2]:lower() - if ltoken2 == "all" then - if TomTom.db.profile.general.confirmremoveall then - StaticPopup_Show("TOMTOM_REMOVE_ALL_CONFIRM") - else - StaticPopupDialogs["TOMTOM_REMOVE_ALL_CONFIRM"].OnAccept() - return - end - - elseif tokens[2] then - -- Reset the named zone - local zone = table.concat(tokens, " ", 2) + if ltoken2 == "all" then + if TomTom.db.profile.general.confirmremoveall then + StaticPopup_Show("TOMTOM_REMOVE_ALL_CONFIRM") + else + StaticPopupDialogs["TOMTOM_REMOVE_ALL_CONFIRM"].OnAccept() + return + end + + elseif tokens[2] then + -- Reset the named zone + local zone = table.concat(tokens, " ", 2) -- Find a fuzzy match for the zone - local matches = {} - lzone = lowergsub(zone) + local matches = {} + lzone = lowergsub(zone) - for name, mapId in pairs(nameToMapId) do + for name, mapId in pairs(nameToMapId) do local lname = lowergsub(name) - if lname:match(lzone) then - table.insert(matches, name) - end - end - - if #matches > 5 then - local msg = string.format(L["Found %d possible matches for zone %s. Please be more specific"], #matches, zone) - ChatFrame1:AddMessage(msg) - return - elseif #matches > 1 then - table.sort(matches) - - ChatFrame1:AddMessage(string.format(L["Found multiple matches for zone '%s'. Did you mean: %s"], zone, table.concat(matches, ", "))) - return + if lname:match(lzone) then + table.insert(matches, name) + end + end + + if #matches > 5 then + local msg = string.format(L["Found %d possible matches for zone %s. Please be more specific"], #matches, zone) + ChatFrame1:AddMessage(msg) + return + elseif #matches > 1 then + table.sort(matches) + + ChatFrame1:AddMessage(string.format(L["Found multiple matches for zone '%s'. Did you mean: %s"], zone, table.concat(matches, ", "))) + return elseif #matches == 0 then local msg = string.format(L["Could not find any matches for zone %s."], zone) ChatFrame1:AddMessage(msg) @@ -1171,24 +1171,24 @@ SlashCmdList["TOMTOM_WAY"] = function(msg) local zoneEnd for idx = 1, #tokens do local token = tokens[idx] - if tonumber(token) then - -- We've encountered a number, so the zone name must have - -- ended at the prior token - zoneEnd = idx - 1 + if tonumber(token) then + -- We've encountered a number, so the zone name must have + -- ended at the prior token + zoneEnd = idx - 1 break - end - end + end + end if not zoneEnd then usage() return end - -- This is a waypoint set, with a zone before the coords - local zone = table.concat(tokens, " ", 1, zoneEnd) - local x,y,desc = select(zoneEnd + 1, unpack(tokens)) + -- This is a waypoint set, with a zone before the coords + local zone = table.concat(tokens, " ", 1, zoneEnd) + local x,y,desc = select(zoneEnd + 1, unpack(tokens)) - if desc then desc = table.concat(tokens, " ", zoneEnd + 3) end + if desc then desc = table.concat(tokens, " ", zoneEnd + 3) end -- Find a fuzzy match for the zone local matches = {} @@ -1201,22 +1201,22 @@ SlashCmdList["TOMTOM_WAY"] = function(msg) end end - if #matches > 5 then - local msg = string.format(L["Found %d possible matches for zone %s. Please be more specific"], #matches, zone) - ChatFrame1:AddMessage(msg) - return - elseif #matches > 1 then - local msg = string.format(L["Found multiple matches for zone '%s'. Did you mean: %s"], zone, table.concat(matches, ", ")) - ChatFrame1:AddMessage(msg) - return + if #matches > 5 then + local msg = string.format(L["Found %d possible matches for zone %s. Please be more specific"], #matches, zone) + ChatFrame1:AddMessage(msg) + return + elseif #matches > 1 then + local msg = string.format(L["Found multiple matches for zone '%s'. Did you mean: %s"], zone, table.concat(matches, ", ")) + ChatFrame1:AddMessage(msg) + return elseif #matches == 0 then local msg = string.format(L["Could not find any matches for zone %s."], zone) ChatFrame1:AddMessage(msg) return end - -- There was only one match, so proceed - local zoneName = matches[1] + -- There was only one match, so proceed + local zoneName = matches[1] local mapId = nameToMapId[zoneName] x = x and tonumber(x) @@ -1226,32 +1226,32 @@ SlashCmdList["TOMTOM_WAY"] = function(msg) return usage() end - x = tonumber(x) - y = tonumber(y) - TomTom:AddMFWaypoint(mapId, nil, x/100, y/100, { + x = tonumber(x) + y = tonumber(y) + TomTom:AddMFWaypoint(mapId, nil, x/100, y/100, { title = desc, }) - elseif tonumber(tokens[1]) then - -- A vanilla set command - local x,y,desc = unpack(tokens) - if not x or not tonumber(x) then - return usage() - elseif not y or not tonumber(y) then - return usage() - end - if desc then - desc = table.concat(tokens, " ", 3) - end + elseif tonumber(tokens[1]) then + -- A vanilla set command + local x,y,desc = unpack(tokens) + if not x or not tonumber(x) then + return usage() + elseif not y or not tonumber(y) then + return usage() + end + if desc then + desc = table.concat(tokens, " ", 3) + end x = tonumber(x) y = tonumber(y) local m, f = TomTom:GetCurrentPlayerPosition() if m and x and y then - TomTom:AddMFWaypoint(m, f, x/100, y/100, { + TomTom:AddMFWaypoint(m, f, x/100, y/100, { title = desc }) end - else - return usage() - end + else + return usage() + end end diff --git a/TomTom_Corpse.lua b/TomTom_Corpse.lua index 0ceec7d..9a30acb 100644 --- a/TomTom_Corpse.lua +++ b/TomTom_Corpse.lua @@ -18,16 +18,16 @@ local astrolabe = DongleStub("TTAstrolabe-1.0") local m,f,x,y,uid local function StartCorpseSearch() - if not IsInInstance() then - eventFrame:Show() - end + if not IsInInstance() then + eventFrame:Show() + end end local function ClearCorpseArrow() - if uid then - TomTom:RemoveWaypoint(uid) - m,f,x,y,uid = nil, nil, nil, nil, nil - end + if uid then + TomTom:RemoveWaypoint(uid) + m,f,x,y,uid = nil, nil, nil, nil, nil + end end local function GetCorpseLocation() @@ -38,10 +38,10 @@ local function GetCorpseLocation() end end - -- Cache the result so we don't scan the maps multiple times - if m and f and x and y then - return m, f, x, y - end + -- Cache the result so we don't scan the maps multiple times + if m and f and x and y then + return m, f, x, y + end -- See if the player corpse is on the current map local om = GetCurrentMapAreaID() @@ -57,97 +57,97 @@ local function GetCorpseLocation() -- Scan the continent maps to see if we can find the player's corpse local c - local oc,oz = GetCurrentMapContinent(), GetCurrentMapZone() - - for i=1,select("#", GetMapContinents()) do - SetMapZoom(i) - local cx, cy = GetCorpseMapPosition() - if cx ~= 0 and cy ~= 0 then - c = i - break - end - end - - -- If we found the corpse on a continent, find out which zone it is in - if c and c ~= -1 then - for i=1,select("#", GetMapZones(c)) do - SetMapZoom(c, i) - local cx,cy = GetCorpseMapPosition() - if cx > 0 and cy > 0 then + local oc,oz = GetCurrentMapContinent(), GetCurrentMapZone() + + for i=1,select("#", GetMapContinents()) do + SetMapZoom(i) + local cx, cy = GetCorpseMapPosition() + if cx ~= 0 and cy ~= 0 then + c = i + break + end + end + + -- If we found the corpse on a continent, find out which zone it is in + if c and c ~= -1 then + for i=1,select("#", GetMapZones(c)) do + SetMapZoom(c, i) + local cx,cy = GetCorpseMapPosition() + if cx > 0 and cy > 0 then m = GetCurrentMapAreaID() f = GetCurrentMapDungeonLevel() x = cx y = cy - break - end - end - end + break + end + end + end - -- Restore the map to its previous zoom level - SetMapZoom(oc, oz) + -- Restore the map to its previous zoom level + SetMapZoom(oc, oz) - if m and f and x and y then - return m,f,x,y - end + if m and f and x and y then + return m,f,x,y + end end local function SetCorpseArrow() - if m and f and x and y then - uid = TomTom:AddMFWaypoint(m, f, x, y, { + if m and f and x and y then + uid = TomTom:AddMFWaypoint(m, f, x, y, { title = L["My Corpse"], persistent = false, }) - return uid - end + return uid + end end local counter, throttle = 0, 0.5 eventFrame:SetScript("OnUpdate", function(self, elapsed) - counter = counter + elapsed - if counter < throttle then - return - else - counter = 0 - if TomTom.profile.general.corpse_arrow then - if GetCorpseLocation() then - if SetCorpseArrow() then - self:Hide() - end - end - else - self:Hide() - end - end + counter = counter + elapsed + if counter < throttle then + return + else + counter = 0 + if TomTom.profile.general.corpse_arrow then + if GetCorpseLocation() then + if SetCorpseArrow() then + self:Hide() + end + end + else + self:Hide() + end + end end) eventFrame:SetScript("OnEvent", function(self, event, arg1, ...) - if event == "ADDON_LOADED" and arg1 == "TomTom" then - self:UnregisterEvent("ADDON_LOADED") - if UnitIsDeadOrGhost("player") then - StartCorpseSearch() - end - end - - if event == "PLAYER_ALIVE" then - if UnitIsDeadOrGhost("player") then - StartCorpseSearch() - else - ClearCorpseArrow() - end - elseif event == "PLAYER_DEAD" then - -- Cheat a bit and avoid the map flipping - SetMapToCurrentZone() + if event == "ADDON_LOADED" and arg1 == "TomTom" then + self:UnregisterEvent("ADDON_LOADED") + if UnitIsDeadOrGhost("player") then + StartCorpseSearch() + end + end + + if event == "PLAYER_ALIVE" then + if UnitIsDeadOrGhost("player") then + StartCorpseSearch() + else + ClearCorpseArrow() + end + elseif event == "PLAYER_DEAD" then + -- Cheat a bit and avoid the map flipping + SetMapToCurrentZone() m = GetCurrentMapAreaID() f = GetCurrentMapDungeonLevel() if not IsInInstance() then x,y = GetPlayerMapPosition("player") end - StartCorpseSearch() - elseif event == "PLAYER_UNGHOST" then - ClearCorpseArrow() - end + StartCorpseSearch() + elseif event == "PLAYER_UNGHOST" then + ClearCorpseArrow() + end end) if IsLoggedIn() then - eventFrame:GetScript("OnEvent")(eventFrame, "ADDON_LOADED", "TomTom") + eventFrame:GetScript("OnEvent")(eventFrame, "ADDON_LOADED", "TomTom") end diff --git a/TomTom_POIIntegration.lua b/TomTom_POIIntegration.lua index 24a33d7..61ba948 100644 --- a/TomTom_POIIntegration.lua +++ b/TomTom_POIIntegration.lua @@ -197,24 +197,24 @@ end local hooked = {} hooksecurefunc("QuestPOI_DisplayButton", function(parentName, buttonType, buttonIndex, questId) - local buttonName = "poi"..tostring(parentName)..tostring(buttonType).."_"..tostring(buttonIndex); - local poiButton = _G[buttonName]; - - if not hooked[buttonName] then - poiButton:HookScript("OnClick", poi_OnClick) - poiButton:RegisterForClicks("AnyUp") - hooked[buttonName] = true - end - - -- Check to see if there is a swap button - local swapName = "poi" .. parentName .. "_Swap" - local swapButton = _G[swapName] - - if not hooked[swapName] and swapButton then - swapButton:HookScript("OnClick", poi_OnClick) - swapButton:RegisterForClicks("AnyUp") - hooked[swapName] = true - end + local buttonName = "poi"..tostring(parentName)..tostring(buttonType).."_"..tostring(buttonIndex); + local poiButton = _G[buttonName]; + + if not hooked[buttonName] then + poiButton:HookScript("OnClick", poi_OnClick) + poiButton:RegisterForClicks("AnyUp") + hooked[buttonName] = true + end + + -- Check to see if there is a swap button + local swapName = "poi" .. parentName .. "_Swap" + local swapButton = _G[swapName] + + if not hooked[swapName] and swapButton then + swapButton:HookScript("OnClick", poi_OnClick) + swapButton:RegisterForClicks("AnyUp") + hooked[swapName] = true + end end) function TomTom:EnableDisablePOIIntegration() diff --git a/TomTom_Waypoints.lua b/TomTom_Waypoints.lua index 1481bd8..47b0a74 100644 --- a/TomTom_Waypoints.lua +++ b/TomTom_Waypoints.lua @@ -13,16 +13,16 @@ local astrolabe = DongleStub("TTAstrolabe-1.0") -- Create a tooltip to be used when mousing over waypoints local tooltip = CreateFrame("GameTooltip", "TomTomTooltip", UIParent, "GameTooltipTemplate") do - -- Set the the tooltip's lines - local i = 1 - tooltip.lines = {} - repeat - local line = getglobal("TomTomTooltipTextLeft"..i) - if line then - tooltip.lines[i] = line - end - i = i + 1 - until not line + -- Set the the tooltip's lines + local i = 1 + tooltip.lines = {} + repeat + local line = getglobal("TomTomTooltipTextLeft"..i) + if line then + tooltip.lines[i] = line + end + i = i + 1 + until not line end -- Store a reference to the minimap parent @@ -41,20 +41,20 @@ local square_half = math.sqrt(0.5) local rad_135 = math.rad(135) local function rotateArrow(self) - if self.disabled then return end + if self.disabled then return end - local angle = astrolabe:GetDirectionToIcon(self) - if not angle then return self:Hide() end - angle = angle + rad_135 + local angle = astrolabe:GetDirectionToIcon(self) + if not angle then return self:Hide() end + angle = angle + rad_135 - if GetCVar("rotateMinimap") == "1" then - --local cring = MiniMapCompassRing:GetFacing() + if GetCVar("rotateMinimap") == "1" then + --local cring = MiniMapCompassRing:GetFacing() local cring = GetPlayerFacing() - angle = angle - cring - end + angle = angle - cring + end - 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) + 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) end function TomTom:ReparentMinimap(minimap) @@ -69,359 +69,359 @@ local waypointMap = {} function TomTom:SetWaypoint(waypoint, callbacks, show_minimap, show_world) local m, f, x, y = unpack(waypoint) - -- Try to acquire a waypoint from the frame pool - local point = table.remove(pool) + -- Try to acquire a waypoint from the frame pool + local point = table.remove(pool) if not point then - point = {} + point = {} - local minimap = CreateFrame("Button", nil, minimapParent) - minimap:SetHeight(20) - minimap:SetWidth(20) - minimap:RegisterForClicks("RightButtonUp") + local minimap = CreateFrame("Button", nil, minimapParent) + minimap:SetHeight(20) + minimap:SetWidth(20) + minimap:RegisterForClicks("RightButtonUp") -- Add to the "All points" table so we can reparent easily table.insert(all_points, minimap) - minimap.icon = minimap:CreateTexture("BACKGROUND") - minimap.icon:SetTexture("Interface\\AddOns\\TomTom\\Images\\GoldGreenDot") - minimap.icon:SetPoint("CENTER", 0, 0) - minimap.icon:SetHeight(12) - minimap.icon:SetWidth(12) - - minimap.arrow = minimap:CreateTexture("BACKGROUND") - minimap.arrow:SetTexture("Interface\\AddOns\\TomTom\\Images\\MinimapArrow-Green") - minimap.arrow:SetPoint("CENTER", 0 ,0) - minimap.arrow:SetHeight(40) - minimap.arrow:SetWidth(40) - minimap.arrow:Hide() - - -- Add the behavior scripts - minimap:SetScript("OnEnter", Minimap_OnEnter) - minimap:SetScript("OnLeave", Minimap_OnLeave) - minimap:SetScript("OnUpdate", Minimap_OnUpdate) - minimap:SetScript("OnClick", Minimap_OnClick) - minimap:RegisterEvent("PLAYER_ENTERING_WORLD") - minimap:SetScript("OnEvent", Minimap_OnEvent) + minimap.icon = minimap:CreateTexture("BACKGROUND") + minimap.icon:SetTexture("Interface\\AddOns\\TomTom\\Images\\GoldGreenDot") + minimap.icon:SetPoint("CENTER", 0, 0) + minimap.icon:SetHeight(12) + minimap.icon:SetWidth(12) + + minimap.arrow = minimap:CreateTexture("BACKGROUND") + minimap.arrow:SetTexture("Interface\\AddOns\\TomTom\\Images\\MinimapArrow-Green") + minimap.arrow:SetPoint("CENTER", 0 ,0) + minimap.arrow:SetHeight(40) + minimap.arrow:SetWidth(40) + minimap.arrow:Hide() + + -- Add the behavior scripts + minimap:SetScript("OnEnter", Minimap_OnEnter) + minimap:SetScript("OnLeave", Minimap_OnLeave) + minimap:SetScript("OnUpdate", Minimap_OnUpdate) + minimap:SetScript("OnClick", Minimap_OnClick) + minimap:RegisterEvent("PLAYER_ENTERING_WORLD") + minimap:SetScript("OnEvent", Minimap_OnEvent) if not TomTomMapOverlay then local overlay = CreateFrame("Frame", "TomTomMapOverlay", WorldMapButton) overlay:SetAllPoints(true) end - local worldmap = CreateFrame("Button", nil, TomTomMapOverlay) - worldmap:SetHeight(12) - worldmap:SetWidth(12) - worldmap:RegisterForClicks("RightButtonUp") - worldmap.icon = worldmap:CreateTexture("ARTWORK") - worldmap.icon:SetAllPoints() - worldmap.icon:SetTexture("Interface\\AddOns\\TomTom\\Images\\GoldGreenDot") + local worldmap = CreateFrame("Button", nil, TomTomMapOverlay) + worldmap:SetHeight(12) + worldmap:SetWidth(12) + worldmap:RegisterForClicks("RightButtonUp") + worldmap.icon = worldmap:CreateTexture("ARTWORK") + worldmap.icon:SetAllPoints() + worldmap.icon:SetTexture("Interface\\AddOns\\TomTom\\Images\\GoldGreenDot") + + worldmap:RegisterEvent("WORLD_MAP_UPDATE") + worldmap:SetScript("OnEnter", World_OnEnter) + worldmap:SetScript("OnLeave", World_OnLeave) + worldmap:SetScript("OnClick", World_OnClick) + worldmap:SetScript("OnEvent", World_OnEvent) + + point.worldmap = worldmap + point.minimap = minimap + end + + waypointMap[waypoint] = point + + point.m = m + point.f = f + point.x = x + point.y = y + 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 + + -- Process the callbacks table to put distances in a consumable format + if callbacks and callbacks.distance then + point.dlist = {} + + for k,v in pairs(callbacks.distance) do + table.insert(point.dlist, k) + end + + table.sort(point.dlist) + end - worldmap:RegisterEvent("WORLD_MAP_UPDATE") - worldmap:SetScript("OnEnter", World_OnEnter) - worldmap:SetScript("OnLeave", World_OnLeave) - worldmap:SetScript("OnClick", World_OnClick) - worldmap:SetScript("OnEvent", World_OnEvent) + -- Link the actual frames back to the waypoint object + point.minimap.point = point + point.worldmap.point = point + point.uid = waypoint - point.worldmap = worldmap - point.minimap = minimap - end + -- Place the waypoint + astrolabe:PlaceIconOnMinimap(point.minimap, m, f, x, y) - waypointMap[waypoint] = point + if show_world then + astrolabe:PlaceIconOnWorldMap(TomTomMapOverlay, point.worldmap, m, f, x, y) + else + point.worldmap.disabled = true + end - point.m = m - point.f = f - point.x = x - point.y = y - 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 - - -- Process the callbacks table to put distances in a consumable format - if callbacks and callbacks.distance then - point.dlist = {} - - for k,v in pairs(callbacks.distance) do - table.insert(point.dlist, k) - end - - table.sort(point.dlist) - end - - -- Link the actual frames back to the waypoint object - point.minimap.point = point - point.worldmap.point = point - point.uid = waypoint - - -- Place the waypoint - astrolabe:PlaceIconOnMinimap(point.minimap, m, f, x, y) - - if show_world then - astrolabe:PlaceIconOnWorldMap(TomTomMapOverlay, point.worldmap, m, f, x, y) - else - point.worldmap.disabled = true - 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.disabled = true - rotateArrow(point.minimap) - else - point.minimap:EnableMouse(true) - point.minimap.disabled = false - rotateArrow(point.minimap) - 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.disabled = true + rotateArrow(point.minimap) + else + point.minimap:EnableMouse(true) + point.minimap.disabled = false + rotateArrow(point.minimap) + end end function TomTom:HideWaypoint(uid, minimap, worldmap) local point = waypointMap[uid] - if point then - if minimap then - point.minimap.disabled = true - point.minimap:Hide() - end - - if worldmap then - point.worldmap.disabled = true - point.worldmap:Hide() - end - end + if point then + if minimap then + point.minimap.disabled = true + point.minimap:Hide() + end + + if worldmap then + point.worldmap.disabled = true + point.worldmap:Hide() + end + end end function TomTom:ShowWaypoint(uid) - local point = waypointMap[uid] - if point then - point.minimap.disabled = not point.data.show_minimap - point.minimap:Show() - - point.worldmap.disabled = not point.data.show_worldmap - point.worldmap:Show() - end + local point = waypointMap[uid] + if point then + point.minimap.disabled = not point.data.show_minimap + point.minimap:Show() + + point.worldmap.disabled = not point.data.show_worldmap + point.worldmap:Show() + end end -- This function removes the waypoint from the active set function TomTom:ClearWaypoint(uid) local point = waypointMap[uid] - if point then - astrolabe:RemoveIconFromMinimap(point.minimap) - point.minimap:Hide() - point.worldmap:Hide() - - -- Clear our handles to the callback tables - point.callbacks = nil - point.minimap.callbacks = nil - point.worldmap.callbacks = nil - - -- Clear disabled flags - point.minimap.disabled = nil - point.worldmap.disabled = nil - - point.dlist = nil - point.uid = nil - table.insert(pool, point) - end + if point then + astrolabe:RemoveIconFromMinimap(point.minimap) + point.minimap:Hide() + point.worldmap:Hide() + + -- Clear our handles to the callback tables + point.callbacks = nil + point.minimap.callbacks = nil + point.worldmap.callbacks = nil + + -- Clear disabled flags + point.minimap.disabled = nil + point.worldmap.disabled = nil + + point.dlist = nil + point.uid = nil + table.insert(pool, point) + end end function TomTom:GetDistanceToWaypoint(uid) local point = waypointMap[uid] - return point and astrolabe:GetDistanceToIcon(point.minimap) + return point and astrolabe:GetDistanceToIcon(point.minimap) end function TomTom:GetDirectionToWaypoint(uid) - local point = waypointMap[uid] - return point and astrolabe:GetDirectionToIcon(point.minimap) + local point = waypointMap[uid] + return point and astrolabe:GetDirectionToIcon(point.minimap) end do - local tooltip_uid,tooltip_callbacks + local tooltip_uid,tooltip_callbacks - local function tooltip_onupdate(self, elapsed) - if tooltip_callbacks and tooltip_callbacks.tooltip_update then - local dist,x,y = TomTom:GetDistanceToWaypoint(tooltip_uid) - tooltip_callbacks.tooltip_update("tooltip_update", tooltip, tooltip_uid, dist) - end - end + local function tooltip_onupdate(self, elapsed) + if tooltip_callbacks and tooltip_callbacks.tooltip_update then + local dist,x,y = TomTom:GetDistanceToWaypoint(tooltip_uid) + tooltip_callbacks.tooltip_update("tooltip_update", tooltip, tooltip_uid, dist) + end + end - function Minimap_OnClick(self, button) - local data = self.callbacks + function Minimap_OnClick(self, button) + local data = self.callbacks - if data and data.onclick then - data.onclick("onclick", self.point.uid, self, button) - end - end + if data and data.onclick then + data.onclick("onclick", self.point.uid, self, button) + end + end - function Minimap_OnEnter(self, motion) - local data = self.callbacks + function Minimap_OnEnter(self, motion) + local data = self.callbacks - if data and data.tooltip_show then - local uid = self.point.uid - local dist,x,y = TomTom:GetDistanceToWaypoint(uid) + if data and data.tooltip_show then + local uid = self.point.uid + local dist,x,y = TomTom:GetDistanceToWaypoint(uid) - tooltip_uid = uid - tooltip_callbacks = data + tooltip_uid = uid + tooltip_callbacks = data - -- Parent to UIParent, unless it's hidden - if UIParent:IsVisible() then - tooltip:SetParent(UIParent) - else - tooltip:SetParent(self) - end + -- Parent to UIParent, unless it's hidden + if UIParent:IsVisible() then + tooltip:SetParent(UIParent) + else + tooltip:SetParent(self) + end - tooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT") + tooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT") - data.tooltip_show("tooltip_show", tooltip, uid, dist) - tooltip:Show() + data.tooltip_show("tooltip_show", tooltip, uid, dist) + tooltip:Show() - -- Set the update script if there is one - if data.tooltip_update then - tooltip:SetScript("OnUpdate", tooltip_onupdate) - else - tooltip:SetScript("OnUpdate", nil) - end - end - end + -- Set the update script if there is one + if data.tooltip_update then + tooltip:SetScript("OnUpdate", tooltip_onupdate) + else + tooltip:SetScript("OnUpdate", nil) + end + end + end - function Minimap_OnLeave(self, motion) - tooltip_uid,tooltip_callbacks = nil,nil - tooltip:Hide() - end + function Minimap_OnLeave(self, motion) + tooltip_uid,tooltip_callbacks = nil,nil + tooltip:Hide() + end - World_OnEnter = Minimap_OnEnter - World_OnLeave = Minimap_OnLeave - World_OnClick = Minimap_OnClick + World_OnEnter = Minimap_OnEnter + World_OnLeave = Minimap_OnLeave + World_OnClick = Minimap_OnClick - local minimap_count = 0 + local minimap_count = 0 - function Minimap_OnUpdate(self, elapsed) - local dist,x,y = astrolabe:GetDistanceToIcon(self) - local disabled = self.disabled + function Minimap_OnUpdate(self, elapsed) + local dist,x,y = astrolabe:GetDistanceToIcon(self) + local disabled = self.disabled - if not dist then - self:Hide() - return - end + if not dist then + self:Hide() + return + end - minimap_count = minimap_count + elapsed + minimap_count = minimap_count + elapsed - if minimap_count < 0.1 then return end + if minimap_count < 0.1 then return end - -- Reset the counter - minimap_count = 0 + -- Reset the counter + minimap_count = 0 - local edge = astrolabe:IsIconOnEdge(self) - local data = self.point - local callbacks = data.callbacks + local edge = astrolabe:IsIconOnEdge(self) + local data = self.point + local callbacks = data.callbacks - if edge then - -- Check to see if this is a transition - if not disabled then - self.icon:Hide() - self.arrow:Show() + if edge then + -- Check to see if this is a transition + if not disabled then + self.icon:Hide() + self.arrow:Show() - -- Rotate the icon, as required - local angle = astrolabe:GetDirectionToIcon(self) - angle = angle + rad_135 + -- Rotate the icon, as required + local angle = astrolabe:GetDirectionToIcon(self) + angle = angle + rad_135 - if GetCVar("rotateMinimap") == "1" then - --local cring = MiniMapCompassRing:GetFacing() + if GetCVar("rotateMinimap") == "1" then + --local cring = MiniMapCompassRing:GetFacing() local cring = GetPlayerFacing() - angle = angle - cring - end - - 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) - end - else - if not disabled then - self.icon:Show() - self.arrow:Hide() - end - end - - if callbacks and callbacks.distance then - local list = data.dlist - - local state = data.state - local newstate - - -- Calculate the initial state - if not state then - for i=1,#list do - if dist <= list[i] then - state = i - break - end - end - - -- Handle the case where we're outside the largest circle - if not state then state = -1 end - - data.state = state - else - -- Calculate the new state - for i=1,#list do - if dist <= list[i] then - newstate = i - break - end - end - - -- Handle the case where we're outside the largest circle - if not newstate then newstate = -1 end - end - - -- If newstate is set, then this is a transition - -- If only state is set, this is the initial state - - if state ~= newstate then - -- Handle the initial state - newstate = newstate or state - local distance = list[newstate] - local callback = callbacks.distance[distance] - if callback then - callback("distance", data.uid, distance, dist, data.lastdist) - end - data.state = newstate - end - - -- Update the last distance with the current distance - data.lastdist = dist - end - end - - function World_OnEvent(self, event, ...) - if event == "WORLD_MAP_UPDATE" then - if not self.point.uid then - return - end - - local data = self.point - if data.worldmap and data.show_world and not self.disabled then - local x,y = astrolabe:PlaceIconOnWorldMap(TomTomMapOverlay, self, data.m, data.f, data.x, data.y) + angle = angle - cring + end + + 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) + end + else + if not disabled then + self.icon:Show() + self.arrow:Hide() + end + end + + if callbacks and callbacks.distance then + local list = data.dlist + + local state = data.state + local newstate + + -- Calculate the initial state + if not state then + for i=1,#list do + if dist <= list[i] then + state = i + break + end + end + + -- Handle the case where we're outside the largest circle + if not state then state = -1 end + + data.state = state + else + -- Calculate the new state + for i=1,#list do + if dist <= list[i] then + newstate = i + break + end + end + + -- Handle the case where we're outside the largest circle + if not newstate then newstate = -1 end + end + + -- If newstate is set, then this is a transition + -- If only state is set, this is the initial state + + if state ~= newstate then + -- Handle the initial state + newstate = newstate or state + local distance = list[newstate] + local callback = callbacks.distance[distance] + if callback then + callback("distance", data.uid, distance, dist, data.lastdist) + end + data.state = newstate + end + + -- Update the last distance with the current distance + data.lastdist = dist + end + end + + function World_OnEvent(self, event, ...) + if event == "WORLD_MAP_UPDATE" then + if not self.point.uid then + return + end + + local data = self.point + if data.worldmap and data.show_world and not self.disabled then + local x,y = astrolabe:PlaceIconOnWorldMap(TomTomMapOverlay, self, data.m, data.f, data.x, data.y) local pdata = data.uid - 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 - - function Minimap_OnEvent(self, event, ...) - if event == "PLAYER_ENTERING_WORLD" then - local data = self.point - if data and data.uid and waypointMap[data.uid] then - astrolabe:PlaceIconOnMinimap(self, data.m, data.f, data.x, data.y) - end - end - end + 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 + + function Minimap_OnEvent(self, event, ...) + if event == "PLAYER_ENTERING_WORLD" then + local data = self.point + if data and data.uid and waypointMap[data.uid] then + astrolabe:PlaceIconOnMinimap(self, data.m, data.f, data.x, data.y) + end + end + end end