forked from mtcontrib/minetest_inventory_icon
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
c9ef53904a | |||
42da48502e | |||
b29164fd7f | |||
1a59ee78c4 | |||
608943de66 | |||
700fd8b4a6 | |||
5f7b6273bd | |||
c4f1ae3992 | |||
59c822095b | |||
7bc1afbeb0 | |||
1750111664 | |||
4a8da309e5 | |||
5d4695a4c6 |
21
README.md
Normal file
21
README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# Inventory Icon
|
||||
Version: 1.1.0
|
||||
|
||||
## Description
|
||||
This simple mod adds an icon to the player's HUD at the bottom right corner.
|
||||
It shows how many inventory slots are available and how many of them are
|
||||
occupied.
|
||||
|
||||
This mod also supports the Bags and Unified Inventory mods. If one of these
|
||||
mods are used, icons for each bag are displayed, too.
|
||||
|
||||
## Licenses
|
||||
### Code
|
||||
The code is licensed under the MIT License.
|
||||
|
||||
### Media files
|
||||
Licensed under [CC-BY-SA 3.0 Unported](https://creativecommons.org/licenses/by-sa/3.0/).
|
||||
|
||||
#### Authors
|
||||
* `inventory_icon_backpack_free.png`: DitsyDM and Traipse OpenRPG (CC-BY-SA 3.0 Unported)
|
||||
* `inventory_icon_backpack_full.png`: DitsyDM, Traipse OpenRPG and Wuzzy (CC-BY-SA 3.0 Unported)
|
23
README.txt
23
README.txt
@ -1,23 +0,0 @@
|
||||
Inventory Icon
|
||||
==============
|
||||
Version: 1.0.1
|
||||
|
||||
This simple mod adds an icon to the player's HUD which shows how many inventory slots are available and how many of them are occupied.
|
||||
|
||||
This mod also supports the Unified Inventory mod. If this mod is used, icons for each bag are displayed, too.
|
||||
|
||||
|
||||
----------------
|
||||
|
||||
License of code:
|
||||
WTFPL
|
||||
|
||||
License of media files:
|
||||
CC-BY-SA 3.0 Unported
|
||||
|
||||
Authors:
|
||||
- inventory_icon_backpack_free.png: DitsyDM and Traipse OpenRPG (CC-BY-SA 3.0 Unported)
|
||||
- inventory_icon_backpack_full.png: DitsyDM, Traipse OpenRPG and Wuzzy (CC-BY-SA 3.0 Unported)
|
||||
- inventory_icon_bags_small.png: Tonyka (New BSD License)
|
||||
- inventory_icon_bags_medium.png: Tonyka (New BSD License)
|
||||
- inventory_icon_bags_large.png: Tonyka (New BSD License)
|
@ -1 +1,3 @@
|
||||
bags?
|
||||
unified_inventory?
|
||||
intllib?
|
||||
|
@ -1 +1 @@
|
||||
Shows a little backpack icon in the HUD, which shows how many slots are available and free in the player inventory.
|
||||
Shows a backpack icon in the HUD, which shows how many slots are available and free in the player inventory and equipped bags (if available).
|
||||
|
128
init.lua
128
init.lua
@ -1,8 +1,18 @@
|
||||
inventory_icon = {}
|
||||
local S
|
||||
if (minetest.get_modpath("intllib")) then
|
||||
S = intllib.Getter()
|
||||
else
|
||||
S = function(s,a,...)a={a,...}return s:gsub("@(%d+)",function(n)return a[tonumber(n)]end)end
|
||||
end
|
||||
|
||||
local inventory_icon = {}
|
||||
inventory_icon.hudids = {}
|
||||
|
||||
inventory_icon.COLORIZE_STRING = "[colorize:#A00000:192"
|
||||
|
||||
local mod_ui = minetest.get_modpath("unified_inventory") ~= nil
|
||||
local mod_bags = minetest.get_modpath("bags") ~= nil
|
||||
|
||||
function inventory_icon.get_inventory_state(inv, listname)
|
||||
local size = inv:get_size(listname)
|
||||
local occupied = 0
|
||||
@ -16,7 +26,7 @@ function inventory_icon.get_inventory_state(inv, listname)
|
||||
end
|
||||
|
||||
function inventory_icon.replace_icon(name)
|
||||
return "inventory_icon_"..name
|
||||
return name.."^[resize:32x32"
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
@ -44,45 +54,47 @@ minetest.register_on_joinplayer(function(player)
|
||||
offset = {x=-36,y=-20},
|
||||
alignment = {x=0,y=0},
|
||||
number = 0xFFFFFF,
|
||||
text = string.format("%d/%d", occupied, size)
|
||||
text = S("@1/@2", occupied, size)
|
||||
})
|
||||
if minetest.get_modpath("unified_inventory") ~= nil then
|
||||
if mod_ui or mod_bags then
|
||||
inventory_icon.hudids[name].bags = {}
|
||||
local bags_inv = minetest.get_inventory({type = "detached", name = name.."_bags"})
|
||||
for i=1,4 do
|
||||
local bag = bags_inv:get_stack("bag"..i, 1)
|
||||
local scale, text, icon
|
||||
if bag:is_empty() then
|
||||
scale = { x = 0, y = 0 }
|
||||
text = ""
|
||||
icon = "inventory_icon_bags_small.png"
|
||||
else
|
||||
scale = { x = 1, y = 1 }
|
||||
local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents")
|
||||
text = string.format("%d/%d", occupied, size)
|
||||
icon = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image)
|
||||
if occupied >= size then
|
||||
icon = icon .. "^" .. inventory_icon.COLORIZE_STRING
|
||||
if bags_inv then
|
||||
for i=1,4 do
|
||||
local bag = bags_inv:get_stack("bag"..i, 1)
|
||||
local scale, text, icon
|
||||
if bag:is_empty() then
|
||||
scale = { x = 0, y = 0 }
|
||||
text = ""
|
||||
icon = "bags_small.png^[resize:32x32"
|
||||
else
|
||||
scale = { x = 1, y = 1 }
|
||||
local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents")
|
||||
text = S("@1/@2", occupied, size)
|
||||
icon = inventory_icon.replace_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({
|
||||
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
|
||||
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)
|
||||
@ -105,31 +117,33 @@ minetest.register_globalstep(function(dtime)
|
||||
icon = "inventory_icon_backpack_free.png"
|
||||
end
|
||||
player:hud_change(hudids.main.icon, "text", icon)
|
||||
player:hud_change(hudids.main.text, "text", string.format("%d/%d", occupied, size))
|
||||
player:hud_change(hudids.main.text, "text", S("@1/@2", occupied, size))
|
||||
|
||||
if minetest.get_modpath("unified_inventory") ~= nil then
|
||||
if mod_ui or mod_bags then
|
||||
local bags_inv = minetest.get_inventory({type = "detached", name = playername.."_bags"})
|
||||
for i=1,4 do
|
||||
local bag = bags_inv:get_stack("bag"..i, 1)
|
||||
local scale, text, icon
|
||||
if bag:is_empty() then
|
||||
scale = { x = 0, y = 0 }
|
||||
text = ""
|
||||
icon = "inventory_icon_bags_small.png"
|
||||
else
|
||||
scale = { x = 1, y = 1 }
|
||||
local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents")
|
||||
text = string.format("%d/%d", occupied, size)
|
||||
icon = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image)
|
||||
if occupied >= size then
|
||||
icon = icon .. "^" .. inventory_icon.COLORIZE_STRING
|
||||
if bags_inv then
|
||||
for i=1,4 do
|
||||
local bag = bags_inv:get_stack("bag"..i, 1)
|
||||
local scale, text, icon
|
||||
if bag:is_empty() then
|
||||
scale = { x = 0, y = 0 }
|
||||
text = ""
|
||||
icon = "bags_small.png^[resize:32x32"
|
||||
else
|
||||
scale = { x = 1, y = 1 }
|
||||
local occupied, size = inventory_icon.get_inventory_state(player:get_inventory(), "bag"..i.."contents")
|
||||
text = S("@1/@2", occupied, size)
|
||||
icon = inventory_icon.replace_icon(minetest.registered_items[bag:get_name()].inventory_image)
|
||||
if occupied >= size then
|
||||
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].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)
|
||||
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
|
||||
|
1
locale/de.txt
Normal file
1
locale/de.txt
Normal file
@ -0,0 +1 @@
|
||||
@1/@2 = @1/@2
|
3
locale/template.txt
Normal file
3
locale/template.txt
Normal file
@ -0,0 +1,3 @@
|
||||
# Shows number of occupied (@1) vs number of total inventory slots (@2).
|
||||
# Try to keep the translation short.
|
||||
@1/@2 =
|
BIN
screenshot.png
Normal file
BIN
screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
Binary file not shown.
Before Width: | Height: | Size: 386 B After Width: | Height: | Size: 818 B |
Binary file not shown.
Before Width: | Height: | Size: 670 B |
Binary file not shown.
Before Width: | Height: | Size: 922 B |
Binary file not shown.
Before Width: | Height: | Size: 699 B |
Reference in New Issue
Block a user