diff --git a/api/formspec_helpers.lua b/editor/api/formspec_helpers.lua similarity index 100% rename from api/formspec_helpers.lua rename to editor/api/formspec_helpers.lua diff --git a/editor/edit_mode.lua b/editor/edit_mode.lua index 5063e27..25dcb01 100644 --- a/editor/edit_mode.lua +++ b/editor/edit_mode.lua @@ -138,6 +138,7 @@ yl_speak_up.add_to_command_help_text = yl_speak_up.add_to_command_help_text.. dofile(modpath .. "fs/fs_edit_options_dialog.lua") -- -- set name, description and owner (owner only with npc_talk_master priv) -- dofile(modpath .. "fs/fs_initial_config.lua") + dofile(modpath .. "fs/fs_initial_config_in_edit_mode.lua") -- -- inspect and accept items the player gave to the NPC -- dofile(modpath .. "fs/fs_player_offers_item.lua") -- -- inventory management, trading and handling of quest items: diff --git a/editor/fs/fs_initial_config_in_edit_mode.lua b/editor/fs/fs_initial_config_in_edit_mode.lua new file mode 100644 index 0000000..0bdae79 --- /dev/null +++ b/editor/fs/fs_initial_config_in_edit_mode.lua @@ -0,0 +1,42 @@ + + +-- add option to show, add and delete other players who may edit this npc; +-- add buttons for skin change and editing properties +local old_get_fs_initial_config = yl_speak_up.get_fs_initial_config +yl_speak_up.get_fs_initial_config = function(player, n_id, d_id, is_initial_config, add_formspec) + -- nothing to add if this is the initial configuration + if(is_initial_config) then + return old_get_fs_initial_config(player, n_id, d_id, is_initial_config, nil) + end + + local pname = player:get_player_name() + local dialog = yl_speak_up.speak_to[pname].dialog + -- dialog.n_may_edit was a string for a short time in development + if(not(dialog.n_may_edit) or type(dialog.n_may_edit) ~= "table") then + dialog.n_may_edit = {} + end + local table_of_names = dialog.n_may_edit + local may_be_edited_by = { + -- these buttons and formspecs are provided by the editor: + "button[1.0,5.5;4,0.9;edit_skin;Edit Skin]", + "button[6.0,5.5;4,0.9;edit_properties;Edit Properties]", + -- who can edit this NPC? + "label[0.2,4.75;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, + 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.\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." + )} + -- show the formspec to the player + return old_get_fs_initial_config(player, n_id, d_id, is_initial_config, may_be_edited_by) +end diff --git a/fs/fs_initial_config.lua b/fs/fs_initial_config.lua index f765f42..a1fdbb7 100644 --- a/fs/fs_initial_config.lua +++ b/fs/fs_initial_config.lua @@ -119,7 +119,7 @@ yl_speak_up.input_fs_initial_config = function(player, formname, fields) yl_speak_up.speak_to[pname].tmp_index = index + 1 end end - -- selected a player name in the why may edit this NPC dropdown? + -- selected a player name in the woy may edit this NPC dropdown? elseif(fields.list_may_edit and fields.list_may_edit ~= "") then local tmp_list = yl_speak_up.sort_keys(dialog.n_may_edit, true) local index = table.indexof(tmp_list, fields.list_may_edit) @@ -301,7 +301,8 @@ end -- initialize the npc without having to use a staff; -- returns true when initialization possible -yl_speak_up.get_fs_initial_config = function(player, n_id, d_id, is_initial_config) +-- the entries from add_formspec are added to the output +yl_speak_up.get_fs_initial_config = function(player, n_id, d_id, is_initial_config, add_formspec) local pname = player:get_player_name() -- is the player allowed to edit this npc? @@ -316,8 +317,6 @@ yl_speak_up.get_fs_initial_config = function(player, n_id, d_id, is_initial_conf local tmp_descr = "A new NPC without description" 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 @@ -325,56 +324,51 @@ yl_speak_up.get_fs_initial_config = function(player, n_id, d_id, is_initial_conf tmp_name = (dialog.n_npc or tmp_name) tmp_descr = (dialog.n_description or tmp_descr) tmp_text = "You can change the name and description of your NPC." - -- dialog.n_may_edit was a string for a short time in development - if(not(dialog.n_may_edit) or type(dialog.n_may_edit) ~= "table") then - 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.75;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, - 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.\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." - ) end - local formspec = "size[11,8.0]".. - "label[0.2,0.5;"..tmp_text.."]".. + local formspec = {"size[11,8.0]", + "label[0.2,0.5;", + tmp_text, + "]", -- name of the npc - "checkbox[2.2,0.9;show_nametag;;"..tostring(tmp_show_nametag).."]".. - "label[2.7,0.9;Show nametag]".. - "label[0.2,1.65;Name:]".. - "field[2.2,1.2;4,0.9;n_npc;;"..minetest.formspec_escape(tmp_name).."]".. - "label[7.0,1.65;NPC ID: "..minetest.colorize("#FFFF00",tostring(n_id)).."]".. - "tooltip[n_npc;n_npc: The name of the NPC;#FFFFFF;#000000]".. + "checkbox[2.2,0.9;show_nametag;;", + tostring(tmp_show_nametag), + "]", + "label[2.7,0.9;Show nametag]", + "label[0.2,1.65;Name:]", + "field[2.2,1.2;4,0.9;n_npc;;", + minetest.formspec_escape(tmp_name), + "]", + "label[7.0,1.65;NPC ID: ", + minetest.colorize("#FFFF00",tostring(n_id)), + "]", + "tooltip[n_npc;n_npc: The name of the NPC;#FFFFFF;#000000]", -- description of the npc - "label[0.2,2.65;Description:]".. - "field[2.2,2.2;8,0.9;n_description;;"..minetest.formspec_escape(tmp_descr).."]".. - "tooltip[n_description;n_description: A description for the NPC;#FFFFFF;#000000]".. + "label[0.2,2.65;Description:]", + "field[2.2,2.2;8,0.9;n_description;;", + minetest.formspec_escape(tmp_descr), + "]", + "tooltip[n_description;n_description: A description for the NPC;#FFFFFF;#000000]", -- the owner of the NPC - "label[0.2,3.65;Owner:]".. - "field[2.2,3.2;8,0.9;n_owner;;"..minetest.formspec_escape(tmp_owner).."]".. + "label[0.2,3.65;Owner:]", + "field[2.2,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]".. - may_be_edited_by.. - "button[1.0,5.5;4,0.9;edit_skin;Edit Skin]".. - "button[6.0,5.5;4,0.9;edit_properties;Edit Properties]".. + "if you have the npc_talk_master priv.;#FFFFFF;#000000]", -- save and exit buttons - "button[3.2,7.0;2,0.9;save_initial_config;Save]".. + "button[3.2,7.0;2,0.9;save_initial_config;Save]", "button_exit[5.4,7.0;2,0.9;exit;Exit]" + } + -- add some entries in edit mode + if(add_formspec) then + for _, v in ipairs(add_formspec) do + table.insert(formspec, v) + end + elseif(not(is_initial_config)) then + -- TODO: add import/export/show texture? + end -- show the formspec to the player - return formspec + return table.concat(formspec, "") end @@ -382,7 +376,7 @@ yl_speak_up.get_fs_initial_config_wrapper = function(player, param) if(not(param)) then param = {} end - return yl_speak_up.get_fs_initial_config(player, param.n_id, param.d_id, param.is_initial_config) + return yl_speak_up.get_fs_initial_config(player, param.n_id, param.d_id, param.is_initial_config, nil) end yl_speak_up.register_fs("initial_config",