From 57118bc2528d83d1990849c9e397993cd006a18e Mon Sep 17 00:00:00 2001 From: Serhii Mozhaiskyi Date: Fri, 13 Dec 2019 09:35:04 +0200 Subject: [PATCH] multiline RDS messages for transmitters --- rds.lua | 27 ++++++++++++++------------- transmitter.lua | 24 ++++++++++++++++-------- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/rds.lua b/rds.lua index d340ee4..07361fe 100644 --- a/rds.lua +++ b/rds.lua @@ -3,23 +3,24 @@ function ham_radio.get_rds_messages(frequency, is_receiver_station) local rds_messages = {} for position, transmitter in pairs(transmitters) do if transmitter.rds_message ~= "" and transmitter.rds_message ~= nil then - -- construct message - local message = table.concat({ - '[ Radio | ', - transmitter.operated_by, - ' ] ', - transmitter.rds_message, - }, "") - if is_receiver_station then - message = table.concat({ - '[ ', + for rds_message_line in transmitter.rds_message:gmatch("[^\n]+") do + -- construct message + local message = table.concat({ + '[ Radio | ', transmitter.operated_by, ' ] ', - transmitter.rds_message + rds_message_line, }, "") + if is_receiver_station then + message = table.concat({ + '[ ', + transmitter.operated_by, + ' ] ', + rds_message_line + }, "") + end + table.insert(rds_messages, message) end - - table.insert(rds_messages, message) end end return rds_messages diff --git a/transmitter.lua b/transmitter.lua index 9f3ce77..f2aa2e2 100644 --- a/transmitter.lua +++ b/transmitter.lua @@ -13,8 +13,16 @@ ham_radio.transmitter_update_infotext = function(meta) 'Frequency: ', frequency } if rds_message ~= "" then + local display_message = string.sub( + rds_message, + utf8.offset(rds_message,1), + utf8.offset(rds_message,60+1)-1 + ) table.insert(infotext, '\nRDS message: "') - table.insert(infotext, rds_message) + table.insert(infotext, display_message) + if display_message:len() < rds_message:len() then + table.insert(infotext, "...") + end table.insert(infotext, '"') end meta:set_string("infotext", table.concat(infotext, '')) @@ -23,12 +31,12 @@ end minetest.register_node("ham_radio:transmitter", { description = "Radio Transmitter", tiles = { - "ham_radio_transmitter_top.png", - "ham_radio_transmitter_top.png", - "ham_radio_transmitter_side.png", - "ham_radio_transmitter_side.png", - "ham_radio_transmitter_side.png", - "ham_radio_transmitter_front.png" + "ham_radio_transmitter_top.png", + "ham_radio_transmitter_top.png", + "ham_radio_transmitter_side.png", + "ham_radio_transmitter_side.png", + "ham_radio_transmitter_side.png", + "ham_radio_transmitter_front.png" }, groups = {cracky=2,oddly_breakable_by_hand=2}, sounds = default.node_sound_metal_defaults(), @@ -48,7 +56,7 @@ minetest.register_node("ham_radio:transmitter", { "tooltip[frequency;Integer number ", ham_radio.settings.frequency.min,"-", ham_radio.settings.frequency.max, "]", - "field[0.25,3.5;7,1;rds_message;RDS message;${rds_message}]", + "textarea[0.25,3.5;7,6;rds_message;RDS message;${rds_message}]", "button_exit[2,4.5;3,1;;Done]" },'') )