diff --git a/functions.lua b/functions.lua index ee4b13c..742af2c 100644 --- a/functions.lua +++ b/functions.lua @@ -2705,9 +2705,7 @@ yl_speak_up.input_edit_option_dialog = function(player, formname, fields) -- do not switch target dialog (we are in edit mode) yl_speak_up.speak_to[pname].target_d_id = nil -- create a new trade for this dialog and option - with ID " " - minetest.show_formspec(pname, "yl_speak_up:add_trade_simple", - yl_speak_up.get_fs_add_trade_simple(player, - tostring(d_id).." "..tostring(o_id))) + yl_speak_up.show_fs_add_trade_simple(player, tostring(d_id).." "..tostring(o_id)) return -- the player wants to see the previous option/answer diff --git a/trade_list.lua b/trade_list.lua index 451ada0..02fd15e 100644 --- a/trade_list.lua +++ b/trade_list.lua @@ -16,8 +16,7 @@ yl_speak_up.input_trade_list = function(player, formname, fields) -- the player wants to add a new trade if(fields.trade_list_add_trade) then -- show the trade config dialog for a new trade - minetest.show_formspec(pname, "yl_speak_up:add_trade_simple", - yl_speak_up.get_fs_add_trade_simple(player, "new")) + yl_speak_up.show_fs_add_trade_simple(player, "new") return end diff --git a/trade_simple.lua b/trade_simple.lua index d195b7c..f1936c5 100644 --- a/trade_simple.lua +++ b/trade_simple.lua @@ -20,6 +20,20 @@ yl_speak_up.show_fs_trade_simple = function(player, trade_id) end +-- also provides an easier way to call this function +yl_speak_up.show_fs_add_trade_simple = function(player, trade_id) + if(not(player)) then + return + end + if(not(trade_id) and yl_speak_up.speak_to[pname]) then + trade_id = yl_speak_up.speak_to[pname].trade_id + end + minetest.show_formspec(player:get_player_name(), + "yl_speak_up:add_trade_simple", + yl_speak_up.get_fs_add_trade_simple(player, trade_id)) +end + + -- possible inputs: -- fields.edit_trade_simple go on to showing the add_trade_simple formspec -- fields.abort_trade_simple, ESC, depends on context @@ -115,8 +129,7 @@ yl_speak_up.input_do_trade_simple = function(player, formname, fields) -- show the edit trade formspec if(fields.edit_trade_simple) then - minetest.show_formspec(pname, "yl_speak_up:add_trade_simple", - yl_speak_up.get_fs_add_trade_simple(player, trade.trade_id)) + yl_speak_up.show_fs_add_trade_simple(player, trade.trade_id) return end @@ -239,8 +252,7 @@ yl_speak_up.input_add_trade_simple = function(player, formname, fields) -- we return from showing an error message (the player may not have noticed -- a chat message while viewing a formspec; thus, we showed a formspec message) if(fields.back_from_error_msg) then - minetest.show_formspec(pname, "yl_speak_up:add_trade_simple", - yl_speak_up.get_fs_add_trade_simple(player)) + yl_speak_up.show_fs_add_trade_simple(player) return end