0.91 release

This commit is contained in:
RealBadAngel 2012-12-03 23:36:15 +01:00
parent 35e91348dd
commit 5baccadd93

103
init.lua

@ -17,32 +17,43 @@ unified_inventory.filtered_items_list = {}
unified_inventory.activefilter = {} unified_inventory.activefilter = {}
-- default inventory page -- default inventory page
unified_inventory.default = minetest.setting_get("inventory_default") or "craft" unified_inventory.default = "craft"
local home_gui = {} local home_gui = {}
local homepos = {} local homepos = {}
unified_inventory.home_filename = minetest.get_worldpath()..'/unified_inventory_home' unified_inventory.home_filename = minetest.get_worldpath()..'/unified_inventory_home'
-- register_button -- Create detached creative inventory after loading all mods
unified_inventory.register_button = function(player,name,label) minetest.after(0.01, function()
local player_name = player:get_player_name() unified_inventory.items_list = {}
if unified_inventory.buttons[player_name] == nil then for name,def in pairs(minetest.registered_items) do
unified_inventory.buttons[player_name] = {} if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
and def.description and def.description ~= "" then
table.insert(unified_inventory.items_list, name)
end end
unified_inventory.buttons[player_name][name] = label end
end table.sort(unified_inventory.items_list)
unified_inventory.items_list_size = #unified_inventory.items_list
print ("Unified Inventory. inventory size: "..unified_inventory.items_list_size)
end)
unified_inventory.register_control_button = function(player,name,label) -- register_on_joinplayer
minetest.register_on_joinplayer(function(player)
local player_name = player:get_player_name() local player_name = player:get_player_name()
if unified_inventory.control_buttons[player_name] == nil then table.insert(unified_inventory.players, player_name)
unified_inventory.control_buttons[player_name] = {} unified_inventory.current_index[player_name] = 1
end unified_inventory.filtered_items_list[player_name] = {}
unified_inventory.control_buttons[player_name][name] = label unified_inventory.filtered_items_list[player_name] = unified_inventory.items_list
end unified_inventory.filtered_items_list_size[player_name]=unified_inventory.items_list_size
unified_inventory.activefilter[player_name]=""
unified_inventory.apply_filter(player_name, "")
unified_inventory.set_inventory_formspec(player,unified_inventory.get_formspec(player, unified_inventory.default))
end)
-- set_inventory_formspec -- set_inventory_formspec
unified_inventory.set_inventory_formspec = function(player,formspec) unified_inventory.set_inventory_formspec = function(player,formspec)
if player then
if minetest.setting_getbool("creative_mode") then if minetest.setting_getbool("creative_mode") then
-- if creative mode is on then wait a bit -- if creative mode is on then wait a bit
minetest.after(0.01,function() minetest.after(0.01,function()
@ -51,10 +62,12 @@ unified_inventory.set_inventory_formspec = function(player,formspec)
else else
player:set_inventory_formspec(formspec) player:set_inventory_formspec(formspec)
end end
end
end end
-- get_formspec -- get_formspec
unified_inventory.get_formspec = function(player,page) unified_inventory.get_formspec = function(player,page)
if player==nil then return "" end
local player_name = player:get_player_name() local player_name = player:get_player_name()
unified_inventory.current_page[player_name]=page unified_inventory.current_page[player_name]=page
@ -194,20 +207,6 @@ unified_inventory.refill = minetest.create_detached_inventory("refill", {
}) })
unified_inventory.refill:set_size("main", 1) unified_inventory.refill:set_size("main", 1)
-- register_on_joinplayer
minetest.register_on_joinplayer(function(player)
local player_name = player:get_player_name()
table.insert(unified_inventory.players, player_name)
unified_inventory.current_index[player_name] = 1
minetest.after(1,function()
unified_inventory.set_inventory_formspec(player,unified_inventory.get_formspec(player, unified_inventory.default))
end)
unified_inventory.filtered_items_list[player_name] = {}
unified_inventory.filtered_items_list[player_name] = unified_inventory.items_list
unified_inventory.filtered_items_list_size[player_name]=unified_inventory.items_list_size
unified_inventory.activefilter[player_name]=""
end)
-- register_on_player_receive_fields -- register_on_player_receive_fields
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
local player_name = player:get_player_name() local player_name = player:get_player_name()
@ -264,7 +263,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
-- Inventory page controls -- Inventory page controls
local start_i=math.floor(unified_inventory.current_index[player_name]/80 +1 ) local start=math.floor(unified_inventory.current_index[player_name]/80 +1 )
local start_i=start
local pagemax = math.floor((unified_inventory.filtered_items_list_size[player_name]-1) / (80) + 1) local pagemax = math.floor((unified_inventory.filtered_items_list_size[player_name]-1) / (80) + 1)
if fields.start_list then if fields.start_list then
@ -291,12 +291,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if start_i > pagemax then if start_i > pagemax then
start_i = pagemax start_i = pagemax
end end
if not (start_i ==start) then
unified_inventory.current_index[player_name] = (start_i-1)*80+1 unified_inventory.current_index[player_name] = (start_i-1)*80+1
unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,unified_inventory.current_page[player_name])) unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,unified_inventory.current_page[player_name]))
end
local list_index=unified_inventory.current_index[player_name] local list_index=unified_inventory.current_index[player_name]
for i=0,80,1 do for i=0,80,1 do
local button="item_button"..list_index local button="item_button"..list_index
if fields[button] then if fields[button] then
@ -317,22 +317,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
if fields.searchbutton then if fields.searchbutton then
local size=0 unified_inventory.apply_filter(player_name, fields.searchbox)
unified_inventory.filtered_items_list[player_name]={}
for name,def in pairs(minetest.registered_items) do
if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
and def.description and def.description ~= "" then
if string.find(def.name, fields.searchbox) or string.find(def.description, fields.searchbox) then
table.insert(unified_inventory.filtered_items_list[player_name], name)
size=size+1
end
end
end
table.sort(unified_inventory.filtered_items_list[player_name])
unified_inventory.filtered_items_list_size[player_name]=size
unified_inventory.current_index[player_name]=1
unified_inventory.activefilter[player_name]=fields.searchbox
unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,unified_inventory.current_page[player_name])) unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,unified_inventory.current_page[player_name]))
end end
@ -380,19 +365,25 @@ unified_inventory.go_home = function(player)
end end
end end
--apply filter to the inventory list
-- Create detached creative inventory after loading all mods unified_inventory.apply_filter = function(player_name,filter)
minetest.after(0.01, function() local size=0
unified_inventory.items_list = {} unified_inventory.filtered_items_list[player_name]={}
for name,def in pairs(minetest.registered_items) do for name,def in pairs(minetest.registered_items) do
if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0) if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
and def.description and def.description ~= "" then and def.description and def.description ~= "" then
table.insert(unified_inventory.items_list, name) if string.find(def.name, filter) or string.find(def.description, filter) then
table.insert(unified_inventory.filtered_items_list[player_name], name)
size=size+1
end end
end end
table.sort(unified_inventory.items_list)
unified_inventory.items_list_size = #unified_inventory.items_list
print ("Unified Inventory. inventory size: "..unified_inventory.items_list_size)
end) end
table.sort(unified_inventory.filtered_items_list[player_name])
unified_inventory.filtered_items_list_size[player_name]=size
unified_inventory.current_index[player_name]=1
unified_inventory.activefilter[player_name]=filter
unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,unified_inventory.current_page[player_name]))
end