sync with Technic's UI

This commit is contained in:
RealBadAngel 2013-03-03 16:28:24 +01:00
parent 2fa07f5c30
commit adac1aedc4
36 changed files with 121 additions and 62 deletions

@ -1,11 +1,13 @@
-- override minetest.register_craft
crafts_table ={} crafts_table ={}
crafts_table_count=0 crafts_table_count=0
UI_recipes_hook=true
-- override minetest.register_craft
local minetest_register_craft = minetest.register_craft local minetest_register_craft = minetest.register_craft
minetest.register_craft = function (options) minetest.register_craft = function (options)
minetest_register_craft(options)
register_craft(options) register_craft(options)
if options.type=="alloy" or options.type=="grinding" then return end
minetest_register_craft(options)
end end
-- register_craft -- register_craft

@ -36,13 +36,14 @@ end)
-- register_on_joinplayer -- register_on_joinplayer
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
local player_name = player:get_player_name() 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.current_index[player_name] = 1
unified_inventory.filtered_items_list[player_name] = {} unified_inventory.filtered_items_list[player_name] = {}
unified_inventory.filtered_items_list[player_name] = unified_inventory.items_list 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.filtered_items_list_size[player_name]=unified_inventory.items_list_size
unified_inventory.activefilter[player_name]="" unified_inventory.activefilter[player_name]=""
unified_inventory.apply_filter(player_name, "") unified_inventory.apply_filter(player, "")
unified_inventory.alternate[player_name] = 1 unified_inventory.alternate[player_name] = 1
unified_inventory.current_item[player_name] =nil unified_inventory.current_item[player_name] =nil
unified_inventory.set_inventory_formspec(player,unified_inventory.get_formspec(player, unified_inventory.default)) unified_inventory.set_inventory_formspec(player,unified_inventory.get_formspec(player, unified_inventory.default))
@ -53,7 +54,11 @@ local inv = minetest.create_detached_inventory(player:get_player_name().."craftr
return 0 return 0
end, end,
allow_take = function(inv, listname, index, stack, player) 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, end,
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
return 0 return 0
@ -73,6 +78,7 @@ unified_inventory.refill = minetest.create_detached_inventory(player_name.."refi
end, end,
on_put = function(inv, listname, index, stack, player) on_put = function(inv, listname, index, stack, player)
inv:set_stack(listname, index, ItemStack(stack:get_name().." "..stack:get_stack_max())) inv:set_stack(listname, index, ItemStack(stack:get_name().." "..stack:get_stack_max()))
minetest.sound_play("electricity", {to_player=player_name, gain = 1.0})
end, end,
}) })
unified_inventory.refill:set_size("main", 1) unified_inventory.refill:set_size("main", 1)
@ -89,6 +95,8 @@ unified_inventory.trash = minetest.create_detached_inventory("trash", {
end, end,
on_put = function(inv, listname, index, stack, player) on_put = function(inv, listname, index, stack, player)
inv:set_stack(listname, index, nil) inv:set_stack(listname, index, nil)
local player_name=player:get_player_name()
minetest.sound_play("trash", {to_player=player_name, gain = 1.0})
end, end,
}) })
unified_inventory.trash:set_size("main", 1) unified_inventory.trash:set_size("main", 1)
@ -114,29 +122,64 @@ unified_inventory.get_formspec = function(player,page)
unified_inventory.current_page[player_name]=page unified_inventory.current_page[player_name]=page
local formspec = "size[14,10]" local formspec = "size[14,10]"
-- player inventory -- player inventory
formspec = formspec .. "list[current_player;main;0,4.5;8,4;]" 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 -- main buttons
formspec = formspec .. "button[0,9;1.8,.5;craft;Craft]" local start_x=0
formspec = formspec .. "button[1.6,9;1.8,.5;craftguide;Craft Guide]" formspec = formspec .. "image_button["..(start_x+.65*0)..",9;.8,.8;ui_craft_icon.png;craft;]"
formspec = formspec .. "button[3.2,9;1.8,.5;bags;Bags]" formspec = formspec .. "image_button["..(start_x+.65*1)..",9;.8,.8;ui_craftguide_icon.png;craftguide;]"
formspec = formspec .. "button[4.8,9;1.8,.5;misc;Misc.]" formspec = formspec .. "image_button["..(start_x+.65*2)..",9;.8,.8;ui_bags_icon.png;bags;]"
formspec = formspec .. "image_button["..(start_x+.65*3)..",9;.8,.8;ui_sethome_icon.png;home_gui_set;]"
formspec = formspec .. "image_button["..(start_x+.65*4)..",9;.8,.8;ui_gohome_icon.png;home_gui_go;]"
if minetest.setting_getbool("creative_mode") then
formspec = formspec .. "image_button["..(start_x+.65*5)..",9;.8,.8;ui_sun_icon.png;misc_set_day;]"
formspec = formspec .. "image_button["..(start_x+.65*6)..",9;.8,.8;ui_moon_icon.png;misc_set_night;]"
formspec = formspec .. "image_button["..(start_x+.65*7)..",9;.8,.8;ui_trash_icon.png;clear_inv;]"
end
--controls to flip items pages --controls to flip items pages
local start_x=9.2 start_x=9.2
formspec = formspec .. "button["..(start_x+.6*0)..",9;.8,.5;start_list;|<]" formspec = formspec .. "image_button["..(start_x+.6*0)..",9;.8,.8;ui_skip_backward_icon.png;start_list;]"
formspec = formspec .. "button["..(start_x+.6*1)..",9;.8,.5;rewind3;<<]" formspec = formspec .. "image_button["..(start_x+.6*1)..",9;.8,.8;ui_doubleleft_icon.png;rewind3;]"
formspec = formspec .. "button["..(start_x+.6*2)..",9;.8,.5;rewind1;<]" formspec = formspec .. "image_button["..(start_x+.6*2)..",9;.8,.8;ui_left_icon.png;rewind1;]"
formspec = formspec .. "button["..(start_x+.6*3)..",9;.8,.5;forward1;>]" formspec = formspec .. "image_button["..(start_x+.6*3)..",9;.8,.8;ui_right_icon.png;forward1;]"
formspec = formspec .. "button["..(start_x+.6*4)..",9;.8,.5;forward3;>>]" formspec = formspec .. "image_button["..(start_x+.6*4)..",9;.8,.8;ui_doubleright_icon.png;forward3;]"
formspec = formspec .. "button["..(start_x+.6*5)..",9;.8,.5;end_list;>|]" formspec = formspec .. "image_button["..(start_x+.6*5)..",9;.8,.8;ui_skip_forward_icon.png;end_list;]"
-- search box -- search box
formspec = formspec .. "field[9.195,8.325;3,1;searchbox;;]" formspec = formspec .. "field[9.5,8.325;3,1;searchbox;;]"
formspec = formspec .. "button[12,8;1.2,1;searchbutton;Search]" formspec = formspec .. "image_button[12.2,8.1;.8,.8;ui_search_icon.png;searchbutton;]"
-- craft page -- craft page
if page=="craft" then if page=="craft" then
formspec = formspec.."label[0,0;Crafting]" formspec = formspec.."label[0,0;Crafting]"
@ -149,7 +192,7 @@ unified_inventory.get_formspec = function(player,page)
formspec = formspec.."list[detached:trash;main;7,3;1,1;]" formspec = formspec.."list[detached:trash;main;7,3;1,1;]"
end end
end end
-- craft guide page -- craft guide page
if page=="craftguide" then if page=="craftguide" then
formspec = formspec.."label[0,0;Crafting Guide]" formspec = formspec.."label[0,0;Crafting Guide]"
@ -164,7 +207,7 @@ unified_inventory.get_formspec = function(player,page)
local alternates = 0 local alternates = 0
local alternate = unified_inventory.alternate[player_name] local alternate = unified_inventory.alternate[player_name]
local crafts = crafts_table[item_name] local crafts = crafts_table[item_name]
if crafts ~= nil then if crafts ~= nil then
alternates = #crafts alternates = #crafts
local craft = crafts[alternate] local craft = crafts[alternate]
@ -193,10 +236,10 @@ unified_inventory.get_formspec = function(player,page)
end end
end end
end end
-- bags -- bags
if page=="bags" then 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[0,2;2,0.5;bag1;Bag 1]"
formspec=formspec.."button[2,2;2,0.5;bag2;Bag 2]" formspec=formspec.."button[2,2;2,0.5;bag2;Bag 2]"
formspec=formspec.."button[4,2;2,0.5;bag3;Bag 3]" formspec=formspec.."button[4,2;2,0.5;bag3;Bag 3]"
@ -206,7 +249,7 @@ unified_inventory.get_formspec = function(player,page)
formspec=formspec.."list[detached:"..player_name.."_bags;bag3;4.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;]" formspec=formspec.."list[detached:"..player_name.."_bags;bag4;6.5,1;1,1;]"
end end
for i=1,4 do for i=1,4 do
if page=="bag"..i then if page=="bag"..i then
local image = player:get_inventory():get_stack("bag"..i, 1):get_definition().inventory_image local image = player:get_inventory():get_stack("bag"..i, 1):get_definition().inventory_image
@ -214,24 +257,7 @@ unified_inventory.get_formspec = function(player,page)
formspec=formspec.."list[current_player;bag"..i.."contents;0,1;8,3;]" formspec=formspec.."list[current_player;bag"..i.."contents;0,1;8,3;]"
end end
end end
-- Miscellaneous
if page=="misc" then
formspec = formspec.."label[0,0;Miscellaneous]"
formspec=formspec.."button[0,1;2,0.5;home_gui_set;Set Home]"
formspec=formspec.."button_exit[2,1;2,0.5;home_gui_go;Go Home]"
local home = homepos[player_name]
if home ~= nil then
formspec = formspec
formspec=formspec.."label[4,.9;Home set to:]"
formspec=formspec.."label[5.7,.9;("..math.floor(home.x)..","..math.floor(home.y)..","..math.floor(home.z)..")]"
end
if minetest.setting_getbool("creative_mode") then
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
end
--Items list --Items list
local list_index=unified_inventory.current_index[player_name] local list_index=unified_inventory.current_index[player_name]
local page=math.floor(list_index / (80) + 1) local page=math.floor(list_index / (80) + 1)
@ -257,28 +283,26 @@ 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()
-- main buttons -- main buttons
if fields.craft then if fields.craft then
unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"craft")) unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"craft"))
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
return return
end end
if fields.craftguide then if fields.craftguide then
unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"craftguide")) unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"craftguide"))
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
return return
end end
if fields.bags then if fields.bags then
unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"bags")) unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"bags"))
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
return return
end end
if fields.misc then
unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"misc"))
return
end
-- bags -- bags
for i=1,4 do for i=1,4 do
local page = "bag"..i local page = "bag"..i
@ -287,21 +311,28 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
page = "bags" page = "bags"
end end
unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,page)) unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,page))
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
return return
end end
end end
-- Miscellaneous -- Miscellaneous
if fields.home_gui_set then if fields.home_gui_set then
unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"misc"))
unified_inventory.set_home(player, player:getpos()) unified_inventory.set_home(player, player:getpos())
local home = homepos[player_name]
if home ~= nil then
minetest.sound_play("dingdong", {to_player=player_name, gain = 1.0})
minetest.chat_send_player(player_name, "Home position set to: "..math.floor(home.x)..","..math.floor(home.y)..","..math.floor(home.z))
end
end end
if fields.home_gui_go then if fields.home_gui_go then
unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"craft")) unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"craft"))
minetest.sound_play("teleport", {to_player=player_name, gain = 1.0})
unified_inventory.go_home(player) unified_inventory.go_home(player)
end end
if fields.misc_set_day then if fields.misc_set_day then
if minetest.get_player_privs(player_name).settime==true then if minetest.get_player_privs(player_name).settime==true then
minetest.sound_play("birds", {to_player=player_name, gain = 1.0})
minetest.env:set_timeofday((6000 % 24000) / 24000) minetest.env:set_timeofday((6000 % 24000) / 24000)
minetest.chat_send_player(player_name, "Time of day set to 6am") minetest.chat_send_player(player_name, "Time of day set to 6am")
else else
@ -310,12 +341,20 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
if fields.misc_set_night then if fields.misc_set_night then
if minetest.get_player_privs(player_name).settime==true then if minetest.get_player_privs(player_name).settime==true then
minetest.sound_play("owl", {to_player=player_name, gain = 1.0})
minetest.env:set_timeofday((21000 % 24000) / 24000) minetest.env:set_timeofday((21000 % 24000) / 24000)
minetest.chat_send_player(player_name, "Time of day set to 9pm") minetest.chat_send_player(player_name, "Time of day set to 9pm")
else else
minetest.chat_send_player(player_name, "You don't have settime priviledge!") minetest.chat_send_player(player_name, "You don't have settime priviledge!")
end end
end end
if fields.clear_inv then
local inventory = {}
player:get_inventory():set_list("main", inventory)
minetest.chat_send_player(player_name, 'Inventory Cleared!')
minetest.sound_play("trash_all", {to_player=player_name, gain = 1.0})
end
-- Inventory page controls -- Inventory page controls
local start=math.floor(unified_inventory.current_index[player_name]/80 +1 ) local start=math.floor(unified_inventory.current_index[player_name]/80 +1 )
@ -323,21 +362,27 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
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
minetest.sound_play("paperflip1", {to_player=player_name, gain = 1.0})
start_i = 1 start_i = 1
end end
if fields.rewind1 then if fields.rewind1 then
minetest.sound_play("paperflip1", {to_player=player_name, gain = 1.0})
start_i = start_i - 1 start_i = start_i - 1
end end
if fields.forward1 then if fields.forward1 then
minetest.sound_play("paperflip1", {to_player=player_name, gain = 1.0})
start_i = start_i + 1 start_i = start_i + 1
end end
if fields.rewind3 then if fields.rewind3 then
minetest.sound_play("paperflip1", {to_player=player_name, gain = 1.0})
start_i = start_i - 3 start_i = start_i - 3
end end
if fields.forward3 then if fields.forward3 then
minetest.sound_play("paperflip1", {to_player=player_name, gain = 1.0})
start_i = start_i + 3 start_i = start_i + 3
end end
if fields.end_list then if fields.end_list then
minetest.sound_play("paperflip1", {to_player=player_name, gain = 1.0})
start_i = pagemax start_i = pagemax
end end
if start_i < 1 then if start_i < 1 then
@ -357,10 +402,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
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
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
if minetest.setting_getbool("creative_mode")==false then if minetest.setting_getbool("creative_mode")==false then
unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"craftguide")) unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,"craftguide"))
page="craftguide" page="craftguide"
end end
if page=="craftguide" then if page=="craftguide" then
unified_inventory.current_item[player_name] = unified_inventory.filtered_items_list[player_name][list_index] unified_inventory.current_item[player_name] = unified_inventory.filtered_items_list[player_name][list_index]
unified_inventory.alternate[player_name] = 1 unified_inventory.alternate[player_name] = 1
@ -381,13 +427,15 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
list_index=list_index+1 list_index=list_index+1
end end
if fields.searchbutton then if fields.searchbutton or fields.searchbox 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])) unified_inventory.set_inventory_formspec(player, unified_inventory.get_formspec(player,unified_inventory.current_page[player_name]))
minetest.sound_play("paperflip2", {to_player=player_name, gain = 1.0})
end end
-- alternate button -- alternate button
if fields.alternate then if fields.alternate then
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
local item_name=unified_inventory.current_item[player_name] local item_name=unified_inventory.current_item[player_name]
if item_name then if item_name then
local alternates = 0 local alternates = 0
@ -432,7 +480,8 @@ load_home() -- run it now
-- set_home -- set_home
unified_inventory.set_home = function(player, pos) unified_inventory.set_home = function(player, pos)
homepos[player:get_player_name()] = pos local player_name=player:get_player_name()
homepos[player_name] = pos
-- save the home data from the table to the file -- save the home data from the table to the file
local output = io.open(unified_inventory.home_filename..".home", "w") local output = io.open(unified_inventory.home_filename..".home", "w")
for k, v in pairs(homepos) do for k, v in pairs(homepos) do
@ -452,9 +501,17 @@ unified_inventory.go_home = function(player)
end end
--apply filter to the inventory list (create filtered copy of full one) --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 size=0
local str_temp1=string.lower(filter) local str_temp1=string.lower(filter)
if str_temp1 ~= "" then
for i=1,str_temp1:len(),1 do
if string.byte(str_temp1,i) == 91 then
str_temp1=""
end
end
end
local str_temp2 local str_temp2
local str_temp3 local str_temp3
unified_inventory.filtered_items_list[player_name]={} unified_inventory.filtered_items_list[player_name]={}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB