mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-12-13 18:20:17 +01:00
Minor style cleanup
This commit is contained in:
parent
e5cb84d02e
commit
6705549a31
66
init.lua
66
init.lua
@ -84,15 +84,18 @@ function craftguide:get_tooltip(item, recipe_type, cooktime, groups)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function craftguide:get_recipe(player_name, tooltipl, item, recipe_num, recipes)
|
function craftguide:get_recipe(player_name, tooltipl, item, recipe_num, recipes)
|
||||||
local formspec, recipe_type = "", recipes[recipe_num].type
|
local formspec, recipes_total = "", #recipes
|
||||||
if #recipes > 1 then formspec = formspec..
|
if recipes_total > 1 then
|
||||||
"button[0,"..(iY+3)..";2,1;alternate;Alternate]"..
|
formspec = formspec..
|
||||||
"label[0,"..(iY+2)..".5;Recipe "..
|
"button[0,"..(iY+3)..";2,1;alternate;Alternate]"..
|
||||||
recipe_num.." of "..#recipes.."]"
|
"label[0,"..(iY+2)..".5;Recipe "..
|
||||||
|
recipe_num.." of "..recipes_total.."]"
|
||||||
end
|
end
|
||||||
|
local recipe_type = recipes[recipe_num].type
|
||||||
if recipe_type == "cooking" then
|
if recipe_type == "cooking" then
|
||||||
formspec = formspec.."image["..(xoffset-0.8)..","..(iY+1)..
|
formspec = formspec..
|
||||||
".5;0.5,0.5;default_furnace_front.png]"
|
"image["..(xoffset-0.8)..","..(iY+1)..
|
||||||
|
".5;0.5,0.5;default_furnace_front.png]"
|
||||||
end
|
end
|
||||||
|
|
||||||
local items = recipes[recipe_num].items
|
local items = recipes[recipe_num].items
|
||||||
@ -105,8 +108,8 @@ function craftguide:get_recipe(player_name, tooltipl, item, recipe_num, recipes)
|
|||||||
width > craftgrid_limit or rows > craftgrid_limit then
|
width > craftgrid_limit or rows > craftgrid_limit then
|
||||||
formspec = formspec..
|
formspec = formspec..
|
||||||
"label["..xoffset..","..(iY+2)..
|
"label["..xoffset..","..(iY+2)..
|
||||||
";Recipe is too big to\nbe displayed ("..
|
";Recipe is too big to\nbe displayed ("..
|
||||||
width.."x"..rows..")]"
|
width.."x"..rows..")]"
|
||||||
else
|
else
|
||||||
for i, v in pairs(items) do
|
for i, v in pairs(items) do
|
||||||
local X = (i-1) % width + xoffset
|
local X = (i-1) % width + xoffset
|
||||||
@ -123,20 +126,21 @@ function craftguide:get_recipe(player_name, tooltipl, item, recipe_num, recipes)
|
|||||||
local groups = extract_groups(v)
|
local groups = extract_groups(v)
|
||||||
local label = groups and "\nG" or ""
|
local label = groups and "\nG" or ""
|
||||||
local item_r = self:group_to_item(v)
|
local item_r = self:group_to_item(v)
|
||||||
local tooltip = self:get_tooltip(item_r, recipe_type,
|
local tooltip = self:get_tooltip(
|
||||||
width, groups)
|
item_r, recipe_type, width, groups)
|
||||||
|
|
||||||
formspec = formspec.."item_image_button["..X..","..Y..
|
formspec = formspec..
|
||||||
";"..btn_size..","..btn_size..";"..item_r..
|
"item_image_button["..X..","..Y..";"..
|
||||||
";"..item_r..";"..label.."]"..tooltip
|
btn_size..","..btn_size..";"..item_r..
|
||||||
|
";"..item_r..";"..label.."]"..tooltip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local output = recipes[recipe_num].output
|
local output = recipes[recipe_num].output
|
||||||
return formspec..
|
return formspec..
|
||||||
"image["..(xoffset-1)..","..(iY+2)..
|
"image["..(xoffset-1)..","..(iY+2)..
|
||||||
".12;0.9,0.7;craftguide_arrow.png]"..
|
".12;0.9,0.7;craftguide_arrow.png]"..
|
||||||
"item_image_button["..(xoffset-2)..","..(iY+2)..";1,1;"..
|
"item_image_button["..(xoffset-2)..","..(iY+2)..";1,1;"..
|
||||||
output..";"..item..";]"..tooltipl
|
output..";"..item..";]"..tooltipl
|
||||||
end
|
end
|
||||||
|
|
||||||
function craftguide:get_formspec(player_name, is_fuel)
|
function craftguide:get_formspec(player_name, is_fuel)
|
||||||
@ -149,15 +153,16 @@ function craftguide:get_formspec(player_name, is_fuel)
|
|||||||
tooltip[clear;Reset]
|
tooltip[clear;Reset]
|
||||||
field_close_on_enter[craftguide_filter, false] ]]..
|
field_close_on_enter[craftguide_filter, false] ]]..
|
||||||
"button["..(iX-3)..".4,0;0.8,0.95;prev;<]"..
|
"button["..(iX-3)..".4,0;0.8,0.95;prev;<]"..
|
||||||
"label["..(iX-2)..".1,0.18;"..
|
"label["..(iX-2)..".1,0.18;"..colorize(data.pagenum)..
|
||||||
colorize(data.pagenum).." / "..data.pagemax.."]"..
|
" / "..data.pagemax.."]"..
|
||||||
"button["..(iX-1)..".2,0;0.8,0.95;next;>]"..
|
"button["..(iX-1)..".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).."]"
|
||||||
|
|
||||||
if not next(data.items) then
|
if not next(data.items) then
|
||||||
formspec = formspec.."label["..(xoffset -
|
formspec = formspec..
|
||||||
(iX%2 == 0 and 1.5 or 1))..",2;No item to show]"
|
"label["..(xoffset - (iX%2 == 0 and 1.5 or 1))..
|
||||||
|
",2;No item to show]"
|
||||||
end
|
end
|
||||||
|
|
||||||
local first_item = (data.pagenum - 1) * ipp
|
local first_item = (data.pagenum - 1) * ipp
|
||||||
@ -167,8 +172,9 @@ function craftguide:get_formspec(player_name, is_fuel)
|
|||||||
local X = i % iX
|
local X = i % iX
|
||||||
local Y = (i % ipp - X) / iX+1
|
local Y = (i % ipp - X) / iX+1
|
||||||
|
|
||||||
formspec = formspec.."item_image_button["..X..","..Y..";1,1;"..
|
formspec = formspec..
|
||||||
name..";"..name.."_inv;]"
|
"item_image_button["..X..","..Y..";1,1;"..
|
||||||
|
name..";"..name.."_inv;]"
|
||||||
end
|
end
|
||||||
|
|
||||||
if data.item and minetest.registered_items[data.item] then
|
if data.item and minetest.registered_items[data.item] then
|
||||||
@ -195,7 +201,9 @@ function craftguide:get_formspec(player_name, is_fuel)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function player_has_item(T)
|
local function player_has_item(T)
|
||||||
for i=1, #T do if T[i] then return true end end
|
for i=1, #T do
|
||||||
|
if T[i] then return true end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function group_to_items(group)
|
local function group_to_items(group)
|
||||||
@ -233,7 +241,9 @@ function craftguide:recipe_in_inv(inv, item_name, recipes_f)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i=#show_item_recipes, 1, -1 do
|
for i=#show_item_recipes, 1, -1 do
|
||||||
if not show_item_recipes[i] then remove(recipes, i) end
|
if not show_item_recipes[i] then
|
||||||
|
remove(recipes, i)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return recipes, player_has_item(show_item_recipes)
|
return recipes, player_has_item(show_item_recipes)
|
||||||
@ -318,7 +328,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
else
|
else
|
||||||
for item in pairs(fields) do
|
for item in pairs(fields) do
|
||||||
if not item:find(":") then break end
|
if not item:find(":") then break end
|
||||||
if item:sub(-4) == "_inv" then item = item:sub(1,-5) end
|
if item:sub(-4) == "_inv" then
|
||||||
|
item = item:sub(1,-5)
|
||||||
|
end
|
||||||
|
|
||||||
local recipes = minetest.get_all_craft_recipes(item)
|
local recipes = minetest.get_all_craft_recipes(item)
|
||||||
local is_fuel = minetest.get_craft_result({
|
local is_fuel = minetest.get_craft_result({
|
||||||
|
Loading…
Reference in New Issue
Block a user