Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Commit 3b3da66

Browse files
committed
Improve tooltip for toolrepair
1 parent 84795a6 commit 3b3da66

File tree

3 files changed

+35
-38
lines changed

3 files changed

+35
-38
lines changed

init.lua

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ local sfinv_only = core.settings:get_bool("craftguide_sfinv_only") and rawget(_G
1515

1616
local log = core.log
1717
local after = core.after
18-
local clrz = core.colorize
18+
local clr = core.colorize
1919
local reg_tools = core.registered_tools
2020
local reg_items = core.registered_items
2121
local show_formspec = core.show_formspec
@@ -418,55 +418,48 @@ local function groups_to_items(groups, get_all)
418418
return names
419419
end
420420

421-
local function not_repairable(tool)
421+
local function repairable(tool)
422422
local def = reg_tools[tool]
423-
return toolrepair and def and def.groups and def.groups.disable_repair == 1
423+
return toolrepair and def and def.groups and def.groups.disable_repair ~= 1
424424
end
425425

426426
local function get_tooltip(item, info)
427-
local tooltip
428-
429-
local function add(str)
430-
return tooltip .. "\n" .. str
431-
end
432-
433427
local function get_desc(def, name)
434428
name = name or item
435429
return def and def.description or
436430
(def and match(name, ":.*"):gsub("%W%l", upper):sub(2):gsub("_", " ") or
437431
S("Unknown Item (@1)", name))
438432
end
439433

434+
local tooltip = get_desc(reg_items[item])
435+
436+
local function add(str)
437+
return tooltip .. "\n" .. str
438+
end
439+
440440
if info.groups then
441441
local groupstr, c = {}, 0
442442

443443
for i = 1, #info.groups do
444444
c = c + 1
445-
groupstr[c] = clrz("yellow", info.groups[i])
445+
groupstr[c] = clr("yellow", info.groups[i])
446446
end
447447

448448
groupstr = concat(groupstr, ", ")
449449
tooltip = S("Any item belonging to the group(s): @1", groupstr)
450-
else
451-
local def = reg_items[item]
452-
tooltip = get_desc(def)
453-
454-
if info.norepair then
455-
tooltip = add(S("This tool cannot be repaired"))
456-
end
457450
end
458451

459452
if info.cooktime then
460-
tooltip = add(S("Cooking time: @1", clrz("yellow", info.cooktime)))
453+
tooltip = add(S("Cooking time: @1", clr("yellow", info.cooktime)))
461454
end
462455

463456
if info.burntime then
464-
tooltip = add(S("Burning time: @1", clrz("yellow", info.burntime)))
457+
tooltip = add(S("Burning time: @1", clr("yellow", info.burntime)))
465458
end
466459

467460
if info.replace then
468461
local def = reg_items[info.replace]
469-
local desc = clrz("yellow", get_desc(def, info.replace))
462+
local desc = clr("yellow", get_desc(def, info.replace))
470463

471464
if info.cooktime then
472465
tooltip = add(S("Replaced by @1 on smelting", desc))
@@ -477,6 +470,10 @@ local function get_tooltip(item, info)
477470
end
478471
end
479472

473+
if info.repair then
474+
tooltip = add(S("Repairable by step of @1", clr("yellow", toolrepair .. "%")))
475+
end
476+
480477
return fmt("tooltip[%s;%s]", item, ESC(tooltip))
481478
end
482479

@@ -523,23 +520,23 @@ local function get_output_fs(fs, L)
523520
output_X, YOFFSET + (sfinv_only and 0.7 or 0),
524521
1.1, 1.1, item, ESC(name), "")
525522

526-
local norepair = not_repairable(item)
523+
local repair = repairable(item)
527524

528-
if burntime or norepair then
525+
if burntime or repair then
529526
fs[#fs + 1] = get_tooltip(name, {
530527
burntime = burntime,
531-
norepair = norepair,
528+
repair = repair,
532529
})
530+
end
533531

534-
if burntime then
535-
fs[#fs + 1] = fmt(FMT.image,
536-
output_X + 1, YOFFSET + (sfinv_only and 0.7 or 0.1),
537-
0.6, 0.4, PNG.arrow)
532+
if burntime then
533+
fs[#fs + 1] = fmt(FMT.image,
534+
output_X + 1, YOFFSET + (sfinv_only and 0.7 or 0.1),
535+
0.6, 0.4, PNG.arrow)
538536

539-
fs[#fs + 1] = fmt(FMT.image,
540-
output_X + 1.6, YOFFSET + (sfinv_only and 0.55 or 0),
541-
0.6, 0.6, PNG.fire)
542-
end
537+
fs[#fs + 1] = fmt(FMT.image,
538+
output_X + 1.6, YOFFSET + (sfinv_only and 0.55 or 0),
539+
0.6, 0.6, PNG.fire)
543540
end
544541
end
545542
end
@@ -635,7 +632,7 @@ local function get_recipe_fs(data, fs)
635632
burntime = burntime,
636633
cooktime = cooktime,
637634
replace = replace,
638-
norepair = nil,
635+
repair = nil,
639636
}
640637

641638
for _, v in pairs(infos) do
@@ -694,7 +691,7 @@ local function make_formspec(name)
694691

695692
fs[#fs + 1] = fmt("label[%f,%f;%s / %u]",
696693
sfinv_only and 6.35 or 7.85, 0.06,
697-
clrz("yellow", data.pagenum), data.pagemax)
694+
clr("yellow", data.pagenum), data.pagemax)
698695

699696
fs[#fs + 1] = fmt([[
700697
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)
855852
old_register_craft(recipe)
856853

857854
if recipe.type == "toolrepair" then
858-
toolrepair = recipe.additional_wear ~= 0
855+
toolrepair = recipe.additional_wear * -100
859856
end
860857

861858
local output = recipe.output or
@@ -1433,7 +1430,7 @@ register_command("craft", {
14331430
end
14341431
end
14351432

1436-
local red = clrz("red", "[craftguide] ")
1433+
local red = clr("red", "[craftguide] ")
14371434

14381435
if not node_name then
14391436
return false, red .. S("No node pointed")
@@ -1450,7 +1447,7 @@ register_command("craft", {
14501447
end
14511448

14521449
if not recipes or #recipes == 0 then
1453-
local ylw = clrz("yellow", node_name)
1450+
local ylw = clr("yellow", node_name)
14541451
local msg = red .. "%s: " .. ylw
14551452

14561453
if usages then

locale/craftguide.fr.tr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Cooking time: @1=Temps de cuisson : @1
99
Replaced by @1 on smelting=Remplacé par @1 lors de la cuisson
1010
Replaced by @1 on burning=Remplacé par @1 lors de la combustion
1111
Replaced by @1 on crafting=Remplacé par @1 lors de la fabrication
12-
This tool cannot be repaired=Cet outil ne peut être réparé
12+
Repairable by step of @1=Réparable par étape de @1
1313
Any item belonging to the group(s): @1=Tout item appartenant au(x) groupe(s) : @1
1414
Recipe's too big to be displayed (@1x@2)=La recette est trop grande pour être affichée (@1x@2)
1515
Shapeless=Sans forme

locale/template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Cooking time: @1=
1010
Replaced by @1 on smelting=
1111
Replaced by @1 on burning=
1212
Replaced by @1 on crafting=
13-
This tool cannot be repaired=
13+
Repairable by step of @1=
1414
Any item belonging to the group(s): @1=
1515
Recipe's too big to be displayed (@1x@2)=
1616
Shapeless=

0 commit comments

Comments
 (0)