Compare commits

13 Commits

Author SHA1 Message Date
c9ef53904a Try to fix mahmutelmas06's reported bug 2016-11-12 21:51:32 +01:00
42da48502e Version 1.1.0 2016-11-12 21:18:55 +01:00
b29164fd7f Code = MIT License 2016-11-12 21:18:06 +01:00
1a59ee78c4 Add link to license 2016-11-12 20:28:08 +01:00
608943de66 Use new intllib format strings 2016-11-09 01:55:18 +01:00
700fd8b4a6 Fix outdated inttlib boilerplate 2016-11-09 01:52:54 +01:00
5f7b6273bd Update metadata 2016-09-01 20:45:23 +02:00
c4f1ae3992 Add intllib support 2016-09-01 20:27:21 +02:00
59c822095b Update README, use Markdown format 2016-09-01 20:21:34 +02:00
7bc1afbeb0 Add support for old bags mod 2016-09-01 20:16:24 +02:00
1750111664 Use bag icons directly from UI 2016-09-01 20:05:40 +02:00
4a8da309e5 Unify backpack icon PNG formats 2016-09-01 19:56:34 +02:00
5d4695a4c6 Stop polluting global namespace 2016-08-11 18:30:00 +02:00
13 changed files with 100 additions and 81 deletions

21
README.md Normal file
View 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)

View File

@ -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)

View File

@ -1 +1,3 @@
bags?
unified_inventory?
intllib?

View File

@ -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
View File

@ -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
View File

@ -0,0 +1 @@
@1/@2 = @1/@2

3
locale/template.txt Normal file
View 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 =

1
mod.conf Normal file
View File

@ -0,0 +1 @@
name = inventory_icon

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