From e5fd5b08f9f422cb61496b48b3352c7494c4d316 Mon Sep 17 00:00:00 2001 From: ywang Date: Thu, 5 Aug 2021 11:49:17 +0200 Subject: Add option to exclude inside display from the text HUD --- advtrains/api_doc.txt | 4 +++- advtrains/trainhud.lua | 7 ++++--- advtrains/wagons.lua | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/advtrains/api_doc.txt b/advtrains/api_doc.txt index d3e7ca9..ef625db 100644 --- a/advtrains/api_doc.txt +++ b/advtrains/api_doc.txt @@ -111,6 +111,8 @@ advtrains.register_wagon(name, prototype, description, inventory_image) graphical_hud = function(train, flip) end ^- optional: Graphical HUD to show to the driver. The HUD formats defined by advtrains are used by default. + hud_without_text_inside = false + ^- optional: whether the inside display should be excluded from the text HUD custom_on_step = function(self, dtime) end ^- optional: Execute custom code on every step @@ -146,7 +148,7 @@ If you can't enter or leave a train because the doors are closed, holding the Sn # Train HUD The text_hud and graphical_hud fields of the wagons allow you to specify the look of your driver HUDs. -* The text_hud function should return a string that will be shown to the driver. This should usually include the inside display as well +* The text_hud function should return a string that will be shown to the driver. Usually this should not include the inside display. * The graphical_hud function should return a texture string and the height of the texture. This is used to allow proper positioning of the text HUD. There are currently a few pre-defined elements that can help create the graphical HUD. These functions are in the advtrains.hud table: diff --git a/advtrains/trainhud.lua b/advtrains/trainhud.lua index 6d66618..449216a 100644 --- a/advtrains/trainhud.lua +++ b/advtrains/trainhud.lua @@ -86,11 +86,11 @@ function advtrains.on_control_change(pc, train, flip) end end end -function advtrains.update_driver_hud(pname, train, flip, thud, ghud) - local inside=train.text_inside or "" +function advtrains.update_driver_hud(pname, train, flip, thud, ghud, nointext) + local inside=nointext and "" or (train.text_inside or "").."\n" local ft = (thud or advtrains.hud.dtext)(train, flip) local ht, gs = (ghud or advtrains.hud.dgraphical)(train, flip) - advtrains.set_trainhud(pname, inside.."\n"..ft, ht, gs) + advtrains.set_trainhud(pname, inside..ft, ht, gs) end function advtrains.clear_driver_hud(pname) advtrains.set_trainhud(pname, "") @@ -185,6 +185,7 @@ end function advtrains.hud.dtext(train, flip) local st = {} if train.debug then st = {train.debug} end + local res = advtrains.speed_restriction st[#st+1] = attrans("Train ID: @1", train.id) diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index 596c272..b7b88df 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -307,10 +307,10 @@ function wagon:on_step(dtime) local has_driverstand = pname and advtrains.check_driving_couple_protection(pname, data.owner, data.whitelist) has_driverstand = has_driverstand and self:is_driver_stand(seat) if has_driverstand and driver then - advtrains.update_driver_hud(driver:get_player_name(), self:train(), data.wagon_flipped, self.text_hud, self.graphical_hud) + advtrains.update_driver_hud(driver:get_player_name(), self:train(), data.wagon_flipped, self.text_hud, self.graphical_hud, self.hud_without_text_inside) elseif driver then --only show the inside text - local inside=self:train().text_inside or "" + local inside=(not self.hud_without_text_inside) and self:train().text_inside or "" advtrains.set_trainhud(driver:get_player_name(), inside) end if driver and driver:get_player_control_bits()~=self.seatpc[seatno] then -- cgit v1.2.3