mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 08:03:45 +01:00
Add help formspec for CSM commands (#13937)
This commit is contained in:
parent
176e674a51
commit
893594d81a
@ -7,6 +7,7 @@ dofile(clientpath .. "register.lua")
|
|||||||
dofile(commonpath .. "after.lua")
|
dofile(commonpath .. "after.lua")
|
||||||
dofile(commonpath .. "mod_storage.lua")
|
dofile(commonpath .. "mod_storage.lua")
|
||||||
dofile(commonpath .. "chatcommands.lua")
|
dofile(commonpath .. "chatcommands.lua")
|
||||||
|
dofile(commonpath .. "information_formspecs.lua")
|
||||||
dofile(clientpath .. "chatcommands.lua")
|
dofile(clientpath .. "chatcommands.lua")
|
||||||
dofile(clientpath .. "death_formspec.lua")
|
dofile(clientpath .. "death_formspec.lua")
|
||||||
dofile(clientpath .. "misc.lua")
|
dofile(clientpath .. "misc.lua")
|
||||||
|
@ -89,7 +89,7 @@ local function do_help_cmd(name, param)
|
|||||||
if #args > 1 then
|
if #args > 1 then
|
||||||
return false, S("Too many arguments, try using just /help <command>")
|
return false, S("Too many arguments, try using just /help <command>")
|
||||||
end
|
end
|
||||||
local use_gui = INIT ~= "client" and core.get_player_by_name(name)
|
local use_gui = INIT == "client" or core.get_player_by_name(name)
|
||||||
use_gui = use_gui and not opts:find("t")
|
use_gui = use_gui and not opts:find("t")
|
||||||
|
|
||||||
if #args == 0 and not use_gui then
|
if #args == 0 and not use_gui then
|
||||||
@ -163,8 +163,8 @@ end
|
|||||||
|
|
||||||
if INIT == "client" then
|
if INIT == "client" then
|
||||||
core.register_chatcommand("help", {
|
core.register_chatcommand("help", {
|
||||||
params = core.gettext("[all | <cmd>]"),
|
params = core.gettext("[all | <cmd>] [-t]"),
|
||||||
description = core.gettext("Get help for commands"),
|
description = core.gettext("Get help for commands (-t: output in chat)"),
|
||||||
func = function(param)
|
func = function(param)
|
||||||
return do_help_cmd(nil, param)
|
return do_help_cmd(nil, param)
|
||||||
end,
|
end,
|
||||||
|
@ -61,15 +61,20 @@ local function build_chatcommands_formspec(name, sel, copy)
|
|||||||
for i, data in ipairs(mod_cmds) do
|
for i, data in ipairs(mod_cmds) do
|
||||||
rows[#rows + 1] = COLOR_BLUE .. ",0," .. F(data[1]) .. ","
|
rows[#rows + 1] = COLOR_BLUE .. ",0," .. F(data[1]) .. ","
|
||||||
for j, cmds in ipairs(data[2]) do
|
for j, cmds in ipairs(data[2]) do
|
||||||
local has_priv = check_player_privs(name, cmds[2].privs)
|
local has_priv = INIT == "client" or check_player_privs(name, cmds[2].privs)
|
||||||
rows[#rows + 1] = ("%s,1,%s,%s"):format(
|
rows[#rows + 1] = ("%s,1,%s,%s"):format(
|
||||||
has_priv and COLOR_GREEN or COLOR_GRAY,
|
has_priv and COLOR_GREEN or COLOR_GRAY,
|
||||||
cmds[1], F(cmds[2].params))
|
cmds[1], F(cmds[2].params))
|
||||||
if sel == #rows then
|
if sel == #rows then
|
||||||
description = cmds[2].description
|
description = cmds[2].description
|
||||||
if copy then
|
if copy then
|
||||||
core.chat_send_player(name, S("Command: @1 @2",
|
local msg = S("Command: @1 @2",
|
||||||
core.colorize("#0FF", "/" .. cmds[1]), cmds[2].params))
|
core.colorize("#0FF", "/" .. cmds[1]), cmds[2].params)
|
||||||
|
if INIT == "client" then
|
||||||
|
core.display_chat_message(msg)
|
||||||
|
else
|
||||||
|
core.chat_send_player(name, msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -111,26 +116,46 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- DETAILED CHAT COMMAND INFORMATION
|
-- DETAILED CHAT COMMAND INFORMATION
|
||||||
|
if INIT == "client" then
|
||||||
|
core.register_on_formspec_input(function(formname, fields)
|
||||||
|
if formname ~= "__builtin:help_cmds" or fields.quit then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
core.register_on_player_receive_fields(function(player, formname, fields)
|
local event = core.explode_table_event(fields.list)
|
||||||
if formname ~= "__builtin:help_cmds" or fields.quit then
|
if event.type ~= "INV" then
|
||||||
return
|
core.show_formspec("__builtin:help_cmds",
|
||||||
end
|
build_chatcommands_formspec(nil, event.row, event.type == "DCL"))
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
core.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
if formname ~= "__builtin:help_cmds" or fields.quit then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local event = core.explode_table_event(fields.list)
|
local event = core.explode_table_event(fields.list)
|
||||||
if event.type ~= "INV" then
|
if event.type ~= "INV" then
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
core.show_formspec(name, "__builtin:help_cmds",
|
core.show_formspec(name, "__builtin:help_cmds",
|
||||||
build_chatcommands_formspec(name, event.row, event.type == "DCL"))
|
build_chatcommands_formspec(name, event.row, event.type == "DCL"))
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
function core.show_general_help_formspec(name)
|
function core.show_general_help_formspec(name)
|
||||||
core.show_formspec(name, "__builtin:help_cmds",
|
if INIT == "client" then
|
||||||
build_chatcommands_formspec(name))
|
core.show_formspec("__builtin:help_cmds",
|
||||||
|
build_chatcommands_formspec(name))
|
||||||
|
else
|
||||||
|
core.show_formspec(name, "__builtin:help_cmds",
|
||||||
|
build_chatcommands_formspec(name))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function core.show_privs_help_formspec(name)
|
if INIT ~= "client" then
|
||||||
core.show_formspec(name, "__builtin:help_privs",
|
function core.show_privs_help_formspec(name)
|
||||||
build_privs_formspec(name))
|
core.show_formspec(name, "__builtin:help_privs",
|
||||||
|
build_privs_formspec(name))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user