Compare commits

...

7 Commits

Author SHA1 Message Date
0de66b1a09 Small cleanup 2020-09-07 00:57:57 +02:00
aa46556020 Fix tooltip 2 2020-08-31 22:46:30 +02:00
ce59bd35d4 Fix tooltip 2020-08-31 15:07:39 +02:00
8c3efefd92 Cleanup 2020-08-29 23:14:59 +02:00
92c6a53fb2 Don't translate labels directly 2020-08-29 18:42:04 +02:00
f17922cf68 Improve header display 2020-08-29 18:34:04 +02:00
f91436d6ce Add chinese translations 2020-08-25 19:19:33 +02:00
2 changed files with 90 additions and 72 deletions

122
init.lua
View File

@ -819,22 +819,18 @@ local function is_fav(favs, query_item)
end end
local function weird_desc(str) local function weird_desc(str)
return not true_str(str) or find(str, "[\\]*") or not find(str, "%u") return not true_str(str) or find(str, "\n") or not find(str, "%u")
end end
local function toupper(str) local function toupper(str)
return str:gsub("%f[%w]%l", upper):gsub("_", " ") return str:gsub("%f[%w]%l", upper):gsub("_", " ")
end end
local function strip_newline(str) local function nice_strip(str, limit)
return match(str, "[^\n]*") return #str > limit and fmt("%s...", sub(str, 1, limit - 3)) or str
end end
local function strip_prefix(str) local function get_desc(item)
return match(str, ".*@.*%)(.*)()") or str
end
local function get_desc(item, lang_code)
if sub(item, 1, 1) == "_" then if sub(item, 1, 1) == "_" then
item = sub(item, 2) item = sub(item, 2)
end end
@ -844,10 +840,7 @@ 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():match("[^\n]*")
desc = desc:trim()
desc = strip_newline(desc)
desc = strip_prefix(desc)
if not find(desc, "%u") then if not find(desc, "%u") then
desc = toupper(desc) desc = toupper(desc)
@ -863,7 +856,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 +874,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 +892,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 +920,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 +999,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 +1014,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
@ -1110,13 +1103,7 @@ local function get_grid_fs(lang_code, fs, rcp, spacing)
fs[#fs + 1] = fmt(FMT.image, X, Y, btn_size, btn_size, PNG.selected) fs[#fs + 1] = fmt(FMT.image, X, Y, btn_size, btn_size, PNG.selected)
end end
local btn_name = "" local btn_name = groups and fmt("group|%s|%s", groups[1], item) or item
if groups then
btn_name = fmt("group|%s|%s", groups[1], item)
elseif item ~= "" then
btn_name = item
end
fs[#fs + 1] = fmt(FMT.item_image_button, fs[#fs + 1] = fmt(FMT.item_image_button,
X, Y, btn_size, btn_size, item, btn_name, label) X, Y, btn_size, btn_size, item, btn_name, label)
@ -1138,7 +1125,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 +1133,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 +1170,20 @@ 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)) fs[#fs + 1] = "style_type[label;font=bold;font_size=22]"
desc = #desc > 33 and fmt("%s...", sub(desc, 1, 30)) or desc fs[#fs + 1] = fmt(FMT.label, 8.75, spacing - 0.1, nice_strip(ESC(get_desc(query_item)), 45))
local t_desc = query_item fs[#fs + 1] = "style_type[label;font=mono;font_size=16]"
t_desc = #t_desc > 40 and fmt("%s...", sub(t_desc, 1, 37)) or t_desc fs[#fs + 1] = fmt(FMT.label, 8.75, spacing + 0.3, clr("#7bf", nice_strip(query_item, 35)))
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 +1212,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 +1233,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 +1250,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 +1330,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 +1353,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 +2123,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

View File

@ -0,0 +1,40 @@
# textdomain: craftguide
Any black dye=任何黑染料
Any black flower=任何黑花
Any blue dye=任何蓝染料
Any blue flower=任何蓝花
Any brown dye=任何棕染料
Any coal=任何煤炭
Any cyan dye=任何青染料
Any dark green dye=任何暗绿染料
Any dark grey dye=任何暗灰染料
Any green dye=任何绿染料
Any green flower=任何绿花
Any grey dye=任何灰染料
Any item belonging to the group(s): @1=任何属于以下组别的物品:@1
Any kind of stone block=任何石方块
Any magenta dye=任何品红染料
Any orange dye=任何橙染料
Any orange flower=任何橙花
Any pink dye=任何粉红染料
Any red dye=任何红染料
Any red flower=任何红花
Any sand=任何沙
Any stick=任何棒
Any vessel=任何容器
Any violet dye=任何紫染料
Any violet flower=任何紫花
Any white dye=任何白染料
Any white flower=任何白花
Any wood planks=任何木板
Any wool=任何羊毛
Any yellow dye=任何黄染料
Any yellow flower=任何黄花
Cooking time: @1=熔炼时间为:@1
No items to show=没有可显示的项目。
Recipe @1 of @2=第@1个配方共@2个
Usage @1 of @2=第@1个用法共@2个
Recipe is too big to be displayed=配方太大,无法显示。
Shapeless=无序配方
Unknown Item=不明物品