Skip to content

Commit

Permalink
Player Inventory: Bags: add buttons for each bag on bag content page. C…
Browse files Browse the repository at this point in the history
…loses #1705
  • Loading branch information
alek13 committed Sep 28, 2024
1 parent d0a68e2 commit dbe0fd0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 deletions.
11 changes: 8 additions & 3 deletions mods/lord/Player/lord_inventory/locale/lottarmor.en.tr
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# textdomain: lord_inventory

# Tabs:
Main=Main
Bags=Bags


# Main Tab:
crafting_image=lord_inventory_crafting.en.png

Back=Back
# Bags Tab:
All Bags=All Bags
Bag=Bag
Main=Main
Bags=Bags
11 changes: 8 additions & 3 deletions mods/lord/Player/lord_inventory/locale/lottarmor.ru.tr
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# textdomain: lord_inventory

# Tabs:
Main=Основное
Bags=Сумки


# Main Tab:
crafting_image=lord_inventory_crafting.ru.png

Back=На главную
# Bags Tab:
All Bags=Все Сумки
Bag=Сумка
Main=На главную
Bags=Сумки
56 changes: 33 additions & 23 deletions mods/lord/Player/lord_inventory/src/inventory/Form/BagsTab.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local S = minetest.get_translator("lord_inventory")
local S = minetest.get_translator('lord_inventory')


--- @class inventory.Form.BagsTab: base_classes.Form.Element.Tab
Expand All @@ -19,27 +19,37 @@ function BagsTab:get_spec()

-- Form with bags selection
if bag == 0 then
return "list[current_player;main;0,3.5;8,4;]"
.. "button[0,2;2,0.5;bag1;" .. S("Bag") .. " 1]"
.. "button[2,2;2,0.5;bag2;" .. S("Bag") .. " 2]"
.. "button[4,2;2,0.5;bag3;" .. S("Bag") .. " 3]"
.. "button[6,2;2,0.5;bag4;" .. S("Bag") .. " 4]"
.. "list[detached:" .. player_name .. "_bags;bag1;0.5,1;1,1;]"
.. "list[detached:" .. player_name .. "_bags;bag2;2.5,1;1,1;]"
.. "list[detached:" .. player_name .. "_bags;bag3;4.5,1;1,1;]"
.. "list[detached:" .. player_name .. "_bags;bag4;6.5,1;1,1;]"
return ''
.. 'button[0,2;2,0.5;bag1;' .. S('Bag') .. ' 1]'
.. 'button[2,2;2,0.5;bag2;' .. S('Bag') .. ' 2]'
.. 'button[4,2;2,0.5;bag3;' .. S('Bag') .. ' 3]'
.. 'button[6,2;2,0.5;bag4;' .. S('Bag') .. ' 4]'
.. 'list[detached:' .. player_name .. '_bags;bag1;0.5,1;1,1;]'
.. 'list[detached:' .. player_name .. '_bags;bag2;2.5,1;1,1;]'
.. 'list[detached:' .. player_name .. '_bags;bag3;4.5,1;1,1;]'
.. 'list[detached:' .. player_name .. '_bags;bag4;6.5,1;1,1;]'
.. 'list[current_player;main;0,4.5 ;8,1; ]'
.. 'list[current_player;main;0,5.75;8,3;8]'
end

-- Form with bag contents
local player = minetest.get_player_by_name(player_name)
local image = player:get_inventory():get_stack("bag" .. bag, 1):get_definition().inventory_image

return "list[current_player;main;0,4.5;8,4;]"
.. "button[0,0;2,0.5;bags;" .. S("Bags") .. "]"
.. "image[7,-0.15;1,1;" .. image .. "]"
.. "list[current_player;bag" .. bag .. "contents;0,1;8,3;]"
.. "listring[current_player;bag" .. bag .. "contents]"
.. "listring[current_player;main]"
local image = player:get_inventory():get_stack('bag' .. bag, 1):get_definition().inventory_image
local bags_buttons = 'style_type[image_button;font=bold;textcolor=#fffb]'
for i = 1, 4 do
local button_image = player:get_inventory():get_stack('bag' .. i, 1):get_definition().inventory_image or ''
bags_buttons = bags_buttons ..
'image_button['..
(1 + i) .. ',-0.125;1,0.83;' .. button_image .. ';bag'..i..';' .. i ..
']'
end

return 'button[0,0;2,0.5;bags;' .. S('All Bags') .. ']' .. bags_buttons .. 'image[7,-0.15;1,1;' .. image .. ']'
.. 'list[current_player;bag' .. bag .. 'contents;0,1;8,3;]'
.. 'list[current_player;main;0,4.5 ;8,1; ]'
.. 'list[current_player;main;0,5.75;8,3;8]'
.. 'listring[current_player;bag' .. bag .. 'contents]'
.. 'listring[current_player;main]'
end

--- @param fields table
Expand All @@ -52,7 +62,7 @@ function BagsTab:handle(fields)
end

for i = 1, 4 do
local page = "bag" .. i
local page = 'bag' .. i
if fields[page] then
self.current_bag = i
local item_in_slot_definition = minetest.get_player_by_name(self.form.player_name)
Expand All @@ -73,10 +83,10 @@ minetest.register_on_joinplayer(function(joined_player, last_login)
local player_name = joined_player:get_player_name()
local player_inv = joined_player:get_inventory()

local bags_inv = minetest.create_detached_inventory(player_name .. "_bags", {
local bags_inv = minetest.create_detached_inventory(player_name .. '_bags', {
on_put = function(inv, list_name, index, stack, player)
player:get_inventory():set_stack(list_name, index, stack)
player:get_inventory():set_size(list_name .. "contents", stack:get_definition().groups.bagslots)
player:get_inventory():set_size(list_name .. 'contents', stack:get_definition().groups.bagslots)
end,
on_take = function(inv, list_name, index, stack, player)
player:get_inventory():set_stack(list_name, index, nil)
Expand All @@ -89,7 +99,7 @@ minetest.register_on_joinplayer(function(joined_player, last_login)
end
end,
allow_take = function(inv, list_name, index, stack, player)
if player:get_inventory():is_empty(list_name .. "contents") == true then
if player:get_inventory():is_empty(list_name .. 'contents') == true then
return stack:get_count()
else
return 0
Expand All @@ -101,7 +111,7 @@ minetest.register_on_joinplayer(function(joined_player, last_login)
}, player_name)

for i = 1, 4 do
local bag = "bag" .. i
local bag = 'bag' .. i
player_inv:set_size(bag, 1)
bags_inv:set_size(bag, 1)
bags_inv:set_stack(bag, 1, player_inv:get_stack(bag, 1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ local formspec_template = ''
.. 'image[7,3;1,1;lord_inventory_trash_slot.png]'
.. 'list[detached:trash;main;7,3;1,1;]'
-- Player inventory content
.. 'list[current_player;main;0,4.25;8,1;]'
.. 'list[current_player;main;0,5.5;8,3;8]'
.. 'list[current_player;main;0,4.5 ;8,1; ]'
.. 'list[current_player;main;0,5.75;8,3;8]'
-- options
.. 'listring[current_player;main]'
.. 'listring[current_player;craft]'
Expand Down

0 comments on commit dbe0fd0

Please sign in to comment.