1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-24 17:50:37 +01:00

[inventory_icon] Use minetest.after (already-used 1s delay)

This commit is contained in:
Wouters Dorian 2015-07-31 14:58:28 +02:00
parent a6faed9f94
commit f94ecd5fd8

View File

@ -91,48 +91,46 @@ minetest.register_on_leaveplayer(function(player)
inventory_icon.hudids[player:get_player_name()] = nil inventory_icon.hudids[player:get_player_name()] = nil
end) end)
inventory_icon.timer = 0 local function tick()
minetest.register_globalstep(function(dtime) minetest.after(1, tick)
inventory_icon.timer = inventory_icon.timer + dtime for playername,hudids in pairs(inventory_icon.hudids) do
if inventory_icon.timer > 1 then local player = minetest.get_player_by_name(playername)
for playername,hudids in pairs(inventory_icon.hudids) do local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "main")
local player = minetest.get_player_by_name(playername) local icon, color
local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "main") if occupied >= size then
local icon, color icon = "inventory_icon_backpack_full.png"
if occupied >= size then else
icon = "inventory_icon_backpack_full.png" icon = "inventory_icon_backpack_free.png"
else end
icon = "inventory_icon_backpack_free.png" player:hud_change(hudids.main.icon, "text", icon)
end player:hud_change(hudids.main.text, "text", string.format("%d/%d", occupied, size))
player:hud_change(hudids.main.icon, "text", icon)
player:hud_change(hudids.main.text, "text", string.format("%d/%d", occupied, size))
if minetest.get_modpath("unified_inventory") ~= nil then if minetest.get_modpath("unified_inventory") ~= nil then
local bags_inv = minetest.get_inventory({type = "detached", name = playername.."_bags"}) local bags_inv = minetest.get_inventory({type = "detached", name = playername.."_bags"})
for i=1,4 do for i=1,4 do
local bag = bags_inv:get_stack("bag"..i, 1) local bag = bags_inv:get_stack("bag"..i, 1)
local scale, text, icon local scale, text, icon
if bag:is_empty() then if bag:is_empty() then
scale = { x = 0, y = 0 } scale = { x = 0, y = 0 }
text = "" text = ""
icon = "inventory_icon_bags_small.png" icon = "inventory_icon_bags_small.png"
else else
scale = { x = 1, y = 1 } scale = { x = 1, y = 1 }
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 = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image) icon = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image)
if occupied >= size then if occupied >= size then
icon = icon .. "^" .. inventory_icon.COLORIZE_STRING icon = icon .. "^" .. inventory_icon.COLORIZE_STRING
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, "scale", scale)
player:hud_change(inventory_icon.hudids[playername].bags[i].text, "text", text)
player:hud_change(inventory_icon.hudids[playername].bags[i].text, "scale", scale)
end end
player:hud_change(inventory_icon.hudids[playername].bags[i].icon, "text", icon)
player:hud_change(inventory_icon.hudids[playername].bags[i].icon, "scale", scale)
player:hud_change(inventory_icon.hudids[playername].bags[i].text, "text", text)
player:hud_change(inventory_icon.hudids[playername].bags[i].text, "scale", scale)
end end
end end
inventory_icon.timer = 0
end end
end) end
tick()