X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=builtin%2Fcommon%2Finformation_formspecs.lua;h=1445a017cd39ab9060e128412839f21f1ed2ec5e;hb=ac4eb746fe9da775a8bffe825a868581c0353169;hp=4e893f7aa164be4d1b2d6a3587499922111e346d;hpb=69bf964241666428e8d1663164a443654f51d53a;p=minetest.git diff --git a/builtin/common/information_formspecs.lua b/builtin/common/information_formspecs.lua index 4e893f7aa..1445a017c 100644 --- a/builtin/common/information_formspecs.lua +++ b/builtin/common/information_formspecs.lua @@ -20,8 +20,8 @@ local LIST_FORMSPEC_DESCRIPTION = [[ button_exit[5,7;3,1;quit;%s] ]] -local formspec_escape = core.formspec_escape -local check_player_privs = core.check_player_privs +local F = core.formspec_escape +local S = core.get_translator("__builtin") -- CHAT COMMANDS FORMSPEC @@ -31,7 +31,6 @@ local mod_cmds = {} local function load_mod_command_tree() mod_cmds = {} - local check_player_privs = core.check_player_privs for name, def in pairs(core.registered_chatcommands) do mod_cmds[def.mod_origin] = mod_cmds[def.mod_origin] or {} local cmds = mod_cmds[def.mod_origin] @@ -52,22 +51,24 @@ core.after(0, load_mod_command_tree) local function build_chatcommands_formspec(name, sel, copy) local rows = {} - rows[1] = "#FFF,0,Command,Parameters" + rows[1] = "#FFF,0,"..F(S("Command"))..","..F(S("Parameters")) - local description = "For more information, click on any entry in the list.\n" .. - "Double-click to copy the entry to the chat history." + local description = S("For more information, click on " + .. "any entry in the list.").. "\n" .. + S("Double-click to copy the entry to the chat history.") + local privs = core.get_player_privs(name) for i, data in ipairs(mod_cmds) do - rows[#rows + 1] = COLOR_BLUE .. ",0," .. formspec_escape(data[1]) .. "," + rows[#rows + 1] = COLOR_BLUE .. ",0," .. F(data[1]) .. "," for j, cmds in ipairs(data[2]) do - local has_priv = check_player_privs(name, cmds[2].privs) + local has_priv = privs[cmds[2].privs] rows[#rows + 1] = ("%s,1,%s,%s"):format( has_priv and COLOR_GREEN or COLOR_GRAY, - cmds[1], formspec_escape(cmds[2].params)) + cmds[1], F(cmds[2].params)) if sel == #rows then description = cmds[2].description if copy then - core.chat_send_player(name, ("Command: %s %s"):format( + core.chat_send_player(name, S("Command: @1 @2", core.colorize("#0FF", "/" .. cmds[1]), cmds[2].params)) end end @@ -75,36 +76,36 @@ local function build_chatcommands_formspec(name, sel, copy) end return LIST_FORMSPEC_DESCRIPTION:format( - "Available commands: (see also: /help )", + F(S("Available commands: (see also: /help )")), table.concat(rows, ","), sel or 0, - description, "Close" + F(description), F(S("Close")) ) end --- PRIVILEGES FORMSPEC +-- PRIVILEGES FORMSPEC local function build_privs_formspec(name) local privs = {} - for name, def in pairs(core.registered_privileges) do - privs[#privs + 1] = { name, def } + for priv_name, def in pairs(core.registered_privileges) do + privs[#privs + 1] = { priv_name, def } end table.sort(privs, function(a, b) return a[1] < b[1] end) local rows = {} - rows[1] = "#FFF,0,Privilege,Description" + rows[1] = "#FFF,0,"..F(S("Privilege"))..","..F(S("Description")) local player_privs = core.get_player_privs(name) for i, data in ipairs(privs) do rows[#rows + 1] = ("%s,0,%s,%s"):format( player_privs[data[1]] and COLOR_GREEN or COLOR_GRAY, - data[1], formspec_escape(data[2].description)) + data[1], F(data[2].description)) end return LIST_FORMSPEC:format( - "Available privileges:", + F(S("Available privileges:")), table.concat(rows, ","), - "Close" + F(S("Close")) ) end @@ -116,7 +117,7 @@ core.register_on_player_receive_fields(function(player, formname, fields) return end - local event = minetest.explode_table_event(fields.list) + local event = core.explode_table_event(fields.list) if event.type ~= "INV" then local name = player:get_player_name() core.show_formspec(name, "__builtin:help_cmds", @@ -124,22 +125,12 @@ core.register_on_player_receive_fields(function(player, formname, fields) end end) - -local help_command = core.registered_chatcommands["help"] -local old_help_func = help_command.func - -help_command.func = function(name, param) - if param == "privs" then - core.show_formspec(name, "__builtin:help_privs", - build_privs_formspec(name)) - return - end - if param == "" or param == "all" then - core.show_formspec(name, "__builtin:help_cmds", - build_chatcommands_formspec(name)) - return - end - - old_help_func(name, param) +function core.show_general_help_formspec(name) + core.show_formspec(name, "__builtin:help_cmds", + build_chatcommands_formspec(name)) end +function core.show_privs_help_formspec(name) + core.show_formspec(name, "__builtin:help_privs", + build_privs_formspec(name)) +end