mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-11-26 04:23:44 +01:00
Add Fuel time indication
This commit is contained in:
parent
864b43da2c
commit
3f81c7961f
43
init.lua
43
init.lua
@ -27,28 +27,36 @@ function craftguide:group_to_item(item)
|
|||||||
return item
|
return item
|
||||||
end
|
end
|
||||||
|
|
||||||
function craftguide:extract_groups(itemstr)
|
local function extract_groups(str)
|
||||||
if itemstr:sub(1,6) ~= "group:" then return end
|
if str:sub(1,6) ~= "group:" then return end
|
||||||
return itemstr:sub(7):split(",")
|
return str:sub(7):split(",")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function colorize(str)
|
||||||
|
return minetest.colorize("#FFFF00", str)
|
||||||
end
|
end
|
||||||
|
|
||||||
function craftguide:get_tooltip(item, recipe_type, cooktime, groups)
|
function craftguide:get_tooltip(item, recipe_type, cooktime, groups)
|
||||||
local tooltip = ""
|
local tooltip = "tooltip["..item..";"
|
||||||
|
local fueltime = minetest.get_craft_result({method="fuel", width=1, items={item}}).time
|
||||||
|
local has_extras = groups or recipe_type == "cooking" or fueltime > 0
|
||||||
|
local item_desc = groups and "" or minetest.registered_items[item].description
|
||||||
|
|
||||||
if groups then
|
if groups then
|
||||||
local groupstr = "Any item belonging to the "
|
local groupstr = "Any item belonging to the "
|
||||||
for i=1, #groups do
|
for i=1, #groups do
|
||||||
groupstr = groupstr..minetest.colorize("#FFFF00", groups[i])..
|
groupstr = groupstr..colorize(groups[i])..(groups[i+1] and " and " or "")
|
||||||
((groups[i+1] and " and ") or "")
|
|
||||||
end
|
end
|
||||||
tooltip = "tooltip["..item..";"..groupstr.." group(s)"..
|
tooltip = tooltip..groupstr.." group(s)"
|
||||||
((recipe_type ~= "cooking" and "]") or "")
|
|
||||||
end
|
end
|
||||||
if recipe_type == "cooking" then
|
if recipe_type == "cooking" then
|
||||||
tooltip = ((groups and tooltip) or ("tooltip["..item..";"))..
|
tooltip = tooltip..item_desc.."\nCooking time: "..colorize(cooktime)
|
||||||
((groups and "") or minetest.registered_items[item].description)..
|
|
||||||
"\nCooking time: "..minetest.colorize("#FFFF00", cooktime).."]"
|
|
||||||
end
|
end
|
||||||
return tooltip
|
if fueltime > 0 then
|
||||||
|
tooltip = tooltip..item_desc.."\nBurning time: "..colorize(fueltime)
|
||||||
|
end
|
||||||
|
|
||||||
|
return has_extras and tooltip.."]" or ""
|
||||||
end
|
end
|
||||||
|
|
||||||
function craftguide:get_formspec(player_name)
|
function craftguide:get_formspec(player_name)
|
||||||
@ -63,8 +71,7 @@ function craftguide:get_formspec(player_name)
|
|||||||
tooltip[clear;Reset]
|
tooltip[clear;Reset]
|
||||||
field_close_on_enter[craftguide_filter, false]
|
field_close_on_enter[craftguide_filter, false]
|
||||||
button[5.4,0;0.8,0.95;prev;<] ]]..
|
button[5.4,0;0.8,0.95;prev;<] ]]..
|
||||||
"label[6.1,0.18;"..minetest.colorize("#FFFF00",
|
"label[6.1,0.18;"..colorize(data.pagenum).." / "..data.pagemax.."]"..
|
||||||
data.pagenum).." / "..data.pagemax.."]"..
|
|
||||||
"button[7.2,0;0.8,0.95;next;>]"..
|
"button[7.2,0;0.8,0.95;next;>]"..
|
||||||
"field[0.3,0.32;2.6,1;craftguide_filter;;"..
|
"field[0.3,0.32;2.6,1;craftguide_filter;;"..
|
||||||
minetest.formspec_escape(data.filter).."]"..
|
minetest.formspec_escape(data.filter).."]"..
|
||||||
@ -77,7 +84,7 @@ function craftguide:get_formspec(player_name)
|
|||||||
local first_item = (data.pagenum - 1) * npp
|
local first_item = (data.pagenum - 1) * npp
|
||||||
for i = first_item, first_item + npp - 1 do
|
for i = first_item, first_item + npp - 1 do
|
||||||
local name = data.items[i+1]
|
local name = data.items[i+1]
|
||||||
if not name then break end -- last page
|
if not name then break end
|
||||||
local X = i % 8
|
local X = i % 8
|
||||||
local Y = ((i % npp - X) / 8) + 1
|
local Y = ((i % npp - X) / 8) + 1
|
||||||
|
|
||||||
@ -116,8 +123,8 @@ function craftguide:get_formspec(player_name)
|
|||||||
for i, v in pairs(items) do
|
for i, v in pairs(items) do
|
||||||
local X = (i-1) % width + 4.5
|
local X = (i-1) % width + 4.5
|
||||||
local Y = ceil(i / width + (5 - min(2, rows)))
|
local Y = ceil(i / width + (5 - min(2, rows)))
|
||||||
local groups = self:extract_groups(v)
|
local groups = extract_groups(v)
|
||||||
local label = (groups and "\nG") or ""
|
local label = groups and "\nG" or ""
|
||||||
local item = self:group_to_item(v)
|
local item = self:group_to_item(v)
|
||||||
local tooltip = self:get_tooltip(item, recipe_type, width, groups)
|
local tooltip = self:get_tooltip(item, recipe_type, width, groups)
|
||||||
|
|
||||||
@ -192,7 +199,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
craftguide:get_items(player_name)
|
craftguide:get_items(player_name)
|
||||||
craftguide:get_formspec(player_name)
|
craftguide:get_formspec(player_name)
|
||||||
elseif fields.alternate then
|
elseif fields.alternate then
|
||||||
data.recipe_num = (data.recipe_num and data.recipe_num + 1) or 1
|
data.recipe_num = data.recipe_num and data.recipe_num + 1 or 1
|
||||||
craftguide:get_formspec(player_name)
|
craftguide:get_formspec(player_name)
|
||||||
elseif fields.search or fields.key_enter_field == "craftguide_filter" then
|
elseif fields.search or fields.key_enter_field == "craftguide_filter" then
|
||||||
data.filter = fields.craftguide_filter:lower()
|
data.filter = fields.craftguide_filter:lower()
|
||||||
|
Loading…
Reference in New Issue
Block a user