Improve tooltip for toolrepair

This commit is contained in:
Jean-Patrick Guerrero 2019-09-10 13:41:17 +02:00
parent 84795a6523
commit 3b3da66a0d
3 changed files with 35 additions and 38 deletions

@ -15,7 +15,7 @@ local sfinv_only = core.settings:get_bool("craftguide_sfinv_only") and rawget(_G
local log = core.log local log = core.log
local after = core.after local after = core.after
local clrz = core.colorize local clr = core.colorize
local reg_tools = core.registered_tools local reg_tools = core.registered_tools
local reg_items = core.registered_items local reg_items = core.registered_items
local show_formspec = core.show_formspec local show_formspec = core.show_formspec
@ -418,18 +418,12 @@ local function groups_to_items(groups, get_all)
return names return names
end end
local function not_repairable(tool) local function repairable(tool)
local def = reg_tools[tool] local def = reg_tools[tool]
return toolrepair and def and def.groups and def.groups.disable_repair == 1 return toolrepair and def and def.groups and def.groups.disable_repair ~= 1
end end
local function get_tooltip(item, info) local function get_tooltip(item, info)
local tooltip
local function add(str)
return tooltip .. "\n" .. str
end
local function get_desc(def, name) local function get_desc(def, name)
name = name or item name = name or item
return def and def.description or return def and def.description or
@ -437,36 +431,35 @@ local function get_tooltip(item, info)
S("Unknown Item (@1)", name)) S("Unknown Item (@1)", name))
end end
local tooltip = get_desc(reg_items[item])
local function add(str)
return tooltip .. "\n" .. str
end
if info.groups then if info.groups then
local groupstr, c = {}, 0 local groupstr, c = {}, 0
for i = 1, #info.groups do for i = 1, #info.groups do
c = c + 1 c = c + 1
groupstr[c] = clrz("yellow", info.groups[i]) groupstr[c] = clr("yellow", info.groups[i])
end end
groupstr = concat(groupstr, ", ") groupstr = concat(groupstr, ", ")
tooltip = S("Any item belonging to the group(s): @1", groupstr) tooltip = S("Any item belonging to the group(s): @1", groupstr)
else
local def = reg_items[item]
tooltip = get_desc(def)
if info.norepair then
tooltip = add(S("This tool cannot be repaired"))
end
end end
if info.cooktime then if info.cooktime then
tooltip = add(S("Cooking time: @1", clrz("yellow", info.cooktime))) tooltip = add(S("Cooking time: @1", clr("yellow", info.cooktime)))
end end
if info.burntime then if info.burntime then
tooltip = add(S("Burning time: @1", clrz("yellow", info.burntime))) tooltip = add(S("Burning time: @1", clr("yellow", info.burntime)))
end end
if info.replace then if info.replace then
local def = reg_items[info.replace] local def = reg_items[info.replace]
local desc = clrz("yellow", get_desc(def, info.replace)) local desc = clr("yellow", get_desc(def, info.replace))
if info.cooktime then if info.cooktime then
tooltip = add(S("Replaced by @1 on smelting", desc)) tooltip = add(S("Replaced by @1 on smelting", desc))
@ -477,6 +470,10 @@ local function get_tooltip(item, info)
end end
end end
if info.repair then
tooltip = add(S("Repairable by step of @1", clr("yellow", toolrepair .. "%")))
end
return fmt("tooltip[%s;%s]", item, ESC(tooltip)) return fmt("tooltip[%s;%s]", item, ESC(tooltip))
end end
@ -523,13 +520,14 @@ local function get_output_fs(fs, L)
output_X, YOFFSET + (sfinv_only and 0.7 or 0), output_X, YOFFSET + (sfinv_only and 0.7 or 0),
1.1, 1.1, item, ESC(name), "") 1.1, 1.1, item, ESC(name), "")
local norepair = not_repairable(item) local repair = repairable(item)
if burntime or norepair then if burntime or repair then
fs[#fs + 1] = get_tooltip(name, { fs[#fs + 1] = get_tooltip(name, {
burntime = burntime, burntime = burntime,
norepair = norepair, repair = repair,
}) })
end
if burntime then if burntime then
fs[#fs + 1] = fmt(FMT.image, fs[#fs + 1] = fmt(FMT.image,
@ -541,7 +539,6 @@ local function get_output_fs(fs, L)
0.6, 0.6, PNG.fire) 0.6, 0.6, PNG.fire)
end end
end end
end
end end
local function get_recipe_fs(data, fs) local function get_recipe_fs(data, fs)
@ -635,7 +632,7 @@ local function get_recipe_fs(data, fs)
burntime = burntime, burntime = burntime,
cooktime = cooktime, cooktime = cooktime,
replace = replace, replace = replace,
norepair = nil, repair = nil,
} }
for _, v in pairs(infos) do for _, v in pairs(infos) do
@ -694,7 +691,7 @@ local function make_formspec(name)
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,
clrz("yellow", data.pagenum), data.pagemax) clr("yellow", data.pagenum), data.pagemax)
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]
@ -855,7 +852,7 @@ core.register_craft = function(recipe)
old_register_craft(recipe) old_register_craft(recipe)
if recipe.type == "toolrepair" then if recipe.type == "toolrepair" then
toolrepair = recipe.additional_wear ~= 0 toolrepair = recipe.additional_wear * -100
end end
local output = recipe.output or local output = recipe.output or
@ -1433,7 +1430,7 @@ register_command("craft", {
end end
end end
local red = clrz("red", "[craftguide] ") local red = clr("red", "[craftguide] ")
if not node_name then if not node_name then
return false, red .. S("No node pointed") return false, red .. S("No node pointed")
@ -1450,7 +1447,7 @@ register_command("craft", {
end end
if not recipes or #recipes == 0 then if not recipes or #recipes == 0 then
local ylw = clrz("yellow", node_name) local ylw = clr("yellow", node_name)
local msg = red .. "%s: " .. ylw local msg = red .. "%s: " .. ylw
if usages then if usages then

@ -9,7 +9,7 @@ Cooking time: @1=Temps de cuisson : @1
Replaced by @1 on smelting=Remplacé par @1 lors de la cuisson Replaced by @1 on smelting=Remplacé par @1 lors de la cuisson
Replaced by @1 on burning=Remplacé par @1 lors de la combustion Replaced by @1 on burning=Remplacé par @1 lors de la combustion
Replaced by @1 on crafting=Remplacé par @1 lors de la fabrication Replaced by @1 on crafting=Remplacé par @1 lors de la fabrication
This tool cannot be repaired=Cet outil ne peut être réparé Repairable by step of @1=Réparable par étape de @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's 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

@ -10,7 +10,7 @@ Cooking time: @1=
Replaced by @1 on smelting= Replaced by @1 on smelting=
Replaced by @1 on burning= Replaced by @1 on burning=
Replaced by @1 on crafting= Replaced by @1 on crafting=
This tool cannot be repaired= Repairable by step of @1=
Any item belonging to the group(s): @1= Any item belonging to the group(s): @1=
Recipe's too big to be displayed (@1x@2)= Recipe's too big to be displayed (@1x@2)=
Shapeless= Shapeless=