Page 1 of 1

[wip][mod] FormSpec mini API [formspeccer]

PostPosted: Mon Oct 17, 2016 01:15
by taikedz
A little API that is intended to help in the creation of form specs.


The form spec sublanguage is a little fiddly, so this API is intended to make it resemble other APIs by making it table-based.

Example:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local formname = "mymod:myform"

formspeccer:newform(formname,"10,7") -- a new form , 10x7

formspeccer:add_field(formname,{
    name="field1",
    label="Your name",
    value="Sam", -- optional pre-populated value for the form
})

formspeccer:add_button(
    {
        name="send",
        label="Send!",
        xy="2,3",
        wh="1,1",
    },
    true -- optional , makes it an exit button
)

-- just show the form to a player
formspeccer:show(player,"mymod:myform")

Re: [wip][mod] FormSpec mini API [formspeccer]

PostPosted: Mon Oct 17, 2016 10:58
by azekill_DIABLO
awesome!

Re: [wip][mod] FormSpec mini API [formspeccer]

PostPosted: Mon Oct 17, 2016 22:01
by bell07
Bookmarked.

Great work!

I play with thought to start a new mod for for formspec widgets library. And your API will be really welcome for the widgets. So maybe we working together in the feature.
The planned widgets are some "full-featured" easy to use formspec generators like "Open file dialog" and some framework modules like "tabbed screen". Yu can find a small "as-needed-by-project-prototype" in https://github.com/bell07/minetest-town ... idgets.lua

Re: [wip][mod] FormSpec mini API [formspeccer]

PostPosted: Tue Oct 18, 2016 09:08
by Naj
I worked a bit on a formspec API.

It's using object but I find it too heavy. I love the table style. Much better.

I'll publish code soon. I worked on auto placing / sizing and on event handling.

It could be good to have a good and common formspec framework.

Re: [wip][mod] FormSpec mini API [formspeccer]

PostPosted: Tue Oct 18, 2016 10:23
by taikedz
Nice one Naj, would love to see the code you have so far

bell07 interesting - are you wanting to make some sort of pre-made generalized forms?

Re: [wip][mod] FormSpec mini API [formspeccer]

PostPosted: Tue Oct 18, 2016 20:03
by bell07
My idea is a framework that handle all formspec related methods like, on_receive_fields, *metadata_inventory*, set_string "formspec" and maybe other in one. So the next pseudo-code should be possible (if lua syntax correct oO).

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local nodedef = {....definition ...}
specwidget.add_interface(nodedef)
register_node("mynode", nodedef)

local form = nodedef.specwidget:newform("selection", "10x10")
form:add_selector("Please select file", {"file1","file2","file3"}, "10x8")
form:add_button("open", { label="open", on_press = function print(file) end }
form:add_button("cancel", { label = "cancel", on_press = function parent.specwidget:set_active(form2) end }

local form2 = nodedef.specwidget:newform("selection", "8x8")
..
..
..

local node = minetest.get_node({1,2,3})
node.specwidget:set_active(form)


Do you have any sample how to use your API? Currently I miss the way to handle the on_receive_fields

Re: [wip][mod] FormSpec mini API [formspeccer]

PostPosted: Fri Oct 21, 2016 13:44
by taikedz
API added to current implementation.

I am thinking I might want to re-write it for better flexibility.... I will try not to break any documented API at this point..... but no promises!

bell07 - some comments might help...

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
form:add_button("open", { label="open", on_press = function print(file) end }
form:add_button("cancel", { label = "cancel", on_press = function parent.specwidget:set_active(form2) end }


They way I read this, I understand that you want to be able to supply a function through on_press that will be called in the receive_fields callback, conditional on the button being the one that was pressed... So essentially you are also generating a switching function based on all the buttons with on_press on it....

I think that would work...... certainly looks promising and a rather much cleaner way, for the modder's perspecitve, of tying funcitonality to the node... but..... I expect there would also need to be a way of adding a final custom handler... for when player uses the Enter key.... I'm pretty sure there's something buging me about this approach for a reason.... can't seem to put my finger on it...

Re: [wip][mod] FormSpec mini API [formspeccer]

PostPosted: Fri Oct 21, 2016 13:48
by rubenwardy
smartfs has bindings for events such as button presses.

However, it uses parameters rather than a table to make elements, so that doesn't look as nice.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local btn = state:button(1, 1, 2, 2, "name", "label")
btn:click(function()
    minetest.chat_send_player(name, "You clicked a button!")
end)

Re: [wip][mod] FormSpec mini API [formspeccer]

PostPosted: Fri Oct 21, 2016 13:59
by taikedz
rubenwardy -- hmm. Didn't see smartfs

I did try to check first if someone else had done this already. I didn't really set out to duplicate efforts.... :-/

There are quite a few new elements to formspecs since you last updated the code it seems.... are you still intending to maintain smartfs?

Re: [wip][mod] FormSpec mini API [formspeccer]

PostPosted: Fri Oct 21, 2016 16:01
by rubenwardy
I would like to, but I'm lacking time to do so - what with being a core developer and also a uni student

Re: [wip][mod] FormSpec mini API [formspeccer]

PostPosted: Fri Oct 21, 2016 16:06
by taikedz
OK - well what I'll probably do is an implementation of a couple of simple mods I have here against smartfs, and see which direction I want to continue effort on...

If I do have suggestions should I send to minetest-mods fork or your fork?

Re: [wip][mod] FormSpec mini API [formspeccer]

PostPosted: Fri Oct 21, 2016 19:38
by bell07
Thank you @rubenwardy for mention smartfs. I fail to see it too. For now I play with them for better understanding. The first challenge for me is the smartfs and formspeccer are both for "player inventory" that will be opened trough show(player..) method. But my first mods uses nodemeta inventory. So I have to do this integration by myself.
By the way, I found this info: http://dev.minetest.net/Lua_Table_Formspec. Any presumption when it will be implemented?

Re: [wip][mod] FormSpec mini API [formspeccer]

PostPosted: Fri Oct 21, 2016 22:43
by rubenwardy
The minetest-mods is the main one