Optimizations and Fixes for long descriptions
Added: - 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
c95fdccbd9
commit
58ba2fae61
2
init.lua
2
init.lua
|
@ -191,7 +191,7 @@ dofile(modpath.."/register.lua")
|
|||
if minetest.settings:get_bool("unified_inventory_bags") ~= false then
|
||||
dofile(modpath.."/bags.lua")
|
||||
end
|
||||
if minetest.settings:get_bool("unified_inventory_enable_item_names") ~= false then
|
||||
if minetest.settings:get_bool("unified_inventory_item_names") ~= false then
|
||||
dofile(modpath.."/item_names.lua")
|
||||
end
|
||||
dofile(modpath.."/waypoints.lua")
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
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")
|
||||
local shorten_names = minetest.settings:get_bool("unified_inventory_shorten_names")
|
||||
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()
|
||||
|
@ -69,6 +72,20 @@ 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
|
||||
if shorten_names and string.len(desc) > max_length then
|
||||
local prefix_end = string.find(desc, ")") -- Some items have prefix: @#35cdff)Desert Eagle, @default)Locked Chest
|
||||
if not prefix_end then
|
||||
prefix_end = 1
|
||||
end
|
||||
if max_length > 0 then
|
||||
desc = string.sub(desc, prefix_end + 1 , max_length + prefix_end) .. " [...]"
|
||||
else
|
||||
desc = ""
|
||||
end
|
||||
end
|
||||
player:hud_change(data.hud, 'text', desc)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,4 +16,10 @@ unified_inventory_hide_disabled_buttons (Hide disabled buttons) bool false
|
|||
|
||||
unified_inventory_automatic_categorization (Items automatically added to categories) bool true
|
||||
|
||||
unified_inventory_enable_item_names (Item names are shown above hotbar) 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_shorten_names (Shorten long item names) bool true
|
||||
|
||||
unified_inventory_max_item_name_length (Maximum length of an item name before it's truncated) int 80
|
||||
|
|
Loading…
Reference in New Issue