From 54abad72f0e866f68b88d2fba5768739e26b388a Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Wed, 12 Dec 2018 20:18:53 +0100 Subject: [PATCH] Add item tooltips with mod name Inspired by #118, @Quent42340 --- internal.lua | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/internal.lua b/internal.lua index 06967d2..3fad275 100644 --- a/internal.lua +++ b/internal.lua @@ -223,7 +223,8 @@ function unified_inventory.get_formspec(player, page) for y = 0, ui_peruser.pagerows - 1 do for x = 0, ui_peruser.pagecols - 1 do local name = unified_inventory.filtered_items_list[player_name][list_index] - if minetest.registered_items[name] then + local item = minetest.registered_items[name] + if item then -- Clicked on current item: Flip crafting direction if name == unified_inventory.current_item[player_name] then local cdir = unified_inventory.current_craft_direction[player_name] @@ -236,12 +237,18 @@ function unified_inventory.get_formspec(player, page) -- Default: use active search direction by default dir = unified_inventory.active_search_direction[player_name] end - formspec[n] = "item_image_button[" - ..(8.2 + x * 0.7).."," - ..(ui_peruser.formspec_y + ui_peruser.page_y + y * 0.7)..";.81,.81;" - ..name..";item_button_"..dir.."_" - ..unified_inventory.mangle_for_formspec(name)..";]" - n = n+1 + + local button_name = "item_button_" .. dir .. "_" + .. unified_inventory.mangle_for_formspec(name) + formspec[n] = ("item_image_button[%f,%f;.81,.81;%s;%s;]"):format( + 8.2 + x * 0.7, ui_peruser.formspec_y + ui_peruser.page_y + y * 0.7, + name, button_name + ) + formspec[n + 1] = ("tooltip[%s;%s \\[%s\\]]"):format( + button_name, minetest.formspec_escape(item.description), + item.mod_origin or "??" + ) + n = n + 2 list_index = list_index + 1 end end