Re-added inventory widget
This commit is contained in:
parent
d008b947ff
commit
12ec479cf0
@ -50,8 +50,7 @@ local inspector_form = {
|
||||
id = 'test_form',
|
||||
spacing = 0.1,
|
||||
margin = 0.7,
|
||||
{ type = 'label', label = 'TITRE', width = 3 },
|
||||
{ type = 'tab', label = 'node', orientation = 'vetical',
|
||||
{ type = 'tab', label = 'node', orientation = 'vertical',
|
||||
data = function(form)
|
||||
local pos = form:get_context().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.param2 end },
|
||||
},
|
||||
{ type = 'tab', label = 'meta', orientation = 'vetical',
|
||||
{ type = 'tab', label = 'meta', orientation = 'vertical',
|
||||
{ type = 'label', height = 1, width = 6, label = "Metadata:" },
|
||||
{ type = 'vbox',
|
||||
max_items = 3,
|
||||
@ -86,12 +85,12 @@ local inspector_form = {
|
||||
end
|
||||
return data
|
||||
end,
|
||||
{ type = 'label', width = 2, height = nofs.fs_field_height,
|
||||
{ type = 'label', width = 2,
|
||||
init = function(item)
|
||||
item:get_context().label = item.parent:get_context().data.key
|
||||
end,
|
||||
},
|
||||
{ type = 'field', width = 4, height = nofs.fs_field_height,
|
||||
{ type = 'field', width = 4,
|
||||
init = function(item)
|
||||
item:get_context().value = item.parent:get_context().data.value
|
||||
end,
|
||||
@ -100,7 +99,7 @@ local inspector_form = {
|
||||
meta:set_string(item.parent:get_context().data.key, item:get_context().value)
|
||||
end,
|
||||
},
|
||||
{ type = 'button', width = 1, height = nofs.fs_field_height, label="...",
|
||||
{ type = 'button', width = 1, label="...",
|
||||
on_clicked = function(item)
|
||||
local data = item.parent:get_context().data
|
||||
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 = 'button', width = 2, label= 'Cancel', exit = true, },
|
||||
{ type = 'button', width = 2, label = 'Save', exit = true,
|
||||
on_clicked = nofs.event.save },
|
||||
},
|
||||
{ type = 'pager' },
|
||||
}
|
||||
|
||||
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.h - imgsize.y - padding.y*2 - btn_height*2/3) / spacing.y + 1)
|
||||
end,
|
||||
-- list : see specific bellow
|
||||
image = function(geometry)
|
||||
return string.format("%g,%g;%g,%g",
|
||||
geometry.x - padding.x/spacing.x,
|
||||
@ -52,6 +53,18 @@ local fsgeometry = {
|
||||
geometry.w * spacing.x / imgsize.x,
|
||||
geometry.h * spacing.y / imgsize.y)
|
||||
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)
|
||||
return string.format("%g,%g;%g,%g",
|
||||
geometry.x, -- It seems that for text_area, padding has been forgotten
|
||||
@ -59,6 +72,12 @@ local fsgeometry = {
|
||||
geometry.w - imgsize.x + 1,
|
||||
(geometry.h + spacing.y) / imgsize.y - 1)
|
||||
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)
|
||||
return string.format("%g,%g;%g,%g",
|
||||
geometry.x - padding.x/spacing.x,
|
||||
@ -94,33 +113,14 @@ local fsgeometry = {
|
||||
geometry.w,
|
||||
geometry.h)
|
||||
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 = {
|
||||
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]",
|
||||
location, list_name,
|
||||
X, Y, W, H,
|
||||
starting_index)
|
||||
geometry.x, geometry.y, geometry.w, geometry.h,
|
||||
starting_index or 1)
|
||||
end,
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ end
|
||||
|
||||
function nofs.fs_element_string(type, geometry, ...)
|
||||
if fsspecific[type] then
|
||||
return string.format("%s[%s]", type, fsspecific[type](geometry, ...))
|
||||
return fsspecific[type](geometry, ...)
|
||||
else
|
||||
assert (fsgeometry[type], string.format('Unknown element type "%s".', type))
|
||||
return string.format("%s[%s;%s]", type, fsgeometry[type](geometry),
|
||||
|
@ -301,16 +301,23 @@ nofs.register_widget("checkbox", {
|
||||
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", {
|
||||
render = function(item, offset)
|
||||
item:have_an_id()
|
||||
return string.format("list[%s;%s;%s;]%s",
|
||||
item.def.inventory or "current_player",
|
||||
item.def.list or "main",
|
||||
fspossize(item, offset),
|
||||
item.def.listring and "listring[]" or "")
|
||||
return nofs.fs_element_string('list',
|
||||
nofs.add_offset(item.geometry, offset),
|
||||
-- TODO : link node inventory to form's node
|
||||
item:get_attribute('location') or "",
|
||||
item:get_attribute('list') or "",
|
||||
item:get_context().start_item or "")
|
||||
end,
|
||||
})
|
||||
]]
|
||||
|
@ -126,7 +126,7 @@ local function render_container(item, offset)
|
||||
|
||||
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
|
||||
-- Box must have an ID to be addressed
|
||||
item:have_an_id()
|
||||
|
Loading…
x
Reference in New Issue
Block a user