From e04a6b963e4dcaef9f39d7dc2fce42c1f626d1ec Mon Sep 17 00:00:00 2001 From: Sokomine Date: Wed, 3 May 2023 22:07:23 +0200 Subject: [PATCH] fixed adding/removing players to may_be_edited_by; fixed logging of name/desc changes --- fs_initial_config.lua | 51 +++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/fs_initial_config.lua b/fs_initial_config.lua index 19b016d..9d7979d 100644 --- a/fs_initial_config.lua +++ b/fs_initial_config.lua @@ -26,7 +26,11 @@ yl_speak_up.input_fs_initial_config = function(player, formname, fields) return end - if((not(fields.save_initial_config) and not(fields.show_nametag)) or (fields and fields.exit)) then + if((not(fields.save_initial_config) + and not(fields.show_nametag) + and not(fields.list_may_edit) + and not(fields.add_may_edit) + ) 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 @@ -204,20 +208,30 @@ yl_speak_up.input_fs_initial_config = function(player, formname, fields) "Initial config saved. ".. "NPC name: \""..tostring(fields.n_npc).. "\" Description: \""..tostring(fields.n_description).."\".") + elseif(fields.add_may_edit and fields.add_may_edit ~= "") then + yl_speak_up.log_change(pname, n_id, + "Added to \"may be edited by\": "..tostring(fields.add_may_edit)) + elseif(fields.delete_may_edit and fields.delete_may_edit ~= "" + and fields.list_may_edit and fields.list_may_edit ~= "") then + yl_speak_up.log_change(pname, n_id, + "Removed from \"may be edited by\": "..tostring(fields.list_may_edit)) -- just change name and description elseif((fields.n_npc and fields.n_npc ~= "") or (fields.n_description and fields.n_description ~= "")) then dialog = yl_speak_up.speak_to[pname].dialog - dialog.n_npc = fields.n_npc - dialog.n_description = fields.n_description - yl_speak_up.save_dialog(n_id, dialog) + if(dialog.n_npc ~= fields.n_npc + or dialog.n_description ~= fields.n_description) then + dialog.n_npc = fields.n_npc + dialog.n_description = fields.n_description + yl_speak_up.save_dialog(n_id, dialog) - yl_speak_up.log_change(pname, n_id, - "Name and/or description changed. ".. - "NPC name: \""..tostring(fields.n_npc).. - "\" Description: \""..tostring(fields.n_description).. - "\" May be edited by: \"".. - table.concat(yl_speak_up.sort_keys(dialog.n_may_edit, true), " ").."\".") + yl_speak_up.log_change(pname, n_id, + "Name and/or description changed. ".. + "NPC name: \""..tostring(fields.n_npc).. + "\" Description: \""..tostring(fields.n_description).. + "\" May be edited by: \"".. + table.concat(yl_speak_up.sort_keys(dialog.n_may_edit, true), " ").."\".") + end end dialog = yl_speak_up.speak_to[pname].dialog @@ -263,8 +277,15 @@ yl_speak_up.input_fs_initial_config = function(player, formname, fields) {n_id = n_id, d_id = yl_speak_up.speak_to[pname].d_id, false}) return end - -- actually start a chat with our new npc - yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = d_id}) + if((fields.add_may_edit and fields.add_may_edit ~= "") + or (fields.delete_may_edit and fields.delete_may_edit ~= "")) then + -- show this formspec again + yl_speak_up.show_fs(player, "initial_config", + {n_id = n_id, d_id = yl_speak_up.speak_to[pname].d_id, false}) + else + -- actually start a chat with our new npc + yl_speak_up.show_fs(player, "talk", {n_id = n_id, d_id = d_id}) + end end @@ -305,12 +326,14 @@ yl_speak_up.get_fs_initial_config = function(player, n_id, d_id, is_initial_conf -- 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, - 3.0, 4.3, 0.0, 1.0, "list_may_edit", "player", "Remove player from list", + 3.0, 4.3, 0.0, 1.0, "list_may_edit", "player", + "Remove selected\nplayer 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.", + "in order to actually edit the NPC.\n".. + "Click on \"Save\" to add the new player.", "delete_may_edit", "If you click here, the player will no\n".. "longer be able to edit your NPC."