Let's look at this formspec:
Let's take a look at the code:
- Code: Select all
local formspec = ""
for x = 0, 11 do
for y = 0, 11 do
formspec = formspec .."image_button[".. x ..",".. x ..";1,1;logo.png;name;Button]"
end
end
formspec = formspec.. "image_button[1,1;10,10;logo.png;name;Button]"
minetest.register_globalstep(function(dtime)
local player = minetest.get_player_by_name("singleplayer")
if player then
local controls = player:get_player_control()
if controls.jump then
minetest.show_formspec("singleplayer", "formspec:test", "real_coordinates[]size[12,12]"..
formspec..
"")
end
player:set_look_vertical(math.rad(0))
end
end)
minetest.register_on_joinplayer(function(player)
player:set_physics_override({gravity = 0})
end)
minetest.register_on_player_receive_fields(function(player, formname, fields)
if not player or not formname then
return
end
if fields.name then
minetest.chat_send_all("Yay!")
else
minetest.chat_send_all("Aw.")
end
end)
Notice anything interesting?
This is currently WIP, but it adds an extra tag
real_coordinates[] which unifies all elements to a common coordinate system. I've only implemented the base form window and image buttons, but since I've gotten these to work, the rest will be easy to complete.
The code can be found at
https://github.com/v-rob/minetest.
A minimal game for demonstrating the formspecs (which is the code above, and will be updated constantly) can be found at
https://github.com/v-rob/minetest_formspec_game. Press space to open the formspec.
Besides coordinating, I'm also planning on making dropdowns optionally return the selected number as opposed to text as something orwell said at
viewtopic.php?f=7&t=20186#p343413. I won't be adding state handling like said there because an API could do that without having to muck around in the engine.
Suggestions are always welcome. Once I finish this, I'll make a PR.