biogasmachines: add tooltips to recipe hintbar icons.

Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
This commit is contained in:
Michal Cieslakiewicz 2019-03-09 23:38:20 +01:00
parent b90cbbe409
commit e2b125e2ac
5 changed files with 36 additions and 11 deletions

View File

@ -150,6 +150,15 @@ local fmxy = {
biogas_time = tostring(BIOGAS_TICKS * TIMER_TICK_SEC),
}
-- get node/item/tool description for tooltip
local function formspec_tooltip(name)
local def = minetest.registered_nodes[name] or
minetest.registered_craftitems[name] or
minetest.registered_items[name] or
minetest.registered_tools[name] or nil
return def and def.description or ""
end
-- recipe hint bar
local function formspec_recipe_hint_bar(recipe_idx)
if #hintbar_recipes == 0 or recipe_idx > #hintbar_recipes then
@ -168,15 +177,19 @@ local function formspec_recipe_hint_bar(recipe_idx)
string.format("%2d / %2d", recipe_idx, #hintbar_recipes) .. "]" ..
"image_button[1.9,3.3;0.5,0.5;;right;>]" ..
"item_image[2.4,3.25;0.5,0.5;" .. input_name .. "]" ..
"tooltip[2.4,3.25;0.5,0.5;" .. formspec_tooltip(input_name) .. "]" ..
"label[2.9,3.25;x " .. input_count .. "]" ..
"image[3.3,3.25;0.5,0.5;tubelib_gui_arrow.png^[resize:16x16]" ..
"label[3.7,3.25;" ..
string.format("%2d sec +", recipe.time * TIMER_TICK_SEC) .. "]" ..
"item_image[4.5,3.25;0.5,0.5;default:ice]" ..
"tooltip[4.5,3.25;0.5,0.5;Ice]" ..
"image[4.9,3.25;0.5,0.5;tubelib_gui_arrow.png^[resize:16x16]" ..
"item_image[5.3,3.25;0.5,0.5;" .. output_name .. "]" ..
"tooltip[5.3,3.25;0.5,0.5;" .. formspec_tooltip(output_name) .. "]" ..
"label[5.8,3.25;x " .. output_count .. "]" ..
"item_image[6.5,3.25;0.5,0.5;tubelib_addons1:biogas]" ..
"tooltip[6.5,3.25;0.5,0.5;Biogas]" ..
"label[7,3.25;= " .. fmxy.biogas_time .. " sec]"
end

View File

@ -136,12 +136,16 @@ local function formspec(self, pos, meta)
"image_button[" .. fmxy.mid_x .. ",2;1,1;" ..
self:get_state_button_image(meta) .. ";state_button;]" ..
"item_image[1,3.25;0.5,0.5;tubelib_addons1:biogas]" ..
"tooltip[1,3.25;0.5,0.5;Biogas]" ..
"label[1.5,3.25;= " .. fmxy.biogas_time .. " sec]" ..
"item_image[3,3.25;0.5,0.5;default:ice]" ..
"tooltip[3,3.25;0.5,0.5;Ice]" ..
"label[3.5,3.25;= " .. fmxy.ice_time .. " sec]" ..
"item_image[5.25,3.25;0.5,0.5;tubelib_addons1:biogas]" ..
"tooltip[5.25,3.25;0.5,0.5;Biogas]" ..
"image[5.75,3.25;0.5,0.5;tubelib_gui_arrow.png^[resize:16x16]" ..
"item_image[6.25,3.25;0.5,0.5;default:ice]" ..
"tooltip[6.25,3.25;0.5,0.5;Ice]" ..
"label[6.75,3.25;x " .. fmxy.ice_qty .. "]" ..
"item_image[" .. fmxy.inv_out_x .. ",0;1,1;default:ice]" ..
"list[context;dst;" .. fmxy.inv_out_x .. ",0;" .. fmxy.inv_out_w ..

View File

@ -128,6 +128,7 @@ local function formspec(self, pos, meta)
"label[2.75,3.25;=]" ..
"item_image[3,3.25;0.5,0.5;default:furnace]" ..
"item_image[4.5,3.25;0.5,0.5;tubelib_addons1:biogas]" ..
"tooltip[4.5,3.25;0.5,0.5;Biogas]" ..
"label[5,3.25;= " .. fmxy.biogas_time .. " sec]" ..
"list[context;dst;" .. fmxy.inv_out_x .. ",0;" .. fmxy.inv_out_w ..
"," .. fmxy.inv_h .. ";]" ..

View File

@ -140,35 +140,41 @@ local fmxy = { inv_h = tostring(INV_H),
inv_out_x = tostring(INV_IN_W + 2),
}
-- get node/item/tool description for tooltip
local function formspec_tooltip(name)
local def = minetest.registered_nodes[name] or
minetest.registered_craftitems[name] or
minetest.registered_items[name] or
minetest.registered_tools[name] or nil
return def and def.description or ""
end
-- recipe hint bar
local function formspec_recipe_hint_bar(recipe_idx)
if #biogas_sources == 0 or recipe_idx > #biogas_sources then
return ""
end
local input_item = biogas_sources[recipe_idx]
--local input_desc = minetest.registered_nodes[input_item].description
local recipe = biogas_recipes[input_item]
local extra_item = recipe.extra and recipe.extra:get_name() or ""
return "item_image[0,0;1,1;" .. input_item .. "]" ..
"label[0.5,3.25;Recipe]" ..
"image_button[1.5,3.3;0.5,0.5;;left;<]" ..
"label[2,3.25;" ..
string.format("%2d / %2d", recipe_idx, #biogas_sources) ..
"]" ..
string.format("%2d / %2d", recipe_idx, #biogas_sources) .. "]" ..
"image_button[2.8,3.3;0.5,0.5;;right;>]" ..
"item_image[3.6,3.25;0.5,0.5;" .. input_item .. "]" ..
--"tooltip[3.6,3.25;0.5,0.5;" .. -- not supported in 0.4.x
-- minetest.registered_nodes[input_item].description ..
-- ";;]" ..
"tooltip[3.6,3.25;0.5,0.5;" .. formspec_tooltip(input_item) .. "]" ..
"image[4,3.25;0.5,0.5;tubelib_gui_arrow.png^[resize:16x16]" ..
"label[4.4,3.25;" ..
string.format("%2d sec", recipe.time * TIMER_TICK_SEC) ..
"]" ..
string.format("%2d sec", recipe.time * TIMER_TICK_SEC) .. "]" ..
"image[5,3.25;0.5,0.5;tubelib_gui_arrow.png^[resize:16x16]" ..
"item_image[5.5,3.25;0.5,0.5;tubelib_addons1:biogas]" ..
"tooltip[5.5,3.25;0.5,0.5;Biogas]" ..
"label[6,3.25;x " .. tostring(recipe.count) .. "]" ..
(recipe.extra and "item_image[6.5,3.25;0.5,0.5;" ..
recipe.extra:get_name() .. "]label[7,3.25;x " ..
tostring(recipe.extra:get_count()) .. "]" or "")
(recipe.extra and "item_image[6.5,3.25;0.5,0.5;" .. extra_item .. "]" ..
"tooltip[6.5,3.25;0.5,0.5;" .. formspec_tooltip(extra_item) .. "]" ..
"label[7,3.25;x " .. tostring(recipe.extra:get_count()) .. "]" or "")
end
-- formspec

View File

@ -104,6 +104,7 @@ local function formspec(self, pos, meta)
"item_image[2.75,3.25;0.5,0.5;default:furnace]" ..
"label[3.25,3.25;x 2]" ..
"item_image[4.5,3.25;0.5,0.5;tubelib_addons1:biogas]" ..
"tooltip[4.5,3.25;0.5,0.5;Biogas]" ..
"label[5,3.25;= " .. fmxy.biogas_time .. " sec]" ..
"list[context;dst;" .. fmxy.inv_out_x .. ",0;" .. fmxy.inv_out_w ..
"," .. fmxy.inv_h .. ";]" ..