InteractiveHelp = {
--------------------------------------------------------------------------------
	tutorialScreen      = nil,
	askDialogPostAction = nil,
	forcedObject        = nil,

	States = {
			ASKED_FOR_HELP			= 'AskedForInteractiveHelp',
			HELP_SHOWN				= 'InteractiveHelpShown',
			SHOWING_HELP			= 'ShowingInteractiveHelp',
			SKIP_HELP               = 'InteractiveHelpSkip',
			DEFAULT_TIP_SHOW_DELAY	= .7
			},

	----------------------------------------------------------------------------
	askDialog = {
		show = function (postAction)
			assert(current_scene)       -- На момент вызов должен быть проинициализирован current_scene.
			if not getPlayModeParameters().tutorialEnabled then -- not isCasualPlayMode() then
				SetGameState(InteractiveHelp.States.ASKED_FOR_HELP, 'true')
				SetGameState(InteractiveHelp.States.SHOWING_HELP,	'false')
				return
			end
			
			if HasGameState(InteractiveHelp.States.ASKED_FOR_HELP) then
				postAction(InteractiveHelp.isBeingShown(), true)
				return
			end
	
			current_scene:getPlayField():getMouseBlocker():push()
			InteractiveHelp.askDialogPostAction = postAction

			local screen = createYesNoScreen("INTERACTIVE_HELP_NEEDED",
											 InteractiveHelp.askDialog.onAgree,
											 InteractiveHelp.askDialog.onDecline, false)
		end,

	-- Event Handlers - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
		onAgree = function ()
			if InteractiveHelp.wasAskedForHelp() then
				RemoveGameState(InteractiveHelp.States.ASKED_FOR_HELP)
			end
			AddGameState(InteractiveHelp.States.ASKED_FOR_HELP, "true")
	
			current_scene:getPlayField():getMouseBlocker():pop()
			AddGameState(InteractiveHelp.States.SHOWING_HELP, "true")
	
			if (InteractiveHelp.askDialogPostAction) then
				InteractiveHelp.askDialogPostAction(true, false)
				InteractiveHelp.askDialogPostAction = nil;
			end
		end,
		onDecline = function ()
			AddGameState(InteractiveHelp.States.ASKED_FOR_HELP, "true")
			AddGameState(InteractiveHelp.States.SKIP_HELP, 'true')

			current_scene:getPlayField():getMouseBlocker():pop()

			if InteractiveHelp.askDialogPostAction then
				InteractiveHelp.askDialogPostAction(false, false)
				InteractiveHelp.askDialogPostAction = nil
			end
		end
	},

	wasAskedForHelp = function ()
		return HasGameState(InteractiveHelp.States.ASKED_FOR_HELP)
	end,

	isBeingShown = function ()
		return HasGameState(InteractiveHelp.States.SHOWING_HELP, "true");
	end,
		
	isSkip = function()
		return HasGameState(InteractiveHelp.States.SKIP_HELP, 'true')
	end,

	skip = function ()
		if InteractiveHelp.tutorialScreen then
			InteractiveHelp.tutorialScreen:onSkipTutorialButtonClick()
		end
		SetGameState(InteractiveHelp.States.SHOWING_HELP, "false")
		AddGameState(InteractiveHelp.States.SKIP_HELP, 'true')
	end,

	deactivate = function()
		SetGameState(InteractiveHelp.States.SHOWING_HELP,	"false")
		SetGameState(InteractiveHelp.States.ASKED_FOR_HELP,	"false")
	end,

	inGameMenu = function ()
		GetCurrentLevel():GetPanelLuaObject():OnMenuButtonClick()
	end,

	registeredTips = {},

	registerTipConstructor = function (id, Constructor, isCompleted)
		assert(not InteractiveHelp.registeredTips[id] and "Attempt to register tip with existing Id !")
		InteractiveHelp.registeredTips[id] = {}
		InteractiveHelp.registeredTips[id].Constructor = Constructor
		InteractiveHelp.registeredTips[id].isCompleted = isCompleted
	end,

	showTip = function (tipId, delay, ignoreChecking, show_many_times)
		if  ( (not ignoreChecking) and (not InteractiveHelp.isBeingShown())  ) or
			( InteractiveHelp.isHelpCompleted(tipId) and not show_many_times ) or
			HasGameState('AUTOPLAY', '1')
		then
			return
		end
		--if (not ignoreChecking) and not isCasualPlayMode() then
		--	return
		--end
		assert(current_scene)       -- На момент вызов должен быть проинициализирован current_scene.
		assert(InteractiveHelp.registeredTips[tipId])

		delay = delay or InteractiveHelp.States.DEFAULT_TIP_SHOW_DELAY
		local playfield = current_scene:getPlayField()
		current_scene:getPanel():getMainEntity():setRespondable(false)

		playfield:getMouseBlocker():push()
		playfield.timer:add(function()
								InteractiveHelp.registeredTips[tipId].Constructor(tipId)
								playfield.timer:add(function()
														current_scene:getPanel():getMainEntity():setRespondable(true)
														if not playfield:isDestroyed() then
															playfield:getMouseBlocker():pop()
														end
													end, SCREEN_SHOW_HIDE + 0.1) -- Данная задержка нужна для проявления окна.
							end, delay)
	end,
		
	isHelpShown = function (tipId)
		local messageTextAlias = 'INTERACTIVE_HELP_MSG_'..tipId
		return HasGameState(InteractiveHelp.States.HELP_SHOWN, messageTextAlias)
	end,

	setHelpShown = function (tipId)
		local messageTextAlias = 'INTERACTIVE_HELP_MSG_'..tipId
		AddUniqueGameState(InteractiveHelp.States.HELP_SHOWN, messageTextAlias)
	end,
	
	isHelpCompleted = function (tipId)
		assert( InteractiveHelp.registeredTips[tipId] )
		if InteractiveHelp.registeredTips[tipId].isCompleted then
			return InteractiveHelp.registeredTips[tipId].isCompleted(tipId)
		else
			return InteractiveHelp.isHelpShown(tipId)
		end
	end,
}