mirror of
https://github.com/minetest-mods/unified_inventory.git
synced 2024-12-27 19:20:27 +01:00
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
This commit is contained in:
parent
5d233a0f0a
commit
43c9b50800
5
init.lua
5
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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user