forked from minetest-mods/unified_inventory
Merge pull request #63 from Wuzzy2/search
Improve search and group handling and related usability
This commit is contained in:
commit
f6ea3daef7
|
@ -14,9 +14,10 @@ Unified inventory code is licensed under the GNU LGPLv2+.
|
||||||
Licenses for textures:
|
Licenses for textures:
|
||||||
|
|
||||||
VanessaE: (WTFPL)
|
VanessaE: (WTFPL)
|
||||||
* ui\_group.png
|
* `ui_group.png`
|
||||||
|
|
||||||
RealBadAngel: (WTFPL)
|
RealBadAngel: (WTFPL)
|
||||||
* Everything else.
|
* Everything else.
|
||||||
|
|
||||||
|
Tango Project: (WTFPL)
|
||||||
|
* `ui_reset_icon.png
|
||||||
|
|
|
@ -120,6 +120,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
if string.sub(clicked_item, 1, 6) == "group:" then
|
if string.sub(clicked_item, 1, 6) == "group:" then
|
||||||
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
|
minetest.sound_play("click", {to_player=player_name, gain = 0.1})
|
||||||
unified_inventory.apply_filter(player, clicked_item, new_dir)
|
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
|
return
|
||||||
end
|
end
|
||||||
if new_dir == "recipe"
|
if new_dir == "recipe"
|
||||||
|
@ -153,11 +156,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
|
||||||
if fields.searchbutton then
|
if fields.searchbutton then
|
||||||
unified_inventory.apply_filter(player, unified_inventory.current_searchbox[player_name], "nochange")
|
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.set_inventory_formspec(player,
|
||||||
unified_inventory.current_page[player_name])
|
unified_inventory.current_page[player_name])
|
||||||
minetest.sound_play("paperflip2",
|
minetest.sound_play("paperflip2",
|
||||||
{to_player=player_name, gain = 1.0})
|
{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
|
end
|
||||||
|
|
||||||
-- alternate buttons
|
-- alternate buttons
|
||||||
|
|
29
group.lua
29
group.lua
|
@ -1,3 +1,5 @@
|
||||||
|
local S = unified_inventory.gettext
|
||||||
|
|
||||||
function unified_inventory.canonical_item_spec_matcher(spec)
|
function unified_inventory.canonical_item_spec_matcher(spec)
|
||||||
local specname = ItemStack(spec):get_name()
|
local specname = ItemStack(spec):get_name()
|
||||||
if specname:sub(1, 6) == "group:" then
|
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)
|
return unified_inventory.canonical_item_spec_matcher(spec)(itemname)
|
||||||
end
|
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 = {
|
unified_inventory.registered_group_items = {
|
||||||
mesecon_conductor_craftable = "mesecons:wire_00000000_off",
|
mesecon_conductor_craftable = "mesecons:wire_00000000_off",
|
||||||
stone = "default:cobble",
|
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",
|
wool = "wool:white",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,13 +179,19 @@ function unified_inventory.get_formspec(player, page)
|
||||||
.. minetest.formspec_escape(unified_inventory.current_searchbox[player_name]) .. "]"
|
.. 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;]"
|
formspec[n+1] = "image_button[12.2,8.1;.8,.8;ui_search_icon.png;searchbutton;]"
|
||||||
.. "tooltip[searchbutton;" ..F("Search") .. "]"
|
.. "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
|
else
|
||||||
formspec[n] = "field[8.5,5.225;2.2,1;searchbox;;"
|
formspec[n] = "field[8.5,5.225;2.2,1;searchbox;;"
|
||||||
.. minetest.formspec_escape(unified_inventory.current_searchbox[player_name]) .. "]"
|
.. minetest.formspec_escape(unified_inventory.current_searchbox[player_name]) .. "]"
|
||||||
formspec[n+1] = "image_button[10.3,5;.8,.8;ui_search_icon.png;searchbutton;]"
|
formspec[n+1] = "image_button[10.3,5;.8,.8;ui_search_icon.png;searchbutton;]"
|
||||||
.. "tooltip[searchbutton;" ..F("Search") .. "]"
|
.. "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
|
end
|
||||||
n = n+2
|
n = n+3
|
||||||
|
|
||||||
local no_matches = "No matching items"
|
local no_matches = "No matching items"
|
||||||
if draw_lite_mode then
|
if draw_lite_mode then
|
||||||
|
|
|
@ -25,6 +25,7 @@ Page = Seite
|
||||||
%s of %s = %s von %s
|
%s of %s = %s von %s
|
||||||
Filter = Filter
|
Filter = Filter
|
||||||
Search = Suchen
|
Search = Suchen
|
||||||
|
Reset search and display everything = Suche zurücksetzen und alles anzeigen
|
||||||
|
|
||||||
### register.lua ###
|
### register.lua ###
|
||||||
Can use the creative inventory = Kann das Kreativinventar nutzen
|
Can use the creative inventory = Kann das Kreativinventar nutzen
|
||||||
|
@ -56,6 +57,8 @@ Show next usage = Nächste Verwendung zeigen
|
||||||
Show previous recipe = Vorheriges Rezept zeigen
|
Show previous recipe = Vorheriges Rezept zeigen
|
||||||
Show previous usage = Vorherige Verwendung zeigen
|
Show previous usage = Vorherige Verwendung zeigen
|
||||||
This recipe is too\nlarge to be displayed. = Dieses Rezept ist zu\ngroß, um angezeigt\nzu werden.
|
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
|
Recipe %d of %d = Rezept %d von %d
|
||||||
Usage %d of %d = Verwendung %d von %d
|
Usage %d of %d = Verwendung %d von %d
|
||||||
No recipes = Keine Rezepte
|
No recipes = Keine Rezepte
|
||||||
|
@ -70,6 +73,9 @@ Clear inventory = Inventar leeren
|
||||||
Give me: = Gib mir:
|
Give me: = Gib mir:
|
||||||
To craft grid: = Ins Fertigungsraster:
|
To craft grid: = Ins Fertigungsraster:
|
||||||
|
|
||||||
|
### group.lua ###
|
||||||
|
\sand\s=\sund\s
|
||||||
|
|
||||||
### waypoints.lua ###
|
### waypoints.lua ###
|
||||||
White = Weiß
|
White = Weiß
|
||||||
Yellow = Gelb
|
Yellow = Gelb
|
||||||
|
|
|
@ -26,6 +26,7 @@ Page =
|
||||||
%s of %s =
|
%s of %s =
|
||||||
Filter =
|
Filter =
|
||||||
Search =
|
Search =
|
||||||
|
Reset search and display everything =
|
||||||
|
|
||||||
### register.lua ###
|
### register.lua ###
|
||||||
Can use the creative inventory =
|
Can use the creative inventory =
|
||||||
|
@ -59,6 +60,10 @@ Show previous recipe =
|
||||||
Show previous usage =
|
Show previous usage =
|
||||||
# Shown for huge crafting recipes; try to keep the line length short and use multiple line breaks as needed
|
# 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. =
|
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 =
|
Recipe %d of %d =
|
||||||
Usage %d of %d =
|
Usage %d of %d =
|
||||||
No recipes =
|
No recipes =
|
||||||
|
@ -73,6 +78,10 @@ Clear inventory =
|
||||||
Give me: =
|
Give me: =
|
||||||
To craft grid: =
|
To craft grid: =
|
||||||
|
|
||||||
|
### group.lua ###
|
||||||
|
# Logical connective, example: “Any item belonging to the groups foo and bar”
|
||||||
|
\sand\s =
|
||||||
|
|
||||||
### waypoints.lua ###
|
### waypoints.lua ###
|
||||||
White =
|
White =
|
||||||
Yellow =
|
Yellow =
|
||||||
|
|
21
register.lua
21
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
|
selectitem = group_item.sole and displayitem or name
|
||||||
end
|
end
|
||||||
local label = show_is_group and "G" or ""
|
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,
|
x, y, w, h,
|
||||||
minetest.formspec_escape(displayitem),
|
minetest.formspec_escape(displayitem), buttonname, label)
|
||||||
minetest.formspec_escape(buttonname_prefix..unified_inventory.mangle_for_formspec(selectitem)),
|
if show_is_group then
|
||||||
label)
|
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
|
end
|
||||||
|
|
||||||
local recipe_text = {
|
local recipe_text = {
|
||||||
|
|
BIN
textures/ui_reset_icon.png
Normal file
BIN
textures/ui_reset_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
Loading…
Reference in New Issue
Block a user