Fix List object, add Minecraft Style Inventory example to Documentation
This commit is contained in:
parent
e6e886b047
commit
3512dcd923
18
README.md
18
README.md
@ -31,6 +31,24 @@ form:add(button2)
|
|||||||
form:show(player)
|
form:show(player)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Minecraft Style Inventory**
|
||||||
|
```lua
|
||||||
|
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;]
|
||||||
|
]]
|
||||||
|
```
|
||||||
|
|
||||||
###FormSpec
|
###FormSpec
|
||||||
####Parameters
|
####Parameters
|
||||||
- **name** (required): The name of the formspec used in register_on_player_received_fields. This must be set when the FormSpec is created.
|
- **name** (required): The name of the formspec used in register_on_player_received_fields. This must be set when the FormSpec is created.
|
||||||
|
34
init.lua
34
init.lua
@ -22,6 +22,7 @@ Element = class(function(a,d)
|
|||||||
a.player = d.player
|
a.player = d.player
|
||||||
a.exit = d.exit
|
a.exit = d.exit
|
||||||
a.inv = d.inv
|
a.inv = d.inv
|
||||||
|
a.list = d.list
|
||||||
a.vertical = d.vertical
|
a.vertical = d.vertical
|
||||||
a.selected = d.selected
|
a.selected = d.selected
|
||||||
a.dropdown = d.dropdown
|
a.dropdown = d.dropdown
|
||||||
@ -85,10 +86,13 @@ function FormSpec:add(element)
|
|||||||
if element.left == nil then
|
if element.left == nil then
|
||||||
element.left = 0.25
|
element.left = 0.25
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if ( element.top + element.height ) > self.elements_height then
|
||||||
|
self.elements_height = ( element.top + element.height )
|
||||||
|
end
|
||||||
|
|
||||||
self.elements_height = self.elements_height + element.height
|
if ( element.left + element.width ) > self.elements_width then
|
||||||
if element.width > self.elements_width then
|
self.elements_width = ( element.left + element.width )
|
||||||
self.elements_width = element.width
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--TODO ALIGNMENTS
|
--TODO ALIGNMENTS
|
||||||
@ -131,8 +135,8 @@ end)
|
|||||||
-- LIST
|
-- LIST
|
||||||
List = class(Element,function(c,def)
|
List = class(Element,function(c,def)
|
||||||
Element.init(c,def)
|
Element.init(c,def)
|
||||||
c.format = "list[{inv};{list};{left},{top};{width},{height};{starting_index}"
|
c.format = "list[{inv};{list};{left},{top};{width},{height};{starting_index}]"
|
||||||
c.starting_index = c.starting_index or 1
|
--c.starting_index = c.starting_index or 1
|
||||||
c.height = c.height or 1
|
c.height = c.height or 1
|
||||||
c.width = c.width or 1
|
c.width = c.width or 1
|
||||||
end)
|
end)
|
||||||
@ -255,20 +259,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end)
|
end)
|
||||||
--[[
|
--[[
|
||||||
function formspec_test(player)
|
function formspec_test(player)
|
||||||
local form = FormSpec({name="dialog"})
|
local form = FormSpec({name="minecraft_inventory"})
|
||||||
form.callback = function(self,player,fields)
|
form:add(Image({left=1,top=0.6,width=1,height=2,texture="player.png"}))
|
||||||
if fields.chat then
|
form:add(PlayerInventory({left=0,top=3.5}))
|
||||||
minetest.chat_send_player(player:get_player_name(),fields.txt)
|
form:add(CraftInventory({left=3,top=0}))
|
||||||
end
|
form:add(List({inv="current_player",list="craftpreview",left=7,top=1}))
|
||||||
end
|
form:show(player:get_player_name())
|
||||||
|
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user