diff --git a/editor/api/fs_edit_general.lua b/editor/api/fs_edit_general.lua index 71db75d..d968e47 100644 --- a/editor/api/fs_edit_general.lua +++ b/editor/api/fs_edit_general.lua @@ -430,7 +430,7 @@ yl_speak_up.save_element_p_or_a_or_e = function( -- the button is called store_trade_simple instead of save_element in -- the trade simple function(s); we want to store a trade fields.store_trade_simple = true - local res = yl_speak_up.input_add_trade_simple(player, "", fields) + local res = yl_speak_up.input_add_trade_simple(player, "", fields, nil) -- the above function sets: -- dialog.trades[ trade_id ] = {pay={ps},buy={bs}, d_id = d_id, o_id = o_id} -- store the trade as an action: diff --git a/editor/trade_in_edit_mode.lua b/editor/trade_in_edit_mode.lua index 35d5a6f..64a370a 100644 --- a/editor/trade_in_edit_mode.lua +++ b/editor/trade_in_edit_mode.lua @@ -68,3 +68,27 @@ yl_speak_up.delete_trade_simple = function(player, trade_id) end return old_delete_trade_simple(player, trade_id) end + + +-- override fs/fs_add_trade_simple.lua: +-- (this is kept here as it is trade related and does not change the formspec as such) + +local old_input_add_trade_simple = yl_speak_up.input_add_trade_simple +yl_speak_up.input_add_trade_simple = function(player, formname, fields, input_to) + if(not(player)) then + return 0 + end + local pname = player:get_player_name() + + input_to = "add_trade_simple" + -- are we editing an action of the type trade? + if( yl_speak_up.speak_to[pname][ "tmp_action" ] + and yl_speak_up.speak_to[pname][ "tmp_action" ].what == 3 + and yl_speak_up.in_edit_mode(pname) + and yl_speak_up.edit_mode[pname] == n_id) then + input_to = "edit_actions" + end + + return old_input_add_trade_simple(player, formname, fields, input_to) +end + diff --git a/fs/fs_add_trade_simple.lua b/fs/fs_add_trade_simple.lua index 355f404..1eb5e54 100644 --- a/fs/fs_add_trade_simple.lua +++ b/fs/fs_add_trade_simple.lua @@ -80,17 +80,14 @@ end -- go back to edit options dialog -- abort_trade_simple, ESC go back to edit options dialog -- The rest is inventory item movement. -yl_speak_up.input_add_trade_simple = function(player, formname, fields) +yl_speak_up.input_add_trade_simple = function(player, formname, fields, input_to) if(not(player)) then return 0 end local pname = player:get_player_name() - local input_to = "add_trade_simple" - -- are we editing an action of the type trade? - if( yl_speak_up.speak_to[pname][ "tmp_action" ] - and yl_speak_up.speak_to[pname][ "tmp_action" ].what == 3) then - input_to = "edit_actions" + if(not(input_to)) then + input_to = "add_trade_simple" end -- we return from showing an error message (the player may not have noticed @@ -132,7 +129,7 @@ yl_speak_up.input_add_trade_simple = function(player, formname, fields) local o_id = yl_speak_up.speak_to[pname].o_id -- the trade can only be changed in edit mode - if((not(n_id) or yl_speak_up.edit_mode[pname] ~= n_id) + if((input_to == "add_trade_simple") -- exception: when adding a new trade via the trade list -- (that is allowed without having to be in edit mode) and not(trade_id == "new" and yl_speak_up.may_edit_npc(player, n_id))) then @@ -254,7 +251,7 @@ yl_speak_up.input_add_trade_simple = function(player, formname, fields) dialog.trades = {} end if(dialog.trades[ trade_id ] and dialog.trades[ trade_id ].d_id - and input_to ~= "edit_actions") then + and input_to == "add_trade_simple") then yl_speak_up.speak_to[pname].trade_id = trade_id -- tell the player that the new trade has been added yl_speak_up.show_fs(player, "msg", {