From d6acadf018c54d4a41c9f4d854b82f7f4cf099bc Mon Sep 17 00:00:00 2001 From: ywang Date: Sat, 19 Dec 2020 18:15:02 +0100 Subject: Use PNG textures for the indication of reverser, lever, control mode, shunt mode, and doors --- advtrains/textures/advtrains_hud_atc.png | Bin 0 -> 369 bytes advtrains/textures/advtrains_hud_b1.png | Bin 0 -> 256 bytes advtrains/textures/advtrains_hud_b2.png | Bin 0 -> 309 bytes advtrains/textures/advtrains_hud_blank.png | Bin 0 -> 81 bytes advtrains/textures/advtrains_hud_blue.png | Bin 0 -> 83 bytes advtrains/textures/advtrains_hud_emg.png | Bin 0 -> 441 bytes advtrains/textures/advtrains_hud_f.png | Bin 0 -> 139 bytes advtrains/textures/advtrains_hud_gray.png | Bin 0 -> 82 bytes advtrains/textures/advtrains_hud_l_right.png | Bin 0 -> 119 bytes advtrains/textures/advtrains_hud_lzb.png | Bin 0 -> 329 bytes advtrains/textures/advtrains_hud_man.png | Bin 0 -> 416 bytes advtrains/textures/advtrains_hud_n.png | Bin 0 -> 204 bytes advtrains/textures/advtrains_hud_na.png | Bin 0 -> 329 bytes advtrains/textures/advtrains_hud_orange.png | Bin 0 -> 83 bytes advtrains/textures/advtrains_hud_p.png | Bin 0 -> 193 bytes advtrains/textures/advtrains_hud_r.png | Bin 0 -> 206 bytes advtrains/textures/advtrains_hud_red.png | Bin 0 -> 83 bytes advtrains/textures/advtrains_hud_shunt.png | Bin 0 -> 440 bytes advtrains/trainhud.lua | 67 +++++++++++++++++---------- 19 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 advtrains/textures/advtrains_hud_atc.png create mode 100644 advtrains/textures/advtrains_hud_b1.png create mode 100644 advtrains/textures/advtrains_hud_b2.png create mode 100644 advtrains/textures/advtrains_hud_blank.png create mode 100644 advtrains/textures/advtrains_hud_blue.png create mode 100644 advtrains/textures/advtrains_hud_emg.png create mode 100644 advtrains/textures/advtrains_hud_f.png create mode 100644 advtrains/textures/advtrains_hud_gray.png create mode 100644 advtrains/textures/advtrains_hud_l_right.png create mode 100644 advtrains/textures/advtrains_hud_lzb.png create mode 100644 advtrains/textures/advtrains_hud_man.png create mode 100644 advtrains/textures/advtrains_hud_n.png create mode 100644 advtrains/textures/advtrains_hud_na.png create mode 100644 advtrains/textures/advtrains_hud_orange.png create mode 100644 advtrains/textures/advtrains_hud_p.png create mode 100644 advtrains/textures/advtrains_hud_r.png create mode 100644 advtrains/textures/advtrains_hud_red.png create mode 100644 advtrains/textures/advtrains_hud_shunt.png diff --git a/advtrains/textures/advtrains_hud_atc.png b/advtrains/textures/advtrains_hud_atc.png new file mode 100644 index 0000000..e46f9bb Binary files /dev/null and b/advtrains/textures/advtrains_hud_atc.png differ diff --git a/advtrains/textures/advtrains_hud_b1.png b/advtrains/textures/advtrains_hud_b1.png new file mode 100644 index 0000000..50fe46e Binary files /dev/null and b/advtrains/textures/advtrains_hud_b1.png differ diff --git a/advtrains/textures/advtrains_hud_b2.png b/advtrains/textures/advtrains_hud_b2.png new file mode 100644 index 0000000..6aa91bf Binary files /dev/null and b/advtrains/textures/advtrains_hud_b2.png differ diff --git a/advtrains/textures/advtrains_hud_blank.png b/advtrains/textures/advtrains_hud_blank.png new file mode 100644 index 0000000..26b59e7 Binary files /dev/null and b/advtrains/textures/advtrains_hud_blank.png differ diff --git a/advtrains/textures/advtrains_hud_blue.png b/advtrains/textures/advtrains_hud_blue.png new file mode 100644 index 0000000..9fbc572 Binary files /dev/null and b/advtrains/textures/advtrains_hud_blue.png differ diff --git a/advtrains/textures/advtrains_hud_emg.png b/advtrains/textures/advtrains_hud_emg.png new file mode 100644 index 0000000..1633caa Binary files /dev/null and b/advtrains/textures/advtrains_hud_emg.png differ diff --git a/advtrains/textures/advtrains_hud_f.png b/advtrains/textures/advtrains_hud_f.png new file mode 100644 index 0000000..2ca5d0a Binary files /dev/null and b/advtrains/textures/advtrains_hud_f.png differ diff --git a/advtrains/textures/advtrains_hud_gray.png b/advtrains/textures/advtrains_hud_gray.png new file mode 100644 index 0000000..96e0535 Binary files /dev/null and b/advtrains/textures/advtrains_hud_gray.png differ diff --git a/advtrains/textures/advtrains_hud_l_right.png b/advtrains/textures/advtrains_hud_l_right.png new file mode 100644 index 0000000..70d51db Binary files /dev/null and b/advtrains/textures/advtrains_hud_l_right.png differ diff --git a/advtrains/textures/advtrains_hud_lzb.png b/advtrains/textures/advtrains_hud_lzb.png new file mode 100644 index 0000000..d74b1ed Binary files /dev/null and b/advtrains/textures/advtrains_hud_lzb.png differ diff --git a/advtrains/textures/advtrains_hud_man.png b/advtrains/textures/advtrains_hud_man.png new file mode 100644 index 0000000..9c1f906 Binary files /dev/null and b/advtrains/textures/advtrains_hud_man.png differ diff --git a/advtrains/textures/advtrains_hud_n.png b/advtrains/textures/advtrains_hud_n.png new file mode 100644 index 0000000..bdf26f1 Binary files /dev/null and b/advtrains/textures/advtrains_hud_n.png differ diff --git a/advtrains/textures/advtrains_hud_na.png b/advtrains/textures/advtrains_hud_na.png new file mode 100644 index 0000000..b4a53ee Binary files /dev/null and b/advtrains/textures/advtrains_hud_na.png differ diff --git a/advtrains/textures/advtrains_hud_orange.png b/advtrains/textures/advtrains_hud_orange.png new file mode 100644 index 0000000..1d62d51 Binary files /dev/null and b/advtrains/textures/advtrains_hud_orange.png differ diff --git a/advtrains/textures/advtrains_hud_p.png b/advtrains/textures/advtrains_hud_p.png new file mode 100644 index 0000000..8ef4f46 Binary files /dev/null and b/advtrains/textures/advtrains_hud_p.png differ diff --git a/advtrains/textures/advtrains_hud_r.png b/advtrains/textures/advtrains_hud_r.png new file mode 100644 index 0000000..edd11df Binary files /dev/null and b/advtrains/textures/advtrains_hud_r.png differ diff --git a/advtrains/textures/advtrains_hud_red.png b/advtrains/textures/advtrains_hud_red.png new file mode 100644 index 0000000..983ce1f Binary files /dev/null and b/advtrains/textures/advtrains_hud_red.png differ diff --git a/advtrains/textures/advtrains_hud_shunt.png b/advtrains/textures/advtrains_hud_shunt.png new file mode 100644 index 0000000..e01a91a Binary files /dev/null and b/advtrains/textures/advtrains_hud_shunt.png differ diff --git a/advtrains/trainhud.lua b/advtrains/trainhud.lua index 14f68af..2471225 100644 --- a/advtrains/trainhud.lua +++ b/advtrains/trainhud.lua @@ -88,38 +88,55 @@ function advtrains.on_control_change(pc, train, flip) end function advtrains.update_driver_hud(pname, train, flip) local inside=train.text_inside or "" - advtrains.set_trainhud(pname, inside.."\n"..advtrains.hud_train_format(train, flip)) + local ft, ht = advtrains.hud_train_format(train, flip) + advtrains.set_trainhud(pname, inside.."\n"..ft, ht) end function advtrains.clear_driver_hud(pname) advtrains.set_trainhud(pname, "") end -function advtrains.set_trainhud(name, text) +function advtrains.set_trainhud(name, text, driver) local hud = advtrains.hud[name] local player=minetest.get_player_by_name(name) if not player then return end + local driverhud = { + hud_elem_type = "image", + name = "ADVTRAINS_DRIVER", + position = {x=0.5, y=0.7}, + offset = {x=0,y=5}, + text = driver or "advtrains_hud_blank.png", + alignment = {x=0,y=1}, + scale = {x=1,y=1},} if not hud then - hud = {} + hud = {["driver"]={}} advtrains.hud[name] = hud hud.id = player:hud_add({ hud_elem_type = "text", name = "ADVTRAINS", number = 0xFFFFFF, position = {x=0.5, y=0.7}, - offset = {x=0, y=0}, + offset = {x=0, y=-5}, text = text, scale = {x=200, y=60}, - alignment = {x=0, y=0}, + alignment = {x=0, y=-1}, }) hud.oldText=text - return - elseif hud.oldText ~= text then - player:hud_change(hud.id, "text", text) - hud.oldText=text + hud.driver = player:hud_add(driverhud) + else + if hud.oldText ~= text then + player:hud_change(hud.id, "text", text) + hud.oldText=text + end + if hud.driver then + player:hud_change(hud.driver, "text", driver or "advtrains_hud_blank.png") + elseif driver then + hud.driver = player:hud_add(driverhud) + end end end + function advtrains.set_help_hud(name, text) local hud = advtrains.hhud[name] local player=minetest.get_player_by_name(name) @@ -159,7 +176,6 @@ Value Disp Control Meaning ]] function advtrains.hud_train_format(train, flip) - local fct=flip and -1 or 1 if not train then return "" end local max = train.max_speed or 10 @@ -167,25 +183,27 @@ function advtrains.hud_train_format(train, flip) local vel = advtrains.abs_ceil(train.velocity) local vel_kmh=advtrains.abs_ceil(advtrains.ms_to_kmh(train.velocity)) - local levers = {[0] = "EMG", "B 2", "B 1", " N ", " P "} + local levers = { + [0] = "advtrains_hud_red.png^advtrains_hud_emg.png", + "advtrains_hud_orange.png^advtrains_hud_b2.png", + "advtrains_hud_orange.png^advtrains_hud_b1.png", + "advtrains_hud_gray.png^advtrains_hud_n.png", + "advtrains_hud_blue.png^advtrains_hud_p.png"} local tlev=train.lever if train.velocity==0 and not train.active_control then tlev=1 end - local doorstr = function(side, open) - return (open and "<%s>" or ">%s<"):format(side) - end - - local topLine, firstLine local st = {} if train.debug then st = {train.debug} end - st[#st+1] = ("[%s] [%s] [%s %s]%s [%s]"):format( - mletter[fct], - levers[tlev] or "N/A", - doorstr("L", train.door_open==-1), - doorstr("R", train.door_open==1), - train.is_shunt and " [SHUNT]" or "", - (train.tarvelocity or train.atc_command) and "ATC" or (train.ctrl.lzb and "LZB" or "MAN")) + local ht = ("[combine:100x66:0,0=(%s):50,0=(%s):0,22=(%s):50,22=(%s):0,44=(%s):50,44=(%s)"):format( + ("advtrains_hud_blue.png^advtrains_hud_%s.png"):format(flip and "r" or "f"), + levers[tlev or 32767] or "advtrains_hud_gray.png^advtrains_hud_na.png", + (train.tarvelocity or train.atc_command) + and "advtrains_hud_blue.png^advtrains_hud_atc.png" + or (train.ctrl.lzb and "advtrains_hud_red.png^advtrains_hud_lzb.png" or "advtrains_hud_gray.png^advtrains_hud_man.png"), + train.is_shunt and "advtrains_hud_orange.png^advtrains_hud_shunt.png" or "advtrains_hud_gray.png^advtrains_hud_shunt.png", + train.door_open == -1 and "advtrains_hud_blue.png^advtrains_hud_l_right.png" or "advtrains_hud_gray.png^advtrains_hud_l_right.png", + train.door_open == 1 and "advtrains_hud_blue.png^advtrains_hud_r.png" or "advtrains_hud_gray.png^advtrains_hud_r.png") local velstr = function(vel, name) return ("%s%02d m/s (%02d km/h)"):format( @@ -215,7 +233,6 @@ function advtrains.hud_train_format(train, flip) end i=i+1 end - - return table.concat(st,"\n") + return table.concat(st,"\n"), ht end -- cgit v1.2.3