[lua] function GetEstimatedTime and function postTaxiNodeOnButtonEnter

Viewer

copydownloadembedprintName: function GetEstimatedTime and function postTaxiNodeOnButtonEnter
  1. local function GetEstimatedTime(slot)  -- estimates flight times based on hops
  2.         local etime, numnodes = 0, NumTaxiNodes()
  3.         for hop = 1, GetNumRoutes(slot), 1 do
  4.                 local s, sx, sy = nil, floor(100 * TaxiGetSrcX(slot, hop)), floor(100 * TaxiGetSrcY(slot, hop))
  5.                 local d, dx, dy = nil, floor(100 * TaxiGetDestX(slot, hop)), floor(100 * TaxiGetDestY(slot, hop))
  6.                 for i = 1, numnodes, 1 do
  7.                         local ix, iy = TaxiNodePosition(i)
  8.                         ix, iy = floor(100 * ix), floor(100 * iy)
  9.                         if not s and sx == ix and sy == iy then
  10.                                 s = ShortenName(FixTypos(TaxiNodeName(i)))  --ShortenName(TaxiNodeName(i))
  11.                         end
  12.                         if not d and dx == ix and dy == iy then
  13.                                 d = ShortenName(FixTypos(TaxiNodeName(i)))  --ShortenName(TaxiNodeName(i))
  14.                         end
  15.                         if s and d then break end
  16.                 end
  17.                 if s and d and vars[s] and vars[s][d] then
  18.                         etime = etime + vars[s][d]
  19.                 else
  20.                         return nil
  21.                 end
  22.         end
  23.         return etime
  24. end
  25. local function postTaxiNodeOnButtonEnter(button) -- adds duration info to node tooltips
  26.         local id = button:GetID()
  27.         GameTooltipTextLeft1:SetText(FixTypos(TaxiNodeName(id)))
  28.         if TaxiNodeGetType(id) ~= "REACHABLE" then
  29.                 return
  30.         end
  31.         local ftime = (vars[source] and vars[source][ ShortenName(FixTypos(TaxiNodeName(id))) ])  --ShortenName(TaxiNodeName(id))
  32.         or GetEstimatedTime(id) or 0
  33.         if ftime > 0 then
  34.                 gtt:AddLine(L_duration..FormatTime(ftime), 1, 1, 1)
  35.         else
  36.                 gtt:AddLine(L_duration.."-:--", 0.8, 0.8, 0.8)
  37.         end
  38.         gtt:Show()
  39. end

Editor

You can edit this paste and save as new:


File Description
  • function GetEstimatedTime and function postTaxiNodeOnButtonEnter
  • Paste Code
  • 02 Sep-2022
  • 1.42 Kb
You can Share it: