renamed add_buttons function to get_fs_talkdialog_add_edit_and_command_buttons and placed commands like walk/follow/stand/inventory there
This commit is contained in:
parent
8b3fb10faf
commit
89bd9ea546
@ -358,15 +358,20 @@ end
|
||||
-- if the player can edit the NPC,
|
||||
-- either add a button for entering edit mode
|
||||
-- or add the buttons needed to edit the dialog when in *edit mode*
|
||||
local old_talkdialog_add_edit_buttons = yl_speak_up.get_fs_talkdialog_add_edit_buttons
|
||||
yl_speak_up.get_fs_talkdialog_add_edit_buttons = function(
|
||||
local old_talkdialog_add_edit_and_command_buttons = yl_speak_up.get_fs_talkdialog_add_edit_and_command_buttons
|
||||
yl_speak_up.get_fs_talkdialog_add_edit_and_command_buttons = function(
|
||||
pname, formspec, h, pname_for_old_fs, is_a_start_dialog,
|
||||
active_dialog, luaentity, may_edit_npc, anz_options)
|
||||
-- add the buttons that are added to all editable NPC *first*:
|
||||
-- inventory access, commands for mobs_npc, custom commands
|
||||
local res = old_talkdialog_add_edit_and_command_buttons(
|
||||
pname, formspec, h, pname_for_old_fs, is_a_start_dialog,
|
||||
active_dialog, luaentity, may_edit_npc, anz_options)
|
||||
formspec = res.formspec
|
||||
h = res.h
|
||||
-- if the player cannot *enter* edit_mode:
|
||||
if(not(may_edit_npc)) then
|
||||
return old_talkdialog_add_edit_buttons(
|
||||
pname, formspec, h, pname_for_old_fs, is_a_start_dialog,
|
||||
active_dialog, luaentity, may_edit_npc, anz_options)
|
||||
return res
|
||||
end
|
||||
local edit_mode = yl_speak_up.in_edit_mode(pname)
|
||||
-- button "show log" for those who can edit the NPC (entering edit mode is not required)
|
||||
|
||||
@ -386,10 +386,59 @@ end
|
||||
-- if the player can edit the NPC,
|
||||
-- either add a button for entering edit mode
|
||||
-- or add the buttons needed to edit the dialog when in *edit mode*
|
||||
yl_speak_up.get_fs_talkdialog_add_edit_buttons = function(
|
||||
yl_speak_up.get_fs_talkdialog_add_edit_and_command_buttons = function(
|
||||
pname, formspec, h, pname_for_old_fs, is_a_start_dialog,
|
||||
active_dialog, luaentity, may_edit_npc, anz_options)
|
||||
-- outside edit mode: nothing to add here
|
||||
if(not(may_edit_npc)) then
|
||||
return {h = h, formspec = formspec}
|
||||
end
|
||||
|
||||
if(is_a_start_dialog) then
|
||||
-- show the "show your inventory"-button even when not in edit mode
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"show_inventory",
|
||||
"Access and manage the inventory of the NPC. This is used for adding trade "..
|
||||
"items, getting collected payments and managing quest items.",
|
||||
"Show your inventory (only accessible to owner)!",
|
||||
true, nil, nil, pname_for_old_fs)
|
||||
end
|
||||
|
||||
-- mobs_redo based NPC can follow, stand or wander around
|
||||
if(luaentity and luaentity.order and may_edit_npc
|
||||
-- not all mobs need or support this feature
|
||||
and table.indexof(yl_speak_up.emulate_orders_on_rightclick, luaentity.name) > -1) then
|
||||
if(luaentity.order ~= "follow") then
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"order_follow",
|
||||
"The NPC will follow you.",
|
||||
"New order: Follow me!",
|
||||
((luaentity.owner == pname) and (luaentity.order ~= "follow")),
|
||||
"New order: Follow me. (Only available for owner).",
|
||||
nil, pname_for_old_fs)
|
||||
end
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"order_stand",
|
||||
"The NPC will wait here.",
|
||||
"New order: Stand here.",
|
||||
(luaentity.order ~= "stand"), nil, nil, pname_for_old_fs)
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"order_wander",
|
||||
"The NPC will wander around randomly.",
|
||||
"New order: Wander around a bit on your own.",
|
||||
(luaentity.order ~= "walking"), nil, nil, pname_for_old_fs)
|
||||
end
|
||||
|
||||
-- some mobs may need additional things in on_rightclick (i.e. beeing picked up)
|
||||
if(luaentity and may_edit_npc
|
||||
and yl_speak_up.add_on_rightclick_entry[luaentity.name]) then
|
||||
local m = yl_speak_up.add_on_rightclick_entry[luaentity.name]
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"order_custom",
|
||||
minetest.formspec_escape(m.text_if_false),
|
||||
minetest.formspec_escape(m.text_if_true),
|
||||
(m.condition), nil, nil, pname_for_old_fs)
|
||||
end
|
||||
return {h = h, formspec = formspec}
|
||||
end
|
||||
|
||||
@ -624,25 +673,6 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
||||
dialog, nil, pname_for_old_fs)
|
||||
end
|
||||
|
||||
-- can the player edit this NPC?
|
||||
local may_edit_npc = yl_speak_up.may_edit_npc(player, n_id)
|
||||
-- for muting and for checking the owner/order, the luaentity is needed
|
||||
local obj = yl_speak_up.speak_to[pname].obj
|
||||
-- some precautions - someone else might have eliminated the NPC in the meantime
|
||||
local luaentity = nil
|
||||
if(obj) then
|
||||
luaentity = obj:get_luaentity()
|
||||
end
|
||||
|
||||
|
||||
-- If in edit mode, add new menu entries: "add new options", "end edit mode" and what else is needed.
|
||||
-- Else allow to enter edit mode
|
||||
local res = yl_speak_up.get_fs_talkdialog_add_edit_buttons(
|
||||
pname, formspec, h, pname_for_old_fs, is_a_start_dialog,
|
||||
active_dialog, luaentity, may_edit_npc, anz_options)
|
||||
formspec = res.formspec
|
||||
h = res.h
|
||||
|
||||
|
||||
-- add a Let's trade button to the first dialog if the NPC has trades
|
||||
local has_trades = nil
|
||||
@ -661,52 +691,29 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
||||
"Show a list of trades the NPC has to offer.",
|
||||
"Let's trade!",
|
||||
(has_trades), nil, nil, pname_for_old_fs)
|
||||
|
||||
elseif(is_a_start_dialog and may_edit_npc) then
|
||||
-- show the "show your inventory"-button even when not in edit mode
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"show_inventory",
|
||||
"Access and manage the inventory of the NPC. This is used for adding trade "..
|
||||
"items, getting collected payments and managing quest items.",
|
||||
"Show your inventory (only accessible to owner)!",
|
||||
true, nil, nil, pname_for_old_fs)
|
||||
end
|
||||
|
||||
-- mobs_redo based NPC can follow, stand or wander around
|
||||
if(luaentity and luaentity.order and may_edit_npc
|
||||
-- not all mobs need or support this feature
|
||||
and table.indexof(yl_speak_up.emulate_orders_on_rightclick, luaentity.name) > -1) then
|
||||
if(luaentity.order ~= "follow") then
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"order_follow",
|
||||
"The NPC will follow you.",
|
||||
"New order: Follow me!",
|
||||
((luaentity.owner == pname) and (luaentity.order ~= "follow")),
|
||||
"New order: Follow me. (Only available for owner).",
|
||||
nil, pname_for_old_fs)
|
||||
end
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"order_stand",
|
||||
"The NPC will wait here.",
|
||||
"New order: Stand here.",
|
||||
(luaentity.order ~= "stand"), nil, nil, pname_for_old_fs)
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"order_wander",
|
||||
"The NPC will wander around randomly.",
|
||||
"New order: Wander around a bit on your own.",
|
||||
(luaentity.order ~= "walking"), nil, nil, pname_for_old_fs)
|
||||
|
||||
-- can the player edit this NPC?
|
||||
local may_edit_npc = yl_speak_up.may_edit_npc(player, n_id)
|
||||
-- for muting and for checking the owner/order, the luaentity is needed
|
||||
local obj = yl_speak_up.speak_to[pname].obj
|
||||
-- some precautions - someone else might have eliminated the NPC in the meantime
|
||||
local luaentity = nil
|
||||
if(obj) then
|
||||
luaentity = obj:get_luaentity()
|
||||
end
|
||||
|
||||
-- some mobs may need additional things in on_rightclick (i.e. beeing picked up)
|
||||
if(luaentity and may_edit_npc
|
||||
and yl_speak_up.add_on_rightclick_entry[luaentity.name]) then
|
||||
local m = yl_speak_up.add_on_rightclick_entry[luaentity.name]
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"order_custom",
|
||||
minetest.formspec_escape(m.text_if_false),
|
||||
minetest.formspec_escape(m.text_if_true),
|
||||
(m.condition), nil, nil, pname_for_old_fs)
|
||||
end
|
||||
|
||||
-- If in edit mode, add new menu entries: "add new options", "end edit mode" and what else is needed.
|
||||
-- Else allow to enter edit mode
|
||||
-- also covers commands for mobs_npc (walk, stand, follow), custom commands and inventory access
|
||||
local res = yl_speak_up.get_fs_talkdialog_add_edit_and_command_buttons(
|
||||
pname, formspec, h, pname_for_old_fs, is_a_start_dialog,
|
||||
active_dialog, luaentity, may_edit_npc, anz_options)
|
||||
formspec = res.formspec
|
||||
h = res.h
|
||||
|
||||
|
||||
-- we are finished with adding buttons to the bottom of the formspec
|
||||
local bottom_window_fs = table.concat(formspec, "\n")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user