API tweaks

This commit is contained in:
ShadowNinja 2013-10-02 23:25:07 -04:00
parent ec328d8270
commit 04600f64d8
3 changed files with 26 additions and 16 deletions

View File

@ -4,9 +4,9 @@
-- License: GPLv3
unified_inventory.register_page("bags", {
get_formspec = function(player, formspec)
get_formspec = function(player)
local player_name = player:get_player_name()
formspec = formspec .. "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]"
local formspec = "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]"
formspec = formspec.."label[0,0;Bags]"
formspec = formspec.."button[0,2;2,0.5;bag1;Bag 1]"
formspec = formspec.."button[2,2;2,0.5;bag2;Bag 2]"
@ -16,7 +16,7 @@ unified_inventory.register_page("bags", {
formspec = formspec.."list[detached:"..player_name.."_bags;bag2;2.5,1;1,1;]"
formspec = formspec.."list[detached:"..player_name.."_bags;bag3;4.5,1;1,1;]"
formspec = formspec.."list[detached:"..player_name.."_bags;bag4;6.5,1;1,1;]"
return formspec
return {formspec=formspec}
end,
})
@ -27,10 +27,10 @@ unified_inventory.register_button("bags", {
for i = 1, 4 do
unified_inventory.register_page("bag"..i, {
get_formspec = function(player, formspec)
get_formspec = function(player)
local stack = player:get_inventory():get_stack("bag"..i, 1)
local image = stack:get_definition().inventory_image
formspec = formspec.."image[7,0;1,1;"..image.."]"
local formspec = "image[7,0;1,1;"..image.."]"
formspec = formspec.."list[current_player;bag"..i.."contents;0,1;8,3;]"
local slots = stack:get_definition().groups.bagslots
if slots == 8 then
@ -40,7 +40,7 @@ for i = 1, 4 do
elseif slots == 24 then
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]"
end
return formspec
return {formspec=formspec}
end,
})
end

View File

@ -5,18 +5,18 @@ function unified_inventory.get_formspec(player, page)
end
local player_name = player:get_player_name()
unified_inventory.current_page[player_name] = page
local pagedef = unified_inventory.pages[page]
local formspec = "size[14,10]"
-- Player inventory
formspec = formspec .. "list[current_player;main;0,4.5;8,4;]"
local fsdata = nil
-- Background
formspec = formspec .. "background[-0.19,-0.2;14.38,10.55;ui_form_bg.png]"
-- Current page
if unified_inventory.pages[page] then
formspec = unified_inventory.pages[page].get_formspec(player, formspec)
fsdata = pagedef.get_formspec(player)
formspec = formspec .. fsdata.formspec
else
return "" -- Invalid page name
end
@ -31,6 +31,15 @@ function unified_inventory.get_formspec(player, page)
end
end
if fsdata.draw_inventory ~= false then
-- Player inventory
formspec = formspec .. "list[current_player;main;0,4.5;8,4;]"
end
if fsdata.draw_item_list == false then
return formspec
end
-- Controls to flip items pages
local start_x = 9.2
formspec = formspec .. "image_button["..(start_x + 0.6 * 0)..",9;.8,.8;ui_skip_backward_icon.png;start_list;]"

View File

@ -118,7 +118,7 @@ unified_inventory.register_button("clear_inv", {
unified_inventory.register_page("craft", {
get_formspec = function(player, formspec)
local player_name = player:get_player_name()
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_crafting_form.png]"
local formspec = "background[0.06,0.99;7.92,7.52;ui_crafting_form.png]"
formspec = formspec.."label[0,0;Crafting]"
formspec = formspec.."list[current_player;craftpreview;6,1;1,1;]"
formspec = formspec.."list[current_player;craft;2,1;3,3;]"
@ -128,14 +128,14 @@ unified_inventory.register_page("craft", {
formspec = formspec.."label[0,2.5;Refill:]"
formspec = formspec.."list[detached:"..player_name.."refill;main;0,3;1,1;]"
end
return formspec
return {formspec=formspec}
end,
})
unified_inventory.register_page("craftguide", {
get_formspec = function(player, formspec)
get_formspec = function(player)
local player_name = player:get_player_name()
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_craftguide_form.png]"
local formspec = "background[0.06,0.99;7.92,7.52;ui_craftguide_form.png]"
formspec = formspec.."label[0,0;Crafting Guide]"
formspec = formspec.."list[detached:"..player_name.."craftrecipe;output;6,1;1,1;]"
formspec = formspec.."label[2,0.5;Input:]"
@ -176,7 +176,7 @@ unified_inventory.register_page("craftguide", {
if not craft then
craftinv:set_stack("output", 1, nil)
return formspec
return {formspec=formspec}
end
craftinv:set_stack("output", 1, craft.output)
@ -209,6 +209,7 @@ unified_inventory.register_page("craftguide", {
i = i + 1
end
end
return formspec
return {formspec=formspec}
end,
})