[Mod] Formspec Framework [formspec]

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

[Mod] Formspec Framework [formspec]

by BrandonReese » Thu Jul 28, 2016 13:17

I am working on a mod that hopefully makes working with Formspecs more enjoyable. It gives you more of a programming interface to formspecs rather than just concatenating a bunch of strings. It does some basic auto vertical positioning of elements within the form as well as auto form sizing. Hopefully the auto positioning will get more advanced and I am going to make this work with all formspec elements. View the README on GitHub to see what it currently supports.

Example:
Image
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 form = FormSpec({name="dialog"})
   form.callback = function(self,player,fields)
      if fields.chat then
         minetest.chat_send_player(player:get_player_name(),fields.txt)
      end
   end
   
   local txt = Field({name="txt",label="Enter Text"})
   local button = Button({name="chat",label="Chat"})
   local button2 = Button({exit=true,name="exit",label="Close"})
   form:add(txt)
   form:add(button)
   form:add(button2)
   form:show(player)


Minecraft Style Inventory
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 form = FormSpec({name="minecraft_inventory"})
form:add(Image({left=1,top=0.6,width=1,height=2,texture="player.png"}))
form:add(PlayerInventory({left=0,top=3.5}))
form:add(CraftInventory({left=3,top=0}))
form:add(List({inv="current_player",list="craftpreview",left=7,top=1}))
form:show(player:get_player_name())

--[[OLD FORMSPEC WAY
size[8,7.5;]
image[1,0.6;1,2;player.png]
list[current_player;main;0,3.5;8,4;]
list[current_player;craft;3,0;3,3;]
list[current_player;craftpreview;7,1;1,1;]
]]


License: LGPL 2.1
Source: https://github.com/bremaweb/formspec
Attachments
simple-formspec.png
simple-formspec.png (22.55 KiB) Viewed 811 times
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: [Mod] Formspec Framework [formspec]

by rubenwardy » Thu Jul 28, 2016 18:33

Looks good - I was planning on having auto resizing layouts in smartfs, but never got around to it.

It might be cool to allow registering callbacks on objects, like:

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
button1:click(function(name, fields)                    end)


makes code nicer
 

User avatar
Naj
Member
 
Posts: 170
Joined: Sat Sep 19, 2015 21:14
GitHub: pyrollo
In-game: naj

Re: [Mod] Formspec Framework [formspec]

by Naj » Fri Jul 29, 2016 08:55

That's a very good idea to have such Framework. I start thinking of some stuff for item/group selection and display (for use in filters for example).
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: [Mod] Formspec Framework [formspec]

by azekill_DIABLO » Fri Jul 29, 2016 09:09

+1
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
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

User avatar
Naj
Member
 
Posts: 170
Joined: Sat Sep 19, 2015 21:14
GitHub: pyrollo
In-game: naj

Re: [Mod] Formspec Framework [formspec]

by Naj » Mon Aug 08, 2016 08:03

I'm working on a mod with several formspecs.

And I'm bored of having to write many ...on_receive_fields stuff and so on. So I may add many helpers in your Framework.

What are the plans for your Framework ? Are you working on it ? (I'd like to avoid double work :) )
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

Re: [Mod] Formspec Framework [formspec]

by BrandonReese » Mon Aug 08, 2016 13:38

I am still working on it. I don't have any solid plans or goals for it. If you want to fork it and add your helpers that is welcome. It's not documented on the readme but I added a Dialog helper to make a simple text dialog with one button. I plan on more of those types of helpers and special classes.

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
--Dialog returns a  FormSpec object
local d = Dialog('form_name','Text to display in the dialog','Button Label')
-- if you want to add a callback for the form that can go here
--d.callback = function(player,fields) ... end
d:show("player_name")
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 7 guests

cron