From 80b47889ecb86d3c7c0a160de1af7b24f3befaed Mon Sep 17 00:00:00 2001 From: Sokomine Date: Fri, 21 Jul 2023 20:35:22 +0200 Subject: [PATCH] added additional info to /npc_talk list --- fs_npc_list.lua | 85 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 8 deletions(-) diff --git a/fs_npc_list.lua b/fs_npc_list.lua index 38d8799..62e69c5 100644 --- a/fs_npc_list.lua +++ b/fs_npc_list.lua @@ -166,6 +166,11 @@ yl_speak_up.input_show_npc_list = function(player, formname, fields) yl_speak_up.show_fs_ver(pname, "yl_speak_up:show_npc_list", yl_speak_up.get_fs_show_npc_list(pname, nil)) return + else + -- show details about a specific NPC + yl_speak_up.show_fs_ver(pname, "yl_speak_up:show_npc_list", + yl_speak_up.get_fs_show_npc_list(pname, selected.row)) + return end end return @@ -257,7 +262,7 @@ end -- allow to toggle between trade entries and full log -- Note: takes pname instead of player(object) as first parameter -yl_speak_up.get_fs_show_npc_list = function(pname, param) +yl_speak_up.get_fs_show_npc_list = function(pname, selected_row) -- which NPC can the player edit? local level = 0 if( minetest.check_player_privs(pname, {npc_master=true}) @@ -271,7 +276,7 @@ yl_speak_up.get_fs_show_npc_list = function(pname, param) return "size[5,1]label[0,0;Error: You do not have the npc_talk_owner priv.]" end - local formspec_start = 'size[18,12]'.. + local formspec_start = 'size[18,14.7]'.. -- 'button[0.5,11.1;17,0.8;', -- back_link, -- ']'.. @@ -290,12 +295,75 @@ yl_speak_up.get_fs_show_npc_list = function(pname, param) 'color;text,align=center;'.. -- last known position 'color;text,align=center]'.. -- does he have extra privs? 'table[0.1,1.0;17.8,9.8;show_npc_list;' + -- add information about a specific NPC (selected row) + local info_current_row = '' + if(selected_row + and selected_row > 1 + and yl_speak_up.cache_npc_list_per_player[pname] + and yl_speak_up.cache_npc_list_per_player[pname][selected_row-1]) then + local k = yl_speak_up.cache_npc_list_per_player[pname][selected_row-1] + local data = yl_speak_up.npc_list[k] + local line = yl_speak_up.cache_general_npc_list_lines[k] + if(data) then + local edit_list = {data.owner} + if(data.may_edit) then + for e, t in pairs(data.may_edit or {}) do + table.insert(edit_list, e) + end + end + local n_id = 'n_'..tostring(k) + local priv_list = {} + if(yl_speak_up.npc_priv_table[n_id]) then + for priv, has_it in pairs(yl_speak_up.npc_priv_table[n_id]) do + table.insert(priv_list, priv) + end + else + priv_list = {'- none -'} + end + local prop_text = 'label[3.0,2.0;- none -]' + if(data.properties) then + local prop_list = {} + for k, v in pairs(data.properties) do + table.insert(prop_list, minetest.formspec_escape( + tostring(k)..' = '..tostring(v))) + end + if(#prop_list > 0) then + prop_text = 'dropdown[3.0,1.8;8,0.6;properties;'.. + table.concat(prop_list, ',')..';;]' + end + end +-- TODO is_generic +-- TODO edit, visit button + info_current_row = + 'container[0.1,11.2]'.. + 'label[0.1,0.0;Name, Desc:]'.. + 'label[3.0,0.0;'..tostring(line.n_name)..']'.. + 'label[0.1,0.5;Typ:]'.. + 'label[3.0,0.5;'.. + minetest.formspec_escape(tostring(data.typ or '- ? -'))..']'.. + 'label[10.1,0.5;First seen at:]'.. + 'label[13.1,0.5;'.. + minetest.formspec_escape(tostring(data.created_at or '- ? -'))..']'.. + 'label[0.1,1.0;Can be edited by:]'.. + 'label[3.0,1.0;'.. + minetest.formspec_escape(table.concat(edit_list, ', '))..']'.. + 'label[0.1,1.5;Has the privs:]'.. + 'label[3.0,1.5;'.. + minetest.formspec_escape(table.concat(priv_list, ', '))..']'.. + 'label[0.1,2.0;Properties:]'.. + prop_text.. + 'container_end[]' + end + else + selected_row = 1 + info_current_row = 'label[0.1,11.2;Click on a column name/header in order to sort by '.. + 'that column.\nClick it again in order to reverse sort order.\n'.. + 'Click on a row to get more information about a specific NPC.\n'.. + 'Only NPC that can be edited by you are shown.]' + end local formspec = {} -- TODO: blocks may also be talked to - -- TODO desc as mouseover?, created_at? - -- TODO: created_at, typ (race?)? - local tmp_liste = {} for k, v in pairs(yl_speak_up.npc_list) do @@ -343,7 +411,7 @@ yl_speak_up.get_fs_show_npc_list = function(pname, param) table.insert(formspec, k) end end - yl_speak_up.cache_npc_list_per_player = tmp_list + yl_speak_up.cache_npc_list_per_player[pname] = tmp_liste for i, k in ipairs(tmp_liste) do local data = yl_speak_up.npc_list[k] @@ -374,8 +442,9 @@ yl_speak_up.get_fs_show_npc_list = function(pname, param) table.insert(formspec, line.is_loaded_color) table.insert(formspec, line.priv_list) end - table.insert(formspec, ";1]") - return formspec_start..table.concat(formspec, ',') + table.insert(formspec, ";"..selected_row.."]") + return formspec_start..table.concat(formspec, ',')..info_current_row.. + 'button_exit[0.1,14;19.6,0.6;exit;Exit]' end