Merge pull request #71 from Wuzzy2/minicraft

Show crafting recipes correctly with size > 3
This commit is contained in:
Vanessa Ezekowitz 2016-08-14 16:17:08 -04:00 committed by GitHub
commit dba69b1f71
3 changed files with 38 additions and 6 deletions

@ -55,6 +55,7 @@ Show next recipe = Nächstes Rezept zeigen
Show next usage = Nächste Verwendung zeigen Show next usage = Nächste Verwendung zeigen
Show previous recipe = Vorheriges Rezept zeigen Show previous recipe = Vorheriges Rezept zeigen
Show previous usage = Vorherige Verwendung zeigen Show previous usage = Vorherige Verwendung zeigen
This recipe is too\nlarge to be displayed. = Dieses Rezept ist zu\ngroß, um angezeigt\nzu werden.
Recipe %d of %d = Rezept %d von %d Recipe %d of %d = Rezept %d von %d
Usage %d of %d = Verwendung %d von %d Usage %d of %d = Verwendung %d von %d
No recipes = Keine Rezepte No recipes = Keine Rezepte

@ -57,6 +57,8 @@ Show next recipe =
Show next usage = Show next usage =
Show previous recipe = Show previous recipe =
Show previous usage = Show previous usage =
# Shown for huge crafting recipes; try to keep the line length short and use multiple line breaks as needed
This recipe is too\nlarge to be displayed. =
Recipe %d of %d = Recipe %d of %d =
Usage %d of %d = Usage %d of %d =
No recipes = No recipes =

@ -188,7 +188,7 @@ local function stack_image_button(x, y, w, h, buttonname_prefix, item)
selectitem = group_item.sole and displayitem or name selectitem = group_item.sole and displayitem or name
end end
local label = show_is_group and "G" or "" local label = show_is_group and "G" or ""
return string.format("item_image_button[%f,%f;%u,%u;%s;%s;%s]", return string.format("item_image_button[%f,%f;%f,%f;%s;%s;%s]",
x, y, w, h, x, y, w, h,
minetest.formspec_escape(displayitem), minetest.formspec_escape(displayitem),
minetest.formspec_escape(buttonname_prefix..unified_inventory.mangle_for_formspec(selectitem)), minetest.formspec_escape(buttonname_prefix..unified_inventory.mangle_for_formspec(selectitem)),
@ -284,28 +284,57 @@ unified_inventory.register_page("craftguide", {
-- 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.
local xoffset = 1.5 + (3 - display_size.width) local xoffset = 5.5
-- Offset factor for crafting grids with side length > 4
local of = (3/math.max(3, math.max(display_size.width, display_size.height)))
local od = 0
-- Minimum grid size at which size optimazation measures kick in
local mini_craft_size = 6
if display_size.width >= mini_craft_size then
od = math.max(1, display_size.width - 2)
xoffset = xoffset - 0.1
end
-- Size modifier factor
local sf = math.min(1, of * (1.05 + 0.05*od))
-- Button size
local bsize_h = 1.1 * sf
local bsize_w = bsize_h
if display_size.width >= mini_craft_size then
bsize_w = 1.175 * sf
end
if (bsize_h > 0.35 and display_size.width) then
for y = 1, display_size.height do for y = 1, display_size.height do
for x = 1, display_size.width do for x = 1, display_size.width do
local item local item
if craft and x <= craft_width then if craft and x <= craft_width then
item = craft.items[(y-1) * craft_width + x] item = craft.items[(y-1) * craft_width + x]
end end
-- Flipped x, used to build formspec buttons from right to left
local fx = display_size.width - (x-1)
-- x offset, y offset
local xof = (fx-1) * of + of
local yof = (y-1) * of + 1
if item then if item then
formspec = formspec..stack_image_button( formspec = formspec..stack_image_button(
xoffset + x, formspecy - 1 + y, 1.1, 1.1, 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[" formspec = formspec.."image_button["
..tostring(xoffset + x)..","..tostring(formspecy - 1 + y) ..tostring(xoffset - xof)..","..tostring(formspecy - 1 + yof)
..";1,1;ui_blank_image.png;;]" ..";"..bsize_w..","..bsize_h..";ui_blank_image.png;;]"
end end
end end
end end
else
-- Error
formspec = formspec.."label["
..tostring(2)..","..tostring(formspecy)
..";"..minetest.formspec_escape(S("This recipe is too\nlarge to be displayed.")).."]"
end
if craft_type.uses_crafting_grid then if craft_type.uses_crafting_grid and display_size.width <= 3 then
formspec = formspec.."label[0,"..(formspecy + 0.9)..";" .. F("To craft grid:") .. "]" formspec = formspec.."label[0,"..(formspecy + 0.9)..";" .. F("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]"