[Mod] Formspec Framework [formspec]

User avatar
BrandonReese
Member
 
Posts: 839
Joined: Wed Sep 12, 2012 00:44
Location: USA
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
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
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
(22.55 KiB) Not downloaded yet
 

User avatar
rubenwardy
Moderator
 
Posts: 5545
Joined: Tue Jun 12, 2012 18:11
Location: United Kingdom
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:

Code: Select all
button1:click(function(name, fields)                    end)


makes code nicer
 

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

User avatar
BrandonReese
Member
 
Posts: 839
Joined: Wed Sep 12, 2012 00:44
Location: USA
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.

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: BuckarooBanzay and 5 guests