summaryrefslogtreecommitdiff
path: root/internal.lua
diff options
context:
space:
mode:
Diffstat (limited to 'internal.lua')
-rw-r--r--internal.lua114
1 files changed, 63 insertions, 51 deletions
diff --git a/internal.lua b/internal.lua
index 28fbde7..a93b847 100644
--- a/internal.lua
+++ b/internal.lua
@@ -23,28 +23,30 @@ function unified_inventory.get_formspec(player, page)
unified_inventory.current_page[player_name] = page
local pagedef = unified_inventory.pages[page]
- local formspec = "size[14,10]"
- -- Background
- formspec = formspec .. "background[-0.19,-0.25;14.4,10.75;ui_form_bg.png]"
+ local formspec = {
+ "size[14,10]",
+ "background[-0.19,-0.25;14.4,10.75;ui_form_bg.png]" -- Background
+ }
+ local n = 3
if unified_inventory.lite_mode then
- formspec = "size[11,7.7]"
- formspec = formspec .. "background[-0.19,-0.2;11.4,8.4;ui_form_bg.png]"
+ formspec[1] = "size[11,7.7]"
+ formspec[2] = "background[-0.19,-0.2;11.4,8.4;ui_form_bg.png]"
end
- if unified_inventory.is_creative(player_name) and page == "craft" then
- formspec = formspec.."background[0,"..(unified_inventory.formspec_y + 2)..";1,1;ui_single_slot.png]"
+ if unified_inventory.is_creative(player_name)
+ and page == "craft" then
+ formspec[n] = "background[0,"..(unified_inventory.formspec_y + 2)..";1,1;ui_single_slot.png]"
+ n = n+1
end
- local fsdata = nil
-
-- Current page
- if unified_inventory.pages[page] then
- fsdata = pagedef.get_formspec(player)
- formspec = formspec .. fsdata.formspec
- else
+ if not unified_inventory.pages[page] then
return "" -- Invalid page name
end
+ local fsdata = pagedef.get_formspec(player)
+ formspec[n] = fsdata.formspec
+ n = n+1
local button_row = 0
local button_col = 0
@@ -57,34 +59,35 @@ function unified_inventory.get_formspec(player, page)
button_col = 1
end
- local tooltip = def.tooltip or ""
if def.type == "image" then
- formspec = formspec.."image_button["
- ..( unified_inventory.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4)
- ..","..(unified_inventory.main_button_y + button_row * 0.7)..";0.8,0.8;"
- ..minetest.formspec_escape(def.image)..";"
- ..minetest.formspec_escape(def.name)..";]"
- .."tooltip["..minetest.formspec_escape(def.name)
- ..";"..tooltip.."]"
+ formspec[n] = "image_button["
+ formspec[n+1] = ( unified_inventory.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4)
+ formspec[n+2] = ","..(unified_inventory.main_button_y + button_row * 0.7)..";0.8,0.8;"
+ formspec[n+3] = minetest.formspec_escape(def.image)..";"
+ formspec[n+4] = minetest.formspec_escape(def.name)..";]"
+ formspec[n+5] = "tooltip["..minetest.formspec_escape(def.name)
+ formspec[n+6] = ";"..(def.tooltip or "").."]"
+ n = n+7
end
end
if fsdata.draw_inventory ~= false then
-- Player inventory
- formspec = formspec.."listcolors[#00000000;#00000000]"
- formspec = formspec .. "list[current_player;main;0,"..(unified_inventory.formspec_y + 3.5)..";8,4;]"
+ formspec[n] = "listcolors[#00000000;#00000000]"
+ formspec[n+1] = "list[current_player;main;0,"..(unified_inventory.formspec_y + 3.5)..";8,4;]"
+ n = n+2
end
if fsdata.draw_item_list == false then
- return formspec
+ return table.concat(formspec, "")
end
-- Controls to flip items pages
local start_x = 9.2
if not unified_inventory.lite_mode then
- formspec = formspec
- .. "image_button[" .. (start_x + 0.6 * 0)
+ formspec[n] =
+ "image_button[" .. (start_x + 0.6 * 0)
.. ",9;.8,.8;ui_skip_backward_icon.png;start_list;]"
.. "tooltip[start_list;" .. minetest.formspec_escape(S("First page")) .. "]"
@@ -106,8 +109,8 @@ function unified_inventory.get_formspec(player, page)
.. ",9;.8,.8;ui_skip_forward_icon.png;end_list;]"
.. "tooltip[end_list;" .. minetest.formspec_escape(S("Last page")) .. "]"
else
- formspec = formspec
- .. "image_button[" .. (8.2 + 0.65 * 0)
+ formspec[n] =
+ "image_button[" .. (8.2 + 0.65 * 0)
.. ",5.8;.8,.8;ui_skip_backward_icon.png;start_list;]"
.. "tooltip[start_list;" .. minetest.formspec_escape(S("First page")) .. "]"
.. "image_button[" .. (8.2 + 0.65 * 1)
@@ -120,20 +123,22 @@ function unified_inventory.get_formspec(player, page)
.. ",5.8;.8,.8;ui_skip_forward_icon.png;end_list;]"
.. "tooltip[end_list;" .. minetest.formspec_escape(S("Last page")) .. "]"
end
+ n = n+1
-- Search box
if not unified_inventory.lite_mode then
- formspec = formspec .. "field[9.5,8.325;3,1;searchbox;;"
+ formspec[n] = "field[9.5,8.325;3,1;searchbox;;"
.. minetest.formspec_escape(unified_inventory.current_searchbox[player_name]) .. "]"
- formspec = formspec .. "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;" ..S("Search") .. "]"
else
- formspec = formspec .. "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]) .. "]"
- formspec = formspec .. "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;" ..S("Search") .. "]"
end
+ n = n+2
local no_matches = "No matching items"
if unified_inventory.lite_mode then
@@ -142,7 +147,7 @@ function unified_inventory.get_formspec(player, page)
-- Items list
if #unified_inventory.filtered_items_list[player_name] == 0 then
- formspec = formspec.."label[8.2,"..unified_inventory.form_header_y..";" .. S(no_matches) .. "]"
+ formspec[n] = "label[8.2,"..unified_inventory.form_header_y..";" .. S(no_matches) .. "]"
else
local dir = unified_inventory.active_search_direction[player_name]
local list_index = unified_inventory.current_index[player_name]
@@ -155,35 +160,39 @@ function unified_inventory.get_formspec(player, page)
for x = 0, unified_inventory.pagecols - 1 do
local name = unified_inventory.filtered_items_list[player_name][list_index]
if minetest.registered_items[name] then
- formspec = formspec.."item_image_button["
- ..(8.2 + x * 0.7)..","
- ..(unified_inventory.formspec_y + unified_inventory.page_y + y * 0.7)..";.81,.81;"
- ..name..";item_button_"..dir.."_"
- ..unified_inventory.mangle_for_formspec(name)..";]"
+ formspec[n] = "item_image_button["
+ ..(8.2 + x * 0.7)..","
+ ..(unified_inventory.formspec_y + unified_inventory.page_y + y * 0.7)..";.81,.81;"
+ ..name..";item_button_"..dir.."_"
+ ..unified_inventory.mangle_for_formspec(name)..";]"
+ n = n+1
list_index = list_index + 1
end
end
end
- formspec = formspec.."label[8.2,"..unified_inventory.form_header_y..";"..S("Page") .. ": "
+ formspec[n] = "label[8.2,"..unified_inventory.form_header_y..";"..S("Page") .. ": "
.. S("%s of %s"):format(page,pagemax).."]"
end
+ n= n+1
+
if unified_inventory.activefilter[player_name] ~= "" then
- formspec = formspec.."label[8.2,"..(unified_inventory.form_header_y + 0.4)..";" .. S("Filter") .. ":]"
- formspec = formspec.."label[9.1,"..(unified_inventory.form_header_y + 0.4)..";"..minetest.formspec_escape(unified_inventory.activefilter[player_name]).."]"
+ formspec[n] = "label[8.2,"..(unified_inventory.form_header_y + 0.4)..";" .. S("Filter") .. ":]"
+ formspec[n+1] = "label[9.1,"..(unified_inventory.form_header_y + 0.4)..";"..minetest.formspec_escape(unified_inventory.activefilter[player_name]).."]"
end
- return formspec
+ return table.concat(formspec, "")
end
function unified_inventory.set_inventory_formspec(player, page)
if player then
- local formspec = unified_inventory.get_formspec(player, page)
- player:set_inventory_formspec(formspec)
+ player:set_inventory_formspec(unified_inventory.get_formspec(player, page))
end
end
--apply filter to the inventory list (create filtered copy of full one)
function unified_inventory.apply_filter(player, filter, search_dir)
- if not player then return false end
+ if not player then
+ return false
+ end
local player_name = player:get_player_name()
local lfilter = string.lower(filter)
local ffilter
@@ -191,7 +200,8 @@ function unified_inventory.apply_filter(player, filter, search_dir)
local groups = lfilter:sub(7):split(",")
ffilter = function(name, def)
for _, group in ipairs(groups) do
- if not ((def.groups[group] or 0) > 0) then
+ if not def.groups[group]
+ or def.groups[group] <= 0 then
return false
end
end
@@ -206,11 +216,13 @@ function unified_inventory.apply_filter(player, filter, search_dir)
end
unified_inventory.filtered_items_list[player_name]={}
for name, def in pairs(minetest.registered_items) do
- if (def.groups.not_in_creative_inventory or 0) == 0
- and (def.description or "") ~= ""
- and ffilter(name, def)
- and (unified_inventory.is_creative(player_name)
- or unified_inventory.crafts_for.recipe[def.name]) then
+ if (not def.groups.not_in_creative_inventory
+ or def.groups.not_in_creative_inventory == 0)
+ and def.description
+ and def.description ~= ""
+ and ffilter(name, def)
+ and (unified_inventory.is_creative(player_name)
+ or unified_inventory.crafts_for.recipe[def.name]) then
table.insert(unified_inventory.filtered_items_list[player_name], name)
end
end