From 43c9b5080031093f86530c38fa613cd4e79dd625 Mon Sep 17 00:00:00 2001 From: fmmaks <108734737+fmmaks666@users.noreply.github.com> Date: Sun, 15 Oct 2023 22:02:35 +0300 Subject: [PATCH] Add `unified_inventory_enable_item_names` setting (#235) Show only names settings: in case of multi-line descriptions, only the first line is shown Shorten long descriptions: Removes all characters after x index, and add `[...]` Max length before truncation: x for Shorten long descriptions Notes: If Max length == 0, then item names won't be displayed --- init.lua | 5 +++-- item_names.lua | 11 +++++++++++ settingtypes.txt | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 4a09b324..8f91acad 100644 --- a/init.lua +++ b/init.lua @@ -191,7 +191,8 @@ dofile(modpath.."/register.lua") if minetest.settings:get_bool("unified_inventory_bags") ~= false then dofile(modpath.."/bags.lua") end - -dofile(modpath.."/item_names.lua") +if minetest.settings:get_bool("unified_inventory_item_names") ~= false then + dofile(modpath.."/item_names.lua") +end dofile(modpath.."/waypoints.lua") dofile(modpath.."/legacy.lua") -- mod compatibility diff --git a/item_names.lua b/item_names.lua index a1368f88..cb9f2a3f 100644 --- a/item_names.lua +++ b/item_names.lua @@ -3,6 +3,8 @@ local item_names = {} -- [player_name] = { hud, dtime, itemname } local dlimit = 3 -- HUD element will be hidden after this many seconds local hudbars_mod = minetest.get_modpath("hudbars") +local only_names = minetest.settings:get_bool("unified_inventory_only_names", true) +local max_length = tonumber(minetest.settings:get("unified_inventory_max_item_name_length")) or 80 local function set_hud(player) local player_name = player:get_player_name() @@ -60,6 +62,7 @@ minetest.register_globalstep(function(dtime) data.itemname = itemname data.index = index data.dtime = 0 + local lang_code = minetest.get_player_information(player:get_player_name()).lang_code local desc = stack.get_meta and stack:get_meta():get_string("description") @@ -69,6 +72,14 @@ minetest.register_globalstep(function(dtime) local def = minetest.registered_items[itemname] desc = def and def.description or "" end + if only_names and desc and string.find(desc, "\n") then + desc = string.match(desc, "([^\n]*)") + end + desc = minetest.get_translated_string(lang_code, desc) + desc = minetest.strip_colors(desc) + if string.len(desc) > max_length and max_length > 0 then + desc = string.sub(desc, 1, max_length) .. " [...]" + end player:hud_change(data.hud, 'text', desc) end end diff --git a/settingtypes.txt b/settingtypes.txt index 5ab7f84a..83190a9e 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -15,3 +15,9 @@ unified_inventory_hide_disabled_buttons (Hide disabled buttons) bool false unified_inventory_automatic_categorization (Items automatically added to categories) bool true + +unified_inventory_item_names (Item names are shown above hotbar) bool true + +unified_inventory_only_names (Show only item name) bool true + +unified_inventory_max_item_name_length (Maximum length of an item name before it's truncated, 0 disables option) int 80