Skip to content

Commit

Permalink
Add unified_inventory_enable_item_names setting (#235)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fmmaks666 authored Oct 15, 2023
1 parent 5d233a0 commit 43c9b50
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions item_names.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 43c9b50

Please sign in to comment.