mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-15 23:51:05 +01:00
Show preview of new banner pattern when crafting it
This commit is contained in:
parent
e3d5b8a94c
commit
bee4dc4854
2 changed files with 112 additions and 8 deletions
|
@ -35,6 +35,49 @@ mcl_banners.colors = {
|
||||||
["unicolor_light_blue"] = {"light_blue", S("Light Blue Banner"), "mcl_wool:light_blue", "#4040CF", "mcl_dye:lightblue", N("Light Blue") },
|
["unicolor_light_blue"] = {"light_blue", S("Light Blue Banner"), "mcl_wool:light_blue", "#4040CF", "mcl_dye:lightblue", N("Light Blue") },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
local pattern_names = {
|
||||||
|
"",
|
||||||
|
"border",
|
||||||
|
"bricks",
|
||||||
|
"circle",
|
||||||
|
"creeper",
|
||||||
|
"cross",
|
||||||
|
"curly_border",
|
||||||
|
"diagonal_up_left",
|
||||||
|
"diagonal_up_right",
|
||||||
|
"diagonal_right",
|
||||||
|
"diagonal_left",
|
||||||
|
"flower",
|
||||||
|
"gradient",
|
||||||
|
"gradient_up",
|
||||||
|
"half_horizontal_bottom",
|
||||||
|
"half_horizontal",
|
||||||
|
"half_vertical",
|
||||||
|
"half_vertical_right",
|
||||||
|
"thing",
|
||||||
|
"rhombus",
|
||||||
|
"skull",
|
||||||
|
"small_stripes",
|
||||||
|
"square_bottom_left",
|
||||||
|
"square_bottom_right",
|
||||||
|
"square_top_left",
|
||||||
|
"square_top_right",
|
||||||
|
"straight_cross",
|
||||||
|
"stripe_bottom",
|
||||||
|
"stripe_center",
|
||||||
|
"stripe_downleft",
|
||||||
|
"stripe_downright",
|
||||||
|
"stripe_left",
|
||||||
|
"stripe_middle",
|
||||||
|
"stripe_right",
|
||||||
|
"stripe_top",
|
||||||
|
"triangle_bottom",
|
||||||
|
"triangle_top",
|
||||||
|
"triangles_bottom",
|
||||||
|
"triangles_top",
|
||||||
|
}
|
||||||
|
|
||||||
local colors_reverse = {}
|
local colors_reverse = {}
|
||||||
for k,v in pairs(mcl_banners.colors) do
|
for k,v in pairs(mcl_banners.colors) do
|
||||||
colors_reverse["mcl_banners:banner_item_"..v[1]] = k
|
colors_reverse["mcl_banners:banner_item_"..v[1]] = k
|
||||||
|
@ -300,24 +343,72 @@ minetest.register_node("mcl_banners:hanging_banner", {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- for pattern_name, pattern in pairs(patterns) do
|
||||||
for colorid, colortab in pairs(mcl_banners.colors) do
|
for colorid, colortab in pairs(mcl_banners.colors) do
|
||||||
|
for i, pattern_name in ipairs(pattern_names) do
|
||||||
local itemid = colortab[1]
|
local itemid = colortab[1]
|
||||||
local desc = colortab[2]
|
local desc = colortab[2]
|
||||||
local wool = colortab[3]
|
local wool = colortab[3]
|
||||||
local colorize = colortab[4]
|
local colorize = colortab[4]
|
||||||
|
|
||||||
local itemstring = "mcl_banners:banner_item_"..itemid
|
local itemstring
|
||||||
local inv
|
if pattern_name == "" then
|
||||||
if colorize then
|
itemstring = "mcl_banners:banner_item_" .. itemid
|
||||||
inv = "mcl_banners_item_base.png^(mcl_banners_item_overlay.png^[colorize:"..colorize..")"
|
|
||||||
else
|
else
|
||||||
inv = "mcl_banners_item_base.png^mcl_banners_item_overlay.png"
|
itemstring = "mcl_banners:banner_preview" .. "_" .. pattern_name .. "_" .. itemid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local inv
|
||||||
|
local base
|
||||||
|
local finished_banner
|
||||||
|
if pattern_name == "" then
|
||||||
|
if colorize then
|
||||||
|
-- Base texture with base color
|
||||||
|
base = "mcl_banners_item_base.png^(mcl_banners_item_overlay.png^[colorize:"..colorize..")^[resize:32x32"
|
||||||
|
else
|
||||||
|
base = "mcl_banners_item_base.png^mcl_banners_item_overlay.png^[resize:32x32"
|
||||||
|
end
|
||||||
|
finished_banner = base
|
||||||
|
else
|
||||||
|
-- Banner item preview background
|
||||||
|
base = "mcl_banners_item_base.png^(mcl_banners_item_overlay.png^[colorize:#CCCCCC)^[resize:32x32"
|
||||||
|
|
||||||
|
desc = S("Preview Banner")
|
||||||
|
|
||||||
|
local pattern = "mcl_banners_" .. pattern_name .. ".png"
|
||||||
|
local color = colorize
|
||||||
|
|
||||||
|
-- Generate layer texture
|
||||||
|
|
||||||
|
-- TODO: The layer texture in the icon is squished
|
||||||
|
-- weirdly because the width/height aspect ratio of
|
||||||
|
-- the banner icon is 1:1.5, whereas the aspect ratio
|
||||||
|
-- of the banner entity is 1:2. A solution would be to
|
||||||
|
-- redraw the pattern textures as low-resolution pixel
|
||||||
|
-- art and use that instead.
|
||||||
|
|
||||||
|
local layer = "(([combine:20x40:-2,-2="..pattern.."^[resize:16x24^[colorize:"..color..":"..layer_ratio.."))"
|
||||||
|
|
||||||
|
function escape(text)
|
||||||
|
return text:gsub("%^", "\\%^"):gsub(":", "\\:") -- :gsub("%(", "\\%("):gsub("%)", "\\%)")
|
||||||
|
end
|
||||||
|
|
||||||
|
finished_banner = "[combine:32x32:0,0=" .. escape(base) .. ":8,4=" .. escape(layer)
|
||||||
|
end
|
||||||
|
|
||||||
|
inv = finished_banner
|
||||||
|
|
||||||
-- Banner items.
|
-- Banner items.
|
||||||
-- This is the player-visible banner item. It comes in 16 base colors.
|
-- This is the player-visible banner item. It comes in 16 base colors with a lot of patterns.
|
||||||
-- The multiple items are really only needed for the different item images.
|
-- The multiple items are really only needed for the different item images.
|
||||||
-- TODO: Combine the items into only 1 item.
|
-- TODO: Combine the items into only 1 item.
|
||||||
|
local groups
|
||||||
|
if pattern_name == "" then
|
||||||
|
groups = { banner = 1, deco_block = 1, flammable = -1 }
|
||||||
|
else
|
||||||
|
groups = { not_in_creative_inventory = 1 }
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_craftitem(itemstring, {
|
minetest.register_craftitem(itemstring, {
|
||||||
description = desc,
|
description = desc,
|
||||||
_tt_help = S("Paintable decoration"),
|
_tt_help = S("Paintable decoration"),
|
||||||
|
@ -326,7 +417,7 @@ for colorid, colortab in pairs(mcl_banners.colors) do
|
||||||
wield_image = inv,
|
wield_image = inv,
|
||||||
-- Banner group groups together the banner items, but not the nodes.
|
-- Banner group groups together the banner items, but not the nodes.
|
||||||
-- Used for crafting.
|
-- Used for crafting.
|
||||||
groups = { banner = 1, deco_block = 1, flammable = -1 },
|
groups = groups,
|
||||||
stack_max = 16,
|
stack_max = 16,
|
||||||
|
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
|
@ -493,6 +584,7 @@ for colorid, colortab in pairs(mcl_banners.colors) do
|
||||||
doc.add_entry_alias("nodes", "mcl_banners:standing_banner", "craftitems", itemstring)
|
doc.add_entry_alias("nodes", "mcl_banners:standing_banner", "craftitems", itemstring)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if minetest.get_modpath("doc") then
|
if minetest.get_modpath("doc") then
|
||||||
-- Add item to node alias
|
-- Add item to node alias
|
||||||
|
|
|
@ -253,6 +253,11 @@ for colorid, colortab in pairs(mcl_banners.colors) do
|
||||||
dye_to_colorid_mapping[colortab[5]] = colorid
|
dye_to_colorid_mapping[colortab[5]] = colorid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local dye_to_itemid_mapping = {}
|
||||||
|
for colorid, colortab in pairs(mcl_banners.colors) do
|
||||||
|
dye_to_itemid_mapping[colortab[5]] = colortab[1]
|
||||||
|
end
|
||||||
|
|
||||||
-- Create a banner description containing all the layer names
|
-- Create a banner description containing all the layer names
|
||||||
mcl_banners.make_advanced_banner_description = function(description, layers)
|
mcl_banners.make_advanced_banner_description = function(description, layers)
|
||||||
if layers == nil or #layers == 0 then
|
if layers == nil or #layers == 0 then
|
||||||
|
@ -491,8 +496,15 @@ local banner_pattern_craft = function(itemstack, player, old_craft_grid, craft_i
|
||||||
imeta:set_string("description", ometa:get_string("description"))
|
imeta:set_string("description", ometa:get_string("description"))
|
||||||
imeta:set_string("name", mname)
|
imeta:set_string("name", mname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if craft_predict then
|
||||||
|
local itemid_prefix = "mcl_banners:banner_preview"
|
||||||
|
local coloritemid = dye_to_itemid_mapping[dye]
|
||||||
|
return ItemStack(itemid_prefix .. "_" .. matching_pattern .. "_" .. coloritemid)
|
||||||
|
else
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv)
|
minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv)
|
||||||
return banner_pattern_craft(itemstack, player, old_craft_grid, craft_inv, true)
|
return banner_pattern_craft(itemstack, player, old_craft_grid, craft_inv, true)
|
||||||
|
|
Loading…
Reference in a new issue