diff options
author | Y. Wang <y5nw@protonmail.com> | 2025-01-20 15:33:01 +0100 |
---|---|---|
committer | orwell <orwell@bleipb.de> | 2025-01-28 22:32:14 +0100 |
commit | 48f2950cd3aa3174d3193c3db00498fd3d43c6b4 (patch) | |
tree | 882be17d1791c948e9c60daad7cbd5b0833d9017 /advtrains/trainhud.lua | |
parent | a212310913c33fb855ca0f262beda6d857382ff8 (diff) | |
download | advtrains-48f2950cd3aa3174d3193c3db00498fd3d43c6b4.tar.gz advtrains-48f2950cd3aa3174d3193c3db00498fd3d43c6b4.tar.bz2 advtrains-48f2950cd3aa3174d3193c3db00498fd3d43c6b4.zip |
Adjust HUD code
Diffstat (limited to 'advtrains/trainhud.lua')
-rw-r--r-- | advtrains/trainhud.lua | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/advtrains/trainhud.lua b/advtrains/trainhud.lua index b1e2036..9d9d475 100644 --- a/advtrains/trainhud.lua +++ b/advtrains/trainhud.lua @@ -233,40 +233,41 @@ function advtrains.hud_train_format(train, flip) if train.tarvelocity then hud:add(1+train.tarvelocity*11, 85, T"advtrains_hud_arrow.png":transform"FY":multiply"cyan") end - local lzbdisp local lzb = train.lzb - if lzb and lzb.checkpoints then - local oc = lzb.checkpoints - for i = 1, #oc do - if advtrains.interlocking then - local udata = oc[i].udata - if udata and udata.signal_pos then - local sigd = advtrains.interlocking.db.get_sigd_for_signal(udata.signal_pos) - if sigd then - local tcbs = advtrains.interlocking.db.get_tcbs(sigd) or {} - if tcbs.route_rsn then - table.insert(st, ("%s: %s"):format(minetest.pos_to_string(sigd.p), tcbs.route_rsn)) - end - end + local lzbdisp = {c = "darkslategray", d = 888} + if lzb and lzb.checkpoints and lzb.checkpoints[1] then + local cp = lzb.checkpoints[1] + if advtrains.interlocking and cp.udata and cp.udata.signal_pos then + local sigd = advtrains.interlocking.db.get_sigd_for_signal(cp.udata.signal_pos) + if sigd then + local tcbs = advtrains.interlocking.db.get_tcbs(sigd) or {} + if tcbs.route_rsn then + table.insert(st, ("%s: %s"):format(minetest.pos_to_string(sigd.p), tcbs.route_rsn)) end end - local spd = oc[i].speed - spd = advtrains.speed.min(spd, train.speed_restriction) - if spd == -1 then spd = nil end - local c = not spd and "lime" or (type(spd) == "number" and (spd == 0) and "red" or "orange") or nil - if c then - if spd and spd~=0 then - hud:add(1+spd*11, 50, T"advtrains_hud_arrow.png":multiply"red") - end - local dist = math.floor(((oc[i].index or train.index)-train.index)) - dist = math.max(0, math.min(999, dist)) - lzbdisp = {c = c, d = dist} - break - end end - end - if not lzbdisp then - lzbdisp = {c = "darkslategray", d = 888} + local spd = cp.speed + local c, arrow + if not spd or spd == -1 then + c = "lime" + elseif spd == 0 then + c = "red" + elseif not res or spd <= res then + c = "orange" + arrow = true + elseif spd <= max then + c = "yellow" + arrow = true + else + c = "cyan" + arrow = true + end + if arrow then + hud:add(1+spd*11, 50, T"advtrains_hud_arrow.png":multiply"red") + end + local dist = math.floor(((cp.index or train.index)-train.index)) + dist = math.max(0, math.min(999, dist)) + lzbdisp = {c = c, d = dist} end hud:add_fill(130, 10, 30, 5, lzbdisp.c) hud:add_fill(130, 35, 30, 5, lzbdisp.c) |