class 'AlternativeHOZoomBase' (ZoomZoneBase)
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:__init(playfield, mode)
	mode = mode or ZOOM_TYPE_FULLSCREEN
	ZoomZoneBase.__init(self, 'AlternativeHOZoomBase', mode, playfield)

	self.interactiveBinds = {}
	self.pOpenButton = nil

	self:setCloseOnClickFade(false)
	self:getHOLogic().onTaskObjectFound:add( bind(self.onTaskObjectFound, self))
	--self:setupTest()
end
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:open(time)
	ZoomZoneBase.open(self, time)

	if self.pOpenButton then
		self.pOpenButton:setRespondable(false)
	end
end
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:close(time)
	ZoomZoneBase.close(self, time)

	if self.pOpenButton then
		self.pOpenButton:setRespondable(true)
	end
end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- SETTERS --------------------------------------------------------------------
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:setOpenButton(openButton)
	self.pOpenButton = openButton
end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- GETTERS --------------------------------------------------------------------
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:getHOLogic()
	return self.playfield:getHOLogic()
end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- CALLBACKS ------------------------------------------------------------------
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:onTaskObjectFound(object)
	local interactiveBind, interactiveBindIndex = self:getInteractiveBind(object:getName())
	if interactiveBind then
		self:removeInteractiveBind(interactiveBindIndex)
	end
end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- TASKS ----------------------------------------------------------------------
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:getRandomTaskObject()
	local allTasks	 = self.playfield:getHOLogic():getNotFoundTaskObjects()
	local objectName = (#allTasks ~= 0) and allTasks[math.random(#allTasks)]
										 or nil
	return objectName
end
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:findTaskObject(objectName)
	local hoLogic = self.playfield:getHOLogic()

	if hoLogic:isTaskObject(objectName) then
		SetTaskObjectFound(self.playfield:getName(), objectName)

		local interactiveBind = self:getInteractiveBind(objectName)
		local delay			  = interactiveBind and interactiveBind.duration or 0
		local action		  = function()
									local object = self.playfield:getEntityNamed(objectName)
									object.onClickBegin:notify(object, nil)
								end

		-- выполнение инерактива
		if interactiveBind then
			local checkTable = self:getCheckInteractiveTable()

			for i=1, #checkTable do
				local funct = checkTable[i]

				if funct( interactiveBind.interactObject ) then
					break
				end
			end
		end

		-- выполнение таска
		if delay == 0 then
			action()
		else
			self.playfield:getTimer():add(action, delay)
		end
	end
end
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:getCheckInteractiveTable()
	local checkTable = {}

	table.insert(checkTable,
					function(interactEntityName)
						if self.playfield:getActiveObject(interactEntityName) then
							local bCompleted = self.playfield:isObjectClicked(interactEntityName)

							if not bCompleted then
								local entity = self.playfield:getEntityNamed(interactEntityName)
								entity.onClickBegin:notify(entity, nil)
							end
							return true
						end

						return false
					end)

	table.insert(checkTable,
					function(interactEntityName)
						local dragObject = self.playfield:getDragManager():get(interactEntityName)

						if dragObject then
							if not dragObject:isUsed() then
								local dropTargets = dragObject:getDropTarget()

								for i, target in ipairs(dropTargets) do
									if not dragObject:isDropOnTarget( target:getName() ) then
										dragObject:createSessionData(nil)
										dragObject:onDropTarget(target)
									end
								end
							end
							return true
						end

						return false
					end)

	return checkTable
end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- INTERACTIVES ---------------------------------------------------------------
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:addInteractiveBind(taskObjects, interactObject, duration)
	local interactive			= {}
	interactive.taskObjects		= taskObjects
	interactive.interactObject	= interactObject
	interactive.duration		= duration

	table.insert(self.interactiveBinds, interactive)
end
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:removeInteractiveBind(key)
	local interactive
	local interactiveIndex

	if type(key) == 'number' then
		interactiveIndex = key
	else
		interactive, interactiveIndex = self:getInteractive(key)
	end

	if interactiveIndex then
		table.remove(self.interactiveBinds, interactiveIndex)
	end
end
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:getInteractiveBind(taskObjectName)
	for i, interactive in ipairs(self.interactiveBinds) do
		local objectsType = type(interactive.taskObjects)

		if objectsType == 'string' then
			if interactive.taskObjects == taskObjectName then
				return interactive, i
			end
		elseif objectsType == 'table' then
			for _, objectName in ipairs(interactive.taskObjects) do
				if objectName == taskObjectName then
					return interactive, i
				end
			end
		end
	end

	return nil
end
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
-- TEST -----------------------------------------------------------------------
-------------------------------------------------------------------------------

function AlternativeHOZoomBase:setupTest()
	local entity	 = self.playfield:getZoomFade()
	local connection = nil
	local action	 =	function()
							local taskObject = self:getRandomTaskObject()

							if taskObject then
								self:findTaskObject(taskObject)
							end
						end
	
	self.on_open = function()	
		connection = entity.onClickBegin:add(action)
	end

	self.on_close = function()
		connection:remove()
		connection = nil
	end
end
-------------------------------------------------------------------------------