diff --git a/editor/edit_mode.lua b/editor/edit_mode.lua index 31e97ec..defd00d 100644 --- a/editor/edit_mode.lua +++ b/editor/edit_mode.lua @@ -148,6 +148,8 @@ yl_speak_up.add_to_command_help_text = yl_speak_up.add_to_command_help_text.. -- -- trade one item(stack) against one other item(stack) -- dofile(modpath .. "api/api_trade_inv.lua") -- dofile(modpath .. "fs/fs_do_trade_simple.lua") + -- handle back button diffrently when editing a trade as an action: + dofile(modpath .. "fs/fs_do_trade_simple_in_edit_mode.lua") -- dofile(modpath .. "fs/fs_add_trade_simple.lua") -- -- just click on a button to buy items from the trade list -- dofile(modpath .. "fs/fs_trade_via_buy_button.lua") diff --git a/editor/fs/fs_do_trade_simple_in_edit_mode.lua b/editor/fs/fs_do_trade_simple_in_edit_mode.lua new file mode 100644 index 0000000..a9645c5 --- /dev/null +++ b/editor/fs/fs_do_trade_simple_in_edit_mode.lua @@ -0,0 +1,44 @@ +-- spimple trading: one item(stack) for another item(stack) +-- (in edit_mode it's a bit diffrent) + + +-- if in edit mode: go back to the edit_options dialog +local old_input_do_trade_simple = yl_speak_up.input_do_trade_simple +yl_speak_up.input_do_trade_simple = function(player, formname, fields) + if(not(player)) then + return 0 + end + local pname = player:get_player_name() + + -- which trade are we talking about? + local trade = yl_speak_up.trade[pname] + + + local n_id = yl_speak_up.speak_to[pname].n_id + -- if in edit mode: go back to the edit options dialog + if(fields.back_to_edit_options + and n_id and yl_speak_up.in_edit_mode(pname)) then + local dialog = yl_speak_up.speak_to[pname].dialog + local tr = dialog.trades[ trade.trade_id ] + if(tr) then + -- done trading + yl_speak_up.speak_to[pname].target_d_id = nil + yl_speak_up.speak_to[pname].trade_id = nil + -- go to the edit options dialog + yl_speak_up.show_fs(player, "edit_option_dialog", + {n_id = n_id, d_id = tr.d_id, o_id = tr.o_id}) + return + end + end + + + -- can the player edit this trade? + if(fields.edit_trade_simple + and n_id and yl_speak_up.in_edit_mode(pname)) then + -- force edit mode for this trade + trade.edit_trade = true + yl_speak_up.trade[pname] = trade + end + + return old_input_do_trade_simple(player, formname, fields) +end diff --git a/fs/fs_do_trade_simple.lua b/fs/fs_do_trade_simple.lua index 45ae33c..9cee1c8 100644 --- a/fs/fs_do_trade_simple.lua +++ b/fs/fs_do_trade_simple.lua @@ -12,7 +12,7 @@ yl_speak_up.trade_fail_fs = "size[6,2]".. -- fields.abort_trade_simple, ESC, depends on context -- fields.delete_trade_simple delete this trade -- fields.finished_trading --- if in edit mode: go back to edit options dialog +-- if in edit_mode: go back to edit options dialog (handled by editor/) -- if traded at least once: go on to the target dialog -- if not traded: go back to the original dialog yl_speak_up.input_do_trade_simple = function(player, formname, fields) @@ -57,35 +57,11 @@ yl_speak_up.input_do_trade_simple = function(player, formname, fields) return end - local n_id = yl_speak_up.speak_to[pname].n_id - -- if in edit mode: go back to the edit options dialog - if(fields.back_to_edit_options - and yl_speak_up.edit_mode[pname] == n_id and n_id) then - local dialog = yl_speak_up.speak_to[pname].dialog - local tr = dialog.trades[ trade.trade_id ] - if(tr) then - -- done trading - yl_speak_up.speak_to[pname].target_d_id = nil - yl_speak_up.speak_to[pname].trade_id = nil - -- go to the edit options dialog - yl_speak_up.show_fs(player, "edit_option_dialog", - {n_id = n_id, d_id = tr.d_id, o_id = tr.o_id}) - return - end - end - if(fields.delete_trade_simple) then yl_speak_up.delete_trade_simple(player, trade.trade_id) return end - -- can the player edit this trade? - if(fields.edit_trade_simple - and (yl_speak_up.edit_mode[pname] == yl_speak_up.speak_to[pname].n_id - and (yl_speak_up.speak_to[pname].n_id))) then - -- force edit mode for this trade - trade.edit_trade = true - end local trade_inv = minetest.get_inventory({type="detached", name="yl_speak_up_player_"..pname}) local player_inv = player:get_inventory() @@ -110,6 +86,7 @@ yl_speak_up.input_do_trade_simple = function(player, formname, fields) local success = not(not(trade and trade.trade_done and trade.trade_done > 0)) local a_id = trade.a_id local o_id = trade.o_id + local n_id = yl_speak_up.speak_to[pname].n_id yl_speak_up.debug_msg(player, n_id, o_id, "Ending trade.") -- done trading yl_speak_up.speak_to[pname].target_d_id = nil @@ -271,7 +248,7 @@ yl_speak_up.get_fs_do_trade_simple = function(player, trade_id) -- the NPCs' inventory local npc_inv = minetest.get_inventory({type="detached", name="yl_speak_up_npc_"..tostring(trade.n_id)}) - -- show edit button for the owner if in edit_mode + -- show edit button for the owner if the owner can edit the npc if(yl_speak_up.may_edit_npc(player, trade.n_id)) then -- for trades in trade list: allow delete (new trades can easily be added) -- allow delete for trades in trade list even if not in edit mode diff --git a/fs/fs_trade_via_buy_button.lua b/fs/fs_trade_via_buy_button.lua index f7273bc..b5a4dad 100644 --- a/fs/fs_trade_via_buy_button.lua +++ b/fs/fs_trade_via_buy_button.lua @@ -306,7 +306,7 @@ yl_speak_up.get_fs_trade_via_buy_button = function(player, trade_id) "NPC and want to get back to talking with the NPC.]") end - -- show edit button for the owner if in edit_mode + -- show edit button for the owner if the player can edit the NPC if(yl_speak_up.may_edit_npc(player, n_id)) then -- for trades in trade list: allow delete (new trades can easily be added) -- allow delete for trades in trade list even if not in edit mode