Merge pull request #71 from Wuzzy2/minicraft
Show crafting recipes correctly with size > 3
This commit is contained in:
commit
dba69b1f71
@ -55,6 +55,7 @@ Show next recipe = Nächstes Rezept zeigen
|
||||
Show next usage = Nächste Verwendung zeigen
|
||||
Show previous recipe = Vorheriges Rezept 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
|
||||
Usage %d of %d = Verwendung %d von %d
|
||||
No recipes = Keine Rezepte
|
||||
|
@ -57,6 +57,8 @@ Show next recipe =
|
||||
Show next usage =
|
||||
Show previous recipe =
|
||||
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 =
|
||||
Usage %d of %d =
|
||||
No recipes =
|
||||
|
41
register.lua
41
register.lua
@ -188,7 +188,7 @@ local function stack_image_button(x, y, w, h, buttonname_prefix, item)
|
||||
selectitem = group_item.sole and displayitem or name
|
||||
end
|
||||
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,
|
||||
minetest.formspec_escape(displayitem),
|
||||
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,
|
||||
-- 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 x = 1, display_size.width do
|
||||
local item
|
||||
if craft and x <= craft_width then
|
||||
item = craft.items[(y-1) * craft_width + x]
|
||||
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
|
||||
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_",
|
||||
ItemStack(item))
|
||||
else
|
||||
-- Fake buttons just to make grid
|
||||
formspec = formspec.."image_button["
|
||||
..tostring(xoffset + x)..","..tostring(formspecy - 1 + y)
|
||||
..";1,1;ui_blank_image.png;;]"
|
||||
..tostring(xoffset - xof)..","..tostring(formspecy - 1 + yof)
|
||||
..";"..bsize_w..","..bsize_h..";ui_blank_image.png;;]"
|
||||
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:") .. "]"
|
||||
.."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]"
|
||||
|
Loading…
Reference in New Issue
Block a user