diff options
author | heav-4 <heavpoot@gmail.com> | 2022-02-13 09:08:07 +0000 |
---|---|---|
committer | heav-4 <heavpoot@gmail.com> | 2022-02-13 09:08:07 +0000 |
commit | d1204f7c4b3f2e299687cda7ed4c2df62ed304c3 (patch) | |
tree | 7935ecc23f84871a5a5d4351329a24454d030bf9 | |
parent | 2cafb2efd5bb1e33913ceaabbf309f29d4c762b2 (diff) | |
parent | f57e3ffa95adfeb38fcba5ee900a4db22f92bd5f (diff) |
Merge branch 'master' of citrons.xyz:vzxv
-rw-r--r-- | mods/vzxv_inv/textures/vzxvnext.png | bin | 0 -> 108 bytes | |||
-rw-r--r-- | mods/vzxv_inv/textures/vzxvplus.png | bin | 0 -> 96 bytes | |||
-rw-r--r-- | mods/vzxv_inv/textures/vzxvprev.png | bin | 0 -> 111 bytes | |||
-rw-r--r-- | mods/vzxv_inv/ui.lua | 98 |
4 files changed, 91 insertions, 7 deletions
diff --git a/mods/vzxv_inv/textures/vzxvnext.png b/mods/vzxv_inv/textures/vzxvnext.png Binary files differnew file mode 100644 index 0000000..f8a2c94 --- /dev/null +++ b/mods/vzxv_inv/textures/vzxvnext.png diff --git a/mods/vzxv_inv/textures/vzxvplus.png b/mods/vzxv_inv/textures/vzxvplus.png Binary files differnew file mode 100644 index 0000000..38c5c95 --- /dev/null +++ b/mods/vzxv_inv/textures/vzxvplus.png diff --git a/mods/vzxv_inv/textures/vzxvprev.png b/mods/vzxv_inv/textures/vzxvprev.png Binary files differnew file mode 100644 index 0000000..20796bd --- /dev/null +++ b/mods/vzxv_inv/textures/vzxvprev.png diff --git a/mods/vzxv_inv/ui.lua b/mods/vzxv_inv/ui.lua index f74299b..b227267 100644 --- a/mods/vzxv_inv/ui.lua +++ b/mods/vzxv_inv/ui.lua @@ -1,19 +1,103 @@ -local inventory = vzxv.formspec(function() +local dummy_inventory = { + {name = "vzxv:dirt", count = 56}, + {name = "vzxv:moistdirt", count = 340}, + {name = "vzxv:grass", count = 99}, + {name = "vzxv:moistgrass", count = 99}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:metalaxe", count = 34}, + {name = "vzxv:woodaxe", count = 34}, + {name = "vzxv:stoneaxe", count = 34}, + {name = "vzxv:metalspade", count = 34}, + {name = "vzxv:woodspade", count = 34}, + {name = "vzxv:stonespade", count = 34}, + {name = "vzxv:woodadze", count = 34}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, + {name = "vzxv:apioform", count = 20}, +} + +local inv_state = {} + +local per_page = 8 + +local function inventory_item(offsx, offsy, item, idx) + item_image({offsx, offsy}, {1, 1}, item.name) + label({offsx + 0.75, offsy + 0.9}, item.count) + label({offsx + 1.25, offsy + 0.5}, item.name) + image_button( + {offsx + 5.25, offsy + 0.25}, {0.5, 0.5}, + "vzxvplus.png", "item:" .. idx, "" + ) +end +vzxv.formspec(inventory_item) + +local inventory = vzxv.formspec(function(state) formspec_version(4) - size{2, 2} - item_image({0.5, 0.5}, {1, 1}, "vzxv:apioform") + if #dummy_inventory < per_page then + size{8, 11.25} + else + size{14.25, 11.25} + end + label({0.25, 0.6}, "Inventory") + -- vertical hotbar display + for i=1,8 do + list("current_player", "main", {0.25, i * 1.25}, {1, 1}, i - 1) + end + local p = state.page * per_page + for i = p + 1, p + per_page do + if i > #dummy_inventory then break end + inventory_item(1.75, (i - p) * 1.25, dummy_inventory[i], i) + end + if #dummy_inventory > per_page then + p = p + per_page + for i = p + 1, p + per_page do + if i > #dummy_inventory then break end + inventory_item(8.25, (i - p) * 1.25, dummy_inventory[i], i) + end + end + if state.page ~= 0 then + image_button({12, 0.37}, {1, 0.5}, "vzxvprev.png", "prev", "") + end + if p + per_page < #dummy_inventory then + image_button({13, 0.37}, {1, 0.5}, "vzxvnext.png", "next", "") + end end) minetest.register_on_joinplayer(function(player) - player:set_inventory_formspec(inventory()) - print(inventory()) + local name = player:get_player_name() + inv_state[name] = {page = 0} + player:set_inventory_formspec(inventory(inv_state[name])) +end) + +minetest.register_on_leaveplayer(function(player) + inv_state[player:get_player_name()] = nil end) minetest.register_on_player_receive_fields(function(player, formname, fields) if formname ~= "" then return end - for k,v in pairs(fields) do - print(k,v) + local state = inv_state[player:get_player_name()] + if fields.next then + state.page = state.page + 1 + end + if fields.prev then + state.page = state.page - 1 + end + if (state.page + 1) * per_page > #dummy_inventory or state.page < 0 then + state.page = 1 end + + player:set_inventory_formspec(inventory(state)) end) |