Use/support sfinv.
This commit is contained in:
parent
963ed683bb
commit
05944fe17a
@ -286,13 +286,12 @@ function mod.get_trashcan_formspec(pos, player)
|
||||
|
||||
local spos = pos.x .. ',' .. pos.y .. ',' .. pos.z
|
||||
local formspec = 'size[9,8]' ..
|
||||
'list[nodemeta:' .. spos .. ';main;0,0.3;8,4;]' ..
|
||||
'list[nodemeta:' .. spos .. ';main;0,0.3;8,2;]' ..
|
||||
'list[current_player;main;0,4;8,4;' .. scroll_to .. ']' ..
|
||||
'listring[]' ..
|
||||
'image_button[3,2.5;2,1;transparent_button.png;dinv_trash_empty;Empty Trash]' ..
|
||||
'image_button[8,4;1,1;transparent_button.png;dinv_trash_inventory_up;Up]' ..
|
||||
'image_button[8,6;1,1;transparent_button.png;dinv_trash_inventory_down;Down]' ..
|
||||
default.get_hotbar_bg(0,4.85)
|
||||
'image_button[8,6;1,1;transparent_button.png;dinv_trash_inventory_down;Down]'
|
||||
|
||||
return formspec
|
||||
end
|
||||
@ -340,17 +339,19 @@ end
|
||||
|
||||
|
||||
-- The main formspec...
|
||||
function mod.make_inventory_spec(player)
|
||||
function mod.make_inventory_spec_sfinv(this, player, context)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
|
||||
local player_name = player:get_player_name()
|
||||
if not mod.dat[player_name] then
|
||||
mod.dat[player_name] = {}
|
||||
end
|
||||
local dat = mod.dat[player_name]
|
||||
local scroll_main_to = dat['scroll_main_to'] or 0
|
||||
|
||||
local inventory = ''
|
||||
inventory = inventory .. mod.form_size
|
||||
inventory = inventory .. mod.worn_items_inv
|
||||
inventory = inventory .. mod.empty_button
|
||||
inventory = inventory .. mod.fill_button
|
||||
@ -363,7 +364,9 @@ function mod.make_inventory_spec(player)
|
||||
inventory = inventory .. mod.recipe_grid(player)
|
||||
inventory = inventory .. mod.recipe_list(player)
|
||||
|
||||
return inventory
|
||||
local size = 'size[11.25,7.25]'
|
||||
local show_inv = false
|
||||
return sfinv.make_formspec(player, context, inventory, show_inv, size)
|
||||
end
|
||||
|
||||
|
||||
@ -409,6 +412,41 @@ minetest.after(0, function()
|
||||
end)
|
||||
|
||||
|
||||
function mod.receive_sfinv_fields(self, player, context, fields)
|
||||
if not (player and fields) then
|
||||
return
|
||||
end
|
||||
|
||||
if not (
|
||||
fields['dinv_main_inventory_up']
|
||||
or fields['dinv_main_inventory_down']
|
||||
or fields['dinv_recipe_list']
|
||||
or fields['dinv_recipe_next']
|
||||
or fields['dinv_empty_craft']
|
||||
or fields['dinv_fill_craft']
|
||||
) then
|
||||
return
|
||||
end
|
||||
|
||||
local pinv = player:get_inventory()
|
||||
local main_inventory_size = pinv:get_size('main')
|
||||
|
||||
if fields and fields['dinv_main_inventory_up'] then
|
||||
mod.scroll_main(player, -16, main_inventory_size)
|
||||
elseif fields and fields['dinv_main_inventory_down'] then
|
||||
mod.scroll_main(player, 16, main_inventory_size)
|
||||
elseif fields and fields['dinv_recipe_list'] then
|
||||
mod.show_recipe(player, fields['dinv_recipe_list'])
|
||||
elseif fields and fields['dinv_recipe_next'] then
|
||||
mod.switch_recipe(player, 1)
|
||||
elseif fields and fields['dinv_empty_craft'] then
|
||||
mod.empty_craft(player)
|
||||
elseif fields and fields['dinv_fill_craft'] then
|
||||
mod.recipe_fill(player)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function mod.recipe_fill(player)
|
||||
local player_name = player:get_player_name()
|
||||
local dat = mod.dat[player_name]
|
||||
@ -708,7 +746,7 @@ function mod.scroll_main(player, amount, max)
|
||||
scroll = 0
|
||||
end
|
||||
mod.dat[player_name].scroll_main_to = scroll
|
||||
player:set_inventory_formspec(mod.make_inventory_spec(player))
|
||||
sfinv.set_player_inventory_formspec(player)
|
||||
end
|
||||
end
|
||||
|
||||
@ -840,7 +878,8 @@ function mod.show_recipe(player, field)
|
||||
if t.type == 'CHG' and t.index then
|
||||
mod.dat[player_name].craft_item_number = tonumber(t.index)
|
||||
mod.dat[player_name].recipe_number = 1
|
||||
player:set_inventory_formspec(mod.make_inventory_spec(player))
|
||||
|
||||
sfinv.set_player_inventory_formspec(player)
|
||||
end
|
||||
end
|
||||
|
||||
@ -866,8 +905,7 @@ function mod.switch_recipe(player, amount)
|
||||
dat.recipe_number = 1
|
||||
end
|
||||
|
||||
--print(dat.recipe_number)
|
||||
player:set_inventory_formspec(mod.make_inventory_spec(player))
|
||||
sfinv.set_player_inventory_formspec(player)
|
||||
end
|
||||
|
||||
|
||||
@ -1041,19 +1079,28 @@ end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local player_name = player:get_player_name()
|
||||
--[[
|
||||
if not mod.dat[player_name] then
|
||||
mod.dat[player_name] = {}
|
||||
end
|
||||
--]]
|
||||
|
||||
local pinv = player:get_inventory()
|
||||
pinv:set_size(WORN_INV, 8)
|
||||
mod.set_main_size_by_bags(player)
|
||||
mod.set_armor(player)
|
||||
mod.set_armor_textures(player)
|
||||
player:set_inventory_formspec(mod.make_inventory_spec(player))
|
||||
end)
|
||||
|
||||
|
||||
--sfinv.register_page(mod_name..':inventory', {
|
||||
sfinv.override_page('sfinv:crafting', {
|
||||
title = 'Inventory',
|
||||
get = mod.make_inventory_spec_sfinv,
|
||||
on_player_receive_fields = mod.receive_sfinv_fields,
|
||||
})
|
||||
|
||||
|
||||
-- Handle inventory moves (change armor, etc.).
|
||||
minetest.register_on_player_inventory_action(function(player, action, inventory, inventory_info)
|
||||
if not (player and action and inventory and inventory_info) then
|
||||
@ -1099,20 +1146,18 @@ minetest.register_on_player_inventory_action(function(player, action, inventory,
|
||||
end)
|
||||
|
||||
|
||||
-- Get input from the formspec buttons/list.
|
||||
-- Get input from the trash formspec buttons.
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname ~= mod_name..':trashcan' then
|
||||
return
|
||||
end
|
||||
|
||||
if not (player and fields) then
|
||||
return
|
||||
end
|
||||
|
||||
if not (
|
||||
fields['dinv_main_inventory_up']
|
||||
or fields['dinv_main_inventory_down']
|
||||
or fields['dinv_recipe_list']
|
||||
or fields['dinv_recipe_next']
|
||||
or fields['dinv_empty_craft']
|
||||
or fields['dinv_fill_craft']
|
||||
or fields['dinv_trash_inventory_up']
|
||||
fields['dinv_trash_inventory_up']
|
||||
or fields['dinv_trash_inventory_down']
|
||||
or fields['dinv_trash_empty']
|
||||
) then
|
||||
@ -1122,19 +1167,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local pinv = player:get_inventory()
|
||||
local main_inventory_size = pinv:get_size('main')
|
||||
|
||||
if fields and fields['dinv_main_inventory_up'] then
|
||||
mod.scroll_main(player, -16, main_inventory_size)
|
||||
elseif fields and fields['dinv_main_inventory_down'] then
|
||||
mod.scroll_main(player, 16, main_inventory_size)
|
||||
elseif fields and fields['dinv_recipe_list'] then
|
||||
mod.show_recipe(player, fields['dinv_recipe_list'])
|
||||
elseif fields and fields['dinv_recipe_next'] then
|
||||
mod.switch_recipe(player, 1)
|
||||
elseif fields and fields['dinv_empty_craft'] then
|
||||
mod.empty_craft(player)
|
||||
elseif fields and fields['dinv_fill_craft'] then
|
||||
mod.recipe_fill(player)
|
||||
elseif fields and fields['dinv_trash_inventory_up'] then
|
||||
if fields and fields['dinv_trash_inventory_up'] then
|
||||
mod.scroll_trash(player, -16, main_inventory_size)
|
||||
elseif fields and fields['dinv_trash_inventory_down'] then
|
||||
mod.scroll_trash(player, 16, main_inventory_size)
|
||||
|
Loading…
x
Reference in New Issue
Block a user