diff options
Diffstat (limited to 'advtrains/trainhud.lua')
-rw-r--r-- | advtrains/trainhud.lua | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/advtrains/trainhud.lua b/advtrains/trainhud.lua index b2744ad..ce4b913 100644 --- a/advtrains/trainhud.lua +++ b/advtrains/trainhud.lua @@ -10,6 +10,8 @@ advtrains.hud[player:get_player_name()] = nil advtrains.hhud[player:get_player_name()] = nil end) +local hud_type_key = minetest.features.hud_def_type_field and "type" or "hud_elem_type" + local mletter={[1]="F", [-1]="R", [0]="N"} function advtrains.on_control_change(pc, train, flip) @@ -103,19 +105,21 @@ function advtrains.set_trainhud(name, text, driver) if not player then return end + local drivertext = driver or "" local driverhud = { - hud_elem_type = "image", + [hud_type_key] = "image", name = "ADVTRAINS_DRIVER", position = {x=0.5, y=1}, offset = {x=0,y=-170}, - text = driver or "", + text = drivertext, alignment = {x=0,y=-1}, - scale = {x=1,y=1},} + scale = {x=1,y=1}, + } if not hud then - hud = {["driver"]={}} + hud = {} advtrains.hud[name] = hud hud.id = player:hud_add({ - hud_elem_type = "text", + [hud_type_key] = "text", name = "ADVTRAINS", number = 0xFFFFFF, position = {x=0.5, y=1}, @@ -124,17 +128,22 @@ function advtrains.set_trainhud(name, text, driver) scale = {x=200, y=60}, alignment = {x=0, y=-1}, }) - hud.oldText=text hud.driver = player:hud_add(driverhud) + hud.oldText = text + hud.oldDriver = drivertext 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 "") + if hud.oldDriver ~= drivertext then + player:hud_change(hud.driver, "text", drivertext) + hud.oldDriver = drivertext + end elseif driver then hud.driver = player:hud_add(driverhud) + hud.oldDriver = drivertext end end end @@ -149,7 +158,7 @@ function advtrains.set_help_hud(name, text) hud = {} advtrains.hhud[name] = hud hud.id = player:hud_add({ - hud_elem_type = "text", + [hud_type_key] = "text", name = "ADVTRAINS_HELP", number = 0xFFFFFF, position = {x=1, y=0.3}, |