Use table.concat to build formspecs, style cleanups
This commit is contained in:
parent
e9b4b52dc1
commit
b871ccfc41
99
bags.lua
99
bags.lua
@ -9,18 +9,19 @@ local F = minetest.formspec_escape
|
|||||||
unified_inventory.register_page("bags", {
|
unified_inventory.register_page("bags", {
|
||||||
get_formspec = function(player)
|
get_formspec = function(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local formspec = "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]"
|
return { formspec = table.concat({
|
||||||
formspec = formspec.."label[0,0;"..F(S("Bags")).."]"
|
"background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]",
|
||||||
formspec = formspec.."button[0,2;2,0.5;bag1;"..F(S("Bag @1", 1)).."]"
|
"label[0,0;" .. F(S("Bags")) .. "]",
|
||||||
formspec = formspec.."button[2,2;2,0.5;bag2;"..F(S("Bag @1", 2)).."]"
|
"button[0,2;2,0.5;bag1;" .. F(S("Bag @1", 1)) .. "]",
|
||||||
formspec = formspec.."button[4,2;2,0.5;bag3;"..F(S("Bag @1", 3)).."]"
|
"button[2,2;2,0.5;bag2;" .. F(S("Bag @1", 2)) .. "]",
|
||||||
formspec = formspec.."button[6,2;2,0.5;bag4;"..F(S("Bag @1", 4)).."]"
|
"button[4,2;2,0.5;bag3;" .. F(S("Bag @1", 3)) .. "]",
|
||||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
"button[6,2;2,0.5;bag4;" .. F(S("Bag @1", 4)) .. "]",
|
||||||
formspec = formspec.."list[detached:"..F(player_name).."_bags;bag1;0.5,1;1,1;]"
|
"listcolors[#00000000;#00000000]",
|
||||||
formspec = formspec.."list[detached:"..F(player_name).."_bags;bag2;2.5,1;1,1;]"
|
"list[detached:" .. F(player_name) .. "_bags;bag1;0.5,1;1,1;]",
|
||||||
formspec = formspec.."list[detached:"..F(player_name).."_bags;bag3;4.5,1;1,1;]"
|
"list[detached:" .. F(player_name) .. "_bags;bag2;2.5,1;1,1;]",
|
||||||
formspec = formspec.."list[detached:"..F(player_name).."_bags;bag4;6.5,1;1,1;]"
|
"list[detached:" .. F(player_name) .. "_bags;bag3;4.5,1;1,1;]",
|
||||||
return {formspec=formspec}
|
"list[detached:" .. F(player_name) .. "_bags;bag4;6.5,1;1,1;]"
|
||||||
|
}) }
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -38,37 +39,39 @@ local function get_player_bag_stack(player, i)
|
|||||||
}):get_stack("bag" .. i, 1)
|
}):get_stack("bag" .. i, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = 1, 4 do
|
for bag_i = 1, 4 do
|
||||||
local bi = i
|
unified_inventory.register_page("bag" .. bag_i, {
|
||||||
unified_inventory.register_page("bag"..bi, {
|
|
||||||
get_formspec = function(player)
|
get_formspec = function(player)
|
||||||
local stack = get_player_bag_stack(player, bi)
|
local stack = get_player_bag_stack(player, bag_i)
|
||||||
local image = stack:get_definition().inventory_image
|
local image = stack:get_definition().inventory_image
|
||||||
local formspec = ("image[7,0;1,1;"..image.."]"
|
local fs = {
|
||||||
.."label[0,0;"..F(S("Bag @1", bi)).."]"
|
"image[7,0;1,1;" .. image .. "]",
|
||||||
.."listcolors[#00000000;#00000000]"
|
"label[0,0;" .. F(S("Bag @1", bag_i)) .. "]",
|
||||||
.."list[current_player;bag"..bi.."contents;0,1;8,3;]"
|
"listcolors[#00000000;#00000000]",
|
||||||
.."listring[current_name;bag"..bi.."contents]"
|
"list[current_player;bag" .. bag_i .. "contents;0,1;8,3;]",
|
||||||
.."listring[current_player;main]")
|
"listring[current_name;bag" .. bag_i .. "contents]",
|
||||||
|
"listring[current_player;main]"
|
||||||
|
}
|
||||||
local slots = stack:get_definition().groups.bagslots
|
local slots = stack:get_definition().groups.bagslots
|
||||||
if slots == 8 then
|
if slots == 8 then
|
||||||
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_sm_form.png]"
|
fs[#fs + 1] = "background[0.06,0.99;7.92,7.52;ui_bags_sm_form.png]"
|
||||||
elseif slots == 16 then
|
elseif slots == 16 then
|
||||||
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_med_form.png]"
|
fs[#fs + 1] = "background[0.06,0.99;7.92,7.52;ui_bags_med_form.png]"
|
||||||
elseif slots == 24 then
|
elseif slots == 24 then
|
||||||
formspec = formspec.."background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]"
|
fs[#fs + 1] = "background[0.06,0.99;7.92,7.52;ui_bags_lg_form.png]"
|
||||||
end
|
end
|
||||||
local player_name = player:get_player_name() -- For if statement.
|
local player_name = player:get_player_name() -- For if statement.
|
||||||
if unified_inventory.trash_enabled or unified_inventory.is_creative(player_name) or minetest.get_player_privs(player_name).give then
|
if unified_inventory.trash_enabled
|
||||||
formspec = (formspec.."background[6.06,0;0.92,0.92;ui_bags_trash.png]"
|
or unified_inventory.is_creative(player_name)
|
||||||
.."list[detached:trash;main;6,0.1;1,1;]")
|
or minetest.get_player_privs(player_name).give then
|
||||||
|
fs[#fs + 1] = "background[6.06,0;0.92,0.92;ui_bags_trash.png]"
|
||||||
|
.. "list[detached:trash;main;6,0.1;1,1;]"
|
||||||
end
|
end
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
for i = 1, 4 do
|
for i = 1, 4 do
|
||||||
local def = get_player_bag_stack(player, i):get_definition()
|
local def = get_player_bag_stack(player, i):get_definition()
|
||||||
local button
|
|
||||||
if def.groups.bagslots then
|
if def.groups.bagslots then
|
||||||
local list_name = "bag"..i.."contents"
|
local list_name = "bag" .. i .. "contents"
|
||||||
local size = inv:get_size(list_name)
|
local size = inv:get_size(list_name)
|
||||||
local used = 0
|
local used = 0
|
||||||
for si = 1, size do
|
for si = 1, size do
|
||||||
@ -78,14 +81,12 @@ for i = 1, 4 do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local img = def.inventory_image
|
local img = def.inventory_image
|
||||||
local label = F(S("Bag @1", i)).."\n"..used.."/"..size
|
local label = F(S("Bag @1", i)) .. "\n" .. used .. "/" .. size
|
||||||
button = "image_button["..(i+1)..",0;1,1;"..img..";bag"..i..";"..label.."]"
|
fs[#fs + 1] = string.format("image_button[%i,0;1,1;%s;bag%i;%s]",
|
||||||
else
|
i + 1, img, i, label)
|
||||||
button = ""
|
|
||||||
end
|
end
|
||||||
formspec = formspec..button
|
|
||||||
end
|
end
|
||||||
return {formspec=formspec}
|
return { formspec = table.concat(fs) }
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@ -95,12 +96,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
for i = 1, 4 do
|
for i = 1, 4 do
|
||||||
if fields["bag"..i] then
|
if fields["bag" .. i] then
|
||||||
local stack = get_player_bag_stack(player, i)
|
local stack = get_player_bag_stack(player, i)
|
||||||
if not stack:get_definition().groups.bagslots then
|
if not stack:get_definition().groups.bagslots then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
unified_inventory.set_inventory_formspec(player, "bag"..i)
|
unified_inventory.set_inventory_formspec(player, "bag" .. i)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -110,7 +111,7 @@ local function save_bags_metadata(player, bags_inv)
|
|||||||
local is_empty = true
|
local is_empty = true
|
||||||
local bags = {}
|
local bags = {}
|
||||||
for i = 1, 4 do
|
for i = 1, 4 do
|
||||||
local bag = "bag"..i
|
local bag = "bag" .. i
|
||||||
if not bags_inv:is_empty(bag) then
|
if not bags_inv:is_empty(bag) then
|
||||||
-- Stack limit is 1, otherwise use stack:to_string()
|
-- Stack limit is 1, otherwise use stack:to_string()
|
||||||
bags[i] = bags_inv:get_stack(bag, 1):get_name()
|
bags[i] = bags_inv:get_stack(bag, 1):get_name()
|
||||||
@ -133,7 +134,7 @@ local function load_bags_metadata(player, bags_inv)
|
|||||||
if not bags_meta then
|
if not bags_meta then
|
||||||
-- Backwards compatiblity
|
-- Backwards compatiblity
|
||||||
for i = 1, 4 do
|
for i = 1, 4 do
|
||||||
local bag = "bag"..i
|
local bag = "bag" .. i
|
||||||
if not player_inv:is_empty(bag) then
|
if not player_inv:is_empty(bag) then
|
||||||
-- Stack limit is 1, otherwise use stack:to_string()
|
-- Stack limit is 1, otherwise use stack:to_string()
|
||||||
bags[i] = player_inv:get_stack(bag, 1):get_name()
|
bags[i] = player_inv:get_stack(bag, 1):get_name()
|
||||||
@ -143,7 +144,7 @@ local function load_bags_metadata(player, bags_inv)
|
|||||||
end
|
end
|
||||||
-- Fill detached slots
|
-- Fill detached slots
|
||||||
for i = 1, 4 do
|
for i = 1, 4 do
|
||||||
local bag = "bag"..i
|
local bag = "bag" .. i
|
||||||
bags_inv:set_size(bag, 1)
|
bags_inv:set_size(bag, 1)
|
||||||
bags_inv:set_stack(bag, 1, bags[i] or "")
|
bags_inv:set_stack(bag, 1, bags[i] or "")
|
||||||
end
|
end
|
||||||
@ -155,7 +156,7 @@ local function load_bags_metadata(player, bags_inv)
|
|||||||
|
|
||||||
-- Clean up deprecated garbage after saving
|
-- Clean up deprecated garbage after saving
|
||||||
for i = 1, 4 do
|
for i = 1, 4 do
|
||||||
local bag = "bag"..i
|
local bag = "bag" .. i
|
||||||
player_inv:set_size(bag, 0)
|
player_inv:set_size(bag, 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -163,9 +164,9 @@ end
|
|||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local player_inv = player:get_inventory()
|
local player_inv = player:get_inventory()
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local bags_inv = minetest.create_detached_inventory(player_name.."_bags",{
|
local bags_inv = minetest.create_detached_inventory(player_name .. "_bags",{
|
||||||
on_put = function(inv, listname, index, stack, player)
|
on_put = function(inv, listname, index, stack, player)
|
||||||
player:get_inventory():set_size(listname.."contents",
|
player:get_inventory():set_size(listname .. "contents",
|
||||||
stack:get_definition().groups.bagslots)
|
stack:get_definition().groups.bagslots)
|
||||||
save_bags_metadata(player, inv)
|
save_bags_metadata(player, inv)
|
||||||
end,
|
end,
|
||||||
@ -175,14 +176,14 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
local player_inv = player:get_inventory()
|
local player_inv = player:get_inventory()
|
||||||
local old_slots = player_inv:get_size(listname.."contents")
|
local old_slots = player_inv:get_size(listname .. "contents")
|
||||||
|
|
||||||
if new_slots >= old_slots then
|
if new_slots >= old_slots then
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- using a smaller bag, make sure it fits
|
-- using a smaller bag, make sure it fits
|
||||||
local old_list = player_inv:get_list(listname.."contents")
|
local old_list = player_inv:get_list(listname .. "contents")
|
||||||
local new_list = {}
|
local new_list = {}
|
||||||
local slots_used = 0
|
local slots_used = 0
|
||||||
local use_new_list = false
|
local use_new_list = false
|
||||||
@ -196,7 +197,7 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
end
|
end
|
||||||
if new_slots >= slots_used then
|
if new_slots >= slots_used then
|
||||||
if use_new_list then
|
if use_new_list then
|
||||||
player_inv:set_list(listname.."contents", new_list)
|
player_inv:set_list(listname .. "contents", new_list)
|
||||||
end
|
end
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
@ -204,13 +205,13 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
return 0
|
return 0
|
||||||
end,
|
end,
|
||||||
allow_take = function(inv, listname, index, stack, player)
|
allow_take = function(inv, listname, index, stack, player)
|
||||||
if player:get_inventory():is_empty(listname.."contents") then
|
if player:get_inventory():is_empty(listname .. "contents") then
|
||||||
return stack:get_count()
|
return stack:get_count()
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end,
|
end,
|
||||||
on_take = function(inv, listname, index, stack, player)
|
on_take = function(inv, listname, index, stack, player)
|
||||||
player:get_inventory():set_size(listname.."contents", 0)
|
player:get_inventory():set_size(listname .. "contents", 0)
|
||||||
save_bags_metadata(player, inv)
|
save_bags_metadata(player, inv)
|
||||||
end,
|
end,
|
||||||
allow_move = function()
|
allow_move = function()
|
||||||
|
28
group.lua
28
group.lua
@ -2,7 +2,12 @@ local S = unified_inventory.gettext
|
|||||||
|
|
||||||
function unified_inventory.canonical_item_spec_matcher(spec)
|
function unified_inventory.canonical_item_spec_matcher(spec)
|
||||||
local specname = ItemStack(spec):get_name()
|
local specname = ItemStack(spec):get_name()
|
||||||
if specname:sub(1, 6) == "group:" then
|
if specname:sub(1, 6) ~= "group:" then
|
||||||
|
return function (itemname)
|
||||||
|
return itemname == specname
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local group_names = specname:sub(7):split(",")
|
local group_names = specname:sub(7):split(",")
|
||||||
return function (itemname)
|
return function (itemname)
|
||||||
local itemdef = minetest.registered_items[itemname]
|
local itemdef = minetest.registered_items[itemname]
|
||||||
@ -13,9 +18,6 @@ function unified_inventory.canonical_item_spec_matcher(spec)
|
|||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
else
|
|
||||||
return function (itemname) return itemname == specname end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function unified_inventory.item_matches_spec(item, spec)
|
function unified_inventory.item_matches_spec(item, spec)
|
||||||
@ -25,23 +27,11 @@ end
|
|||||||
|
|
||||||
function unified_inventory.extract_groupnames(groupname)
|
function unified_inventory.extract_groupnames(groupname)
|
||||||
local specname = ItemStack(groupname):get_name()
|
local specname = ItemStack(groupname):get_name()
|
||||||
if specname:sub(1, 6) == "group:" then
|
if specname:sub(1, 6) ~= "group:" then
|
||||||
local group_names = specname:sub(7):split(",")
|
|
||||||
if #group_names == 1 then
|
|
||||||
return group_names[1], 1
|
|
||||||
end
|
|
||||||
local s = ""
|
|
||||||
for g=1,#group_names do
|
|
||||||
if g > 1 then
|
|
||||||
-- List connector
|
|
||||||
s = s .. S(" and ")
|
|
||||||
end
|
|
||||||
s = s .. group_names[g]
|
|
||||||
end
|
|
||||||
return s, #group_names
|
|
||||||
else
|
|
||||||
return nil, 0
|
return nil, 0
|
||||||
end
|
end
|
||||||
|
local group_names = specname:sub(7):split(",")
|
||||||
|
return table.concat(group_names, S(" and ")), #group_names
|
||||||
end
|
end
|
||||||
|
|
||||||
unified_inventory.registered_group_items = {
|
unified_inventory.registered_group_items = {
|
||||||
|
117
register.lua
117
register.lua
@ -266,64 +266,77 @@ unified_inventory.register_page("craftguide", {
|
|||||||
|
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local player_privs = minetest.get_player_privs(player_name)
|
local player_privs = minetest.get_player_privs(player_name)
|
||||||
local formspec = ""
|
local fs = {
|
||||||
formspec = formspec.."background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]"
|
"background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]",
|
||||||
formspec = formspec.."label[0,"..formheadery..";" .. F(S("Crafting Guide")) .. "]"
|
"label[0,"..formheadery..";" .. F(S("Crafting Guide")) .. "]",
|
||||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
"listcolors[#00000000;#00000000]"
|
||||||
|
}
|
||||||
local item_name = unified_inventory.current_item[player_name]
|
local item_name = unified_inventory.current_item[player_name]
|
||||||
if not item_name then return {formspec=formspec} end
|
if not item_name then
|
||||||
|
return { formspec = table.concat(fs) }
|
||||||
|
end
|
||||||
|
|
||||||
local item_name_shown
|
local item_name_shown
|
||||||
if minetest.registered_items[item_name] and minetest.registered_items[item_name].description then
|
if minetest.registered_items[item_name]
|
||||||
item_name_shown = string.format(S("%s (%s)"), minetest.registered_items[item_name].description, item_name)
|
and minetest.registered_items[item_name].description then
|
||||||
|
item_name_shown = string.format(S("%s (%s)"),
|
||||||
|
minetest.registered_items[item_name].description, item_name)
|
||||||
else
|
else
|
||||||
item_name_shown = item_name
|
item_name_shown = item_name
|
||||||
end
|
end
|
||||||
|
|
||||||
local dir = unified_inventory.current_craft_direction[player_name]
|
local dir = unified_inventory.current_craft_direction[player_name]
|
||||||
local rdir
|
local rdir = dir == "recipe" and "usage" or "recipe"
|
||||||
if dir == "recipe" then rdir = "usage" end
|
|
||||||
if dir == "usage" then rdir = "recipe" end
|
|
||||||
local crafts = unified_inventory.crafts_for[dir][item_name]
|
local crafts = unified_inventory.crafts_for[dir][item_name]
|
||||||
local alternate = unified_inventory.alternate[player_name]
|
local alternate = unified_inventory.alternate[player_name]
|
||||||
local alternates, craft
|
local alternates, craft
|
||||||
if crafts ~= nil and #crafts > 0 then
|
if crafts and #crafts > 0 then
|
||||||
alternates = #crafts
|
alternates = #crafts
|
||||||
craft = crafts[alternate]
|
craft = crafts[alternate]
|
||||||
end
|
end
|
||||||
local has_give = player_privs.give or unified_inventory.is_creative(player_name)
|
local has_give = player_privs.give or unified_inventory.is_creative(player_name)
|
||||||
|
|
||||||
formspec = formspec.."background[0.5,"..(formspecy + 0.2)..";8,3;ui_craftguide_form.png]"
|
fs[#fs + 1] = "background[0.5,"..(formspecy + 0.2)..";8,3;ui_craftguide_form.png]"
|
||||||
formspec = formspec.."textarea["..craftresultx..","..craftresulty
|
fs[#fs + 1] = string.format("textarea[%f,%f;10,1;;%s: %s;]",
|
||||||
..";10,1;;"..F(role_text[dir])..": "..item_name_shown..";]"
|
craftresultx, craftresulty, F(role_text[dir]), item_name_shown)
|
||||||
formspec = formspec..stack_image_button(0, formspecy, 1.1, 1.1, "item_button_"
|
fs[#fs + 1] = stack_image_button(0, formspecy, 1.1, 1.1,
|
||||||
.. rdir .. "_", ItemStack(item_name))
|
"item_button_" .. rdir .. "_", ItemStack(item_name))
|
||||||
|
|
||||||
if not craft then
|
if not craft then
|
||||||
formspec = formspec.."label[5.5,"..(formspecy + 2.35)..";"
|
-- No craft recipes available for this item.
|
||||||
..F(no_recipe_text[dir]).."]"
|
fs[#fs + 1] = "label[5.5,"..(formspecy + 2.35)..";"
|
||||||
|
.. F(no_recipe_text[dir]) .. "]"
|
||||||
local no_pos = dir == "recipe" and 4.5 or 6.5
|
local no_pos = dir == "recipe" and 4.5 or 6.5
|
||||||
local item_pos = dir == "recipe" and 6.5 or 4.5
|
local item_pos = dir == "recipe" and 6.5 or 4.5
|
||||||
formspec = formspec.."image["..no_pos..","..formspecy..";1.1,1.1;ui_no.png]"
|
fs[#fs + 1] = "image["..no_pos..","..formspecy..";1.1,1.1;ui_no.png]"
|
||||||
formspec = formspec..stack_image_button(item_pos, formspecy, 1.1, 1.1, "item_button_"
|
fs[#fs + 1] = stack_image_button(item_pos, formspecy, 1.1, 1.1,
|
||||||
..other_dir[dir].."_", ItemStack(item_name))
|
"item_button_" .. other_dir[dir] .. "_", ItemStack(item_name))
|
||||||
if has_give then
|
if has_give then
|
||||||
formspec = formspec.."label[0,"..(formspecy + 2.10)..";" .. F(S("Give me:")) .. "]"
|
fs[#fs + 1] = "label[0," .. (formspecy + 2.10) .. ";" .. F(S("Give me:")) .. "]"
|
||||||
.."button[0, "..(formspecy + 2.7)..";0.6,0.5;craftguide_giveme_1;1]"
|
.. "button[0, " .. (formspecy + 2.7) .. ";0.6,0.5;craftguide_giveme_1;1]"
|
||||||
.."button[0.6,"..(formspecy + 2.7)..";0.7,0.5;craftguide_giveme_10;10]"
|
.. "button[0.6," .. (formspecy + 2.7) .. ";0.7,0.5;craftguide_giveme_10;10]"
|
||||||
.."button[1.3,"..(formspecy + 2.7)..";0.8,0.5;craftguide_giveme_99;99]"
|
.. "button[1.3," .. (formspecy + 2.7) .. ";0.8,0.5;craftguide_giveme_99;99]"
|
||||||
end
|
end
|
||||||
return {formspec = formspec}
|
return { formspec = table.concat(fs) }
|
||||||
end
|
end
|
||||||
|
|
||||||
local craft_type = unified_inventory.registered_craft_types[craft.type] or
|
local craft_type = unified_inventory.registered_craft_types[craft.type] or
|
||||||
unified_inventory.craft_type_defaults(craft.type, {})
|
unified_inventory.craft_type_defaults(craft.type, {})
|
||||||
if craft_type.icon then
|
if craft_type.icon then
|
||||||
formspec = formspec..string.format(" image[%f,%f;%f,%f;%s]",5.7,(formspecy + 0.05),0.5,0.5,craft_type.icon)
|
fs[#fs + 1] = string.format("image[%f,%f;%f,%f;%s]",
|
||||||
|
5.7, (formspecy + 0.05), 0.5, 0.5, craft_type.icon)
|
||||||
end
|
end
|
||||||
formspec = formspec.."label[5.5,"..(formspecy + 1)..";" .. F(craft_type.description).."]"
|
fs[#fs + 1] = "label[5.5,"..(formspecy + 1)..";" .. F(craft_type.description).."]"
|
||||||
formspec = formspec..stack_image_button(6.5, formspecy, 1.1, 1.1, "item_button_usage_", ItemStack(craft.output))
|
fs[#fs + 1] = stack_image_button(6.5, formspecy, 1.1, 1.1,
|
||||||
local display_size = craft_type.dynamic_display_size and craft_type.dynamic_display_size(craft) or { width = craft_type.width, height = craft_type.height }
|
"item_button_usage_", ItemStack(craft.output))
|
||||||
local craft_width = craft_type.get_shaped_craft_width and craft_type.get_shaped_craft_width(craft) or display_size.width
|
|
||||||
|
local display_size = craft_type.dynamic_display_size
|
||||||
|
and craft_type.dynamic_display_size(craft)
|
||||||
|
or { width = craft_type.width, height = craft_type.height }
|
||||||
|
local craft_width = craft_type.get_shaped_craft_width
|
||||||
|
and craft_type.get_shaped_craft_width(craft)
|
||||||
|
or display_size.width
|
||||||
|
|
||||||
-- This keeps recipes aligned to the right,
|
-- This keeps recipes aligned to the right,
|
||||||
-- so that they're close to the arrow.
|
-- so that they're close to the arrow.
|
||||||
@ -358,47 +371,45 @@ unified_inventory.register_page("craftguide", {
|
|||||||
local xof = (fx-1) * of + of
|
local xof = (fx-1) * of + of
|
||||||
local yof = (y-1) * of + 1
|
local yof = (y-1) * of + 1
|
||||||
if item then
|
if item then
|
||||||
formspec = formspec..stack_image_button(
|
fs[#fs + 1] = stack_image_button(
|
||||||
xoffset - xof, formspecy - 1 + yof, bsize_w, bsize_h,
|
xoffset - xof, formspecy - 1 + yof, bsize_w, bsize_h,
|
||||||
"item_button_recipe_",
|
"item_button_recipe_",
|
||||||
ItemStack(item))
|
ItemStack(item))
|
||||||
else
|
else
|
||||||
-- Fake buttons just to make grid
|
-- Fake buttons just to make grid
|
||||||
formspec = formspec.."image_button["
|
fs[#fs + 1] = string.format("image_button[%f,%f;%f,%f;ui_blank_image.png;;]",
|
||||||
..tostring(xoffset - xof)..","..tostring(formspecy - 1 + yof)
|
xoffset - xof, formspecy - 1 + yof, bsize_w, bsize_h)
|
||||||
..";"..bsize_w..","..bsize_h..";ui_blank_image.png;;]"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Error
|
-- Error
|
||||||
formspec = formspec.."label["
|
fs[#fs + 1] = string.format("label[2,%f;%s]",
|
||||||
..tostring(2)..","..tostring(formspecy)
|
formspecy, F(S("This recipe is too\nlarge to be displayed.")))
|
||||||
..";"..F(S("This recipe is too\nlarge to be displayed.")).."]"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if craft_type.uses_crafting_grid and display_size.width <= 3 then
|
if craft_type.uses_crafting_grid and display_size.width <= 3 then
|
||||||
formspec = formspec.."label[0,"..(formspecy + 0.9)..";" .. F(S("To craft grid:")) .. "]"
|
fs[#fs + 1] = "label[0," .. (formspecy + 0.9) .. ";" .. F(S("To craft grid:")) .. "]"
|
||||||
.."button[0, "..(formspecy + 1.5)..";0.6,0.5;craftguide_craft_1;1]"
|
.. "button[0, " .. (formspecy + 1.5) .. ";0.6,0.5;craftguide_craft_1;1]"
|
||||||
.."button[0.6,"..(formspecy + 1.5)..";0.7,0.5;craftguide_craft_10;10]"
|
.. "button[0.6," .. (formspecy + 1.5) .. ";0.7,0.5;craftguide_craft_10;10]"
|
||||||
.."button[1.3,"..(formspecy + 1.5)..";0.8,0.5;craftguide_craft_max;" .. F(S("All")) .. "]"
|
.. "button[1.3," .. (formspecy + 1.5) .. ";0.8,0.5;craftguide_craft_max;" .. F(S("All")) .. "]"
|
||||||
end
|
end
|
||||||
if has_give then
|
if has_give then
|
||||||
formspec = formspec.."label[0,"..(formspecy + 2.1)..";" .. F(S("Give me:")) .. "]"
|
fs[#fs + 1] = "label[0," .. (formspecy + 2.1) .. ";" .. F(S("Give me:")) .. "]"
|
||||||
.."button[0, "..(formspecy + 2.7)..";0.6,0.5;craftguide_giveme_1;1]"
|
.. "button[0, " .. (formspecy + 2.7) .. ";0.6,0.5;craftguide_giveme_1;1]"
|
||||||
.."button[0.6,"..(formspecy + 2.7)..";0.7,0.5;craftguide_giveme_10;10]"
|
.. "button[0.6," .. (formspecy + 2.7) .. ";0.7,0.5;craftguide_giveme_10;10]"
|
||||||
.."button[1.3,"..(formspecy + 2.7)..";0.8,0.5;craftguide_giveme_99;99]"
|
.. "button[1.3," .. (formspecy + 2.7) .. ";0.8,0.5;craftguide_giveme_99;99]"
|
||||||
end
|
end
|
||||||
|
|
||||||
if alternates and alternates > 1 then
|
if alternates and alternates > 1 then
|
||||||
formspec = formspec.."label[5.5,"..(formspecy + 1.6)..";"
|
fs[#fs + 1] = "label[5.5," .. (formspecy + 1.6) .. ";"
|
||||||
..string.format(F(recipe_text[dir]), alternate, alternates).."]"
|
.. string.format(F(recipe_text[dir]), alternate, alternates) .. "]"
|
||||||
.."image_button[5.5,"..(formspecy + 2)..";1,1;ui_left_icon.png;alternate_prev;]"
|
.. "image_button[5.5," .. (formspecy + 2) .. ";1,1;ui_left_icon.png;alternate_prev;]"
|
||||||
.."image_button[6.5,"..(formspecy + 2)..";1,1;ui_right_icon.png;alternate;]"
|
.. "image_button[6.5," .. (formspecy + 2) .. ";1,1;ui_right_icon.png;alternate;]"
|
||||||
.."tooltip[alternate_prev;"..F(prev_alt_text[dir]).."]"
|
.. "tooltip[alternate_prev;" .. F(prev_alt_text[dir]) .. "]"
|
||||||
.."tooltip[alternate;"..F(next_alt_text[dir]).."]"
|
.. "tooltip[alternate;" .. F(next_alt_text[dir]) .. "]"
|
||||||
end
|
end
|
||||||
return {formspec = formspec}
|
return { formspec = table.concat(fs) }
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user