From e33f713f54a4729a735ea5f169dfbc08461faf67 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Tue, 4 Jan 2022 01:30:33 +0100 Subject: [PATCH] added yl_speak_up.fs_your_inventory_select_item to avoid repetition --- fs_edit_general.lua | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/fs_edit_general.lua b/fs_edit_general.lua index 0fb4b65..3d994bd 100644 --- a/fs_edit_general.lua +++ b/fs_edit_general.lua @@ -73,6 +73,21 @@ minetest.register_chatcommand( 'npc_talk_debug', { }); +-- helper function; get a formspec with the inventory of the player (for selecting items) +yl_speak_up.fs_your_inventory_select_item = function(pname, data) + return "label[0.2,4.2;Name of the item(stack):]".. + "field[4.0,4.0;16.0,0.6;inv_stack_name;;"..(data.inv_stack_name or "").."]".. + "tooltip[inv_stack_name;Enter name of the block and amount.\n".. + "Example: \"default:apple 3\" for three apples,\n".. + " \"farming:bread\" for a bread.]".. + "label[0.2,5.7;Or put the item in here\nand click on \"Update\":]".. + "button[5.5,5.5;1.5,0.9;store_item_name;Update]".. + "list[detached:yl_speak_up_player_"..pname..";npc_wants;4.0,5.5;1,1;]".. + "label[8,4.9;Your inventory:]".. + "list[current_player;main;8,5.3;8,4;]" +end + + -- helper function: get the names of the inventory lists of the node at position -- pos on the map and return the index of search_for_list_name in that index yl_speak_up.get_node_inv_lists = function(pos, search_for_list_name) @@ -1731,16 +1746,7 @@ yl_speak_up.get_fs_edit_option_precondition_inv = function( end return formspec.. intro.. - "label[0.2,4.2;Name of the item(stack):]".. - "field[4.0,4.0;16.0,0.6;inv_stack_name;;"..(data.inv_stack_name or "").."]".. - "tooltip[inv_stack_name;Enter name of the block and amount.\n".. - "Example: \"default:apple 3\" for three apples,\n".. - " \"farming:bread\" for a bread.]".. - "label[0.2,5.7;Or put the item in here\nand click on \"Store\":]".. - "button[5.5,5.5;1.5,0.9;store_item_name;Store]".. - "list[detached:yl_speak_up_player_"..pname..";npc_wants;4.0,5.5;1,1;]".. - "label[8,4.9;Your inventory:]".. - "list[current_player;main;8,5.3;8,4;]".. + yl_speak_up.fs_your_inventory_select_item(pname, data).. block_selection.. save_button end @@ -1763,16 +1769,7 @@ yl_speak_up.get_fs_edit_option_effect_give_item_or_take_item = function( "label[0.2,3.0;"..text.."]".. "label[0.2,3.5;Note: You can *save* this effect only if you have the ".. "\"npc_master\" priv!]".. - "label[0.2,4.2;Name of the item(stack):]".. - "field[4.0,4.0;16.0,0.6;inv_stack_name;;"..(data.inv_stack_name or "").."]".. - "tooltip[inv_stack_name;Enter name of the block and amount.\n".. - "Example: \"default:apple 3\" for three apples,\n".. - " \"farming:bread\" for a bread.]".. - "label[0.2,5.7;Or put the item in here\nand click on \"Store\":]".. - "button[5.5,5.5;1.5,0.9;store_item_name;Store]".. - "list[detached:yl_speak_up_player_"..pname..";npc_wants;4.0,5.5;1,1;]".. - "label[8,4.9;Your inventory:]".. - "list[current_player;main;8,5.3;8,4;]".. + yl_speak_up.fs_your_inventory_select_item(pname, data).. save_button end