Fix display of group ingredients

Commit 043f6081452365daaa033c58e0738527ccb64c3d broke a couple of things
in the course of its refactoring.  This patch restores the "G" flag that
signals group ingredients, the preference for "default:" items as group
representatives (where a representative isn't specifically registered),
and the built-in registration of default:cobble as representative for
group:stone (because it's the most commonly-used item in that group).
This commit is contained in:
Zefram 2014-06-13 09:54:21 +01:00 committed by Diego Martinez
parent 7f4f0fd225
commit dbf98cb694
2 changed files with 9 additions and 6 deletions

@ -1,6 +1,7 @@
unified_inventory.registered_group_items = { unified_inventory.registered_group_items = {
mesecon_conductor_craftable = "mesecons:wire_00000000_off", mesecon_conductor_craftable = "mesecons:wire_00000000_off",
stone = "default:cobble",
wool = "wool:white", wool = "wool:white",
} }
@ -21,7 +22,7 @@ end
-- Among equally-preferred items, we just pick the one with the -- Among equally-preferred items, we just pick the one with the
-- lexicographically earliest name. -- lexicographically earliest name.
function compute_group_item(group_name) local function compute_group_item(group_name)
local candidate_items = {} local candidate_items = {}
for itemname, itemdef in pairs(minetest.registered_items) do for itemname, itemdef in pairs(minetest.registered_items) do
if (itemdef.groups.not_in_creative_inventory or 0) == 0 and if (itemdef.groups.not_in_creative_inventory or 0) == 0 and
@ -40,8 +41,10 @@ function compute_group_item(group_name)
for _, item in ipairs(candidate_items) do for _, item in ipairs(candidate_items) do
local pref local pref
if item == unified_inventory.registered_group_items[group_name] then if item == unified_inventory.registered_group_items[group_name] then
pref = 4
elseif item == "default:"..group_name then
pref = 3 pref = 3
elseif item:gsub("^[^:]+:", "") == group_name then elseif item:gsub("^[^:]*:", "") == group_name then
pref = 2 pref = 2
else else
pref = 1 pref = 1

@ -156,17 +156,17 @@ local function stack_image_button(x, y, w, h, buttonname_prefix, item)
if name:sub(1, 6) == "group:" then if name:sub(1, 6) == "group:" then
local group_name = name:sub(7) local group_name = name:sub(7)
local group_item = unified_inventory.get_group_item(group_name) local group_item = unified_inventory.get_group_item(group_name)
show_group = not group_item.sole show_is_group = not group_item.sole
displayitem = group_item.item or "unknown" displayitem = group_item.item or "unknown"
selectitem = group_item.sole and displayitem or name selectitem = group_item.sole and displayitem or name
end end
-- Hackily shift the count to the bottom right local label = string.format("\n\n%s%7d", show_is_group and "G" or " ", count):gsub(" 1$", " .")
local shiftstr = "\n\n " if label == "\n\n ." then label = "" end
return string.format("item_image_button[%u,%u;%u,%u;%s;%s;%s]", return string.format("item_image_button[%u,%u;%u,%u;%s;%s;%s]",
x, y, w, h, x, y, w, h,
minetest.formspec_escape(displayitem), minetest.formspec_escape(displayitem),
minetest.formspec_escape(buttonname_prefix..selectitem), minetest.formspec_escape(buttonname_prefix..selectitem),
count ~= 1 and shiftstr..tostring(count) or "") label)
end end
unified_inventory.register_page("craftguide", { unified_inventory.register_page("craftguide", {