Apply correct bag color for full bags right from the beginning

This commit is contained in:
Wuzzy 2015-06-23 21:40:03 +02:00
parent f207fcf5b2
commit c1728a7050

View File

@ -1,6 +1,8 @@
inventory_icon = {}
inventory_icon.hudids = {}
inventory_icon.COLORIZE_STRING = "[colorize:#A00000:192"
function inventory_icon.get_inventory_state(inv, listname)
local size = inv:get_size(listname)
local occupied = 0
@ -55,6 +57,9 @@ minetest.register_on_joinplayer(function(player)
local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents")
text = string.format("%d/%d", occupied, size)
icon = minetest.registered_items[bag:get_name()].inventory_image
if occupied >= size then
icon = icon .. "^" .. inventory_icon.COLORIZE_STRING
end
end
inventory_icon.hudids[name].bags[i] = {}
inventory_icon.hudids[name].bags[i].icon = player:hud_add({
@ -113,7 +118,7 @@ minetest.register_globalstep(function(dtime)
text = string.format("%d/%d", occupied, size)
icon = minetest.registered_items[bag:get_name()].inventory_image
if occupied >= size then
icon = icon .. "^[colorize:#A00000:192"
icon = icon .. "^" .. inventory_icon.COLORIZE_STRING
end
end
player:hud_change(inventory_icon.hudids[playername].bags[i].icon, "text", icon)