mirror of
git://repo.or.cz/minetest_inventory_icon.git
synced 2025-01-10 07:20:17 +01:00
Apply correct bag color for full bags right from the beginning
This commit is contained in:
parent
f207fcf5b2
commit
c1728a7050
7
init.lua
7
init.lua
@ -1,6 +1,8 @@
|
|||||||
inventory_icon = {}
|
inventory_icon = {}
|
||||||
inventory_icon.hudids = {}
|
inventory_icon.hudids = {}
|
||||||
|
|
||||||
|
inventory_icon.COLORIZE_STRING = "[colorize:#A00000:192"
|
||||||
|
|
||||||
function inventory_icon.get_inventory_state(inv, listname)
|
function inventory_icon.get_inventory_state(inv, listname)
|
||||||
local size = inv:get_size(listname)
|
local size = inv:get_size(listname)
|
||||||
local occupied = 0
|
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")
|
local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents")
|
||||||
text = string.format("%d/%d", occupied, size)
|
text = string.format("%d/%d", occupied, size)
|
||||||
icon = minetest.registered_items[bag:get_name()].inventory_image
|
icon = minetest.registered_items[bag:get_name()].inventory_image
|
||||||
|
if occupied >= size then
|
||||||
|
icon = icon .. "^" .. inventory_icon.COLORIZE_STRING
|
||||||
|
end
|
||||||
end
|
end
|
||||||
inventory_icon.hudids[name].bags[i] = {}
|
inventory_icon.hudids[name].bags[i] = {}
|
||||||
inventory_icon.hudids[name].bags[i].icon = player:hud_add({
|
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)
|
text = string.format("%d/%d", occupied, size)
|
||||||
icon = minetest.registered_items[bag:get_name()].inventory_image
|
icon = minetest.registered_items[bag:get_name()].inventory_image
|
||||||
if occupied >= size then
|
if occupied >= size then
|
||||||
icon = icon .. "^[colorize:#A00000:192"
|
icon = icon .. "^" .. inventory_icon.COLORIZE_STRING
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
player:hud_change(inventory_icon.hudids[playername].bags[i].icon, "text", icon)
|
player:hud_change(inventory_icon.hudids[playername].bags[i].icon, "text", icon)
|
||||||
|
Loading…
Reference in New Issue
Block a user