mirror of
git://repo.or.cz/minetest_inventory_icon.git
synced 2025-01-23 12:10:15 +01:00
Try to fix mahmutelmas06's reported bug
This commit is contained in:
parent
42da48502e
commit
c9ef53904a
106
init.lua
106
init.lua
@ -59,40 +59,42 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
if mod_ui or mod_bags then
|
if mod_ui or mod_bags then
|
||||||
inventory_icon.hudids[name].bags = {}
|
inventory_icon.hudids[name].bags = {}
|
||||||
local bags_inv = minetest.get_inventory({type = "detached", name = name.."_bags"})
|
local bags_inv = minetest.get_inventory({type = "detached", name = name.."_bags"})
|
||||||
for i=1,4 do
|
if bags_inv then
|
||||||
local bag = bags_inv:get_stack("bag"..i, 1)
|
for i=1,4 do
|
||||||
local scale, text, icon
|
local bag = bags_inv:get_stack("bag"..i, 1)
|
||||||
if bag:is_empty() then
|
local scale, text, icon
|
||||||
scale = { x = 0, y = 0 }
|
if bag:is_empty() then
|
||||||
text = ""
|
scale = { x = 0, y = 0 }
|
||||||
icon = "bags_small.png^[resize:32x32"
|
text = ""
|
||||||
else
|
icon = "bags_small.png^[resize:32x32"
|
||||||
scale = { x = 1, y = 1 }
|
else
|
||||||
local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents")
|
scale = { x = 1, y = 1 }
|
||||||
text = S("@1/@2", occupied, size)
|
local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents")
|
||||||
icon = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image)
|
text = S("@1/@2", occupied, size)
|
||||||
if occupied >= size then
|
icon = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image)
|
||||||
icon = icon .. "^" .. inventory_icon.COLORIZE_STRING
|
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].icon = player:hud_add({
|
||||||
|
hud_elem_type = "image",
|
||||||
|
position = {x=1,y=1},
|
||||||
|
scale = scale,
|
||||||
|
size = { x=32, y=32 },
|
||||||
|
offset = {x=-36,y=-32 -40*i},
|
||||||
|
text = icon,
|
||||||
|
})
|
||||||
|
inventory_icon.hudids[name].bags[i].text = player:hud_add({
|
||||||
|
hud_elem_type = "text",
|
||||||
|
position = {x=1,y=1},
|
||||||
|
scale = scale,
|
||||||
|
offset = {x=-36,y=-20 -40*i},
|
||||||
|
alignment = {x=0,y=0},
|
||||||
|
number = 0xFFFFFF,
|
||||||
|
text = text,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
inventory_icon.hudids[name].bags[i] = {}
|
|
||||||
inventory_icon.hudids[name].bags[i].icon = player:hud_add({
|
|
||||||
hud_elem_type = "image",
|
|
||||||
position = {x=1,y=1},
|
|
||||||
scale = scale,
|
|
||||||
size = { x=32, y=32 },
|
|
||||||
offset = {x=-36,y=-32 -40*i},
|
|
||||||
text = icon,
|
|
||||||
})
|
|
||||||
inventory_icon.hudids[name].bags[i].text = player:hud_add({
|
|
||||||
hud_elem_type = "text",
|
|
||||||
position = {x=1,y=1},
|
|
||||||
scale = scale,
|
|
||||||
offset = {x=-36,y=-20 -40*i},
|
|
||||||
alignment = {x=0,y=0},
|
|
||||||
number = 0xFFFFFF,
|
|
||||||
text = text,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -119,27 +121,29 @@ minetest.register_globalstep(function(dtime)
|
|||||||
|
|
||||||
if mod_ui or mod_bags then
|
if mod_ui or mod_bags 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
|
if bags_inv then
|
||||||
local bag = bags_inv:get_stack("bag"..i, 1)
|
for i=1,4 do
|
||||||
local scale, text, icon
|
local bag = bags_inv:get_stack("bag"..i, 1)
|
||||||
if bag:is_empty() then
|
local scale, text, icon
|
||||||
scale = { x = 0, y = 0 }
|
if bag:is_empty() then
|
||||||
text = ""
|
scale = { x = 0, y = 0 }
|
||||||
icon = "bags_small.png^[resize:32x32"
|
text = ""
|
||||||
else
|
icon = "bags_small.png^[resize:32x32"
|
||||||
scale = { x = 1, y = 1 }
|
else
|
||||||
local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents")
|
scale = { x = 1, y = 1 }
|
||||||
text = S("@1/@2", occupied, size)
|
local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents")
|
||||||
icon = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image)
|
text = S("@1/@2", occupied, size)
|
||||||
if occupied >= size then
|
icon = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image)
|
||||||
icon = icon .. "^" .. inventory_icon.COLORIZE_STRING
|
if occupied >= size then
|
||||||
|
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)
|
player:hud_change(inventory_icon.hudids[playername].bags[i].icon, "scale", scale)
|
||||||
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, "text", text)
|
||||||
player:hud_change(inventory_icon.hudids[playername].bags[i].text, "scale", scale)
|
player:hud_change(inventory_icon.hudids[playername].bags[i].text, "scale", scale)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user