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

Commit 6b76c8c

Browse files
committed
API to set a custom background
1 parent 5f68d2d commit 6b76c8c

15 files changed

+60
-83
lines changed

API.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,12 @@ You can add a stereotype like so:
151151
```Lua
152152
craftguide.group_stereotypes.radioactive = "mod:item"
153153
```
154+
155+
#### `craftguide.background`
156+
157+
You can set a custom background theme by overriding this variable:
158+
159+
```Lua
160+
craftguide.background = "my_custom_bg.png"
161+
162+
```

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ Use the command `/craft` to show the recipe(s) of the pointed node.
1717
For developers, `craftguide` also has a [modding API](https://github.com/minetest-mods/craftguide/blob/master/API.md).
1818

1919

20-
![Preview2](https://i.imgur.com/ZxGNxrK.png)
20+
![Preview2](https://i.imgur.com/oGSvbTW.png)

init.lua

Lines changed: 50 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
craftguide = {}
22

3+
craftguide.background = "craftguide_bg_full.png"
4+
35
local pdata = {}
46
local core = core
57

@@ -443,15 +445,11 @@ local function get_recipe_fs(data)
443445
fs[#fs + 1] = fmt(FMT.button,
444446
xoffset + (sfinv_only and 1.98 or 2.7),
445447
yoffset + (sfinv_only and 1.9 or 1.2),
446-
2.2,
447-
1,
448-
"alternate",
449-
btn_lab)
448+
2.2, 1, "alternate", btn_lab)
450449

451450
if width > GRID_LIMIT or rows > GRID_LIMIT then
452451
fs[#fs + 1] = fmt(FMT.label,
453-
sfinv_only and 2 or 3,
454-
7,
452+
sfinv_only and 2 or 3, 7,
455453
ESC(S("Recipe is too big to be displayed (@1x@2)", width, rows)))
456454

457455
return concat(fs)
@@ -491,13 +489,8 @@ local function get_recipe_fs(data)
491489
local label = groups and "\nG" or ""
492490

493491
fs[#fs + 1] = fmt(FMT.item_image_button,
494-
X,
495-
Y + (sfinv_only and 0.7 or 0),
496-
btn_size,
497-
btn_size,
498-
item,
499-
match(item, "%S*"),
500-
ESC(label))
492+
X, Y + (sfinv_only and 0.7 or 0),
493+
btn_size, btn_size, item, match(item, "%S*"), ESC(label))
501494

502495
local burntime = fuel_cache[item]
503496

@@ -519,69 +512,44 @@ local function get_recipe_fs(data)
519512
local pos_y = yoffset + (sfinv_only and 0.25 or -0.45)
520513

521514
fs[#fs + 1] = fmt(FMT.image,
522-
min(3.9, rightest) + 1.2,
523-
pos_y,
524-
0.5,
525-
0.5,
526-
icon)
515+
min(3.9, rightest) + 1.2, pos_y, 0.5, 0.5, icon)
527516

528517
local tooltip = custom_recipe and custom_recipe.description or
529518
shapeless and S("Shapeless") or S("Cooking")
530519

531520
fs[#fs + 1] = fmt("tooltip[%f,%f;%f,%f;%s]",
532-
rightest + 1.2,
533-
pos_y,
534-
0.5,
535-
0.5,
536-
ESC(tooltip))
521+
rightest + 1.2, pos_y, 0.5, 0.5, ESC(tooltip))
537522
end
538523

539524
local arrow_X = rightest + (s_btn_size or 1.1)
540525
local output_X = arrow_X + 0.9
541526

542527
fs[#fs + 1] = fmt(FMT.image,
543-
arrow_X,
544-
yoffset + (sfinv_only and 0.9 or 0.2),
545-
0.9,
546-
0.7,
547-
"craftguide_arrow.png")
528+
arrow_X, yoffset + (sfinv_only and 0.9 or 0.2),
529+
0.9, 0.7, "craftguide_arrow.png")
548530

549531
if recipe.type == "fuel" then
550532
fs[#fs + 1] = fmt(FMT.image,
551-
output_X,
552-
yoffset + (sfinv_only and 0.7 or 0),
553-
1.1,
554-
1.1,
555-
"craftguide_fire.png")
533+
output_X, yoffset + (sfinv_only and 0.7 or 0),
534+
1.1, 1.1, "craftguide_fire.png")
556535
else
557536
local output_name = match(recipe.output, "%S+")
558537
local burntime = fuel_cache[output_name]
559538

560539
fs[#fs + 1] = fmt(FMT.item_image_button,
561-
output_X,
562-
yoffset + (sfinv_only and 0.7 or 0),
563-
1.1,
564-
1.1,
565-
recipe.output,
566-
ESC(output_name),
567-
"")
540+
output_X, yoffset + (sfinv_only and 0.7 or 0),
541+
1.1, 1.1, recipe.output, ESC(output_name), "")
568542

569543
if burntime then
570544
fs[#fs + 1] = get_tooltip(output_name, nil, nil, burntime)
571545

572546
fs[#fs + 1] = fmt(FMT.image,
573-
output_X + 1,
574-
yoffset + (sfinv_only and 0.7 or 0.1),
575-
0.6,
576-
0.4,
577-
"craftguide_arrow.png")
547+
output_X + 1, yoffset + (sfinv_only and 0.7 or 0.1),
548+
0.6, 0.4, "craftguide_arrow.png")
578549

