mirror of
https://github.com/minetest-mods/craftguide.git
synced 2025-07-13 21:40:19 +02:00
Compare commits
3 Commits
f91436d6ce
...
8c3efefd92
Author | SHA1 | Date | |
---|---|---|---|
8c3efefd92 | |||
92c6a53fb2 | |||
f17922cf68 |
101
init.lua
101
init.lua
@ -834,7 +834,7 @@ local function strip_prefix(str)
|
|||||||
return match(str, ".*@.*%)(.*)()") or str
|
return match(str, ".*@.*%)(.*)()") or str
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_desc(item, lang_code)
|
local function get_desc(item)
|
||||||
if sub(item, 1, 1) == "_" then
|
if sub(item, 1, 1) == "_" then
|
||||||
item = sub(item, 2)
|
item = sub(item, 2)
|
||||||
end
|
end
|
||||||
@ -844,7 +844,6 @@ local function get_desc(item, lang_code)
|
|||||||
if def then
|
if def then
|
||||||
local desc = def.description
|
local desc = def.description
|
||||||
if true_str(desc) then
|
if true_str(desc) then
|
||||||
desc = translate(lang_code, desc)
|
|
||||||
desc = desc:trim()
|
desc = desc:trim()
|
||||||
desc = strip_newline(desc)
|
desc = strip_newline(desc)
|
||||||
desc = strip_prefix(desc)
|
desc = strip_prefix(desc)
|
||||||
@ -863,7 +862,7 @@ local function get_desc(item, lang_code)
|
|||||||
return S("Unknown Item (@1)", item)
|
return S("Unknown Item (@1)", item)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_tooltip(item, info, lang_code)
|
local function get_tooltip(item, info)
|
||||||
local tooltip
|
local tooltip
|
||||||
|
|
||||||
if info.groups then
|
if info.groups then
|
||||||
@ -881,7 +880,7 @@ local function get_tooltip(item, info, lang_code)
|
|||||||
tooltip = S("Any item belonging to the group(s): @1", groupstr)
|
tooltip = S("Any item belonging to the group(s): @1", groupstr)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
tooltip = get_desc(item, lang_code)
|
tooltip = get_desc(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function add(str)
|
local function add(str)
|
||||||
@ -899,7 +898,7 @@ local function get_tooltip(item, info, lang_code)
|
|||||||
if info.replace then
|
if info.replace then
|
||||||
for i = 1, #info.replace.items do
|
for i = 1, #info.replace.items do
|
||||||
local rpl = match(info.replace.items[i], "%S+")
|
local rpl = match(info.replace.items[i], "%S+")
|
||||||
local desc = clr("#ff0", get_desc(rpl, lang_code))
|
local desc = clr("#ff0", get_desc(rpl))
|
||||||
|
|
||||||
if info.replace.type == "cooking" then
|
if info.replace.type == "cooking" then
|
||||||
tooltip = add(S("Replaced by @1 on smelting", desc))
|
tooltip = add(S("Replaced by @1 on smelting", desc))
|
||||||
@ -927,21 +926,21 @@ local function get_tooltip(item, info, lang_code)
|
|||||||
if several then
|
if several then
|
||||||
for i = 1, #info.tools do
|
for i = 1, #info.tools do
|
||||||
names = fmt("%s\t\t- %s\n",
|
names = fmt("%s\t\t- %s\n",
|
||||||
names, clr("#ff0", get_desc(info.tools[i], lang_code)))
|
names, clr("#ff0", get_desc(info.tools[i])))
|
||||||
end
|
end
|
||||||
|
|
||||||
tooltip = add(S("Only drop if using one of these tools: @1",
|
tooltip = add(S("Only drop if using one of these tools: @1",
|
||||||
sub(names, 1, -2)))
|
sub(names, 1, -2)))
|
||||||
else
|
else
|
||||||
tooltip = add(S("Only drop if using this tool: @1",
|
tooltip = add(S("Only drop if using this tool: @1",
|
||||||
clr("#ff0", get_desc(info.tools[1], lang_code))))
|
clr("#ff0", get_desc(info.tools[1]))))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return fmt("tooltip[%s;%s]", item, ESC(tooltip))
|
return fmt("tooltip[%s;%s]", item, ESC(tooltip))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_output_fs(lang_code, fs, rcp, shapeless, right, btn_size, _btn_size, spacing)
|
local function get_output_fs(fs, rcp, shapeless, right, btn_size, _btn_size, spacing)
|
||||||
local custom_recipe = craft_types[rcp.type]
|
local custom_recipe = craft_types[rcp.type]
|
||||||
|
|
||||||
if custom_recipe or shapeless or rcp.type == "cooking" then
|
if custom_recipe or shapeless or rcp.type == "cooking" then
|
||||||
@ -1006,7 +1005,7 @@ local function get_output_fs(lang_code, fs, rcp, shapeless, right, btn_size, _bt
|
|||||||
}
|
}
|
||||||
|
|
||||||
if next(infos) then
|
if next(infos) then
|
||||||
fs[#fs + 1] = get_tooltip(_name, infos, lang_code)
|
fs[#fs + 1] = get_tooltip(_name, infos)
|
||||||
end
|
end
|
||||||
|
|
||||||
if infos.burntime then
|
if infos.burntime then
|
||||||
@ -1021,7 +1020,7 @@ local function get_output_fs(lang_code, fs, rcp, shapeless, right, btn_size, _bt
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_grid_fs(lang_code, fs, rcp, spacing)
|
local function get_grid_fs(fs, rcp, spacing)
|
||||||
local width = rcp.width or 1
|
local width = rcp.width or 1
|
||||||
local right, btn_size, _btn_size = 0, ITEM_BTN_SIZE
|
local right, btn_size, _btn_size = 0, ITEM_BTN_SIZE
|
||||||
local cooktime, shapeless
|
local cooktime, shapeless
|
||||||
@ -1138,7 +1137,7 @@ local function get_grid_fs(lang_code, fs, rcp, spacing)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if next(infos) then
|
if next(infos) then
|
||||||
fs[#fs + 1] = get_tooltip(btn_name, infos, lang_code)
|
fs[#fs + 1] = get_tooltip(btn_name, infos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1146,25 +1145,25 @@ local function get_grid_fs(lang_code, fs, rcp, spacing)
|
|||||||
fs[#fs + 1] = "style_type[item_image_button;border=false]"
|
fs[#fs + 1] = "style_type[item_image_button;border=false]"
|
||||||
end
|
end
|
||||||
|
|
||||||
get_output_fs(lang_code, fs, rcp, shapeless, right, btn_size, _btn_size, spacing)
|
get_output_fs(fs, rcp, shapeless, right, btn_size, _btn_size, spacing)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_rcp_lbl(lang_code, show_usages, unum, rnum, fs, panel, spacing, rn, is_recipe)
|
local function get_rcp_lbl(fs, data, panel, spacing, rn, is_recipe)
|
||||||
local lbl
|
local lbl
|
||||||
|
|
||||||
if (not sfinv_only and is_recipe) or (sfinv_only and not show_usages) then
|
if (not sfinv_only and is_recipe) or (sfinv_only and not data.show_usages) then
|
||||||
lbl = ES("Recipe @1 of @2", rnum, rn)
|
lbl = ES("Recipe @1 of @2", data.rnum, rn)
|
||||||
|
|
||||||
elseif not sfinv_only or (sfinv_only and show_usages) then
|
elseif not sfinv_only or (sfinv_only and data.show_usages) then
|
||||||
lbl = ES("Usage @1 of @2", unum, rn)
|
lbl = ES("Usage @1 of @2", data.unum, rn)
|
||||||
|
|
||||||
elseif sfinv_only then
|
elseif sfinv_only then
|
||||||
lbl = show_usages and ES("Usage @1 of @2", unum, rn) or
|
lbl = data.show_usages and ES("Usage @1 of @2", data.unum, rn) or
|
||||||
ES("Recipe @1 of @2", rnum, rn)
|
ES("Recipe @1 of @2", data.rnum, rn)
|
||||||
end
|
end
|
||||||
|
|
||||||
lbl = translate(lang_code, lbl)
|
local _lbl = translate(data.lang_code, lbl)
|
||||||
local lbl_len = #lbl:gsub("[\128-\191]", "") -- Count chars, not bytes in UTF-8 strings
|
local lbl_len = #_lbl:gsub("[\128-\191]", "") -- Count chars, not bytes in UTF-8 strings
|
||||||
local shift = min(0.9, abs(13 - max(13, lbl_len)) * 0.1)
|
local shift = min(0.9, abs(13 - max(13, lbl_len)) * 0.1)
|
||||||
|
|
||||||
fs[#fs + 1] = fmt(FMT.label,
|
fs[#fs + 1] = fmt(FMT.label,
|
||||||
@ -1183,21 +1182,25 @@ local function get_rcp_lbl(lang_code, show_usages, unum, rnum, fs, panel, spacin
|
|||||||
x_arrow + 1.8, y_arrow, PNG.next, next_name, "")
|
x_arrow + 1.8, y_arrow, PNG.next, next_name, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
local rcp = is_recipe and panel.rcp[rnum] or panel.rcp[unum]
|
local rcp = is_recipe and panel.rcp[data.rnum] or panel.rcp[data.unum]
|
||||||
get_grid_fs(lang_code, fs, rcp, spacing)
|
get_grid_fs(fs, rcp, spacing)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_title_fs(query_item, lang_code, favs, fs, spacing)
|
local function get_title_fs(query_item, favs, fs, spacing)
|
||||||
local desc = ESC(get_desc(query_item, lang_code))
|
local desc = ESC(get_desc(query_item))
|
||||||
desc = #desc > 33 and fmt("%s...", sub(desc, 1, 30)) or desc
|
desc = #desc > 33 and fmt("%s...", sub(desc, 1, 30)) or desc
|
||||||
local t_desc = query_item
|
local t_desc = query_item
|
||||||
t_desc = #t_desc > 40 and fmt("%s...", sub(t_desc, 1, 37)) or t_desc
|
t_desc = #t_desc > 35 and fmt("%s...", sub(t_desc, 1, 32)) or t_desc
|
||||||
|
|
||||||
|
fs[#fs + 1] = "style_type[label;font=bold;font_size=22]"
|
||||||
|
fs[#fs + 1] = fmt(FMT.label, 8.75, spacing - 0.1, desc)
|
||||||
|
fs[#fs + 1] = "style_type[label;font=mono;font_size=16]"
|
||||||
|
fs[#fs + 1] = fmt(FMT.label, 8.75, spacing + 0.3, clr("#7bf", t_desc))
|
||||||
|
fs[#fs + 1] = "style_type[label;font=normal;font_size=16]"
|
||||||
|
|
||||||
fs[#fs + 1] = fmt(FMT.hypertext,
|
fs[#fs + 1] = fmt(FMT.hypertext,
|
||||||
9.05, spacing - 0.1, 5.85, 1.2,
|
13.8, spacing - 0.15, 1.1, 1.3,
|
||||||
fmt("<item name=%s float=right width=64 height=64 rotate=yes>" ..
|
fmt("<item name=%s width=64 rotate=yes>", query_item))
|
||||||
"<big><b>%s</b></big>\n<style color=#7bf font=mono>%s</style>",
|
|
||||||
query_item, desc, t_desc))
|
|
||||||
|
|
||||||
local fav = is_fav(favs, query_item)
|
local fav = is_fav(favs, query_item)
|
||||||
local nfavs = #favs
|
local nfavs = #favs
|
||||||
@ -1226,17 +1229,15 @@ local function get_title_fs(query_item, lang_code, favs, fs, spacing)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_panels(lang_code, query_item, recipes, usages, show_usages,
|
local function get_panels(data, fs)
|
||||||
favs, unum, rnum, fs)
|
|
||||||
|
|
||||||
local _title = {name = "title", height = 1.2}
|
local _title = {name = "title", height = 1.2}
|
||||||
local _favs = {name = "favs", height = 1.91}
|
local _favs = {name = "favs", height = 1.91}
|
||||||
local _recipes = {name = "recipes", rcp = recipes, height = 3.5}
|
local _recipes = {name = "recipes", rcp = data.recipes, height = 3.5}
|
||||||
local _usages = {name = "usages", rcp = usages, height = 3.5}
|
local _usages = {name = "usages", rcp = data.usages, height = 3.5}
|
||||||
local panels = {_title, _recipes, _usages, _favs}
|
local panels = {_title, _recipes, _usages, _favs}
|
||||||
|
|
||||||
if sfinv_only then
|
if sfinv_only then
|
||||||
panels = {show_usages and _usages or _recipes}
|
panels = {data.show_usages and _usages or _recipes}
|
||||||
end
|
end
|
||||||
|
|
||||||
for idx = 1, #panels do
|
for idx = 1, #panels do
|
||||||
@ -1249,12 +1250,11 @@ local function get_panels(lang_code, query_item, recipes, usages, show_usages,
|
|||||||
end
|
end
|
||||||
|
|
||||||
local rn = panel.rcp and #panel.rcp
|
local rn = panel.rcp and #panel.rcp
|
||||||
local is_recipe = sfinv_only and not show_usages or panel.name == "recipes"
|
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"
|
local recipe_or_usage = panel.name == "recipes" or panel.name == "usages"
|
||||||
|
|
||||||
if rn then
|
if rn then
|
||||||
get_rcp_lbl(lang_code, show_usages, unum, rnum, fs, panel,
|
get_rcp_lbl(fs, data, panel, spacing, rn, is_recipe)
|
||||||
spacing, rn, is_recipe)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if sfinv_only then return end
|
if sfinv_only then return end
|
||||||
@ -1267,21 +1267,20 @@ local function get_panels(lang_code, query_item, recipes, usages, show_usages,
|
|||||||
|
|
||||||
fs[#fs + 1] = fmt(FMT.hypertext,
|
fs[#fs + 1] = fmt(FMT.hypertext,
|
||||||
8.29, YOFFSET + spacing + 0.3, 6.8, 1,
|
8.29, YOFFSET + spacing + 0.3, 6.8, 1,
|
||||||
fmt("<center><style size=20><b>%s</b></style></center>",
|
fmt("<center><style size=20><b>%s</b></style></center>", lbl))
|
||||||
translate(lang_code, lbl)))
|
|
||||||
|
|
||||||
elseif panel.name == "title" then
|
elseif panel.name == "title" then
|
||||||
get_title_fs(query_item, lang_code, favs, fs, spacing)
|
get_title_fs(data.query_item, data.favs, fs, spacing)
|
||||||
|
|
||||||
elseif panel.name == "favs" then
|
elseif panel.name == "favs" then
|
||||||
fs[#fs + 1] = fmt(FMT.label, 8.3, spacing - 0.15, ES"Bookmarks")
|
fs[#fs + 1] = fmt(FMT.label, 8.3, spacing - 0.15, ES"Bookmarks")
|
||||||
|
|
||||||
for i = 1, #favs do
|
for i = 1, #data.favs do
|
||||||
local item = favs[i]
|
local item = data.favs[i]
|
||||||
local X = 7.85 + (i - 0.5)
|
local X = 7.85 + (i - 0.5)
|
||||||
local Y = spacing + 0.4
|
local Y = spacing + 0.4
|
||||||
|
|
||||||
if query_item == item then
|
if data.query_item == item then
|
||||||
fs[#fs + 1] = fmt(FMT.image, X, Y,
|
fs[#fs + 1] = fmt(FMT.image, X, Y,
|
||||||
ITEM_BTN_SIZE, ITEM_BTN_SIZE, PNG.selected)
|
ITEM_BTN_SIZE, ITEM_BTN_SIZE, PNG.selected)
|
||||||
end
|
end
|
||||||
@ -1348,8 +1347,7 @@ local function make_fs(data)
|
|||||||
|
|
||||||
fs[#fs + 1] = fmt(FMT.hypertext,
|
fs[#fs + 1] = fmt(FMT.hypertext,
|
||||||
0.05, 3, 8.29, 1,
|
0.05, 3, 8.29, 1,
|
||||||
fmt("<center><style size=20><b>%s</b></style></center>",
|
fmt("<center><style size=20><b>%s</b></style></center>", lbl))
|
||||||
translate(data.lang_code, lbl)))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local first_item = (data.pagenum - 1) * IPP
|
local first_item = (data.pagenum - 1) * IPP
|
||||||
@ -1372,8 +1370,7 @@ local function make_fs(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if (data.recipes and #data.recipes > 0) or (data.usages and #data.usages > 0) then
|
if (data.recipes and #data.recipes > 0) or (data.usages and #data.usages > 0) then
|
||||||
get_panels(data.lang_code, data.query_item, data.recipes, data.usages,
|
get_panels(data, fs)
|
||||||
data.show_usages, data.favs, data.unum, data.rnum, fs)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return concat(fs)
|
return concat(fs)
|
||||||
@ -2143,13 +2140,11 @@ function craftguide.show(name, item, show_usages)
|
|||||||
if not recipes and not usages then
|
if not recipes and not usages then
|
||||||
if not recipes_cache[item] and not usages_cache[item] then
|
if not recipes_cache[item] and not usages_cache[item] then
|
||||||
return false, msg(name, fmt("%s: %s",
|
return false, msg(name, fmt("%s: %s",
|
||||||
S"No recipe or usage for this item",
|
S"No recipe or usage for this item", get_desc(item)))
|
||||||
get_desc(item, data.lang_code)))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return false, msg(name, fmt("%s: %s",
|
return false, msg(name, fmt("%s: %s",
|
||||||
S"You don't know a recipe or usage for this item",
|
S"You don't know a recipe or usage for this item", get_desc(item)))
|
||||||
get_desc(item, data.lang_code)))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
data.query_item = item
|
data.query_item = item
|
||||||
|
Reference in New Issue
Block a user