mirror of
https://github.com/minetest-mods/craftguide.git
synced 2025-07-04 00:50:55 +02:00
Compare commits
7 Commits
redesign
...
4ff1fd15b8
Author | SHA1 | Date | |
---|---|---|---|
4ff1fd15b8 | |||
35021a6f0b | |||
7ef62f4f8b | |||
f075e67be9 | |||
cd17b8d38e | |||
46cb7615bf | |||
679e005f58 |
164
init.lua
164
init.lua
@ -7,7 +7,6 @@ local searches = {}
|
|||||||
local recipes_cache = {}
|
local recipes_cache = {}
|
||||||
local usages_cache = {}
|
local usages_cache = {}
|
||||||
local fuel_cache = {}
|
local fuel_cache = {}
|
||||||
|
|
||||||
local toolrepair
|
local toolrepair
|
||||||
|
|
||||||
local progressive_mode = core.settings:get_bool "craftguide_progressive_mode"
|
local progressive_mode = core.settings:get_bool "craftguide_progressive_mode"
|
||||||
@ -16,6 +15,7 @@ local autocache = core.settings:get_bool "craftguide_autocache"
|
|||||||
|
|
||||||
local http = core.request_http_api()
|
local http = core.request_http_api()
|
||||||
local storage = core.get_mod_storage()
|
local storage = core.get_mod_storage()
|
||||||
|
local singleplayer = core.is_singleplayer()
|
||||||
|
|
||||||
local reg_items = core.registered_items
|
local reg_items = core.registered_items
|
||||||
local reg_tools = core.registered_tools
|
local reg_tools = core.registered_tools
|
||||||
@ -111,6 +111,20 @@ local function get_fs_version(name)
|
|||||||
return info and info.formspec_version or 1
|
return info and info.formspec_version or 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function outdated(name)
|
||||||
|
local fs = fmt([[
|
||||||
|
size[6.6,1.3]
|
||||||
|
image[0,0;1,1;%s]
|
||||||
|
label[1,0;%s]
|
||||||
|
button_exit[2.8,0.8;1,1;;OK]
|
||||||
|
]],
|
||||||
|
PNG.book,
|
||||||
|
"Your Minetest client is outdated.\n" ..
|
||||||
|
"Get the latest version on minetest.net to use the Crafting Guide.")
|
||||||
|
|
||||||
|
return show_formspec(name, "craftguide", fs)
|
||||||
|
end
|
||||||
|
|
||||||
local function mul_elem(elem, n)
|
local function mul_elem(elem, n)
|
||||||
local fstr, elems = "", {}
|
local fstr, elems = "", {}
|
||||||
|
|
||||||
@ -697,6 +711,10 @@ local function is_fav(data)
|
|||||||
return fav, i
|
return fav, i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function check_newline(def)
|
||||||
|
return def and def.description and find(def.description, "\n")
|
||||||
|
end
|
||||||
|
|
||||||
local function get_desc(name)
|
local function get_desc(name)
|
||||||
if sub(name, 1, 1) == "_" then
|
if sub(name, 1, 1) == "_" then
|
||||||
name = sub(name, 2)
|
name = sub(name, 2)
|
||||||
@ -814,11 +832,15 @@ local function get_output_fs(data, fs, L)
|
|||||||
fs[#fs + 1] = fmt("item_image_button[%f,%f;%f,%f;%s;%s;%s]",
|
fs[#fs + 1] = fmt("item_image_button[%f,%f;%f,%f;%s;%s;%s]",
|
||||||
output_X, Y, 1.1, 1.1, item, _name, "")
|
output_X, Y, 1.1, 1.1, item, _name, "")
|
||||||
|
|
||||||
|
|
||||||
|
local def = reg_items[name]
|
||||||
|
|
||||||
local infos = {
|
local infos = {
|
||||||
unknown = not reg_items[name] or nil,
|
unknown = not def or nil,
|
||||||
burntime = fuel_cache[name],
|
burntime = fuel_cache[name],
|
||||||
repair = repairable(name),
|
repair = repairable(name),
|
||||||
rarity = L.rarity,
|
rarity = L.rarity,
|
||||||
|
newline = check_newline(def),
|
||||||
}
|
}
|
||||||
|
|
||||||
if next(infos) then
|
if next(infos) then
|
||||||
@ -887,9 +909,9 @@ local function get_grid_fs(data, fs, rcp, spacing)
|
|||||||
_btn_size = btn_size
|
_btn_size = btn_size
|
||||||
|
|
||||||
X = (btn_size * ((i - 1) % width) + XOFFSET -
|
X = (btn_size * ((i - 1) % width) + XOFFSET -
|
||||||
(sfinv_only and 2.83 or 0.5)) * (0.83 - (x_y / 5))
|
(sfinv_only and 2.83 or 0)) * (0.83 - (x_y / 5))
|
||||||
Y = (btn_size * floor((i - 1) / width) +
|
Y = (btn_size * floor((i - 1) / width) +
|
||||||
(sfinv_only and 5.81 or 5.5) + x_y) * (0.86 - (x_y / 5))
|
(sfinv_only and 5.81 or 3.92) + x_y) * (0.86 - (x_y / 5))
|
||||||
end
|
end
|
||||||
|
|
||||||
if X > rightest then
|
if X > rightest then
|
||||||
@ -925,12 +947,15 @@ local function get_grid_fs(data, fs, rcp, spacing)
|
|||||||
fs[#fs + 1] = fmt(FMT.item_image_button,
|
fs[#fs + 1] = fmt(FMT.item_image_button,
|
||||||
X, Y, btn_size, btn_size, item, item, label)
|
X, Y, btn_size, btn_size, item, item, label)
|
||||||
|
|
||||||
|
local def = reg_items[name]
|
||||||
|
|
||||||
local infos = {
|
local infos = {
|
||||||
unknown = not reg_items[name] or nil,
|
unknown = not def or nil,
|
||||||
groups = groups,
|
groups = groups,
|
||||||
burntime = fuel_cache[name],
|
burntime = fuel_cache[name],
|
||||||
cooktime = cooktime,
|
cooktime = cooktime,
|
||||||
replace = replace,
|
replace = replace,
|
||||||
|
newline = check_newline(def),
|
||||||
}
|
}
|
||||||
|
|
||||||
if next(infos) then
|
if next(infos) then
|
||||||
@ -1098,6 +1123,7 @@ local function make_fs(data)
|
|||||||
style[clear;fgimg=%s;fgimg_hovered=%s]
|
style[clear;fgimg=%s;fgimg_hovered=%s]
|
||||||
style[prev_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
|
style[prev_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
|
||||||
style[next_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
|
style[next_page;fgimg=%s;fgimg_hovered=%s;fgimg_pressed=%s]
|
||||||
|
style[pagenum;border=false]
|
||||||
]],
|
]],
|
||||||
PNG.selected, PNG.selected,
|
PNG.selected, PNG.selected,
|
||||||
PNG.search, PNG.search_hover,
|
PNG.search, PNG.search_hover,
|
||||||
@ -1113,9 +1139,9 @@ local function make_fs(data)
|
|||||||
|
|
||||||
data.pagemax = max(1, ceil(#data.items / IPP))
|
data.pagemax = max(1, ceil(#data.items / IPP))
|
||||||
|
|
||||||
fs[#fs + 1] = fmt("label[%f,%f;%s / %u]",
|
fs[#fs + 1] = fmt(FMT.button,
|
||||||
sfinv_only and 6.35 or (9 * 7.85) / 11,
|
sfinv_only and 5.85 or 6, -0.1, sfinv_only and 1.82 or 1.62, 1, "pagenum",
|
||||||
0.06, clr("#ff0", data.pagenum), data.pagemax)
|
fmt("%u / %u", data.pagenum, data.pagemax))
|
||||||
|
|
||||||
if #data.items == 0 then
|
if #data.items == 0 then
|
||||||
local no_item = ES"No item to show"
|
local no_item = ES"No item to show"
|
||||||
@ -1144,8 +1170,7 @@ local function make_fs(data)
|
|||||||
fs[#fs + 1] = fmt(FMT.image, X, Y, 1, 1, PNG.selected)
|
fs[#fs + 1] = fmt(FMT.image, X, Y, 1, 1, PNG.selected)
|
||||||
end
|
end
|
||||||
|
|
||||||
fs[#fs + 1] = fmt("item_image_button[%f,%f;%f,%f;%s;%s_inv;]",
|
fs[#fs + 1] = fmt("item_image_button[%f,%f;1,1;%s;%s_inv;]", X, Y, item, item)
|
||||||
X, Y, 1, 1, item, item)
|
|
||||||
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
|
||||||
@ -1166,12 +1191,12 @@ end
|
|||||||
|
|
||||||
craftguide.register_craft_type("digging", {
|
craftguide.register_craft_type("digging", {
|
||||||
description = ES"Digging",
|
description = ES"Digging",
|
||||||
icon = "default_tool_steelpick.png",
|
icon = "craftguide_steelpick.png",
|
||||||
})
|
})
|
||||||
|
|
||||||
craftguide.register_craft_type("digging_chance", {
|
craftguide.register_craft_type("digging_chance", {
|
||||||
description = ES"Digging Chance",
|
description = ES"Digging Chance",
|
||||||
icon = "default_tool_mesepick.png",
|
icon = "craftguide_mesepick.png",
|
||||||
})
|
})
|
||||||
|
|
||||||
local function search(data)
|
local function search(data)
|
||||||
@ -1549,6 +1574,10 @@ on_mods_loaded(get_init_items)
|
|||||||
on_joinplayer(function(player)
|
on_joinplayer(function(player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
init_data(name)
|
init_data(name)
|
||||||
|
|
||||||
|
if pdata[name].fs_version < FORMSPEC_MINIMAL_VERSION then
|
||||||
|
outdated(name)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function fields(player, _f)
|
local function fields(player, _f)
|
||||||
@ -1653,9 +1682,8 @@ if sfinv_only then
|
|||||||
get = function(self, player, context)
|
get = function(self, player, context)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local data = pdata[name]
|
local data = pdata[name]
|
||||||
local formspec = make_fs(data)
|
|
||||||
|
|
||||||
return sfinv.make_formspec(player, context, formspec)
|
return sfinv.make_formspec(player, context, make_fs(data))
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_enter = function(self, player, context)
|
on_enter = function(self, player, context)
|
||||||
@ -1684,17 +1712,7 @@ else
|
|||||||
local data = pdata[name]
|
local data = pdata[name]
|
||||||
|
|
||||||
if data.fs_version < FORMSPEC_MINIMAL_VERSION then
|
if data.fs_version < FORMSPEC_MINIMAL_VERSION then
|
||||||
local fs = fmt([[
|
return outdated(name)
|
||||||
size[6.6,1.3]
|
|
||||||
image[0,0;1,1;%s]
|
|
||||||
label[1,0;%s]
|
|
||||||
button_exit[2.8,0.8;1,1;;OK]
|
|
||||||
]],
|
|
||||||
PNG.nothing,
|
|
||||||
"Your Minetest client is outdated.\n" ..
|
|
||||||
"Get the latest version on minetest.net to use the Crafting Guide.")
|
|
||||||
|
|
||||||
return show_formspec(name, "craftguide", fs)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if next(recipe_filters) then
|
if next(recipe_filters) then
|
||||||
@ -1725,7 +1743,12 @@ else
|
|||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "wallmounted",
|
paramtype2 = "wallmounted",
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
groups = {choppy = 1, attached_node = 1, oddly_breakable_by_hand = 1, flammable = 3},
|
groups = {
|
||||||
|
choppy = 1,
|
||||||
|
attached_node = 1,
|
||||||
|
oddly_breakable_by_hand = 1,
|
||||||
|
flammable = 3,
|
||||||
|
},
|
||||||
node_box = {
|
node_box = {
|
||||||
type = "wallmounted",
|
type = "wallmounted",
|
||||||
wall_top = {-0.5, 0.4375, -0.5, 0.5, 0.5, 0.5},
|
wall_top = {-0.5, 0.4375, -0.5, 0.5, 0.5, 0.5},
|
||||||
@ -1770,7 +1793,7 @@ else
|
|||||||
if rawget(_G, "sfinv_buttons") then
|
if rawget(_G, "sfinv_buttons") then
|
||||||
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",
|
||||||
image = PNG.book,
|
image = PNG.book,
|
||||||
action = function(player)
|
action = function(player)
|
||||||
on_use(player)
|
on_use(player)
|
||||||
@ -1780,7 +1803,6 @@ else
|
|||||||
end
|
end
|
||||||
|
|
||||||
if progressive_mode then
|
if progressive_mode then
|
||||||
local PLAYERS = {}
|
|
||||||
local POLL_FREQ = 0.25
|
local POLL_FREQ = 0.25
|
||||||
local HUD_TIMER_MAX = 1.5
|
local HUD_TIMER_MAX = 1.5
|
||||||
|
|
||||||
@ -1867,6 +1889,34 @@ if progressive_mode then
|
|||||||
return inv_items
|
return inv_items
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function init_hud(player, data)
|
||||||
|
data.hud = {
|
||||||
|
bg = player:hud_add{
|
||||||
|
hud_elem_type = "image",
|
||||||
|
position = {x = 0.78, y = 1},
|
||||||
|
alignment = {x = 1, y = 1},
|
||||||
|
scale = {x = 370, y = 112},
|
||||||
|
text = PNG.bg,
|
||||||
|
},
|
||||||
|
|
||||||
|
book = player:hud_add{
|
||||||
|
hud_elem_type = "image",
|
||||||
|
position = {x = 0.79, y = 1.02},
|
||||||
|
alignment = {x = 1, y = 1},
|
||||||
|
scale = {x = 4, y = 4},
|
||||||
|
text = PNG.book,
|
||||||
|
},
|
||||||
|
|
||||||
|
text = player:hud_add{
|
||||||
|
hud_elem_type = "text",
|
||||||
|
position = {x = 0.84, y = 1.04},
|
||||||
|
alignment = {x = 1, y = 1},
|
||||||
|
number = 0xffffff,
|
||||||
|
text = "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
local function show_hud_success(player, data)
|
local function show_hud_success(player, data)
|
||||||
-- It'd better to have an engine function `hud_move` to only need
|
-- It'd better to have an engine function `hud_move` to only need
|
||||||
-- 2 calls for the notification's back and forth.
|
-- 2 calls for the notification's back and forth.
|
||||||
@ -1914,8 +1964,9 @@ if progressive_mode then
|
|||||||
-- Workaround. Need an engine call to detect when the contents of
|
-- Workaround. Need an engine call to detect when the contents of
|
||||||
-- the player inventory changed, instead.
|
-- the player inventory changed, instead.
|
||||||
local function poll_new_items()
|
local function poll_new_items()
|
||||||
for i = 1, #PLAYERS do
|
local players = get_players()
|
||||||
local player = PLAYERS[i]
|
for i = 1, #players do
|
||||||
|
local player = players[i]
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local data = pdata[name]
|
local data = pdata[name]
|
||||||
|
|
||||||
@ -1948,12 +1999,13 @@ if progressive_mode then
|
|||||||
poll_new_items()
|
poll_new_items()
|
||||||
|
|
||||||
globalstep(function()
|
globalstep(function()
|
||||||
for i = 1, #PLAYERS do
|
local players = get_players()
|
||||||
local player = PLAYERS[i]
|
for i = 1, #players do
|
||||||
|
local player = players[i]
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local data = pdata[name]
|
local data = pdata[name]
|
||||||
|
|
||||||
if data.show_hud ~= nil then
|
if data.show_hud ~= nil and singleplayer then
|
||||||
show_hud_success(player, data)
|
show_hud_success(player, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1962,8 +2014,6 @@ if progressive_mode then
|
|||||||
craftguide.add_recipe_filter("Default progressive filter", progressive_filter)
|
craftguide.add_recipe_filter("Default progressive filter", progressive_filter)
|
||||||
|
|
||||||
on_joinplayer(function(player)
|
on_joinplayer(function(player)
|
||||||
PLAYERS = get_players()
|
|
||||||
|
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local data = pdata[name]
|
local data = pdata[name]
|
||||||
|
|
||||||
@ -1971,31 +2021,9 @@ if progressive_mode then
|
|||||||
data.inv_items = dslz(meta:get_string "inv_items") or {}
|
data.inv_items = dslz(meta:get_string "inv_items") or {}
|
||||||
data.known_recipes = dslz(meta:get_string "known_recipes") or 0
|
data.known_recipes = dslz(meta:get_string "known_recipes") or 0
|
||||||
|
|
||||||
data.hud = {
|
if singleplayer then
|
||||||
bg = player:hud_add{
|
init_hud(player, data)
|
||||||
hud_elem_type = "image",
|
end
|
||||||
position = {x = 0.78, y = 1},
|
|
||||||
alignment = {x = 1, y = 1},
|
|
||||||
scale = {x = 370, y = 112},
|
|
||||||
text = PNG.bg,
|
|
||||||
},
|
|
||||||
|
|
||||||
book = player:hud_add{
|
|
||||||
hud_elem_type = "image",
|
|
||||||
position = {x = 0.79, y = 1.02},
|
|
||||||
alignment = {x = 1, y = 1},
|
|
||||||
scale = {x = 4, y = 4},
|
|
||||||
text = PNG.book,
|
|
||||||
},
|
|
||||||
|
|
||||||
text = player:hud_add{
|
|
||||||
hud_elem_type = "text",
|
|
||||||
position = {x = 0.84, y = 1.04},
|
|
||||||
alignment = {x = 1, y = 1},
|
|
||||||
number = 0xffffff,
|
|
||||||
text = "",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local to_save = {"inv_items", "known_recipes"}
|
local to_save = {"inv_items", "known_recipes"}
|
||||||
@ -2011,14 +2039,12 @@ if progressive_mode then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
on_leaveplayer(function(player)
|
on_leaveplayer(save_meta)
|
||||||
PLAYERS = get_players()
|
|
||||||
save_meta(player)
|
|
||||||
end)
|
|
||||||
|
|
||||||
on_shutdown(function()
|
on_shutdown(function()
|
||||||
for i = 1, #PLAYERS do
|
local players = get_players()
|
||||||
local player = PLAYERS[i]
|
for i = 1, #players do
|
||||||
|
local player = players[i]
|
||||||
save_meta(player)
|
save_meta(player)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -2046,13 +2072,11 @@ function craftguide.show(name, item, show_usages)
|
|||||||
if not recipes and not usages then
|
if not recipes and not usages then
|
||||||
if not recipes_cache[item] and not usages_cache[item] then
|
if not recipes_cache[item] and not usages_cache[item] then
|
||||||
return false, msg(name, fmt("%s: %s",
|
return false, msg(name, fmt("%s: %s",
|
||||||
S"No recipe or usage for this item",
|
S"No recipe or usage for this item", get_desc(item)))
|
||||||
get_desc(item)))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return false, msg(name, fmt("%s: %s",
|
return false, msg(name, fmt("%s: %s",
|
||||||
S"You don't know a recipe or usage for this item",
|
S"You don't know a recipe or usage for this item", get_desc(item)))
|
||||||
get_desc(item)))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
data.query_item = item
|
data.query_item = item
|
||||||
|
BIN
textures/craftguide_mesepick.png
Normal file
BIN
textures/craftguide_mesepick.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
BIN
textures/craftguide_steelpick.png
Normal file
BIN
textures/craftguide_steelpick.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
Reference in New Issue
Block a user