Files
EasyRoute/Tracker.lua
T
notforever-ship-it ab84cc38cd Release 0.7.0: a step-by-step guide like RestedXP, with an arrow
- Pick a difficulty, then a guide for your level and faction: RestedXP's free classic guides,
  Alliance and Horde, levels 1 to 60 (CC BY-NC-SA 4.0, credited in the README and Help).
- The step window shows the step you are on and ticks it off as you accept, kill, loot and
  hand in; the guide moves on by itself. The gear opens every guide by level.
- An arrow at the top of the screen points at the next place, with the distance in yards.
- Casual leaves out group quests and elite quests, Medium leaves out group quests, Hard does all.
- New commands: /er guides, /er arrow, /er next, /er stop.
2026-10-08 18:11:30 +01:00

582 lines
20 KiB
Lua

-- Easy Route: the step window, laid out like RestedXP's. At the top, the step you are on in a box ("Step 12"), with
-- a tick for each thing in it as you do it and the count for kill and collect objectives; under it the guide's name
-- with a gear for the guide menu; then the next few steps (click one to jump to it); and < > to step by hand.
-- The guide menu lists the guides for your faction by level, the ones that suit you now marked, like RestedXP's.
--
-- The steps and when they are done come from Steps.lua; the arrow is Arrow.lua.
local ER = EasyRoute
local GOLD, GREY, WHITE, END = ER.GOLD, ER.GREY, ER.WHITE, ER.END
local GREEN = ER.GREEN
local W = 300
local LINES, ROWS = 9, 6
local MARK = { A = "|cffffff00!|r ", T = "|cffffff00?|r ", C = "|cffff8040*|r ", K = "|cff00bcd4*|r ", X = "|cffb070ff*|r ",
H = "|cff79a2ff*|r ", F = "|cff79a2ff*|r ", P = "|cff79a2ff*|r ", B = "|cff79a2ff*|r " }
local T = { lines = {}, rows = {} }
local M = { groupRows = {}, guideRows = {}, extraRows = {} }
local Refresh
local function Say(msg)
if DEFAULT_CHAT_FRAME then DEFAULT_CHAT_FRAME:AddMessage("|cff33ff99Easy Route:|r " .. msg) end
end
local function Plain(text)
text = string.gsub(text or "", "|c%x%x%x%x%x%x%x%x", "")
return (string.gsub(text, "|r", ""))
end
-- About how many rows a line of text wraps to in the window.
local function Rows(text, perRow)
local n = math.ceil(string.len(Plain(text)) / perRow)
if n < 1 then n = 1 end
if n > 4 then n = 4 end
return n
end
local function Backdrop(f, alpha)
f:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 14,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
f:SetBackdropColor(0.03, 0.03, 0.05, alpha or 0.9)
f:SetBackdropBorderColor(0.55, 0.55, 0.6, 1)
end
local function Tip(widget, fn)
widget:SetScript("OnEnter", function()
local title, body, hint = fn(this)
if not title then return end
GameTooltip:SetOwner(this, "ANCHOR_LEFT")
GameTooltip:SetText(title)
if body then GameTooltip:AddLine(body, 1, 1, 1, 1) end
if hint then GameTooltip:AddLine(hint, 0.6, 0.6, 0.6, 1) end
GameTooltip:Show()
end)
widget:SetScript("OnLeave", function() GameTooltip:Hide() end)
end
local function Credit(parent, x, y)
local credit = parent:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
credit:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", x, y)
credit:SetText(GREY .. "Made by " .. END .. "|cffabd473stealthzi" .. END .. GREY .. " v" .. ER.VERSION .. END)
return credit
end
------------------------------------------------------------------------------------------------------
-- The step box
------------------------------------------------------------------------------------------------------
-- The lines of one step: { text, done, kind, step }.
local function StepLines(step, max)
local out = {}
local Steps = ER.Steps
for _, e in ipairs(step.elements) do
local line = Steps.Line(step, e)
if line then
line.step = step
table.insert(out, line)
if max and table.getn(out) >= max then break end
end
end
if table.getn(out) == 0 then table.insert(out, { text = Steps.Title(step), step = step }) end
return out
end
local function LineText(line)
local text = line.text
if line.done == true then
return GREEN .. "[x] " .. END .. GREY .. Plain(text) .. END
elseif line.done == false then
return GREY .. "[ ] " .. END .. (MARK[line.kind] or "") .. text
end
return text
end
local function FillBox()
local Steps = ER.Steps
local step = Steps.Current()
local lines = {}
if step then
for _, l in ipairs(StepLines(step)) do table.insert(lines, l) end
if Steps.ByHand(step) then
table.insert(lines, { text = GREY .. "Click here or press > when this is done." .. END, step = step, tick = true })
end
else
table.insert(lines, { text = GOLD .. "This guide is finished." .. END })
local nxt = Steps.NextGuide()
if nxt then
table.insert(lines, { text = "Next: " .. WHITE .. (nxt.title or nxt.name) .. END .. GREY .. " (click to start it)" .. END, nextGuide = nxt })
else
table.insert(lines, { text = GREY .. "Open the guide menu (the gear) to pick the next one." .. END })
end
end
local side = Steps.Side()
if table.getn(side) > 0 then
table.insert(lines, { text = GREY .. "On the way:" .. END })
for _, s in ipairs(side) do
for _, l in ipairs(StepLines(s, 2)) do
l.side = true
table.insert(lines, l)
end
end
end
local y = -12
for i = 1, LINES do
local b, line = T.lines[i], lines[i]
if line then
local text = LineText(line)
local h = Rows(text, 42) * 14 + 2
b:ClearAllPoints()
b:SetPoint("TOPLEFT", T.box, "TOPLEFT", 10, y)
b:SetHeight(h)
b.text:SetHeight(h)
b.text:SetText(text)
b.line = line
b:Show()
y = y - h - 2
else
b.line = nil
b:Hide()
end
end
T.box:SetHeight(-y + 8)
T.tab:SetText(step and (GOLD .. "Step " .. Steps.Position() .. END .. GREY .. " of " .. Steps.Count() .. END) or (GOLD .. "Done" .. END))
T.tick:SetText(step and Steps.ByHand(step) and "Done" or "Skip")
end
------------------------------------------------------------------------------------------------------
-- The guide name and the list of what comes next
------------------------------------------------------------------------------------------------------
local function FillList()
local Steps = ER.Steps
local info = Steps.Info()
T.name:SetText(info and (GOLD .. (info.title or info.name) .. END) or "")
T.group:SetText(info and (GREY .. info.group .. " - " .. ER.MODES[ER.Mode()].label .. END) or "")
local list = Steps.Upcoming(ROWS)
for i = 1, ROWS do
local r, s = T.rows[i], list[i]
if s then
r.text:SetText(GREY .. s.n .. END .. " " .. Plain(Steps.Title(s)))
r.step = s
r:Show()
else
r.step = nil
r:Hide()
end
end
end
Refresh = function()
if not T.frame or not T.frame:IsShown() then return end
if not ER.Steps.Running() then
T.frame:Hide()
return
end
FillBox()
FillList()
T.frame:SetHeight(T.box:GetHeight() + 44 + ROWS * 16 + 40)
end
ER.StepsChanged = function()
Refresh()
if M.frame and M.frame:IsShown() and M.Refresh then M.Refresh() end
end
------------------------------------------------------------------------------------------------------
-- The guide menu
------------------------------------------------------------------------------------------------------
local function MenuRow(parent, name, w)
local r = CreateFrame("Button", name, parent)
r:SetWidth(w)
r:SetHeight(16)
local glow = r:CreateTexture(nil, "HIGHLIGHT")
glow:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
glow:SetBlendMode("ADD")
glow:SetAllPoints(r)
r.text = r:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
r.text:SetPoint("LEFT", r, "LEFT", 4, 0)
r.text:SetWidth(w - 8)
r.text:SetJustifyH("LEFT")
return r
end
local function ShowGroup(grp)
M.group = grp
local suggested = {}
local best = ER.Steps.Suggest()[1]
if best then suggested[best] = 1 end
local running = ER.Steps.Info()
local n = 0
for i, r in ipairs(M.guideRows) do
local g = grp and grp.guides[i]
if g then
local text = g.title or g.name
if running == g then
text = GREEN .. text .. " (now)" .. END
elseif suggested[g] then
text = GOLD .. text .. END .. GREY .. " - suits you" .. END
else
text = WHITE .. text .. END
end
r.text:SetText(text)
r.guide = g
r:Show()
n = i
else
r.guide = nil
r:Hide()
end
end
M.panel:SetHeight(n * 16 + 36)
M.panelTitle:SetText(grp and (GOLD .. grp.name .. END) or "")
if grp then M.panel:Show() else M.panel:Hide() end
end
M.Refresh = function()
local groups = ER.Steps.Groups()
local suggested = ER.Steps.Suggest()[1]
local n = 0
for i, r in ipairs(M.groupRows) do
local grp = groups[i]
if grp then
local has = false
for _, g in ipairs(grp.guides) do if g == suggested then has = true end end
r.text:SetText((has and GOLD or WHITE) .. grp.name .. END .. GREY .. " >" .. END)
r.grp = grp
r:Show()
n = i
else
r.grp = nil
r:Hide()
end
end
local y = -30 - n * 16 - 10
M.otherTitle:ClearAllPoints()
M.otherTitle:SetPoint("TOPLEFT", M.frame, "TOPLEFT", 12, y)
y = y - 16
local extras = {
{ "Change difficulty (" .. ER.MODES[ER.Mode()].label .. ")", function()
M.frame:Hide()
if ER.ShowWizardMood then ER.ShowWizardMood() end
end },
{ (ER.db and ER.db.arrowOff) and "Show the arrow" or "Hide the arrow", function()
if ER.ToggleArrow then ER.ToggleArrow() end
M.Refresh()
end },
{ "Start this guide again", function()
local info = ER.Steps.Info()
if info then ER.Steps.Load(ER.Steps.Key(info), true) end
M.frame:Hide()
end },
{ "Stop the guide", function()
ER.Steps.Stop()
M.frame:Hide()
Say("guide stopped. " .. GOLD .. "/er" .. END .. " starts one again.")
end },
{ "Close", function() M.frame:Hide() end },
}
for i, r in ipairs(M.extraRows) do
local x = extras[i]
r:ClearAllPoints()
r:SetPoint("TOPLEFT", M.frame, "TOPLEFT", 8, y - (i - 1) * 16)
r.text:SetText(WHITE .. x[1] .. END)
r.fn = x[2]
r:Show()
end
M.frame:SetHeight(-y + table.getn(extras) * 16 + 34)
-- Open on the group that holds the guide that suits you best.
local open = M.group
if not open then
for _, grp in ipairs(groups) do
for _, g in ipairs(grp.guides) do if g == suggested then open = grp end end
end
end
ShowGroup(open or groups[1])
end
local function BuildMenu()
local f = CreateFrame("Frame", "EasyRouteGuideMenu", UIParent)
M.frame = f
f:SetWidth(220)
f:SetHeight(200)
f:SetFrameStrata("DIALOG")
f:SetClampedToScreen(true)
f:EnableMouse(true)
Backdrop(f, 0.95)
f:Hide()
table.insert(UISpecialFrames, "EasyRouteGuideMenu")
local title = f:CreateFontString(nil, "ARTWORK", "GameFontNormal")
title:SetPoint("TOPLEFT", f, "TOPLEFT", 12, -10)
title:SetText("Available guides")
for i = 1, 6 do
local r = MenuRow(f, "EasyRouteGuideMenuGroup" .. i, 204)
r:SetPoint("TOPLEFT", f, "TOPLEFT", 8, -28 - (i - 1) * 16)
r:SetScript("OnEnter", function() if this.grp then ShowGroup(this.grp) end end)
r:SetScript("OnClick", function() if this.grp then ShowGroup(this.grp) end end)
r:Hide()
M.groupRows[i] = r
end
M.otherTitle = f:CreateFontString(nil, "ARTWORK", "GameFontNormal")
M.otherTitle:SetText("Options")
for i = 1, 5 do
local r = MenuRow(f, "EasyRouteGuideMenuExtra" .. i, 204)
r:SetScript("OnClick", function() if this.fn then this.fn() end end)
r:Hide()
M.extraRows[i] = r
end
Credit(f, -10, 8)
local p = CreateFrame("Frame", "EasyRouteGuideMenuPanel", f)
M.panel = p
p:SetWidth(270)
p:SetHeight(200)
p:SetPoint("TOPLEFT", f, "TOPRIGHT", -2, 0)
p:EnableMouse(true)
Backdrop(p, 0.95)
M.panelTitle = p:CreateFontString(nil, "ARTWORK", "GameFontNormal")
M.panelTitle:SetPoint("TOPLEFT", p, "TOPLEFT", 12, -10)
for i = 1, 22 do
local r = MenuRow(p, "EasyRouteGuideMenuGuide" .. i, 254)
r:SetPoint("TOPLEFT", p, "TOPLEFT", 8, -28 - (i - 1) * 16)
r:SetScript("OnClick", function()
local g = this.guide
if not g then return end
M.frame:Hide()
ER.StartGuide(ER.Steps.Key(g))
end)
Tip(r, function(b)
local g = b.guide
if not g then return nil end
return g.title or g.name, "Levels " .. g.lo .. " to " .. g.hi .. ".", "Click to follow this guide."
end)
r:Hide()
M.guideRows[i] = r
end
end
-- Opens the guide menu, next to the step window when it is up, in the middle of the screen when not.
function ER.ShowGuideMenu(anchor)
if not M.frame then BuildMenu() end
M.group = nil
M.frame:ClearAllPoints()
if anchor then
M.frame:SetPoint("TOPRIGHT", anchor, "BOTTOMLEFT", 0, 0)
elseif T.frame and T.frame:IsShown() then
M.frame:SetPoint("TOPRIGHT", T.frame, "TOPLEFT", -276, 0)
else
M.frame:SetPoint("CENTER", UIParent, "CENTER", -140, 40)
end
M.frame:Show()
M.Refresh()
end
------------------------------------------------------------------------------------------------------
-- Building the window
------------------------------------------------------------------------------------------------------
local function Button(name, parent, w, label, fn)
local b = CreateFrame("Button", name, parent, "UIPanelButtonTemplate")
b:SetWidth(w)
b:SetHeight(20)
b:SetText(label)
b:SetScript("OnClick", fn)
return b
end
local function Build()
local f = CreateFrame("Frame", "EasyRouteTracker", UIParent)
T.frame = f
f:SetWidth(W)
f:SetHeight(300)
local pos = ER.db and ER.db.trackerPos
if type(pos) == "table" and pos.point then
f:SetPoint(pos.point, UIParent, pos.relPoint or pos.point, pos.x or 0, pos.y or 0)
else
f:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", -40, -220)
end
f:SetFrameStrata("MEDIUM")
f:SetClampedToScreen(true)
f:EnableMouse(true)
f:SetMovable(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", function() this:StartMoving() end)
f:SetScript("OnDragStop", function()
this:StopMovingOrSizing()
local point, _, relPoint, x, y = this:GetPoint()
if ER.db then ER.db.trackerPos = { point = point, relPoint = relPoint, x = x, y = y } end
end)
f:SetScript("OnShow", function() Refresh() end)
f:Hide()
-- The step box, with its "Step 12" tab on top.
local box = CreateFrame("Frame", "EasyRouteTrackerBox", f)
T.box = box
box:SetWidth(W)
box:SetHeight(80)
box:SetPoint("TOPLEFT", f, "TOPLEFT", 0, -16)
Backdrop(box, 0.92)
box:SetBackdropBorderColor(0.85, 0.65, 0.3, 1)
local tab = CreateFrame("Frame", "EasyRouteTrackerTab", f)
tab:SetWidth(130)
tab:SetHeight(22)
tab:SetPoint("BOTTOMLEFT", box, "TOPLEFT", 6, -6)
Backdrop(tab, 0.95)
tab:SetBackdropBorderColor(0.85, 0.65, 0.3, 1)
T.tab = tab:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
T.tab:SetPoint("CENTER", tab, "CENTER", 0, 0)
local close = CreateFrame("Button", "EasyRouteTrackerClose", f, "UIPanelCloseButton")
close:SetWidth(24)
close:SetHeight(24)
close:SetPoint("BOTTOMRIGHT", box, "TOPRIGHT", 2, -6)
close:SetScript("OnClick", function()
f:Hide()
Say("step window hidden; the guide keeps going. " .. GOLD .. "/er" .. END .. " shows it again.")
end)
for i = 1, LINES do
local b = CreateFrame("Button", "EasyRouteTrackerLine" .. i, box)
b:SetWidth(W - 20)
b:SetHeight(14)
local glow = b:CreateTexture(nil, "HIGHLIGHT")
glow:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
glow:SetBlendMode("ADD")
glow:SetAllPoints(b)
b.text = b:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
b.text:SetPoint("TOPLEFT", b, "TOPLEFT", 0, 0)
b.text:SetWidth(W - 20)
b.text:SetJustifyH("LEFT")
b.text:SetJustifyV("TOP")
b:SetScript("OnClick", function()
local line = this.line
if line and line.nextGuide then
ER.StartGuide(ER.Steps.Key(line.nextGuide))
return
end
if not line or not line.step then return end
if line.tick or line.kind == "M" or ER.Steps.ByHand(line.step) then
ER.Steps.Tick(line.step.n)
end
end)
Tip(b, function(btn)
local line = btn.line
if not line or not line.step then return nil end
local hint = "The arrow shows where this happens."
if line.tick or line.kind == "M" or ER.Steps.ByHand(line.step) then hint = "Click when you have done this." end
return Plain(ER.Steps.Title(line.step)), Plain(line.text), hint
end)
b:Hide()
T.lines[i] = b
end
-- The guide's name, with the gear for the guide menu.
local head = CreateFrame("Button", "EasyRouteTrackerHead", f)
T.head = head
head:SetWidth(W)
head:SetHeight(38)
head:SetPoint("TOPLEFT", box, "BOTTOMLEFT", 0, 2)
Backdrop(head, 0.92)
local icon = head:CreateTexture(nil, "ARTWORK")
icon:SetTexture("Interface\\Icons\\INV_Misc_Book_09")
icon:SetWidth(26)
icon:SetHeight(26)
icon:SetPoint("LEFT", head, "LEFT", 7, 0)
T.name = head:CreateFontString(nil, "ARTWORK", "GameFontNormal")
T.name:SetPoint("TOPLEFT", icon, "TOPRIGHT", 6, 0)
T.name:SetWidth(W - 80)
T.name:SetJustifyH("LEFT")
T.group = head:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
T.group:SetPoint("BOTTOMLEFT", icon, "BOTTOMRIGHT", 6, 0)
T.group:SetWidth(W - 80)
T.group:SetJustifyH("LEFT")
head:SetScript("OnClick", function() ER.ShowGuideMenu() end)
local gear = CreateFrame("Button", "EasyRouteTrackerGear", head)
gear:SetWidth(22)
gear:SetHeight(22)
gear:SetPoint("RIGHT", head, "RIGHT", -8, 0)
gear:SetNormalTexture("Interface\\Icons\\INV_Misc_Gear_01")
gear:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
gear:SetScript("OnClick", function() ER.ShowGuideMenu() end)
Tip(gear, function() return "Guide menu", "Pick another guide, change the difficulty, hide the arrow.", nil end)
Tip(head, function() return "Guide menu", "Click to pick another guide.", nil end)
-- What comes next.
local list = CreateFrame("Frame", "EasyRouteTrackerList", f)
T.list = list
list:SetWidth(W)
list:SetHeight(ROWS * 16 + 40)
list:SetPoint("TOPLEFT", head, "BOTTOMLEFT", 0, 2)
Backdrop(list, 0.85)
for i = 1, ROWS do
local r = MenuRow(list, "EasyRouteTrackerRow" .. i, W - 16)
r:SetPoint("TOPLEFT", list, "TOPLEFT", 8, -8 - (i - 1) * 16)
r:SetScript("OnClick", function() if this.step then ER.Steps.Jump(this.step.n) end end)
Tip(r, function(b)
if not b.step then return nil end
local lines = {}
for _, l in ipairs(StepLines(b.step)) do table.insert(lines, Plain(l.text)) end
return "Step " .. b.step.n, table.concat(lines, "\n"), "Click to jump to this step."
end)
r:Hide()
T.rows[i] = r
end
Button("EasyRouteTrackerPrev", list, 26, "<", function() ER.Steps.Prev() end):SetPoint("BOTTOMLEFT", list, "BOTTOMLEFT", 8, 8)
Button("EasyRouteTrackerNext", list, 26, ">", function() ER.Steps.Next() end):SetPoint("BOTTOMLEFT", list, "BOTTOMLEFT", 36, 8)
T.tick = Button("EasyRouteTrackerTick", list, 50, "Skip", function()
local step = ER.Steps.Current()
if step and ER.Steps.ByHand(step) then ER.Steps.Tick(step.n) else ER.Steps.Next() end
end)
T.tick:SetPoint("BOTTOMLEFT", list, "BOTTOMLEFT", 64, 8)
Tip(T.tick, function()
return "Done / Skip", "Done: you have done this step. Skip: leave this step out and go on.", nil
end)
Credit(list, -10, 12)
end
function ER.ShowTracker()
if not T.frame then Build() end
T.frame:Show()
Refresh()
end
function ER.TrackerShown()
return T.frame and T.frame:IsShown() or false
end
function ER.ToggleTracker()
if not T.frame then Build() end
if T.frame:IsShown() then T.frame:Hide() else ER.ShowTracker() end
end
-- Starts a guide and shows the step window and the arrow.
function ER.StartGuide(key, fresh)
if not ER.Steps.Load(key, fresh) then
Say("that guide could not be loaded.")
return false
end
local info = ER.Steps.Info()
Say("following " .. GOLD .. (info.title or info.name) .. END .. ". The arrow points the way; " .. GOLD .. "/er" .. END ..
" shows or hides the steps.")
if ER.db then ER.db.arrowOff = nil end -- a new guide always starts with the arrow on
ER.ShowTracker()
if ER.ArrowUpdate then ER.ArrowUpdate() end
return true
end
-- Picks the step window back up after a login when a guide was running.
local starter = CreateFrame("Frame", "EasyRouteTrackerStarter")
starter:RegisterEvent("PLAYER_ENTERING_WORLD")
starter:SetScript("OnEvent", function()
this:UnregisterEvent("PLAYER_ENTERING_WORLD")
this.wait = 0
this:SetScript("OnUpdate", function()
this.wait = this.wait + arg1
if this.wait < 2 then return end
this:SetScript("OnUpdate", nil)
if ER.Steps.Running() or ER.Steps.Resume() then ER.ShowTracker() end
end)
end)