summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2022-02-15 00:22:20 -0600
committerthe lemons <citrons@mondecitronne.com>2022-02-15 00:22:20 -0600
commit5ae924d9a4220b952ac3f481bb58df97ff7676ec (patch)
treec3f614465f206b9d18cd25c950fdf8ccc6db0a35
parentd0173cf965d48a292201a2155deca5ce7ecb6ff6 (diff)
inventory UI allows player to remove item from hotbar
-rw-r--r--mods/vzxv_inv/init.lua21
-rw-r--r--mods/vzxv_inv/textures/vzxvminus.pngbin0 -> 92 bytes
-rw-r--r--mods/vzxv_inv/ui.lua28
-rw-r--r--mods/vzxv_worldgen/biome.lua2
4 files changed, 39 insertions, 12 deletions
diff --git a/mods/vzxv_inv/init.lua b/mods/vzxv_inv/init.lua
index 8c7aff4..38dd18e 100644
--- a/mods/vzxv_inv/init.lua
+++ b/mods/vzxv_inv/init.lua
@@ -91,6 +91,27 @@ function vzxv.add_to_hotbar(player, idx, make_room)
end
end
+function vzxv.in_hotbar(player, stack)
+ local hotbar = player:get_inventory()
+ for i=1,8 do
+ local s = hotbar:get_stack("main", i)
+ if match(s, stack) then
+ return true
+ end
+ end
+ return false
+end
+
+function vzxv.remove_from_hotbar(player, stack)
+ local hotbar = player:get_inventory()
+ for i=1,8 do
+ local s = hotbar:get_stack("main", i)
+ if match(s, stack) then
+ hotbar:set_stack("main", i, ItemStack "")
+ end
+ end
+end
+
-- item is given to player
-- TODO: weight limit
function vzxv.give_items(player, stack)
diff --git a/mods/vzxv_inv/textures/vzxvminus.png b/mods/vzxv_inv/textures/vzxvminus.png
new file mode 100644
index 0000000..7c30ab5
--- /dev/null
+++ b/mods/vzxv_inv/textures/vzxvminus.png
Binary files differ
diff --git a/mods/vzxv_inv/ui.lua b/mods/vzxv_inv/ui.lua
index 431bff1..fb22fa6 100644
--- a/mods/vzxv_inv/ui.lua
+++ b/mods/vzxv_inv/ui.lua
@@ -1,6 +1,4 @@
--- TODO: removing items from hotbar
-
local inv_state = {}
local per_page = 8
@@ -11,18 +9,20 @@ local function sort_inv(inv)
end)
end
-local function inventory_item(offsx, offsy, item, idx)
+local function inventory_item(offsx, offsy, item, idx, in_hotbar)
item_image({offsx, offsy}, {1, 1}, item:get_name())
label({offsx + 0.75, offsy + 0.9}, item:get_count())
label({offsx + 1.25, offsy + 0.5}, item:get_short_description())
image_button(
{offsx + 5.25, offsy + 0.25}, {0.5, 0.5},
- "vzxvplus.png", "item:" .. idx, ""
+ in_hotbar and "vzxvminus.png" or "vzxvplus.png",
+ "item:" .. idx, ""
)
end
vzxv.formspec(inventory_item)
-local inventory = vzxv.formspec(function(state, inv)
+local vzxv = vzxv
+local inventory = vzxv.formspec(function(state, inv, player)
formspec_version(4)
if #inv <= per_page then
size{8, 11.25}
@@ -37,13 +37,15 @@ local inventory = vzxv.formspec(function(state, inv)
local p = state.page * per_page
for i = p + 1, p + per_page do
if i > #inv then break end
- inventory_item(1.75, (i - p) * 1.25, inv[i], i)
+ inventory_item(1.75, (i - p) * 1.25, inv[i], i,
+ vzxv.in_hotbar(player, inv[i]))
end
if #inv > per_page then
p = p + per_page
for i = p + 1, p + per_page do
if i > #inv then break end
- inventory_item(8.25, (i - p) * 1.25, inv[i], i)
+ inventory_item(8.25, (i - p) * 1.25, inv[i], i,
+ vzxv.in_hotbar(player, inv[i]))
end
end
if state.page ~= 0 then
@@ -59,7 +61,7 @@ minetest.register_on_joinplayer(function(player)
inv_state[name] = {page = 0}
local inv = vzxv.get_inventory(player)
sort_inv(inv)
- player:set_inventory_formspec(inventory(inv_state[name], inv))
+ player:set_inventory_formspec(inventory(inv_state[name], inv, player))
end)
minetest.register_on_leaveplayer(function(player)
@@ -88,16 +90,20 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
idx = idx and tonumber(idx)
if idx and inv[idx] then
local real_idx = vzxv.inventory_idx(player, inv[idx])
- vzxv.add_to_hotbar(player, real_idx, true)
+ if not vzxv.in_hotbar(player, inv[idx]) then
+ vzxv.add_to_hotbar(player, real_idx, true)
+ else
+ vzxv.remove_from_hotbar(player, inv[idx])
+ end
end
end
- player:set_inventory_formspec(inventory(state, inv))
+ player:set_inventory_formspec(inventory(state, inv, player))
end)
vzxv.on_inventory_update:register(function (player, inv)
sort_inv(inv)
local state = inv_state[player:get_player_name()]
- player:set_inventory_formspec(inventory(state, inv))
+ player:set_inventory_formspec(inventory(state, inv, player))
end)
diff --git a/mods/vzxv_worldgen/biome.lua b/mods/vzxv_worldgen/biome.lua
index ba7e189..3b64328 100644
--- a/mods/vzxv_worldgen/biome.lua
+++ b/mods/vzxv_worldgen/biome.lua
@@ -14,7 +14,7 @@ end
local noise_params = {
elevation = {
seed = 1,
- offset = -50,
+ offset = -50,
scale = 50,
spread = {x=2500,y=2500,z=500},
octaves = 5,