Add fallback background is not -dev version

This commit is contained in:
Jean-Patrick Guerrero 2019-09-07 12:07:25 +02:00
parent 22787e41e3
commit bf616f5d21
5 changed files with 62 additions and 75 deletions

105
init.lua

@ -48,7 +48,27 @@ local vec_add, vec_mul = vector.add, vector.multiply
local ROWS = sfinv_only and 9 or 11 local ROWS = sfinv_only and 9 or 11
local LINES = 5 local LINES = 5
local IPP = ROWS * LINES local IPP = ROWS * LINES
local GRID_LIMIT = 8 local WH_LIMIT = 8
local XOFFSET = sfinv_only and 3.83 or 4.66
local YOFFSET = sfinv_only and 6 or 6.6
local DEV_CORE = sub(core.get_version().string, -3) == "dev"
craftguide.background = "craftguide_bg_full.png"
local PNG = {
bg = "craftguide_bg.png",
bg_full = craftguide.background,
search = "craftguide_search_icon.png",
clear = "craftguide_clear_icon.png",
prev = "craftguide_next_icon.png^\\[transformFX",
next = "craftguide_next_icon.png",
arrow = "craftguide_arrow.png",
fire = "craftguide_fire.png",
book = "craftguide_book.png",
sign = "craftguide_sign.png",
}
local FMT = { local FMT = {
box = "box[%f,%f;%f,%f;%s]", box = "box[%f,%f;%f,%f;%s]",
@ -71,8 +91,6 @@ craftguide.group_stereotypes = {
mesecon_conductor_craftable = "mesecons:wire_00000000_off", mesecon_conductor_craftable = "mesecons:wire_00000000_off",
} }
craftguide.background = "craftguide_bg_full.png"
local function table_replace(t, val, new) local function table_replace(t, val, new)
for k, v in pairs(t) do for k, v in pairs(t) do
if v == val then if v == val then
@ -385,7 +403,7 @@ local function groups_to_item(groups)
return "" return ""
end end
local function get_tooltip(item, groups, cooktime, burntime) local function get_tooltip(item, burntime, groups, cooktime)
local tooltip local tooltip
if groups then if groups then
@ -423,8 +441,6 @@ local function get_recipe_fs(data)
local fs = {} local fs = {}
local recipe = data.recipes[data.rnum] local recipe = data.recipes[data.rnum]
local width = recipe.width local width = recipe.width
local xoffset = sfinv_only and 3.83 or 4.66
local yoffset = sfinv_only and 6 or 6.6
local cooktime, shapeless local cooktime, shapeless
if recipe.type == "cooking" then if recipe.type == "cooking" then
@ -443,22 +459,22 @@ local function get_recipe_fs(data)
ESC(S("Recipe @1 of @2", data.rnum, #data.recipes)) ESC(S("Recipe @1 of @2", data.rnum, #data.recipes))
fs[#fs + 1] = fmt(FMT.button, fs[#fs + 1] = fmt(FMT.button,
xoffset + (sfinv_only and 1.98 or 2.7), XOFFSET + (sfinv_only and 1.98 or 2.7),
yoffset + (sfinv_only and 1.9 or 1.2), YOFFSET + (sfinv_only and 1.9 or 1.2),
2.2, 1, "alternate", btn_lab) 2.2, 1, "alternate", btn_lab)
if width > GRID_LIMIT or rows > GRID_LIMIT then if width > WH_LIMIT or rows > WH_LIMIT then
fs[#fs + 1] = fmt(FMT.label, fs[#fs + 1] = fmt(FMT.label,
sfinv_only and 2 or 3, 7, sfinv_only and 2 or 3, 7,
ESC(S("Recipe is too big to be displayed (@1x@2)", width, rows))) ESC(S("Recipe's too big to be displayed (@1x@2)", width, rows)))
return concat(fs) return concat(fs)
end end
for i = 1, width * rows do for i = 1, width * rows do
local item = recipe.items[i] or "" local item = recipe.items[i] or ""
local X = ceil((i - 1) % width - width) + xoffset local X = ceil((i - 1) % width - width) + XOFFSET
local Y = ceil(i / width) + yoffset - min(2, rows) local Y = ceil(i / width) + YOFFSET - min(2, rows)
if width > 3 or rows > 3 then if width > 3 or rows > 3 then
local xof = 1 - 4 / width local xof = 1 - 4 / width
@ -469,10 +485,10 @@ local function get_recipe_fs(data)
(3.5 + (xof * 2)) / width or (3.5 + (yof * 2)) / rows (3.5 + (xof * 2)) / width or (3.5 + (yof * 2)) / rows
s_btn_size = btn_size s_btn_size = btn_size
X = (btn_size * ((i - 1) % width) + xoffset - X = (btn_size * ((i - 1) % width) + XOFFSET -
(sfinv_only and 2.83 or (xoffset - 2))) * (0.83 - (x_y / 5)) (sfinv_only and 2.83 or (XOFFSET - 2))) * (0.83 - (x_y / 5))
Y = (btn_size * floor((i - 1) / width) + Y = (btn_size * floor((i - 1) / width) +
(5 + ((sfinv_only and 0.81 or 1.5) + x_y))) * (0.86 - (x_y / 5)) (sfinv_only and 5.81 or 6.5) + x_y) * (0.86 - (x_y / 5))
end end
if X > rightest then if X > rightest then
@ -495,7 +511,7 @@ local function get_recipe_fs(data)
local burntime = fuel_cache[item] local burntime = fuel_cache[item]
if groups or cooktime or burntime then if groups or cooktime or burntime then
fs[#fs + 1] = get_tooltip(item, groups, cooktime, burntime) fs[#fs + 1] = get_tooltip(item, burntime, groups, cooktime)
end end
end end
@ -509,7 +525,7 @@ local function get_recipe_fs(data)
icon = fmt("craftguide_%s.png^[resize:16x16", icon) icon = fmt("craftguide_%s.png^[resize:16x16", icon)
end end
local pos_y = yoffset + (sfinv_only and 0.25 or -0.45) local pos_y = YOFFSET + (sfinv_only and 0.25 or -0.45)
fs[#fs + 1] = fmt(FMT.image, fs[#fs + 1] = fmt(FMT.image,
min(3.9, rightest) + 1.2, pos_y, 0.5, 0.5, icon) min(3.9, rightest) + 1.2, pos_y, 0.5, 0.5, icon)
@ -525,31 +541,31 @@ local function get_recipe_fs(data)
local output_X = arrow_X + 0.9 local output_X = arrow_X + 0.9
fs[#fs + 1] = fmt(FMT.image, fs[#fs + 1] = fmt(FMT.image,
arrow_X, yoffset + (sfinv_only and 0.9 or 0.2), arrow_X, YOFFSET + (sfinv_only and 0.9 or 0.2),
0.9, 0.7, "craftguide_arrow.png") 0.9, 0.7, PNG.arrow)
if recipe.type == "fuel" then if recipe.type == "fuel" then
fs[#fs + 1] = fmt(FMT.image, fs[#fs + 1] = fmt(FMT.image,
output_X, yoffset + (sfinv_only and 0.7 or 0), output_X, YOFFSET + (sfinv_only and 0.7 or 0),
1.1, 1.1, "craftguide_fire.png") 1.1, 1.1, PNG.fire)
else else
local output_name = match(recipe.output, "%S+") local output_name = match(recipe.output, "%S+")
local burntime = fuel_cache[output_name] local burntime = fuel_cache[output_name]
fs[#fs + 1] = fmt(FMT.item_image_button, fs[#fs + 1] = fmt(FMT.item_image_button,
output_X, yoffset + (sfinv_only and 0.7 or 0), output_X, YOFFSET + (sfinv_only and 0.7 or 0),
1.1, 1.1, recipe.output, ESC(output_name), "") 1.1, 1.1, recipe.output, ESC(output_name), "")
if burntime then if burntime then
fs[#fs + 1] = get_tooltip(output_name, nil, nil, burntime) fs[#fs + 1] = get_tooltip(output_name, burntime)
fs[#fs + 1] = fmt(FMT.image, fs[#fs + 1] = fmt(FMT.image,
output_X + 1, yoffset + (sfinv_only and 0.7 or 0.1), output_X + 1, YOFFSET + (sfinv_only and 0.7 or 0.1),
0.6, 0.4, "craftguide_arrow.png") 0.6, 0.4, PNG.arrow)
fs[#fs + 1] = fmt(FMT.image, fs[#fs + 1] = fmt(FMT.image,
output_X + 1.6, yoffset + (sfinv_only and 0.55 or 0), output_X + 1.6, YOFFSET + (sfinv_only and 0.55 or 0),
0.6, 0.6, "craftguide_fire.png") 0.6, 0.6, PNG.fire)
end end
end end
@ -567,9 +583,9 @@ local function make_formspec(name)
size[%f,%f;] size[%f,%f;]
no_prepend[] no_prepend[]
bgcolor[#00000000;false] bgcolor[#00000000;false]
background[1,1;1,1;%s;true;10] background[1,1;1,1;%s;true%s]
]], ]],
9.5, 8.4, craftguide.background) 9.5, 8.4, PNG.bg_full, DEV_CORE and ";10" or "")
end end
fs[#fs + 1] = fmt([[ fs[#fs + 1] = fmt([[
@ -578,29 +594,23 @@ local function make_formspec(name)
]], ]],
sfinv_only and 2.76 or 2.72, ESC(data.filter)) sfinv_only and 2.76 or 2.72, ESC(data.filter))
local search_icon = "craftguide_search_icon.png"
local clear_icon = "craftguide_clear_icon.png"
fs[#fs + 1] = fmt([[ fs[#fs + 1] = fmt([[
image_button[%f,-0.05;0.85,0.85;%s;search;;;false;%s^\[colorize:yellow:255] image_button[%f,-0.05;0.85,0.85;%s;search;;;false;%s^\[colorize:yellow:255]
image_button[%f,-0.05;0.85,0.85;%s;clear;;;false;%s^\[colorize:red:255] image_button[%f,-0.05;0.85,0.85;%s;clear;;;false;%s^\[colorize:red:255]
]], ]],
sfinv_only and 2.6 or 2.54, search_icon, search_icon, sfinv_only and 2.6 or 2.54, PNG.search, PNG.search,
sfinv_only and 3.3 or 3.25, clear_icon, clear_icon) sfinv_only and 3.3 or 3.25, PNG.clear, PNG.clear)
fs[#fs + 1] = fmt("label[%f,%f;%s / %u]", fs[#fs + 1] = fmt("label[%f,%f;%s / %u]",
sfinv_only and 6.35 or 7.85, 0.06, sfinv_only and 6.35 or 7.85, 0.06,
colorize("yellow", data.pagenum), data.pagemax) colorize("yellow", data.pagenum), data.pagemax)
local prev_icon = "craftguide_next_icon.png^\\[transformFX"
local next_icon = "craftguide_next_icon.png"
fs[#fs + 1] = fmt([[ fs[#fs + 1] = fmt([[
image_button[%f,-0.05;0.8,0.8;%s;prev;;;false;%s^\[colorize:yellow:255] image_button[%f,-0.05;0.8,0.8;%s;prev;;;false;%s^\[colorize:yellow:255]
image_button[%f,-0.05;0.8,0.8;%s;next;;;false;%s^\[colorize:yellow:255] image_button[%f,-0.05;0.8,0.8;%s;next;;;false;%s^\[colorize:yellow:255]
]], ]],
sfinv_only and 5.45 or 6.83, prev_icon, prev_icon, sfinv_only and 5.45 or 6.83, PNG.prev, PNG.prev,
sfinv_only and 7.2 or 8.75, next_icon, next_icon) sfinv_only and 7.2 or 8.75, PNG.next, PNG.next)
if #data.items == 0 then if #data.items == 0 then
local no_item = S("No item to show") local no_item = S("No item to show")
@ -615,6 +625,7 @@ local function make_formspec(name)
end end
local first_item = (data.pagenum - 1) * IPP local first_item = (data.pagenum - 1) * IPP
for i = first_item, first_item + IPP - 1 do for i = first_item, first_item + IPP - 1 do
local item = data.items[i + 1] local item = data.items[i + 1]
if not item then break end if not item then break end
@ -896,8 +907,8 @@ else
core.register_craftitem("craftguide:book", { core.register_craftitem("craftguide:book", {
description = S("Crafting Guide"), description = S("Crafting Guide"),
inventory_image = "craftguide_book.png", inventory_image = PNG.book,
wield_image = "craftguide_book.png", wield_image = PNG.book,
stack_max = 1, stack_max = 1,
groups = {book = 1}, groups = {book = 1},
on_use = function(itemstack, user) on_use = function(itemstack, user)
@ -908,9 +919,9 @@ else
core.register_node("craftguide:sign", { core.register_node("craftguide:sign", {
description = S("Crafting Guide Sign"), description = S("Crafting Guide Sign"),
drawtype = "nodebox", drawtype = "nodebox",
tiles = {"craftguide_sign.png"}, tiles = {PNG.sign},
inventory_image = "craftguide_sign.png", inventory_image = PNG.sign,
wield_image = "craftguide_sign.png", wield_image = PNG.sign,
paramtype = "light", paramtype = "light",
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
sunlight_propagates = true, sunlight_propagates = true,
@ -962,7 +973,7 @@ else
sfinv_buttons.register_button("craftguide", { sfinv_buttons.register_button("craftguide", {
title = S("Crafting Guide"), 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, cooking recipes and fuels"),
image = "craftguide_book.png", image = PNG.book,
action = function(player) action = function(player)
on_use(player) on_use(player)
end, end,
@ -1197,7 +1208,7 @@ if progressive_mode then
position = {x = 0.78, y = 1}, position = {x = 0.78, y = 1},
alignment = {x = 1, y = 1}, alignment = {x = 1, y = 1},
scale = {x = 370, y = 112}, scale = {x = 370, y = 112},
text = "craftguide_bg.png", text = PNG.bg,
}), }),
book = player:hud_add({ book = player:hud_add({
@ -1205,7 +1216,7 @@ if progressive_mode then
position = {x = 0.79, y = 1.02}, position = {x = 0.79, y = 1.02},
alignment = {x = 1, y = 1}, alignment = {x = 1, y = 1},
scale = {x = 4, y = 4}, scale = {x = 4, y = 4},
text = "craftguide_book.png", text = PNG.book,
}), }),
text = player:hud_add({ text = player:hud_add({

@ -3,20 +3,14 @@
Craft Guide=Rezeptbuch Craft Guide=Rezeptbuch
Crafting Guide=Rezeptbuch Crafting Guide=Rezeptbuch
Crafting Guide Sign=Rezepttafel Crafting Guide Sign=Rezepttafel
Search=Suche
Reset=Zurücksetzen
Previous page=Vorherige Seite
Next page=Nächste Seite
Usage @1 of @2=Verwendung @1 von @2 Usage @1 of @2=Verwendung @1 von @2
Recipe @1 of @2=Rezept @1 von @2 Recipe @1 of @2=Rezept @1 von @2
Burning time: @1=Brennzeit: @1 Burning time: @1=Brennzeit: @1
Cooking time: @1=Kochzeit: @1 Cooking time: @1=Kochzeit: @1
Any item belonging to the group(s): @1=Beliebiger Gegenstand aus Gruppe(n): @1 Any item belonging to the group(s): @1=Beliebiger Gegenstand aus Gruppe(n): @1
Recipe is too big to be displayed (@1x@2)=Rezept ist zu groß für die Anzeige (@1×@2) Recipe's too big to be displayed (@1x@2)=Rezept ist zu groß für die Anzeige (@1×@2)
Shapeless=Formlos Shapeless=Formlos
Cooking=Kochen Cooking=Kochen
Increase window size=Fenster vergrößern
Decrease window size=Fenster verkleinern
No item to show=Nichts anzuzeigen No item to show=Nichts anzuzeigen
Collect items to reveal more recipes=Gegenstände aufsammeln, um mehr Rezepte aufzudecken Collect items to reveal more recipes=Gegenstände aufsammeln, um mehr Rezepte aufzudecken
Show recipe(s) of the pointed node=Rezept(e) des gezeigten Blocks anzeigen Show recipe(s) of the pointed node=Rezept(e) des gezeigten Blocks anzeigen

@ -2,20 +2,14 @@
Craft Guide=Guide de recettes Craft Guide=Guide de recettes
Crafting Guide=Guide de recettes Crafting Guide=Guide de recettes
Search=Rechercher
Reset=Réinitialiser
Previous page=Page précédente
Next page=Page suivante
Usage @1 of @2=Usage @1 de @2 Usage @1 of @2=Usage @1 de @2
Recipe @1 of @2=Recette @1 de @2 Recipe @1 of @2=Recette @1 de @2
Burning time: @1=Temps de combustion : @1 Burning time: @1=Temps de combustion : @1
Cooking time: @1=Temps de cuisson : @1 Cooking time: @1=Temps de cuisson : @1
Any item belonging to the group(s): @1=Tout item appartenant au(x) groupe(s) : @1 Any item belonging to the group(s): @1=Tout item appartenant au(x) groupe(s) : @1
Recipe is too big to be displayed (@1x@2)=La recette est trop grande pour être affichée (@1x@2) Recipe's too big to be displayed (@1x@2)=La recette est trop grande pour être affichée (@1x@2)
Shapeless=Sans forme Shapeless=Sans forme
Cooking=Cuisson Cooking=Cuisson
Increase window size=Agrandir la fenêtre
Decrease window size=Réduire la fenêtre
No item to show=Aucun item à afficher No item to show=Aucun item à afficher
Collect items to reveal more recipes=Collecte des items pour révéler plus de recettes Collect items to reveal more recipes=Collecte des items pour révéler plus de recettes
Show recipe(s) of the pointed node=Affiche les recettes du bloc visé Show recipe(s) of the pointed node=Affiche les recettes du bloc visé

@ -3,20 +3,14 @@
Craft Guide=книга рецептов крафта Craft Guide=книга рецептов крафта
Crafting Guide=книга рецептов крафта Crafting Guide=книга рецептов крафта
Crafting Guide Sign=Знак с книгой рецептов Crafting Guide Sign=Знак с книгой рецептов
Search=Поиск
Reset=Сброс
Previous page=Предыдущая страница
Next page=Следущая страница
Usage @1 of @2=использование @1 из @2 Usage @1 of @2=использование @1 из @2
Recipe @1 of @2=Рецепт @1 из @2 Recipe @1 of @2=Рецепт @1 из @2
Burning time: @1=Время горения: @1 Burning time: @1=Время горения: @1
Cooking time: @1=Время преготовления: @1 Cooking time: @1=Время преготовления: @1
Any item belonging to the group(s): @1=Любой элемент из группы: @1 Any item belonging to the group(s): @1=Любой элемент из группы: @1
Recipe is too big to be displayed (@1x@2)=Рецепт слишком большой для показа (@1x@2) Recipe's too big to be displayed (@1x@2)=Рецепт слишком большой для показа (@1x@2)
Shapeless=Бесформенный Shapeless=Бесформенный
Cooking=Приготовление Cooking=Приготовление
Increase window size=Увеличить окно
Decrease window size=Уменьшить окно
No item to show=Нет элемента для показа No item to show=Нет элемента для показа
Collect items to reveal more recipes=Собирайте предметы, чтобы раскрыть больше рецептов Collect items to reveal more recipes=Собирайте предметы, чтобы раскрыть больше рецептов
Show recipe(s) of the pointed node=Показать рецепт(ы) выбранной ноды Show recipe(s) of the pointed node=Показать рецепт(ы) выбранной ноды

@ -3,20 +3,14 @@
Craft Guide= Craft Guide=
Crafting Guide= Crafting Guide=
Crafting Guide Sign= Crafting Guide Sign=
Search=
Reset=
Previous page=
Next page=
Usage @1 of @2= Usage @1 of @2=
Recipe @1 of @2= Recipe @1 of @2=
Burning time: @1= Burning time: @1=
Cooking time: @1= Cooking time: @1=
Any item belonging to the group(s): @1= Any item belonging to the group(s): @1=
Recipe is too big to be displayed (@1x@2)= Recipe's too big to be displayed (@1x@2)=
Shapeless= Shapeless=
Cooking= Cooking=
Increase window size=
Decrease window size=
No item to show= No item to show=
Collect items to reveal more recipes= Collect items to reveal more recipes=
Show recipe(s) of the pointed node= Show recipe(s) of the pointed node=