turned yl_speak_up.get_fs_talkdialog_add_player_offers_item into extra function

This commit is contained in:
Sokomine 2024-02-02 19:44:51 +01:00
parent 3dab37dae7
commit 4d2da67f9d
2 changed files with 25 additions and 12 deletions

View File

@ -341,3 +341,14 @@ yl_speak_up.get_fs_talkdialog_line = function(
(current_index > 1))
return {h = h, formspec = formspec}
end
-- add a prefix to "I want to give you something." dialog option in edit_mode:
local old_talkdialog_offers_item = yl_speak_up.get_fs_talkdialog_add_player_offers_item
yl_speak_up.get_fs_talkdialog_add_player_offers_item = function(pname, formspec, h, dialog, add_text, pname_for_old_fs)
local offer_item_add_text = ""
if(yl_speak_up.in_edit_mode(pname)) then
offer_item_add_text = minetest.formspec_escape("[dialog d_got_item] -> ")
end
return old_talkdialog_offers_item(pname, formspec, h, dialog, offer_item_add_text, pname_for_old_fs)
end

View File

@ -576,6 +576,18 @@ yl_speak_up.apply_autoanswer_and_random_and_d_got_item = function(player, pname,
end
yl_speak_up.get_fs_talkdialog_add_player_offers_item = function(pname, formspec, h, dialog, add_text, pname_for_old_fs)
return yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
"player_offers_item",
"If you want to give something (items) to this NPC\n"..
"- either because he requested it or as a present -\n"..
"click here. The NPC will return items he doesn't want.",
(add_text or "").."I want to give you something.",
-- show this in edit mode and when the NPC actually accepts items
(add_text or dialog.n_dialogs["d_got_item"]), nil, nil, pname_for_old_fs)
end
-- recursion_depth is increased each time autoanswer is automaticly selected
yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, recursion_depth)
local pname = player:get_player_name()
@ -716,18 +728,8 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
or active_dialog.is_a_start_dialog))
-- add a "I want to give you something" button to the first dialog if the NPC accepts items
if(is_a_start_dialog) then
local offer_item_add_text = ""
if(edit_mode) then
offer_item_add_text = minetest.formspec_escape("[dialog d_got_item] -> ")
end
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
"player_offers_item",
"If you want to give something (items) to this NPC\n"..
"- either because he requested it or as a present -\n"..
"click here. The NPC will return items he doesn't want.",
offer_item_add_text.."I want to give you something.",
-- show this in edit mode and when the NPC actually accepts items
(edit_mode or dialog.n_dialogs["d_got_item"]), nil, nil, pname_for_old_fs)
h = yl_speak_up.get_fs_talkdialog_add_player_offers_item(pname, formspec, h,
dialog, nil, pname_for_old_fs)
end
-- can the player edit this NPC?