mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-11-23 03:13:44 +01:00
Code cleanup, change arrow texture
This commit is contained in:
parent
4a5c0acd96
commit
aa4f2c55f2
113
init.lua
113
init.lua
@ -38,14 +38,16 @@ end
|
|||||||
|
|
||||||
function craftguide:get_tooltip(item, recipe_type, cooktime, groups)
|
function craftguide:get_tooltip(item, recipe_type, cooktime, groups)
|
||||||
local tooltip = "tooltip["..item..";"
|
local tooltip = "tooltip["..item..";"
|
||||||
local fueltime = minetest.get_craft_result({method="fuel", width=1, items={item}}).time
|
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 has_extras = groups or recipe_type == "cooking" or fueltime > 0
|
||||||
local item_desc = groups and "" or minetest.registered_items[item].description
|
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..colorize(groups[i])..(groups[i+1] and " and " or "")
|
groupstr = groupstr..colorize(groups[i])..
|
||||||
|
(groups[i+1] and " and " or "")
|
||||||
end
|
end
|
||||||
tooltip = tooltip..groupstr.." group(s)"
|
tooltip = tooltip..groupstr.." group(s)"
|
||||||
end
|
end
|
||||||
@ -59,50 +61,10 @@ function craftguide:get_tooltip(item, recipe_type, cooktime, groups)
|
|||||||
return has_extras and tooltip.."]" or ""
|
return has_extras and tooltip.."]" or ""
|
||||||
end
|
end
|
||||||
|
|
||||||
function craftguide:get_formspec(player_name)
|
function craftguide:get_recipe(player_name, data, tooltip_l)
|
||||||
local data = datas[player_name]
|
local formspec = ""
|
||||||
data.pagenum = max(1, data.pagenum or 1)
|
|
||||||
data.pagemax = max(1, data.pagemax or 1)
|
|
||||||
|
|
||||||
local formspec = [[ size[8,6.6;]
|
|
||||||
button[2.5,0.2;0.8,0.5;search;?]
|
|
||||||
button[3.2,0.2;0.8,0.5;clear;X]
|
|
||||||
tooltip[search;Search]
|
|
||||||
tooltip[clear;Reset]
|
|
||||||
field_close_on_enter[craftguide_filter, false]
|
|
||||||
button[5.4,0;0.8,0.95;prev;<] ]]..
|
|
||||||
"label[6.1,0.18;"..colorize(data.pagenum).." / "..data.pagemax.."]"..
|
|
||||||
"button[7.2,0;0.8,0.95;next;>]"..
|
|
||||||
"field[0.3,0.32;2.6,1;craftguide_filter;;"..
|
|
||||||
minetest.formspec_escape(data.filter).."]"..
|
|
||||||
default.gui_bg..default.gui_bg_img
|
|
||||||
|
|
||||||
if not next(data.items) then
|
|
||||||
formspec = formspec.."label[2.9,2;No item to show]"
|
|
||||||
end
|
|
||||||
|
|
||||||
local first_item = (data.pagenum - 1) * npp
|
|
||||||
for i = first_item, first_item + npp - 1 do
|
|
||||||
local name = data.items[i+1]
|
|
||||||
if not name then break end
|
|
||||||
local X = i % 8
|
|
||||||
local Y = ((i % npp - X) / 8) + 1
|
|
||||||
|
|
||||||
formspec = formspec.."item_image_button["..X..","..Y..";1,1;"..name..";"..name..";]"
|
|
||||||
end
|
|
||||||
|
|
||||||
if data.item and minetest.registered_items[data.item] then
|
|
||||||
local recipes = minetest.get_all_craft_recipes(data.item)
|
local recipes = minetest.get_all_craft_recipes(data.item)
|
||||||
local is_fuel_only = minetest.get_craft_result({
|
|
||||||
method="fuel", width=1, items={data.item}}).time
|
|
||||||
local tooltip_l = self:get_tooltip(data.item)
|
|
||||||
|
|
||||||
if is_fuel_only and not recipes then
|
|
||||||
formspec = formspec..
|
|
||||||
"image[3.5,5;1,1;gui_furnace_arrow_bg.png^[transformR270]"..
|
|
||||||
"item_image_button[2.5,5;1,1;"..data.item..";"..data.item..";]"..
|
|
||||||
tooltip_l.."image[4.5,5;1,1;craftguide_none.png]"
|
|
||||||
else
|
|
||||||
if progressive_mode then
|
if progressive_mode then
|
||||||
local T = self:recipe_in_inv(player_name, data.item)
|
local T = self:recipe_in_inv(player_name, data.item)
|
||||||
for i=#T, 1, -1 do
|
for i=#T, 1, -1 do
|
||||||
@ -119,8 +81,8 @@ function craftguide:get_formspec(player_name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local recipe_type = recipes[data.recipe_num].type
|
local recipe_type = recipes[data.recipe_num].type
|
||||||
if recipe_type == "cooking" then
|
if recipe_type == "cooking" then formspec = formspec..
|
||||||
formspec = formspec.."image[3.75,4.6;0.5,0.5;default_furnace_front.png]"
|
"image[3.75,4.5;0.5,0.5;default_furnace_front.png]"
|
||||||
end
|
end
|
||||||
|
|
||||||
local items = recipes[data.recipe_num].items
|
local items = recipes[data.recipe_num].items
|
||||||
@ -143,9 +105,58 @@ function craftguide:get_formspec(player_name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local output = recipes[data.recipe_num].output
|
local output = recipes[data.recipe_num].output
|
||||||
formspec = formspec..[[
|
return formspec..[[
|
||||||
image[3.5,5;1,1;gui_furnace_arrow_bg.png^[transformR90]
|
image[3.5,5.12;0.9,0.7;craftguide_arrow.png]
|
||||||
item_image_button[2.5,5;1,1;]]..output..";"..data.item..";]"..tooltip_l
|
item_image_button[2.5,5;1,1;]]..output..";"..data.item..";]"..tooltip_l
|
||||||
|
end
|
||||||
|
|
||||||
|
function craftguide:get_formspec(player_name)
|
||||||
|
local data = datas[player_name]
|
||||||
|
data.pagenum = max(1, data.pagenum or 1)
|
||||||
|
data.pagemax = max(1, data.pagemax or 1)
|
||||||
|
|
||||||
|
local formspec = [[ size[8,6.6;]
|
||||||
|
button[2.5,0.2;0.8,0.5;search;?]
|
||||||
|
button[3.2,0.2;0.8,0.5;clear;X]
|
||||||
|
tooltip[search;Search]
|
||||||
|
tooltip[clear;Reset]
|
||||||
|
field_close_on_enter[craftguide_filter, false]
|
||||||
|
button[5.4,0;0.8,0.95;prev;<] ]]..
|
||||||
|
"label[6.1,0.18;"..
|
||||||
|
colorize(data.pagenum).." / "..data.pagemax.."]"..
|
||||||
|
"button[7.2,0;0.8,0.95;next;>]"..
|
||||||
|
"field[0.3,0.32;2.6,1;craftguide_filter;;"..
|
||||||
|
minetest.formspec_escape(data.filter).."]"..
|
||||||
|
default.gui_bg..default.gui_bg_img
|
||||||
|
|
||||||
|
if not next(data.items) then
|
||||||
|
formspec = formspec.."label[2.9,2;No item to show]"
|
||||||
|
end
|
||||||
|
|
||||||
|
local first_item = (data.pagenum - 1) * npp
|
||||||
|
for i = first_item, first_item + npp - 1 do
|
||||||
|
local name = data.items[i+1]
|
||||||
|
if not name then break end
|
||||||
|
local X = i % 8
|
||||||
|
local Y = ((i % npp - X) / 8) + 1
|
||||||
|
|
||||||
|
formspec = formspec.."item_image_button["..X..","..Y..";1,1;"..
|
||||||
|
name..";"..name..";]"
|
||||||
|
end
|
||||||
|
|
||||||
|
if data.item and minetest.registered_items[data.item] then
|
||||||
|
local is_fuel_only = minetest.get_craft_result({
|
||||||
|
method="fuel", width=1, items={data.item}}).time > 0
|
||||||
|
local tooltip = self:get_tooltip(data.item)
|
||||||
|
|
||||||
|
if is_fuel_only and not minetest.get_craft_recipe(data.item).items then
|
||||||
|
formspec = formspec..[[
|
||||||
|
image[3.5,5.12;0.9,0.7;craftguide_arrow.png]
|
||||||
|
item_image_button[4.5,5;1,1;]]..
|
||||||
|
data.item..";"..data.item..";]"..
|
||||||
|
tooltip.."image[2.5,5;1,1;craftguide_none.png]"
|
||||||
|
else
|
||||||
|
formspec = formspec..self:get_recipe(player_name, data, tooltip)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -229,7 +240,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
method="fuel", width=1, items={item}}).time > 0
|
method="fuel", width=1, items={item}}).time > 0
|
||||||
if minetest.get_craft_recipe(item).items or is_fuel then
|
if minetest.get_craft_recipe(item).items or is_fuel then
|
||||||
if progressive_mode then
|
if progressive_mode then
|
||||||
local _, has_item = craftguide:recipe_in_inv(player_name, item)
|
local _, has_item =
|
||||||
|
craftguide:recipe_in_inv(player_name, item)
|
||||||
if not has_item then return end
|
if not has_item then return end
|
||||||
end
|
end
|
||||||
data.item = item
|
data.item = item
|
||||||
@ -254,7 +266,8 @@ minetest.register_craftitem("craftguide:book", {
|
|||||||
craftguide:get_items(player_name)
|
craftguide:get_items(player_name)
|
||||||
craftguide:get_formspec(player_name)
|
craftguide:get_formspec(player_name)
|
||||||
else
|
else
|
||||||
minetest.show_formspec(player_name, "craftguide:book", datas[player_name].formspec)
|
minetest.show_formspec(player_name, "craftguide:book",
|
||||||
|
datas[player_name].formspec)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
BIN
textures/craftguide_arrow.png
Normal file
BIN
textures/craftguide_arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 242 B |
Loading…
Reference in New Issue
Block a user