579550
fs[#fs + 1] = fmt(FMT.image,
580-
output_X + 1.6,
581-
yoffset + (sfinv_only and 0.55 or 0),
582-
0.6,
583-
0.6,
584-
"craftguide_fire.png")
551+
output_X + 1.6, yoffset + (sfinv_only and 0.55 or 0),
552+
0.6, 0.6, "craftguide_fire.png")
585553
end
586554
end
587555

@@ -595,41 +563,44 @@ local function make_formspec(name)
595563
local fs = {}
596564

597565
if not sfinv_only then
598-
fs[#fs + 1] = fmt("size[%f,%f;]", 9.5, 8.4)
599-
600-
fs[#fs + 1] = [[
566+
fs[#fs + 1] = fmt([[
567+
size[%f,%f;]
601568
no_prepend[]
602569
bgcolor[#00000000;false]
603-
background[1,1;1,1;craftguide_bg_full.png;true;10]
604-
]]
570+
background[1,1;1,1;%s;true;10]
571+
]],
572+
9.5, 8.4, craftguide.background)
605573
end
606574

607-
fs[#fs + 1] = fmt("field[0.25,0.2;%f,1;filter;;%s]",
608-
sfinv_only and 2.76 or 2.72,
609-
ESC(data.filter))
575+
fs[#fs + 1] = fmt([[
576+
field[0.25,0.2;%f,1;filter;;%s]
577+
field_close_on_enter[filter;false]
578+
]],
579+
sfinv_only and 2.76 or 2.72, ESC(data.filter))
580+
581+
local search_icon = "craftguide_search_icon.png"
582+
local clear_icon = "craftguide_clear_icon.png"
610583

611-
fs[#fs + 1] = fmt(
612-
"field_close_on_enter[filter;false]\
613-
image_button[%f,-0.05;0.85,0.85;craftguide_search_icon.png;search;;;false;" ..
614-
"craftguide_search_icon.png^\\[colorize:yellow:255]" ..
615-
"image_button[%f,-0.05;0.85,0.85;craftguide_clear_icon.png;clear;;;false;" ..
616-
"craftguide_clear_icon.png^\\[colorize:red:255]",
617-
sfinv_only and 2.6 or 2.54,
618-
sfinv_only and 3.3 or 3.25)
584+
fs[#fs + 1] = fmt([[
585+
image_button[%f,-0.05;0.85,0.85;%s;search;;;false;%s^\[colorize:yellow:255]
586+
image_button[%f,-0.05;0.85,0.85;%s;clear;;;false;%s^\[colorize:red:255]
587+
]],
588+
sfinv_only and 2.6 or 2.54, search_icon, search_icon,
589+
sfinv_only and 3.3 or 3.25, clear_icon, clear_icon)
619590

620591
fs[#fs + 1] = fmt("label[%f,%f;%s / %u]",
621-
sfinv_only and 6.35 or 7.85,
622-
0.06,
623-
colorize("yellow", data.pagenum),
624-
data.pagemax)
625-
626-
fs[#fs + 1] = fmt(
627-
"image_button[%f,-0.05;0.8,0.8;craftguide_prev_icon.png;prev;;;false;" ..
628-
"craftguide_prev_icon.png^\\[colorize:yellow:255]" ..
629-
"image_button[%f,-0.05;0.8,0.8;craftguide_next_icon.png;next;;;false;" ..
630-
"craftguide_next_icon.png^\\[colorize:yellow:255]",
631-
sfinv_only and 5.45 or 6.83,
632-
sfinv_only and 7.2 or 8.75)
592+
sfinv_only and 6.35 or 7.85, 0.06,
593+
colorize("yellow", data.pagenum), data.pagemax)
594+
595+
local prev_icon = "craftguide_next_icon.png^\\[transformFX"
596+
local next_icon = "craftguide_next_icon.png"
597+
598+
fs[#fs + 1] = fmt([[
599+
image_button[%f,-0.05;0.8,0.8;%s;prev;;;false;%s^\[colorize:yellow:255]
600+
image_button[%f,-0.05;0.8,0.8;%s;next;;;false;%s^\[colorize:yellow:255]
601+
]],
602+
sfinv_only and 5.45 or 6.83, prev_icon, prev_icon,
603+
sfinv_only and 7.2 or 8.75, next_icon, next_icon)
633604

634605
if #data.items == 0 then
635606
local no_item = S("No item to show")
@@ -654,10 +625,7 @@ local function make_formspec(name)
654625
fs[#fs + 1] = fmt("item_image_button[%f,%f;%f,%f;%s;%s_inv;]",
655626
X - (X * (sfinv_only and 0.12 or 0.14)) - 0.05,
656627
Y - (Y * 0.1) - 0.1,
657-
1,
658-
1,
659-
item,
660-
item)
628+
1, 1, item, item)
661629
end
662630

663631
if data.recipes and #data.recipes > 0 then

textures/craftguide_arrow.png

103 Bytes
Loading

textures/craftguide_bg_full.png

171 Bytes
Loading

textures/craftguide_book.png

2.83 KB
Loading

textures/craftguide_clear_icon.png

185 Bytes
Loading

textures/craftguide_fire.png

2.81 KB
Loading

textures/craftguide_furnace.png

2.86 KB
Loading

textures/craftguide_next_icon.png

209 Bytes
Loading

textures/craftguide_prev_icon.png

-523 Bytes
Binary file not shown.

textures/craftguide_search_icon.png

857 Bytes
Loading

textures/craftguide_shapeless.png

150 Bytes
Loading

textures/craftguide_sign.png

268 Bytes
Loading

textures/craftguide_sign_inv.png

157 Bytes
Loading

0 commit comments

Comments
 (0)