1
0
mirror of https://github.com/Uberi/Minetest-WorldEdit.git synced 2024-12-26 02:30:40 +01:00

worldedit_gui: Improve behaviour of some input fields

Can't be bothered to do the rest. This stuff should be
rewritten in a modular fashion anyway.
This commit is contained in:
sfan5 2019-09-18 18:52:27 +02:00
parent adab528f8a
commit 45acf09e4a

View File

@ -173,6 +173,7 @@ worldedit.register_gui_function("worldedit_gui_set", {
local nodename = worldedit.normalize_nodename(node) local nodename = worldedit.normalize_nodename(node)
return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_set") .. return "size[6.5,3]" .. worldedit.get_formspec_header("worldedit_gui_set") ..
string.format("field[0.5,1.5;4,0.8;worldedit_gui_set_node;Name;%s]", minetest.formspec_escape(node)) .. string.format("field[0.5,1.5;4,0.8;worldedit_gui_set_node;Name;%s]", minetest.formspec_escape(node)) ..
"field_close_on_enter[worldedit_gui_set_node;false]" ..
"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]" ..
formspec_node("5.5,1.1", nodename) .. formspec_node("5.5,1.1", nodename) ..
"button_exit[0,2.5;3,0.8;worldedit_gui_set_submit;Set Nodes]" "button_exit[0,2.5;3,0.8;worldedit_gui_set_submit;Set Nodes]"
@ -180,18 +181,20 @@ worldedit.register_gui_function("worldedit_gui_set", {
}) })
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 or fields.worldedit_gui_set_submit then local ret = false
if fields.worldedit_gui_set_search or fields.key_enter_field == "worldedit_gui_set_node" then
gui_nodename1[name] = tostring(fields.worldedit_gui_set_node) gui_nodename1[name] = tostring(fields.worldedit_gui_set_node)
worldedit.show_page(name, "worldedit_gui_set") worldedit.show_page(name, "worldedit_gui_set")
ret = true -- fallthrough
end
if fields.worldedit_gui_set_submit then if fields.worldedit_gui_set_submit then
local n = worldedit.normalize_nodename(gui_nodename1[name]) local n = worldedit.normalize_nodename(gui_nodename1[name])
if n then if n then
minetest.chatcommands["/set"].func(name, n) minetest.chatcommands["/set"].func(name, n)
end end
end
return true return true
end end
return false return ret
end) end)
worldedit.register_gui_function("worldedit_gui_replace", { worldedit.register_gui_function("worldedit_gui_replace", {
@ -202,9 +205,11 @@ worldedit.register_gui_function("worldedit_gui_replace", {
local search_nodename, replace_nodename = worldedit.normalize_nodename(search), worldedit.normalize_nodename(replace) local search_nodename, replace_nodename = worldedit.normalize_nodename(search), worldedit.normalize_nodename(replace)
return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_replace") .. return "size[6.5,4]" .. worldedit.get_formspec_header("worldedit_gui_replace") ..
string.format("field[0.5,1.5;4,0.8;worldedit_gui_replace_search;Name;%s]", minetest.formspec_escape(search)) .. string.format("field[0.5,1.5;4,0.8;worldedit_gui_replace_search;Name;%s]", minetest.formspec_escape(search)) ..
"field_close_on_enter[worldedit_gui_replace_search;false]" ..
"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]" ..
formspec_node("5.5,1.1", search_nodename) .. formspec_node("5.5,1.1", search_nodename) ..
string.format("field[0.5,2.5;4,0.8;worldedit_gui_replace_replace;Name;%s]", minetest.formspec_escape(replace)) .. string.format("field[0.5,2.5;4,0.8;worldedit_gui_replace_replace;Name;%s]", minetest.formspec_escape(replace)) ..
"field_close_on_enter[worldedit_gui_replace_replace;false]" ..
"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]" ..
formspec_node("5.5,2.1", replace_nodename) .. formspec_node("5.5,2.1", replace_nodename) ..
"button_exit[0,3.5;3,0.8;worldedit_gui_replace_submit;Replace Nodes]" .. "button_exit[0,3.5;3,0.8;worldedit_gui_replace_submit;Replace Nodes]" ..
@ -213,28 +218,28 @@ worldedit.register_gui_function("worldedit_gui_replace", {
}) })
worldedit.register_gui_handler("worldedit_gui_replace", function(name, fields) worldedit.register_gui_handler("worldedit_gui_replace", function(name, fields)
local ret = false
if fields.worldedit_gui_replace_search_search or fields.worldedit_gui_replace_replace_search if fields.worldedit_gui_replace_search_search or fields.worldedit_gui_replace_replace_search
or fields.worldedit_gui_replace_submit or fields.worldedit_gui_replace_submit_inverse then or table.indexof({"worldedit_gui_replace_search", "worldedit_gui_replace_replace"}, fields.key_enter_field) ~= -1 then
gui_nodename1[name] = tostring(fields.worldedit_gui_replace_search) gui_nodename1[name] = tostring(fields.worldedit_gui_replace_search)
gui_nodename2[name] = tostring(fields.worldedit_gui_replace_replace) gui_nodename2[name] = tostring(fields.worldedit_gui_replace_replace)
worldedit.show_page(name, "worldedit_gui_replace") worldedit.show_page(name, "worldedit_gui_replace")
local submit = nil ret = true -- fallthrough
if fields.worldedit_gui_replace_submit then end
submit = "replace" if fields.worldedit_gui_replace_submit or fields.worldedit_gui_replace_submit_inverse then
elseif fields.worldedit_gui_replace_submit_inverse then local submit = "replace"
if fields.worldedit_gui_replace_submit_inverse then
submit = "replaceinverse" submit = "replaceinverse"
end end
if submit then
local n1 = worldedit.normalize_nodename(gui_nodename1[name]) local n1 = worldedit.normalize_nodename(gui_nodename1[name])
local n2 = worldedit.normalize_nodename(gui_nodename2[name]) local n2 = worldedit.normalize_nodename(gui_nodename2[name])
if n1 and n2 then if n1 and n2 then
minetest.chatcommands["/"..submit].func(name, string.format("%s %s", n1, n2)) minetest.chatcommands["/"..submit].func(name, string.format("%s %s", n1, n2))
end end
end
return true return true
end end
return false return ret
end) end)
worldedit.register_gui_function("worldedit_gui_sphere_dome", { worldedit.register_gui_function("worldedit_gui_sphere_dome", {