diff --git a/formspec_helpers.lua b/formspec_helpers.lua new file mode 100644 index 0000000..6babbd5 --- /dev/null +++ b/formspec_helpers.lua @@ -0,0 +1,41 @@ + +-- helper function: +-- create a formspec dropdown list with player names (first entry: Add player) and +-- an option to delete players from that list +yl_speak_up.create_dropdown_playerlist = function(player, pname, + table_of_names, index_selected, + start_x, start_y, dropdown_name, + field_name_for_adding_player, explain_add_player, + field_name_for_deleting_player, explain_delete_player) + + local text = "dropdown["..tostring(start_x)..","..tostring(start_y)..";3.8;".. + tostring(dropdown_name)..";Add player:" + -- table_of_names is a table with the playernames as keys + -- we want to work with indices later on; in order to be able to do that reliably, we + -- need a defined order of names + local tmp_list = yl_speak_up.sort_keys(table_of_names, true) + for i, p in ipairs(tmp_list) do + text = text..","..minetest.formspec_escape(p) + end + -- has an entry been selected? + if(not(index_selected) or index_selected < 0 or index_selected > #tmp_list+1) then + index_selected = 1 + end + text = text..";"..tostring(index_selected)..";]" + if(index_selected == 1) then + -- first index "Add player" selected? Then offer a field for entering the name + text = text.."field["..tostring(start_x + 4.0)..","..tostring(start_y + 0.3)..";3.5,0.9;".. + tostring(field_name_for_adding_player)..";;]".. + "tooltip["..tostring(field_name_for_adding_player)..";".. + "Enter the name of the player whom you\n".. + "want to grant the right to "..tostring(explain_add_player).."]" + else + text = text.."button["..tostring(start_x + 3.8)..","..tostring(start_y)..";3.5,0.9;".. + tostring(field_name_for_deleting_player)..";".. + "Remove player from list]".. + "tooltip["..tostring(field_name_for_deleting_player)..";".. + "If you click here, the player will no\n".. + "longer be able to "..tostring(explain_delete_player).."]" + end + return text +end diff --git a/init.lua b/init.lua index 96f138d..96176f2 100644 --- a/init.lua +++ b/init.lua @@ -29,6 +29,8 @@ dofile(modpath .. "fs_save_or_discard_or_back.lua") dofile(modpath .. "custrom_functions_you_can_override.lua") -- some helper functions for formatting text for a formspec talbe dofile(modpath .. "print_as_table.lua") +-- create i.e. a dropdown list of player names +dofile(modpath .. "formspec_helpers.lua") -- handle alternate text for dialogs dofile(modpath .. "fs_alternate_text.lua") -- common functions for editing preconditions and effects diff --git a/quest_api.lua b/quest_api.lua index 5e29f0a..a77c666 100644 --- a/quest_api.lua +++ b/quest_api.lua @@ -277,6 +277,7 @@ end -- the dialog data of an NPC is saved - use this to save some statistical data -- plus store which variables are used by this NPC +-- TODO: show this data in a formspec to admins for maintenance yl_speak_up.update_stored_npc_data = function(n_id, dialog) -- in order to determine the position of the NPC, we need its object local pname = yl_speak_up.get_pname_for_n_id(n_id) @@ -345,6 +346,7 @@ yl_speak_up.update_stored_npc_data = function(n_id, dialog) n_id = n_id, name = tostring(dialog.n_npc), owner = tostring(yl_speak_up.npc_owner[ n_id ]), + may_edit = dialog.n_may_edit or {}, pos = tostring(npc_pos), anz_dialogs = anz_dialogs, anz_options = anz_options,