From 1659aed8ab209794d021146cc56b42f9e41fe8e4 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Fri, 9 Feb 2024 05:44:30 +0100 Subject: [PATCH] took care of delete_trade_simple regarding edit_mode --- api/api_trade.lua | 15 ++------------- editor/trade_in_edit_mode.lua | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/api/api_trade.lua b/api/api_trade.lua index cfcf3de..10235fa 100644 --- a/api/api_trade.lua +++ b/api/api_trade.lua @@ -165,19 +165,8 @@ yl_speak_up.delete_trade_simple = function(player, trade_id) if(dialog and dialog.trades and trade_id and dialog.trades[ trade_id ] and n_id) then - if( dialog.trades[ trade_id ].d_id - and yl_speak_up.edit_mode[pname] ~= n_id) then - yl_speak_up.show_fs(player, "msg", { - input_to = "yl_speak_up:do_trade_simple", - formspec = "size[6,2]".. - "label[0.2,-0.2;".. - "Trades that are attached to dialog options\n".. - "can only be deleted in edit mode. Please tell\n".. - "your NPC that you are its owner and have\n".. - "new commands!]".. - "button[2,1.5;1,0.9;back_from_error_msg;Back]"}) - return - end + -- Note: That the trade cannot be deleted outside edit mode if it is the action + -- belonging to an option is checked in editor/trade_*.lua if( dialog.trades[ trade_id ].d_id ) then back_to_d_id = dialog.trades[ trade_id ].d_id back_to_o_id = dialog.trades[ trade_id ].o_id diff --git a/editor/trade_in_edit_mode.lua b/editor/trade_in_edit_mode.lua index 2e68320..35d5a6f 100644 --- a/editor/trade_in_edit_mode.lua +++ b/editor/trade_in_edit_mode.lua @@ -37,3 +37,34 @@ yl_speak_up.do_trade_simple = function(player, count) end return old_do_trade_simple(player, count) end + + + +-- overrides for api/api_trade.lua: + +-- do not allow deleting trades that are actions of an option if not in edit mode: +local old_delete_trade_simple = yl_speak_up.delete_trade_simple +yl_speak_up.delete_trade_simple = function(player, trade_id) + local pname = player:get_player_name() + local n_id = yl_speak_up.speak_to[pname].n_id + -- get the necessary dialog data + local dialog = yl_speak_up.speak_to[pname].dialog + if(dialog and dialog.trades and trade_id + and dialog.trades[ trade_id ] and n_id) then + + if( dialog.trades[ trade_id ].d_id + and yl_speak_up.edit_mode[pname] ~= n_id) then + yl_speak_up.show_fs(player, "msg", { + input_to = "yl_speak_up:do_trade_simple", + formspec = "size[6,2]".. + "label[0.2,-0.2;".. + "Trades that are attached to dialog options\n".. + "can only be deleted in edit mode. Please tell\n".. + "your NPC that you are its owner and have\n".. + "new commands!]".. + "button[2,1.5;1,0.9;back_from_error_msg;Back]"}) + return + end + end + return old_delete_trade_simple(player, trade_id) +end