allow to set up the npc again

This commit is contained in:
Sokomine 2021-07-27 01:58:44 +02:00
parent e96365a483
commit ea276c04d8

View File

@ -5,11 +5,6 @@ yl_speak_up.input_fs_initial_config = function(player, formname, fields)
local pname = player:get_player_name()
local n_id = yl_speak_up.speak_to[pname].n_id
-- not in edit mode? then abort
if(yl_speak_up.edit_mode[pname] ~= n_id or not(n_id)) then
return
end
if(fields.back_from_error_msg) then
-- no point in showing the formspec or error message again if we did so already
if(not(yl_speak_up.may_edit_npc(player, n_id))) then
@ -21,7 +16,7 @@ yl_speak_up.input_fs_initial_config = function(player, formname, fields)
return
end
if(not(fields.save_initial_config) and (fields.quit or fields.exit)) then
if(not(fields.save_initial_config) or (fields and fields.exit)) then
-- is the player editing the npc? then leaving this config
-- dialog has to lead back to the talk dialog
if(yl_speak_up.edit_mode[pname] == n_id and n_id) then
@ -222,6 +217,7 @@ yl_speak_up.get_fs_initial_config = function(player, n_id, d_id, is_initial_conf
local tmp_text = "Please provide your new NPC with a name and description!"
local tmp_owner = (yl_speak_up.npc_owner[ n_id ] or "- none -")
local table_of_names = {}
local may_be_edited_by = ""
-- use existing name and description as presets when just editing
if(not(is_initial_config)) then
local dialog = yl_speak_up.speak_to[pname].dialog
@ -233,6 +229,22 @@ yl_speak_up.get_fs_initial_config = function(player, n_id, d_id, is_initial_conf
dialog.n_may_edit = {}
end
table_of_names = dialog.n_may_edit
may_be_edited_by =
-- who can edit this NPC?
"label[0.2,4.05;May be edited by:]"..
-- offer a dropdown list and a text input field for player names for adding
yl_speak_up.create_dropdown_playerlist(player, pname,
table_of_names, yl_speak_up.speak_to[pname].tmp_index,
2.5, 3.9, 0.0, "list_may_edit", "player", "Remove player from list",
"add_may_edit",
"Enter the name of the player whom you\n"..
"want to grant the right to edit your NPC.\n"..
"The player needs at least the npc_talk_owner priv\n"..
"in order to actually edit the NPC.",
"delete_may_edit",
"If you click here, the player will no\n"..
"longer be able to edit your NPC."
)
end
local formspec = "size[10,6]"..
"label[0.2,0.2;"..tmp_text.."]"..
@ -249,21 +261,7 @@ yl_speak_up.get_fs_initial_config = function(player, n_id, d_id, is_initial_conf
"field[2.0,3.2;8,0.9;n_owner;;"..minetest.formspec_escape(tmp_owner).."]"..
"tooltip[n_owner;The owner of the NPC. This can only be changed\n"..
"if you have the npc_talk_master priv.;#FFFFFF;#000000]"..
-- who can edit this NPC?
"label[0.2,4.05;May be edited by:]"..
-- offer a dropdown list and a text input field for player names for adding
yl_speak_up.create_dropdown_playerlist(player, pname,
table_of_names, yl_speak_up.speak_to[pname].tmp_index,
2.5, 3.9, 0.0, "list_may_edit", "player", "Remove player from list",
"add_may_edit",
"Enter the name of the player whom you\n"..
"want to grant the right to edit your NPC.\n"..
"The player needs at least the npc_talk_owner priv\n"..
"in order to actually edit the NPC.",
"delete_may_edit",
"If you click here, the player will no\n"..
"longer be able to edit your NPC."
)..
may_be_edited_by..
-- save and exit buttons
"button_exit[3.2,5.2;2,0.9;save_initial_config;Save]"..
"button_exit[5.4,5.2;2,0.9;exit;Exit]"