From 1841fcaae410fc69f8dbc8b37f2c3262e000b135 Mon Sep 17 00:00:00 2001 From: James Whitehead Ii Date: Fri, 14 Mar 2008 15:17:10 +0000 Subject: [PATCH] * Merging all changes from 2.4 branch * Configuration dialog should work on 2.3 and 2.4 --- Babelfish.lua | 2 +- Localization.enUS.lua | 3 +- TomTom.lua | 151 +++++++++++++++++++---- TomTom.toc | 3 +- TomTom_Config.lua | 318 ++++++++++++++++++++++++++++++------------------- TomTom_CrazyArrow.lua | 73 +++++++----- TomTom_Waypoints.lua | 52 ++++---- TomTom_Zones.lua | 142 ---------------------- 8 files changed, 396 insertions(+), 348 deletions(-) delete mode 100644 TomTom_Zones.lua diff --git a/Babelfish.lua b/Babelfish.lua index 7fe9104..f5971af 100644 --- a/Babelfish.lua +++ b/Babelfish.lua @@ -24,4 +24,4 @@ for idx,match in ipairs(work) do print(string.format("\t[\"%s\"] = \"%s\",", match, val)) end print("}\n") -print("setmetatable(TomTomLocals, {__index=function(t,k) rawset(t, k, k) end})") +print("setmetatable(TomTomLocals, {__index=function(t,k) rawset(t, k, k); return k; end})") diff --git a/Localization.enUS.lua b/Localization.enUS.lua index f6a5726..01618c1 100644 --- a/Localization.enUS.lua +++ b/Localization.enUS.lua @@ -43,6 +43,7 @@ TomTomLocals = { ["Shows an estimate of how long it will take you to reach the waypoint at your current speed"] = "Shows an estimate of how long it will take you to reach the waypoint at your current speed", ["The floating waypoint arrow can change color depending on whether or nor you are facing your destination. By default it will display green when you are facing it directly, and red when you are facing away from it. These colors can be changed in this section. Setting these options to the same color will cause the arrow to not change color at all"] = "The floating waypoint arrow can change color depending on whether or nor you are facing your destination. By default it will display green when you are facing it directly, and red when you are facing away from it. These colors can be changed in this section. Setting these options to the same color will cause the arrow to not change color at all", ["This setting will control the distance at which the waypoint arrow switches to a downwards arrow, indicating you have arrived at your destination"] = "This setting will control the distance at which the waypoint arrow switches to a downwards arrow, indicating you have arrived at your destination", + ["TomTom"] = "TomTom", ["TomTom can display a tooltip containing information abouto waypoints, when they are moused over. This setting toggles that functionality"] = "TomTom can display a tooltip containing information abouto waypoints, when they are moused over. This setting toggles that functionality", ["TomTom can display multiple waypoint arrows on the minimap. These options control the display of these waypoints"] = "TomTom can display multiple waypoint arrows on the minimap. These options control the display of these waypoints", ["TomTom can display multiple waypoints on the world map. These options control the display of these waypoints"] = "TomTom can display multiple waypoints on the world map. These options control the display of these waypoints", @@ -57,4 +58,4 @@ TomTomLocals = { ["\"Arrival Distance\""] = "\"Arrival Distance\"", } -setmetatable(TomTomLocals, {__index=function(t,k) rawset(t, k, k) end}) +setmetatable(TomTomLocals, {__index=function(t,k) rawset(t, k, k); return k; end}) diff --git a/TomTom.lua b/TomTom.lua index 9aeeecb..40a7ad4 100755 --- a/TomTom.lua +++ b/TomTom.lua @@ -4,7 +4,6 @@ -- Simple localization table for messages local L = TomTomLocals - local Astrolabe = DongleStub("Astrolabe-0.4") -- Create the addon object @@ -16,6 +15,9 @@ local WorldMap_OnUpdate local Block_OnClick,Block_OnUpdate,BlockOnEnter,BlockOnLeave local Block_OnDragStart,Block_OnDragStop local callbackTbl +local RoundCoords + +local waypoints = {} function TomTom:Initialize() self.defaults = { @@ -70,6 +72,7 @@ function TomTom:Initialize() self.db = self:InitializeDB("TomTomDB", self.defaults) self.tooltip = CreateFrame("GameTooltip", "TomTomTooltip", nil, "GameTooltipTemplate") + self.dropdown = CreateFrame("Frame", "TomTomDropdown", nil, "UIDropDownMenuTemplate") self:RegisterEvent("PLAYER_LEAVING_WORLD") self:RegisterEvent("PLAYER_ENTERING_WORLD") @@ -98,10 +101,10 @@ function TomTom:ShowHideWorldCoords() TomTomWorldFrame = CreateFrame("Frame", nil, WorldMapFrame) TomTomWorldFrame.Player = TomTomWorldFrame:CreateFontString("OVERLAY", nil, "GameFontHighlightSmall") TomTomWorldFrame.Player:SetPoint("BOTTOM", WorldMapPositioningGuide, "BOTTOM", -100, 11) - + TomTomWorldFrame.Cursor = TomTomWorldFrame:CreateFontString("OVERLAY", nil, "GameFontHighlightSmall") TomTomWorldFrame.Cursor:SetPoint("BOTTOM", WorldMapPositioningGuide, "BOTTOM", 100, 11) - + TomTomWorldFrame:SetScript("OnUpdate", WorldMap_OnUpdate) end @@ -146,11 +149,11 @@ function TomTom:ShowHideBlockCoords() 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}, - }) + 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) @@ -188,18 +191,18 @@ end local Orig_WorldMapButton_OnClick = WorldMapButton_OnClick function WorldMapButton_OnClick(...) local mouseButton, button = ... - if IsControlKeyDown() and mouseButton == "RightButton" then + if IsControlKeyDown() and mouseButton == "RightButton" then local c,z = GetCurrentMapContinent(), GetCurrentMapZone() local x,y = GetCurrentCursorPosition() - + if z == 0 then return end - local uid = TomTom:AddWaypoint(c,z,x*100,y*100) - else - return Orig_WorldMapButton_OnClick(...) - end + local uid = TomTom:AddZWaypoint(c,z,x*100,y*100) + else + return Orig_WorldMapButton_OnClick(...) + end end WorldMapMagnifyingGlassButton:SetText(ZOOM_OUT_BUTTON_TEXT .. "\nCtrl+Right Click To Add a Waypoint") @@ -219,10 +222,61 @@ local function WaypointCallback(event, arg1, arg2, arg3) end end +--[[------------------------------------------------------------------- +-- Dropdown menu code +-------------------------------------------------------------------]]-- + +local dropdown_info = { + -- Define level one elements here + [1] = { + { -- Title + text = L["Waypoint Options"], + isTitle = 1, + }, + { -- Remove waypoint + text = L["Remove waypoint"], + func = function() + local uid = TomTom.dropdown.uid + local data = waypoints[uid] + TomTom:RemoveWaypoint(uid) + TomTom:PrintF("Removing waypoint %0.2f, %0.2f in %s", data.x, data.y, data.zone) + end, + }, + } +} + +local function init_dropdown(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 + UIDropDownMenu_AddButton(entry, level) + end +end + callbackTbl = { + onclick = function(event, uid, self, button) + TomTom.dropdown.uid = uid + UIDropDownMenu_Initialize(TomTom.dropdown, init_dropdown) + ToggleDropDownMenu(1, nil, TomTom.dropdown, "cursor", 0, 0) + end, tooltip_show = function(event, tooltip, uid, dist) - tooltip:SetText("TomTom waypoint") + local data = waypoints[uid] + + tooltip:SetText(data.title or "TomTom waypoint") tooltip:AddLine(string.format("%s yards away", math.floor(dist)), 1, 1, 1) + tooltip:AddLine(string.format("%s (%.2f, %.2f)", data.zone, data.x, data.y), 0.7, 0.7, 0.7) tooltip:Show() end, tooltip_update = function(event, tooltip, uid, dist) @@ -246,13 +300,68 @@ function TomTom:AddWaypoint(x,y,desc) return end - local point = self:SetWaypoint(c, z, x, y, callbackTbl) - self:SetCrazyArrow(point, self.db.profile.arrow.arrival) + return self:AddZWaypoint(c,z,x,y,desc) end function TomTom:AddZWaypoint(c,z,x,y,desc) - local point = self:SetWaypoint(c,z,x,y, callbackTbl) - self:SetCrazyArrow(point, self.db.profile.arrow.arrival) + local uid = self:SetWaypoint(c,z,x/100,y/100, callbackTbl) + self:SetCrazyArrow(uid, self.db.profile.arrow.arrival, desc) + + -- Store this waypoint in the uid + waypoints[uid] = { + title = desc, + coord = self:GetCoord(x / 100 , y / 100), + zone = self:GetMapFile(c,z), + x = x, + y = y, + } +end + +-- Code taken from HandyNotes, thanks Xinhuan + +--------------------------------------------------------- +-- Public functions for plugins to convert between MapFile <-> C,Z +-- +local continentMapFile = { + [WORLDMAP_COSMIC_ID] = "Cosmic", -- That constant is -1 + [0] = "World", + [1] = "Kalimdor", + [2] = "Azeroth", + [3] = "Expansion01", +} +local reverseMapFileC = {} +local reverseMapFileZ = {} +for C = 1, #Astrolabe.ContinentList do + for Z = 1, #Astrolabe.ContinentList[C] do + local mapFile = Astrolabe.ContinentList[C][Z] + reverseMapFileC[mapFile] = C + reverseMapFileZ[mapFile] = Z + end +end +for C = -1, 3 do + local mapFile = continentMapFile[C] + reverseMapFileC[mapFile] = C + reverseMapFileZ[mapFile] = 0 +end + +function TomTom:GetMapFile(C, Z) + if not C or not Z then return end + if Z == 0 then + return continentMapFile[C] + elseif C > 0 then + return Astrolabe.ContinentList[C][Z] + end +end +function TomTom:GetCZ(mapFile) + return reverseMapFileC[mapFile], reverseMapFileZ[mapFile] +end + +-- Public functions for plugins to convert between coords <--> x,y +function TomTom:GetCoord(x, y) + return floor(x * 10000 + 0.5) * 10000 + floor(y * 10000 + 0.5) +end +function TomTom:GetXY(id) + return floor(id / 10000) / 10000, (id % 10000) / 10000 end TomTom = DongleStub("Dongle-1.1"):New("TomTom", TomTom) @@ -322,7 +431,9 @@ end SLASH_WAY1 = "/way" SlashCmdList["WAY"] = function(msg) - local x,y,desc = msg:match("(%d+%.?%d*)%s+(%d+%.?%d*)%s*(.*)") + local x,y,desc = msg:match("(%d+%.?%d*)%s+(%d+%.?%d*)%s*(.*)$") + if not desc:match("%S") then desc = nil end + x,y = tonumber(x), tonumber(y) TomTom:PrintF("Adding waypoint %d %d", x, y) TomTom:AddWaypoint(x, y, desc) diff --git a/TomTom.toc b/TomTom.toc index 1ecbdcd..1d5a8a6 100755 --- a/TomTom.toc +++ b/TomTom.toc @@ -1,4 +1,4 @@ -## Interface: 20300 +## Interface: 20400 ## Title: TomTom ## Notes: Acts as your portable navigation assistant ## SavedVariables: TomTomDB @@ -16,7 +16,6 @@ Localization.enUS.lua TomTom.lua TomTom_Waypoints.lua -TomTom_Zones.lua TomTom_CrazyArrow.lua TomTom_Config.lua diff --git a/TomTom_Config.lua b/TomTom_Config.lua index c244f57..2b24449 100644 --- a/TomTom_Config.lua +++ b/TomTom_Config.lua @@ -6,9 +6,10 @@ local L = TomTomLocals options.type = "group" options.name = "TomTom" -function options.get(info) +local function get(info) local ns,opt = string.split(".", info.arg) local val = TomTom.db.profile[ns][opt] + --TomTom:Print("get", ns, opt, val) if type(val) == "table" then return unpack(val) else @@ -16,9 +17,9 @@ function options.get(info) end end -function options.set(info, arg1, arg2, arg3, arg4) +local function set(info, arg1, arg2, arg3, arg4) local ns,opt = string.split(".", info.arg) - --TomTom:Print(ns, opt, arg1, arg2, arg3, arg4) + --TomTom:Print("set", ns, opt, arg1, arg2, arg3, arg4) if arg2 then local entry = TomTom.db.profile[ns][opt] entry[1] = arg1 @@ -42,6 +43,8 @@ options.args.coordblock = { type = "group", name = L["Coordinate Block"], desc = L["Options that alter the coordinate block"], + get = get, + set = set, args = { desc = { order = 1, @@ -53,27 +56,36 @@ options.args.coordblock = { type = "toggle", name = L["Enable coordinate block"], desc = L["Enables a floating block that displays your current position in the current zone"], + width = "double", arg = "block.enable", }, - accuracy = { - order = 3, - type = "range", - name = "Accuracy", - desc = L["Coordinates can be displayed as simple XX, YY coordinate, or as more precise XX.XX, YY.YY. This setting allows you to control that precision"], - min = 0, max = 2, step = 1, - arg = "block.accuracy", - }, lock = { - order = 4, + order = 3, type = "toggle", name = L["Lock coordinate block"], + desc = L["Locks the coordinate block so it can't be accidentally dragged to another location"], + width = "double", arg = "block.lock", }, - display = { + accuracy = { + order = 4, + type = "range", + name = "Coordinate Accuracy", + desc = L["Coordinates can be displayed as simple XX, YY coordinate, or as more precise XX.XX, YY.YY. This setting allows you to control that precision"], + min = 0, max = 2, step = 1, + arg = "block.accuracy", + }, + display = { order = 4, type = "group", + inline = true, name = L["Display Settings"], args = { + help = { + type = "description", + name = L["The display of the coordinate block can be customized by changing the options below."], + order = 1, + }, bordercolor = { type = "color", name = L["Border color"], @@ -107,63 +119,11 @@ options.args.coordblock = { }, } -- End coordinate block settings -options.args.mapcoord = { - type = "group", - name = L["Map Coordinates"], - desc = L["Options that customize the map coordinate display"], - args = { - help = { - order = 1, - type = "description", - name = L["TomTom is capable of displaying the player's coordinates on the world map, as well as the current coordinate position of the cursor. These options can be used to enable or disable these displays"], - }, - player = { - type = "group", - name = L["Player Coordinates"], - args = { - enableplayer = { - order = 1, - type = "toggle", - name = L["Enable player coordinates"], - arg = "mapcoords.playerenable", - }, - playeraccuracy = { - order = 4, - type = "range", - name = L["Player coordinate accuracy"], - desc = L["Coordinates can be displayed as simple XX, YY coordinate, or as more precise XX.XX, YY.YY. This setting allows you to control that precision"], - min = 0, max = 2, step = 1, - arg = "mapcoords.playeraccuracy", - }, - }, - }, - cursor = { - type = "group", - name = L["Cursor Coordinates"], - args = { - enablecursor = { - order = 3, - type = "toggle", - name = L["Enable cursor coordinates"], - arg = "mapcoords.cursorenable", - }, - - cursoraccuracy = { - order = 5, - type = "range", - name = L["Cursor coordinate accuracy"], - desc = L["Coordinates can be displayed as simple XX, YY coordinate, or as more precise XX.XX, YY.YY. This setting allows you to control that precision"], - min = 0, max = 2, step = 1, - arg = "mapcoords.cursoraccuracy", - }, - }, - }, - }, -} -- end map coord options - options.args.crazytaxi = { type = "group", name = L["Waypoint Arrow"], + get = get, + set = set, args = { help = { order = 1, @@ -177,31 +137,33 @@ options.args.crazytaxi = { width = "double", arg = "arrow.enable", }, - heredistance = { - order = 3, - type = "range", - name = L["\"Arrival Distance\""], - desc = L["This setting will control the distance at which the waypoint arrow switches to a downwards arrow, indicating you have arrived at your destination"], - min = 0, max = 150, step = 5, - arg = "arrow.arrival", - }, lock = { - order = 4, + order = 3, type = "toggle", - name = L["Lock arrow"], + name = L["Lock waypoint arrow"], desc = L["Locks the waypoint arrow, so it can't be moved accidentally"], arg = "arrow.lock", }, arrival = { - order = 5, + order = 4, type = "toggle", - name = L["Show time to arrival"], + name = L["Show estimated time to arrival"], desc = L["Shows an estimate of how long it will take you to reach the waypoint at your current speed"], + width = "double", arg = "arrow.showtta", }, + heredistance = { + order = 5, + type = "range", + name = L["\"Arrival Distance\""], + desc = L["This setting will control the distance at which the waypoint arrow switches to a downwards arrow, indicating you have arrived at your destination"], + min = 0, max = 150, step = 5, + arg = "arrow.arrival", + }, color = { type = "group", name = L["Arrow colors"], + inline = true, args = { help = { order = 1, @@ -209,20 +171,26 @@ options.args.crazytaxi = { name = L["The floating waypoint arrow can change color depending on whether or nor you are facing your destination. By default it will display green when you are facing it directly, and red when you are facing away from it. These colors can be changed in this section. Setting these options to the same color will cause the arrow to not change color at all"], }, colorstart = { + order = 2, type = "color", name = L["Good color"], + desc = L["The color to be displayed when you are moving in the direction of the active waypoint"], arg = "arrow.goodcolor", hasAlpha = false, }, colormiddle = { + order = 3, type = "color", name = L["Middle color"], + desc = L["The color to be displayed when you are halfway between the direction of the active waypoint and the completely wrong direction"], arg = "arrow.middlecolor", hasAlpha = false, }, colorend = { + order = 4, type = "color", name = L["Bad color"], + desc = L["The color to be displayed when you are moving in the opposite direction of the active waypoint"], arg = "arrow.badcolor", hasAlpha = false, }, @@ -234,6 +202,8 @@ options.args.crazytaxi = { options.args.minimap = { type = "group", name = L["Minimap"], + get = get, + set = set, args = { help = { order = 1, @@ -258,6 +228,7 @@ options.args.minimap = { type = "toggle", name = L["Enable mouseover tooltips"], desc = L["TomTom can display a tooltip containing information abouto waypoints, when they are moused over. This setting toggles that functionality"], + width = "double", arg = "minimap.tooltip", }, @@ -265,72 +236,126 @@ options.args.minimap = { } -- End minimap options options.args.worldmap = { - type = "group", - name = L["World Map"], - args = { - help = { - order = 1, - type = "description", - name = L["TomTom can display multiple waypoints on the world map. These options control the display of these waypoints"], - }, - enable = { - order = 2, - type = "toggle", - name = L["Enable world map waypoints"], - width = "double", - arg = "worldmap.enable", - }, - otherzone = { - type = "toggle", - name = L["Display waypoints from other zones"], - desc = L["TomTom can hide waypoints in other zones, this setting toggles that functionality"], - width = "double", - arg = "worldmap.otherzone", - }, - tooltip = { - type = "toggle", - name = L["Enable mouseover tooltips"], - desc = L["TomTom can display a tooltip containing information abouto waypoints, when they are moused over. This setting toggles that functionality"], - arg = "worldmap.tooltip", - }, - createclick = { - type = "toggle", - name = L["Allow control-right clicking on map to create new waypoint"], - width = "double", - arg = "worldmap.clickcreate", - }, - }, + type = "group", + name = L["World Map"], + get = get, + set = set, + args = { + help = { + order = 1, + type = "description", + name = L["TomTom can display multiple waypoints on the world map. These options control the display of these waypoints"], + }, + enable = { + order = 2, + type = "toggle", + name = L["Enable world map waypoints"], + width = "double", + arg = "worldmap.enable", + }, + otherzone = { + order = 3, + type = "toggle", + name = L["Display waypoints from other zones"], + desc = L["TomTom can hide waypoints in other zones, this setting toggles that functionality"], + width = "double", + arg = "worldmap.otherzone", + }, + tooltip = { + order = 4, + type = "toggle", + name = L["Enable mouseover tooltips"], + desc = L["TomTom can display a tooltip containing information abouto waypoints, when they are moused over. This setting toggles that functionality"], + width = "double", + arg = "worldmap.tooltip", + }, + createclick = { + order = 5, + type = "toggle", + name = L["Allow control-right clicking on map to create new waypoint"], + width = "double", + arg = "worldmap.clickcreate", + }, + player = { + order = 6, + type = "group", + inline = true, + name = L["Player Coordinates"], + args = { + enableplayer = { + order = 1, + type = "toggle", + name = L["Enable showing player coordinates"], + width = "double", + arg = "mapcoords.playerenable", + }, + playeraccuracy = { + order = 4, + type = "range", + name = L["Player coordinate accuracy"], + desc = L["Coordinates can be displayed as simple XX, YY coordinate, or as more precise XX.XX, YY.YY. This setting allows you to control that precision"], + min = 0, max = 2, step = 1, + arg = "mapcoords.playeraccuracy", + }, + }, + }, + cursor = { + order = 7, + type = "group", + inline = true, + name = L["Cursor Coordinates"], + args = { + enablecursor = { + order = 3, + type = "toggle", + name = L["Enable showing cursor coordinates"], + width = "double", + arg = "mapcoords.cursorenable", + }, + + cursoraccuracy = { + order = 5, + type = "range", + name = L["Cursor coordinate accuracy"], + desc = L["Coordinates can be displayed as simple XX, YY coordinate, or as more precise XX.XX, YY.YY. This setting allows you to control that precision"], + min = 0, max = 2, step = 1, + arg = "mapcoords.cursoraccuracy", + }, + }, + }, + }, } -- End world map options options.args.general = { type = "group", name = L["General Options"], + get = get, + set = set, args = { - help = { - order = 1, - type = "description", - name = L["TomTom is able to accept and send waypoints to guild and party members who are also running TomTom. In addition, waypoints may be stored between sessions."], - }, comm = { type = "toggle", + order = 1, name = L["Accept waypoints from guild and party members"], width = "double", arg = "comm.enable", }, promptcomm = { type = "toggle", + order = 2, name = L["Prompt before accepting sent waypoints"], width = "double", arg = "comm.prompt", }, persistence = { type = "toggle", + order = 3, name = L["Save waypoints in between sessions"], width = "double", arg = "persistence.savewaypoints", }, cleardistance = { type = "range", + order = 4, name = L["Clear waypoint distance"], desc = L["Waypoints can be automatically cleared when you reach them. This slider allows you to customize the distance in yards that signals your \"arrival\" at the waypoint. A setting of 0 turns off the auto-clearing feature\n\nChanging this setting only takes effect after reloading your interface."], min = 0, max = 150, step = 1, @@ -339,11 +364,58 @@ options.args.general = { }, } -LibStub("AceConfig-3.0"):RegisterOptionsTable("TomTom", options) -LibStub("AceConfigDialog-3.0"):SetDefaultSize("TomTom", 600, 400) +local config = LibStub("AceConfig-3.0") +local dialog = LibStub("AceConfigDialog-3.0") +local registered = false; + +function GetBuildInfo() return "0.3.0" end SLASH_TOMTOM1 = "/tomtom" SlashCmdList["TOMTOM"] = function(msg) - LibStub("AceConfigDialog-3.0"):Open("TomTom") -end + local build = GetBuildInfo() + + if not registered then + if build == "0.4.0" then + config:RegisterOptionsTable("TomTom", { + name = L["TomTom"], + type = "group", + args = { + help = { + type = "description", + name = "TomTom is a simple navigation assistant", + }, + }, + }) + dialog:SetDefaultSize("TomTom", 600, 400) + dialog:AddToBlizOptions("TomTom", "TomTom") + + -- Add the options in reverse order of how we want them to be shown + -- World Map Options + config:RegisterOptionsTable("TomTom-Worldmap", options.args.worldmap) + dialog:AddToBlizOptions("TomTom-Worldmap", options.args.worldmap.name, "TomTom") + -- Minimap Options + config:RegisterOptionsTable("TomTom-Minimap", options.args.minimap) + dialog:AddToBlizOptions("TomTom-Minimap", options.args.minimap.name, "TomTom") + -- Crazy Taxi Options + config:RegisterOptionsTable("TomTom-CrazyTaxi", options.args.crazytaxi) + dialog:AddToBlizOptions("TomTom-CrazyTaxi", options.args.crazytaxi.name, "TomTom") + -- Coordinate Block Options + config:RegisterOptionsTable("TomTom-CoordBlock", options.args.coordblock) + dialog:AddToBlizOptions("TomTom-CoordBlock", options.args.coordblock.name, "TomTom") + -- General Options + config:RegisterOptionsTable("TomTom-General", options.args.general) + dialog:AddToBlizOptions("TomTom-General", options.args.general.name, "TomTom") + else + config:RegisterOptionsTable("TomTom", options) + dialog:SetDefaultSize("TomTom", 600, 400) + end + registered = true + end + + if build == "0.4.0" then + InterfaceOptionsFrame_OpenToFrame(options.args.general.name, "TomTom") + else + dialog:Open("TomTom") + end +end diff --git a/TomTom_CrazyArrow.lua b/TomTom_CrazyArrow.lua index b79f666..a26e7ce 100644 --- a/TomTom_CrazyArrow.lua +++ b/TomTom_CrazyArrow.lua @@ -107,15 +107,16 @@ local status = wayframe.status local tta = wayframe.tta local arrow = wayframe.arrow local count = 0 -local time = 0 -local distance = 0 -local delta = 0 +local last_distance = 0 +local tta_throttle = 0 +local speed = 0 +local speed_count = 0 local function OnUpdate(self, elapsed) if not active_point then self:Hide() return end - + local dist,x,y = TomTom:GetDistanceToWaypoint(active_point) if not dist then self:Hide() @@ -123,7 +124,7 @@ local function OnUpdate(self, elapsed) end status:SetText(sformat("%d yards", dist)) - + local cell -- Showing the arrival arrow? @@ -144,7 +145,7 @@ local function OnUpdate(self, elapsed) cell = count local column = cell % 9 local row = floor(cell / 9) - + local xstart = (column * 53) / 512 local ystart = (row * 70) / 512 local xend = ((column + 1) * 53) / 512 @@ -160,9 +161,9 @@ local function OnUpdate(self, elapsed) local angle = TomTom:GetDirectionToWaypoint(active_point) local player = GetPlayerBearing() - + angle = angle - player - + local perc = math.abs((math.pi - math.abs(angle)) / math.pi) local gr,gg,gb = unpack(TomTom.db.profile.arrow.goodcolor) @@ -170,40 +171,48 @@ local function OnUpdate(self, elapsed) 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) arrow:SetVertexColor(r,g,b) - + cell = floor(angle / twopi * 108 + 0.5) % 108 local column = cell % 9 local row = floor(cell / 9) - + local xstart = (column * 56) / 512 local ystart = (row * 42) / 512 local xend = ((column + 1) * 56) / 512 local yend = ((row + 1) * 42) / 512 arrow:SetTexCoord(xstart,xend,ystart,yend) + end + + -- Calculate the TTA every second (%01d:%02d) + + tta_throttle = tta_throttle + elapsed + + if tta_throttle >= 1.0 then + -- Calculate the speed in yards per sec at which we're moving + local current_speed = (last_distance - dist) / tta_throttle + + if last_distance == 0 then + current_speed = 0 end - - -- Give time til arrival only if facing towards destination - time = time + elapsed - - if time >= 1 then - if cell <= 27 or cell >= 81 or showDownArrow then - - delta = distance - dist - - if delta > 0 then - local eta = dist/(delta/time) - tta:SetText(sformat("%01d:%02d", eta / 60, eta % 60)) - else - tta:SetText("***") - end - time = 0 - distance = dist - else - tta:SetText("***") - distance = dist - time = 0 - end + + if speed_count < 2 then + speed = (speed + current_speed) / 2 + speed_count = speed_count + 1 + else + speed_count = 0 + speed = current_speed + end + + if speed > 0 then + local eta = math.abs(dist / speed) + tta:SetFormattedText("%01d:%02d", eta / 60, eta % 60) + else + tta:SetText("***") end + + last_distance = dist + tta_throttle = 0 + end end wayframe:SetScript("OnUpdate", OnUpdate) diff --git a/TomTom_Waypoints.lua b/TomTom_Waypoints.lua index 9baa148..02add53 100644 --- a/TomTom_Waypoints.lua +++ b/TomTom_Waypoints.lua @@ -127,7 +127,7 @@ function TomTom:SetWaypoint(c, z, x, y, callbacks) end table.sort(list) - callbacks.distance.__list = list + callbacks.__distances = list end -- Link the actual frames back to the waypoint object @@ -135,7 +135,6 @@ function TomTom:SetWaypoint(c, z, x, y, callbacks) point.worldmap.point = point -- Place the waypoint - local x,y = x/100,y/100 Astrolabe:PlaceIconOnMinimap(point.minimap, c, z, x, y) Astrolabe:PlaceIconOnWorldMap(WorldMapDetailFrame, point.worldmap, c, z, x, y) @@ -149,6 +148,7 @@ function TomTom:RemoveWaypoint(uid) point.minimap:Hide() point.worldmap:Hide() table.insert(pool, point) + point.uid = nil end function TomTom:GetDistanceToWaypoint(uid) @@ -171,6 +171,14 @@ do end end + function Minimap_OnClick(self, button) + local data = self.point.callbacks + + if data.onclick then + data.onclick("onclick", self.point.uid, self, button) + end + end + function Minimap_OnEnter(self, motion) local data = self.point.callbacks @@ -181,7 +189,7 @@ do tooltip_uid = uid tooltip_callbacks = data - tooltip:SetOwner(self, "ANCHOR_CURSOR") + tooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT") data.tooltip_show("tooltip_show", tooltip, uid, dist) tooltip:Show() @@ -196,10 +204,14 @@ do end function Minimap_OnLeave(self, motion) - tooltip_icon,tooltip_callback = nil,nil + tooltip_uid,tooltip_callbacks = nil,nil tooltip:Hide() end + World_OnEnter = Minimap_OnEnter + World_OnLeave = Minimap_OnLeave + World_OnClick = Minimap_OnClick + local square_half = math.sqrt(0.5) local rad_135 = math.rad(135) local minimap_count = 0 @@ -211,7 +223,7 @@ do end minimap_count = minimap_count + elapsed - + -- Only take action every 0.2 seconds if minimap_count < 0.1 then return end @@ -249,7 +261,7 @@ do end if callbacks and callbacks.distance then - local list = callbacks.distance.__list + local list = callbacks.__distances local state = data.state local newstate @@ -293,32 +305,18 @@ do end data.state = newstate end - + -- Update the last distance with the current distance data.lastdist = dist end end - local tooltip_count = 0 - function Tooltip_OnUpdate(self, elapsed) - tooltip_count = tooltip_count + elapsed - if tooltip_count >= 0.2 then - if tooltip_callback then - local dist,x,y = Astrolabe:GetDistanceToIcon(tooltip_icon) - - -- Callback: OnTooltipShown - -- arg1: The tooltip object - -- arg2: The distance to the icon in yards - -- arg3: Boolean value indicating the tooltip was just shown - tooltip_callback("OnTooltipShown", tooltip, dist, false) - tooltip_count = 0 - end - end - end - tooltip:SetScript("OnUpdate", Tooltip_OnUpdate) - function World_OnEvent(self, event, ...) if event == "WORLD_MAP_UPDATE" then + if not self.point.uid then + return + end + local data = self.point -- It seems that data.x and data.y are occasionally not valid -- perhaps when the waypoint is removed. Guard this for now @@ -328,7 +326,7 @@ do return end - local x,y = Astrolabe:PlaceIconOnWorldMap(WorldMapDetailFrame, self, data.c, data.z, data.x/100, data.y/100) + local x,y = Astrolabe:PlaceIconOnWorldMap(WorldMapDetailFrame, self, data.c, data.z, data.x, data.y) if (x and y and (0 < x and x <= 1) and (0 < y and y <= 1)) then self:Show() else @@ -340,7 +338,7 @@ do function Minimap_OnEvent(self, event, ...) if event == "PLAYER_ENTERING_WORLD" then local data = self.data - Astrolabe:PlaceIconOnMinimap(self, data.c, data.z, data.x/100, data.y/100) + Astrolabe:PlaceIconOnMinimap(self, data.c, data.z, data.x, data.y) end end end diff --git a/TomTom_Zones.lua b/TomTom_Zones.lua deleted file mode 100644 index 1e08808..0000000 --- a/TomTom_Zones.lua +++ /dev/null @@ -1,142 +0,0 @@ ---[[-------------------------------------------------------------------------- - TomTom by Cladhaire -----------------------------------------------------------------------------]] - -local tokens = { - -- Kalimdor - ["Ashenvale"] = "ASHE", - ["Azshara"] = "AZSH", - ["Azuremyst Isle"] = "AZUR", - ["Bloodmyst Isle"] = "BLOO", - ["Darkshore"] = "DARK", - ["Darnassus"] = "DARN", - ["Desolace"] = "DESO", - ["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", -} - --- token -> number --- number -> name --- name -> token -local zones = {} -for c in pairs{GetMapContinents()} do - zones[c] = {GetMapZones(c)} - for idx,zone in ipairs(zones[c]) do - local token = tokens[zone] - assert(token, tostring(zone)) - - local key = c * 100 + idx - zones[token] = key - zones[key] = zone - end - zones[c] = nil -end - --- TomTom:GetZoneToken(name or continent [, zone]) --- name (string) - The name of a map zone as returned by GetMapZones() --- continent (number) - The continent number --- zone (number) - The zone number --- --- Converts a zone name or continent/zone pair to a locale-independent token -function TomTom:GetZoneToken(arg1, arg2) - local targ1,targ2 = type(arg1), type(arg2) - - if targ1 == "number" and targ2 == "number" then - -- c,z pair as arguments - local key = arg1 * 100 + arg2 - local name = zones[key] - return name and tokens[name] - elseif targ1 == "string" and targ2 == "nil" then - -- zone name as argument - local token = tokens[arg1] - return tokens[arg1] - end -end - --- TomTom:GetZoneName(token or continent [, zone]) --- token (string) - The locale independent token for the zone --- continent (number) - The continent number --- zone (number) - The zone number --- --- Converts a zone token or continent/zone pair into a zone name -function TomTom:GetZoneName(arg1, arg2) - local targ1,targ2 = type(arg1), type(arg2) - - if targ1 == "number" and targ2 == "number" then - -- c,z pair as arguments - local key = arg1 * 100 + arg2 - return zones[key] - elseif targ1 == "string" and targ2 == "nil" then - -- token as argument - local num = zones[arg1] - return num and zones[num] - end -end - --- TomTom:GetZoneNumber(token or name) --- token (string) - The locale independent token for the zone --- name (string) - The name of the zone --- --- Converts a zone token or name into a continent/zone pair -function TomTom:GetZoneNumber(arg1) - -- convert from name to token first, if possible - local token = tokens[arg1] or arg1 - local key = token and zones[token] - - if key then - return math.floor(key / 100), key % 100 - end -end -- 1.7.9.5