diff --git a/AddonCore.lua b/AddonCore.lua
index 2367ce7..66ba437 100644
--- a/AddonCore.lua
+++ b/AddonCore.lua
@@ -50,6 +50,22 @@ if EMERGENCY_DEBUG then
end
--[[-------------------------------------------------------------------------
+-- Print/Printf support
+-------------------------------------------------------------------------]]--
+
+local printHeader = "|cFF33FF99%s|r: "
+
+function addon:Printf(msg, ...)
+ msg = printHeader .. msg
+ local success, txt = pcall(string.format, msg, addonName, ...)
+ if success then
+ print(txt)
+ else
+ error(string.gsub(txt, "'%?'", string.format("'%s'", "Printf")), 3)
+ end
+end
+
+--[[-------------------------------------------------------------------------
-- Event registration and dispatch
-------------------------------------------------------------------------]]--
@@ -90,18 +106,18 @@ function addon:RegisterMessage(name, handler)
end
function addon:UnregisterMessage(name)
- assert(type(event) == "string", "Invalid argument to 'UnregisterMessage'")
+ assert(type(name) == "string", "Invalid argument to 'UnregisterMessage'")
messageMap[name] = nil
end
function addon:FireMessage(name, ...)
- assert(type(event) == "string", "Invalid argument to 'FireMessage'")
+ assert(type(name) == "string", "Invalid argument to 'FireMessage'")
local handler = messageMap[name]
local handler_t = type(handler)
if handler_t == "function" then
handler(name, ...)
elseif handler_t == "string" and addon[handler] then
- addon[handler](addon, event, ...)
+ addon[handler](addon, name, ...)
end
end
@@ -209,5 +225,8 @@ function about.OnShow(frame)
frame:SetScript("OnShow", nil)
end
+addon.optpanels = addon.optpanels or {}
+addon.optpanels.ABOUT = about
+
about:SetScript("OnShow", about.OnShow)
InterfaceOptions_AddCategory(about)
diff --git a/DatabaseDefaults.lua b/DatabaseDefaults.lua
index e1c6f95..b6f2344 100644
--- a/DatabaseDefaults.lua
+++ b/DatabaseDefaults.lua
@@ -3,5 +3,11 @@ local L = addon.L
addon.defaults = {
char = {},
- profile = {},
+ profile = {
+ positions = {},
+
+ goodcolor = {0, 1, 0},
+ badcolor = {1, 0, 0},
+ middlecolor = {1, 1, 0},
+ },
}
diff --git a/TomTomLite.lua b/TomTomLite.lua
index f8d1b49..cc3afb2 100644
--- a/TomTomLite.lua
+++ b/TomTomLite.lua
@@ -7,6 +7,93 @@ local L = addon.L
addon.callbacks = LibStub("CallbackHandler-1.0"):New(addon)
addon.mapdata = LibStub("LibMapData-1.0")
+addon.waypoints = {}
function addon:Initialize()
+ self.db = LibStub("AceDB-3.0"):New("TomTomLiteDB", self.defaults)
+
+ self.arrow = self:CreateCrazyArrow("TomTomLiteArrow")
+ self.arrow:SetPoint("CENTER", 0, 0)
+ self.arrow:Hide()
+
+ self:RegisterMessage("TOMTOMLITE_WAYPOINT_ADDED")
+end
+
+function addon:CreateCrazyArrow(name, parent)
+ parent = parent or UIParent
+ local frame = CreateFrame("Button", name, parent)
+
+ frame:SetSize(128, 128)
+ frame.arrow = frame:CreateTexture("OVERLAY")
+ frame.arrow:SetAllPoints()
+ frame.arrow:SetTexture("Interface\\Addons\\TomTomLite\\images\\arrow-grey")
+
+ frame.title = frame:CreateFontString("OVERLAY", name .. "Title", "GameFontHighlight")
+ frame.info = frame:CreateFontString("OVERLAY", name .. "Info", "GameFontHighlight")
+ frame.subtitle = frame:CreateFontString("OVERLAY", name .. "Subtitle", "GameFontHighlight")
+
+ frame.title:SetPoint("TOP", frame, "BOTTOM", 0, 0)
+ frame.info:SetPoint("TOP", frame.title, "BOTTOM", 0, 0)
+ frame.subtitle:SetPoint("TOP", frame.info, "BOTTOM", 0, 0)
+
+ frame:Hide()
+
+ -- Set up the OnUpdate handler
+ frame:SetScript("OnUpdate", function(self, elapsed)
+ local map, floor, x, y = unpack(self.waypoint)
+ local distance, angle = addon.mapdata:DistanceAndDirection(map, 0, x, y)
+ local facing = GetPlayerFacing()
+
+ local faceangle = angle - facing
+
+ local perc = math.abs((math.pi - math.abs(faceangle)) / math.pi)
+ local gr,gg,gb = unpack(addon.db.profile.goodcolor)
+ local mr,mg,mb = unpack(addon.db.profile.middlecolor)
+ local br,bg,bb = unpack(addon.db.profile.badcolor)
+ local r,g,b = addon:ColorGradient(perc, br, bg, bb, mr, mg, mb, gr, gg, gb)
+
+ self.arrow:SetVertexColor(r,g,b)
+ self.arrow:SetRotation(faceangle)
+
+ self.subtitle:SetFormattedText("%.1f yards", distance)
+ end)
+
+ -- Code to handle moving the frame
+ frame:SetMovable(true)
+ frame:RegisterForDrag("LeftButton")
+ frame:SetScript("OnDragStart", frame.StartMoving)
+ frame:SetScript("OnDragStop", function(self)
+ self:SetUserPlaced(false)
+ self:StopMovingOrSizing()
+ addon:SavePosition(self)
+ end)
+ frame:SetScript("OnHide", frame:GetScript("OnDragStop"))
+ self:RestorePosition(frame)
+
+ return frame
+end
+
+function addon:AddWaypoint(map, floor, x, y, opt)
+ local waypoint = {map, floor, x, y}
+ if type(opt) == "table" then
+ for k, v in pairs(opt) do
+ if type(k) ~= "number" then
+ waypoint[k] = v
+ end
+ end
+ end
+
+ table.insert(self.waypoints, waypoint)
+ self:FireMessage("TOMTOMLITE_WAYPOINT_ADDED", waypoint)
+end
+
+function addon:TOMTOMLITE_WAYPOINT_ADDED(msg, waypoint, ...)
+ local zone, floor, x, y = unpack(waypoint)
+ local lzone = self.mapdata:MapLocalize(zone)
+ self:Printf("Added a waypoint at (%.2f, %.2f) in %s", x * 100, y * 100, lzone)
+
+ self.arrow.waypoint = waypoint
+ self.arrow.title:SetText(waypoint.title or L["Unknown waypoint"])
+ self.arrow.info:SetFormattedText("%.2f, %.2f - %s", x * 100, y * 100, lzone)
+ self.arrow:Show()
end
diff --git a/TomTomLite.toc b/TomTomLite.toc
index b7c35d1..0a9ff12 100755
--- a/TomTomLite.toc
+++ b/TomTomLite.toc
@@ -16,6 +16,7 @@ libs\CallbackHandler-1.0\CallbackHandler-1.0.xml
libs\AceDB-3.0\AceDB-3.0.xml
libs\LibMapData-1.0\library.lua
+Utils.lua
DatabaseDefaults.lua
TomTomLite.lua
diff --git a/Utils.lua b/Utils.lua
new file mode 100644
index 0000000..fc66ed2
--- /dev/null
+++ b/Utils.lua
@@ -0,0 +1,67 @@
+local addonName, addon = ...
+local L = addon.L
+
+function addon:ColorGradient(perc, ...)
+ local num = select("#", ...)
+ local hexes = type(select(1, ...)) == "string"
+
+ if perc == 1 then
+ return select(num-2, ...), select(num-1, ...), select(num, ...)
+ end
+
+ num = num / 3
+
+ local segment, relperc = math.modf(perc*(num-1))
+ local r1, g1, b1, r2, g2, b2
+ r1, g1, b1 = select((segment*3)+1, ...), select((segment*3)+2, ...), select((segment*3)+3, ...)
+ r2, g2, b2 = select((segment*3)+4, ...), select((segment*3)+5, ...), select((segment*3)+6, ...)
+
+ if not r2 or not g2 or not b2 then
+ return r1, g1, b1
+ else
+ return r1 + (r2-r1)*relperc,
+ g1 + (g2-g1)*relperc,
+ b1 + (b2-b1)*relperc
+ end
+end
+
+function addon:SavePosition(f)
+ local name = f:GetName()
+ local x,y = f:GetLeft(), f:GetTop()
+ local s = f:GetEffectiveScale()
+
+ x,y = x*s,y*s
+
+ local opt = addon.db.profile.positions[name]
+ if not opt then
+ addon.db.profile.positions[name] = {}
+ opt = addon.db.profile.positions[name]
+ end
+ opt.PosX = x
+ opt.PosY = y
+end
+
+function addon:RestorePosition(f)
+ local name = f:GetName()
+ local opt = addon.db.profile.positions[name]
+ if not opt then
+ addon.db.profile.positions[name] = {}
+ opt = addon.db.profile.positions[name]
+ end
+
+ local x = opt.PosX
+ local y = opt.PosY
+
+ local s = f:GetEffectiveScale()
+
+ if not x or not y then
+ f:ClearAllPoints()
+ f:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
+ return
+ end
+
+ x,y = x/s,y/s
+
+ f:ClearAllPoints()
+ f:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x, y)
+end
diff --git a/images/arrow-grey.tga b/images/arrow-grey.tga
new file mode 100644
index 0000000..4473259
Binary files /dev/null and b/images/arrow-grey.tga differ