aboutsummaryrefslogtreecommitdiff
path: root/advtrains/trainhud.lua
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains/trainhud.lua')
-rw-r--r--advtrains/trainhud.lua74
1 files changed, 65 insertions, 9 deletions
diff --git a/advtrains/trainhud.lua b/advtrains/trainhud.lua
index 78c7624..9b7b9e8 100644
--- a/advtrains/trainhud.lua
+++ b/advtrains/trainhud.lua
@@ -1,9 +1,11 @@
--trainhud.lua: holds all the code for train controlling
advtrains.hud = {}
+advtrains.hhud = {}
minetest.register_on_leaveplayer(function(player)
advtrains.hud[player:get_player_name()] = nil
+advtrains.hhud[player:get_player_name()] = nil
end)
local mletter={[1]="F", [-1]="R", [0]="N"}
@@ -40,12 +42,23 @@ function advtrains.on_control_change(pc, train, flip)
end
--shift+use:see wagons.lua
else
+ local act=false
if pc.up then
- train.tarvelocity = math.min(train.tarvelocity + 1, maxspeed)
+ train.lever=4
+ act=true
+ end
+ if pc.jump then
+ train.lever = 1
+ act=true
end
if pc.down then
if train.velocity>0 then
- train.tarvelocity = math.max(train.tarvelocity - 1, 0)
+ if pc.jump then
+ train.lever = 0
+ else
+ train.lever = 2
+ end
+ act=true
else
train.movedir = -train.movedir
end
@@ -64,12 +77,7 @@ function advtrains.on_control_change(pc, train, flip)
train.door_open = train.movedir
end
end
- if train.brake_hold_state~=2 then
- train.brake = false
- end
- if pc.jump then
- train.brake = true
- end
+ train.active_control = act
if pc.aux1 then
--horn
end
@@ -109,6 +117,44 @@ function advtrains.set_trainhud(name, text)
hud.oldText=text
end
end
+function advtrains.set_help_hud(name, text)
+ local hud = advtrains.hhud[name]
+ local player=minetest.get_player_by_name(name)
+ if not player then
+ return
+ end
+ if not hud then
+ hud = {}
+ advtrains.hhud[name] = hud
+ hud.id = player:hud_add({
+ hud_elem_type = "text",
+ name = "ADVTRAINS_HELP",
+ number = 0xFFFFFF,
+ position = {x=1, y=0.3},
+ offset = {x=0, y=0},
+ text = text,
+ scale = {x=200, y=60},
+ alignment = {x=1, y=0},
+ })
+ hud.oldText=text
+ return
+ elseif hud.oldText ~= text then
+ player:hud_change(hud.id, "text", text)
+ hud.oldText=text
+ end
+end
+
+--train.lever:
+--Speed control lever in train, for new train control system.
+--[[
+Value Disp Control Meaning
+0 BB S+Space Emergency Brake
+1 B Space Normal Brake
+2 - S Roll
+3 o <none> Stay at speed
+4 + W Accelerate
+]]
+
function advtrains.hud_train_format(train, flip)
local fct=flip and -1 or 1
if not train then return "" end
@@ -118,9 +164,19 @@ function advtrains.hud_train_format(train, flip)
local tvel=advtrains.abs_ceil(train.tarvelocity)
local vel_kmh=advtrains.abs_ceil(advtrains.ms_to_kmh(train.velocity))
local tvel_kmh=advtrains.abs_ceil(advtrains.ms_to_kmh(train.tarvelocity))
+
+ local levers = "B - o +"
+ local tlev=train.lever
+ if train.velocity==0 and not train.active_control then tlev=1 end
+ if tlev == 0 then levers = ">BB< - o +" end
+ if tlev == 1 then levers = ">B< - o +" end
+ if tlev == 2 then levers = "B >-< o +" end
+ if tlev == 3 then levers = "B - >o< +" end
+ if tlev == 4 then levers = "B - o >+<" end
+
local topLine, firstLine, secondLine
- topLine=" ["..mletter[fct*train.movedir].."] "..doorstr[(train.door_open or 0) * train.movedir].." "..(train.brake and "="..( train.brake_hold_state==2 and "^" or "" ).."B=" or "")
+ topLine=" ["..mletter[fct*train.movedir].."] {"..levers.."} "..doorstr[(train.door_open or 0) * train.movedir]
firstLine=attrans("Speed:").." |"..string.rep("+", vel)..string.rep("_", max-vel).."> "..vel_kmh.." km/h"
secondLine=attrans("Target:").." |"..string.rep("+", tvel)..string.rep("_", max-tvel).."> "..tvel_kmh.." km/h"