| | |
| | | -- 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.players[player_name]={} |
| | | unified_inventory.players[player_name]["sound_volume"]=minetest.setting_get("sound_volume")*10 |
| | | unified_inventory.current_index[player_name] = 1 |
| | | 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]="" |
| | | unified_inventory.apply_filter(player_name, "") |
| | | unified_inventory.apply_filter(player, "") |
| | | unified_inventory.alternate[player_name] = 1 |
| | | unified_inventory.current_item[player_name] =nil |
| | | unified_inventory.set_inventory_formspec(player,unified_inventory.get_formspec(player, unified_inventory.default)) |
| | |
| | | return 0 |
| | | end, |
| | | allow_take = function(inv, listname, index, stack, player) |
| | | return 0 |
| | | if minetest.setting_getbool("creative_mode") then |
| | | return stack:get_count() |
| | | else |
| | | return 0 |
| | | end |
| | | end, |
| | | allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) |
| | | return 0 |
| | |
| | | |
| | | -- player inventory |
| | | formspec = formspec .. "list[current_player;main;0,4.5;8,4;]" |
| | | |
| | | -- backgrounds |
| | | formspec = formspec .. "background[-0.19,-0.2,;14.38,10.55;ui_form_bg.png]" |
| | | if page=="craft" then |
| | | formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_crafting_form.png]" |
| | | end |
| | | if page=="craftguide" then |
| | | formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_craftguide_form.png]" |
| | | end |
| | | if page=="misc" then |
| | | formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_misc_form.png]" |
| | | end |
| | | if page=="bags" then |
| | | formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_bags_main_form.png]" |
| | | end |
| | | |
| | | for i=1,4 do |
| | | if page=="bag"..i then |
| | | local slots = player:get_inventory():get_stack(page, 1):get_definition().groups.bagslots |
| | | if slots == 8 then |
| | | formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_bags_sm_form.png]" |
| | | elseif slots == 16 then |
| | | formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_bags_med_form.png]" |
| | | elseif slots == 24 then |
| | | formspec = formspec .. "background[0.12,1.05,;7.8,7.4;ui_bags_lg_form.png]" |
| | | end |
| | | end |
| | | end |
| | | |
| | | -- main buttons |
| | | formspec = formspec .. "button[0,9;1.8,.5;craft;Craft]" |
| | |
| | | end |
| | | end |
| | | end |
| | | |
| | | |
| | | -- bags |
| | | if page=="bags" then |
| | | formspec = formspec.."label[0,0;Bags]" |
| | | 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]" |
| | | formspec=formspec.."button[4,2;2,0.5;bag3;Bag 3]" |
| | |
| | | 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;]" |
| | | end |
| | | |
| | | |
| | | for i=1,4 do |
| | | if page=="bag"..i then |
| | | local image = player:get_inventory():get_stack("bag"..i, 1):get_definition().inventory_image |
| | |
| | | formspec=formspec.."list[current_player;bag"..i.."contents;0,1;8,3;]" |
| | | end |
| | | end |
| | | |
| | | |
| | | -- Miscellaneous |
| | | if page=="misc" then |
| | | formspec = formspec.."label[0,0;Miscellaneous]" |
| | |
| | | formspec=formspec.."button[0,2;2,0.5;misc_set_day;Set Day]" |
| | | formspec=formspec.."button[2,2;2,0.5;misc_set_night;Set Night]" |
| | | end |
| | | formspec = formspec.."label[0,3;Sound volume: "..unified_inventory.players[player_name]["sound_volume"].."]" |
| | | formspec=formspec.."button[2.5,3;.8,0.5;misc_vol_down;-]" |
| | | formspec=formspec.."button[3.2,3;.8,0.5;misc_vol_up;+]" |
| | | end |
| | | |
| | | |
| | | --Items list |
| | | local list_index=unified_inventory.current_index[player_name] |
| | | local page=math.floor(list_index / (80) + 1) |
| | |
| | | minetest.chat_send_player(player_name, "You don't have settime priviledge!") |
| | | end |
| | | end |
| | | if fields.misc_vol_down then |
| | | local sound_volume=unified_inventory.players[player_name]["sound_volume"] |
| | | sound_volume=sound_volume-1 |
| | | if sound_volume<0 then sound_volume=0 end |
| | | minetest.setting_set("sound_volume",sound_volume/10) |
| | | unified_inventory.players[player_name]["sound_volume"]=sound_volume |
| | | unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"misc")) |
| | | end |
| | | if fields.misc_vol_up then |
| | | local sound_volume=unified_inventory.players[player_name]["sound_volume"] |
| | | sound_volume=sound_volume+1 |
| | | if sound_volume>10 then sound_volume=10 end |
| | | minetest.setting_set("sound_volume",sound_volume/10) |
| | | unified_inventory.players[player_name]["sound_volume"]=sound_volume |
| | | unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"misc")) |
| | | end |
| | | |
| | | -- Inventory page controls |
| | | local start=math.floor(unified_inventory.current_index[player_name]/80 +1 ) |
| | |
| | | end |
| | | |
| | | if fields.searchbutton then |
| | | unified_inventory.apply_filter(player_name, fields.searchbox) |
| | | unified_inventory.apply_filter(player, fields.searchbox) |
| | | unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,unified_inventory.current_page[player_name])) |
| | | end |
| | | |
| | |
| | | end |
| | | |
| | | --apply filter to the inventory list (create filtered copy of full one) |
| | | unified_inventory.apply_filter = function(player_name,filter) |
| | | unified_inventory.apply_filter = function(player,filter) |
| | | local player_name = player:get_player_name() |
| | | local size=0 |
| | | local str_temp1=string.lower(filter) |
| | | local str_temp2 |