smartfs update

This commit is contained in:
Alexander Weber 2017-03-09 20:10:30 +01:00
parent f4c4925f26
commit 958e19edab

View File

@ -311,7 +311,7 @@ end
------------------------------------------------------ ------------------------------------------------------
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
local name = player:get_player_name() local name = player:get_player_name()
if smartfs.opened[name] and smartfs.opened[name].location.type == "player"then if smartfs.opened[name] and smartfs.opened[name].location.type == "player" then
if smartfs.opened[name].def.name == formname then if smartfs.opened[name].def.name == formname then
local state = smartfs.opened[name] local state = smartfs.opened[name]
state:_sfs_on_receive_fields_(name, fields) state:_sfs_on_receive_fields_(name, fields)
@ -377,7 +377,6 @@ end
------------------------------------------------------ ------------------------------------------------------
-- Smartfs Framework - create a form object (state) -- Smartfs Framework - create a form object (state)
------------------------------------------------------ ------------------------------------------------------
--function smartfs._makeState_(form, newplayer, params, is_inv, nodepos)
function smartfs._makeState_(form, params, location, newplayer) function smartfs._makeState_(form, params, location, newplayer)
------------------------------------------------------ ------------------------------------------------------
-- State - -- Object to manage players -- State - -- Object to manage players
@ -449,7 +448,7 @@ function smartfs._makeState_(form, params, location, newplayer)
res = "size["..self._size.w..","..self._size.h.."]" res = "size["..self._size.w..","..self._size.h.."]"
end end
for key,val in pairs(self._ele) do for key,val in pairs(self._ele) do
if val:getVisible() == true then if val:getVisible() then
res = res .. val:getBackgroundString() .. val:build() res = res .. val:getBackgroundString() .. val:build()
end end
end end
@ -457,7 +456,7 @@ function smartfs._makeState_(form, params, location, newplayer)
end, end,
show = location._show_, show = location._show_,
-- process /apply received field value -- process /apply received field value
_sfs_process_value_ = function(self, field, value) -- process each single received field _sfs_process_value_ = function(self, field, value)
local cur_namespace = self:getNamespace() local cur_namespace = self:getNamespace()
if cur_namespace == "" or cur_namespace == string.sub(field, 1, string.len(cur_namespace)) then -- Check current namespace if cur_namespace == "" or cur_namespace == string.sub(field, 1, string.len(cur_namespace)) then -- Check current namespace
local rel_fieldname = string.sub(field, string.len(cur_namespace)+1) --cut the namespace local rel_fieldname = string.sub(field, string.len(cur_namespace)+1) --cut the namespace
@ -491,14 +490,13 @@ function smartfs._makeState_(form, params, location, newplayer)
end end
end, end,
-- process onInput hook for the state -- process onInput hook for the state
_sfs_process_oninput_ = function(self, fields, player) --process hooks _sfs_process_oninput_ = function(self, fields, player)
-- call onInput hook if enabled
if self._onInput then if self._onInput then
self:_onInput(fields, player) self:_onInput(fields, player)
end end
-- recursive all onInput hooks on visible containers -- recursive all onInput hooks on visible containers
for elename, eledef in pairs(self._ele) do for elename, eledef in pairs(self._ele) do
if eledef.getContainerState and eledef:getVisible() == true then if eledef.getContainerState and eledef:getVisible() then
eledef:getContainerState():_sfs_process_oninput_(fields, player) eledef:getContainerState():_sfs_process_oninput_(fields, player)
end end
end end
@ -511,12 +509,11 @@ function smartfs._makeState_(form, params, location, newplayer)
end end
-- process onInput hooks -- process onInput hooks
self:_sfs_process_oninput_(fields, player) self:_sfs_process_oninput_(fields, player)
-- do actions -- do actions
for field, value in pairs(fields) do for field, value in pairs(fields) do
self:_sfs_process_action_(field, value, player) self:_sfs_process_action_(field, value, player)
end end
-- handle quit/exit
if not fields.quit and not self.closed and not self.obsolete then if not fields.quit and not self.closed and not self.obsolete then
self:show() self:show()
else else
@ -681,12 +678,20 @@ function smartfs._makeState_(form, params, location, newplayer)
closes = exitf or false closes = exitf or false
}) })
end, end,
label = function(self, x, y, name, text, vertical) label = function(self, x, y, name, text)
return self:element("label", { return self:element("label", {
pos = {x=x,y=y}, pos = {x=x,y=y},
name = name, name = name,
value = text, value = text,
vertical = vertical vertical = false
})
end,
vertlabel = function(self, x, y, name, text)
return self:element("label", {
pos = {x=x,y=y},
name = name,
value = text,
vertical = true
}) })
end, end,
toggle = function(self, x, y, w, h, name, list) toggle = function(self, x, y, w, h, name, list)
@ -792,7 +797,14 @@ function smartfs._makeState_(form, params, location, newplayer)
return self:element("container", { return self:element("container", {
pos = {x=x, y=y}, pos = {x=x, y=y},
name = name, name = name,
relative = relative relative = false
})
end,
view = function(self, x, y, name, relative)
return self:element("container", {
pos = {x=x, y=y},
name = name,
relative = true
}) })
end, end,
} }
@ -850,11 +862,6 @@ smartfs.element("button", {
if self._click then if self._click then
self:_click(self.root, player) self:_click(self.root, player)
end end
--[[ not needed. there is a quit field received in this case
if self.data.closes then
self.root.location.rootState:close()
end
]]--
end, end,
onClick = function(self,func) onClick = function(self,func)
self._click = func self._click = func
@ -890,6 +897,9 @@ smartfs.element("button", {
end, end,
setClose = function(self,bool) setClose = function(self,bool)
self.data.closes = bool self.data.closes = bool
end,
getClose = function(self)
return self.data.closes or false
end end
}) })
@ -1358,8 +1368,6 @@ smartfs.element("container", {
-- element interface methods -- element interface methods
build = function(self) build = function(self)
--the background string is "under" the container. Parts of this background can be overriden by elements (with background) from container
if self:getVisible() == true then
if self.data.relative ~= true then if self.data.relative ~= true then
return "container["..self.data.pos.x..","..self.data.pos.y.."]".. return "container["..self.data.pos.x..","..self.data.pos.y.."]"..
self:getContainerState():_buildFormspec_(false).. self:getContainerState():_buildFormspec_(false)..
@ -1367,9 +1375,6 @@ smartfs.element("container", {
else else
return self:getContainerState():_buildFormspec_(false) return self:getContainerState():_buildFormspec_(false)
end end
else
return ""
end
end, end,
getContainerState = function(self) getContainerState = function(self)
return self._state return self._state