mirror of
https://github.com/minetest-mods/craftguide.git
synced 2025-06-30 15:10:38 +02:00
Compare commits
17 Commits
1.13
...
0b7bfca0ec
Author | SHA1 | Date | |
---|---|---|---|
0b7bfca0ec | |||
60d89f51e7 | |||
1c990f6476 | |||
6f2c79e7e1 | |||
762c166485 | |||
0806894dc2 | |||
7e0819aa18 | |||
4a5f18124a | |||
c7a56824c2 | |||
35c3bc170d | |||
4ff1fd15b8 | |||
35021a6f0b | |||
7ef62f4f8b | |||
f075e67be9 | |||
cd17b8d38e | |||
46cb7615bf | |||
679e005f58 |
@ -19,4 +19,4 @@ For developers, `craftguide` also has a [modding API](https://github.com/minetes
|
||||
Love this mod? Donations are appreciated: https://www.paypal.me/jpg84240
|
||||
|
||||
|
||||

|
||||

|
||||
|
509
init.lua
509
init.lua
@ -7,7 +7,6 @@ local searches = {}
|
||||
local recipes_cache = {}
|
||||
local usages_cache = {}
|
||||
local fuel_cache = {}
|
||||
|
||||
local toolrepair
|
||||
|
||||
local progressive_mode = core.settings:get_bool "craftguide_progressive_mode"
|
||||
@ -16,6 +15,7 @@ local autocache = core.settings:get_bool "craftguide_autocache"
|
||||
|
||||
local http = core.request_http_api()
|
||||
local storage = core.get_mod_storage()
|
||||
local singleplayer = core.is_singleplayer()
|
||||
|
||||
local reg_items = core.registered_items
|
||||
local reg_tools = core.registered_tools
|
||||
@ -64,9 +64,11 @@ local vec_add, vec_mul = vector.add, vector.multiply
|
||||
local FORMSPEC_MINIMAL_VERSION = 3
|
||||
|
||||
local ROWS = 9
|
||||
local LINES = sfinv_only and 5 or 9
|
||||
local LINES = sfinv_only and 5 or 10
|
||||
local IPP = ROWS * LINES
|
||||
local WH_LIMIT = 8
|
||||
local WH_LIMIT = 5
|
||||
local MAX_FAVS = 6
|
||||
local ITEM_BTN_SIZE = 1.1
|
||||
|
||||
local XOFFSET = sfinv_only and 3.83 or 11.2
|
||||
local YOFFSET = sfinv_only and 4.9 or 1
|
||||
@ -111,6 +113,20 @@ local function get_fs_version(name)
|
||||
return info and info.formspec_version or 1
|
||||
end
|
||||
|
||||
local function outdated(name)
|
||||
local fs = fmt([[
|
||||
size[6.6,1.3]
|
||||
image[0,0;1,1;%s]
|
||||
label[1,0;%s]
|
||||
button_exit[2.8,0.8;1,1;;OK]
|
||||
]],
|
||||
PNG.book,
|
||||
"Your Minetest client is outdated.\n" ..
|
||||
"Get the latest version on minetest.net to use the Crafting Guide.")
|
||||
|
||||
return show_formspec(name, "craftguide", fs)
|
||||
end
|
||||
|
||||
local function mul_elem(elem, n)
|
||||
local fstr, elems = "", {}
|
||||
|
||||
@ -697,6 +713,10 @@ local function is_fav(data)
|
||||
return fav, i
|
||||
end
|
||||
|
||||
local function check_newline(def)
|
||||
return def and def.description and find(def.description, "\n")
|
||||
end
|
||||
|
||||
local function get_desc(name)
|
||||
if sub(name, 1, 1) == "_" then
|
||||
name = sub(name, 2)
|
||||
@ -760,26 +780,44 @@ local function get_tooltip(name, info)
|
||||
end
|
||||
|
||||
if info.rarity then
|
||||
local chance = (1 / info.rarity) * 100
|
||||
local chance = (1 / max(1, info.rarity)) * 100
|
||||
tooltip = add(S("@1 of chance to drop", clr("#ff0", chance .. "%")))
|
||||
end
|
||||
|
||||
if info.tools then
|
||||
local several = #info.tools > 1
|
||||
local names = several and "\n" or ""
|
||||
|
||||
if several then
|
||||
for i = 1, #info.tools do
|
||||
names = fmt("%s\t\t- %s\n",
|
||||
names, clr("#ff0", get_desc(info.tools[i])))
|
||||
end
|
||||
|
||||
tooltip = add(S("Only drop if using one of these tools: @1",
|
||||
sub(names, 1, -2)))
|
||||
else
|
||||
tooltip = add(S("Only drop if using this tool: @1",
|
||||
clr("#ff0", get_desc(info.tools[1]))))
|
||||
end
|
||||
end
|
||||
|
||||
return fmt("tooltip[%s;%s]", name, ESC(tooltip))
|
||||
end
|
||||
|
||||
local function get_output_fs(data, fs, L)
|
||||
local custom_recipe = craft_types[L.recipe.type]
|
||||
local function get_output_fs(data, fs, rcp, shapeless, right, btn_size, _btn_size, spacing)
|
||||
local custom_recipe = craft_types[rcp.type]
|
||||
|
||||
if custom_recipe or L.shapeless or L.recipe.type == "cooking" then
|
||||
if custom_recipe or shapeless or rcp.type == "cooking" then
|
||||
local icon = custom_recipe and custom_recipe.icon or
|
||||
L.shapeless and "shapeless" or "furnace"
|
||||
shapeless and "shapeless" or "furnace"
|
||||
|
||||
if not custom_recipe then
|
||||
icon = fmt("craftguide_%s.png^[resize:16x16", icon)
|
||||
end
|
||||
|
||||
local pos_x = L.rightest + L.btn_size + 0.1
|
||||
local pos_y = YOFFSET + (sfinv_only and 0.25 or -0.45) + L.spacing
|
||||
local pos_x = right + btn_size + 0.1
|
||||
local pos_y = YOFFSET + (sfinv_only and 1.55 or -0.45) + spacing
|
||||
|
||||
if sub(icon, 1, 18) == "craftguide_furnace" then
|
||||
fs[#fs + 1] = fmt(FMT.animated_image,
|
||||
@ -789,36 +827,43 @@ local function get_output_fs(data, fs, L)
|
||||
end
|
||||
|
||||
local tooltip = custom_recipe and custom_recipe.description or
|
||||
L.shapeless and S"Shapeless" or S"Cooking"
|
||||
shapeless and S"Shapeless" or S"Cooking"
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.tooltip, pos_x, pos_y, 0.5, 0.5, ESC(tooltip))
|
||||
end
|
||||
|
||||
local arrow_X = L.rightest + (L._btn_size or 1.1)
|
||||
local arrow_X = right + (_btn_size or ITEM_BTN_SIZE)
|
||||
local output_X = arrow_X + 0.9
|
||||
local Y = YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing
|
||||
local Y = YOFFSET + (sfinv_only and 2 or 0) + spacing
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.image, arrow_X, Y + 0.2, 0.9, 0.7, PNG.arrow)
|
||||
|
||||
if L.recipe.type == "fuel" then
|
||||
fs[#fs + 1] = fmt(FMT.animated_image, output_X, Y, 1.1, 1.1, PNG.fire_anim, 8, 180)
|
||||
if rcp.type == "fuel" then
|
||||
fs[#fs + 1] = fmt(FMT.animated_image, output_X, Y,
|
||||
ITEM_BTN_SIZE, ITEM_BTN_SIZE, PNG.fire_anim, 8, 180)
|
||||
else
|
||||
local item = L.recipe.output
|
||||
local item = rcp.output
|
||||
item = clean_name(item)
|
||||
local name = match(item, "%S*")
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.image, output_X, Y, 1.1, 1.1, PNG.selected)
|
||||
fs[#fs + 1] = fmt(FMT.image, output_X, Y,
|
||||
ITEM_BTN_SIZE, ITEM_BTN_SIZE, PNG.selected)
|
||||
|
||||
local _name = sfinv_only and name or fmt("_%s", name)
|
||||
|
||||
fs[#fs + 1] = fmt("item_image_button[%f,%f;%f,%f;%s;%s;%s]",
|
||||
output_X, Y, 1.1, 1.1, item, _name, "")
|
||||
output_X, Y, ITEM_BTN_SIZE, ITEM_BTN_SIZE, item, _name, "")
|
||||
|
||||
|
||||
local def = reg_items[name]
|
||||
|
||||
local infos = {
|
||||
unknown = not reg_items[name] or nil,
|
||||
unknown = not def or nil,
|
||||
burntime = fuel_cache[name],
|
||||
repair = repairable(name),
|
||||
rarity = L.rarity,
|
||||
rarity = rcp.rarity,
|
||||
tools = rcp.tools,
|
||||
newline = check_newline(def),
|
||||
}
|
||||
|
||||
if next(infos) then
|
||||
@ -827,11 +872,11 @@ local function get_output_fs(data, fs, L)
|
||||
|
||||
if infos.burntime then
|
||||
fs[#fs + 1] = fmt(FMT.image,
|
||||
output_X + 1, YOFFSET + (sfinv_only and 0.7 or 0.1) + L.spacing,
|
||||
output_X + 1, YOFFSET + (sfinv_only and 2 or 0.1) + spacing,
|
||||
0.6, 0.4, PNG.arrow)
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.animated_image,
|
||||
output_X + 1.6, YOFFSET + (sfinv_only and 0.55 or 0) + L.spacing,
|
||||
output_X + 1.6, YOFFSET + (sfinv_only and 1.85 or 0) + spacing,
|
||||
0.6, 0.6, PNG.fire_anim, 8, 180)
|
||||
end
|
||||
end
|
||||
@ -839,9 +884,7 @@ end
|
||||
|
||||
local function get_grid_fs(data, fs, rcp, spacing)
|
||||
local width = rcp.width or 1
|
||||
local replacements = rcp.replacements
|
||||
local rarity = rcp.rarity
|
||||
local rightest, btn_size, _btn_size = 0, 1.1
|
||||
local right, btn_size, _btn_size = 0, ITEM_BTN_SIZE
|
||||
local cooktime, shapeless
|
||||
|
||||
if rcp.type == "cooking" then
|
||||
@ -878,22 +921,15 @@ local function get_grid_fs(data, fs, rcp, spacing)
|
||||
local Y = ceil(i / width) + YOFFSET - min(2, rows) + spacing
|
||||
|
||||
if large_recipe then
|
||||
local xof = 1 - 4 / width
|
||||
local yof = 1 - 4 / rows
|
||||
local x_y = width > rows and xof or yof
|
||||
|
||||
btn_size = width > rows and
|
||||
(3.5 + (xof * 2)) / width or (3.5 + (yof * 2)) / rows
|
||||
btn_size = width > 3 and 3 / width or 3 / rows
|
||||
_btn_size = btn_size
|
||||
|
||||
X = (btn_size * ((i - 1) % width) + XOFFSET -
|
||||
(sfinv_only and 2.83 or 0.5)) * (0.83 - (x_y / 5))
|
||||
Y = (btn_size * floor((i - 1) / width) +
|
||||
(sfinv_only and 5.81 or 5.5) + x_y) * (0.86 - (x_y / 5))
|
||||
X = btn_size * ((i - 1) % width) + XOFFSET - 2.65
|
||||
Y = btn_size * floor((i - 1) / width) + spacing + (sfinv and 4 or 0)
|
||||
end
|
||||
|
||||
if X > rightest then
|
||||
rightest = X
|
||||
if X > right then
|
||||
right = X
|
||||
end
|
||||
|
||||
local groups
|
||||
@ -906,9 +942,9 @@ local function get_grid_fs(data, fs, rcp, spacing)
|
||||
local label = groups and "\nG" or ""
|
||||
local replace
|
||||
|
||||
if replacements then
|
||||
for j = 1, #replacements do
|
||||
local replacement = replacements[j]
|
||||
if rcp.replacements then
|
||||
for j = 1, #rcp.replacements do
|
||||
local replacement = rcp.replacements[j]
|
||||
if replacement[1] == name then
|
||||
label = (label ~= "" and "\n" or "") .. label .. "\nR"
|
||||
replace = replacement[2]
|
||||
@ -916,7 +952,7 @@ local function get_grid_fs(data, fs, rcp, spacing)
|
||||
end
|
||||
end
|
||||
|
||||
Y = Y + (sfinv_only and 0.7 or 0)
|
||||
Y = Y + (sfinv_only and 2 or 0)
|
||||
|
||||
if not large_recipe then
|
||||
fs[#fs + 1] = fmt(FMT.image, X, Y, btn_size, btn_size, PNG.selected)
|
||||
@ -925,12 +961,15 @@ local function get_grid_fs(data, fs, rcp, spacing)
|
||||
fs[#fs + 1] = fmt(FMT.item_image_button,
|
||||
X, Y, btn_size, btn_size, item, item, label)
|
||||
|
||||
local def = reg_items[name]
|
||||
|
||||
local infos = {
|
||||
unknown = not reg_items[name] or nil,
|
||||
unknown = not def or nil,
|
||||
groups = groups,
|
||||
burntime = fuel_cache[name],
|
||||
cooktime = cooktime,
|
||||
replace = replace,
|
||||
newline = check_newline(def),
|
||||
}
|
||||
|
||||
if next(infos) then
|
||||
@ -942,79 +981,13 @@ local function get_grid_fs(data, fs, rcp, spacing)
|
||||
fs[#fs + 1] = "style_type[item_image_button;border=false]"
|
||||
end
|
||||
|
||||
get_output_fs(data, fs, {
|
||||
recipe = rcp,
|
||||
shapeless = shapeless,
|
||||
rightest = rightest,
|
||||
btn_size = btn_size,
|
||||
_btn_size = _btn_size,
|
||||
spacing = spacing,
|
||||
rarity = rarity,
|
||||
})
|
||||
get_output_fs(data, fs, rcp, shapeless, right, btn_size, _btn_size, spacing)
|
||||
end
|
||||
|
||||
local function get_panels(data, fs)
|
||||
local start_y = sfinv_only and 0.33 or 0
|
||||
local function get_rcp_lbl(data, fs, panel, spacing, rn, is_recipe)
|
||||
local lbl
|
||||
|
||||
local panels = {
|
||||
{dat = data.usages or {}, height = 3.5},
|
||||
{dat = data.recipes or {}, height = 3.5},
|
||||
}
|
||||
|
||||
if not sfinv_only then
|
||||
panels.favs = {height = 2.19}
|
||||
else
|
||||
panels = data.show_usages and {{dat = data.usages}} or {{dat = data.recipes}}
|
||||
end
|
||||
|
||||
for k, v in pairs(panels) do
|
||||
start_y = start_y + 1
|
||||
local spacing = (start_y - 1) * 3.6
|
||||
|
||||
if not sfinv_only then
|
||||
fs[#fs + 1] = fmt("background9[8.1,%f;6.6,%f;%s;false;%d]",
|
||||
-0.2 + spacing, v.height, PNG.bg_full, 10)
|
||||
|
||||
if k == 2 then
|
||||
local fav = is_fav(data)
|
||||
local nfavs = #data.favs
|
||||
|
||||
fs[#fs + 1] = fmt(
|
||||
"style[fav;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]",
|
||||
fmt("craftguide_fav%s.png", fav and "" or "_off"),
|
||||
fmt("craftguide_fav%s.png", fav and "_off" or ""),
|
||||
fmt("craftguide_fav%s.png", fav and "_off" or ""))
|
||||
|
||||
if nfavs < 6 or (nfavs >= 6 and fav) then
|
||||
fs[#fs + 1] = fmt(FMT.image_button,
|
||||
14, spacing, 0.5, 0.45, "", "fav", "")
|
||||
end
|
||||
|
||||
fs[#fs + 1] = fmt("tooltip[fav;%s]",
|
||||
fav and ES"Unmark this item" or ES"Mark this item")
|
||||
end
|
||||
end
|
||||
|
||||
local rn = v.dat and #v.dat or -1
|
||||
local _rn = tostring(rn)
|
||||
local xu = tostring(data.unum) .. _rn
|
||||
local xr = tostring(data.rnum) .. _rn
|
||||
xu = max(-0.3, -((#xu - 3) * 0.05))
|
||||
xr = max(-0.3, -((#xr - 3) * 0.05))
|
||||
|
||||
local is_recipe = sfinv_only and not data.show_usages or k == 2
|
||||
local lbl = ""
|
||||
|
||||
if not sfinv_only and rn == 0 then
|
||||
local X = XOFFSET - 0.7
|
||||
local Y = YOFFSET - 0.4 + spacing
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.image, X, Y, 2, 2, PNG.nothing)
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.tooltip,
|
||||
X, Y, 2, 2, is_recipe and ES"No recipes" or ES"No usages")
|
||||
|
||||
elseif (not sfinv_only and is_recipe) or
|
||||
if (not sfinv_only and is_recipe) or
|
||||
(sfinv_only and not data.show_usages) then
|
||||
lbl = ES("Recipe @1 of @2", data.rnum, rn)
|
||||
|
||||
@ -1027,6 +1000,12 @@ local function get_panels(data, fs)
|
||||
ES("Recipe @1 of @2", data.rnum, rn)
|
||||
end
|
||||
|
||||
local _rn = tostring(rn)
|
||||
local xu = tostring(data.unum) .. _rn
|
||||
local xr = tostring(data.rnum) .. _rn
|
||||
xu = max(-0.3, -((#xu - 3) * 0.05))
|
||||
xr = max(-0.3, -((#xr - 3) * 0.05))
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.label,
|
||||
XOFFSET + (sfinv_only and 2.3 or 1.6) + (is_recipe and xr or xu),
|
||||
YOFFSET + (sfinv_only and 3.4 or 1.5 + spacing), lbl)
|
||||
@ -1038,31 +1017,122 @@ local function get_panels(data, fs)
|
||||
local x_arrow = XOFFSET + (sfinv_only and 1.7 or 1)
|
||||
local y_arrow = YOFFSET + (sfinv_only and 3.3 or 1.4 + spacing)
|
||||
|
||||
fs[#fs + 1] = fmt([[
|
||||
style[%s;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
|
||||
style[%s;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
|
||||
]],
|
||||
prev_name, PNG.prev, PNG.prev_hover, PNG.prev_hover,
|
||||
next_name, PNG.next, PNG.next_hover, PNG.next_hover)
|
||||
|
||||
fs[#fs + 1] = fmt(mul_elem(FMT.arrow, 2),
|
||||
x_arrow + (is_recipe and xr or xu), y_arrow,
|
||||
PNG.prev, prev_name, "",
|
||||
x_arrow + 1.8, y_arrow, PNG.next, next_name, "")
|
||||
end
|
||||
|
||||
local rcp = v.dat and (is_recipe and v.dat[data.rnum] or v.dat[data.unum])
|
||||
if rcp then
|
||||
local rcp = is_recipe and panel.rcp[data.rnum] or panel.rcp[data.unum]
|
||||
get_grid_fs(data, fs, rcp, spacing)
|
||||
end
|
||||
|
||||
if k == "favs" and not sfinv_only then
|
||||
fs[#fs + 1] = fmt(FMT.label, 8.3, spacing - 0.1, ES"Bookmarks")
|
||||
local function get_title_fs(data, fs, spacing)
|
||||
local desc = ESC(get_desc(data.query_item))
|
||||
desc = #desc > 33 and fmt("%s...", sub(desc, 1, 30)) or desc
|
||||
local t_desc = data.query_item
|
||||
t_desc = #t_desc > 40 and fmt("%s...", sub(t_desc, 1, 37)) or t_desc
|
||||
|
||||
fs[#fs + 1] = fmt("hypertext[9.05,%f;5.85,1.2;item_title;%s]",
|
||||
spacing - 0.1,
|
||||
fmt("<item name=%s float=right width=64 height=64 rotate=yes>" ..
|
||||
"<big><b>%s</b></big>\n<style color=#7bf font=mono>%s</style>",
|
||||
data.query_item, desc, t_desc))
|
||||
|
||||
local fav = is_fav(data)
|
||||
local nfavs = #data.favs
|
||||
|
||||
if nfavs < MAX_FAVS or (nfavs == MAX_FAVS and fav) then
|
||||
local fav_marked = fmt("craftguide_fav%s.png", fav and "_off" or "")
|
||||
|
||||
fs[#fs + 1] = fmt(
|
||||
"style[fav;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]",
|
||||
fmt("craftguide_fav%s.png", fav and "" or "_off"), fav_marked, fav_marked)
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.image_button, 8.25, spacing + 0.15, 0.5, 0.45, "", "fav", "")
|
||||
|
||||
fs[#fs + 1] = fmt("tooltip[fav;%s]",
|
||||
fav and ES"Unmark this item" or ES"Mark this item")
|
||||
else
|
||||
fs[#fs + 1] = fmt(
|
||||
"style[fav_no;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]",
|
||||
"craftguide_fav_off.png", PNG.nothing, PNG.nothing)
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.image_button,
|
||||
8.25, spacing + 0.15, 0.5, 0.45, "", "fav_no", "")
|
||||
|
||||
fs[#fs + 1] = fmt("tooltip[fav_no;%s]",
|
||||
ES"Cannot mark this item. Limit of bookmarks reached.")
|
||||
end
|
||||
end
|
||||
|
||||
local function get_panels(data, fs)
|
||||
local title = {name = "title", height = 1.2}
|
||||
local favs = {name = "favs", height = 1.91}
|
||||
local recipes = {name = "recipes", rcp = data.recipes, height = 3.5}
|
||||
local usages = {name = "usages", rcp = data.usages, height = 3.5}
|
||||
local panels = {title, recipes, usages, favs}
|
||||
|
||||
if sfinv_only then
|
||||
panels = {data.show_usages and usages or recipes}
|
||||
end
|
||||
|
||||
for idx = 1, #panels do
|
||||
local panel, spacing = panels[idx], 0
|
||||
|
||||
if idx > 1 then
|
||||
for _idx = idx - 1, 1, -1 do
|
||||
spacing = spacing + panels[_idx].height + 0.1
|
||||
end
|
||||
end
|
||||
|
||||
local rn = panel.rcp and #panel.rcp
|
||||
local is_recipe = sfinv_only and not data.show_usages or panel.name == "recipes"
|
||||
local recipe_or_usage = panel.name == "recipes" or panel.name == "usages"
|
||||
|
||||
if rn then
|
||||
get_rcp_lbl(data, fs, panel, spacing, rn, is_recipe)
|
||||
end
|
||||
|
||||
if sfinv_only then return end
|
||||
|
||||
fs[#fs + 1] = fmt("background9[8.1,%f;6.6,%f;%s;false;%d]",
|
||||
-0.2 + spacing, panel.height, PNG.bg_full, 10)
|
||||
|
||||
if recipe_or_usage and not rn then
|
||||
local X = XOFFSET - 0.7
|
||||
local Y = YOFFSET - 0.4 + spacing
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.image, X, Y, 2, 2, PNG.nothing)
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.tooltip,
|
||||
X, Y, 2, 2, is_recipe and ES"No recipes" or ES"No usages")
|
||||
|
||||
elseif panel.name == "title" then
|
||||
get_title_fs(data, fs, spacing)
|
||||
|
||||
elseif panel.name == "favs" then
|
||||
fs[#fs + 1] = fmt(FMT.label, 8.3, spacing - 0.15, ES"Bookmarks")
|
||||
|
||||
for i = 1, #data.favs do
|
||||
local item = data.favs[i]
|
||||
local X = 7.85 + (i - 0.5)
|
||||
local Y = spacing + 0.45
|
||||
local Y = spacing + 0.4
|
||||
|
||||
if data.query_item == item then
|
||||
fs[#fs + 1] = fmt(FMT.image, X, Y, 1.1, 1.1, PNG.selected)
|
||||
fs[#fs + 1] = fmt(FMT.image, X, Y,
|
||||
ITEM_BTN_SIZE, ITEM_BTN_SIZE, PNG.selected)
|
||||
end
|
||||
|
||||
fs[#fs + 1] = fmt(FMT.item_image_button,
|
||||
X, Y, 1.1, 1.1, item, item, "")
|
||||
X, Y, ITEM_BTN_SIZE, ITEM_BTN_SIZE, item, item, "")
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1085,9 +1155,9 @@ local function make_fs(data)
|
||||
|
||||
fs[#fs + 1] = fmt([[
|
||||
style[filter;border=false]
|
||||
field[0.4,0.2;2.5,1;filter;;%s]
|
||||
field[0.4,0.2;2.6,1;filter;;%s]
|
||||
field_close_on_enter[filter;false]
|
||||
box[0,0;2.4,0.6;#bababa25]
|
||||
box[0,0;2.5,0.6;#bababa25]
|
||||
]],
|
||||
ESC(data.filter))
|
||||
|
||||
@ -1098,6 +1168,7 @@ local function make_fs(data)
|
||||
style[clear;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[pagenum;border=false]
|
||||
]],
|
||||
PNG.selected, PNG.selected,
|
||||
PNG.search, PNG.search_hover,
|
||||
@ -1105,17 +1176,27 @@ local function make_fs(data)
|
||||
PNG.prev, PNG.prev_hover, PNG.prev_hover,
|
||||
PNG.next, PNG.next_hover, PNG.next_hover)
|
||||
|
||||
fs[#fs + 1] = fmt(mul_elem(FMT.image_button, 4),
|
||||
sfinv_only and 2.6 or 2.54, -0.06, 0.85, 0.85, "", "search", "",
|
||||
sfinv_only and 3.3 or 3.25, -0.06, 0.85, 0.85, "", "clear", "",
|
||||
sfinv_only and 5.45 or (9 * 6.83) / 11, -0.06, 0.85, 0.85, "", "prev_page", "",
|
||||
sfinv_only and 7.2 or (9 * 8.75) / 11, -0.06, 0.85, 0.85, "", "next_page", "")
|
||||
fs[#fs + 1] = fmt(mul_elem(FMT.image_button, 2),
|
||||
2.6, -0.06, 0.85, 0.85, "", "search", "",
|
||||
3.3, -0.06, 0.85, 0.85, "", "clear", "")
|
||||
|
||||
if sfinv_only then
|
||||
fs[#fs + 1] = "container[0.2,0]"
|
||||
end
|
||||
|
||||
fs[#fs + 1] = fmt(mul_elem(FMT.image_button, 2),
|
||||
5.35, -0.06, 0.85, 0.85, "", "prev_page", "",
|
||||
7.1, -0.06, 0.85, 0.85, "", "next_page", "")
|
||||
|
||||
data.pagemax = max(1, ceil(#data.items / IPP))
|
||||
|
||||
fs[#fs + 1] = fmt("label[%f,%f;%s / %u]",
|
||||
sfinv_only and 6.35 or (9 * 7.85) / 11,
|
||||
0.06, clr("#ff0", data.pagenum), data.pagemax)
|
||||
fs[#fs + 1] = fmt(FMT.button,
|
||||
5.97, -0.06, 1.36, 0.85, "pagenum",
|
||||
fmt("%s / %u", clr("#ff0", data.pagenum), data.pagemax))
|
||||
|
||||
if sfinv_only then
|
||||
fs[#fs + 1] = "container_end[]"
|
||||
end
|
||||
|
||||
if #data.items == 0 then
|
||||
local no_item = ES"No item to show"
|
||||
@ -1166,12 +1247,12 @@ end
|
||||
|
||||
craftguide.register_craft_type("digging", {
|
||||
description = ES"Digging",
|
||||
icon = "default_tool_steelpick.png",
|
||||
icon = "craftguide_steelpick.png",
|
||||
})
|
||||
|
||||
craftguide.register_craft_type("digging_chance", {
|
||||
description = ES"Digging Chance",
|
||||
icon = "default_tool_mesepick.png",
|
||||
description = ES"Digging (by chance)",
|
||||
icon = "craftguide_mesepick.png",
|
||||
})
|
||||
|
||||
local function search(data)
|
||||
@ -1357,12 +1438,16 @@ local function handle_drops_table(name, drop)
|
||||
if not dstack:is_empty() and dname ~= name then
|
||||
local dcount = dstack:get_count()
|
||||
|
||||
if #di.items == 1 and di.rarity == 1 and max_start then
|
||||
if #di.items == 1 and max_start and
|
||||
(not di.rarity or di.rarity <= 1) then
|
||||
if not drop_sure[dname] then
|
||||
drop_sure[dname] = 0
|
||||
drop_sure[dname] = {}
|
||||
end
|
||||
|
||||
drop_sure[dname] = drop_sure[dname] + dcount
|
||||
drop_sure[dname] = {
|
||||
output = (drop_sure[dname].output or 0) + dcount,
|
||||
tools = di.tools,
|
||||
}
|
||||
|
||||
if max_items_left then
|
||||
max_items_left = max_items_left - 1
|
||||
@ -1377,24 +1462,22 @@ local function handle_drops_table(name, drop)
|
||||
drop_maybe[dname] = {}
|
||||
end
|
||||
|
||||
if not drop_maybe[dname].output then
|
||||
drop_maybe[dname].output = 0
|
||||
end
|
||||
|
||||
drop_maybe[dname] = {
|
||||
output = drop_maybe[dname].output + dcount,
|
||||
output = (drop_maybe[dname].output or 0) + dcount,
|
||||
rarity = di.rarity,
|
||||
tools = di.tools,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for item, count in pairs(drop_sure) do
|
||||
for item, data in pairs(drop_sure) do
|
||||
craftguide.register_craft{
|
||||
type = "digging",
|
||||
items = {name},
|
||||
output = fmt("%s %u", item, count),
|
||||
output = fmt("%s %u", item, data.output),
|
||||
tools = data.tools,
|
||||
}
|
||||
end
|
||||
|
||||
@ -1404,19 +1487,21 @@ local function handle_drops_table(name, drop)
|
||||
items = {name},
|
||||
output = fmt("%s %u", item, data.output),
|
||||
rarity = data.rarity,
|
||||
tools = data.tools,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
local function register_drops(name, drop)
|
||||
if true_str(drop) then
|
||||
local dstack = ItemStack(drop)
|
||||
|
||||
if not dstack:is_empty() and dstack:get_name() ~= name then
|
||||
craftguide.register_craft{
|
||||
type = "digging",
|
||||
items = {name},
|
||||
output = drop,
|
||||
}
|
||||
end
|
||||
elseif is_table(drop) then
|
||||
handle_drops_table(name, drop)
|
||||
end
|
||||
@ -1476,10 +1561,12 @@ local function get_init_items()
|
||||
recipes_cache = dslz(storage:get "recipes_cache")
|
||||
else
|
||||
print "[craftguide] Caching data (this may take a while)"
|
||||
local hash = {}
|
||||
local _select, _preselect = {}, {}
|
||||
|
||||
for name, def in pairs(reg_items) do
|
||||
if show_item(def) then
|
||||
if name ~= "" and show_item(def) then
|
||||
register_drops(name, def.drop)
|
||||
|
||||
if not fuel_cache[name] then
|
||||
cache_fuel(name)
|
||||
end
|
||||
@ -1489,16 +1576,19 @@ local function get_init_items()
|
||||
end
|
||||
|
||||
cache_usages(name)
|
||||
register_drops(name, def.drop)
|
||||
|
||||
if name ~= "" and recipes_cache[name] or usages_cache[name] then
|
||||
_preselect[name] = true
|
||||
end
|
||||
end
|
||||
|
||||
for name in pairs(_preselect) do
|
||||
if recipes_cache[name] or usages_cache[name] then
|
||||
init_items[#init_items + 1] = name
|
||||
hash[name] = true
|
||||
end
|
||||
_select[name] = true
|
||||
end
|
||||
end
|
||||
|
||||
handle_aliases(hash)
|
||||
handle_aliases(_select)
|
||||
sort(init_items)
|
||||
|
||||
storage:set_string("init_items", slz(init_items))
|
||||
@ -1549,6 +1639,10 @@ on_mods_loaded(get_init_items)
|
||||
on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
init_data(name)
|
||||
|
||||
if pdata[name].fs_version < FORMSPEC_MINIMAL_VERSION then
|
||||
outdated(name)
|
||||
end
|
||||
end)
|
||||
|
||||
local function fields(player, _f)
|
||||
@ -1579,7 +1673,7 @@ local function fields(player, _f)
|
||||
data.pagenum = 1
|
||||
search(data)
|
||||
|
||||
elseif _f.prev_page or _f.next_page then
|
||||
elseif _f.prev_page or _f.next_page or _f.pagenum then
|
||||
if data.pagemax == 1 then return end
|
||||
data.pagenum = data.pagenum - (_f.prev_page and 1 or -1)
|
||||
|
||||
@ -1593,7 +1687,7 @@ local function fields(player, _f)
|
||||
local fav, i = is_fav(data)
|
||||
local total = #data.favs
|
||||
|
||||
if total < 6 and not fav then
|
||||
if total < MAX_FAVS and not fav then
|
||||
data.favs[total + 1] = data.query_item
|
||||
elseif fav then
|
||||
remove(data.favs, i)
|
||||
@ -1653,9 +1747,8 @@ if sfinv_only then
|
||||
get = function(self, player, context)
|
||||
local name = player:get_player_name()
|
||||
local data = pdata[name]
|
||||
local formspec = make_fs(data)
|
||||
|
||||
return sfinv.make_formspec(player, context, formspec)
|
||||
return sfinv.make_formspec(player, context, make_fs(data))
|
||||
end,
|
||||
|
||||
on_enter = function(self, player, context)
|
||||
@ -1684,17 +1777,7 @@ else
|
||||
local data = pdata[name]
|
||||
|
||||
if data.fs_version < FORMSPEC_MINIMAL_VERSION then
|
||||
local fs = fmt([[
|
||||
size[6.6,1.3]
|
||||
image[0,0;1,1;%s]
|
||||
label[1,0;%s]
|
||||
button_exit[2.8,0.8;1,1;;OK]
|
||||
]],
|
||||
PNG.nothing,
|
||||
"Your Minetest client is outdated.\n" ..
|
||||
"Get the latest version on minetest.net to use the Crafting Guide.")
|
||||
|
||||
return show_formspec(name, "craftguide", fs)
|
||||
return outdated(name)
|
||||
end
|
||||
|
||||
if next(recipe_filters) then
|
||||
@ -1725,7 +1808,12 @@ else
|
||||
paramtype = "light",
|
||||
paramtype2 = "wallmounted",
|
||||
sunlight_propagates = true,
|
||||
groups = {choppy = 1, attached_node = 1, oddly_breakable_by_hand = 1, flammable = 3},
|
||||
groups = {
|
||||
choppy = 1,
|
||||
attached_node = 1,
|
||||
oddly_breakable_by_hand = 1,
|
||||
flammable = 3,
|
||||
},
|
||||
node_box = {
|
||||
type = "wallmounted",
|
||||
wall_top = {-0.5, 0.4375, -0.5, 0.5, 0.5, 0.5},
|
||||
@ -1770,7 +1858,7 @@ else
|
||||
if rawget(_G, "sfinv_buttons") then
|
||||
sfinv_buttons.register_button("craftguide", {
|
||||
title = S"Crafting Guide",
|
||||
tooltip = S"Shows a list of available crafting recipes, cooking recipes and fuels",
|
||||
tooltip = S"Shows a list of available crafting recipes",
|
||||
image = PNG.book,
|
||||
action = function(player)
|
||||
on_use(player)
|
||||
@ -1780,7 +1868,6 @@ else
|
||||
end
|
||||
|
||||
if progressive_mode then
|
||||
local PLAYERS = {}
|
||||
local POLL_FREQ = 0.25
|
||||
local HUD_TIMER_MAX = 1.5
|
||||
|
||||
@ -1867,6 +1954,34 @@ if progressive_mode then
|
||||
return inv_items
|
||||
end
|
||||
|
||||
local function init_hud(player, data)
|
||||
data.hud = {
|
||||
bg = player:hud_add{
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0.78, y = 1},
|
||||
alignment = {x = 1, y = 1},
|
||||
scale = {x = 370, y = 112},
|
||||
text = PNG.bg,
|
||||
},
|
||||
|
||||
book = player:hud_add{
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0.79, y = 1.02},
|
||||
alignment = {x = 1, y = 1},
|
||||
scale = {x = 4, y = 4},
|
||||
text = PNG.book,
|
||||
},
|
||||
|
||||
text = player:hud_add{
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0.84, y = 1.04},
|
||||
alignment = {x = 1, y = 1},
|
||||
number = 0xffffff,
|
||||
text = "",
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
local function show_hud_success(player, data)
|
||||
-- It'd better to have an engine function `hud_move` to only need
|
||||
-- 2 calls for the notification's back and forth.
|
||||
@ -1914,8 +2029,9 @@ if progressive_mode then
|
||||
-- Workaround. Need an engine call to detect when the contents of
|
||||
-- the player inventory changed, instead.
|
||||
local function poll_new_items()
|
||||
for i = 1, #PLAYERS do
|
||||
local player = PLAYERS[i]
|
||||
local players = get_players()
|
||||
for i = 1, #players do
|
||||
local player = players[i]
|
||||
local name = player:get_player_name()
|
||||
local data = pdata[name]
|
||||
|
||||
@ -1948,12 +2064,13 @@ if progressive_mode then
|
||||
poll_new_items()
|
||||
|
||||
globalstep(function()
|
||||
for i = 1, #PLAYERS do
|
||||
local player = PLAYERS[i]
|
||||
local players = get_players()
|
||||
for i = 1, #players do
|
||||
local player = players[i]
|
||||
local name = player:get_player_name()
|
||||
local data = pdata[name]
|
||||
|
||||
if data.show_hud ~= nil then
|
||||
if data.show_hud ~= nil and singleplayer then
|
||||
show_hud_success(player, data)
|
||||
end
|
||||
end
|
||||
@ -1962,8 +2079,6 @@ if progressive_mode then
|
||||
craftguide.add_recipe_filter("Default progressive filter", progressive_filter)
|
||||
|
||||
on_joinplayer(function(player)
|
||||
PLAYERS = get_players()
|
||||
|
||||
local name = player:get_player_name()
|
||||
local data = pdata[name]
|
||||
|
||||
@ -1971,31 +2086,9 @@ if progressive_mode then
|
||||
data.inv_items = dslz(meta:get_string "inv_items") or {}
|
||||
data.known_recipes = dslz(meta:get_string "known_recipes") or 0
|
||||
|
||||
data.hud = {
|
||||
bg = player:hud_add{
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0.78, y = 1},
|
||||
alignment = {x = 1, y = 1},
|
||||
scale = {x = 370, y = 112},
|
||||
text = PNG.bg,
|
||||
},
|
||||
|
||||
book = player:hud_add{
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0.79, y = 1.02},
|
||||
alignment = {x = 1, y = 1},
|
||||
scale = {x = 4, y = 4},
|
||||
text = PNG.book,
|
||||
},
|
||||
|
||||
text = player:hud_add{
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0.84, y = 1.04},
|
||||
alignment = {x = 1, y = 1},
|
||||
number = 0xffffff,
|
||||
text = "",
|
||||
},
|
||||
}
|
||||
if singleplayer then
|
||||
init_hud(player, data)
|
||||
end
|
||||
end)
|
||||
|
||||
local to_save = {"inv_items", "known_recipes"}
|
||||
@ -2011,14 +2104,12 @@ if progressive_mode then
|
||||
end
|
||||
end
|
||||
|
||||
on_leaveplayer(function(player)
|
||||
PLAYERS = get_players()
|
||||
save_meta(player)
|
||||
end)
|
||||
on_leaveplayer(save_meta)
|
||||
|
||||
on_shutdown(function()
|
||||
for i = 1, #PLAYERS do
|
||||
local player = PLAYERS[i]
|
||||
local players = get_players()
|
||||
for i = 1, #players do
|
||||
local player = players[i]
|
||||
save_meta(player)
|
||||
end
|
||||
end)
|
||||
@ -2046,13 +2137,11 @@ 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, fmt("%s: %s",
|
||||
S"No recipe or usage for this item",
|
||||
get_desc(item)))
|
||||
S"No recipe or usage for this item", get_desc(item)))
|
||||
end
|
||||
|
||||
return false, msg(name, fmt("%s: %s",
|
||||
S"You don't know a recipe or usage for this item",
|
||||
get_desc(item)))
|
||||
S"You don't know a recipe or usage for this item", get_desc(item)))
|
||||
end
|
||||
|
||||
data.query_item = item
|
||||
|
@ -56,5 +56,10 @@ No node pointed=Aucun bloc visé
|
||||
You don't know a recipe or usage for this item=Tu ne connais aucune recette pour ce bloc
|
||||
No recipe or usage for this item=Aucune recette pour ce bloc
|
||||
Digging=Destruction
|
||||
Digging Chance=Destruction chanceuse
|
||||
Digging (by chance)=Destruction chanceuse
|
||||
@1 of chance to drop=@1 de chance de tomber
|
||||
Mark this item=Mettre en favori.
|
||||
Unmark this item=Enlever des favoris.
|
||||
Cannot mark this item. Limit of bookmarks reached.=Impossible de mettre cet item en favori. Limite des favoris atteinte.
|
||||
Only drop if using one of these tools: @1=Tombe seulement si détruit avec un de ces outils: @1
|
||||
Only drop if using this tool: @1=Tombe seulement si détruit avec cet outil: @1
|
||||
|
@ -56,5 +56,10 @@ No node pointed=
|
||||
You don't know a recipe or usage for this item=
|
||||
No recipe or usage for this item=
|
||||
Digging=
|
||||
Digging Chance=
|
||||
Digging (by chance)=
|
||||
@1 of chance to drop=
|
||||
Mark this item=
|
||||
Unmark this item=
|
||||
Cannot mark this item. Limit of bookmarks reached.=
|
||||
Only drop if using one of these tools: @1=
|
||||
Only drop if using this tool: @1=
|
||||
|
BIN
textures/craftguide_mesepick.png
Normal file
BIN
textures/craftguide_mesepick.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
BIN
textures/craftguide_steelpick.png
Normal file
BIN
textures/craftguide_steelpick.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
Reference in New Issue
Block a user