Compare commits

..

24 Commits

Author SHA1 Message Date
fcea88ac8c Remove useless stuff 2020-12-31 02:50:13 +01:00
8bde3fd86b Remove unused setting 2020-12-31 00:36:57 +01:00
fd764e2e36 Minor fix 2 2020-12-31 00:11:36 +01:00
d6083e2c03 Minor fix 2020-12-30 23:48:58 +01:00
42e255f07f Divorce inventory from craftguide (moved to my new repo "i3") 2020-12-30 23:41:21 +01:00
fab1c54234 WIP inventory mode 2020-12-30 23:13:09 +01:00
46c0d9e81b tweak icon 2020-12-28 21:15:11 +01:00
9e50192c54 New export icon 2020-12-28 20:50:02 +01:00
12aad9e55f Correct positioning 2020-12-28 03:30:15 +01:00
1fe30415f3 Update License 2020-12-26 20:49:09 +01:00
cce82cdbb4 Add vignette when opening the guide 2020-12-26 02:11:16 +01:00
63ae743a68 Small tweak 2020-12-26 01:18:49 +01:00
2e30413b52 Rename function 2020-12-25 23:12:25 +01:00
83832b4508 Add tooltips in header in case strings too long 2020-12-25 22:16:03 +01:00
e2864d9cd0 Minor teak 2020-12-25 21:22:10 +01:00
fa2910925e New screenshot 2020-12-25 20:59:47 +01:00
6cb4888722 New next/prev textures 2020-12-25 20:45:02 +01:00
7d9ddcb397 Tuning 2020-12-25 19:42:40 +01:00
75e1acad46 Rename file names 2020-12-25 19:25:48 +01:00
a5e913f3a4 New search icon 2020-12-25 19:21:19 +01:00
24fdd07f56 Minor fix 2020-12-24 23:12:38 +01:00
7e70ccab27 Minor tweaks 2020-12-22 22:14:57 +01:00
3bd2da9e32 Update Screenshot 2020-12-20 15:47:06 +01:00
b7bfa5a623 Little correction 2020-12-20 15:02:11 +01:00
19 changed files with 315 additions and 167 deletions

View File

@ -4,8 +4,6 @@ allow_defined_top = true
read_globals = {
"minetest",
"default",
"sfinv",
"sfinv_buttons",
"vector",
"string",
"table",

View File

@ -11,9 +11,6 @@ This crafting guide features a **progressive mode**.
This mode is a Terraria-like system that shows recipes you can craft
from items you ever had in your inventory. To enable it: `craftguide_progressive_mode = true` in `minetest.conf`.
`craftguide` is also integrated in `sfinv` (Minetest Game inventory). To enable it:
`craftguide_sfinv_only = true` in `minetest.conf`.
Use the command `/craft` to show the recipe(s) of the pointed node.
For developers, `craftguide` also has a [modding API](https://github.com/minetest-mods/craftguide/blob/master/API.md).
@ -21,4 +18,4 @@ For developers, `craftguide` also has a [modding API](https://github.com/minetes
Love this mod? Donations are appreciated: https://www.paypal.me/jpg84240
![Preview2](https://i.imgur.com/JllwFGg.png)
![Preview2](https://user-images.githubusercontent.com/7883281/103141399-113b5e00-46f4-11eb-96cd-0167972ca1cf.png)

447
init.lua
View File

@ -78,22 +78,34 @@ local MIN_FORMSPEC_VERSION = 4
local PNG = {
bg = "craftguide_bg.png",
bg_full = "craftguide_bg_full.png",
search = "craftguide_search_icon.png",
prev = "craftguide_next_icon.png^\\[transformFX",
next = "craftguide_next_icon.png",
search = "craftguide_search.png",
prev = "craftguide_next.png^\\[transformFX",
next = "craftguide_next.png",
arrow = "craftguide_arrow.png",
trash = "craftguide_trash.png",
sort_az = "craftguide_sort.png",
sort_za = "craftguide_sort2.png",
compress = "craftguide_compress.png",
fire = "craftguide_fire.png",
fire_anim = "craftguide_fire_anim.png",
book = "craftguide_book.png",
sign = "craftguide_sign.png",
cancel = "craftguide_cancel.png",
selected = "craftguide_selected.png",
export = "craftguide_export.png",
slot = "craftguide_slot.png",
tab = "craftguide_tab.png",
furnace_anim = "craftguide_furnace_anim.png",
cancel_hover = "craftguide_cancel.png^\\[brighten",
search_hover = "craftguide_search_icon_hover.png",
prev_hover = "craftguide_next_icon_hover.png^\\[transformFX",
next_hover = "craftguide_next_icon_hover.png",
search_hover = "craftguide_search.png^\\[brighten",
export_hover = "craftguide_export.png^\\[brighten",
trash_hover = "craftguide_trash.png^\\[brighten",
compress_hover = "craftguide_compress.png^\\[brighten",
sort_az_hover = "craftguide_sort.png^\\[brighten",
sort_za_hover = "craftguide_sort2.png^\\[brighten",
prev_hover = "craftguide_next_hover.png^\\[transformFX",
next_hover = "craftguide_next_hover.png",
tab_hover = "craftguide_tab_hover.png",
}
local fs_elements = {
@ -104,43 +116,51 @@ local fs_elements = {
tooltip = "tooltip[%f,%f;%f,%f;%s]",
item_image = "item_image[%f,%f;%f,%f;%s]",
bg9 = "background9[%f,%f;%f,%f;%s;false;%u]",
model = "model[%f,%f;%f,%f;%s;%s;%s;0,0;true;true;%s]",
model = "model[%f,%f;%f,%f;%s;%s;%s;%s;%s;true;%s]",
image_button = "image_button[%f,%f;%f,%f;%s;%s;%s]",
animated_image = "animated_image[%f,%f;%f,%f;;%s;%u;%u]",
scrollbar = "scrollbar[%f,%f;%f,%f;horizontal;%s;%u]",
item_image_button = "item_image_button[%f,%f;%f,%f;%s;%s;%s]",
arrow = "image_button[%f,%f;0.7,0.7;%s;%s;;;false;%s]",
}
local styles = sprintf([[
style_type[label,field;font_size=+0]
style_type[image_button;border=false;sound=craftguide_click]
style_type[item_image_button;border=false;bgimg_hovered=%s;bgimg_pressed=%s;
sound=craftguide_click]
style_type[item_image_button;border=false;bgimg_hovered=%s;sound=craftguide_click]
style[filter;border=false]
style[cancel;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
style[search;fgimg=%s;fgimg_hovered=%s]
style[prev_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
style[next_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
style[prev_recipe;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
style[next_recipe;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
style[prev_usage;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
style[next_usage;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
style[cancel;fgimg=%s;fgimg_hovered=%s;content_offset=0]
style[search;fgimg=%s;fgimg_hovered=%s;content_offset=0]
style[trash;fgimg=%s;fgimg_hovered=%s;content_offset=0;sound=craftguide_delete]
style[sort_az;fgimg=%s;fgimg_hovered=%s;content_offset=0]
style[sort_za;fgimg=%s;fgimg_hovered=%s;content_offset=0]
style[compress;fgimg=%s;fgimg_hovered=%s;content_offset=0]
style[prev_page;fgimg=%s;fgimg_hovered=%s]
style[next_page;fgimg=%s;fgimg_hovered=%s]
style[prev_recipe;fgimg=%s;fgimg_hovered=%s]
style[next_recipe;fgimg=%s;fgimg_hovered=%s]
style[prev_usage;fgimg=%s;fgimg_hovered=%s]
style[next_usage;fgimg=%s;fgimg_hovered=%s]
style[guide_mode,inv_mode;fgimg_hovered=%s;noclip=true;content_offset=0;sound=craftguide_tab]
style[pagenum,no_item,no_rcp;border=false;font=bold;font_size=+2;content_offset=0]
style[craft_rcp,craft_usg;border=false;noclip=true;font_size=+0;sound=craftguide_craft;
bgimg=craftguide_btn9.png;bgimg_hovered=craftguide_btn9_hovered.png;
bgimg_pressed=craftguide_btn9_pressed.png;bgimg_middle=4,6]
]],
PNG.selected, PNG.selected,
PNG.cancel, PNG.cancel_hover, PNG.cancel_hover,
PNG.slot,
PNG.cancel, PNG.cancel_hover,
PNG.search, PNG.search_hover,
PNG.prev, PNG.prev_hover, PNG.prev_hover,
PNG.next, PNG.next_hover, PNG.next_hover,
PNG.prev, PNG.prev_hover, PNG.prev_hover,
PNG.next, PNG.next_hover, PNG.next_hover,
PNG.prev, PNG.prev_hover, PNG.prev_hover,
PNG.next, PNG.next_hover, PNG.next_hover)
PNG.trash, PNG.trash_hover,
PNG.sort_az, PNG.sort_az_hover,
PNG.sort_za, PNG.sort_za_hover,
PNG.compress, PNG.compress_hover,
PNG.prev, PNG.prev_hover,
PNG.next, PNG.next_hover,
PNG.prev, PNG.prev_hover,
PNG.next, PNG.next_hover,
PNG.prev, PNG.prev_hover,
PNG.next, PNG.next_hover,
PNG.tab_hover)
local function get_lang_code(info)
return info and info.lang_code
@ -844,10 +864,86 @@ local function groups_to_items(groups, get_all)
return get_all and names or ""
end
local function get_stack_max(data, is_recipe, rcp)
data.inv = data.player:get_inventory()
local list = data.inv:get_list("main")
local size = data.inv:get_size("main")
local function sort_itemlist(player, az)
local inv = player:get_inventory()
local list = inv:get_list("main")
local size = inv:get_size("main")
local new_inv, stack_meta = {}, {}
for i = 1, size do
local stack = list[i]
local name = stack:get_name()
local count = stack:get_count()
local empty = stack:is_empty()
local meta = stack:get_meta():to_table()
if not empty then
if next(meta.fields) then
stack_meta[#stack_meta + 1] = stack
else
new_inv[#new_inv + 1] = sprintf("%s %u", name, count)
end
end
end
if az then
sort(new_inv)
else
sort(new_inv, function(a, b) return a > b end)
end
inv:set_list("main", new_inv)
for i = 1, #stack_meta do
inv:set_stack("main", #new_inv + i, stack_meta[i])
end
end
local function compress_items(player)
local inv = player:get_inventory()
local list = inv:get_list("main")
local size = inv:get_size("main")
local new_inv, _new_inv, stack_meta = {}, {}, {}
for i = 1, size do
local stack = list[i]
local name = stack:get_name()
local count = stack:get_count()
local empty = stack:is_empty()
local meta = stack:get_meta():to_table()
if not empty then
if next(meta.fields) then
stack_meta[#stack_meta + 1] = stack
else
new_inv[name] = new_inv[name] or 0
new_inv[name] = new_inv[name] + count
end
end
end
for name, count in pairs(new_inv) do
local stackmax = ItemStack(name):get_stack_max()
local iter = ceil(count / stackmax)
local leftover = count
for _ = 1, iter do
_new_inv[#_new_inv + 1] = sprintf("%s %u", name, min(stackmax, leftover))
leftover = leftover - stackmax
end
end
sort(_new_inv)
inv:set_list("main", _new_inv)
for i = 1, #stack_meta do
inv:set_stack("main", #_new_inv + i, stack_meta[i])
end
end
local function get_stack_max(inv, data, is_recipe, rcp)
local list = inv:get_list("main")
local size = inv:get_size("main")
local counts_inv, counts_rcp, counts = {}, {}, {}
local rcp_usg = is_recipe and "recipe" or "usage"
@ -868,6 +964,8 @@ local function get_stack_max(data, is_recipe, rcp)
for name in pairs(counts_rcp) do
if is_group(name) then
local def = reg_items[item]
if def then
local groups = extract_groups(name)
if item_has_groups(def.groups, groups) then
@ -875,6 +973,7 @@ local function get_stack_max(data, is_recipe, rcp)
end
end
end
end
counts_inv[item] = (counts_inv[item] or 0) + count
end
@ -897,11 +996,29 @@ local function get_stack_max(data, is_recipe, rcp)
return max_stacks
end
local function get_stack(player, pname, stack, message)
local inv = player:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
msg(pname, sprintf("%s added in your inventory", message))
else
local dir = player:get_look_dir()
local ppos = player:get_pos()
ppos.y = ppos.y + 1.625
local look_at = vec_add(ppos, vec_mul(dir, 1))
core.add_item(look_at, stack)
msg(pname, sprintf("%s spawned", message))
end
end
local function craft_stack(player, pname, data, craft_rcp)
local inv = player:get_inventory()
local rcp_usg = craft_rcp and "recipe" or "usage"
local output = craft_rcp and data.recipes[data.rnum].output or data.usages[data.unum].output
output = ItemStack(output)
local stackname, stackcount = output:get_name(), output:get_count()
local stackname, stackcount, stackmax = output:get_name(), output:get_count(), output:get_stack_max()
local scrbar_val = data[sprintf("scrbar_%s", craft_rcp and "rcp" or "usg")] or 1
for name, count in pairs(data.export_counts[rcp_usg].rcp) do
@ -927,36 +1044,32 @@ local function craft_stack(player, pname, data, craft_rcp)
end
for k, v in pairs(items) do
data.inv:remove_item("main", sprintf("%s %s", k, v * scrbar_val))
inv:remove_item("main", sprintf("%s %s", k, v * scrbar_val))
end
end
local count = stackcount * scrbar_val
local stack = ItemStack(sprintf("%s %s", stackname, count))
local desc = get_desc(stackname)
local iter = ceil(count / stackmax)
local leftover = count
for _ = 1, iter do
local c = min(stackmax, leftover)
local message
if count > 1 then
message = clr("#ff0", sprintf("%s x %s", count, desc))
if c > 1 then
message = clr("#ff0", sprintf("%s x %s", c, desc))
else
message = clr("#ff0", sprintf("%s", desc))
end
if data.inv:room_for_item("main", stack) then
data.inv:add_item("main", stack)
msg(pname, sprintf("%s added in your inventory", message))
else
local dir = player:get_look_dir()
local ppos = player:get_pos()
ppos.y = ppos.y + 1.625
local look_at = vec_add(ppos, vec_mul(dir, 1))
core.add_item(look_at, stack)
msg(pname, sprintf("%s crafted", message))
local stack = ItemStack(sprintf("%s %s", stackname, c))
get_stack(player, pname, stack, message)
leftover = leftover - stackmax
end
end
local function select_item(player, data, _f)
local function select_item(player, name, data, _f)
local item
for field in pairs(_f) do
@ -982,7 +1095,6 @@ local function select_item(player, data, _f)
local recipes, usages = get_recipes(item, data, player)
if not recipes and not usages then return end
if data.show_usages and not usages then return end
data.query_item = item
data.recipes = recipes
@ -1124,7 +1236,7 @@ local function get_output_fs(fs, data, rcp, is_recipe, shapeless, right, btn_siz
fs(fmt("image", arrow_X, Y + 0.06, 1, 1, PNG.arrow))
if rcp.type == "fuel" then
fs(fmt("animated_image", X, Y, ITEM_BTN_SIZE, ITEM_BTN_SIZE, PNG.fire_anim, 8, 180))
fs(fmt("animated_image", X + 0.05, Y, ITEM_BTN_SIZE, ITEM_BTN_SIZE, PNG.fire_anim, 8, 180))
else
local item = rcp.output
item = ItemStack(clean_name(item))
@ -1132,13 +1244,13 @@ local function get_output_fs(fs, data, rcp, is_recipe, shapeless, right, btn_siz
local count = item:get_count()
local bt_s = ITEM_BTN_SIZE * 1.2
fs(fmt("image", X, Y - 0.11, bt_s, bt_s, PNG.selected))
fs(fmt("image", X, Y - 0.11, bt_s, bt_s, PNG.slot))
local _name = sprintf("_%s", name)
fs(fmt("item_image_button", X + 0.1, Y, ITEM_BTN_SIZE, ITEM_BTN_SIZE,
sprintf("%s %u", name,
count * (is_recipe and data.scrbar_rcp or data.scrbar_usg or 1)),
fs(fmt("item_image_button",
X + 0.1, Y, ITEM_BTN_SIZE, ITEM_BTN_SIZE,
sprintf("%s %u", name, count * (is_recipe and data.scrbar_rcp or data.scrbar_usg or 1)),
_name, ""))
local def = reg_items[name]
@ -1240,7 +1352,7 @@ local function get_grid_fs(fs, data, rcp, is_recipe)
end
if not large_recipe then
fs(fmt("image", X, Y, btn_size, btn_size, PNG.selected))
fs(fmt("image", X, Y, btn_size, btn_size, PNG.slot))
end
local btn_name = groups and sprintf("group|%s|%s", groups[1], item) or item
@ -1294,11 +1406,11 @@ local function get_rcp_lbl(fs, data, panel, rn, is_recipe)
local btn_suffix = is_recipe and "recipe" or "usage"
local prev_name = sprintf("prev_%s", btn_suffix)
local next_name = sprintf("next_%s", btn_suffix)
local x_arrow = data.xoffset + 4.9
local y_arrow = data.yoffset + 3
local x_arrow = data.xoffset + 5.09
local y_arrow = data.yoffset + 3.2
fs(fmt("arrow", x_arrow - shift, y_arrow, PNG.prev, prev_name, ""),
fmt("arrow", x_arrow + 2.3, y_arrow, PNG.next, next_name, ""))
fs(fmt("image_button", x_arrow - shift, y_arrow, 0.3, 0.3, "", prev_name, ""),
fmt("image_button", x_arrow + 2.3, y_arrow, 0.3, 0.3, "", next_name, ""))
end
local rcp = is_recipe and panel.rcp[data.rnum] or panel.rcp[data.unum]
@ -1346,10 +1458,10 @@ local function get_model_fs(fs, data, def, model_alias)
fs(fmt("model",
data.xoffset + 6.6, data.yoffset + 0.05, 1.3, 1.3, "",
def.mesh, concat(t, ","), model_alias and model_alias.frames or ""))
def.mesh, concat(t, ","), "0,0", "true", model_alias and model_alias.frames or ""))
end
local function get_title_fs(fs, data)
local function get_header(fs, data)
local fav = is_fav(data.favs, data.query_item)
local nfavs = #data.favs
local star_x, star_y, star_size = data.xoffset + 0.4, data.yoffset + 0.5, 0.4
@ -1368,13 +1480,26 @@ local function get_title_fs(fs, data)
sprintf("tooltip[nofav;%s]", ES"Cannot mark this item. Bookmark limit reached."))
end
local desc_lim, name_lim = 32, 34
local desc = ESC(get_desc(data.query_item, data.lang_code))
local tech_name = data.query_item
local X = data.xoffset + 1.05
local Y1 = data.yoffset + 0.47
local Y2 = Y1 + 0.5
if #desc > desc_lim then
fs(fmt("tooltip", X, Y1 - 0.1, 5.7, 0.24, desc))
desc = snip(desc, desc_lim)
end
if #tech_name > name_lim then
fs(fmt("tooltip", X, Y2 - 0.1, 5.7, 0.24, tech_name))
tech_name = snip(tech_name, name_lim)
end
fs("style_type[label;font=bold;font_size=+6]",
fmt("label", data.xoffset + 1.05, data.yoffset + 0.47,
snip(ESC(get_desc(data.query_item, data.lang_code)), 32)),
"style_type[label;font=mono;font_size=+0]",
fmt("label", data.xoffset + 1.05, data.yoffset + 0.97,
clr("#7bf", snip(data.query_item, 34))),
"style_type[label;font=normal]")
fmt("label", X, Y1, desc), "style_type[label;font=mono;font_size=+0]",
fmt("label", X, Y2, clr("#7bf", tech_name)), "style_type[label;font=normal;font_size=+0]")
local def = reg_items[data.query_item]
local model_alias = craftguide.model_alias[data.query_item]
@ -1382,8 +1507,7 @@ local function get_title_fs(fs, data)
if def.drawtype == "mesh" or model_alias then
get_model_fs(fs, data, def, model_alias)
else
fs(fmt("item_image",
data.xoffset + 6.8, data.yoffset + 0.17, 1.1, 1.1, data.query_item))
fs(fmt("item_image", data.xoffset + 6.8, data.yoffset + 0.17, 1.1, 1.1, data.query_item))
end
end
@ -1391,22 +1515,14 @@ local function get_export_fs(fs, data, panel, is_recipe, is_usage, max_stacks_rc
local name = is_recipe and "rcp" or "usg"
local show_export = (is_recipe and data.export_rcp) or (is_usage and data.export_usg)
fs(sprintf("style[export_%s;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]",
name, sprintf("craftguide_export%s.png", show_export and "" or "_off"),
"craftguide_export.png", "craftguide_export.png"),
fs(sprintf("style[export_%s;fgimg=%s;fgimg_hovered=%s]",
name, sprintf("%s", show_export and PNG.export_hover or PNG.export), PNG.export_hover),
fmt("image_button",
data.xoffset + 7.35, data.yoffset + 0.2, 0.45, 0.45, "",
sprintf("export_%s", name), ""),
data.xoffset + 7.35, data.yoffset + 0.2, 0.45, 0.45, "", sprintf("export_%s", name), ""),
sprintf("tooltip[export_%s;%s]", name, ES"Quick crafting"))
if not show_export then return end
local item = (is_recipe and panel.rcp[data.rnum].output) or
(is_usage and panel.rcp[data.unum].output)
item = clean_name(item)
local _name = match(item, "%S*")
local stack = ItemStack(_name)
local stack_max = stack:get_stack_max()
local craft_max = is_recipe and max_stacks_rcp or max_stacks_usg
local stack_fs = (is_recipe and data.scrbar_rcp) or (is_usage and data.scrbar_usg) or 1
@ -1421,28 +1537,29 @@ local function get_export_fs(fs, data, panel, is_recipe, is_usage, max_stacks_rc
end
fs(sprintf("style[scrbar_%s;noclip=true]", name),
sprintf("scrollbaroptions[min=1;max=%u;smallstep=1]", min(craft_max, stack_max)),
sprintf("scrollbaroptions[min=1;max=%u;smallstep=1]", craft_max),
fmt("scrollbar",
data.xoffset + 8.1, data.yoffset, 3, 0.35, sprintf("scrbar_%s", name), stack_fs),
fmt("button", data.xoffset + 8.1, data.yoffset + 0.4, 3, 0.7, sprintf("craft_%s", name),
sprintf("%s", sprintf(stack_fs > 1 and ES"Craft %u stacks" or ES"Craft %u stack",
sprintf("%s", sprintf(stack_fs > 1 and ES"Craft %u items" or ES"Craft %u item",
stack_fs))))
end
local function get_rcp_extra(fs, data, panel, is_recipe, is_usage)
local function get_rcp_extra(player, fs, data, panel, is_recipe, is_usage)
local rn = panel.rcp and #panel.rcp
if rn then
local rcp_normal = is_recipe and panel.rcp[data.rnum].type == "normal"
local usg_normal = is_usage and panel.rcp[data.unum].type == "normal"
local max_stacks_rcp, max_stacks_usg = 0, 0
local inv = player:get_inventory()
if rcp_normal then
max_stacks_rcp = get_stack_max(data, is_recipe, panel.rcp[data.rnum])
max_stacks_rcp = get_stack_max(inv, data, is_recipe, panel.rcp[data.rnum])
end
if usg_normal then
max_stacks_usg = get_stack_max(data, is_recipe, panel.rcp[data.unum])
max_stacks_usg = get_stack_max(inv, data, is_recipe, panel.rcp[data.unum])
end
if is_recipe and max_stacks_rcp == 0 then
@ -1476,16 +1593,16 @@ local function get_favs(fs, data)
local Y = data.yoffset + 0.8
if data.query_item == item then
fs(fmt("image", X, Y, ITEM_BTN_SIZE, ITEM_BTN_SIZE, PNG.selected))
fs(fmt("image", X, Y, ITEM_BTN_SIZE, ITEM_BTN_SIZE, PNG.slot))
end
fs(fmt("item_image_button", X, Y, ITEM_BTN_SIZE, ITEM_BTN_SIZE, item, item, ""))
end
end
local function get_panels(fs, data)
local function get_panels(player, fs, data)
local _title = {name = "title", height = 1.4}
local _favs = {name = "favs", height = 2.2}
local _favs = {name = "favs", height = 2.23}
local _recipes = {name = "recipes", rcp = data.recipes, height = 3.9}
local _usages = {name = "usages", rcp = data.usages, height = 3.9}
local panels = {_title, _recipes, _usages, _favs}
@ -1505,53 +1622,37 @@ local function get_panels(fs, data)
local is_recipe, is_usage = panel.name == "recipes", panel.name == "usages"
if is_recipe or is_usage then
get_rcp_extra(fs, data, panel, is_recipe, is_usage)
get_rcp_extra(player, fs, data, panel, is_recipe, is_usage)
elseif panel.name == "title" then
get_title_fs(fs, data)
get_header(fs, data)
elseif panel.name == "favs" then
get_favs(fs, data)
end
end
end
local function make_fs(data)
local fs = setmetatable({}, {
__call = function(t, ...)
t[#t + 1] = concat({...})
end
})
local function get_item_list(fs, data, full_height)
fs(fmt("bg9", 0, 0, data.xoffset, full_height, PNG.bg_full, 10))
data.xoffset = ROWS + 1.04
local filtered = data.filter ~= ""
fs(sprintf([[
formspec_version[%u]
size[%f,%f]
no_prepend[]
bgcolor[#0000]
]],
MIN_FORMSPEC_VERSION, data.xoffset + (data.query_item and 8 or 0), LINES + 1.7), styles)
fs("box[0.2,0.2;4.55,0.6;#bababa25]", "set_focus[filter]")
fs(sprintf("field[0.3,0.2;%f,0.6;filter;;%s]", filtered and 3.45 or 3.9, ESC(data.filter)))
fs("field_close_on_enter[filter;false]")
fs(fmt("bg9", 0, 0, data.xoffset, LINES + 1.7, PNG.bg_full, 10))
fs(sprintf([[
box[0.2,0.2;4,0.6;#bababa25]
set_focus[filter]
field[0.3,0.2;3.4,0.6;filter;;%s]
field_close_on_enter[filter;false]
]], ESC(data.filter)),
fmt("image_button", 4.25, 0.14, 0.7, 0.7, "", "search", ""))
if data.filter ~= "" then
fs(fmt("image_button", 3.75, 0.35, 0.3, 0.3, PNG.cancel, "cancel", ""))
if filtered then
fs(fmt("image_button", 3.75, 0.35, 0.3, 0.3, "", "cancel", ""))
end
fs(fmt("image_button", data.xoffset - 3.2, 0.15, 0.7, 0.7, "", "prev_page", ""),
fmt("image_button", data.xoffset - 0.7, 0.15, 0.7, 0.7, "", "next_page", ""))
fs(fmt("image_button", 4.25, 0.32, 0.35, 0.35, "", "search", ""))
fs(fmt("image_button", data.xoffset - 2.73, 0.3, 0.35, 0.35, "", "prev_page", ""),
fmt("image_button", data.xoffset - 0.55, 0.3, 0.35, 0.35, "", "next_page", ""))
data.pagemax = max(1, ceil(#data.items / IPP))
fs(fmt("button",
data.xoffset - 2.53, 0.15, 1.88, 0.7, "pagenum",
data.xoffset - 2.4, 0.14, 1.88, 0.7, "pagenum",
sprintf("%s / %u", clr("#ff0", data.pagenum), data.pagemax)))
if #data.items == 0 then
@ -1571,28 +1672,46 @@ local function make_fs(data)
if not item then break end
local X = i % ROWS
X = X + (X * 0.08) + 0.2
X = X + (X * 0.1) + 0.2
local Y = (i % IPP - X) / ROWS + 1
Y = Y + (Y * 0.06)
local Y = floor((i % IPP - X) / ROWS + 1)
Y = Y + (Y * 0.06) + 1
if data.query_item == item then
fs(fmt("image", X, Y, 1, 1, PNG.selected))
fs(fmt("image", X, Y, 1, 1, PNG.slot))
end
fs(fmt("item_image_button", X, Y, 1, 1, item, sprintf("%s_inv", item), ""))
end
end
if (data.recipes and #data.recipes > 0) or (data.usages and #data.usages > 0) then
get_panels(fs, data)
local function make_fs(player, data)
local fs = setmetatable({}, {
__call = function(t, ...)
t[#t + 1] = concat({...})
end
})
data.xoffset = ROWS + 1.2
local full_height = LINES + 1.73
fs(sprintf("formspec_version[%u]size[%f,%f]no_prepend[]bgcolor[#0000]",
MIN_FORMSPEC_VERSION, data.xoffset + (data.query_item and 8 or 0), full_height), styles)
get_item_list(fs, data, full_height)
if data.query_item then
get_panels(player, fs, data)
end
return concat(fs)
end
local show_fs = function(player, name)
local function show_fs(player, name)
local data = pdata[name]
show_formspec(name, "craftguide", make_fs(data))
local fs = make_fs(player, data)
show_formspec(name, "craftguide", fs)
end
craftguide.register_craft_type("digging", {
@ -1785,9 +1904,7 @@ local function get_init_items()
for name in pairs(_preselect) do
cache_usages(name)
end
for name in pairs(_preselect) do
if recipes_cache[name] or usages_cache[name] then
init_items[#init_items + 1] = name
_select[name] = true
@ -1810,7 +1927,7 @@ local function get_init_items()
end
end
local function init_data(name)
local function init_data(player, name)
local info = get_player_info(name)
pdata[name] = {
@ -1822,7 +1939,6 @@ local function init_data(name)
export_counts = {},
lang_code = get_lang_code(info),
fs_version = get_formspec_version(info),
player = get_player_by_name(name),
}
end
@ -1836,7 +1952,6 @@ local function reset_data(data)
data.query_item = nil
data.recipes = nil
data.usages = nil
data.show_usages = nil
data.export_rcp = nil
data.export_usg = nil
data.items = data.items_raw
@ -1846,7 +1961,7 @@ on_mods_loaded(get_init_items)
on_joinplayer(function(player)
local name = player:get_player_name()
init_data(name)
init_data(player, name)
local data = pdata[name]
if data.fs_version < MIN_FORMSPEC_VERSION then
@ -1854,13 +1969,26 @@ on_joinplayer(function(player)
end
end)
local function fields(player, _f)
if _f.quit then return end
on_receive_fields(function(player, formname, _f)
if formname ~= "craftguide" then
return false
end
local name = player:get_player_name()
local data = pdata[name]
local sb_rcp, sb_usg = _f.scrbar_rcp, _f.scrbar_usg
if _f.cancel then
if _f.quit then
player:hud_change(data.vignette, "text", "")
data.vignette = nil
data.hud_flags.crosshair = true
player:hud_set_flags(data.hud_flags)
data.hud_flags = nil
return false
elseif _f.cancel then
reset_data(data)
elseif _f.prev_recipe or _f.next_recipe then
@ -1924,6 +2052,22 @@ local function fields(player, _f)
end
end
elseif _f.trash then
local inv = player:get_inventory()
if not inv:is_empty("main") then
inv:set_list("main", {})
end
elseif _f.compress then
compress_items(player)
elseif _f.sort_az or _f.sort_za then
sort_itemlist(player, _f.sort_az)
elseif _f.scrbar_inv then
data.scrbar_inv = tonumber(match(_f.scrbar_inv, "%d+"))
return true
elseif (sb_rcp and sub(sb_rcp, 1, 3) == "CHG") or (sb_usg and sub(sb_usg, 1, 3) == "CHG") then
data.scrbar_rcp = sb_rcp and tonum(match(sb_rcp, "%d+"))
data.scrbar_usg = sb_usg and tonum(match(sb_usg, "%d+"))
@ -1931,21 +2075,16 @@ local function fields(player, _f)
elseif _f.craft_rcp or _f.craft_usg then
craft_stack(player, name, data, _f.craft_rcp)
else
select_item(player, data, _f)
select_item(player, name, data, _f)
end
return true, show_fs(player, name)
end
on_receive_fields(function(player, formname, _f)
if formname == "craftguide" then
fields(player, _f)
end
end)
local function on_use(user)
local name = user:get_player_name()
local data = pdata[name]
if not data then return end
if data.fs_version < MIN_FORMSPEC_VERSION then
return outdated(name)
@ -1956,7 +2095,19 @@ local function on_use(user)
search(data)
end
show_formspec(name, "craftguide", make_fs(data))
show_fs(user, name)
data.vignette = user:hud_add({
hud_elem_type = "image",
position = {x = 0.5, y = 0.5},
scale = {x = -100, y = -100},
text = "craftguide_vignette.png",
z_index = -0xB00B,
})
data.hud_flags = user:hud_get_flags()
data.hud_flags.crosshair = false
user:hud_set_flags(data.hud_flags)
end
core.register_craftitem("craftguide:book", {
@ -2270,7 +2421,7 @@ on_leaveplayer(function(player)
pdata[name] = nil
end)
function craftguide.show(name, item, show_usages)
function craftguide.show(name, item)
if not true_str(name) then
return err "craftguide.show(): player name missing"
end
@ -2287,7 +2438,7 @@ function craftguide.show(name, item, show_usages)
if not recipes and not usages then
if not recipes_cache[item] and not usages_cache[item] then
return false, msg(name, sprintf("%s: %s",
S"No recipe or usage for this item", get_desc(item)))
S"No recipe or usage for this node", clr("#ff0", get_desc(item))))
end
return false, msg(name, sprintf("%s: %s",
@ -2316,10 +2467,14 @@ register_command("craft", {
local node = core.get_node(look_at)
if node.name ~= "air" then
local def = reg_items[node.name]
if def then
node_name = node.name
break
end
end
end
if not node_name then
return false, msg(name, S"No node pointed")

View File

@ -3,7 +3,7 @@ License of source code
The MIT License (MIT)
Copyright (c) 2015-2020 Jean-Patrick Guerrero and contributors.
Copyright (c) 2015-present Jean-Patrick Guerrero and contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -27,10 +27,8 @@ THE SOFTWARE.
Licenses of media (textures)
----------------------------
Copyright © Diego Martínez (kaeza): craftguide_*_icon.png (CC BY-SA 3.0)
paramat (CC BY-SA 3.0):
sfinv_crafting_arrow.png - derived from a texture by BlockMen (CC BY-SA 3.0)
craftguide_arrow.png - derived from a texture by BlockMen (CC BY-SA 3.0)
You are free to:
Share — copy and redistribute the material in any medium or format.

View File

@ -53,7 +53,7 @@ Collect items to reveal more recipes=Collecte des items pour révéler plus de r
Show recipe(s) of the pointed node=Affiche les recettes du bloc visé
No node pointed=Aucun bloc visé
You don't know a recipe or usage for this item=Vous ne connaissez aucune recette pour ce bloc
No recipe or usage for this item=Aucune recette pour ce bloc
No recipe or usage for this node=Aucune recette pour ce bloc
Digging=Destruction
Digging (by chance)=Destruction (par chance)
@1 of chance to drop=@1 de chance de tomber

View File

@ -53,7 +53,7 @@ Collect items to reveal more recipes=
Show recipe(s) of the pointed node=
No node pointed=
You don't know a recipe or usage for this item=
No recipe or usage for this item=
No recipe or usage for this node=
Digging=
Digging (by chance)=
@1 of chance to drop=

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 567 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB