Craftguide: Use better tooltips for group buttons

This commit is contained in:
Wuzzy 2016-08-07 01:39:19 +02:00
parent c9d7942840
commit 15f5b8e804
4 changed files with 53 additions and 4 deletions

View File

@ -1,3 +1,5 @@
local S = unified_inventory.gettext
function unified_inventory.canonical_item_spec_matcher(spec)
local specname = ItemStack(spec):get_name()
if specname:sub(1, 6) == "group:" then
@ -21,6 +23,27 @@ function unified_inventory.item_matches_spec(item, spec)
return unified_inventory.canonical_item_spec_matcher(spec)(itemname)
end
function unified_inventory.extract_groupnames(groupname)
local specname = ItemStack(groupname):get_name()
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
end
end
unified_inventory.registered_group_items = {
mesecon_conductor_craftable = "mesecons:wire_00000000_off",
stone = "default:cobble",

View File

@ -57,6 +57,8 @@ 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.
Any item belonging to the %s group = Irgendein Gegenstand, der zur Gruppe %s gehört
Any item belonging to the groups %s = Irgendein Gegenstand, der zu den Gruppen %s gehört
Recipe %d of %d = Rezept %d von %d
Usage %d of %d = Verwendung %d von %d
No recipes = Keine Rezepte
@ -71,6 +73,9 @@ Clear inventory = Inventar leeren
Give me: = Gib mir:
To craft grid: = Ins Fertigungsraster:
### group.lua ###
\sand\s=\sund\s
### waypoints.lua ###
White = Weiß
Yellow = Gelb

View File

@ -60,6 +60,10 @@ 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. =
# %s = group name (e.g. wool)
Any item belonging to the %s group =
# %s = List of “and”-concatenated group names
Any item belonging to the groups %s =
Recipe %d of %d =
Usage %d of %d =
No recipes =
@ -74,6 +78,10 @@ Clear inventory =
Give me: =
To craft grid: =
### group.lua ###
# Logical connective, example: “Any item belonging to the groups foo and bar”
\sand\s =
### waypoints.lua ###
White =
Yellow =

View File

@ -188,11 +188,24 @@ 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;%f,%f;%s;%s;%s]",
local buttonname = minetest.formspec_escape(buttonname_prefix..unified_inventory.mangle_for_formspec(selectitem))
local button = 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)),
label)
minetest.formspec_escape(displayitem), buttonname, label)
if show_is_group then
local groupstring, andcount = unified_inventory.extract_groupnames(name)
local grouptip
if andcount == 1 then
grouptip = string.format(S("Any item belonging to the %s group"), groupstring)
elseif andcount > 1 then
grouptip = string.format(S("Any item belonging to the groups %s"), groupstring)
end
grouptip = minetest.formspec_escape(grouptip)
if andcount >= 1 then
button = button .. string.format("tooltip[%s;%s]", buttonname, grouptip)
end
end
return button
end
local recipe_text = {