Re-added inventory widget
This commit is contained in:
parent
d008b947ff
commit
12ec479cf0
@ -50,8 +50,7 @@ local inspector_form = {
|
|||||||
id = 'test_form',
|
id = 'test_form',
|
||||||
spacing = 0.1,
|
spacing = 0.1,
|
||||||
margin = 0.7,
|
margin = 0.7,
|
||||||
{ type = 'label', label = 'TITRE', width = 3 },
|
{ type = 'tab', label = 'node', orientation = 'vertical',
|
||||||
{ type = 'tab', label = 'node', orientation = 'vetical',
|
|
||||||
data = function(form)
|
data = function(form)
|
||||||
local pos = form:get_context().pos
|
local pos = form:get_context().pos
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
@ -67,7 +66,7 @@ local inspector_form = {
|
|||||||
{ type = 'label', height = 1, width = 6, init = function(item) item:get_context().label = item.parent:get_context().data.param1 end },
|
{ type = 'label', height = 1, width = 6, init = function(item) item:get_context().label = item.parent:get_context().data.param1 end },
|
||||||
{ type = 'label', height = 1, width = 6, init = function(item) item:get_context().label = item.parent:get_context().data.param2 end },
|
{ type = 'label', height = 1, width = 6, init = function(item) item:get_context().label = item.parent:get_context().data.param2 end },
|
||||||
},
|
},
|
||||||
{ type = 'tab', label = 'meta', orientation = 'vetical',
|
{ type = 'tab', label = 'meta', orientation = 'vertical',
|
||||||
{ type = 'label', height = 1, width = 6, label = "Metadata:" },
|
{ type = 'label', height = 1, width = 6, label = "Metadata:" },
|
||||||
{ type = 'vbox',
|
{ type = 'vbox',
|
||||||
max_items = 3,
|
max_items = 3,
|
||||||
@ -86,12 +85,12 @@ local inspector_form = {
|
|||||||
end
|
end
|
||||||
return data
|
return data
|
||||||
end,
|
end,
|
||||||
{ type = 'label', width = 2, height = nofs.fs_field_height,
|
{ type = 'label', width = 2,
|
||||||
init = function(item)
|
init = function(item)
|
||||||
item:get_context().label = item.parent:get_context().data.key
|
item:get_context().label = item.parent:get_context().data.key
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{ type = 'field', width = 4, height = nofs.fs_field_height,
|
{ type = 'field', width = 4,
|
||||||
init = function(item)
|
init = function(item)
|
||||||
item:get_context().value = item.parent:get_context().data.value
|
item:get_context().value = item.parent:get_context().data.value
|
||||||
end,
|
end,
|
||||||
@ -100,7 +99,7 @@ local inspector_form = {
|
|||||||
meta:set_string(item.parent:get_context().data.key, item:get_context().value)
|
meta:set_string(item.parent:get_context().data.key, item:get_context().value)
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
{ type = 'button', width = 1, height = nofs.fs_field_height, label="...",
|
{ type = 'button', width = 1, label="...",
|
||||||
on_clicked = function(item)
|
on_clicked = function(item)
|
||||||
local data = item.parent:get_context().data
|
local data = item.parent:get_context().data
|
||||||
nofs.show_form(item.form.player_name,
|
nofs.show_form(item.form.player_name,
|
||||||
@ -124,12 +123,42 @@ local inspector_form = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{ type = 'tab', label = 'inventory', orientation = 'vertical',
|
||||||
|
max_items = 1, id = 'inventory',
|
||||||
|
{ type = 'vbox',
|
||||||
|
data = function(form)
|
||||||
|
local data = {}
|
||||||
|
local pos = form:get_context().pos
|
||||||
|
if pos then
|
||||||
|
local inv = minetest.get_meta(pos):get_inventory()
|
||||||
|
for key, _ in pairs(inv:get_lists()) do
|
||||||
|
data[#data+1] = { list = key }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return data
|
||||||
|
end,
|
||||||
|
{ type = 'hbox',
|
||||||
|
{ type = 'label', width = 4,
|
||||||
|
init = function(item) item:get_context().label = 'Inventory: '..
|
||||||
|
item.parent.parent:get_context().data.list end },
|
||||||
|
{ type = 'pager', connected_to = 'inventory' },
|
||||||
|
},
|
||||||
|
{ type = 'inventory', height = 5, width = 8,
|
||||||
|
init = function(item)
|
||||||
|
local pos = item.form:get_context().pos
|
||||||
|
local context = item:get_context()
|
||||||
|
context.location = string.format('nodemeta:%g,%g,%g',
|
||||||
|
pos.x, pos.y, pos.z)
|
||||||
|
context.list = item.parent:get_context().data.list
|
||||||
|
end
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
{ type = 'hbox',
|
{ type = 'hbox',
|
||||||
{ type = 'button', width = 2, label= 'Cancel', exit = true, },
|
{ type = 'button', width = 2, label= 'Cancel', exit = true, },
|
||||||
{ type = 'button', width = 2, label = 'Save', exit = true,
|
{ type = 'button', width = 2, label = 'Save', exit = true,
|
||||||
on_clicked = nofs.event.save },
|
on_clicked = nofs.event.save },
|
||||||
},
|
},
|
||||||
{ type = 'pager' },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
minetest.register_tool("nofs_demo:node_inspector", {
|
minetest.register_tool("nofs_demo:node_inspector", {
|
||||||
|
Binary file not shown.
@ -45,6 +45,7 @@ local fsgeometry = {
|
|||||||
(geometry.w - imgsize.x - padding.x*2 ) / spacing.x + 1,
|
(geometry.w - imgsize.x - padding.x*2 ) / spacing.x + 1,
|
||||||
(geometry.h - imgsize.y - padding.y*2 - btn_height*2/3) / spacing.y + 1)
|
(geometry.h - imgsize.y - padding.y*2 - btn_height*2/3) / spacing.y + 1)
|
||||||
end,
|
end,
|
||||||
|
-- list : see specific bellow
|
||||||
image = function(geometry)
|
image = function(geometry)
|
||||||
return string.format("%g,%g;%g,%g",
|
return string.format("%g,%g;%g,%g",
|
||||||
geometry.x - padding.x/spacing.x,
|
geometry.x - padding.x/spacing.x,
|
||||||
@ -52,6 +53,18 @@ local fsgeometry = {
|
|||||||
geometry.w * spacing.x / imgsize.x,
|
geometry.w * spacing.x / imgsize.x,
|
||||||
geometry.h * spacing.y / imgsize.y)
|
geometry.h * spacing.y / imgsize.y)
|
||||||
end,
|
end,
|
||||||
|
pwdfield = function(geometry) -- Same as field
|
||||||
|
return string.format("%g,%g;%g,0",
|
||||||
|
geometry.x,
|
||||||
|
geometry.y + btn_height*spacing.y,
|
||||||
|
geometry.w + 1 - imgsize.x/spacing.x)
|
||||||
|
end,
|
||||||
|
field = function(geometry)
|
||||||
|
return string.format("%g,%g;%g,0",
|
||||||
|
geometry.x,
|
||||||
|
geometry.y + btn_height*spacing.y,
|
||||||
|
geometry.w + 1 - imgsize.x/spacing.x)
|
||||||
|
end,
|
||||||
textarea = function(geometry)
|
textarea = function(geometry)
|
||||||
return string.format("%g,%g;%g,%g",
|
return string.format("%g,%g;%g,%g",
|
||||||
geometry.x, -- It seems that for text_area, padding has been forgotten
|
geometry.x, -- It seems that for text_area, padding has been forgotten
|
||||||
@ -59,6 +72,12 @@ local fsgeometry = {
|
|||||||
geometry.w - imgsize.x + 1,
|
geometry.w - imgsize.x + 1,
|
||||||
(geometry.h + spacing.y) / imgsize.y - 1)
|
(geometry.h + spacing.y) / imgsize.y - 1)
|
||||||
end,
|
end,
|
||||||
|
button = function(geometry) -- Same as field
|
||||||
|
return string.format("%g,%g;%g,0",
|
||||||
|
geometry.x,
|
||||||
|
geometry.y + btn_height*spacing.y,
|
||||||
|
geometry.w + 1 - imgsize.x/spacing.x)
|
||||||
|
end,
|
||||||
image_button = function(geometry)
|
image_button = function(geometry)
|
||||||
return string.format("%g,%g;%g,%g",
|
return string.format("%g,%g;%g,%g",
|
||||||
geometry.x - padding.x/spacing.x,
|
geometry.x - padding.x/spacing.x,
|
||||||
@ -94,33 +113,14 @@ local fsgeometry = {
|
|||||||
geometry.w,
|
geometry.w,
|
||||||
geometry.h)
|
geometry.h)
|
||||||
end,
|
end,
|
||||||
field = function(geometry)
|
|
||||||
return string.format("%g,%g;%g,0",
|
|
||||||
geometry.x,
|
|
||||||
geometry.y + btn_height*spacing.y,
|
|
||||||
geometry.w + 1 - imgsize.x/spacing.x)
|
|
||||||
end,
|
|
||||||
pwdfield = function(geometry) -- Same as field
|
|
||||||
return string.format("%g,%g;%g,0",
|
|
||||||
geometry.x,
|
|
||||||
geometry.y + btn_height*spacing.y,
|
|
||||||
geometry.w + 1 - imgsize.x/spacing.x)
|
|
||||||
end,
|
|
||||||
button = function(geometry) -- Same as field
|
|
||||||
return string.format("%g,%g;%g,0",
|
|
||||||
geometry.x,
|
|
||||||
geometry.y + btn_height*spacing.y,
|
|
||||||
geometry.w + 1 - imgsize.x/spacing.x)
|
|
||||||
end,
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local fsspecific = {
|
local fsspecific = {
|
||||||
inventory = function(geometry, location, list_name, starting_index)
|
list = function(geometry, location, list_name, starting_index)
|
||||||
return string.format("list[%s;%s;%g,%g;%g,%g;%s]",
|
return string.format("list[%s;%s;%g,%g;%g,%g;%s]",
|
||||||
location, list_name,
|
location, list_name,
|
||||||
X, Y, W, H,
|
geometry.x, geometry.y, geometry.w, geometry.h,
|
||||||
starting_index)
|
starting_index or 1)
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ end
|
|||||||
|
|
||||||
function nofs.fs_element_string(type, geometry, ...)
|
function nofs.fs_element_string(type, geometry, ...)
|
||||||
if fsspecific[type] then
|
if fsspecific[type] then
|
||||||
return string.format("%s[%s]", type, fsspecific[type](geometry, ...))
|
return fsspecific[type](geometry, ...)
|
||||||
else
|
else
|
||||||
assert (fsgeometry[type], string.format('Unknown element type "%s".', type))
|
assert (fsgeometry[type], string.format('Unknown element type "%s".', type))
|
||||||
return string.format("%s[%s;%s]", type, fsgeometry[type](geometry),
|
return string.format("%s[%s;%s]", type, fsgeometry[type](geometry),
|
||||||
|
@ -301,16 +301,23 @@ nofs.register_widget("checkbox", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- WIP
|
|
||||||
--[[
|
-- Inventory
|
||||||
|
-- =========
|
||||||
|
-- Attributes:
|
||||||
|
-- - location (contextualizable) : current_player, node
|
||||||
|
-- - list (contextualizable) : name of the inventory list
|
||||||
|
-- - listring : belongs to the listring or not
|
||||||
|
-- Context:
|
||||||
|
-- - start_index
|
||||||
|
|
||||||
nofs.register_widget("inventory", {
|
nofs.register_widget("inventory", {
|
||||||
render = function(item, offset)
|
render = function(item, offset)
|
||||||
item:have_an_id()
|
return nofs.fs_element_string('list',
|
||||||
return string.format("list[%s;%s;%s;]%s",
|
nofs.add_offset(item.geometry, offset),
|
||||||
item.def.inventory or "current_player",
|
-- TODO : link node inventory to form's node
|
||||||
item.def.list or "main",
|
item:get_attribute('location') or "",
|
||||||
fspossize(item, offset),
|
item:get_attribute('list') or "",
|
||||||
item.def.listring and "listring[]" or "")
|
item:get_context().start_item or "")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
]]
|
|
||||||
|
@ -126,7 +126,7 @@ local function render_container(item, offset)
|
|||||||
|
|
||||||
item:get_context().max_index = #item
|
item:get_context().max_index = #item
|
||||||
|
|
||||||
if overflow --and item.def.overflow and item.def.overflow == 'scrollbar'
|
if overflow and item.def.overflow and item.def.overflow == 'scrollbar'
|
||||||
then
|
then
|
||||||
-- Box must have an ID to be addressed
|
-- Box must have an ID to be addressed
|
||||||
item:have_an_id()
|
item:have_an_id()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user