Ship Routes: solid sea lanes around the continents, labelled edge markers
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
63eebfc8bd
commit
216e6f90b8
6 changed files with 555 additions and 301 deletions
|
|
@ -11,15 +11,19 @@ local COLORS = {
|
|||
Horde = { 1.00, 0.32, 0.24 },
|
||||
Neutral = { 1.00, 0.82, 0.25 },
|
||||
}
|
||||
-- dash and gap as a share of the canvas width; width in screen pixels
|
||||
-- line width in screen pixels, and opacity
|
||||
local STYLE = {
|
||||
boat = { dash = 0.010, gap = 0.006, width = 3 },
|
||||
air = { dash = 0.004, gap = 0.006, width = 2.5 },
|
||||
jump = { dash = 0.003, gap = 0.010 },
|
||||
boat = { width = 3, alpha = 0.95 },
|
||||
air = { width = 2.5, alpha = 0.8 },
|
||||
}
|
||||
-- the zone or continent map each instance is drawn from on the world map
|
||||
local DIMMED = 0.2 -- opacity of other routes while one is highlighted
|
||||
local WORLD_MAP = 947 -- Azeroth: the shared space that legs between continents are drawn in
|
||||
local WORLD = -1 -- instance marker in Data.lua for a point given on the world map
|
||||
-- the zone or continent map each instance is placed on the world map by
|
||||
local HOME_MAP = { [0] = 1415, [1] = 1414, [2991] = 2521 }
|
||||
local NEARBY = 800 -- yards: other departures this close show in a dock's tooltip
|
||||
local EXIT_INSET = 0.025 -- share of the map an edge marker sits inside the border
|
||||
local EXIT_MERGE = 0.06 -- edge markers closer than this share of the map width merge
|
||||
|
||||
local db
|
||||
|
||||
|
|
@ -37,70 +41,156 @@ end
|
|||
ns.Visible = Visible
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- Projection: world position -> normalized position on a uiMap
|
||||
-- Projection: (instance, world x, world y) or a world map point -> position on a uiMap
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local function DirectProjector(uiMapID)
|
||||
local inst, topLeft = C_Map.GetWorldPosFromMapPos(uiMapID, CreateVector2D(0, 0))
|
||||
local _, mid = C_Map.GetWorldPosFromMapPos(uiMapID, CreateVector2D(0.5, 0.5))
|
||||
if not inst or not topLeft or not mid then
|
||||
return nil
|
||||
end
|
||||
local top, left = topLeft:GetXY()
|
||||
local midTop, midLeft = mid:GetXY()
|
||||
local height, width = (top - midTop) * 2, (left - midLeft) * 2
|
||||
if height == 0 or width == 0 then
|
||||
return nil
|
||||
end
|
||||
return function(m, x, y)
|
||||
if m ~= inst then
|
||||
return nil
|
||||
end
|
||||
return (left - y) / width, (top - x) / height
|
||||
end
|
||||
local function IsWorldMap(uiMapID)
|
||||
local info = C_Map.GetMapInfo(uiMapID)
|
||||
return info and info.mapType and info.mapType <= Enum.UIMapType.World
|
||||
end
|
||||
|
||||
local projectors = {}
|
||||
local function GetProjector(uiMapID)
|
||||
local cached = projectors[uiMapID]
|
||||
-- world position on a zone or continent map
|
||||
local direct = {}
|
||||
local function Direct(uiMapID)
|
||||
local cached = direct[uiMapID]
|
||||
if cached ~= nil then
|
||||
return cached or nil
|
||||
end
|
||||
local proj
|
||||
local info = C_Map.GetMapInfo(uiMapID)
|
||||
if info and info.mapType and info.mapType <= Enum.UIMapType.World then
|
||||
-- world maps have no world position of their own: place each home map's rect on it
|
||||
local rects = {}
|
||||
for inst, home in pairs(HOME_MAP) do
|
||||
local minX, maxX, minY, maxY = C_Map.GetMapRectOnMap(home, uiMapID)
|
||||
local direct = DirectProjector(home)
|
||||
if minX and direct and maxX ~= minX then
|
||||
rects[inst] = { direct, minX, maxX, minY, maxY }
|
||||
local fn = false
|
||||
if not IsWorldMap(uiMapID) then
|
||||
local inst, topLeft = C_Map.GetWorldPosFromMapPos(uiMapID, CreateVector2D(0, 0))
|
||||
local _, mid = C_Map.GetWorldPosFromMapPos(uiMapID, CreateVector2D(0.5, 0.5))
|
||||
if inst and topLeft and mid then
|
||||
local top, left = topLeft:GetXY()
|
||||
local midTop, midLeft = mid:GetXY()
|
||||
local height, width = (top - midTop) * 2, (left - midLeft) * 2
|
||||
if height ~= 0 and width ~= 0 then
|
||||
fn = function(m, x, y)
|
||||
if m ~= inst then
|
||||
return nil
|
||||
end
|
||||
return (left - y) / width, (top - x) / height
|
||||
end
|
||||
end
|
||||
end
|
||||
proj = function(m, x, y)
|
||||
local r = rects[m]
|
||||
if not r then
|
||||
return nil
|
||||
end
|
||||
local u, v = r[1](m, x, y)
|
||||
if not u then
|
||||
return nil
|
||||
end
|
||||
return r[2] + u * (r[3] - r[2]), r[4] + v * (r[5] - r[4])
|
||||
end
|
||||
else
|
||||
proj = DirectProjector(uiMapID)
|
||||
end
|
||||
projectors[uiMapID] = proj or false
|
||||
return proj
|
||||
direct[uiMapID] = fn
|
||||
return fn or nil
|
||||
end
|
||||
ns.GetProjector = GetProjector
|
||||
|
||||
-- where a map sits on the world map: { minU, maxU, minV, maxV }
|
||||
local rects = {}
|
||||
local function Rect(uiMapID)
|
||||
local cached = rects[uiMapID]
|
||||
if cached ~= nil then
|
||||
return cached or nil
|
||||
end
|
||||
local r = false
|
||||
if uiMapID == WORLD_MAP then
|
||||
r = { 0, 1, 0, 1 }
|
||||
else
|
||||
local minX, maxX, minY, maxY = C_Map.GetMapRectOnMap(uiMapID, WORLD_MAP)
|
||||
if minX and maxX ~= minX and maxY ~= minY then
|
||||
r = { minX, maxX, minY, maxY }
|
||||
end
|
||||
end
|
||||
rects[uiMapID] = r
|
||||
return r or nil
|
||||
end
|
||||
|
||||
local function ToWorldMap(m, a, b)
|
||||
if m == WORLD then
|
||||
return a, b
|
||||
end
|
||||
local home = HOME_MAP[m]
|
||||
local d, r = home and Direct(home), home and Rect(home)
|
||||
if not d or not r then
|
||||
return nil
|
||||
end
|
||||
local u, v = d(m, a, b)
|
||||
if not u then
|
||||
return nil
|
||||
end
|
||||
return r[1] + u * (r[2] - r[1]), r[3] + v * (r[4] - r[3])
|
||||
end
|
||||
|
||||
local function Project(uiMapID, m, a, b)
|
||||
if m ~= WORLD then
|
||||
local d = Direct(uiMapID)
|
||||
local u, v
|
||||
if d then
|
||||
u, v = d(m, a, b)
|
||||
end
|
||||
if u then
|
||||
return u, v
|
||||
end
|
||||
end
|
||||
local r = Rect(uiMapID)
|
||||
if not r then
|
||||
return nil
|
||||
end
|
||||
local wu, wv = ToWorldMap(m, a, b)
|
||||
if not wu then
|
||||
return nil
|
||||
end
|
||||
return (wu - r[1]) / (r[2] - r[1]), (wv - r[3]) / (r[4] - r[3])
|
||||
end
|
||||
ns.Project = Project
|
||||
|
||||
local function Inside(u, v)
|
||||
return u and u >= 0 and u <= 1 and v >= 0 and v <= 1
|
||||
end
|
||||
|
||||
-- Catmull-Rom through flat canvas points, a step every ~12 units
|
||||
local function Smooth(pts)
|
||||
local n = #pts / 2
|
||||
if n < 3 then
|
||||
return pts
|
||||
end
|
||||
local out = {}
|
||||
local function P(i)
|
||||
i = math.max(1, math.min(n, i))
|
||||
return pts[2 * i - 1], pts[2 * i]
|
||||
end
|
||||
for i = 1, n - 1 do
|
||||
local x0, y0 = P(i - 1)
|
||||
local x1, y1 = P(i)
|
||||
local x2, y2 = P(i + 1)
|
||||
local x3, y3 = P(i + 2)
|
||||
local len = math.sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2)
|
||||
local steps = math.max(2, math.min(24, math.floor(len / 12)))
|
||||
for s = 0, steps - 1 do
|
||||
local t = s / steps
|
||||
local t2, t3 = t * t, t * t * t
|
||||
out[#out + 1] = 0.5 * (2 * x1 + (-x0 + x2) * t + (2 * x0 - 5 * x1 + 4 * x2 - x3) * t2 + (-x0 + 3 * x1 - 3 * x2 + x3) * t3)
|
||||
out[#out + 1] = 0.5 * (2 * y1 + (-y0 + y2) * t + (2 * y0 - 5 * y1 + 4 * y2 - y3) * t2 + (-y0 + 3 * y1 - 3 * y2 + y3) * t3)
|
||||
end
|
||||
end
|
||||
out[#out + 1], out[#out + 2] = pts[#pts - 1], pts[#pts]
|
||||
return out
|
||||
end
|
||||
|
||||
-- walking from the start of a canvas polyline, where it first leaves the W x H box
|
||||
local function ExitPoint(pts, W, H)
|
||||
for i = 1, #pts - 3, 2 do
|
||||
local ax, ay, bx, by = pts[i], pts[i + 1], pts[i + 2], pts[i + 3]
|
||||
if bx < 0 or bx > W or by < 0 or by > H then
|
||||
local t, edge = 1, nil
|
||||
local function try(tt, e)
|
||||
if tt >= 0 and tt < t then
|
||||
t, edge = tt, e
|
||||
end
|
||||
end
|
||||
if bx < 0 then try(ax / (ax - bx), "left") end
|
||||
if bx > W then try((W - ax) / (bx - ax), "right") end
|
||||
if by < 0 then try(ay / (ay - by), "top") end
|
||||
if by > H then try((H - ay) / (by - ay), "bottom") end
|
||||
return ax + (bx - ax) * t, ay + (by - ay) * t, math.atan2(-(by - ay), bx - ax), edge or "right"
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- Text
|
||||
---------------------------------------------------------------------------
|
||||
|
|
@ -142,10 +232,20 @@ local function Departures(stop, except)
|
|||
return out
|
||||
end
|
||||
|
||||
-- an edge marker's line for one leg: where it leads, and how to say it
|
||||
local function ExitText(e)
|
||||
local route = e.route
|
||||
local name = route.stops[e.far][1]
|
||||
if #route.stops > 2 and e.far == e.leg.from then
|
||||
return route.noun .. " from " .. name
|
||||
end
|
||||
return route.noun .. " to " .. name
|
||||
end
|
||||
|
||||
local function FillTooltip(tip, pin)
|
||||
local route = pin.route
|
||||
local c = Color(route)
|
||||
if pin.kind == "dock" then
|
||||
local route = pin.route
|
||||
local c = Color(route)
|
||||
local stop = route.stops[pin.index]
|
||||
tip:SetText(stop[1], 1, 1, 1)
|
||||
tip:AddLine(RouteText(route, pin.index), c[1], c[2], c[3])
|
||||
|
|
@ -163,9 +263,15 @@ local function FillTooltip(tip, pin)
|
|||
end
|
||||
tip:AddLine("Click: show " .. Destinations(route, pin.index)[1][1], 0.5, 0.5, 0.5)
|
||||
else
|
||||
local dest = route.stops[pin.index]
|
||||
tip:SetText(route.noun .. " to " .. dest[1], c[1], c[2], c[3])
|
||||
tip:AddLine("Click: show " .. dest[1], 0.5, 0.5, 0.5)
|
||||
local first = pin.exits[1]
|
||||
local c = Color(first.route)
|
||||
tip:SetText(ExitText(first), c[1], c[2], c[3])
|
||||
for k = 2, #pin.exits do
|
||||
local e = pin.exits[k]
|
||||
local ec = Color(e.route)
|
||||
tip:AddLine(ExitText(e), ec[1], ec[2], ec[3])
|
||||
end
|
||||
tip:AddLine("Click: show " .. first.route.stops[first.far][1], 0.5, 0.5, 0.5)
|
||||
end
|
||||
end
|
||||
ns.FillTooltip = FillTooltip
|
||||
|
|
@ -177,11 +283,7 @@ local function ShowStop(map, stop)
|
|||
return
|
||||
end
|
||||
local target = home
|
||||
local proj = GetProjector(home)
|
||||
local u, v = nil, nil
|
||||
if proj then
|
||||
u, v = proj(stop[2], stop[3], stop[4])
|
||||
end
|
||||
local u, v = Project(home, stop[2], stop[3], stop[4])
|
||||
if u then
|
||||
local info = C_Map.GetMapInfoAtPosition(home, u, v)
|
||||
if info and info.mapID then
|
||||
|
|
@ -192,7 +294,7 @@ local function ShowStop(map, stop)
|
|||
end
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
-- Data provider: lines on an overlay, pins for docks and map exits
|
||||
-- Data provider: lines on an overlay, pins for docks and map edges
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
local provider = CreateFromMixins(MapCanvasDataProviderMixin)
|
||||
|
|
@ -230,7 +332,7 @@ end
|
|||
|
||||
function provider:Segment(x1, y1, x2, y2, c, alpha, px)
|
||||
local scale = self:GetMap():GetCanvasScale()
|
||||
for _, spec in ipairs({ { "BORDER", px + 2, 0, 0, 0, alpha * 0.6 }, { "ARTWORK", px, c[1], c[2], c[3], alpha } }) do
|
||||
for _, spec in ipairs({ { "BORDER", px + 2, 0, 0, 0, alpha * 0.55 }, { "ARTWORK", px, c[1], c[2], c[3], alpha } }) do
|
||||
local line = self:Line(spec[1])
|
||||
line.px = spec[2]
|
||||
line:SetThickness(spec[2] / scale)
|
||||
|
|
@ -240,72 +342,32 @@ function provider:Segment(x1, y1, x2, y2, c, alpha, px)
|
|||
end
|
||||
end
|
||||
|
||||
-- pts: flat canvas-unit list {x1, y1, x2, y2, ...}
|
||||
function provider:Dashed(pts, dash, gap, W, H, c, alpha, px)
|
||||
local on, left = true, dash
|
||||
for i = 1, #pts - 3, 2 do
|
||||
local ax, ay, bx, by = pts[i], pts[i + 1], pts[i + 2], pts[i + 3]
|
||||
local dx, dy = bx - ax, by - ay
|
||||
local len = math.sqrt(dx * dx + dy * dy)
|
||||
local offscreen = (ax < 0 and bx < 0) or (ax > W and bx > W) or (ay < 0 and by < 0) or (ay > H and by > H)
|
||||
local t = 0
|
||||
while t < len do
|
||||
local step = math.min(left, len - t)
|
||||
if on and not offscreen then
|
||||
local s, e = t / len, (t + step) / len
|
||||
self:Segment(ax + dx * s, ay + dy * s, ax + dx * e, ay + dy * e, c, alpha, px)
|
||||
end
|
||||
t = t + step
|
||||
left = left - step
|
||||
if left <= 0 then
|
||||
on = not on
|
||||
left = on and dash or gap
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function provider:DrawLines()
|
||||
self:ClearLines()
|
||||
local canvas = self:GetMap():GetCanvas()
|
||||
local W, H = canvas:GetWidth(), canvas:GetHeight()
|
||||
if not W or W == 0 then
|
||||
return
|
||||
end
|
||||
local hl = self.highlight
|
||||
for _, item in ipairs(self.drawn) do
|
||||
local route = item.route
|
||||
local style = STYLE[route.kind]
|
||||
local c = Color(route)
|
||||
local hl = self.highlight
|
||||
local alpha = (hl and hl ~= route) and 0.25 or 0.95
|
||||
local px = style.width + (hl == route and 1.5 or 0)
|
||||
local parts = item.parts
|
||||
for k, part in ipairs(parts) do
|
||||
if part then
|
||||
local pts = {}
|
||||
for j = 1, #part, 2 do
|
||||
pts[j], pts[j + 1] = part[j] * W, part[j + 1] * H
|
||||
end
|
||||
if route.closed then
|
||||
pts[#pts + 1], pts[#pts + 2] = pts[1], pts[2]
|
||||
end
|
||||
self:Dashed(pts, style.dash * W, style.gap * W, W, H, c, alpha, px)
|
||||
end
|
||||
-- the jump to the next part (teleport or other continent), when both ends show here
|
||||
local nextPart = parts[k % #parts + 1]
|
||||
if not route.closed and part and nextPart then
|
||||
local jump = { part[#part - 1] * W, part[#part] * H, nextPart[1] * W, nextPart[2] * H }
|
||||
self:Dashed(jump, STYLE.jump.dash * W, STYLE.jump.gap * W, W, H, c, alpha * 0.8, px * 0.8)
|
||||
local alpha = (hl and not hl[route]) and DIMMED or style.alpha
|
||||
local px = style.width + ((hl and hl[route]) and 1.5 or 0)
|
||||
local pts = item.pts
|
||||
for i = 1, #pts - 3, 2 do
|
||||
local ax, ay, bx, by = pts[i], pts[i + 1], pts[i + 2], pts[i + 3]
|
||||
local offscreen = (ax < 0 and bx < 0) or (ax > W and bx > W) or (ay < 0 and by < 0) or (ay > H and by > H)
|
||||
if not offscreen then
|
||||
self:Segment(ax, ay, bx, by, c, alpha, px)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function provider:SetHighlight(route)
|
||||
if self.highlight ~= route then
|
||||
self.highlight = route
|
||||
self:DrawLines()
|
||||
end
|
||||
-- routes: a set of routes to light up, or nil
|
||||
function provider:SetHighlight(routes)
|
||||
self.highlight = routes
|
||||
self:DrawLines()
|
||||
end
|
||||
|
||||
function provider:RemoveAllData()
|
||||
|
|
@ -322,57 +384,88 @@ function provider:RefreshAllData()
|
|||
end
|
||||
local map = self:GetMap()
|
||||
local mapID = map:GetMapID()
|
||||
local proj = mapID and GetProjector(mapID)
|
||||
if not proj then
|
||||
if not mapID then
|
||||
return
|
||||
end
|
||||
self.overlay:SetFrameLevel(map:GetPinFrameLevelsManager():GetValidFrameLevel("PIN_FRAME_LEVEL_MAP_HIGHLIGHT"))
|
||||
local canvas = map:GetCanvas()
|
||||
local W, H = canvas:GetWidth(), canvas:GetHeight()
|
||||
if not W or W == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local exits = {}
|
||||
for _, route in ipairs(ns.routes) do
|
||||
if Visible(route) then
|
||||
local item = { route = route, parts = {} }
|
||||
local any = false
|
||||
for k, part in ipairs(route.parts) do
|
||||
local out = false
|
||||
if proj(part.m, part[1], part[2]) then
|
||||
out = {}
|
||||
for j = 1, #part, 2 do
|
||||
out[j], out[j + 1] = proj(part.m, part[j], part[j + 1])
|
||||
end
|
||||
any = true
|
||||
end
|
||||
item.parts[k] = out
|
||||
end
|
||||
if any then
|
||||
self.drawn[#self.drawn + 1] = item
|
||||
end
|
||||
|
||||
for i, stop in ipairs(route.stops) do
|
||||
local u, v = proj(stop[2], stop[3], stop[4])
|
||||
local u, v = Project(mapID, stop[2], stop[3], stop[4])
|
||||
if Inside(u, v) then
|
||||
map:AcquirePin(TEMPLATE, "dock", route, i):SetPosition(u, v)
|
||||
end
|
||||
end
|
||||
|
||||
-- an arrow where the route leaves this map for somewhere it doesn't show
|
||||
if not route.closed then
|
||||
local parts = item.parts
|
||||
for k, part in ipairs(parts) do
|
||||
local n = part and #part or 0
|
||||
if n >= 4 and not parts[k % #parts + 1] and route.parts[k].next then
|
||||
local u, v = part[n - 1], part[n]
|
||||
if Inside(u, v) then
|
||||
local dx, dy = (u - part[n - 3]) * W, (v - part[n - 2]) * H
|
||||
local angle = math.atan2(-dy, dx)
|
||||
map:AcquirePin(TEMPLATE, "exit", route, route.parts[k].next, angle):SetPosition(u, v)
|
||||
for _, leg in ipairs(route.legs) do
|
||||
local pts, ok = {}, true
|
||||
for j = 1, #leg, 3 do
|
||||
local u, v = Project(mapID, leg[j], leg[j + 1], leg[j + 2])
|
||||
if not u then
|
||||
ok = false
|
||||
break
|
||||
end
|
||||
pts[#pts + 1], pts[#pts + 2] = u * W, v * H
|
||||
end
|
||||
if ok and #pts >= 4 then
|
||||
if leg.smooth then
|
||||
pts = Smooth(pts)
|
||||
end
|
||||
self.drawn[#self.drawn + 1] = { route = route, pts = pts }
|
||||
|
||||
-- a leg with one end on this map gets a marker where it leaves
|
||||
local n = #pts
|
||||
local startIn = Inside(pts[1] / W, pts[2] / H)
|
||||
local endIn = Inside(pts[n - 1] / W, pts[n] / H)
|
||||
if startIn ~= endIn then
|
||||
local walk, far = pts, leg.to
|
||||
if endIn then
|
||||
walk, far = {}, leg.from
|
||||
for j = n - 1, 1, -2 do
|
||||
walk[#walk + 1], walk[#walk + 2] = pts[j], pts[j + 1]
|
||||
end
|
||||
end
|
||||
local x, y, angle, edge = ExitPoint(walk, W, H)
|
||||
if x then
|
||||
exits[#exits + 1] = { route = route, leg = leg, far = far, x = x, y = y, angle = angle, edge = edge }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- merge markers that leave at about the same place, then place them inside the border
|
||||
local groups = {}
|
||||
for _, e in ipairs(exits) do
|
||||
local into
|
||||
for _, g in ipairs(groups) do
|
||||
local dx, dy = e.x - g[1].x, e.y - g[1].y
|
||||
if dx * dx + dy * dy <= (EXIT_MERGE * W) ^ 2 then
|
||||
into = g
|
||||
break
|
||||
end
|
||||
end
|
||||
if into then
|
||||
into[#into + 1] = e
|
||||
else
|
||||
groups[#groups + 1] = { e }
|
||||
end
|
||||
end
|
||||
local inset = EXIT_INSET
|
||||
for _, g in ipairs(groups) do
|
||||
local u = math.max(inset, math.min(1 - inset, g[1].x / W))
|
||||
local v = math.max(inset, math.min(1 - inset, g[1].y / H))
|
||||
map:AcquirePin(TEMPLATE, "exit", g):SetPosition(u, v)
|
||||
end
|
||||
|
||||
self:DrawLines()
|
||||
end
|
||||
|
||||
|
|
@ -398,27 +491,67 @@ ShipRoutesPinMixin = CreateFromMixins(MapCanvasPinMixin)
|
|||
function ShipRoutesPinMixin:OnLoad()
|
||||
self:UseFrameLevelType("PIN_FRAME_LEVEL_AREA_POI")
|
||||
self:SetScalingLimits(1, 1.0, 1.25)
|
||||
local font, size = self.Label:GetFont()
|
||||
if font then
|
||||
self.Label:SetFont(font, size, "OUTLINE")
|
||||
end
|
||||
end
|
||||
|
||||
function ShipRoutesPinMixin:OnAcquired(kind, route, index, angle)
|
||||
self.kind, self.route, self.index = kind, route, index
|
||||
local c = Color(route)
|
||||
local exit = kind == "exit"
|
||||
self:SetSize(exit and 15 or 20, exit and 15 or 20)
|
||||
self.Disc:SetVertexColor(0.06, 0.06, 0.08, 0.9)
|
||||
self.Ring:SetVertexColor(c[1], c[2], c[3], 1)
|
||||
self.Glyph:SetTexture(exit and GLYPH.exit or GLYPH[route.kind])
|
||||
self.Glyph:SetRotation(exit and angle or 0)
|
||||
if exit then
|
||||
self.Glyph:SetVertexColor(c[1], c[2], c[3], 1)
|
||||
else
|
||||
local LABEL_ANCHOR = {
|
||||
left = { "LEFT", "RIGHT", 3, 0, "LEFT" },
|
||||
right = { "RIGHT", "LEFT", -3, 0, "RIGHT" },
|
||||
top = { "TOP", "BOTTOM", 0, -2, "CENTER" },
|
||||
bottom = { "BOTTOM", "TOP", 0, 2, "CENTER" },
|
||||
}
|
||||
|
||||
function ShipRoutesPinMixin:OnAcquired(kind, a, b)
|
||||
self.kind = kind
|
||||
self.Label:ClearAllPoints()
|
||||
if kind == "dock" then
|
||||
self.route, self.index, self.exits = a, b, nil
|
||||
local c = Color(a)
|
||||
self:SetSize(20, 20)
|
||||
self.Ring:SetVertexColor(c[1], c[2], c[3], 1)
|
||||
self.Glyph:SetTexture(GLYPH[a.kind])
|
||||
self.Glyph:SetRotation(0)
|
||||
self.Glyph:SetVertexColor(1, 1, 1, 1)
|
||||
self.Label:Hide()
|
||||
else
|
||||
local first = a[1]
|
||||
self.route, self.index, self.exits = first.route, first.far, a
|
||||
local c = Color(first.route)
|
||||
self:SetSize(16, 16)
|
||||
self.Ring:SetVertexColor(c[1], c[2], c[3], 1)
|
||||
self.Glyph:SetTexture(GLYPH.exit)
|
||||
self.Glyph:SetRotation(first.angle)
|
||||
self.Glyph:SetVertexColor(c[1], c[2], c[3], 1)
|
||||
-- one line per destination, in its route's colour
|
||||
local text, seen = {}, {}
|
||||
for _, e in ipairs(a) do
|
||||
local name = e.route.stops[e.far][1]
|
||||
local ec = Color(e.route)
|
||||
local key = name .. ec[1]
|
||||
if not seen[key] then
|
||||
seen[key] = true
|
||||
text[#text + 1] = string.format("|cff%02x%02x%02x%s|r", ec[1] * 255, ec[2] * 255, ec[3] * 255, name)
|
||||
end
|
||||
end
|
||||
local anchor = LABEL_ANCHOR[first.edge]
|
||||
self.Label:SetPoint(anchor[1], self, anchor[2], anchor[3], anchor[4])
|
||||
self.Label:SetJustifyH(anchor[5])
|
||||
self.Label:SetText(table.concat(text, "\n"))
|
||||
self.Label:Show()
|
||||
end
|
||||
self.Disc:SetVertexColor(0.06, 0.06, 0.08, 0.9)
|
||||
self:CheckMouseButtonPassthrough("RightButton")
|
||||
end
|
||||
|
||||
function ShipRoutesPinMixin:OnMouseEnter()
|
||||
provider:SetHighlight(self.route)
|
||||
local set = { [self.route] = true }
|
||||
for _, e in ipairs(self.exits or {}) do
|
||||
set[e.route] = true
|
||||
end
|
||||
provider:SetHighlight(set)
|
||||
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
|
||||
FillTooltip(GameTooltip, self)
|
||||
GameTooltip:Show()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue