Make creative more convenient to use

This commit is contained in:
Wuzzy 2017-01-23 00:33:01 +01:00
parent 19cd922396
commit 558d54befc
1 changed files with 42 additions and 40 deletions

View File

@ -31,7 +31,7 @@ function init()
end end
end, end,
}) })
set_inv("all") set_inv("#all")
end end
function set_inv(filter, player) function set_inv(filter, player)
@ -91,7 +91,7 @@ function set_inv(filter, player)
table.insert(creative_list, name) table.insert(creative_list, name)
end end
elseif filter == "all" then elseif filter == "#all" then
table.insert(creative_list, name) table.insert(creative_list, name)
else --for all other else --for all other
if string.find(string.lower(def.name), filter) or string.find(string.lower(def.description), filter) then if string.find(string.lower(def.name), filter) or string.find(string.lower(def.description), filter) then
@ -180,7 +180,7 @@ local function reset_menu_item_bg()
end end
crafting.set_creative_formspec = function(player, start_i, pagenum, show, page) crafting.set_creative_formspec = function(player, start_i, pagenum, show, page, filter)
reset_menu_item_bg() reset_menu_item_bg()
pagenum = math.floor(pagenum) or 1 pagenum = math.floor(pagenum) or 1
local pagemax = math.floor((crafting.creative_inventory_size-1) / (9*5) + 1) local pagemax = math.floor((crafting.creative_inventory_size-1) / (9*5) + 1)
@ -258,7 +258,13 @@ crafting.set_creative_formspec = function(player, start_i, pagenum, show, page)
"image[9,7;1,1;crafting_creative_trash.png]".. "image[9,7;1,1;crafting_creative_trash.png]"..
listrings listrings
if name == "nix" then formspec = formspec .. "field[5.3,1.3;4,0.75;suche;;]" end if name == "nix" then
if filter == nil then
filter = ""
end
formspec = formspec .. "field[5.3,1.3;4,0.75;suche;;"..filter.."]"
formspec = formspec .. "field_close_on_enter[suche;false]"
end
if pagenum ~= nil then formspec = formspec .. "p"..tostring(pagenum) end if pagenum ~= nil then formspec = formspec .. "p"..tostring(pagenum) end
player:set_inventory_formspec(formspec) player:set_inventory_formspec(formspec)
@ -273,57 +279,47 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.bgcolor then if fields.bgcolor then
minetest.chat_send_all("jupp") minetest.chat_send_all("jupp")
end end
if fields.suche ~= nil and fields.suche ~= "" then
set_inv(string.lower(fields.suche))
minetest.show_formspec(player:get_player_name(), "detached:creative", player:get_inventory_formspec())
end
if fields.blocks then if fields.blocks then
set_inv("#blocks",player) set_inv("#blocks",player)
page = "blocks" page = "blocks"
end elseif fields.deco then
if fields.deco then
set_inv("#deco",player) set_inv("#deco",player)
page = "deco" page = "deco"
end elseif fields.redstone then
if fields.redstone then
set_inv("#redstone",player) set_inv("#redstone",player)
page = "redstone" page = "redstone"
end elseif fields.rail then
if fields.rail then
set_inv("#rail",player) set_inv("#rail",player)
page = "rail" page = "rail"
end elseif fields.misc then
if fields.misc then
set_inv("#misc",player) set_inv("#misc",player)
page = "misc" page = "misc"
end elseif fields.nix then
if fields.default then set_inv("#all",player)
set_inv("all") page = "nix"
page = nil elseif fields.food then
end set_inv("#food",player)
if fields.food then
set_inv("#food")
page = "food" page = "food"
end elseif fields.tools then
if fields.tools then set_inv("#tools",player)
set_inv("#tools")
page = "tools" page = "tools"
end elseif fields.combat then
if fields.combat then set_inv("#combat",player)
set_inv("#combat")
page = "combat" page = "combat"
end elseif fields.brew then
if fields.brew then set_inv("#brew",player)
set_inv("#brew")
page = "brew" page = "brew"
end elseif fields.matr then
if fields.matr then set_inv("#matr",player)
set_inv("#matr")
page = "matr" page = "matr"
end elseif fields.inv then
if fields.inv then
page = "inv" page = "inv"
elseif fields.suche == "" then
set_inv("#all", player)
page = "nix"
elseif fields.suche ~= nil then
set_inv(string.lower(fields.suche),player)
page = "nix"
end end
-- Figure out current page from formspec -- Figure out current page from formspec
local current_page = 0 local current_page = 0
@ -353,7 +349,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if start_i < 0 or start_i >= crafting.creative_inventory_size then if start_i < 0 or start_i >= crafting.creative_inventory_size then
start_i = 0 start_i = 0
end end
crafting.set_creative_formspec(player, start_i, start_i / (9*5) + 1, false, page)
local filter
if fields.suche ~= nil and fields.suche ~= "" then
filter = fields.suche
end
crafting.set_creative_formspec(player, start_i, start_i / (9*5) + 1, false, page, filter)
end) end)