diff options
Diffstat (limited to 'advtrains/trainhud.lua')
-rw-r--r-- | advtrains/trainhud.lua | 85 |
1 files changed, 53 insertions, 32 deletions
diff --git a/advtrains/trainhud.lua b/advtrains/trainhud.lua index ce4b913..eeebff0 100644 --- a/advtrains/trainhud.lua +++ b/advtrains/trainhud.lua @@ -1,5 +1,8 @@ --trainhud.lua: holds all the code for train controlling +-- Get current translator +local S = advtrains.translate + local T = advtrains.texture advtrains.hud = {} @@ -50,6 +53,10 @@ function advtrains.on_control_change(pc, train, flip) train.ctrl_user = 1 act=true end + if train.ars_disable and pc.up then + -- up clears ars disable flag in any situation + train.ars_disable = nil + end -- If atc command set, only "Jump" key can clear command. To prevent accidental control. if train.tarvelocity or train.atc_command then return @@ -229,51 +236,65 @@ 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 - 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") + 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 - 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) hud:add_n7seg(131, 18, 28, 14, lzbdisp.d, 3, lzbdisp.c) if res and res == 0 then - table.insert(st, attrans("OVERRUN RED SIGNAL! Examine situation and reverse train to move again.")) + table.insert(st, S("OVERRUN RED SIGNAL! Examine situation and reverse train to move again.")) end if train.atc_command then - table.insert(st, ("ATC: %s%s"):format(train.atc_delay and advtrains.abs_ceil(train.atc_delay).."s " or "", train.atc_command or "")) + local delay_str = "" + if train.atc_delay and train.atc_delay >= 0 then + delay_str = advtrains.abs_ceil(train.atc_delay).."s " + end + if train.atc_wait_finish then + delay_str = delay_str.."[W] " + end + if train.atc_wait_autocouple then + delay_str = delay_str.."[Cpl] " + end + if train.atc_wait_signal then + delay_str = delay_str.."[G] " + end + table.insert(st, ("ATC: %s%s"):format(delay_str, train.atc_command or "")) end return table.concat(st,"\n"), tostring(hud) |