__ui.dependence = { } do
__ui.dependence.new = function( self )
local dependence = { }
dependence.__list = { }
dependence.__elements = { }
dependence.__state = false
dependence.push = function( self, ... )
local dependencies = { ... }
for i, dependence in ipairs( dependencies ) do
table.insert( self.__list, dependence )
table.insert( self.__elements, dependence[ 1 ] )
end
end
dependence.elements = function( self )
return self.__elements
end
dependence.update = function( self )
local state = true
for i, dependence in ipairs( self.__list ) do
local element = dependence[ 1 ]
local condition = dependence[ 2 ]
local inverse = dependence[ 3 ] or false
if element:type( ) == "selectable" or element:type( ) == "listable" then
if element:get( condition ) == inverse then
state = false
break
end
elseif ( element:get( ) == condition ) == inverse then
state = false
break
end
end
self.__state = state
end
dependence.state = function( self )
return self.__state
end
return setmetatable( dependence, {
__index = self
} )
end