mirror of
https://github.com/minetest-mods/unified_inventory.git
synced 2024-11-20 06:13:44 +01:00
refactor code to use with intllib tool
This commit is contained in:
parent
2ab5a7c90a
commit
c1ab7277ab
10
api.lua
10
api.lua
@ -1,5 +1,5 @@
|
|||||||
local S = unified_inventory.gettext
|
local S = unified_inventory.gettext
|
||||||
local F = unified_inventory.fgettext
|
local F = minetest.formspec_escape
|
||||||
|
|
||||||
-- Create detached creative inventory after loading all mods
|
-- Create detached creative inventory after loading all mods
|
||||||
minetest.after(0.01, function()
|
minetest.after(0.01, function()
|
||||||
@ -233,7 +233,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
unified_inventory.register_craft_type("normal", {
|
unified_inventory.register_craft_type("normal", {
|
||||||
description = F("Crafting"),
|
description = F(S("Crafting")),
|
||||||
icon = "ui_craftgrid_icon.png",
|
icon = "ui_craftgrid_icon.png",
|
||||||
width = 3,
|
width = 3,
|
||||||
height = 3,
|
height = 3,
|
||||||
@ -249,7 +249,7 @@ unified_inventory.register_craft_type("normal", {
|
|||||||
|
|
||||||
|
|
||||||
unified_inventory.register_craft_type("shapeless", {
|
unified_inventory.register_craft_type("shapeless", {
|
||||||
description = F("Mixing"),
|
description = F(S("Mixing")),
|
||||||
icon = "ui_craftgrid_icon.png",
|
icon = "ui_craftgrid_icon.png",
|
||||||
width = 3,
|
width = 3,
|
||||||
height = 3,
|
height = 3,
|
||||||
@ -264,7 +264,7 @@ unified_inventory.register_craft_type("shapeless", {
|
|||||||
|
|
||||||
|
|
||||||
unified_inventory.register_craft_type("cooking", {
|
unified_inventory.register_craft_type("cooking", {
|
||||||
description = F("Cooking"),
|
description = F(S("Cooking")),
|
||||||
icon = "default_furnace_front.png",
|
icon = "default_furnace_front.png",
|
||||||
width = 1,
|
width = 1,
|
||||||
height = 1,
|
height = 1,
|
||||||
@ -272,7 +272,7 @@ unified_inventory.register_craft_type("cooking", {
|
|||||||
|
|
||||||
|
|
||||||
unified_inventory.register_craft_type("digging", {
|
unified_inventory.register_craft_type("digging", {
|
||||||
description = F("Digging"),
|
description = F(S("Digging")),
|
||||||
icon = "default_tool_steelpick.png",
|
icon = "default_tool_steelpick.png",
|
||||||
width = 1,
|
width = 1,
|
||||||
height = 1,
|
height = 1,
|
||||||
|
24
bags.lua
24
bags.lua
@ -4,22 +4,22 @@
|
|||||||
-- License: GPLv3
|
-- License: GPLv3
|
||||||
|
|
||||||
local S = unified_inventory.gettext
|
local S = unified_inventory.gettext
|
||||||
local F = unified_inventory.fgettext
|
local F = minetest.formspec_escape
|
||||||
|
|
||||||
unified_inventory.register_page("bags", {
|
unified_inventory.register_page("bags", {
|
||||||
get_formspec = function(player)
|
get_formspec = function(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local formspec = "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]"
|
local formspec = "background[0.06,0.99;7.92,7.52;ui_bags_main_form.png]"
|
||||||
formspec = formspec.."label[0,0;"..F("Bags").."]"
|
formspec = formspec.."label[0,0;"..F(S("Bags")).."]"
|
||||||
formspec = formspec.."button[0,2;2,0.5;bag1;"..F("Bag 1").."]"
|
formspec = formspec.."button[0,2;2,0.5;bag1;"..F(S("Bag @1", 1)).."]"
|
||||||
formspec = formspec.."button[2,2;2,0.5;bag2;"..F("Bag 2").."]"
|
formspec = formspec.."button[2,2;2,0.5;bag2;"..F(S("Bag @1", 2)).."]"
|
||||||
formspec = formspec.."button[4,2;2,0.5;bag3;"..F("Bag 3").."]"
|
formspec = formspec.."button[4,2;2,0.5;bag3;"..F(S("Bag @1", 3)).."]"
|
||||||
formspec = formspec.."button[6,2;2,0.5;bag4;"..F("Bag 4").."]"
|
formspec = formspec.."button[6,2;2,0.5;bag4;"..F(S("Bag @1", 4)).."]"
|
||||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
formspec = formspec.."listcolors[#00000000;#00000000]"
|
||||||
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag1;0.5,1;1,1;]"
|
formspec = formspec.."list[detached:"..F(player_name).."_bags;bag1;0.5,1;1,1;]"
|
||||||
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag2;2.5,1;1,1;]"
|
formspec = formspec.."list[detached:"..F(player_name).."_bags;bag2;2.5,1;1,1;]"
|
||||||
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag3;4.5,1;1,1;]"
|
formspec = formspec.."list[detached:"..F(player_name).."_bags;bag3;4.5,1;1,1;]"
|
||||||
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."_bags;bag4;6.5,1;1,1;]"
|
formspec = formspec.."list[detached:"..F(player_name).."_bags;bag4;6.5,1;1,1;]"
|
||||||
return {formspec=formspec}
|
return {formspec=formspec}
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -38,7 +38,7 @@ for i = 1, 4 do
|
|||||||
local stack = player:get_inventory():get_stack("bag"..bi, 1)
|
local stack = player:get_inventory():get_stack("bag"..bi, 1)
|
||||||
local image = stack:get_definition().inventory_image
|
local image = stack:get_definition().inventory_image
|
||||||
local formspec = ("image[7,0;1,1;"..image.."]"
|
local formspec = ("image[7,0;1,1;"..image.."]"
|
||||||
.."label[0,0;"..F("Bag @1", bi).."]"
|
.."label[0,0;"..F(S("Bag @1", bi)).."]"
|
||||||
.."listcolors[#00000000;#00000000]"
|
.."listcolors[#00000000;#00000000]"
|
||||||
.."list[current_player;bag"..bi.."contents;0,1;8,3;]"
|
.."list[current_player;bag"..bi.."contents;0,1;8,3;]"
|
||||||
.."listring[current_name;bag"..bi.."contents]"
|
.."listring[current_name;bag"..bi.."contents]"
|
||||||
@ -71,7 +71,7 @@ for i = 1, 4 do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local img = def.inventory_image
|
local img = def.inventory_image
|
||||||
local label = F("Bag @1", i).."\n"..used.."/"..size
|
local label = F(S("Bag @1", i)).."\n"..used.."/"..size
|
||||||
button = "image_button["..(i+1)..",0;1,1;"..img..";bag"..i..";"..label.."]"
|
button = "image_button["..(i+1)..",0;1,1;"..img..";bag"..i..";"..label.."]"
|
||||||
else
|
else
|
||||||
button = ""
|
button = ""
|
||||||
|
15
init.lua
15
init.lua
@ -2,15 +2,9 @@
|
|||||||
|
|
||||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||||
local worldpath = minetest.get_worldpath()
|
local worldpath = minetest.get_worldpath()
|
||||||
local mygettext
|
|
||||||
if rawget(_G, "intllib") then
|
-- Intllib
|
||||||
mygettext = intllib.Getter()
|
local S, NS = dofile(modpath .. "/intllib.lua")
|
||||||
else
|
|
||||||
function mygettext(s, ...)
|
|
||||||
local t = { ... }
|
|
||||||
return (s:gsub("@(%d+)", function(n) return t[tonumber(n)] end))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Data tables definitions
|
-- Data tables definitions
|
||||||
unified_inventory = {
|
unified_inventory = {
|
||||||
@ -40,8 +34,7 @@ unified_inventory = {
|
|||||||
default = "craft",
|
default = "craft",
|
||||||
|
|
||||||
-- intllib
|
-- intllib
|
||||||
gettext = mygettext,
|
gettext = S,
|
||||||
fgettext = function(...) return minetest.formspec_escape(mygettext(...)) end,
|
|
||||||
|
|
||||||
-- "Lite" mode
|
-- "Lite" mode
|
||||||
lite_mode = minetest.setting_getbool("unified_inventory_lite"),
|
lite_mode = minetest.setting_getbool("unified_inventory_lite"),
|
||||||
|
56
internal.lua
56
internal.lua
@ -1,5 +1,5 @@
|
|||||||
local S = unified_inventory.gettext
|
local S = unified_inventory.gettext
|
||||||
local F = unified_inventory.fgettext
|
local F = minetest.formspec_escape
|
||||||
|
|
||||||
-- This pair of encoding functions is used where variable text must go in
|
-- This pair of encoding functions is used where variable text must go in
|
||||||
-- button names, where the text might contain formspec metacharacters.
|
-- button names, where the text might contain formspec metacharacters.
|
||||||
@ -111,16 +111,16 @@ function unified_inventory.get_formspec(player, page)
|
|||||||
formspec[n] = "image_button["
|
formspec[n] = "image_button["
|
||||||
formspec[n+1] = ( ui_peruser.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4)
|
formspec[n+1] = ( ui_peruser.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4)
|
||||||
formspec[n+2] = ","..(ui_peruser.main_button_y + button_row * 0.7)..";0.8,0.8;"
|
formspec[n+2] = ","..(ui_peruser.main_button_y + button_row * 0.7)..";0.8,0.8;"
|
||||||
formspec[n+3] = minetest.formspec_escape(def.image)..";"
|
formspec[n+3] = F(def.image)..";"
|
||||||
formspec[n+4] = minetest.formspec_escape(def.name)..";]"
|
formspec[n+4] = F(def.name)..";]"
|
||||||
formspec[n+5] = "tooltip["..minetest.formspec_escape(def.name)
|
formspec[n+5] = "tooltip["..F(def.name)
|
||||||
formspec[n+6] = ";"..(def.tooltip or "").."]"
|
formspec[n+6] = ";"..(def.tooltip or "").."]"
|
||||||
n = n+7
|
n = n+7
|
||||||
else
|
else
|
||||||
formspec[n] = "image["
|
formspec[n] = "image["
|
||||||
formspec[n+1] = ( ui_peruser.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4)
|
formspec[n+1] = ( ui_peruser.main_button_x + 0.65 * (i - 1) - button_col * 0.65 * 4)
|
||||||
formspec[n+2] = ","..(ui_peruser.main_button_y + button_row * 0.7)..";0.8,0.8;"
|
formspec[n+2] = ","..(ui_peruser.main_button_y + button_row * 0.7)..";0.8,0.8;"
|
||||||
formspec[n+3] = minetest.formspec_escape(def.image).."^[colorize:#808080:alpha]"
|
formspec[n+3] = F(def.image).."^[colorize:#808080:alpha]"
|
||||||
n = n+4
|
n = n+4
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -145,39 +145,39 @@ function unified_inventory.get_formspec(player, page)
|
|||||||
formspec[n] =
|
formspec[n] =
|
||||||
"image_button[" .. (start_x + 0.6 * 0)
|
"image_button[" .. (start_x + 0.6 * 0)
|
||||||
.. ",9;.8,.8;ui_skip_backward_icon.png;start_list;]"
|
.. ",9;.8,.8;ui_skip_backward_icon.png;start_list;]"
|
||||||
.. "tooltip[start_list;" .. F("First page") .. "]"
|
.. "tooltip[start_list;" .. F(S("First page")) .. "]"
|
||||||
|
|
||||||
.. "image_button[" .. (start_x + 0.6 * 1)
|
.. "image_button[" .. (start_x + 0.6 * 1)
|
||||||
.. ",9;.8,.8;ui_doubleleft_icon.png;rewind3;]"
|
.. ",9;.8,.8;ui_doubleleft_icon.png;rewind3;]"
|
||||||
.. "tooltip[rewind3;" .. F("Back three pages") .. "]"
|
.. "tooltip[rewind3;" .. F(S("Back three pages")) .. "]"
|
||||||
.. "image_button[" .. (start_x + 0.6 * 2)
|
.. "image_button[" .. (start_x + 0.6 * 2)
|
||||||
.. ",9;.8,.8;ui_left_icon.png;rewind1;]"
|
.. ",9;.8,.8;ui_left_icon.png;rewind1;]"
|
||||||
.. "tooltip[rewind1;" .. F("Back one page") .. "]"
|
.. "tooltip[rewind1;" .. F(S("Back one page")) .. "]"
|
||||||
|
|
||||||
.. "image_button[" .. (start_x + 0.6 * 3)
|
.. "image_button[" .. (start_x + 0.6 * 3)
|
||||||
.. ",9;.8,.8;ui_right_icon.png;forward1;]"
|
.. ",9;.8,.8;ui_right_icon.png;forward1;]"
|
||||||
.. "tooltip[forward1;" .. F("Forward one page") .. "]"
|
.. "tooltip[forward1;" .. F(S("Forward one page")) .. "]"
|
||||||
.. "image_button[" .. (start_x + 0.6 * 4)
|
.. "image_button[" .. (start_x + 0.6 * 4)
|
||||||
.. ",9;.8,.8;ui_doubleright_icon.png;forward3;]"
|
.. ",9;.8,.8;ui_doubleright_icon.png;forward3;]"
|
||||||
.. "tooltip[forward3;" .. F("Forward three pages") .. "]"
|
.. "tooltip[forward3;" .. F(S("Forward three pages")) .. "]"
|
||||||
|
|
||||||
.. "image_button[" .. (start_x + 0.6 * 5)
|
.. "image_button[" .. (start_x + 0.6 * 5)
|
||||||
.. ",9;.8,.8;ui_skip_forward_icon.png;end_list;]"
|
.. ",9;.8,.8;ui_skip_forward_icon.png;end_list;]"
|
||||||
.. "tooltip[end_list;" .. F("Last page") .. "]"
|
.. "tooltip[end_list;" .. F(S("Last page")) .. "]"
|
||||||
else
|
else
|
||||||
formspec[n] =
|
formspec[n] =
|
||||||
"image_button[" .. (8.2 + 0.65 * 0)
|
"image_button[" .. (8.2 + 0.65 * 0)
|
||||||
.. ",5.8;.8,.8;ui_skip_backward_icon.png;start_list;]"
|
.. ",5.8;.8,.8;ui_skip_backward_icon.png;start_list;]"
|
||||||
.. "tooltip[start_list;" .. F("First page") .. "]"
|
.. "tooltip[start_list;" .. F(S("First page")) .. "]"
|
||||||
.. "image_button[" .. (8.2 + 0.65 * 1)
|
.. "image_button[" .. (8.2 + 0.65 * 1)
|
||||||
.. ",5.8;.8,.8;ui_left_icon.png;rewind1;]"
|
.. ",5.8;.8,.8;ui_left_icon.png;rewind1;]"
|
||||||
.. "tooltip[rewind1;" .. F("Back one page") .. "]"
|
.. "tooltip[rewind1;" .. F(S("Back one page")) .. "]"
|
||||||
.. "image_button[" .. (8.2 + 0.65 * 2)
|
.. "image_button[" .. (8.2 + 0.65 * 2)
|
||||||
.. ",5.8;.8,.8;ui_right_icon.png;forward1;]"
|
.. ",5.8;.8,.8;ui_right_icon.png;forward1;]"
|
||||||
.. "tooltip[forward1;" .. F("Forward one page") .. "]"
|
.. "tooltip[forward1;" .. F(S("Forward one page")) .. "]"
|
||||||
.. "image_button[" .. (8.2 + 0.65 * 3)
|
.. "image_button[" .. (8.2 + 0.65 * 3)
|
||||||
.. ",5.8;.8,.8;ui_skip_forward_icon.png;end_list;]"
|
.. ",5.8;.8,.8;ui_skip_forward_icon.png;end_list;]"
|
||||||
.. "tooltip[end_list;" .. F("Last page") .. "]"
|
.. "tooltip[end_list;" .. F(S("Last page")) .. "]"
|
||||||
end
|
end
|
||||||
n = n+1
|
n = n+1
|
||||||
|
|
||||||
@ -187,26 +187,26 @@ function unified_inventory.get_formspec(player, page)
|
|||||||
|
|
||||||
if not draw_lite_mode then
|
if not draw_lite_mode then
|
||||||
formspec[n] = "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]) .. "]"
|
.. F(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(S("Search")) .. "]"
|
||||||
formspec[n+2] = "image_button[12.9,8.1;.8,.8;ui_reset_icon.png;searchresetbutton;]"
|
formspec[n+2] = "image_button[12.9,8.1;.8,.8;ui_reset_icon.png;searchresetbutton;]"
|
||||||
.. "tooltip[searchbutton;" ..F("Search") .. "]"
|
.. "tooltip[searchbutton;" ..F(S("Search")) .. "]"
|
||||||
.. "tooltip[searchresetbutton;" ..F("Reset search and display everything") .. "]"
|
.. "tooltip[searchresetbutton;" ..F(S("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]) .. "]"
|
.. F(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(S("Search")) .. "]"
|
||||||
formspec[n+2] = "image_button[11,5;.8,.8;ui_reset_icon.png;searchresetbutton;]"
|
formspec[n+2] = "image_button[11,5;.8,.8;ui_reset_icon.png;searchresetbutton;]"
|
||||||
.. "tooltip[searchbutton;" ..F("Search") .. "]"
|
.. "tooltip[searchbutton;" ..F(S("Search")) .. "]"
|
||||||
.. "tooltip[searchresetbutton;" ..F("Reset search and display everything") .. "]"
|
.. "tooltip[searchresetbutton;" ..F(S("Reset search and display everything")) .. "]"
|
||||||
end
|
end
|
||||||
n = n+3
|
n = n+3
|
||||||
|
|
||||||
local no_matches = "No matching items"
|
local no_matches = S("No matching items")
|
||||||
if draw_lite_mode then
|
if draw_lite_mode then
|
||||||
no_matches = "No matches."
|
no_matches = S("No matches.")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Items list
|
-- Items list
|
||||||
@ -246,14 +246,14 @@ function unified_inventory.get_formspec(player, page)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
formspec[n] = "label[8.2,"..ui_peruser.form_header_y..";"..F("Page") .. ": "
|
formspec[n] = "label[8.2,"..ui_peruser.form_header_y..";"..F(S("Page")) .. ": "
|
||||||
.. S("%s of %s"):format(page,pagemax).."]"
|
.. S("%s of %s"):format(page,pagemax).."]"
|
||||||
end
|
end
|
||||||
n= n+1
|
n= n+1
|
||||||
|
|
||||||
if unified_inventory.activefilter[player_name] ~= "" then
|
if unified_inventory.activefilter[player_name] ~= "" then
|
||||||
formspec[n] = "label[8.2,"..(ui_peruser.form_header_y + 0.4)..";" .. F("Filter") .. ":]"
|
formspec[n] = "label[8.2,"..(ui_peruser.form_header_y + 0.4)..";" .. F(S("Filter")) .. ":]"
|
||||||
formspec[n+1] = "label[9.1,"..(ui_peruser.form_header_y + 0.4)..";"..minetest.formspec_escape(unified_inventory.activefilter[player_name]).."]"
|
formspec[n+1] = "label[9.1,"..(ui_peruser.form_header_y + 0.4)..";"..F(unified_inventory.activefilter[player_name]).."]"
|
||||||
end
|
end
|
||||||
return table.concat(formspec, "")
|
return table.concat(formspec, "")
|
||||||
end
|
end
|
||||||
|
45
intllib.lua
Normal file
45
intllib.lua
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
-- Fallback functions for when `intllib` is not installed.
|
||||||
|
-- Code released under Unlicense <http://unlicense.org>.
|
||||||
|
|
||||||
|
-- Get the latest version of this file at:
|
||||||
|
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
|
||||||
|
|
||||||
|
local function format(str, ...)
|
||||||
|
local args = { ... }
|
||||||
|
local function repl(escape, open, num, close)
|
||||||
|
if escape == "" then
|
||||||
|
local replacement = tostring(args[tonumber(num)])
|
||||||
|
if open == "" then
|
||||||
|
replacement = replacement..close
|
||||||
|
end
|
||||||
|
return replacement
|
||||||
|
else
|
||||||
|
return "@"..open..num..close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
|
||||||
|
end
|
||||||
|
|
||||||
|
local gettext, ngettext
|
||||||
|
if minetest.get_modpath("intllib") then
|
||||||
|
if intllib.make_gettext_pair then
|
||||||
|
-- New method using gettext.
|
||||||
|
gettext, ngettext = intllib.make_gettext_pair()
|
||||||
|
else
|
||||||
|
-- Old method using text files.
|
||||||
|
gettext = intllib.Getter()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Fill in missing functions.
|
||||||
|
|
||||||
|
gettext = gettext or function(msgid, ...)
|
||||||
|
return format(msgid, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
|
||||||
|
return format(n==1 and msgid or msgid_plural, ...)
|
||||||
|
end
|
||||||
|
|
||||||
|
return gettext, ngettext
|
58
register.lua
58
register.lua
@ -1,5 +1,5 @@
|
|||||||
local S = unified_inventory.gettext
|
local S = unified_inventory.gettext
|
||||||
local F = unified_inventory.fgettext
|
local F = minetest.formspec_escape
|
||||||
|
|
||||||
minetest.register_privilege("creative", {
|
minetest.register_privilege("creative", {
|
||||||
description = S("Can use the creative inventory"),
|
description = S("Can use the creative inventory"),
|
||||||
@ -171,20 +171,20 @@ unified_inventory.register_page("craft", {
|
|||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local formspec = "background[2,"..formspecy..";6,3;ui_crafting_form.png]"
|
local formspec = "background[2,"..formspecy..";6,3;ui_crafting_form.png]"
|
||||||
formspec = formspec.."background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]"
|
formspec = formspec.."background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]"
|
||||||
formspec = formspec.."label[0,"..formheadery..";" ..F("Crafting").."]"
|
formspec = formspec.."label[0,"..formheadery..";" ..F(S("Crafting")).."]"
|
||||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
formspec = formspec.."listcolors[#00000000;#00000000]"
|
||||||
formspec = formspec.."list[current_player;craftpreview;6,"..formspecy..";1,1;]"
|
formspec = formspec.."list[current_player;craftpreview;6,"..formspecy..";1,1;]"
|
||||||
formspec = formspec.."list[current_player;craft;2,"..formspecy..";3,3;]"
|
formspec = formspec.."list[current_player;craft;2,"..formspecy..";3,3;]"
|
||||||
if unified_inventory.trash_enabled or unified_inventory.is_creative(player_name) or minetest.get_player_privs(player_name).give then
|
if unified_inventory.trash_enabled or unified_inventory.is_creative(player_name) or minetest.get_player_privs(player_name).give then
|
||||||
formspec = formspec.."label[7,"..(formspecy + 1.5)..";" .. F("Trash:") .. "]"
|
formspec = formspec.."label[7,"..(formspecy + 1.5)..";" .. F(S("Trash:")) .. "]"
|
||||||
formspec = formspec.."background[7,"..(formspecy + 2)..";1,1;ui_single_slot.png]"
|
formspec = formspec.."background[7,"..(formspecy + 2)..";1,1;ui_single_slot.png]"
|
||||||
formspec = formspec.."list[detached:trash;main;7,"..(formspecy + 2)..";1,1;]"
|
formspec = formspec.."list[detached:trash;main;7,"..(formspecy + 2)..";1,1;]"
|
||||||
end
|
end
|
||||||
formspec = formspec.."listring[current_name;craft]"
|
formspec = formspec.."listring[current_name;craft]"
|
||||||
formspec = formspec.."listring[current_player;main]"
|
formspec = formspec.."listring[current_player;main]"
|
||||||
if unified_inventory.is_creative(player_name) then
|
if unified_inventory.is_creative(player_name) then
|
||||||
formspec = formspec.."label[0,"..(formspecy + 1.5)..";" .. F("Refill:") .. "]"
|
formspec = formspec.."label[0,"..(formspecy + 1.5)..";" .. F(S("Refill:")) .. "]"
|
||||||
formspec = formspec.."list[detached:"..minetest.formspec_escape(player_name).."refill;main;0,"..(formspecy +2)..";1,1;]"
|
formspec = formspec.."list[detached:"..F(player_name).."refill;main;0,"..(formspecy +2)..";1,1;]"
|
||||||
end
|
end
|
||||||
return {formspec=formspec}
|
return {formspec=formspec}
|
||||||
end,
|
end,
|
||||||
@ -211,10 +211,10 @@ 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 ""
|
||||||
local buttonname = minetest.formspec_escape(buttonname_prefix..unified_inventory.mangle_for_formspec(selectitem))
|
local buttonname = F(buttonname_prefix..unified_inventory.mangle_for_formspec(selectitem))
|
||||||
local button = string.format("item_image_button[%f,%f;%f,%f;%s;%s;%s]",
|
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), buttonname, label)
|
F(displayitem), buttonname, label)
|
||||||
if show_is_group then
|
if show_is_group then
|
||||||
local groupstring, andcount = unified_inventory.extract_groupnames(name)
|
local groupstring, andcount = unified_inventory.extract_groupnames(name)
|
||||||
local grouptip
|
local grouptip
|
||||||
@ -223,7 +223,7 @@ local function stack_image_button(x, y, w, h, buttonname_prefix, item)
|
|||||||
elseif andcount > 1 then
|
elseif andcount > 1 then
|
||||||
grouptip = string.format(S("Any item belonging to the groups %s"), groupstring)
|
grouptip = string.format(S("Any item belonging to the groups %s"), groupstring)
|
||||||
end
|
end
|
||||||
grouptip = minetest.formspec_escape(grouptip)
|
grouptip = F(grouptip)
|
||||||
if andcount >= 1 then
|
if andcount >= 1 then
|
||||||
button = button .. string.format("tooltip[%s;%s]", buttonname, grouptip)
|
button = button .. string.format("tooltip[%s;%s]", buttonname, grouptip)
|
||||||
end
|
end
|
||||||
@ -232,28 +232,28 @@ local function stack_image_button(x, y, w, h, buttonname_prefix, item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local recipe_text = {
|
local recipe_text = {
|
||||||
recipe = "Recipe %d of %d",
|
recipe = S("Recipe %d of %d"),
|
||||||
usage = "Usage %d of %d",
|
usage = S("Usage %d of %d"),
|
||||||
}
|
}
|
||||||
local no_recipe_text = {
|
local no_recipe_text = {
|
||||||
recipe = "No recipes",
|
recipe = S("No recipes"),
|
||||||
usage = "No usages",
|
usage = S("No usages"),
|
||||||
}
|
}
|
||||||
local role_text = {
|
local role_text = {
|
||||||
recipe = "Result",
|
recipe = S("Result"),
|
||||||
usage = "Ingredient",
|
usage = S("Ingredient"),
|
||||||
}
|
}
|
||||||
local next_alt_text = {
|
local next_alt_text = {
|
||||||
recipe = "Show next recipe",
|
recipe = S("Show next recipe"),
|
||||||
usage = "Show next usage",
|
usage = S("Show next usage"),
|
||||||
}
|
}
|
||||||
local prev_alt_text = {
|
local prev_alt_text = {
|
||||||
recipe = "Show previous recipe",
|
recipe = S("Show previous recipe"),
|
||||||
usage = "Show previous usage",
|
usage = S("Show previous usage"),
|
||||||
}
|
}
|
||||||
local other_dir = {
|
local other_dir = {
|
||||||
recipe = "usage",
|
recipe = S("usage"),
|
||||||
usage = "recipe",
|
usage = S("recipe"),
|
||||||
}
|
}
|
||||||
|
|
||||||
unified_inventory.register_page("craftguide", {
|
unified_inventory.register_page("craftguide", {
|
||||||
@ -268,7 +268,7 @@ unified_inventory.register_page("craftguide", {
|
|||||||
local player_privs = minetest.get_player_privs(player_name)
|
local player_privs = minetest.get_player_privs(player_name)
|
||||||
local formspec = ""
|
local formspec = ""
|
||||||
formspec = formspec.."background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]"
|
formspec = formspec.."background[0,"..(formspecy + 3.5)..";8,4;ui_main_inventory.png]"
|
||||||
formspec = formspec.."label[0,"..formheadery..";" .. F("Crafting Guide") .. "]"
|
formspec = formspec.."label[0,"..formheadery..";" .. F(S("Crafting Guide")) .. "]"
|
||||||
formspec = formspec.."listcolors[#00000000;#00000000]"
|
formspec = formspec.."listcolors[#00000000;#00000000]"
|
||||||
local item_name = unified_inventory.current_item[player_name]
|
local item_name = unified_inventory.current_item[player_name]
|
||||||
if not item_name then return {formspec=formspec} end
|
if not item_name then return {formspec=formspec} end
|
||||||
@ -293,20 +293,20 @@ unified_inventory.register_page("craftguide", {
|
|||||||
|
|
||||||
formspec = formspec.."background[0.5,"..(formspecy + 0.2)..";8,3;ui_craftguide_form.png]"
|
formspec = formspec.."background[0.5,"..(formspecy + 0.2)..";8,3;ui_craftguide_form.png]"
|
||||||
formspec = formspec.."textarea["..craftresultx..","..craftresulty
|
formspec = formspec.."textarea["..craftresultx..","..craftresulty
|
||||||
..";10,1;;"..minetest.formspec_escape(F(role_text[dir])..": "..item_name_shown)..";]"
|
..";10,1;;"..F(role_text[dir])..": "..item_name_shown..";]"
|
||||||
formspec = formspec..stack_image_button(0, formspecy, 1.1, 1.1, "item_button_"
|
formspec = formspec..stack_image_button(0, formspecy, 1.1, 1.1, "item_button_"
|
||||||
.. rdir .. "_", ItemStack(item_name))
|
.. rdir .. "_", ItemStack(item_name))
|
||||||
|
|
||||||
if not craft then
|
if not craft then
|
||||||
formspec = formspec.."label[5.5,"..(formspecy + 2.35)..";"
|
formspec = formspec.."label[5.5,"..(formspecy + 2.35)..";"
|
||||||
..minetest.formspec_escape(F(no_recipe_text[dir])).."]"
|
..F(no_recipe_text[dir]).."]"
|
||||||
local no_pos = dir == "recipe" and 4.5 or 6.5
|
local no_pos = dir == "recipe" and 4.5 or 6.5
|
||||||
local item_pos = dir == "recipe" and 6.5 or 4.5
|
local item_pos = dir == "recipe" and 6.5 or 4.5
|
||||||
formspec = formspec.."image["..no_pos..","..formspecy..";1.1,1.1;ui_no.png]"
|
formspec = formspec.."image["..no_pos..","..formspecy..";1.1,1.1;ui_no.png]"
|
||||||
formspec = formspec..stack_image_button(item_pos, formspecy, 1.1, 1.1, "item_button_"
|
formspec = formspec..stack_image_button(item_pos, formspecy, 1.1, 1.1, "item_button_"
|
||||||
..other_dir[dir].."_", ItemStack(item_name))
|
..other_dir[dir].."_", ItemStack(item_name))
|
||||||
if player_privs.give == true or player_privs.creative == true or minetest.setting_getbool("creative_mode") == true then
|
if player_privs.give == true or player_privs.creative == true or minetest.setting_getbool("creative_mode") == true then
|
||||||
formspec = formspec.."label[0,"..(formspecy + 2.10)..";" .. F("Give me:") .. "]"
|
formspec = formspec.."label[0,"..(formspecy + 2.10)..";" .. F(S("Give me:")) .. "]"
|
||||||
.."button[0, "..(formspecy + 2.7)..";0.6,0.5;craftguide_giveme_1;1]"
|
.."button[0, "..(formspecy + 2.7)..";0.6,0.5;craftguide_giveme_1;1]"
|
||||||
.."button[0.6,"..(formspecy + 2.7)..";0.7,0.5;craftguide_giveme_10;10]"
|
.."button[0.6,"..(formspecy + 2.7)..";0.7,0.5;craftguide_giveme_10;10]"
|
||||||
.."button[1.3,"..(formspecy + 2.7)..";0.8,0.5;craftguide_giveme_99;99]"
|
.."button[1.3,"..(formspecy + 2.7)..";0.8,0.5;craftguide_giveme_99;99]"
|
||||||
@ -319,7 +319,7 @@ unified_inventory.register_page("craftguide", {
|
|||||||
if craft_type.icon then
|
if craft_type.icon then
|
||||||
formspec = formspec..string.format(" image[%f,%f;%f,%f;%s]",5.7,(formspecy + 0.05),0.5,0.5,craft_type.icon)
|
formspec = formspec..string.format(" image[%f,%f;%f,%f;%s]",5.7,(formspecy + 0.05),0.5,0.5,craft_type.icon)
|
||||||
end
|
end
|
||||||
formspec = formspec.."label[5.5,"..(formspecy + 1)..";" .. minetest.formspec_escape(craft_type.description).."]"
|
formspec = formspec.."label[5.5,"..(formspecy + 1)..";" .. F(craft_type.description).."]"
|
||||||
formspec = formspec..stack_image_button(6.5, formspecy, 1.1, 1.1, "item_button_usage_", ItemStack(craft.output))
|
formspec = formspec..stack_image_button(6.5, formspecy, 1.1, 1.1, "item_button_usage_", ItemStack(craft.output))
|
||||||
local display_size = craft_type.dynamic_display_size and craft_type.dynamic_display_size(craft) or { width = craft_type.width, height = craft_type.height }
|
local display_size = craft_type.dynamic_display_size and craft_type.dynamic_display_size(craft) or { width = craft_type.width, height = craft_type.height }
|
||||||
local craft_width = craft_type.get_shaped_craft_width and craft_type.get_shaped_craft_width(craft) or display_size.width
|
local craft_width = craft_type.get_shaped_craft_width and craft_type.get_shaped_craft_width(craft) or display_size.width
|
||||||
@ -373,17 +373,17 @@ unified_inventory.register_page("craftguide", {
|
|||||||
-- Error
|
-- Error
|
||||||
formspec = formspec.."label["
|
formspec = formspec.."label["
|
||||||
..tostring(2)..","..tostring(formspecy)
|
..tostring(2)..","..tostring(formspecy)
|
||||||
..";"..minetest.formspec_escape(S("This recipe is too\nlarge to be displayed.")).."]"
|
..";"..F(S("This recipe is too\nlarge to be displayed.")).."]"
|
||||||
end
|
end
|
||||||
|
|
||||||
if craft_type.uses_crafting_grid and display_size.width <= 3 then
|
if craft_type.uses_crafting_grid and display_size.width <= 3 then
|
||||||
formspec = formspec.."label[0,"..(formspecy + 0.9)..";" .. F("To craft grid:") .. "]"
|
formspec = formspec.."label[0,"..(formspecy + 0.9)..";" .. F(S("To craft grid:")) .. "]"
|
||||||
.."button[0, "..(formspecy + 1.5)..";0.6,0.5;craftguide_craft_1;1]"
|
.."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]"
|
.."button[0.6,"..(formspecy + 1.5)..";0.7,0.5;craftguide_craft_10;10]"
|
||||||
.."button[1.3,"..(formspecy + 1.5)..";0.8,0.5;craftguide_craft_max;" .. F("All") .. "]"
|
.."button[1.3,"..(formspecy + 1.5)..";0.8,0.5;craftguide_craft_max;" .. F(S("All")) .. "]"
|
||||||
end
|
end
|
||||||
if player_privs.give == true or player_privs.creative == true or minetest.setting_getbool("creative_mode") == true then
|
if player_privs.give == true or player_privs.creative == true or minetest.setting_getbool("creative_mode") == true then
|
||||||
formspec = formspec.."label[0,"..(formspecy + 2.1)..";" .. F("Give me:") .. "]"
|
formspec = formspec.."label[0,"..(formspecy + 2.1)..";" .. F(S("Give me:")) .. "]"
|
||||||
.."button[0, "..(formspecy + 2.7)..";0.6,0.5;craftguide_giveme_1;1]"
|
.."button[0, "..(formspecy + 2.7)..";0.6,0.5;craftguide_giveme_1;1]"
|
||||||
.."button[0.6,"..(formspecy + 2.7)..";0.7,0.5;craftguide_giveme_10;10]"
|
.."button[0.6,"..(formspecy + 2.7)..";0.7,0.5;craftguide_giveme_10;10]"
|
||||||
.."button[1.3,"..(formspecy + 2.7)..";0.8,0.5;craftguide_giveme_99;99]"
|
.."button[1.3,"..(formspecy + 2.7)..";0.8,0.5;craftguide_giveme_99;99]"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
local S = unified_inventory.gettext
|
local S = unified_inventory.gettext
|
||||||
local F = unified_inventory.fgettext
|
local F = minetest.formspec_escape
|
||||||
|
|
||||||
local hud_colors = {
|
local hud_colors = {
|
||||||
{"#FFFFFF", 0xFFFFFF, S("White")},
|
{"#FFFFFF", 0xFFFFFF, S("White")},
|
||||||
@ -25,7 +25,7 @@ unified_inventory.register_page("waypoints", {
|
|||||||
local waypoints = datastorage.get(player_name, "waypoints")
|
local waypoints = datastorage.get(player_name, "waypoints")
|
||||||
local formspec = "background[0,4.5;8,4;ui_main_inventory.png]" ..
|
local formspec = "background[0,4.5;8,4;ui_main_inventory.png]" ..
|
||||||
"image[0,0;1,1;ui_waypoints_icon.png]" ..
|
"image[0,0;1,1;ui_waypoints_icon.png]" ..
|
||||||
"label[1,0;" .. F("Waypoints") .. "]"
|
"label[1,0;" .. F(S("Waypoints")) .. "]"
|
||||||
|
|
||||||
-- Tabs buttons:
|
-- Tabs buttons:
|
||||||
for i = 1, 5, 1 do
|
for i = 1, 5, 1 do
|
||||||
@ -49,43 +49,43 @@ unified_inventory.register_page("waypoints", {
|
|||||||
"ui_waypoint_set_icon.png;"..
|
"ui_waypoint_set_icon.png;"..
|
||||||
"set_waypoint"..i..";]"..
|
"set_waypoint"..i..";]"..
|
||||||
"tooltip[set_waypoint" .. i .. ";"
|
"tooltip[set_waypoint" .. i .. ";"
|
||||||
.. F("Set waypoint to current location").."]"
|
.. F(S("Set waypoint to current location")).."]"
|
||||||
|
|
||||||
formspec = formspec ..
|
formspec = formspec ..
|
||||||
"image_button[5.2,3.7;.8,.8;"..
|
"image_button[5.2,3.7;.8,.8;"..
|
||||||
(waypoint.active and "ui_on_icon.png" or "ui_off_icon.png")..";"..
|
(waypoint.active and "ui_on_icon.png" or "ui_off_icon.png")..";"..
|
||||||
"toggle_waypoint"..i..";]"..
|
"toggle_waypoint"..i..";]"..
|
||||||
"tooltip[toggle_waypoint" .. i .. ";"
|
"tooltip[toggle_waypoint" .. i .. ";"
|
||||||
.. F("Make waypoint "
|
.. F(S("Make waypoint @1",
|
||||||
..(waypoint.active and "invisible" or "visible")).."]"
|
waypoint.active and S("invisible") or S("visible"))).."]"
|
||||||
|
|
||||||
formspec = formspec ..
|
formspec = formspec ..
|
||||||
"image_button[5.9,3.7;.8,.8;"..
|
"image_button[5.9,3.7;.8,.8;"..
|
||||||
(waypoint.display_pos and "ui_green_icon_background.png" or "ui_red_icon_background.png").."^ui_xyz_icon.png;"..
|
(waypoint.display_pos and "ui_green_icon_background.png" or "ui_red_icon_background.png").."^ui_xyz_icon.png;"..
|
||||||
"toggle_display_pos" .. i .. ";]"..
|
"toggle_display_pos" .. i .. ";]"..
|
||||||
"tooltip[toggle_display_pos" .. i .. ";"
|
"tooltip[toggle_display_pos" .. i .. ";"
|
||||||
.. F((waypoint.display_pos and "Disable" or "Enable")
|
.. F(S("@1 display of waypoint coordinates",
|
||||||
.." display of waypoint coordinates").."]"
|
waypoint.display_pos and S("Disable") or S("Enable"))) .."]"
|
||||||
|
|
||||||
formspec = formspec ..
|
formspec = formspec ..
|
||||||
"image_button[6.6,3.7;.8,.8;"..
|
"image_button[6.6,3.7;.8,.8;"..
|
||||||
"ui_circular_arrows_icon.png;"..
|
"ui_circular_arrows_icon.png;"..
|
||||||
"toggle_color"..i..";]"..
|
"toggle_color"..i..";]"..
|
||||||
"tooltip[toggle_color" .. i .. ";"
|
"tooltip[toggle_color" .. i .. ";"
|
||||||
.. F("Change color of waypoint display").."]"
|
.. F(S("Change color of waypoint display")).."]"
|
||||||
|
|
||||||
formspec = formspec ..
|
formspec = formspec ..
|
||||||
"image_button[7.3,3.7;.8,.8;"..
|
"image_button[7.3,3.7;.8,.8;"..
|
||||||
"ui_pencil_icon.png;"..
|
"ui_pencil_icon.png;"..
|
||||||
"rename_waypoint"..i..";]"..
|
"rename_waypoint"..i..";]"..
|
||||||
"tooltip[rename_waypoint" .. i .. ";"
|
"tooltip[rename_waypoint" .. i .. ";"
|
||||||
.. F("Edit waypoint name").."]"
|
.. F(S("Edit waypoint name")).."]"
|
||||||
|
|
||||||
-- Waypoint's info:
|
-- Waypoint's info:
|
||||||
if waypoint.active then
|
if waypoint.active then
|
||||||
formspec = formspec .. "label[1,0.8;"..F("Waypoint active").."]"
|
formspec = formspec .. "label[1,0.8;"..F(S("Waypoint active")).."]"
|
||||||
else
|
else
|
||||||
formspec = formspec .. "label[1,0.8;"..F("Waypoint inactive").."]"
|
formspec = formspec .. "label[1,0.8;"..F(S("Waypoint inactive")).."]"
|
||||||
end
|
end
|
||||||
|
|
||||||
if temp.edit then
|
if temp.edit then
|
||||||
@ -96,13 +96,13 @@ unified_inventory.register_page("waypoints", {
|
|||||||
"ui_ok_icon.png;"..
|
"ui_ok_icon.png;"..
|
||||||
"confirm_rename"..i.. ";]"..
|
"confirm_rename"..i.. ";]"..
|
||||||
"tooltip[confirm_rename" .. i .. ";"
|
"tooltip[confirm_rename" .. i .. ";"
|
||||||
.. F("Finish editing").."]"
|
.. F(S("Finish editing")).."]"
|
||||||
end
|
end
|
||||||
|
|
||||||
formspec = formspec .. "label[1,1.3;"..F("World position")..": " ..
|
formspec = formspec .. "label[1,1.3;"..F(S("World position"))..": " ..
|
||||||
minetest.pos_to_string(waypoint.world_pos or vector.new()) .. "]" ..
|
minetest.pos_to_string(waypoint.world_pos or vector.new()) .. "]" ..
|
||||||
"label[1,1.8;"..F("Name")..": ".. (waypoint.name or default_name) .. "]" ..
|
"label[1,1.8;"..F(S("Name"))..": ".. (waypoint.name or default_name) .. "]" ..
|
||||||
"label[1,2.3;"..F("HUD text color")..": " ..
|
"label[1,2.3;"..F(S("HUD text color"))..": " ..
|
||||||
hud_colors[waypoint.color or 1][3] .. "]"
|
hud_colors[waypoint.color or 1][3] .. "]"
|
||||||
|
|
||||||
return {formspec=formspec}
|
return {formspec=formspec}
|
||||||
|
Loading…
Reference in New Issue
Block a user