forked from Sokomine/yl_speak_up
made more use of yl_speak_up.add_edit_button_fs_talkdialog
This commit is contained in:
parent
07be18bcf6
commit
3bde8d18c4
@ -21,6 +21,10 @@ yl_speak_up.input_talk = function(player, formname, fields)
|
|||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local o = ""
|
local o = ""
|
||||||
|
|
||||||
|
-- error: not talking?
|
||||||
|
if(not(yl_speak_up.speak_to[pname])) then
|
||||||
|
return
|
||||||
|
end
|
||||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||||
|
|
||||||
-- the NPC needs to be configured first; route input to the configuration dialog
|
-- the NPC needs to be configured first; route input to the configuration dialog
|
||||||
@ -274,14 +278,18 @@ end
|
|||||||
-- show an edit option in the main menu of the NPC;
|
-- show an edit option in the main menu of the NPC;
|
||||||
-- helper function for yl_speak_up.fs_talkdialog(..)
|
-- helper function for yl_speak_up.fs_talkdialog(..)
|
||||||
yl_speak_up.add_edit_button_fs_talkdialog = function(formspec, h, button_name, tooltip, label,
|
yl_speak_up.add_edit_button_fs_talkdialog = function(formspec, h, button_name, tooltip, label,
|
||||||
show_main_not_alternate, alternate_label)
|
show_main_not_alternate, alternate_label, is_exit_button)
|
||||||
-- do not show this button at all if there is no alternate text and the condition is false
|
-- do not show this button at all if there is no alternate text and the condition is false
|
||||||
if(not(alternate_label) and not(show_main_not_alternate)) then
|
if(not(alternate_label) and not(show_main_not_alternate)) then
|
||||||
return h
|
return h
|
||||||
end
|
end
|
||||||
h = h + 1
|
h = h + 1
|
||||||
if(show_main_not_alternate) then
|
if(show_main_not_alternate) then
|
||||||
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;"..tostring(button_name)..";]")
|
if(is_exit_button) then
|
||||||
|
table.insert(formspec, "button_exit[0.5,"..h..";53.8,0.9;"..tostring(button_name)..";]")
|
||||||
|
else
|
||||||
|
table.insert(formspec, "button[0.5,"..h..";53.8,0.9;"..tostring(button_name)..";]")
|
||||||
|
end
|
||||||
table.insert(formspec, "tooltip["..tostring(button_name)..";"..tostring(tooltip).."]")
|
table.insert(formspec, "tooltip["..tostring(button_name)..";"..tostring(tooltip).."]")
|
||||||
table.insert(formspec, "label[0.7,"..(h+0.45)..";"..tostring(label).."]")
|
table.insert(formspec, "label[0.7,"..(h+0.45)..";"..tostring(label).."]")
|
||||||
else
|
else
|
||||||
@ -628,88 +636,48 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
minetest.formspec_escape(sb_v.o_text_when_prerequisites_met).."]")
|
minetest.formspec_escape(sb_v.o_text_when_prerequisites_met).."]")
|
||||||
-- add a tooltip "Edit the text that is displayed on button o_<nr>."
|
-- add a tooltip "Edit the text that is displayed on button o_<nr>."
|
||||||
table.insert(formspec, "tooltip[text_option_" .. oid .. ";Edit the text that is displayed on button "..oid..".]")
|
table.insert(formspec, "tooltip[text_option_" .. oid .. ";Edit the text that is displayed on button "..oid..".]")
|
||||||
|
--
|
||||||
-- normal mode: show an option if the prerequirements (if any are defined) are met
|
-- normal mode: show an option if the prerequirements (if any are defined) are met
|
||||||
elseif allowed[sb_v.o_id] == true then
|
else
|
||||||
h = h + 1
|
local t = "- no text given -"
|
||||||
-- replace $NPC_NAME$ etc.
|
local t_alt = nil
|
||||||
local t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
-- the preconditions are fulfilled; showe the option
|
||||||
|
if(allowed[sb_v.o_id] == true) then
|
||||||
|
-- replace $NPC_NAME$ etc.
|
||||||
|
t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||||
sb_v.o_text_when_prerequisites_met, dialog, pname))
|
sb_v.o_text_when_prerequisites_met, dialog, pname))
|
||||||
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;button_" .. oid .. ";]")
|
-- precondition not fulfilled? the option shall be hidden
|
||||||
table.insert(
|
elseif(sb_v.o_hide_when_prerequisites_not_met == "true") then
|
||||||
formspec,
|
-- show nothing; t_alt remains nil
|
||||||
"tooltip[button_" .. oid .. ";" .. t .. "]"
|
t = nil
|
||||||
)
|
-- precondition not fulfilled? the option shall be greyed out
|
||||||
local l = h + 0.45
|
-- default to greyed out (this option cannot be selected)
|
||||||
table.insert(formspec, "label[0.7," .. l .. ";" .. t .. "]")
|
elseif(sb_v.o_grey_when_prerequisites_not_met == "true") then
|
||||||
else
|
local text = sb_v.o_text_when_prerequisites_not_met
|
||||||
if sb_v.o_hide_when_prerequisites_not_met == "true" then
|
if(not(text) or text == "") then
|
||||||
else
|
text = t or yl_speak_up.message_button_option_prerequisites_not_met_default
|
||||||
-- replace $NPC_NAME$ etc.
|
end
|
||||||
local t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
t = nil
|
||||||
|
-- replace $NPC_NAME$ etc.
|
||||||
|
t_alt = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||||
|
text, dialog, pname))
|
||||||
|
elseif(sb_v.o_grey_when_prerequisites_not_met == "false"
|
||||||
|
and sb_v.o_text_when_prerequisites_not_met ~= "") then
|
||||||
|
-- show in normal coor
|
||||||
|
t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||||
sb_v.o_text_when_prerequisites_not_met, dialog, pname))
|
sb_v.o_text_when_prerequisites_not_met, dialog, pname))
|
||||||
if
|
end
|
||||||
sb_v.o_grey_when_prerequisites_not_met == "true" and
|
if(t or t_alt) then
|
||||||
sb_v.o_text_when_prerequisites_not_met == ""
|
-- actually show the button
|
||||||
then
|
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||||
h = h + 1
|
"button_" .. oid,
|
||||||
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;button_" .. oid .. ";]")
|
t,
|
||||||
table.insert(
|
t,
|
||||||
formspec,
|
(t and not(t_alt)),
|
||||||
"tooltip[button_" ..
|
t_alt,
|
||||||
oid ..
|
nil)
|
||||||
";" .. yl_speak_up.message_button_option_prerequisites_not_met_default .. "]"
|
end
|
||||||
)
|
end
|
||||||
local l = h + 0.45
|
|
||||||
table.insert(
|
|
||||||
formspec,
|
|
||||||
"label[0.7," ..
|
|
||||||
l .. ";" .. yl_speak_up.message_button_option_prerequisites_not_met_default .. "]"
|
|
||||||
)
|
|
||||||
table.insert(formspec, "box[0.5," .. h .. ";53.8,0.9;#BBBBBB]")
|
|
||||||
end
|
|
||||||
if
|
|
||||||
sb_v.o_grey_when_prerequisites_not_met == "true" and
|
|
||||||
sb_v.o_text_when_prerequisites_not_met ~= ""
|
|
||||||
then
|
|
||||||
h = h + 1
|
|
||||||
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;button_" .. oid .. ";]")
|
|
||||||
table.insert(
|
|
||||||
formspec,
|
|
||||||
"tooltip[button_" .. oid .. ";" .. t .. "]"
|
|
||||||
)
|
|
||||||
local l = h + 0.45
|
|
||||||
table.insert(
|
|
||||||
formspec,
|
|
||||||
"label[0.7," .. l .. ";" .. t .. "]"
|
|
||||||
)
|
|
||||||
table.insert(formspec, "box[0.5," .. h .. ";53.8,0.9;#BBBBBB]")
|
|
||||||
end
|
|
||||||
if
|
|
||||||
sb_v.o_grey_when_prerequisites_not_met == "false" and
|
|
||||||
sb_v.o_text_when_prerequisites_not_met == ""
|
|
||||||
then
|
|
||||||
-- no hide, no grey, no text
|
|
||||||
end
|
|
||||||
if
|
|
||||||
sb_v.o_grey_when_prerequisites_not_met == "false" and
|
|
||||||
sb_v.o_text_when_prerequisites_not_met ~= ""
|
|
||||||
then
|
|
||||||
-- no grey, but text
|
|
||||||
h = h + 1
|
|
||||||
table.insert(formspec, "button[0.5," .. h .. ";53.8,0.9;button_" .. oid .. ";]")
|
|
||||||
table.insert(
|
|
||||||
formspec,
|
|
||||||
"tooltip[button_" .. oid .. ";" .. t .. "]"
|
|
||||||
)
|
|
||||||
local l = h + 0.45
|
|
||||||
table.insert(
|
|
||||||
formspec,
|
|
||||||
"label[0.7," .. l .. ";" .. t .. "]"
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -726,7 +694,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
"click here. The NPC will return items he doesn't want.",
|
"click here. The NPC will return items he doesn't want.",
|
||||||
offer_item_add_text.."I want to give you something.",
|
offer_item_add_text.."I want to give you something.",
|
||||||
-- show this in edit mode and when the NPC actually accepts items
|
-- show this in edit mode and when the NPC actually accepts items
|
||||||
(edit_mode or dialog.n_dialogs["d_got_item"]), nil)
|
(edit_mode or dialog.n_dialogs["d_got_item"]), nil, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -741,7 +709,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
-- the amount of allowed options/answers has been reached
|
-- the amount of allowed options/answers has been reached
|
||||||
(anz_options < yl_speak_up.max_number_of_options_per_dialog),
|
(anz_options < yl_speak_up.max_number_of_options_per_dialog),
|
||||||
"Maximum number of allowed answers/options reached. No further options/answers "..
|
"Maximum number of allowed answers/options reached. No further options/answers "..
|
||||||
"can be added.")
|
"can be added.", nil)
|
||||||
|
|
||||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||||
"delete_this_empty_dialog",
|
"delete_this_empty_dialog",
|
||||||
@ -752,7 +720,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
(active_dialog and active_dialog.d_text == "" and anz_options == 0),
|
(active_dialog and active_dialog.d_text == "" and anz_options == 0),
|
||||||
-- (but only show this option if the dialog is empty)
|
-- (but only show this option if the dialog is empty)
|
||||||
"If you want to delete this dialog, you need to delete all options and its "..
|
"If you want to delete this dialog, you need to delete all options and its "..
|
||||||
"text first.")
|
"text first.", nil)
|
||||||
|
|
||||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||||
"show_what_points_to_this_dialog",
|
"show_what_points_to_this_dialog",
|
||||||
@ -761,7 +729,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
"or effects lead the player to this dialog here.",
|
"or effects lead the player to this dialog here.",
|
||||||
"Show what points to this dialog.",
|
"Show what points to this dialog.",
|
||||||
-- there is no alternate text to show
|
-- there is no alternate text to show
|
||||||
true, nil)
|
true, nil, nil)
|
||||||
|
|
||||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||||
"make_first_option",
|
"make_first_option",
|
||||||
@ -771,14 +739,14 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
"Make this dialog the first one shown when starting a conversation.",
|
"Make this dialog the first one shown when starting a conversation.",
|
||||||
(active_dialog and active_dialog.d_sort and tonumber(active_dialog.d_sort) ~= 0),
|
(active_dialog and active_dialog.d_sort and tonumber(active_dialog.d_sort) ~= 0),
|
||||||
-- (but only show this option if it's not already the first one)
|
-- (but only show this option if it's not already the first one)
|
||||||
"This dialog will be shown whenever a conversation is started.")
|
"This dialog will be shown whenever a conversation is started.", nil)
|
||||||
|
|
||||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||||
"show_inventory",
|
"show_inventory",
|
||||||
"Access and manage the inventory of the NPC. This is used for adding trade "..
|
"Access and manage the inventory of the NPC. This is used for adding trade "..
|
||||||
"items, getting collected payments and managing quest items.",
|
"items, getting collected payments and managing quest items.",
|
||||||
"Show your inventory (only accessible to owner)!",
|
"Show your inventory (only accessible to owner)!",
|
||||||
true, nil)
|
true, nil, nil)
|
||||||
|
|
||||||
|
|
||||||
-- chat option: Mute/Unmute NPC
|
-- chat option: Mute/Unmute NPC
|
||||||
@ -795,7 +763,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
"useful while you edit the NPC and don't want players to see "..
|
"useful while you edit the NPC and don't want players to see "..
|
||||||
"unfinished entries and/or quests.",
|
"unfinished entries and/or quests.",
|
||||||
"State: Not muted. Stop talking to other players while I give you new orders.",
|
"State: Not muted. Stop talking to other players while I give you new orders.",
|
||||||
(luaentity and luaentity.yl_speak_up.talk), nil)
|
(luaentity and luaentity.yl_speak_up.talk), nil, nil)
|
||||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||||
"un_mute_npc",
|
"un_mute_npc",
|
||||||
-- unmute the NPC
|
-- unmute the NPC
|
||||||
@ -804,7 +772,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
"finished editing.",
|
"finished editing.",
|
||||||
"State: You are currently muted. Talk to anyone again who wants to talk to you.",
|
"State: You are currently muted. Talk to anyone again who wants to talk to you.",
|
||||||
-- the NPC has to be there
|
-- the NPC has to be there
|
||||||
(luaentity and not(luaentity.yl_speak_up.talk)), nil)
|
(luaentity and not(luaentity.yl_speak_up.talk)), nil, nil)
|
||||||
|
|
||||||
|
|
||||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||||
@ -813,7 +781,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
"players. You can always give him new orders by entering edit mode again.",
|
"players. You can always give him new orders by entering edit mode again.",
|
||||||
-- chat option:"That was all. I'm finished with giving you new orders. Remember them!"
|
-- chat option:"That was all. I'm finished with giving you new orders. Remember them!"
|
||||||
"That was all. I'm finished with giving you new orders. Remember them!",
|
"That was all. I'm finished with giving you new orders. Remember them!",
|
||||||
true, nil)
|
true, nil, true) -- is button_exit
|
||||||
|
|
||||||
-- Offer to enter edit mode if the player has the npc_talk_owner priv AND owns the npc.
|
-- Offer to enter edit mode if the player has the npc_talk_owner priv AND owns the npc.
|
||||||
-- The npc_master priv allows to edit all NPC.
|
-- The npc_master priv allows to edit all NPC.
|
||||||
@ -824,7 +792,7 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
"answers that can be given.",
|
"answers that can be given.",
|
||||||
-- chat option: "I am your owner. I have new orders for you.
|
-- chat option: "I am your owner. I have new orders for you.
|
||||||
"I am your owner. I have new orders for you.",
|
"I am your owner. I have new orders for you.",
|
||||||
true, nil)
|
true, nil, true) -- is button_exit
|
||||||
end
|
end
|
||||||
|
|
||||||
-- add a Let's trade button to the first dialog if the NPC has trades
|
-- add a Let's trade button to the first dialog if the NPC has trades
|
||||||
@ -842,18 +810,16 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
"show_trade_list",
|
"show_trade_list",
|
||||||
"Show a list of trades the NPC has to offer.",
|
"Show a list of trades the NPC has to offer.",
|
||||||
"Let's trade!",
|
"Let's trade!",
|
||||||
(has_trades), nil)
|
(has_trades), nil, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||||
h = h + 1
|
"button_exit",
|
||||||
table.insert(formspec, "button_exit[0.5," .. h .. ";53.8,0.9;button_exit;]")
|
yl_speak_up.message_button_option_exit,
|
||||||
table.insert(formspec, "tooltip[button_exit;" .. yl_speak_up.message_button_option_exit .. "]")
|
yl_speak_up.message_button_option_exit,
|
||||||
local l = h + 0.45
|
true, nil, true) -- button_exit
|
||||||
table.insert(formspec, "label[0.7," .. l .. ";" .. yl_speak_up.message_button_option_exit .. "]")
|
|
||||||
|
|
||||||
table.insert(formspec, "scroll_container_end[]")
|
table.insert(formspec, "scroll_container_end[]")
|
||||||
|
|
||||||
table.insert(formspec, "container_end[]")
|
table.insert(formspec, "container_end[]")
|
||||||
|
|
||||||
-- if the player has an older formspec version
|
-- if the player has an older formspec version
|
||||||
|
Loading…
Reference in New Issue
Block a user