This commit is contained in:
Jean-Patrick Guerrero 2020-08-29 23:08:55 +02:00
parent 92c6a53fb2
commit 8c3efefd92
1 changed files with 21 additions and 25 deletions

View File

@ -1148,21 +1148,21 @@ local function get_grid_fs(fs, rcp, spacing)
get_output_fs(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
local _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)
@ -1182,7 +1182,7 @@ 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(fs, rcp, spacing) get_grid_fs(fs, rcp, spacing)
end end
@ -1200,7 +1200,7 @@ local function get_title_fs(query_item, favs, fs, spacing)
fs[#fs + 1] = fmt(FMT.hypertext, fs[#fs + 1] = fmt(FMT.hypertext,
13.8, spacing - 0.15, 1.1, 1.3, 13.8, spacing - 0.15, 1.1, 1.3,
fmt("<item name=%s float=center width=64 height=64 rotate=yes>", query_item)) fmt("<item name=%s width=64 rotate=yes>", query_item))
local fav = is_fav(favs, query_item) local fav = is_fav(favs, query_item)
local nfavs = #favs local nfavs = #favs
@ -1229,17 +1229,15 @@ local function get_title_fs(query_item, 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
@ -1252,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
@ -1273,17 +1270,17 @@ local function get_panels(lang_code, query_item, recipes, usages, show_usages,
fmt("<center><style size=20><b>%s</b></style></center>", lbl)) fmt("<center><style size=20><b>%s</b></style></center>", lbl))
elseif panel.name == "title" then elseif panel.name == "title" then
get_title_fs(query_item, 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
@ -1373,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)