forked from mtcontrib/Minetest-WorldEdit
Refine GUI.
This commit is contained in:
parent
dbc2348014
commit
6c03ab9c4a
|
@ -19,7 +19,7 @@ end
|
||||||
--determines whether `nodename` is a valid node name, returning a boolean
|
--determines whether `nodename` is a valid node name, returning a boolean
|
||||||
worldedit.normalize_nodename = function(nodename)
|
worldedit.normalize_nodename = function(nodename)
|
||||||
local fullname = ItemStack({name=nodename}):get_name() --resolve aliases of node names to full names
|
local fullname = ItemStack({name=nodename}):get_name() --resolve aliases of node names to full names
|
||||||
if minetest.registered_nodes[fullname] then --directly found node name or alias of nodename
|
if minetest.registered_nodes[fullname] or fullname == "air" then --directly found node name or alias of nodename
|
||||||
return fullname
|
return fullname
|
||||||
end
|
end
|
||||||
for key, value in pairs(minetest.registered_nodes) do
|
for key, value in pairs(minetest.registered_nodes) do
|
||||||
|
|
|
@ -1,70 +1,37 @@
|
||||||
worldedit.register_gui_function("worldedit_gui_about", {
|
--saved state per player
|
||||||
name = "About",
|
local gui_nodename1 = {}
|
||||||
privs = minetest.chatcommands["/about"].privs,
|
local gui_nodename2 = {}
|
||||||
on_select = function(name)
|
local gui_radius = {}
|
||||||
minetest.chatcommands["/about"].func(name, "")
|
local gui_formspec = {}
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
worldedit.register_gui_function("worldedit_gui_inspect", {
|
local register_gui_chatcommand = function(identifier, name, command, callback)
|
||||||
name = "Toggle Inspection",
|
callback = callback or function(name, command) command(name, "") end
|
||||||
privs = minetest.chatcommands["/inspect"].privs,
|
worldedit.register_gui_function(identifier, {
|
||||||
on_select = function(name)
|
name = name,
|
||||||
minetest.chatcommands["/inspect"].func(name, worldedit.inspect[name] and "disable" or "enable")
|
privs = minetest.chatcommands[command].privs,
|
||||||
end,
|
on_select = function(name)
|
||||||
})
|
return callback(name, minetest.chatcommands[command].func)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
worldedit.register_gui_function("worldedit_gui_reset", {
|
register_gui_chatcommand("worldedit_gui_about", "About", "/about")
|
||||||
name = "Reset Region",
|
register_gui_chatcommand("worldedit_gui_inspect", "Toggle Inspection", "/inspect", function(name, command)
|
||||||
privs = minetest.chatcommands["/reset"].privs,
|
command(name, worldedit.inspect[name] and "disable" or "enable")
|
||||||
on_select = function(name)
|
end)
|
||||||
minetest.chatcommands["/reset"].func(name, "")
|
register_gui_chatcommand("worldedit_gui_reset", "Reset Region", "/reset")
|
||||||
end,
|
register_gui_chatcommand("worldedit_gui_mark", "Mark Region", "/mark")
|
||||||
})
|
register_gui_chatcommand("worldedit_gui_unmark", "Unmark Region", "/unmark")
|
||||||
|
|
||||||
worldedit.register_gui_function("worldedit_gui_mark", {
|
|
||||||
name = "Mark Region",
|
|
||||||
privs = minetest.chatcommands["/mark"].privs,
|
|
||||||
on_select = function(name)
|
|
||||||
minetest.chatcommands["/mark"].func(name, "")
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
worldedit.register_gui_function("worldedit_gui_unmark", {
|
|
||||||
name = "Unmark Region",
|
|
||||||
privs = minetest.chatcommands["/unmark"].privs,
|
|
||||||
on_select = function(name)
|
|
||||||
minetest.chatcommands["/unmark"].func(name, "")
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
worldedit.register_gui_function("worldedit_gui_pos1", {
|
|
||||||
name = "Position 1 Here",
|
|
||||||
privs = minetest.chatcommands["/pos1"].privs,
|
|
||||||
on_select = function(name)
|
|
||||||
minetest.chatcommands["/pos1"].func(name, "")
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
worldedit.register_gui_function("worldedit_gui_pos2", {
|
|
||||||
name = "Position 2 Here",
|
|
||||||
privs = minetest.chatcommands["/pos2"].privs,
|
|
||||||
on_select = function(name)
|
|
||||||
minetest.chatcommands["/pos2"].func(name, "")
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
worldedit.register_gui_function("worldedit_gui_p", {
|
worldedit.register_gui_function("worldedit_gui_p", {
|
||||||
name = "Get/Set Positions",
|
name = "Get/Set Positions", privs = minetest.chatcommands["/p"].privs,
|
||||||
privs = minetest.chatcommands["/p"].privs,
|
|
||||||
get_formspec = function(name)
|
get_formspec = function(name)
|
||||||
return "size[12,2]" ..
|
return "size[9,2.5]" .. worldedit.get_formspec_header("worldedit_gui_p") ..
|
||||||
"button[0,0;2,0.5;worldedit_gui;Back]" ..
|
|
||||||
"label[2,0;WorldEdit GUI > Get/Set Positions]" ..
|
|
||||||
"button_exit[0,1;3,0.8;worldedit_gui_p_get;Get Positions]" ..
|
"button_exit[0,1;3,0.8;worldedit_gui_p_get;Get Positions]" ..
|
||||||
"button_exit[3,1;3,0.8;worldedit_gui_p_set;Set Positions]" ..
|
"button_exit[3,1;3,0.8;worldedit_gui_p_set1;Set Position 1]" ..
|
||||||
"button_exit[6,1;3,0.8;worldedit_gui_p_set1;Set Position 1]" ..
|
"button_exit[6,1;3,0.8;worldedit_gui_p_set2;Set Position 2]" ..
|
||||||
"button_exit[9,1;3,0.8;worldedit_gui_p_set2;Set Position 2]"
|
"button_exit[0,2;3,0.8;worldedit_gui_pos1;Position 1 Here]" ..
|
||||||
|
"button_exit[3,2;3,0.8;worldedit_gui_pos2;Position 2 Here]"
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -72,27 +39,27 @@ worldedit.register_gui_handler("worldedit_gui_p", function(name, fields)
|
||||||
if fields.worldedit_gui_p_get then
|
if fields.worldedit_gui_p_get then
|
||||||
minetest.chatcommands["/p"].func(name, "get")
|
minetest.chatcommands["/p"].func(name, "get")
|
||||||
return true
|
return true
|
||||||
elseif fields.worldedit_gui_p_set then
|
|
||||||
minetest.chatcommands["/p"].func(name, "set")
|
|
||||||
return true
|
|
||||||
elseif fields.worldedit_gui_p_set1 then
|
elseif fields.worldedit_gui_p_set1 then
|
||||||
minetest.chatcommands["/p"].func(name, "set1")
|
minetest.chatcommands["/p"].func(name, "set1")
|
||||||
return true
|
return true
|
||||||
elseif fields.worldedit_gui_p_set2 then
|
elseif fields.worldedit_gui_p_set2 then
|
||||||
minetest.chatcommands["/p"].func(name, "set2")
|
minetest.chatcommands["/p"].func(name, "set2")
|
||||||
return true
|
return true
|
||||||
|
elseif fields.worldedit_gui_pos1 then
|
||||||
|
minetest.chatcommands["/pos1"].func(name, "")
|
||||||
|
return true
|
||||||
|
elseif fields.worldedit_gui_pos2 then
|
||||||
|
minetest.chatcommands["/pos2"].func(name, "")
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
worldedit.register_gui_function("worldedit_gui_fixedpos", {
|
worldedit.register_gui_function("worldedit_gui_fixedpos", { --wip: combine this with get/set positions
|
||||||
name = "Fixed Positions",
|
name = "Fixed Positions", privs = minetest.chatcommands["/fixedpos"].privs,
|
||||||
privs = minetest.chatcommands["/fixedpos"].privs,
|
|
||||||
get_formspec = function(name)
|
get_formspec = function(name)
|
||||||
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
local pos1, pos2 = worldedit.pos1[name], worldedit.pos2[name]
|
||||||
return "size[6.5,4]" ..
|
return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_fixedpos") ..
|
||||||
"button[0,0;2,0.5;worldedit_gui;Back]" ..
|
|
||||||
"label[2,0;WorldEdit GUI > Fixed Positions]" ..
|
|
||||||
"label[0,1.2;Position 1]" ..
|
"label[0,1.2;Position 1]" ..
|
||||||
string.format("field[2,1.5;1.5,0.8;worldedit_gui_fixedpos_pos1x;Axis X;%s]", pos1 and pos1.x or "") ..
|
string.format("field[2,1.5;1.5,0.8;worldedit_gui_fixedpos_pos1x;Axis X;%s]", pos1 and pos1.x or "") ..
|
||||||
string.format("field[3.5,1.5;1.5,0.8;worldedit_gui_fixedpos_pos1y;Axis Y;%s]", pos1 and pos1.y or "") ..
|
string.format("field[3.5,1.5;1.5,0.8;worldedit_gui_fixedpos_pos1y;Axis Y;%s]", pos1 and pos1.y or "") ..
|
||||||
|
@ -101,147 +68,148 @@ worldedit.register_gui_function("worldedit_gui_fixedpos", {
|
||||||
string.format("field[2,2.5;1.5,0.8;worldedit_gui_fixedpos_pos2x;Axis X;%s]", pos2 and pos2.x or "") ..
|
string.format("field[2,2.5;1.5,0.8;worldedit_gui_fixedpos_pos2x;Axis X;%s]", pos2 and pos2.x or "") ..
|
||||||
string.format("field[3.5,2.5;1.5,0.8;worldedit_gui_fixedpos_pos2y;Axis Y;%s]", pos2 and pos2.y or "") ..
|
string.format("field[3.5,2.5;1.5,0.8;worldedit_gui_fixedpos_pos2y;Axis Y;%s]", pos2 and pos2.y or "") ..
|
||||||
string.format("field[5,2.5;1.5,0.8;worldedit_gui_fixedpos_pos2z;Axis Z;%s]", pos2 and pos2.z or "") ..
|
string.format("field[5,2.5;1.5,0.8;worldedit_gui_fixedpos_pos2z;Axis Z;%s]", pos2 and pos2.z or "") ..
|
||||||
"button_exit[0,3.5;4,0.8;worldedit_gui_fixedpos_submit;Set Fixed Positions]"
|
"button_exit[0,3.5;3,0.8;worldedit_gui_fixedpos_submit;Set Positions]"
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
worldedit.register_gui_handler("worldedit_gui_fixedpos", function(name, fields)
|
worldedit.register_gui_handler("worldedit_gui_fixedpos", function(name, fields)
|
||||||
if fields.worldedit_gui_fixedpos_submit then
|
if fields.worldedit_gui_fixedpos_submit then
|
||||||
if tonumber(fields.worldedit_gui_fixedpos_pos1x) and tonumber(fields.worldedit_gui_fixedpos_pos1y) and tonumber(fields.worldedit_gui_fixedpos_pos1z) then
|
local x1, y1, z1 = tonumber(fields.worldedit_gui_fixedpos_pos1x), tonumber(fields.worldedit_gui_fixedpos_pos1y), tonumber(fields.worldedit_gui_fixedpos_pos1z)
|
||||||
minetest.chatcommands["/fixedpos"].func(name, string.format("set1 %d %d %d",
|
if x1 and y1 and z1 then
|
||||||
tonumber(fields.worldedit_gui_fixedpos_pos1x), tonumber(fields.worldedit_gui_fixedpos_pos1y), tonumber(fields.worldedit_gui_fixedpos_pos1z)))
|
minetest.chatcommands["/fixedpos"].func(name, string.format("set1 %d %d %d", x1, y1, z1))
|
||||||
end
|
end
|
||||||
if tonumber(fields.worldedit_gui_fixedpos_pos2x) and tonumber(fields.worldedit_gui_fixedpos_pos2y) and tonumber(fields.worldedit_gui_fixedpos_pos2z) then
|
local x2, y2, z2 = tonumber(fields.worldedit_gui_fixedpos_pos2x), tonumber(fields.worldedit_gui_fixedpos_pos2y), tonumber(fields.worldedit_gui_fixedpos_pos2z)
|
||||||
minetest.chatcommands["/fixedpos"].func(name, string.format("set2 %d %d %d",
|
if x2 and y2 and z2 then
|
||||||
tonumber(fields.worldedit_gui_fixedpos_pos2x), tonumber(fields.worldedit_gui_fixedpos_pos2y), tonumber(fields.worldedit_gui_fixedpos_pos2z)))
|
minetest.chatcommands["/fixedpos"].func(name, string.format("set2 %d %d %d", x2, y2, z2))
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
worldedit.register_gui_function("worldedit_gui_volume", {
|
register_gui_chatcommand("worldedit_gui_volume", "Region Volume", "/volume")
|
||||||
name = "Region Volume",
|
|
||||||
privs = minetest.chatcommands["/volume"].privs,
|
|
||||||
on_select = function(name)
|
|
||||||
minetest.chatcommands["/volume"].func(name, "")
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
local gui_nodename_set = {}
|
|
||||||
worldedit.register_gui_function("worldedit_gui_set", {
|
worldedit.register_gui_function("worldedit_gui_set", {
|
||||||
name = "Set Nodes",
|
name = "Set Nodes", privs = minetest.chatcommands["/set"].privs,
|
||||||
privs = minetest.chatcommands["/set"].privs,
|
|
||||||
get_formspec = function(name)
|
get_formspec = function(name)
|
||||||
local value = gui_nodename_set[name] or "Cobblestone"
|
local value = gui_nodename1[name] or "Cobblestone"
|
||||||
local nodename = worldedit.normalize_nodename(value)
|
local nodename = worldedit.normalize_nodename(value)
|
||||||
value = nodename or value
|
return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_set") ..
|
||||||
return "size[6.5,3]" ..
|
|
||||||
"button[0,0;2,0.5;worldedit_gui;Back]" ..
|
|
||||||
"label[2,0;WorldEdit GUI > Set Nodes]" ..
|
|
||||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_set_node;Name;%s]", minetest.formspec_escape(value)) ..
|
string.format("field[0.5,1.5;4,0.8;worldedit_gui_set_node;Name;%s]", minetest.formspec_escape(value)) ..
|
||||||
"button[4,1.18;1.5,0.8;worldedit_gui_set_search;Search]" ..
|
"button[4,1.18;1.5,0.8;worldedit_gui_set_search;Search]" ..
|
||||||
(nodename and string.format("item_image[5.5,1.18;1,1;%s]", nodename)
|
(nodename and string.format("item_image[5.5,1.1;1,1;%s]", nodename)
|
||||||
or "image[5.5,1.18;1,1;unknown_node.png]") ..
|
or "image[5.5,1.1;1,1;unknown_node.png]") ..
|
||||||
"button_exit[0,2.5;4,0.8;worldedit_gui_set_submit;Set Nodes]"
|
"button_exit[0,2.5;3,0.8;worldedit_gui_set_submit;Set Nodes]"
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
worldedit.register_gui_handler("worldedit_gui_set", function(name, fields)
|
worldedit.register_gui_handler("worldedit_gui_set", function(name, fields)
|
||||||
if fields.worldedit_gui_set_search then
|
if fields.worldedit_gui_set_search then
|
||||||
gui_nodename_set[name] = fields.worldedit_gui_set_node
|
gui_nodename1[name] = fields.worldedit_gui_set_node
|
||||||
worldedit.show_page(name, "worldedit_gui_set")
|
worldedit.show_page(name, "worldedit_gui_set")
|
||||||
return true
|
return true
|
||||||
elseif fields.worldedit_gui_set_submit then
|
elseif fields.worldedit_gui_set_submit then
|
||||||
gui_nodename_set[name] = fields.worldedit_gui_set_node
|
gui_nodename1[name] = fields.worldedit_gui_set_node
|
||||||
minetest.chatcommands["/set"].func(name, gui_nodename_set[name])
|
minetest.chatcommands["/set"].func(name, gui_nodename1[name])
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local gui_nodename_replace = {}
|
|
||||||
worldedit.register_gui_function("worldedit_gui_replace", {
|
worldedit.register_gui_function("worldedit_gui_replace", {
|
||||||
name = "Replace Nodes",
|
name = "Replace Nodes", privs = minetest.chatcommands["/replace"].privs,
|
||||||
privs = minetest.chatcommands["/replace"].privs,
|
|
||||||
get_formspec = function(name)
|
get_formspec = function(name)
|
||||||
local search_value = gui_nodename_set[name] or "Cobblestone"
|
local search = gui_nodename1[name] or "Cobblestone"
|
||||||
local search_nodename = worldedit.normalize_nodename(search_value)
|
local search_nodename = worldedit.normalize_nodename(search)
|
||||||
search_value = search_nodename or search_value
|
local replace = gui_nodename2[name] or "Stone"
|
||||||
local replace_value, replace_nodename = gui_nodename_replace[name] or "Stone"
|
local replace_nodename = worldedit.normalize_nodename(replace)
|
||||||
local replace_nodename = worldedit.normalize_nodename(replace_value)
|
return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_replace") ..
|
||||||
replace_value = replace_nodename or replace_value
|
string.format("field[0.5,1.5;4,0.8;worldedit_gui_replace_search;Name;%s]", minetest.formspec_escape(search)) ..
|
||||||
return "size[6,4]" ..
|
|
||||||
"button[0,0;2,0.5;worldedit_gui;Back]" ..
|
|
||||||
"label[2,0;WorldEdit GUI > Replace Nodes]" ..
|
|
||||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_replace_search;Name;%s]", minetest.formspec_escape(search_value)) ..
|
|
||||||
"button[4,1.18;1.5,0.8;worldedit_gui_replace_search_search;Search]" ..
|
"button[4,1.18;1.5,0.8;worldedit_gui_replace_search_search;Search]" ..
|
||||||
(search_nodename and string.format("item_image[5.5,1.18;1,1;%s]", search_nodename)
|
(search_nodename and string.format("item_image[5.5,1.1;1,1;%s]", search_nodename)
|
||||||
or "image[5.5,1.18;1,1;unknown_node.png]") ..
|
or "image[5.5,1.1;1,1;unknown_node.png]") ..
|
||||||
string.format("field[0.5,2.5;4,0.8;worldedit_gui_replace_replace;Name;%s]", minetest.formspec_escape(replace_value)) ..
|
string.format("field[0.5,2.5;4,0.8;worldedit_gui_replace_replace;Name;%s]", minetest.formspec_escape(replace)) ..
|
||||||
"button[4,2.18;1.5,0.8;worldedit_gui_replace_replace_search;Search]" ..
|
"button[4,2.18;1.5,0.8;worldedit_gui_replace_replace_search;Search]" ..
|
||||||
(replace_nodename and string.format("item_image[5.5,2.18;1,1;%s]", replace_nodename)
|
(replace_nodename and string.format("item_image[5.5,2.1;1,1;%s]", replace_nodename)
|
||||||
or "image[5.5,2.18;1,1;unknown_node.png]") ..
|
or "image[5.5,2.1;1,1;unknown_node.png]") ..
|
||||||
"button_exit[0,3.5;4,0.8;worldedit_gui_replace_submit;Replace Nodes]"
|
"button_exit[0,3.5;3,0.8;worldedit_gui_replace_submit;Replace Nodes]" ..
|
||||||
|
"button_exit[3.5,3.5;3,0.8;worldedit_gui_replace_submit_inverse;Replace Inverse]"
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
worldedit.register_gui_handler("worldedit_gui_replace", function(name, fields)
|
worldedit.register_gui_handler("worldedit_gui_replace", function(name, fields)
|
||||||
if fields.worldedit_gui_replace_search_search then
|
if fields.worldedit_gui_replace_search_search then
|
||||||
gui_nodename_set[name] = fields.worldedit_gui_replace_search
|
gui_nodename1[name] = fields.worldedit_gui_replace_search
|
||||||
worldedit.show_page(name, "worldedit_gui_replace")
|
worldedit.show_page(name, "worldedit_gui_replace")
|
||||||
return true
|
return true
|
||||||
elseif fields.worldedit_gui_replace_replace_search then
|
elseif fields.worldedit_gui_replace_replace_search then
|
||||||
gui_nodename_replace[name] = fields.worldedit_gui_replace_replace
|
gui_nodename2[name] = fields.worldedit_gui_replace_replace
|
||||||
worldedit.show_page(name, "worldedit_gui_replace")
|
worldedit.show_page(name, "worldedit_gui_replace")
|
||||||
return true
|
return true
|
||||||
elseif fields.worldedit_gui_replace_submit then
|
elseif fields.worldedit_gui_replace_submit or fields.worldedit_gui_replace_submit_inverse then
|
||||||
gui_nodename_set[name] = fields.worldedit_gui_replace_search
|
gui_nodename1[name] = fields.worldedit_gui_replace_search
|
||||||
gui_nodename_replace[name] = fields.worldedit_gui_replace_replace
|
gui_nodename2[name] = fields.worldedit_gui_replace_replace
|
||||||
minetest.chatcommands["/replace"].func(name, string.format("%s %s", gui_nodename_set[name], gui_nodename_replace[name]))
|
if fields.worldedit_gui_replace_submit then
|
||||||
|
minetest.chatcommands["/replace"].func(name, string.format("%s %s", gui_nodename1[name], gui_nodename2[name]))
|
||||||
|
else
|
||||||
|
minetest.chatcommands["/replaceinverse"].func(name, string.format("%s %s", gui_nodename1[name], gui_nodename2[name]))
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
worldedit.register_gui_function("worldedit_gui_replaceinverse", {
|
worldedit.register_gui_function("worldedit_gui_sphere", {
|
||||||
name = "Replace Inverse",
|
name = "Sphere", privs = minetest.chatcommands["/sphere"].privs,
|
||||||
privs = minetest.chatcommands["/replaceinverse"].privs,
|
|
||||||
get_formspec = function(name)
|
get_formspec = function(name)
|
||||||
local search_value = gui_nodename_set[name] or "Cobblestone"
|
local value = gui_nodename1[name] or "Cobblestone"
|
||||||
local search_nodename = worldedit.normalize_nodename(search_value)
|
local radius = gui_radius[name] or "5"
|
||||||
search_value = search_nodename or search_value
|
local nodename = worldedit.normalize_nodename(value)
|
||||||
local replace_value, replace_nodename = gui_nodename_replace[name] or "Stone"
|
return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_sphere") ..
|
||||||
local replace_nodename = worldedit.normalize_nodename(replace_value)
|
string.format("field[0.5,1.5;4,0.8;worldedit_gui_sphere_node;Name;%s]", minetest.formspec_escape(value)) ..
|
||||||
replace_value = replace_nodename or replace_value
|
"button[4,1.18;1.5,0.8;worldedit_gui_sphere_search;Search]" ..
|
||||||
return "size[6,4]" ..
|
(nodename and string.format("item_image[5.5,1.1;1,1;%s]", nodename)
|
||||||
"button[0,0;2,0.5;worldedit_gui;Back]" ..
|
or "image[5.5,1.1;1,1;unknown_node.png]") ..
|
||||||
"label[2,0;WorldEdit GUI > Replace Inverse]" ..
|
string.format("field[0.5,2.5;4,0.8;worldedit_gui_sphere_radius;Radius;%s]", minetest.formspec_escape(radius)) ..
|
||||||
string.format("field[0.5,1.5;4,0.8;worldedit_gui_replaceinverse_search;Name;%s]", minetest.formspec_escape(search_value)) ..
|
"button_exit[0,3.5;3,0.8;worldedit_gui_sphere_submit_hollow;Hollow Sphere]" ..
|
||||||
"button[4,1.18;1.5,0.8;worldedit_gui_replaceinverse_search_search;Search]" ..
|
"button_exit[3.5,3.5;3,0.8;worldedit_gui_sphere_submit_solid;Solid Sphere]"
|
||||||
(search_nodename and string.format("item_image[5.5,1.18;1,1;%s]", search_nodename)
|
|
||||||
or "image[5.5,1.18;1,1;unknown_node.png]") ..
|
|
||||||
string.format("field[0.5,2.5;4,0.8;worldedit_gui_replaceinverse_replace;Name;%s]", minetest.formspec_escape(replace_value)) ..
|
|
||||||
"button[4,2.18;1.5,0.8;worldedit_gui_replaceinverse_replace_search;Search]" ..
|
|
||||||
(replace_nodename and string.format("item_image[5.5,2.18;1,1;%s]", replace_nodename)
|
|
||||||
or "image[5.5,2.18;1,1;unknown_node.png]") ..
|
|
||||||
"button_exit[0,3.5;4,0.8;worldedit_gui_replaceinverse_submit;Replace Inverse]"
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
worldedit.register_gui_handler("worldedit_gui_replaceinverse", function(name, fields)
|
worldedit.register_gui_handler("worldedit_gui_sphere", function(name, fields)
|
||||||
if fields.worldedit_gui_replaceinverse_search_search then
|
if fields.worldedit_gui_sphere_search then
|
||||||
gui_nodename_set[name] = fields.worldedit_gui_replaceinverse_search
|
gui_nodename1[name] = fields.worldedit_gui_sphere_node
|
||||||
worldedit.show_page(name, "worldedit_gui_replaceinverse")
|
worldedit.show_page(name, "worldedit_gui_sphere")
|
||||||
return true
|
return true
|
||||||
elseif fields.worldedit_gui_replaceinverse_replace_search then
|
elseif fields.worldedit_gui_sphere_submit_hollow or fields.worldedit_gui_sphere_submit_solid then
|
||||||
gui_nodename_replace[name] = fields.worldedit_gui_replaceinverse_replace
|
gui_nodename1[name] = fields.worldedit_gui_sphere_node
|
||||||
worldedit.show_page(name, "worldedit_gui_replaceinverse")
|
gui_radius[name] = fields.worldedit_gui_sphere_radius
|
||||||
|
print(minetest.serialize(fields))
|
||||||
|
if fields.worldedit_gui_sphere_submit_hollow then
|
||||||
|
minetest.chatcommands["/hollowsphere"].func(name, string.format("%s %s", gui_radius[name], gui_nodename1[name]))
|
||||||
|
else
|
||||||
|
minetest.chatcommands["/sphere"].func(name, string.format("%s %s", gui_radius[name], gui_nodename1[name]))
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
elseif fields.worldedit_gui_replaceinverse_submit then
|
end
|
||||||
gui_nodename_set[name] = fields.worldedit_gui_replaceinverse_search
|
return false
|
||||||
gui_nodename_replace[name] = fields.worldedit_gui_replaceinverse_replace
|
end)
|
||||||
minetest.chatcommands["/replaceinverse"].func(name, string.format("%s %s", gui_nodename_set[name], gui_nodename_replace[name]))
|
|
||||||
|
worldedit.register_gui_function("worldedit_gui_formspec_tester", {
|
||||||
|
name = "Formspec Tester",
|
||||||
|
get_formspec = function(name)
|
||||||
|
local value = gui_formspec[name] or ""
|
||||||
|
return "size[8,6.5]" .. worldedit.get_formspec_header("worldedit_gui_formspec_tester") ..
|
||||||
|
string.format("textarea[0.5,1;7.5,5.5;worldedit_gui_formspec_tester_value;Formspec Code;%s]", minetest.formspec_escape(value)) ..
|
||||||
|
"button_exit[0,6;3,0.8;worldedit_gui_formspec_tester_show;Show Formspec]"
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
worldedit.register_gui_handler("worldedit_gui_formspec_tester", function(name, fields)
|
||||||
|
if fields.worldedit_gui_formspec_tester_show then
|
||||||
|
gui_formspec[name] = fields.worldedit_gui_formspec_tester_value or ""
|
||||||
|
worldedit.show_page(name, "worldedit_gui_formspec_tester")
|
||||||
|
minetest.show_formspec(name, "worldedit:formspec_tester", gui_formspec[name])
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
--wip: make back buttons images in all screens
|
--wip: make back buttons images in all screens
|
||||||
--wip: support unified_inventory, it even seems to have some sort of API now
|
--wip: support unified_inventory, it even seems to have some sort of API now
|
||||||
|
--wip: make it look good with image buttons and stuff
|
||||||
|
|
||||||
worldedit = worldedit or {}
|
worldedit = worldedit or {}
|
||||||
|
|
||||||
|
@ -55,11 +56,17 @@ worldedit.register_gui_handler = function(identifier, handler)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
worldedit.get_formspec_header = function(identifier)
|
||||||
|
local entry = worldedit.pages[identifier] or {}
|
||||||
|
return "button[0,0;2,0.5;worldedit_gui;Back]" ..
|
||||||
|
string.format("label[2,0;WorldEdit GUI > %s]", entry.name or "")
|
||||||
|
end
|
||||||
|
|
||||||
local get_formspec = function(name, identifier)
|
local get_formspec = function(name, identifier)
|
||||||
if worldedit.pages[identifier] then
|
if worldedit.pages[identifier] then
|
||||||
return worldedit.pages[identifier].get_formspec(name)
|
return worldedit.pages[identifier].get_formspec(name)
|
||||||
end
|
end
|
||||||
return worldedit.pages["worldedit_gui"].get_formspec(name)
|
return worldedit.pages["worldedit_gui"].get_formspec(name) --default to showing main page if an unknown page is given
|
||||||
end
|
end
|
||||||
|
|
||||||
worldedit.show_page = function(name, page)
|
worldedit.show_page = function(name, page)
|
||||||
|
@ -70,25 +77,13 @@ end
|
||||||
--add button to inventory_plus if it is installed
|
--add button to inventory_plus if it is installed
|
||||||
if inventory_plus then
|
if inventory_plus then
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
--ensure player has permission to perform action
|
inventory_plus.register_button(player, "worldedit_gui", "WorldEdit")
|
||||||
if minetest.check_player_privs(player:get_player_name(), {worldedit=true}) then
|
|
||||||
inventory_plus.register_button(player, "worldedit_gui", "WorldEdit")
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--show the form when the button is pressed
|
--show the form when the button is pressed
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
local name = player:get_player_name()
|
|
||||||
|
|
||||||
--ensure player has permission to perform action
|
|
||||||
if not minetest.check_player_privs(name, {worldedit=true}) then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
--check for showing of main GUI
|
|
||||||
local next_page = nil
|
|
||||||
if fields.worldedit_gui then --main page
|
if fields.worldedit_gui then --main page
|
||||||
worldedit.show_page(name, "worldedit_gui")
|
worldedit.show_page(player:get_player_name(), "worldedit_gui")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
@ -119,7 +114,7 @@ worldedit.register_gui_function("worldedit_gui", {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return string.format("size[%g,%g]", columns * width, y + 0.5) ..
|
return string.format("size[%g,%g]", math.max(columns * width, 5), math.max(y + 0.5, 3)) ..
|
||||||
(inventory_plus and "button[0,0;2,0.5;main;Back]" or "button_exit[0,0;2,0.5;main;Exit]") ..
|
(inventory_plus and "button[0,0;2,0.5;main;Back]" or "button_exit[0,0;2,0.5;main;Exit]") ..
|
||||||
"label[2,0;WorldEdit GUI]" ..
|
"label[2,0;WorldEdit GUI]" ..
|
||||||
table.concat(buttons)
|
table.concat(buttons)
|
||||||
|
@ -131,7 +126,9 @@ worldedit.register_gui_handler("worldedit_gui", function(name, fields)
|
||||||
for identifier, entry in pairs(worldedit.pages) do
|
for identifier, entry in pairs(worldedit.pages) do
|
||||||
if fields[identifier] then
|
if fields[identifier] then
|
||||||
--ensure player has permission to perform action
|
--ensure player has permission to perform action
|
||||||
if not minetest.check_player_privs(name, entry.privs or {}) then
|
local has_privs, missing_privs = minetest.check_player_privs(name, entry.privs or {})
|
||||||
|
if not has_privs then
|
||||||
|
worldedit.player_notify(name, "you are not allowed to use this function (missing privileges: " .. table.concat(missing_privs, ", ") .. ")")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if entry.on_select then
|
if entry.on_select then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user