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 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
|
||||
|
||||
-- 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;
|
||||
-- helper function for yl_speak_up.fs_talkdialog(..)
|
||||
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
|
||||
if(not(alternate_label) and not(show_main_not_alternate)) then
|
||||
return h
|
||||
end
|
||||
h = h + 1
|
||||
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, "label[0.7,"..(h+0.45)..";"..tostring(label).."]")
|
||||
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).."]")
|
||||
-- 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..".]")
|
||||
|
||||
--
|
||||
-- normal mode: show an option if the prerequirements (if any are defined) are met
|
||||
elseif allowed[sb_v.o_id] == true then
|
||||
h = h + 1
|
||||
-- replace $NPC_NAME$ etc.
|
||||
local t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||
else
|
||||
local t = "- no text given -"
|
||||
local t_alt = nil
|
||||
-- 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))
|
||||
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 .. "]")
|
||||
else
|
||||
if sb_v.o_hide_when_prerequisites_not_met == "true" then
|
||||
else
|
||||
-- replace $NPC_NAME$ etc.
|
||||
local t = minetest.formspec_escape(yl_speak_up.replace_vars_in_text(
|
||||
-- precondition not fulfilled? the option shall be hidden
|
||||
elseif(sb_v.o_hide_when_prerequisites_not_met == "true") then
|
||||
-- show nothing; t_alt remains nil
|
||||
t = nil
|
||||
-- precondition not fulfilled? the option shall be greyed out
|
||||
-- default to greyed out (this option cannot be selected)
|
||||
elseif(sb_v.o_grey_when_prerequisites_not_met == "true") then
|
||||
local text = sb_v.o_text_when_prerequisites_not_met
|
||||
if(not(text) or text == "") then
|
||||
text = t or yl_speak_up.message_button_option_prerequisites_not_met_default
|
||||
end
|
||||
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))
|
||||
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 ..
|
||||
";" .. yl_speak_up.message_button_option_prerequisites_not_met_default .. "]"
|
||||
)
|
||||
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
|
||||
if(t or t_alt) then
|
||||
-- actually show the button
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"button_" .. oid,
|
||||
t,
|
||||
t,
|
||||
(t and not(t_alt)),
|
||||
t_alt,
|
||||
nil)
|
||||
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.",
|
||||
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)
|
||||
(edit_mode or dialog.n_dialogs["d_got_item"]), nil, nil)
|
||||
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
|
||||
(anz_options < yl_speak_up.max_number_of_options_per_dialog),
|
||||
"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,
|
||||
"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),
|
||||
-- (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 "..
|
||||
"text first.")
|
||||
"text first.", nil)
|
||||
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"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.",
|
||||
"Show what points to this dialog.",
|
||||
-- there is no alternate text to show
|
||||
true, nil)
|
||||
true, nil, nil)
|
||||
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"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.",
|
||||
(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)
|
||||
"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,
|
||||
"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)
|
||||
true, nil, nil)
|
||||
|
||||
|
||||
-- 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 "..
|
||||
"unfinished entries and/or quests.",
|
||||
"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,
|
||||
"un_mute_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.",
|
||||
"State: You are currently muted. Talk to anyone again who wants to talk to you.",
|
||||
-- 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,
|
||||
@ -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.",
|
||||
-- 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!",
|
||||
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.
|
||||
-- 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.",
|
||||
-- chat option: "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
|
||||
|
||||
-- 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 a list of trades the NPC has to offer.",
|
||||
"Let's trade!",
|
||||
(has_trades), nil)
|
||||
(has_trades), nil, nil)
|
||||
end
|
||||
|
||||
|
||||
h = h + 1
|
||||
table.insert(formspec, "button_exit[0.5," .. h .. ";53.8,0.9;button_exit;]")
|
||||
table.insert(formspec, "tooltip[button_exit;" .. yl_speak_up.message_button_option_exit .. "]")
|
||||
local l = h + 0.45
|
||||
table.insert(formspec, "label[0.7," .. l .. ";" .. yl_speak_up.message_button_option_exit .. "]")
|
||||
h = yl_speak_up.add_edit_button_fs_talkdialog(formspec, h,
|
||||
"button_exit",
|
||||
yl_speak_up.message_button_option_exit,
|
||||
yl_speak_up.message_button_option_exit,
|
||||
true, nil, true) -- button_exit
|
||||
|
||||
table.insert(formspec, "scroll_container_end[]")
|
||||
|
||||
table.insert(formspec, "container_end[]")
|
||||
|
||||
-- if the player has an older formspec version
|
||||
|
Loading…
Reference in New Issue
Block a user