From ef21e70479d31973e47988a2246870ddc429226a Mon Sep 17 00:00:00 2001 From: ywang Date: Sun, 10 Jan 2021 11:40:03 +0100 Subject: Use graphical indication for more elements; improve 7-segment display --- advtrains/textures/advtrains_hud_arrow.png | Bin 92 -> 91 bytes advtrains/textures/advtrains_hud_atc.png | Bin 714 -> 528 bytes advtrains/textures/advtrains_hud_b.png | Bin 355 -> 0 bytes advtrains/textures/advtrains_hud_emg.png | Bin 718 -> 0 bytes advtrains/textures/advtrains_hud_forward.png | Bin 1147 -> 0 bytes advtrains/textures/advtrains_hud_left_door.png | Bin 1032 -> 0 bytes advtrains/textures/advtrains_hud_lzb.png | Bin 618 -> 398 bytes advtrains/textures/advtrains_hud_n.png | Bin 376 -> 0 bytes advtrains/textures/advtrains_hud_p.png | Bin 274 -> 0 bytes advtrains/textures/advtrains_hud_r.png | Bin 322 -> 0 bytes advtrains/textures/advtrains_hud_reverse.png | Bin 1256 -> 0 bytes advtrains/textures/advtrains_hud_right_door.png | Bin 1295 -> 0 bytes advtrains/textures/advtrains_hud_shunt.png | Bin 793 -> 476 bytes advtrains/trainhud.lua | 89 ++++++++++++++---------- 14 files changed, 54 insertions(+), 35 deletions(-) delete mode 100644 advtrains/textures/advtrains_hud_b.png delete mode 100644 advtrains/textures/advtrains_hud_emg.png delete mode 100644 advtrains/textures/advtrains_hud_forward.png delete mode 100644 advtrains/textures/advtrains_hud_left_door.png delete mode 100644 advtrains/textures/advtrains_hud_n.png delete mode 100644 advtrains/textures/advtrains_hud_p.png delete mode 100644 advtrains/textures/advtrains_hud_r.png delete mode 100644 advtrains/textures/advtrains_hud_reverse.png delete mode 100644 advtrains/textures/advtrains_hud_right_door.png diff --git a/advtrains/textures/advtrains_hud_arrow.png b/advtrains/textures/advtrains_hud_arrow.png index 51f5b42..71d75b0 100644 Binary files a/advtrains/textures/advtrains_hud_arrow.png and b/advtrains/textures/advtrains_hud_arrow.png differ diff --git a/advtrains/textures/advtrains_hud_atc.png b/advtrains/textures/advtrains_hud_atc.png index 06c6c1c..e033653 100644 Binary files a/advtrains/textures/advtrains_hud_atc.png and b/advtrains/textures/advtrains_hud_atc.png differ diff --git a/advtrains/textures/advtrains_hud_b.png b/advtrains/textures/advtrains_hud_b.png deleted file mode 100644 index 64908a7..0000000 Binary files a/advtrains/textures/advtrains_hud_b.png and /dev/null differ diff --git a/advtrains/textures/advtrains_hud_emg.png b/advtrains/textures/advtrains_hud_emg.png deleted file mode 100644 index 5739883..0000000 Binary files a/advtrains/textures/advtrains_hud_emg.png and /dev/null differ diff --git a/advtrains/textures/advtrains_hud_forward.png b/advtrains/textures/advtrains_hud_forward.png deleted file mode 100644 index 0f12090..0000000 Binary files a/advtrains/textures/advtrains_hud_forward.png and /dev/null differ diff --git a/advtrains/textures/advtrains_hud_left_door.png b/advtrains/textures/advtrains_hud_left_door.png deleted file mode 100644 index 51b2447..0000000 Binary files a/advtrains/textures/advtrains_hud_left_door.png and /dev/null differ diff --git a/advtrains/textures/advtrains_hud_lzb.png b/advtrains/textures/advtrains_hud_lzb.png index 950de64..e1b5f70 100644 Binary files a/advtrains/textures/advtrains_hud_lzb.png and b/advtrains/textures/advtrains_hud_lzb.png differ diff --git a/advtrains/textures/advtrains_hud_n.png b/advtrains/textures/advtrains_hud_n.png deleted file mode 100644 index bd05f12..0000000 Binary files a/advtrains/textures/advtrains_hud_n.png and /dev/null differ diff --git a/advtrains/textures/advtrains_hud_p.png b/advtrains/textures/advtrains_hud_p.png deleted file mode 100644 index f853b78..0000000 Binary files a/advtrains/textures/advtrains_hud_p.png and /dev/null differ diff --git a/advtrains/textures/advtrains_hud_r.png b/advtrains/textures/advtrains_hud_r.png deleted file mode 100644 index b357cab..0000000 Binary files a/advtrains/textures/advtrains_hud_r.png and /dev/null differ diff --git a/advtrains/textures/advtrains_hud_reverse.png b/advtrains/textures/advtrains_hud_reverse.png deleted file mode 100644 index 1e2a6f8..0000000 Binary files a/advtrains/textures/advtrains_hud_reverse.png and /dev/null differ diff --git a/advtrains/textures/advtrains_hud_right_door.png b/advtrains/textures/advtrains_hud_right_door.png deleted file mode 100644 index 2c0293a..0000000 Binary files a/advtrains/textures/advtrains_hud_right_door.png and /dev/null differ diff --git a/advtrains/textures/advtrains_hud_shunt.png b/advtrains/textures/advtrains_hud_shunt.png index 6517e42..f4d27a5 100644 Binary files a/advtrains/textures/advtrains_hud_shunt.png and b/advtrains/textures/advtrains_hud_shunt.png differ diff --git a/advtrains/trainhud.lua b/advtrains/trainhud.lua index ab08b83..db32824 100644 --- a/advtrains/trainhud.lua +++ b/advtrains/trainhud.lua @@ -184,32 +184,14 @@ 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","r","n","p"} - local lvrcolor = {[0] = "red", "orange", "orange", "cyan", "cyan"} local tlev=train.lever or 1 if train.velocity==0 and not train.active_control then tlev=1 end + local ht = {"[combine:440x110:0,0=(advtrains_hud_bg.png^[resize\\:440x110)"} local st = {} if train.debug then st = {train.debug} end - local ht = {"[combine:300x150:0,0=(advtrains_hud_bg.png^[resize\\:300x150)"} - ht[#ht+1] = "100,0=(advtrains_hud_" .. (flip and "reverse" or "forward") .. ".png^[resize\\:100x20^[makealpha\\:#000000)" - ht[#ht+1] = "200,0=(advtrains_hud_" .. (levers[tlev] or "bg") .. ".png^[resize\\:100x20^[multiply\\:" .. (lvrcolor[tlev] or "#000000") .. "^[makealpha\\:#000000)" - if train.tarvelocity or train.atc_command then - ht[#ht+1] = "100,20=(advtrains_hud_atc.png^[resize\\:100x20^[makealpha\\:#000000)" - end - if train.ctrl.lzb then - ht[#ht+1] = "200,20=(advtrains_hud_lzb.png^[resize\\:100x20^[multiply\\:red^[makealpha\\:#000000)" - end - if train.is_shunt then - ht[#ht+1] = "100,40=(advtrains_hud_shunt.png^[resize\\:100x20^[makealpha\\:#000000)" - end - if train.door_open == -1 then - ht[#ht+1] = "100,60=(advtrains_hud_left_door.png^[resize\\:100x20^[makealpha\\:#000000)" - elseif train.door_open == 1 then - ht[#ht+1] = "200,60=(advtrains_hud_right_door.png^[resize\\:100x24^[makealpha\\:#000000)" - end - -- speed indication(s) + -- seven-segment display local function sevenseg(digit, x, y, w, h, m) --[[ -1- @@ -246,34 +228,71 @@ function advtrains.hud_train_format(train, flip) end end end - sevenseg(math.floor(vel/10), 5, 5, 20, 10, "[colorize\\:red\\:255") - sevenseg(vel%10, 55, 5, 20, 10, "[colorize\\:red\\:255") + + -- lever + ht[#ht+1] = "275,10=(advtrains_hud_bg.png^[colorize\\:cyan^[resize\\:5x18)" + ht[#ht+1] = "275,28=(advtrains_hud_bg.png^[colorize\\:white^[resize\\:5x18)" + ht[#ht+1] = "275,46=(advtrains_hud_bg.png^[colorize\\:orange^[resize\\:5x36)" + ht[#ht+1] = "275,82=(advtrains_hud_bg.png^[colorize\\:red^[resize\\:5x18)" + ht[#ht+1] = "292,16=(advtrains_hud_bg.png^[colorize\\:darkslategray^[resize\\:6x78)" + ht[#ht+1] = sformat("280,%s=(advtrains_hud_bg.png^[colorize\\:gray^[resize\\:30x18)",18*(4-tlev)+10) + -- reverser + ht[#ht+1] = sformat("245,10=(advtrains_hud_arrow.png^[transformFY%s)", flip and "" or "^[multiply\\:cyan") + ht[#ht+1] = sformat("245,85=(advtrains_hud_arrow.png%s)", flip and "^[multiply\\:orange" or "") + ht[#ht+1] = "250,35=(advtrains_hud_bg.png^[colorize\\:darkslategray^[resize\\:5x40)" + ht[#ht+1] = sformat("240,%s=(advtrains_hud_bg.png^[resize\\:25x15^[colorize\\:gray)", flip and 65 or 30) + -- train control/safety indication + if train.tarvelocity or train.atc_command then + ht[#ht+1] = "10,10=(advtrains_hud_atc.png^[resize\\:30x30^[multiply\\:cyan)" + end + if train.ctrl.lzb then + ht[#ht+1] = "50,10=(advtrains_hud_lzb.png^[resize\\:30x30^[multiply\\:red)" + end + if train.is_shunt then + ht[#ht+1] = "90,10=(advtrains_hud_shunt.png^[resize\\:30x30^[multiply\\:orange)" + end + -- door + ht[#ht+1] = "187,10=(advtrains_hud_bg.png^[resize\\:26x30^[colorize\\:white)" + ht[#ht+1] = "189,12=(advtrains_hud_bg.png^[resize\\:22x11)" + ht[#ht+1] = sformat("170,10=(advtrains_hud_bg.png^[resize\\:15x30^[colorize\\:%s)", train.door_open==-1 and "white" or "darkslategray") + ht[#ht+1] = "172,12=(advtrains_hud_bg.png^[resize\\:11x11)" + ht[#ht+1] = sformat("215,10=(advtrains_hud_bg.png^[resize\\:15x30^[colorize\\:%s)", train.door_open==1 and "white" or "darkslategray") + ht[#ht+1] = "217,12=(advtrains_hud_bg.png^[resize\\:11x11)" + -- speed indication(s) + sevenseg(math.floor(vel/10), 320, 10, 30, 10, "[colorize\\:red\\:255") + sevenseg(vel%10, 380, 10, 30, 10, "[colorize\\:red\\:255") for i = 1, vel, 1 do - ht[#ht+1] = sformat("%d,100=(advtrains_hud_bg.png^[resize\\:11x30^[colorize\\:white)", i*14-3) + ht[#ht+1] = sformat("%d,65=(advtrains_hud_bg.png^[resize\\:8x20^[colorize\\:white)", i*11-1) end for i = max+1, 20, 1 do - ht[#ht+1] = sformat("%d,100=(advtrains_hud_bg.png^[resize\\:11x30^[colorize\\:darkslategray)", i*14-3) + ht[#ht+1] = sformat("%d,65=(advtrains_hud_bg.png^[resize\\:8x20^[colorize\\:darkslategray)", i*11-1) end if res and res > 0 then - ht[#ht+1] = sformat("%d,95=(advtrains_hud_bg.png^[resize\\:3x40^[colorize\\:red\\:255)", 8+res*14) + ht[#ht+1] = sformat("%d,60=(advtrains_hud_bg.png^[resize\\:3x30^[colorize\\:red\\:255)", 7+res*11) end if train.tarvelocity then - ht[#ht+1] = sformat("%d,130=(advtrains_hud_arrow.png^[multiply\\:cyan^[transformFY^[makealpha\\:#000000)", 2+train.tarvelocity*14) + ht[#ht+1] = sformat("%d,85=(advtrains_hud_arrow.png^[multiply\\:cyan^[transformFY^[makealpha\\:#000000)", 1+train.tarvelocity*11) end local lzb = train.lzb if lzb and lzb.oncoming then local oc = lzb.oncoming for i = 1, #oc do local spd = oc[i].spd - if not spd then - ht[#ht+1] = "203,43=(advtrains_hud_bg.png^[resize\\:14x14^[colorize\\:lime\\:255)" - elseif spd == 0 then - ht[#ht+1] = "283,43=(advtrains_hud_bg.png^[resize\\:14x14^[colorize\\:red\\:255)" - elseif tonumber(spd) then - ht[#ht+1] = "243,43=(advtrains_hud_bg.png^[resize\\:14x14^[colorize\\:orange\\:255)" - ht[#ht+1] = sformat("%d,85=(advtrains_hud_arrow.png^[multiply\\:red^[makealpha\\:#000000)", 2+spd*14) + local c = not spd and "lime" or (type(spd) == "number" and (spd == 0) and "red" or "orange") or nil + if c then + ht[#ht+1] = sformat("130,10=(advtrains_hud_bg.png^[resize\\:30x5^[colorize\\:%s)",c) + ht[#ht+1] = sformat("130,35=(advtrains_hud_bg.png^[resize\\:30x5^[colorize\\:%s)",c) + if spd and spd~=0 then + ht[#ht+1] = sformat("%d,50=(advtrains_hud_arrow.png^[multiply\\:red^[makealpha\\:#000000)", 1+spd*11) + end + local floor = math.floor + local dist = floor(((oc[i].idx or train.index)-train.index)) + dist = math.max(0, math.min(999, dist)) + for j = 1, 3, 1 do + sevenseg(floor((dist/10^(3-j))%10), 119+j*11, 18, 4, 2, "[colorize\\:"..c) + end + break end - break end end @@ -291,7 +310,7 @@ end local _, texture = advtrains.hud_train_format { -- dummy train object to demonstrate the train hud max_speed = 15, speed_restriction = 15, velocity = 15, tarvelocity = 12, active_control = true, lever = 3, ctrl = {lzb = true}, is_shunt = true, - door_open = 1, lzb = {oncoming = {{spd=6}}} + door_open = 1, lzb = {oncoming = {{spd=6, idx=125.7}}}, index = 0, } minetest.register_node("advtrains:hud_demo",{ -- cgit v1.2.3