summaryrefslogtreecommitdiff
path: root/unified_inventory
diff options
context:
space:
mode:
Diffstat (limited to 'unified_inventory')
-rw-r--r--unified_inventory/README.md5
-rw-r--r--unified_inventory/callbacks.lua29
-rw-r--r--unified_inventory/group.lua29
-rw-r--r--unified_inventory/internal.lua8
-rw-r--r--unified_inventory/locale/de.txt11
-rw-r--r--unified_inventory/locale/template.txt15
-rw-r--r--unified_inventory/register.lua73
-rw-r--r--unified_inventory/textures/ui_reset_icon.pngbin0 -> 11310 bytes
8 files changed, 151 insertions, 19 deletions
diff --git a/unified_inventory/README.md b/unified_inventory/README.md
index 6f5e2d4..489ebab 100644
--- a/unified_inventory/README.md
+++ b/unified_inventory/README.md
@@ -14,9 +14,10 @@ Unified inventory code is licensed under the GNU LGPLv2+.
Licenses for textures:
VanessaE: (WTFPL)
- * ui\_group.png
+ * `ui_group.png`
RealBadAngel: (WTFPL)
* Everything else.
-
+Tango Project: (WTFPL)
+ * `ui_reset_icon.png
diff --git a/unified_inventory/callbacks.lua b/unified_inventory/callbacks.lua
index 9387154..ad6de0a 100644
--- a/unified_inventory/callbacks.lua
+++ b/unified_inventory/callbacks.lua
@@ -120,6 +120,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if string.sub(clicked_item, 1, 6) == "group:" then
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
unified_inventory.apply_filter(player, clicked_item, new_dir)
+ unified_inventory.current_searchbox[player_name] = clicked_item
+ unified_inventory.set_inventory_formspec(player,
+ unified_inventory.current_page[player_name])
return
end
if new_dir == "recipe"
@@ -153,15 +156,21 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.searchbutton then
unified_inventory.apply_filter(player, unified_inventory.current_searchbox[player_name], "nochange")
- unified_inventory.current_searchbox[player_name] = ""
unified_inventory.set_inventory_formspec(player,
unified_inventory.current_page[player_name])
minetest.sound_play("paperflip2",
{to_player=player_name, gain = 1.0})
+ elseif fields.searchresetbutton then
+ unified_inventory.apply_filter(player, "", "nochange")
+ unified_inventory.current_searchbox[player_name] = ""
+ unified_inventory.set_inventory_formspec(player,
+ unified_inventory.current_page[player_name])
+ minetest.sound_play("click",
+ {to_player=player_name, gain = 0.1})
end
- -- alternate button
- if not fields.alternate then
+ -- alternate buttons
+ if not (fields.alternate or fields.alternate_prev) then
return
end
minetest.sound_play("click",
@@ -178,9 +187,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if alternates <= 1 then
return
end
- local alternate = unified_inventory.alternate[player_name] + 1
- if alternate > alternates then
- alternate = 1
+ local alternate
+ if fields.alternate then
+ alternate = unified_inventory.alternate[player_name] + 1
+ if alternate > alternates then
+ alternate = 1
+ end
+ elseif fields.alternate_prev then
+ alternate = unified_inventory.alternate[player_name] - 1
+ if alternate < 1 then
+ alternate = alternates
+ end
end
unified_inventory.alternate[player_name] = alternate
unified_inventory.set_inventory_formspec(player,
diff --git a/unified_inventory/group.lua b/unified_inventory/group.lua
index 9bf6895..23e2587 100644
--- a/unified_inventory/group.lua
+++ b/unified_inventory/group.lua
@@ -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,9 +23,36 @@ 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",
+ wood = "default:wood",
+ book = "default:book",
+ sand = "default:sand",
+ leaves = "default:leaves",
+ tree = "default:tree",
+ vessel = "vessels:glass_bottle",
wool = "wool:white",
}
diff --git a/unified_inventory/internal.lua b/unified_inventory/internal.lua
index 8319191..42ab722 100644
--- a/unified_inventory/internal.lua
+++ b/unified_inventory/internal.lua
@@ -179,13 +179,19 @@ function unified_inventory.get_formspec(player, page)
.. minetest.formspec_escape(unified_inventory.current_searchbox[player_name]) .. "]"
formspec[n+1] = "image_button[12.2,8.1;.8,.8;ui_search_icon.png;searchbutton;]"
.. "tooltip[searchbutton;" ..F("Search") .. "]"
+ formspec[n+2] = "image_button[12.9,8.1;.8,.8;ui_reset_icon.png;searchresetbutton;]"
+ .. "tooltip[searchbutton;" ..F("Search") .. "]"
+ .. "tooltip[searchresetbutton;" ..F("Reset search and display everything") .. "]"
else
formspec[n] = "field[8.5,5.225;2.2,1;searchbox;;"
.. minetest.formspec_escape(unified_inventory.current_searchbox[player_name]) .. "]"
formspec[n+1] = "image_button[10.3,5;.8,.8;ui_search_icon.png;searchbutton;]"
.. "tooltip[searchbutton;" ..F("Search") .. "]"
+ formspec[n+2] = "image_button[11,5;.8,.8;ui_reset_icon.png;searchresetbutton;]"
+ .. "tooltip[searchbutton;" ..F("Search") .. "]"
+ .. "tooltip[searchresetbutton;" ..F("Reset search and display everything") .. "]"
end
- n = n+2
+ n = n+3
local no_matches = "No matching items"
if draw_lite_mode then
diff --git a/unified_inventory/locale/de.txt b/unified_inventory/locale/de.txt
index e652e49..a2f7c3d 100644
--- a/unified_inventory/locale/de.txt
+++ b/unified_inventory/locale/de.txt
@@ -25,6 +25,7 @@ Page = Seite
%s of %s = %s von %s
Filter = Filter
Search = Suchen
+Reset search and display everything = Suche zurücksetzen und alles anzeigen
### register.lua ###
Can use the creative inventory = Kann das Kreativinventar nutzen
@@ -51,6 +52,13 @@ Copy to craft grid: = Ins Fertigungsraster kopieren:
All = Alles
Alternate = Alternative
Crafting Grid = Fertigungsraster
+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.
+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
@@ -65,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
diff --git a/unified_inventory/locale/template.txt b/unified_inventory/locale/template.txt
index e0e50f6..bd27f2f 100644
--- a/unified_inventory/locale/template.txt
+++ b/unified_inventory/locale/template.txt
@@ -26,6 +26,7 @@ Page =
%s of %s =
Filter =
Search =
+Reset search and display everything =
### register.lua ###
Can use the creative inventory =
@@ -53,6 +54,16 @@ Copy to craft grid: =
All =
Alternate =
Crafting Grid =
+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. =
+# %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 =
@@ -67,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 =
diff --git a/unified_inventory/register.lua b/unified_inventory/register.lua
index 978646b..ff38168 100644
--- a/unified_inventory/register.lua
+++ b/unified_inventory/register.lua
@@ -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;%u,%u;%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 = {
@@ -207,6 +220,14 @@ local role_text = {
recipe = "Result",
usage = "Ingredient",
}
+local next_alt_text = {
+ recipe = "Show next recipe",
+ usage = "Show next usage",
+}
+local prev_alt_text = {
+ recipe = "Show previous recipe",
+ usage = "Show previous usage",
+}
local other_dir = {
recipe = "usage",
usage = "recipe",
@@ -276,28 +297,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]"
@@ -313,7 +363,10 @@ unified_inventory.register_page("craftguide", {
if alternates and alternates > 1 then
formspec = formspec.."label[5.5,"..(formspecy + 1.6)..";"
..string.format(F(recipe_text[dir]), alternate, alternates).."]"
- .."button[5.5,"..(formspecy + 2)..";2,1;alternate;" .. F("Alternate") .. "]"
+ .."image_button[5.5,"..(formspecy + 2)..";1,1;ui_left_icon.png;alternate_prev;]"
+ .."image_button[6.5,"..(formspecy + 2)..";1,1;ui_right_icon.png;alternate;]"
+ .."tooltip[alternate_prev;"..F(prev_alt_text[dir]).."]"
+ .."tooltip[alternate;"..F(next_alt_text[dir]).."]"
end
return {formspec = formspec}
end,
diff --git a/unified_inventory/textures/ui_reset_icon.png b/unified_inventory/textures/ui_reset_icon.png
new file mode 100644
index 0000000..ec9ef62
--- /dev/null
+++ b/unified_inventory/textures/ui_reset_icon.png
Binary files differ