Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minetest.close_formspec() to close formspecs from the server side #4737

Merged
merged 1 commit into from Nov 22, 2016

Conversation

orwell96
Copy link
Contributor

@orwell96 orwell96 commented Nov 5, 2016

new implementation of #4675
When an empty formspec string is supplied to show_formspec, and the formname matches the one of the formspec currently open on the client, it will close.
when supplying empty formspec and empty formname, it will close the client's formspec regardless of the open form's name.

For more info, see #4675
Has been documented in init.lua

Has been tested, test code:

minetest.register_node("test:disapp", {
	description = "Disappears",
	tiles = {"default_dirt.png"},
	groups = {crumbly = 3, soil = 1},
	on_construct=function(pos)
		minetest.get_meta(pos):set_string("formspec", "size[2,2]")
	end,
})
minetest.register_node("test:set", {
	description = "Sets form empty",
	tiles = {"default_dirt.png"},
	groups = {crumbly = 3, soil = 1},
	on_construct=function(pos)
		minetest.get_meta(pos):set_string("formspec", "size[2,2]")
	end,
})
minetest.register_node("test:form", {
	description = "show_formspec and close",
	tiles = {"default_dirt.png"},
	groups = {crumbly = 3, soil = 1},
	on_construct=function(pos)
		minetest.show_formspec("moflo", "test", "size[2,4]")
	end,
})
minetest.register_node("test:form2", {
	description = "show_formspec and close with different formname",
	tiles = {"default_dirt.png"},
	groups = {crumbly = 3, soil = 1},
	on_construct=function(pos)
		minetest.show_formspec("moflo", "test2", "size[2,4]")
	end,
})
minetest.register_node("test:form3", {
	description = "show_formspec and close wit formname empty",
	tiles = {"default_dirt.png"},
	groups = {crumbly = 3, soil = 1},
	on_construct=function(pos)
		minetest.show_formspec("moflo", "test2", "size[4,2]")
	end,
})
minetest.register_abm({
	nodenames = {"test:disapp"},
	interval = 10, -- Operation interval in seconds
	chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this
	action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="air"}) end,
})
minetest.register_abm({
	nodenames = {"test:form"},
	interval = 10, -- Operation interval in seconds
	chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this
	action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="air"}) minetest.close_formspec("moflo", "test") end,
})
minetest.register_abm({
	nodenames = {"test:form2"},
	interval = 10, -- Operation interval in seconds
	chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this
	action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="air"}) minetest.close_formspec("moflo", "testblablubb") end,
})
minetest.register_abm({
	nodenames = {"test:form3"},
	interval = 10, -- Operation interval in seconds
	chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this
	action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="air"}) minetest.close_formspec("moflo", "") end,
})
minetest.register_abm({
	nodenames = {"test:set"},
	interval = 10, -- Operation interval in seconds
	chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this
	action = function(pos, node, active_object_count, active_object_count_wider) minetest.get_meta(pos):set_string("formspec", "") end,
})

This will only happen if the formname matches or if formname is "".
@PureTryOut
Copy link

Next time put your code between "code tags":

code here 

That will show up as

code here

It will make it easier readable.

@orwell96
Copy link
Contributor Author

orwell96 commented Nov 8, 2016

Ah, 3 of them works...
Here you are!

@est31
Copy link
Contributor

est31 commented Nov 20, 2016

👍 looks good

@raymoo
Copy link
Contributor

raymoo commented Nov 20, 2016

Does this behave well with the death screen formspec?

@orwell96
Copy link
Contributor Author

the death screen formspec is not covered by this, only metadata and show_formspec

@Zeno-
Copy link
Contributor

Zeno- commented Nov 22, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants