Add button to toggle crafting guide mode
This commit is contained in:
parent
6ecbcd0a84
commit
1fa07b17d7
@ -1,5 +1,9 @@
|
|||||||
local S = minetest.get_translator("crafting")
|
local S = minetest.get_translator("crafting")
|
||||||
|
|
||||||
|
-- Crafting menu display modes
|
||||||
|
local MODE_CRAFTABLE = 1 -- crafting guide mode, show all recipes (default)
|
||||||
|
local MODE_GUIDE = 2 -- craftable mode, only show recipes craftable from input slots
|
||||||
|
|
||||||
--
|
--
|
||||||
-- API
|
-- API
|
||||||
--
|
--
|
||||||
@ -275,6 +279,7 @@ form = form .. "listring[current_player;craft_out]"
|
|||||||
form = form .. default.ui.get_itemslot_bg(0.25, 0.25, 1, 4)
|
form = form .. default.ui.get_itemslot_bg(0.25, 0.25, 1, 4)
|
||||||
form = form .. default.ui.get_itemslot_bg(7.25, 3.25, 1, 1)
|
form = form .. default.ui.get_itemslot_bg(7.25, 3.25, 1, 1)
|
||||||
|
|
||||||
|
form = form .. default.ui.button(1.25, 3.25, 1.0, 1.0, "toggle_filter", S("T"), nil, S("Show all recipes/show only craftable recipes"))
|
||||||
form = form .. default.ui.button(7.25, 1.25, 1, 1, "do_craft_1", "1")
|
form = form .. default.ui.button(7.25, 1.25, 1, 1, "do_craft_1", "1")
|
||||||
form = form .. default.ui.button(7.25, 2.25, 1, 1, "do_craft_10", "10")
|
form = form .. default.ui.button(7.25, 2.25, 1, 1, "do_craft_10", "10")
|
||||||
|
|
||||||
@ -294,7 +299,12 @@ function crafting.get_formspec(name)
|
|||||||
|
|
||||||
local craft_list = ""
|
local craft_list = ""
|
||||||
|
|
||||||
local craftitems = crafting.get_crafts(inv)
|
local craftitems
|
||||||
|
if crafting.userdata[name] and crafting.userdata[name].mode == MODE_GUIDE then
|
||||||
|
craftitems = crafting.get_crafts()
|
||||||
|
else
|
||||||
|
craftitems = crafting.get_crafts(inv)
|
||||||
|
end
|
||||||
|
|
||||||
local selected_craftdef = nil
|
local selected_craftdef = nil
|
||||||
|
|
||||||
@ -409,7 +419,12 @@ local function on_player_receive_fields(player, form_name, fields)
|
|||||||
end
|
end
|
||||||
do_craft_10 = fields.do_craft_10 ~= nil
|
do_craft_10 = fields.do_craft_10 ~= nil
|
||||||
if do_craft_1 or do_craft_10 then
|
if do_craft_1 or do_craft_10 then
|
||||||
local craftitems = crafting.get_crafts(inv)
|
local craftitems
|
||||||
|
if crafting.userdata[name] and crafting.userdata[name].mode == MODE_GUIDE then
|
||||||
|
craftitems = crafting.get_crafts()
|
||||||
|
else
|
||||||
|
craftitems = crafting.get_crafts(inv)
|
||||||
|
end
|
||||||
|
|
||||||
local wanted_itemstack = ItemStack(craftitems[crafting.userdata[name].row])
|
local wanted_itemstack = ItemStack(craftitems[crafting.userdata[name].row])
|
||||||
local output_itemstack = inv:get_stack("craft_out", 1)
|
local output_itemstack = inv:get_stack("craft_out", 1)
|
||||||
@ -456,6 +471,14 @@ local function on_player_receive_fields(player, form_name, fields)
|
|||||||
minetest.show_formspec(name, "crafting:crafting",
|
minetest.show_formspec(name, "crafting:crafting",
|
||||||
crafting.get_formspec(name, crafting.userdata[name].row))
|
crafting.get_formspec(name, crafting.userdata[name].row))
|
||||||
end
|
end
|
||||||
|
elseif fields.toggle_filter then
|
||||||
|
if crafting.userdata[name].mode == MODE_GUIDE then
|
||||||
|
crafting.userdata[name].mode = MODE_CRAFTABLE
|
||||||
|
else
|
||||||
|
crafting.userdata[name].mode = MODE_GUIDE
|
||||||
|
end
|
||||||
|
minetest.show_formspec(name, "crafting:crafting",
|
||||||
|
crafting.get_formspec(name, crafting.userdata[name].row))
|
||||||
end
|
end
|
||||||
|
|
||||||
player:set_inventory_formspec(crafting.get_formspec(name))
|
player:set_inventory_formspec(crafting.get_formspec(name))
|
||||||
@ -486,7 +509,7 @@ local function on_joinplayer(player)
|
|||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
|
|
||||||
if crafting.userdata[name] == nil then
|
if crafting.userdata[name] == nil then
|
||||||
crafting.userdata[name] = {row = 1}
|
crafting.userdata[name] = {row = 1, mode = MODE_CRAFTABLE}
|
||||||
end
|
end
|
||||||
|
|
||||||
if inv:get_size("craft_in") ~= 4 then
|
if inv:get_size("craft_in") ~= 4 then
|
||||||
|
3
mods/crafting/locale/crafting.de.tr
Normal file
3
mods/crafting/locale/crafting.de.tr
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# textdomain:crafting
|
||||||
|
T=U
|
||||||
|
Show all recipes/show only craftable recipes=Alle Rezepte zeigen/nur mögliche Rezepte zeigen
|
3
mods/crafting/locale/template.txt
Normal file
3
mods/crafting/locale/template.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# textdomain:crafting
|
||||||
|
T=
|
||||||
|
Show all recipes/show only craftable recipes=
|
@ -59,50 +59,71 @@ end
|
|||||||
|
|
||||||
-- Buttons
|
-- Buttons
|
||||||
|
|
||||||
function default.ui.image_button(x, y, w, h, name, image)
|
function default.ui.image_button(x, y, w, h, name, image, tooltip)
|
||||||
local image = minetest.formspec_escape(image)
|
local image = minetest.formspec_escape(image)
|
||||||
|
|
||||||
|
local tt = ""
|
||||||
|
if tooltip then
|
||||||
|
tt = "tooltip["..name..";"..minetest.formspec_escape(tooltip).."]"
|
||||||
|
end
|
||||||
|
|
||||||
return "image_button["..x..","..y..";"..w..","..h..";"
|
return "image_button["..x..","..y..";"..w..","..h..";"
|
||||||
..image..";"..name..";;;false;"..image.."]"
|
..image..";"..name..";;;false;"..image.."]"
|
||||||
|
..tt
|
||||||
end
|
end
|
||||||
|
|
||||||
function default.ui.button(x, y, w, h, name, label, noclip)
|
function default.ui.button(x, y, w, h, name, label, noclip, tooltip)
|
||||||
local nc = "false"
|
local nc = "false"
|
||||||
|
|
||||||
if noclip then
|
if noclip then
|
||||||
nc = "true"
|
nc = "true"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local tt = ""
|
||||||
|
if tooltip then
|
||||||
|
tt = "tooltip["..name..";"..minetest.formspec_escape(tooltip).."]"
|
||||||
|
end
|
||||||
|
|
||||||
if w == 1 then
|
if w == 1 then
|
||||||
return "image_button["..x..","..y..";"..w..","..h
|
return "image_button["..x..","..y..";"..w..","..h
|
||||||
..";ui_button_1w_inactive.png;"..name..";"..minetest.formspec_escape(label)..";"
|
..";ui_button_1w_inactive.png;"..name..";"..minetest.formspec_escape(label)..";"
|
||||||
..nc..";false;ui_button_1w_active.png]"
|
..nc..";false;ui_button_1w_active.png]"
|
||||||
|
..tt
|
||||||
elseif w == 2 then
|
elseif w == 2 then
|
||||||
return "image_button["..x..","..y..";"..w..","..h
|
return "image_button["..x..","..y..";"..w..","..h
|
||||||
..";ui_button_2w_inactive.png;"..name..";"..minetest.formspec_escape(label)..";"
|
..";ui_button_2w_inactive.png;"..name..";"..minetest.formspec_escape(label)..";"
|
||||||
..nc..";false;ui_button_2w_active.png]"
|
..nc..";false;ui_button_2w_active.png]"
|
||||||
|
..tt
|
||||||
else
|
else
|
||||||
return "image_button["..x..","..y..";"..w..","..h
|
return "image_button["..x..","..y..";"..w..","..h
|
||||||
..";ui_button_3w_inactive.png;"..name..";"..minetest.formspec_escape(label)..";"
|
..";ui_button_3w_inactive.png;"..name..";"..minetest.formspec_escape(label)..";"
|
||||||
..nc..";false;ui_button_3w_active.png]"
|
..nc..";false;ui_button_3w_active.png]"
|
||||||
|
..tt
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function default.ui.button_exit(x, y, w, h, name, label, noclip)
|
function default.ui.button_exit(x, y, w, h, name, label, noclip, tooltip)
|
||||||
local nc = "false"
|
local nc = "false"
|
||||||
|
|
||||||
if noclip then
|
if noclip then
|
||||||
nc = "true"
|
nc = "true"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local tt = ""
|
||||||
|
if tooltip then
|
||||||
|
tt = "tooltip["..name..";"..minetest.formspec_escape(tooltip).."]"
|
||||||
|
end
|
||||||
|
|
||||||
if w == 2 then
|
if w == 2 then
|
||||||
return "image_button_exit["..x..","..y..";"..w..","..h
|
return "image_button_exit["..x..","..y..";"..w..","..h
|
||||||
..";ui_button_2w_inactive.png;"..name..";"..minetest.formspec_escape(label)..";"
|
..";ui_button_2w_inactive.png;"..name..";"..minetest.formspec_escape(label)..";"
|
||||||
..nc..";false;ui_button_2w_active.png]"
|
..nc..";false;ui_button_2w_active.png]"
|
||||||
|
..tt
|
||||||
else
|
else
|
||||||
return "image_button_exit["..x..","..y..";"..w..","..h
|
return "image_button_exit["..x..","..y..";"..w..","..h
|
||||||
..";ui_button_3w_inactive.png;"..name..";"..minetest.formspec_escape(label)..";"
|
..";ui_button_3w_inactive.png;"..name..";"..minetest.formspec_escape(label)..";"
|
||||||
..nc..";false;ui_button_3w_active.png]"
|
..nc..";false;ui_button_3w_active.png]"
|
||||||
|
..tt
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user