diff --git a/functions.lua b/functions.lua index 4de28ca..ee4b13c 100644 --- a/functions.lua +++ b/functions.lua @@ -2747,9 +2747,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 -- show the trade with ID " " - minetest.show_formspec(pname, "yl_speak_up:do_trade_simple", - yl_speak_up.get_fs_trade_simple(player, - tostring(d_id).." "..tostring(o_id))) + yl_speak_up.show_fs_trade_simple(player, tostring(d_id).." "..tostring(o_id)) return end @@ -3219,8 +3217,7 @@ yl_speak_up.input_talk = function(player, formname, fields) -- which dialog shall be shown in case of a successful trade? yl_speak_up.speak_to[pname].target_d_id = target_dialog -- show the trade dialog - minetest.show_formspec(pname, "yl_speak_up:do_trade_simple", - yl_speak_up.get_fs_trade_simple(player, trade_id)) + yl_speak_up.show_fs_trade_simple(player, trade_id) return end diff --git a/trade_list.lua b/trade_list.lua index 8547e1b..451ada0 100644 --- a/trade_list.lua +++ b/trade_list.lua @@ -31,8 +31,7 @@ yl_speak_up.input_trade_list = function(player, formname, fields) -- normal mode: the player wants to see a particular trade for k,v in pairs(dialog.trades) do if(fields[ k ]) then - minetest.show_formspec(pname, "yl_speak_up:do_trade_simple", - yl_speak_up.get_fs_trade_simple(player, k)) + yl_speak_up.show_fs_trade_simple(player, k) return end end diff --git a/trade_simple.lua b/trade_simple.lua index d948d64..d195b7c 100644 --- a/trade_simple.lua +++ b/trade_simple.lua @@ -6,6 +6,20 @@ yl_speak_up.trade_fail_fs = "size[6,2]".. "button_exit[2,1.5;1,0.9;exit;Exit]" +-- provides an easier call for the trade simple formspec +yl_speak_up.show_fs_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:do_trade_simple", + yl_speak_up.get_fs_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 @@ -32,9 +46,7 @@ yl_speak_up.input_do_trade_simple = function(player, formname, fields) -- a new trade has been stored - show it if(fields.trade_simple_stored) then - minetest.show_formspec(pname, "yl_speak_up:do_trade_simple", - yl_speak_up.get_fs_trade_simple(player, - yl_speak_up.speak_to[pname].trade_id)) + yl_speak_up.show_fs_trade_simple(player, yl_speak_up.speak_to[pname].trade_id) return end @@ -138,8 +150,7 @@ yl_speak_up.input_do_trade_simple = function(player, formname, fields) end -- show this formspec again - minetest.show_formspec(pname, "yl_speak_up:do_trade_simple", - yl_speak_up.get_fs_trade_simple(player)) + yl_speak_up.show_fs_trade_simple(player) end @@ -725,8 +736,7 @@ minetest.register_on_joinplayer(function(player, last_login) if(listname == "pay") then local pname = player:get_player_name() -- show formspec with updated information (perhaps sale is now possible) - minetest.show_formspec(pname, "yl_speak_up:do_trade_simple", - yl_speak_up.get_fs_trade_simple(player)) + yl_speak_up.show_fs_trade_simple(player) end end, on_take = function(inv, listname, index, stack, player) @@ -735,14 +745,12 @@ minetest.register_on_joinplayer(function(player, last_login) if(listname == "pay") then local pname = player:get_player_name() -- show formspec with updated information (perhaps sale is now possible) - minetest.show_formspec(pname, "yl_speak_up:do_trade_simple", - yl_speak_up.get_fs_trade_simple(player)) + yl_speak_up.show_fs_trade_simple(player) elseif(listname == "buy") then yl_speak_up.do_trade_simple(player, stack:get_count()) -- information may require an update (NPC might now be out of stock), or -- the player can do the trade a second time - minetest.show_formspec(pname, "yl_speak_up:do_trade_simple", - yl_speak_up.get_fs_trade_simple(player)) + yl_speak_up.show_fs_trade_simple(player) end end, })