mirror of
https://github.com/minetest-mods/craftguide.git
synced 2025-06-29 14:40:49 +02:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
5fc7e7c087 | |||
aa61333ee3 | |||
e2cdfc28b0 | |||
aa9f7d6da3 | |||
d87c64618c | |||
3455257df5 |
47
init.lua
47
init.lua
@ -644,6 +644,10 @@ local function is_fav(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function get_desc(name)
|
local function get_desc(name)
|
||||||
|
if sub(name, 1, 1) == "_" then
|
||||||
|
name = sub(name, 2)
|
||||||
|
end
|
||||||
|
|
||||||
local def = reg_items[name]
|
local def = reg_items[name]
|
||||||
|
|
||||||
return def and (match(def.description, "%)([%w%s]*)") or def.description) or
|
return def and (match(def.description, "%)([%w%s]*)") or def.description) or
|
||||||
@ -748,9 +752,11 @@ local function get_output_fs(data, fs, L)
|
|||||||
1.1, 1.1, PNG.selected)
|
1.1, 1.1, PNG.selected)
|
||||||
end
|
end
|
||||||
|
|
||||||
fs[#fs + 1] = fmt(FMT.item_image_button,
|
local _name = sfinv_only and name or fmt("_%s", name)
|
||||||
|
|
||||||
|
fs[#fs + 1] = fmt("item_image_button[%f,%f;%f,%f;%s;%s;%s]",
|
||||||
output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
|
output_X, YOFFSET + (sfinv_only and 0.7 or 0) + L.spacing,
|
||||||
1.1, 1.1, item, name, "")
|
1.1, 1.1, item, _name, "")
|
||||||
|
|
||||||
local infos = {
|
local infos = {
|
||||||
unknown = not reg_items[name] or nil,
|
unknown = not reg_items[name] or nil,
|
||||||
@ -760,7 +766,7 @@ local function get_output_fs(data, fs, L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if next(infos) then
|
if next(infos) then
|
||||||
fs[#fs + 1] = get_tooltip(name, infos)
|
fs[#fs + 1] = get_tooltip(_name, infos)
|
||||||
end
|
end
|
||||||
|
|
||||||
if infos.burntime then
|
if infos.burntime then
|
||||||
@ -942,7 +948,7 @@ local function get_panels(data, fs)
|
|||||||
xu = max(-0.3, -((#xu - 3) * 0.05))
|
xu = max(-0.3, -((#xu - 3) * 0.05))
|
||||||
xr = max(-0.3, -((#xr - 3) * 0.05))
|
xr = max(-0.3, -((#xr - 3) * 0.05))
|
||||||
|
|
||||||
local is_recipe = k == 2
|
local is_recipe = sfinv_only and not data.show_usages or k == 2
|
||||||
local lbl
|
local lbl
|
||||||
|
|
||||||
if not sfinv_only and rn == 0 then
|
if not sfinv_only and rn == 0 then
|
||||||
@ -1010,7 +1016,7 @@ local function get_panels(data, fs)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function make_formspec(data)
|
local function make_fs(data)
|
||||||
local fs = {}
|
local fs = {}
|
||||||
|
|
||||||
fs[#fs + 1] = fmt([[
|
fs[#fs + 1] = fmt([[
|
||||||
@ -1118,7 +1124,7 @@ local show_fs = function(player, name)
|
|||||||
if sfinv_only then
|
if sfinv_only then
|
||||||
sfinv.set_player_inventory_formspec(player)
|
sfinv.set_player_inventory_formspec(player)
|
||||||
else
|
else
|
||||||
show_formspec(name, "craftguide", make_formspec(data))
|
show_formspec(name, "craftguide", make_fs(data))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1540,22 +1546,25 @@ end)
|
|||||||
local function fields(player, _f)
|
local function fields(player, _f)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local data = pdata[name]
|
local data = pdata[name]
|
||||||
|
--print(dump(_f))
|
||||||
|
|
||||||
if _f.clear then
|
if _f.clear then
|
||||||
reset_data(data)
|
reset_data(data)
|
||||||
return true, show_fs(player, name)
|
|
||||||
|
|
||||||
elseif _f.prev_recipe or _f.next_recipe then
|
elseif _f.prev_recipe or _f.next_recipe then
|
||||||
local num = data.rnum + (_f.prev_recipe and -1 or 1)
|
local num = data.rnum + (_f.prev_recipe and -1 or 1)
|
||||||
data.rnum = data.recipes[num] and num or (_f.prev_recipe and #data.recipes or 1)
|
data.rnum = data.recipes[num] and num or (_f.prev_recipe and #data.recipes or 1)
|
||||||
return true, show_fs(player, name)
|
|
||||||
|
|
||||||
elseif _f.prev_usage or _f.next_usage then
|
elseif _f.prev_usage or _f.next_usage then
|
||||||
local num = data.unum + (_f.prev_usage and -1 or 1)
|
local num = data.unum + (_f.prev_usage and -1 or 1)
|
||||||
data.unum = data.usages[num] and num or (_f.prev_usage and #data.usages or 1)
|
data.unum = data.usages[num] and num or (_f.prev_usage and #data.usages or 1)
|
||||||
return true, show_fs(player, name)
|
|
||||||
|
|
||||||
elseif (_f.key_enter_field == "filter" or _f.search) and _f.filter ~= "" then
|
elseif _f.key_enter_field == "filter" or _f.search then
|
||||||
|
if _f.filter == "" then
|
||||||
|
reset_data(data)
|
||||||
|
return true, show_fs(player, name)
|
||||||
|
end
|
||||||
|
|
||||||
local str = lower(_f.filter)
|
local str = lower(_f.filter)
|
||||||
if data.filter == str then return end
|
if data.filter == str then return end
|
||||||
|
|
||||||
@ -1563,8 +1572,6 @@ local function fields(player, _f)
|
|||||||
data.pagenum = 1
|
data.pagenum = 1
|
||||||
search(data)
|
search(data)
|
||||||
|
|
||||||
return true, show_fs(player, name)
|
|
||||||
|
|
||||||
elseif _f.prev_page or _f.next_page then
|
elseif _f.prev_page or _f.next_page then
|
||||||
if data.pagemax == 1 then return end
|
if data.pagemax == 1 then return end
|
||||||
data.pagenum = data.pagenum - (_f.prev_page and 1 or -1)
|
data.pagenum = data.pagenum - (_f.prev_page and 1 or -1)
|
||||||
@ -1575,8 +1582,6 @@ local function fields(player, _f)
|
|||||||
data.pagenum = data.pagemax
|
data.pagenum = data.pagemax
|
||||||
end
|
end
|
||||||
|
|
||||||
return true, show_fs(player, name)
|
|
||||||
|
|
||||||
elseif _f.fav then
|
elseif _f.fav then
|
||||||
local fav, i = is_fav(data)
|
local fav, i = is_fav(data)
|
||||||
local total = #data.favs
|
local total = #data.favs
|
||||||
@ -1586,8 +1591,6 @@ local function fields(player, _f)
|
|||||||
elseif fav then
|
elseif fav then
|
||||||
remove(data.favs, i)
|
remove(data.favs, i)
|
||||||
end
|
end
|
||||||
|
|
||||||
return true, show_fs(player, name)
|
|
||||||
else
|
else
|
||||||
local item
|
local item
|
||||||
for field in pairs(_f) do
|
for field in pairs(_f) do
|
||||||
@ -1601,6 +1604,8 @@ local function fields(player, _f)
|
|||||||
return
|
return
|
||||||
elseif sub(item, -4) == "_inv" then
|
elseif sub(item, -4) == "_inv" then
|
||||||
item = sub(item, 1, -5)
|
item = sub(item, 1, -5)
|
||||||
|
elseif sub(item, 1, 1) == "_" then
|
||||||
|
item = sub(item, 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
item = reg_aliases[item] or item
|
item = reg_aliases[item] or item
|
||||||
@ -1611,6 +1616,8 @@ local function fields(player, _f)
|
|||||||
else
|
else
|
||||||
data.show_usages = not data.show_usages
|
data.show_usages = not data.show_usages
|
||||||
end
|
end
|
||||||
|
elseif item == data.query_item then
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local recipes, usages = get_recipes(item, data, player)
|
local recipes, usages = get_recipes(item, data, player)
|
||||||
@ -1622,9 +1629,9 @@ local function fields(player, _f)
|
|||||||
data.usages = usages
|
data.usages = usages
|
||||||
data.rnum = 1
|
data.rnum = 1
|
||||||
data.unum = 1
|
data.unum = 1
|
||||||
|
|
||||||
return true, show_fs(player, name)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return true, show_fs(player, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if sfinv_only then
|
if sfinv_only then
|
||||||
@ -1639,7 +1646,7 @@ 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_formspec(data)
|
local formspec = make_fs(data)
|
||||||
|
|
||||||
return sfinv.make_formspec(player, context, formspec)
|
return sfinv.make_formspec(player, context, formspec)
|
||||||
end,
|
end,
|
||||||
@ -1679,7 +1686,7 @@ else
|
|||||||
search(data)
|
search(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
show_formspec(name, "craftguide", make_formspec(data))
|
show_formspec(name, "craftguide", make_fs(data))
|
||||||
end
|
end
|
||||||
|
|
||||||
core.register_craftitem("craftguide:book", {
|
core.register_craftitem("craftguide:book", {
|
||||||
|
Reference in New Issue
Block a user