2019-09-19 14:00:26 +02:00
|
|
|
local S = minetest.get_translator("unified_inventory")
|
2019-09-19 14:15:10 +02:00
|
|
|
local NS = function(s) return s end
|
2018-04-02 13:33:36 +02:00
|
|
|
local F = minetest.formspec_escape
|
2021-03-07 14:18:17 +01:00
|
|
|
local ui = unified_inventory
|
2013-09-29 00:15:37 +02:00
|
|
|
|
|
|
|
minetest.register_privilege("creative", {
|
2016-08-05 19:34:40 +02:00
|
|
|
description = S("Can use the creative inventory"),
|
2013-09-29 00:15:37 +02:00
|
|
|
give_to_singleplayer = false,
|
|
|
|
})
|
|
|
|
|
2015-10-05 10:24:01 +02:00
|
|
|
minetest.register_privilege("ui_full", {
|
2016-08-05 19:34:40 +02:00
|
|
|
description = S("Forces Unified Inventory to be displayed in Full mode if Lite mode is configured globally"),
|
2015-10-05 10:24:01 +02:00
|
|
|
give_to_singleplayer = false,
|
|
|
|
})
|
|
|
|
|
2013-09-29 00:15:37 +02:00
|
|
|
local trash = minetest.create_detached_inventory("trash", {
|
|
|
|
--allow_put = function(inv, listname, index, stack, player)
|
2021-03-07 14:18:17 +01:00
|
|
|
-- if ui.is_creative(player:get_player_name()) then
|
2013-09-29 00:15:37 +02:00
|
|
|
-- return stack:get_count()
|
|
|
|
-- else
|
|
|
|
-- return 0
|
|
|
|
-- end
|
|
|
|
--end,
|
|
|
|
on_put = function(inv, listname, index, stack, player)
|
|
|
|
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,
|
|
|
|
})
|
|
|
|
trash:set_size("main", 1)
|
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.register_button("craft", {
|
2013-09-29 00:15:37 +02:00
|
|
|
type = "image",
|
|
|
|
image = "ui_craft_icon.png",
|
2014-06-22 00:34:35 +02:00
|
|
|
tooltip = S("Crafting Grid")
|
2013-09-29 00:15:37 +02:00
|
|
|
})
|
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.register_button("craftguide", {
|
2013-09-29 00:15:37 +02:00
|
|
|
type = "image",
|
|
|
|
image = "ui_craftguide_icon.png",
|
2014-06-21 12:44:31 +02:00
|
|
|
tooltip = S("Crafting Guide")
|
2013-09-29 00:15:37 +02:00
|
|
|
})
|
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.register_button("home_gui_set", {
|
2015-10-05 10:24:01 +02:00
|
|
|
type = "image",
|
|
|
|
image = "ui_sethome_icon.png",
|
|
|
|
tooltip = S("Set home position"),
|
|
|
|
hide_lite=true,
|
|
|
|
action = function(player)
|
|
|
|
local player_name = player:get_player_name()
|
|
|
|
if minetest.check_player_privs(player_name, {home=true}) then
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.set_home(player, player:get_pos())
|
|
|
|
local home = ui.home_pos[player_name]
|
2015-10-05 10:24:01 +02:00
|
|
|
if home ~= nil then
|
|
|
|
minetest.sound_play("dingdong",
|
|
|
|
{to_player=player_name, gain = 1.0})
|
2015-06-28 09:47:03 +02:00
|
|
|
minetest.chat_send_player(player_name,
|
2019-09-19 14:15:10 +02:00
|
|
|
S("Home position set to: @1", minetest.pos_to_string(home)))
|
2015-06-28 09:47:03 +02:00
|
|
|
end
|
2015-10-05 10:24:01 +02:00
|
|
|
else
|
|
|
|
minetest.chat_send_player(player_name,
|
|
|
|
S("You don't have the \"home\" privilege!"))
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
2015-10-05 10:24:01 +02:00
|
|
|
end
|
|
|
|
end,
|
2016-11-06 02:28:45 +01:00
|
|
|
condition = function(player)
|
|
|
|
return minetest.check_player_privs(player:get_player_name(), {home=true})
|
|
|
|
end,
|
2015-10-05 10:24:01 +02:00
|
|
|
})
|
2013-09-29 00:15:37 +02:00
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.register_button("home_gui_go", {
|
2015-10-05 10:24:01 +02:00
|
|
|
type = "image",
|
|
|
|
image = "ui_gohome_icon.png",
|
|
|
|
tooltip = S("Go home"),
|
|
|
|
hide_lite=true,
|
|
|
|
action = function(player)
|
|
|
|
local player_name = player:get_player_name()
|
|
|
|
if minetest.check_player_privs(player_name, {home=true}) then
|
2021-03-07 14:18:17 +01:00
|
|
|
if ui.go_home(player) then
|
2020-07-10 21:58:45 +02:00
|
|
|
minetest.sound_play("teleport", {to_player = player_name})
|
|
|
|
end
|
2015-10-05 10:24:01 +02:00
|
|
|
else
|
|
|
|
minetest.chat_send_player(player_name,
|
|
|
|
S("You don't have the \"home\" privilege!"))
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
2015-10-05 10:24:01 +02:00
|
|
|
end
|
|
|
|
end,
|
2016-11-06 02:28:45 +01:00
|
|
|
condition = function(player)
|
|
|
|
return minetest.check_player_privs(player:get_player_name(), {home=true})
|
|
|
|
end,
|
2015-10-05 10:24:01 +02:00
|
|
|
})
|
2013-09-29 00:15:37 +02:00
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.register_button("misc_set_day", {
|
2015-10-05 10:24:01 +02:00
|
|
|
type = "image",
|
|
|
|
image = "ui_sun_icon.png",
|
|
|
|
tooltip = S("Set time to day"),
|
|
|
|
hide_lite=true,
|
|
|
|
action = function(player)
|
|
|
|
local player_name = player:get_player_name()
|
|
|
|
if minetest.check_player_privs(player_name, {settime=true}) then
|
|
|
|
minetest.sound_play("birds",
|
|
|
|
{to_player=player_name, gain = 1.0})
|
|
|
|
minetest.set_timeofday((6000 % 24000) / 24000)
|
|
|
|
minetest.chat_send_player(player_name,
|
|
|
|
S("Time of day set to 6am"))
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(player_name,
|
|
|
|
S("You don't have the settime privilege!"))
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
2015-10-05 10:24:01 +02:00
|
|
|
end
|
|
|
|
end,
|
2016-11-06 02:28:45 +01:00
|
|
|
condition = function(player)
|
|
|
|
return minetest.check_player_privs(player:get_player_name(), {settime=true})
|
|
|
|
end,
|
2015-10-05 10:24:01 +02:00
|
|
|
})
|
2015-06-28 09:47:03 +02:00
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.register_button("misc_set_night", {
|
2015-10-05 10:24:01 +02:00
|
|
|
type = "image",
|
|
|
|
image = "ui_moon_icon.png",
|
|
|
|
tooltip = S("Set time to night"),
|
|
|
|
hide_lite=true,
|
|
|
|
action = function(player)
|
|
|
|
local player_name = player:get_player_name()
|
|
|
|
if minetest.check_player_privs(player_name, {settime=true}) then
|
|
|
|
minetest.sound_play("owl",
|
|
|
|
{to_player=player_name, gain = 1.0})
|
|
|
|
minetest.set_timeofday((21000 % 24000) / 24000)
|
|
|
|
minetest.chat_send_player(player_name,
|
|
|
|
S("Time of day set to 9pm"))
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(player_name,
|
|
|
|
S("You don't have the settime privilege!"))
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
2015-10-05 10:24:01 +02:00
|
|
|
end
|
|
|
|
end,
|
2016-11-06 02:28:45 +01:00
|
|
|
condition = function(player)
|
|
|
|
return minetest.check_player_privs(player:get_player_name(), {settime=true})
|
|
|
|
end,
|
2015-10-05 10:24:01 +02:00
|
|
|
})
|
2013-09-29 00:15:37 +02:00
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.register_button("clear_inv", {
|
2013-09-29 00:15:37 +02:00
|
|
|
type = "image",
|
|
|
|
image = "ui_trash_icon.png",
|
2014-06-21 12:44:31 +02:00
|
|
|
tooltip = S("Clear inventory"),
|
2013-09-29 00:15:37 +02:00
|
|
|
action = function(player)
|
|
|
|
local player_name = player:get_player_name()
|
2021-03-07 14:18:17 +01:00
|
|
|
if not ui.is_creative(player_name) then
|
2013-09-29 00:15:37 +02:00
|
|
|
minetest.chat_send_player(player_name,
|
2014-06-22 00:34:35 +02:00
|
|
|
S("This button has been disabled outside"
|
2013-09-29 00:15:37 +02:00
|
|
|
.." of creative mode to prevent"
|
|
|
|
.." accidental inventory trashing."
|
2014-06-22 00:34:35 +02:00
|
|
|
.."\nUse the trash slot instead."))
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.set_inventory_formspec(player, ui.current_page[player_name])
|
2013-09-29 00:15:37 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
player:get_inventory():set_list("main", {})
|
2016-08-05 19:34:40 +02:00
|
|
|
minetest.chat_send_player(player_name, S('Inventory cleared!'))
|
2013-09-29 00:15:37 +02:00
|
|
|
minetest.sound_play("trash_all",
|
|
|
|
{to_player=player_name, gain = 1.0})
|
|
|
|
end,
|
2016-11-06 02:28:45 +01:00
|
|
|
condition = function(player)
|
2021-03-07 14:18:17 +01:00
|
|
|
return ui.is_creative(player:get_player_name())
|
2016-11-06 02:28:45 +01:00
|
|
|
end,
|
2013-09-29 00:15:37 +02:00
|
|
|
})
|
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.register_page("craft", {
|
2015-10-05 10:24:01 +02:00
|
|
|
get_formspec = function(player, perplayer_formspec)
|
|
|
|
|
2021-03-05 16:58:18 +01:00
|
|
|
local formheaderx = perplayer_formspec.form_header_x
|
|
|
|
local formheadery = perplayer_formspec.form_header_y
|
|
|
|
local craftx = perplayer_formspec.craft_x
|
|
|
|
local crafty = perplayer_formspec.craft_y
|
|
|
|
local craftresultx = craftx + 5
|
2015-10-05 10:24:01 +02:00
|
|
|
|
2013-09-29 00:15:37 +02:00
|
|
|
local player_name = player:get_player_name()
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
local formspec = {
|
|
|
|
string.format("image[%f,%f;%f,%f;ui_crafting_form.png]", craftx, crafty, ui.imgscale*6, ui.imgscale*3),
|
|
|
|
perplayer_formspec.standard_inv_bg,
|
|
|
|
"label["..formheaderx..","..formheadery..";" ..F(S("Crafting")).."]",
|
|
|
|
"listcolors[#00000000;#00000000]",
|
|
|
|
"list[current_player;craftpreview;"..(craftresultx+0.15)..","..(crafty+0.15)..";1,1;]",
|
|
|
|
"list[current_player;craft;"..(craftx+0.15)..","..(crafty+0.15)..";3,3;]",
|
|
|
|
"listring[current_name;craft]",
|
|
|
|
"listring[current_player;main]"
|
|
|
|
}
|
|
|
|
local n=#formspec+1
|
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
if ui.trash_enabled or ui.is_creative(player_name) or minetest.get_player_privs(player_name).give then
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = string.format("label[%f,%f;%s]", craftx + 6.45, crafty + 2.4, F(S("Trash:")))
|
|
|
|
formspec[n+1] = string.format("image[%f,%f;%f,%f;ui_trash_slot.png]",
|
|
|
|
craftx+6.25, crafty + 2.5, ui.imgscale, ui.imgscale)
|
|
|
|
formspec[n+2] = string.format("list[detached:trash;main;%f,%f;1,1;]", craftx + 6.4, crafty + 2.65)
|
|
|
|
n=n+3
|
2017-03-01 23:28:40 +01:00
|
|
|
end
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
if ui.is_creative(player_name) then
|
2021-03-08 15:14:21 +01:00
|
|
|
formspec[n] = string.format("image[%f,%f;%f,%f;ui_single_slot.png]",
|
|
|
|
perplayer_formspec.craft_x - 2.5, perplayer_formspec.craft_y + 2.5,
|
|
|
|
ui.imgscale, ui.imgscale)
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n+1] = string.format("label[%f,%f;%s]", craftx - 2.3, crafty + 2.4,F(S("Refill:")))
|
2021-03-08 15:14:21 +01:00
|
|
|
formspec[n+2] = string.format("list[detached:%srefill;main;%f,%f;1,1;]",
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
F(player_name), craftx - 2.35, crafty + 2.65)
|
2013-09-29 00:15:37 +02:00
|
|
|
end
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
return {formspec=table.concat(formspec)}
|
2013-09-29 00:15:37 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2014-05-01 15:22:25 +02:00
|
|
|
-- stack_image_button(): generate a form button displaying a stack of items
|
|
|
|
--
|
2014-05-01 17:08:24 +02:00
|
|
|
-- The specified item may be a group. In that case, the group will be
|
|
|
|
-- represented by some item in the group, along with a flag indicating
|
|
|
|
-- that it's a group. If the group contains only one item, it will be
|
|
|
|
-- treated as if that item had been specified directly.
|
2014-05-12 04:00:32 +02:00
|
|
|
|
|
|
|
local function stack_image_button(x, y, w, h, buttonname_prefix, item)
|
|
|
|
local name = item:get_name()
|
|
|
|
local count = item:get_count()
|
|
|
|
local show_is_group = false
|
2016-02-09 04:42:31 +01:00
|
|
|
local displayitem = name.." "..count
|
2014-05-12 04:00:32 +02:00
|
|
|
local selectitem = name
|
|
|
|
if name:sub(1, 6) == "group:" then
|
|
|
|
local group_name = name:sub(7)
|
2021-03-07 14:18:17 +01:00
|
|
|
local group_item = ui.get_group_item(group_name)
|
2014-06-13 10:54:21 +02:00
|
|
|
show_is_group = not group_item.sole
|
2014-05-12 04:00:32 +02:00
|
|
|
displayitem = group_item.item or "unknown"
|
|
|
|
selectitem = group_item.sole and displayitem or name
|
2014-05-01 15:22:25 +02:00
|
|
|
end
|
2016-02-09 04:42:31 +01:00
|
|
|
local label = show_is_group and "G" or ""
|
2021-03-07 14:18:17 +01:00
|
|
|
local buttonname = F(buttonname_prefix..ui.mangle_for_formspec(selectitem))
|
2016-08-07 01:39:19 +02:00
|
|
|
local button = string.format("item_image_button[%f,%f;%f,%f;%s;%s;%s]",
|
2014-05-12 04:00:32 +02:00
|
|
|
x, y, w, h,
|
2018-04-02 13:33:36 +02:00
|
|
|
F(displayitem), buttonname, label)
|
2016-08-07 01:39:19 +02:00
|
|
|
if show_is_group then
|
2021-03-07 14:18:17 +01:00
|
|
|
local groupstring, andcount = ui.extract_groupnames(name)
|
2016-08-07 01:39:19 +02:00
|
|
|
local grouptip
|
|
|
|
if andcount == 1 then
|
2019-09-19 14:15:10 +02:00
|
|
|
grouptip = S("Any item belonging to the @1 group", groupstring)
|
2016-08-07 01:39:19 +02:00
|
|
|
elseif andcount > 1 then
|
2019-09-19 14:15:10 +02:00
|
|
|
grouptip = S("Any item belonging to the groups @1", groupstring)
|
2016-08-07 01:39:19 +02:00
|
|
|
end
|
2018-04-02 13:33:36 +02:00
|
|
|
grouptip = F(grouptip)
|
2016-08-07 01:39:19 +02:00
|
|
|
if andcount >= 1 then
|
|
|
|
button = button .. string.format("tooltip[%s;%s]", buttonname, grouptip)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return button
|
2014-05-01 15:22:25 +02:00
|
|
|
end
|
|
|
|
|
2014-06-13 16:04:20 +02:00
|
|
|
local recipe_text = {
|
2019-09-19 14:15:10 +02:00
|
|
|
recipe = NS("Recipe @1 of @2"),
|
|
|
|
usage = NS("Usage @1 of @2"),
|
2014-06-13 16:04:20 +02:00
|
|
|
}
|
|
|
|
local no_recipe_text = {
|
2018-04-02 13:33:36 +02:00
|
|
|
recipe = S("No recipes"),
|
|
|
|
usage = S("No usages"),
|
2014-06-13 16:04:20 +02:00
|
|
|
}
|
|
|
|
local role_text = {
|
2018-04-02 13:33:36 +02:00
|
|
|
recipe = S("Result"),
|
|
|
|
usage = S("Ingredient"),
|
2014-06-13 16:04:20 +02:00
|
|
|
}
|
2016-08-06 23:04:51 +02:00
|
|
|
local next_alt_text = {
|
2018-04-02 13:33:36 +02:00
|
|
|
recipe = S("Show next recipe"),
|
|
|
|
usage = S("Show next usage"),
|
2016-08-06 23:04:51 +02:00
|
|
|
}
|
|
|
|
local prev_alt_text = {
|
2018-04-02 13:33:36 +02:00
|
|
|
recipe = S("Show previous recipe"),
|
|
|
|
usage = S("Show previous usage"),
|
2016-08-06 23:04:51 +02:00
|
|
|
}
|
2014-06-13 16:04:20 +02:00
|
|
|
local other_dir = {
|
2018-04-08 22:21:44 +02:00
|
|
|
recipe = "usage",
|
|
|
|
usage = "recipe",
|
2014-06-13 16:04:20 +02:00
|
|
|
}
|
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.register_page("craftguide", {
|
2015-10-05 10:24:01 +02:00
|
|
|
get_formspec = function(player, perplayer_formspec)
|
|
|
|
|
2021-03-05 16:58:18 +01:00
|
|
|
local craftx = perplayer_formspec.craft_x
|
|
|
|
local crafty = perplayer_formspec.craft_y
|
|
|
|
local craftarrowx = craftx + 3.75
|
|
|
|
local craftresultx = craftx + 5
|
|
|
|
local formheaderx = perplayer_formspec.form_header_x
|
2015-10-05 10:24:01 +02:00
|
|
|
local formheadery = perplayer_formspec.form_header_y
|
2021-03-07 10:13:36 +01:00
|
|
|
local give_x = perplayer_formspec.give_btn_x
|
2015-10-05 10:24:01 +02:00
|
|
|
|
2013-09-29 00:15:37 +02:00
|
|
|
local player_name = player:get_player_name()
|
2015-02-07 18:10:14 +01:00
|
|
|
local player_privs = minetest.get_player_privs(player_name)
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
local formspec = {
|
2021-03-05 16:58:18 +01:00
|
|
|
perplayer_formspec.standard_inv_bg,
|
|
|
|
"label["..formheaderx..","..formheadery..";" .. F(S("Crafting Guide")) .. "]",
|
2019-03-31 11:26:02 +02:00
|
|
|
"listcolors[#00000000;#00000000]"
|
|
|
|
}
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
local item_name = ui.current_item[player_name]
|
2019-03-31 11:26:02 +02:00
|
|
|
if not item_name then
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
return { formspec = table.concat(formspec) }
|
2019-03-31 11:26:02 +02:00
|
|
|
end
|
|
|
|
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
local n = 4
|
|
|
|
|
2016-10-29 14:20:11 +02:00
|
|
|
local item_name_shown
|
2019-03-31 11:26:02 +02:00
|
|
|
if minetest.registered_items[item_name]
|
|
|
|
and minetest.registered_items[item_name].description then
|
2019-09-19 14:15:10 +02:00
|
|
|
item_name_shown = S("@1 (@2)",
|
2019-03-31 11:26:02 +02:00
|
|
|
minetest.registered_items[item_name].description, item_name)
|
2016-10-29 14:20:11 +02:00
|
|
|
else
|
|
|
|
item_name_shown = item_name
|
|
|
|
end
|
2014-06-13 13:35:12 +02:00
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
local dir = ui.current_craft_direction[player_name]
|
2019-03-31 11:26:02 +02:00
|
|
|
local rdir = dir == "recipe" and "usage" or "recipe"
|
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
local crafts = ui.crafts_for[dir][item_name]
|
|
|
|
local alternate = ui.alternate[player_name]
|
2014-06-13 16:04:20 +02:00
|
|
|
local alternates, craft
|
2019-03-31 11:26:02 +02:00
|
|
|
if crafts and #crafts > 0 then
|
2014-04-30 02:10:46 +02:00
|
|
|
alternates = #crafts
|
|
|
|
craft = crafts[alternate]
|
|
|
|
end
|
2021-03-07 14:18:17 +01:00
|
|
|
local has_give = player_privs.give or ui.is_creative(player_name)
|
2014-05-12 04:00:32 +02:00
|
|
|
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = "image["..craftarrowx..","..crafty..";1.25,1.25;ui_crafting_arrow.png]"
|
|
|
|
formspec[n+1] = string.format("textarea[%f,%f;10,1;;%s: %s;]",
|
2021-03-05 16:58:18 +01:00
|
|
|
craftx-2.3, perplayer_formspec.resultstr_y, F(role_text[dir]), item_name_shown)
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
n = n + 2
|
2021-03-05 16:58:18 +01:00
|
|
|
|
|
|
|
local giveme_form = table.concat({
|
2021-03-07 10:13:36 +01:00
|
|
|
"label[".. (give_x+0.1)..",".. (crafty + 2.7) .. ";" .. F(S("Give me:")) .. "]",
|
|
|
|
"button["..(give_x)..",".. (crafty + 2.9) .. ";0.75,0.5;craftguide_giveme_1;1]",
|
|
|
|
"button["..(give_x+0.8)..",".. (crafty + 2.9) .. ";0.75,0.5;craftguide_giveme_10;10]",
|
|
|
|
"button["..(give_x+1.6)..",".. (crafty + 2.9) .. ";0.75,0.5;craftguide_giveme_99;99]"
|
2021-03-05 16:58:18 +01:00
|
|
|
})
|
2014-06-13 16:04:20 +02:00
|
|
|
|
2014-06-13 13:35:12 +02:00
|
|
|
if not craft then
|
2019-03-31 11:26:02 +02:00
|
|
|
-- No craft recipes available for this item.
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = string.format("label[%f,%f;%s]", craftx+2.5, crafty+1.5, F(no_recipe_text[dir]))
|
2021-03-05 16:58:18 +01:00
|
|
|
local no_pos = dir == "recipe" and (craftx+2.5) or craftresultx
|
|
|
|
local item_pos = dir == "recipe" and craftresultx or (craftx+2.5)
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n+1] = "image["..no_pos..","..crafty..";1.2,1.2;ui_no.png]"
|
|
|
|
formspec[n+2] = stack_image_button(item_pos, crafty, 1.2, 1.2,
|
2019-03-31 11:26:02 +02:00
|
|
|
"item_button_" .. other_dir[dir] .. "_", ItemStack(item_name))
|
2019-02-17 15:14:38 +01:00
|
|
|
if has_give then
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n+3] = giveme_form
|
2015-02-07 18:10:14 +01:00
|
|
|
end
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
return { formspec = table.concat(formspec) }
|
2021-03-05 16:58:18 +01:00
|
|
|
else
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = stack_image_button(craftresultx, crafty, 1.2, 1.2,
|
2021-03-05 16:58:18 +01:00
|
|
|
"item_button_" .. rdir .. "_", ItemStack(craft.output))
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n+1] = stack_image_button(craftx-2.3, crafty, 1.2, 1.2,
|
2021-03-05 16:58:18 +01:00
|
|
|
"item_button_usage_", ItemStack(item_name))
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
n = n + 2
|
2014-04-30 01:11:10 +02:00
|
|
|
end
|
2013-10-03 04:20:54 +02:00
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
local craft_type = ui.registered_craft_types[craft.type] or
|
|
|
|
ui.craft_type_defaults(craft.type, {})
|
2015-02-07 18:10:40 +01:00
|
|
|
if craft_type.icon then
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = string.format("image[%f,%f;%f,%f;%s]",
|
2021-03-05 16:58:18 +01:00
|
|
|
craftarrowx+0.1, crafty + 0.95, 1, 1, craft_type.icon)
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
n = n + 1
|
2015-02-07 18:10:40 +01:00
|
|
|
end
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = string.format("label[%f,%f;%s]", craftarrowx+0.15, crafty+0.2, F(craft_type.description))
|
|
|
|
n = n + 1
|
2019-03-31 11:26:02 +02:00
|
|
|
|
|
|
|
local display_size = craft_type.dynamic_display_size
|
|
|
|
and craft_type.dynamic_display_size(craft)
|
|
|
|
or { width = craft_type.width, height = craft_type.height }
|
|
|
|
local craft_width = craft_type.get_shaped_craft_width
|
|
|
|
and craft_type.get_shaped_craft_width(craft)
|
|
|
|
or display_size.width
|
2013-10-03 04:20:54 +02:00
|
|
|
|
2014-05-12 04:00:32 +02:00
|
|
|
-- This keeps recipes aligned to the right,
|
|
|
|
-- so that they're close to the arrow.
|
2021-03-05 16:58:18 +01:00
|
|
|
local xoffset = craftx+3.75
|
|
|
|
local bspc = 1.25
|
2016-08-07 13:20:42 +02:00
|
|
|
-- Offset factor for crafting grids with side length > 4
|
|
|
|
local of = (3/math.max(3, math.max(display_size.width, display_size.height)))
|
2016-08-07 14:54:50 +02:00
|
|
|
local od = 0
|
2021-03-05 16:58:18 +01:00
|
|
|
-- Minimum grid size at which size optimization measures kick in
|
2016-08-07 14:54:50 +02:00
|
|
|
local mini_craft_size = 6
|
|
|
|
if display_size.width >= mini_craft_size then
|
|
|
|
od = math.max(1, display_size.width - 2)
|
|
|
|
xoffset = xoffset - 0.1
|
|
|
|
end
|
2016-08-07 13:20:42 +02:00
|
|
|
-- Size modifier factor
|
2016-08-07 14:54:50 +02:00
|
|
|
local sf = math.min(1, of * (1.05 + 0.05*od))
|
2016-08-07 16:01:53 +02:00
|
|
|
-- Button size
|
2021-03-05 16:58:18 +01:00
|
|
|
local bsize = 1.2 * sf
|
|
|
|
|
|
|
|
if display_size.width >= mini_craft_size then -- it's not a normal 3x3 grid
|
|
|
|
bsize = 0.8 * sf
|
2016-08-07 14:54:50 +02:00
|
|
|
end
|
2021-03-05 16:58:18 +01:00
|
|
|
if (bsize > 0.35 and display_size.width) then
|
2014-06-13 13:15:50 +02:00
|
|
|
for y = 1, display_size.height do
|
2016-08-07 16:01:53 +02:00
|
|
|
for x = 1, display_size.width do
|
2014-06-13 13:15:50 +02:00
|
|
|
local item
|
|
|
|
if craft and x <= craft_width then
|
|
|
|
item = craft.items[(y-1) * craft_width + x]
|
|
|
|
end
|
2016-08-07 16:01:53 +02:00
|
|
|
-- Flipped x, used to build formspec buttons from right to left
|
|
|
|
local fx = display_size.width - (x-1)
|
|
|
|
-- x offset, y offset
|
2021-03-05 16:58:18 +01:00
|
|
|
local xof = ((fx-1) * of + of) * bspc
|
|
|
|
local yof = ((y-1) * of + 1) * bspc
|
2013-10-03 04:20:54 +02:00
|
|
|
if item then
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = stack_image_button(
|
2021-03-05 16:58:18 +01:00
|
|
|
xoffset - xof, crafty - 1.25 + yof, bsize, bsize,
|
2014-06-13 16:04:20 +02:00
|
|
|
"item_button_recipe_",
|
|
|
|
ItemStack(item))
|
2014-05-12 04:00:32 +02:00
|
|
|
else
|
|
|
|
-- Fake buttons just to make grid
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = string.format("image_button[%f,%f;%f,%f;ui_blank_image.png;;]",
|
2021-03-05 16:58:18 +01:00
|
|
|
xoffset - xof, crafty - 1.25 + yof, bsize, bsize)
|
2013-10-03 04:20:54 +02:00
|
|
|
end
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
n = n + 1
|
2013-10-03 04:20:54 +02:00
|
|
|
end
|
|
|
|
end
|
2016-08-07 14:54:50 +02:00
|
|
|
else
|
|
|
|
-- Error
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = string.format("label[2,%f;%s]",
|
2021-03-05 16:58:18 +01:00
|
|
|
crafty, F(S("This recipe is too@nlarge to be displayed.")))
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
n = n + 1
|
2016-08-07 14:54:50 +02:00
|
|
|
end
|
2014-04-30 01:11:10 +02:00
|
|
|
|
2016-08-07 15:08:40 +02:00
|
|
|
if craft_type.uses_crafting_grid and display_size.width <= 3 then
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = "label["..(give_x+0.1)..",".. (crafty + 1.7) .. ";" .. F(S("To craft grid:")) .. "]"
|
|
|
|
formspec[n+1] = "button[".. (give_x)..",".. (crafty + 1.9) .. ";0.75,0.5;craftguide_craft_1;1]"
|
|
|
|
formspec[n+2] = "button[".. (give_x+0.8)..",".. (crafty + 1.9) .. ";0.75,0.5;craftguide_craft_10;10]"
|
|
|
|
formspec[n+3] = "button[".. (give_x+1.6)..",".. (crafty + 1.9) .. ";0.75,0.5;craftguide_craft_max;" .. F(S("All")) .. "]"
|
|
|
|
n = n + 4
|
2015-02-07 18:10:14 +01:00
|
|
|
end
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
|
2019-02-17 15:14:38 +01:00
|
|
|
if has_give then
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = giveme_form
|
|
|
|
n = n + 1
|
2014-04-30 01:11:10 +02:00
|
|
|
end
|
|
|
|
|
2014-05-12 04:00:32 +02:00
|
|
|
if alternates and alternates > 1 then
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
formspec[n] = string.format("label[%f,%f;%s]",
|
|
|
|
craftx+4, crafty + 2.3, F(S(recipe_text[dir], alternate, alternates)))
|
|
|
|
formspec[n+1] = string.format("image_button[%f,%f;1.1,1.1;ui_left_icon.png;alternate_prev;]",
|
|
|
|
craftarrowx+0.2, crafty + 2.6)
|
|
|
|
formspec[n+2] = string.format("image_button[%f,%f;1.1,1.1;ui_right_icon.png;alternate;]",
|
|
|
|
craftarrowx+1.35, crafty + 2.6)
|
|
|
|
formspec[n+3] = "tooltip[alternate_prev;" .. F(prev_alt_text[dir]) .. "]"
|
|
|
|
formspec[n+4] = "tooltip[alternate;" .. F(next_alt_text[dir]) .. "]"
|
2014-04-30 01:11:10 +02:00
|
|
|
end
|
Multiple related changes to string handling
1) Convert most formspec elements to use string.format(), when the
result would be more readable, or less messy, or at least makes the line
shorter, assuming it looked like it really needed it to begin with.
2) Convert all long `foo..","..bar..";"..baz..bleh..` types of excessive
string concatenation into tables that then get concated only once, when
their containing functions return the final formspec string.
3) In some places in the code, such tables were already being used, and
were named "formspec", while others were named "fs". I settled on just
one name, "formspec", as it's more readable, if longer.
4) There was a mix of styles of adding items to those tables:
* Some places used line after line of `t[#t + 1] = foo/bar/baz`.
* Others places used the form `t[1] = foo, t[2] = bar, ...`.
* Still others used the form `t[n] = foo, t[n+1] = bar...`,
with `n` being increased or reset every so often.
Most of them should now be of the third form, with a few of the second.
2021-03-07 16:37:20 +01:00
|
|
|
|
|
|
|
return { formspec = table.concat(formspec) }
|
2013-09-29 00:15:37 +02:00
|
|
|
end,
|
|
|
|
})
|
2013-10-03 05:25:07 +02:00
|
|
|
|
2015-02-07 18:10:14 +01:00
|
|
|
local function craftguide_giveme(player, formname, fields)
|
2019-02-17 15:14:38 +01:00
|
|
|
local player_name = player:get_player_name()
|
|
|
|
local player_privs = minetest.get_player_privs(player_name)
|
|
|
|
if not player_privs.give and
|
2021-03-07 14:18:17 +01:00
|
|
|
not ui.is_creative(player_name) then
|
2019-02-17 15:14:38 +01:00
|
|
|
minetest.log("action", "[unified_inventory] Denied give action to player " ..
|
|
|
|
player_name)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-02-07 18:10:14 +01:00
|
|
|
local amount
|
|
|
|
for k, v in pairs(fields) do
|
|
|
|
amount = k:match("craftguide_giveme_(.*)")
|
|
|
|
if amount then break end
|
|
|
|
end
|
|
|
|
|
2019-02-17 15:14:38 +01:00
|
|
|
amount = tonumber(amount) or 0
|
2015-02-07 18:10:14 +01:00
|
|
|
if amount == 0 then return end
|
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
local output = ui.current_item[player_name]
|
2015-02-07 18:10:14 +01:00
|
|
|
if (not output) or (output == "") then return end
|
|
|
|
|
|
|
|
local player_inv = player:get_inventory()
|
|
|
|
|
|
|
|
player_inv:add_item("main", {name = output, count = amount})
|
|
|
|
end
|
|
|
|
|
|
|
|
local function craftguide_craft(player, formname, fields)
|
2013-10-21 00:02:25 +02:00
|
|
|
local amount
|
|
|
|
for k, v in pairs(fields) do
|
|
|
|
amount = k:match("craftguide_craft_(.*)")
|
|
|
|
if amount then break end
|
|
|
|
end
|
|
|
|
if not amount then return end
|
2019-03-02 08:56:14 +01:00
|
|
|
|
2019-10-26 17:22:33 +02:00
|
|
|
amount = tonumber(amount) or -1 -- fallback for "all"
|
|
|
|
if amount == 0 or amount < -1 or amount > 99 then return end
|
2019-03-02 08:56:14 +01:00
|
|
|
|
2013-10-21 00:02:25 +02:00
|
|
|
local player_name = player:get_player_name()
|
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
local output = ui.current_item[player_name] or ""
|
2019-03-02 08:56:14 +01:00
|
|
|
if output == "" then return end
|
2013-10-21 00:02:25 +02:00
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
local crafts = ui.crafts_for[
|
|
|
|
ui.current_craft_direction[player_name]][output] or {}
|
2019-03-02 08:56:14 +01:00
|
|
|
if #crafts == 0 then return end
|
2013-10-21 00:02:25 +02:00
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
local alternate = ui.alternate[player_name]
|
2013-10-21 00:02:25 +02:00
|
|
|
|
|
|
|
local craft = crafts[alternate]
|
|
|
|
if craft.width > 3 then return end
|
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.craftguide_match_craft(player, "main", "craft", craft, amount)
|
2013-10-21 00:02:25 +02:00
|
|
|
|
2021-03-07 14:18:17 +01:00
|
|
|
ui.set_inventory_formspec(player, "craft")
|
2015-02-07 18:10:14 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
2019-02-17 15:14:38 +01:00
|
|
|
if formname ~= "" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-02-07 18:10:14 +01:00
|
|
|
for k, v in pairs(fields) do
|
|
|
|
if k:match("craftguide_craft_") then
|
|
|
|
craftguide_craft(player, formname, fields)
|
2015-08-16 16:40:49 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if k:match("craftguide_giveme_") then
|
2015-02-07 18:10:14 +01:00
|
|
|
craftguide_giveme(player, formname, fields)
|
2015-08-16 16:40:49 +02:00
|
|
|
return
|
2015-02-07 18:10:14 +01:00
|
|
|
end
|
|
|
|
end
|
2013-10-21 00:02:25 +02:00
|
|
|
end)
|