Skip to content

Commit 5bbb6b3

Browse files
committedSep 12, 2017
Support //cube in the GUI
1 parent d6a9b51 commit 5bbb6b3

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
 

‎worldedit_gui/functionality.lua

+46
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,52 @@ worldedit.register_gui_handler("worldedit_gui_save_load", function(name, fields)
735735
return false
736736
end)
737737

738+
worldedit.register_gui_function("worldedit_gui_cube", {
739+
name = "Cuboid", -- technically the command is misnamed, I know...
740+
privs = combine_we_privs({"hollowcube", "cube"}),
741+
get_formspec = function(name)
742+
local width, height, length = gui_distance1[name], gui_distance2[name], gui_distance3[name]
743+
local node = gui_nodename1[name]
744+
local nodename = worldedit.normalize_nodename(node)
745+
return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_cube") ..
746+
string.format("field[0.5,1.5;4,0.8;worldedit_gui_cube_node;Name;%s]", minetest.formspec_escape(node)) ..
747+
"button[4,1.18;1.5,0.8;worldedit_gui_cube_search;Search]" ..
748+
formspec_node("5.5,1.1", nodename) ..
749+
string.format("field[0.5,2.5;1,0.8;worldedit_gui_cube_width;Width;%s]", minetest.formspec_escape(width)) ..
750+
string.format("field[1.5,2.5;1,0.8;worldedit_gui_cube_height;Height;%s]", minetest.formspec_escape(height)) ..
751+
string.format("field[2.5,2.5;1,0.8;worldedit_gui_cube_length;Length;%s]", minetest.formspec_escape(length)) ..
752+
"button_exit[0,3.5;3,0.8;worldedit_gui_cube_submit_hollow;Hollow Cuboid]" ..
753+
"button_exit[3.5,3.5;3,0.8;worldedit_gui_cube_submit_solid;Solid Cuboid]"
754+
end,
755+
})
756+
757+
worldedit.register_gui_handler("worldedit_gui_cube", function(name, fields)
758+
if fields.worldedit_gui_cube_search
759+
or fields.worldedit_gui_cube_submit_hollow or fields.worldedit_gui_cube_submit_solid then
760+
gui_nodename1[name] = tostring(fields.worldedit_gui_cube_node)
761+
gui_distance1[name] = tostring(fields.worldedit_gui_cube_width)
762+
gui_distance2[name] = tostring(fields.worldedit_gui_cube_height)
763+
gui_distance3[name] = tostring(fields.worldedit_gui_cube_length)
764+
worldedit.show_page(name, "worldedit_gui_cube")
765+
766+
local submit = nil
767+
if fields.worldedit_gui_cube_submit_hollow then
768+
submit = "hollowcube"
769+
elseif fields.worldedit_gui_cube_submit_solid then
770+
submit = "cube"
771+
end
772+
if submit then
773+
local n = worldedit.normalize_nodename(gui_nodename1[name])
774+
if n then
775+
local args = string.format("%s %s %s %s", gui_distance1[name], gui_distance2[name], gui_distance3[name], n)
776+
minetest.chatcommands["/"..submit].func(name, args)
777+
end
778+
end
779+
return true
780+
end
781+
return false
782+
end)
783+
738784
worldedit.register_gui_function("worldedit_gui_clearobjects", {
739785
name = "Clear Objects",
740786
privs = we_privs("clearobjects"),

0 commit comments

Comments
 (0)
Please sign in to comment.