class 'l_04_Gazebo' (PlayField)

function l_04_Gazebo:__init(game_scene, name, path)
	PlayField.__init(self, game_scene, name, path)
	
	-- interactive help --------------------------------------------------------
    self.tutorial = self:getGameScene():getTutorial()
    ----------------------------------------------------------------------------   	
	self:linkScene('area_link_03',   'CursorDown',    '03_Panorama')
	self:linkScene('area_link_05',   'CursorUp',    '05_Forest_path')
	self:linkScene('area_link_ho',   'CursorEye',    '04_Gazebo_HO')
	----------------------------------------------------------------------------	
	self:entityHide('area_click_after_maze', 'area_click_maze_path_dialogue', 'area_bbt_andrea_2', 'area_zoom_Andrea', 'area_zoom_Railing')

	self:getEntityNamed('compositionanim'):hide() 
	self:getEntityNamed('compositionanim_idel'):hide() 

	self:entityHide('box_open')	
	self:getEntityNamed('compositionraven_idle'):play()

	----------------------------------------------------------------------------
	if IsToolFound('04_pick') then
	    self:entityHide('pick')  
	end
	----------------------------------------------------------------------------

	----------------------------------------------------------------------------
	if (IsToolFound('04_letter_to_laura') and not IsToolFound('04_fury_hour_glass')) then
		local info 	= self:getInventory().tools['04_letter_to_laura']
		info.on_tool_window_close = function()
								self:findTool('04_fury_hour_glass', nil,
	                			function()
	                				local achievment = current_scene:getAchievmentsManager():getAchievment('NoSkipMG')
	                				if achievment and achievment:isCompleted() then
		                				SetGameState('achievment_mg_showed', 'true')
		                				current_scene:getInformManager():show_message('achievment_mg')
		                			end
	                			end) 
	                		end
	end
	----------------------------------------------------------------------------

	----------------------------------------------------------------------------
	if (IsToolFound('04_fury_hour_glass') and not HasGameState('achievment_mg_showed', 'true')) then
		SetGameState('achievment_mg_showed', 'true')
		local info 	= self:getInventory().tools['04_fury_hour_glass']
		info.on_tool_window_close = function()								
	                				local achievment = current_scene:getAchievmentsManager():getAchievment('NoSkipMG')
	                				if achievment and achievment:isCompleted() then
		                				SetGameState('achievment_mg_showed', 'true')
		                				current_scene:getInformManager():show_message('achievment_mg')
		                			end      	
	                			end
	end
	--------------------------------------------------------------------------------

	--------------------------------------------------------------------------------
	self.zoom_andrea = self:createZoomZone('Andrea', ZOOM_TYPE_FULLSCREEN)
	--------------------------------------------------------------------------------

	--------------------------------------------------------------------------------
	do 
		if not self:isObjectClicked('area_click_first_visit', self.name) then		
			self.fade_object = self:focusOnAndrea()

		    self:setForcedObject( self:getEntityNamed('area_click_first_visit') )
		end
		
		local function on_click_first_visit(e)
		    self:entityHide(e.target)
		    self:setForcedObject(nil) 

		    self:hideFocus()

		    if not self:isComicsShown('Andrea_1', self.name) then
	            self.zoom_andrea:open()
	        else
	            self.timer:add(function()
	                    self:requestShowHOTutorial()
	                end, 0)
	        end
		end
		self:registerActiveObject('area_click_first_visit', on_click_first_visit, false, 'CursorDialog')
	end
	--------------------------------------------------------------------------------

	self:registerBBT('area_bbt_andrea_1', 'BBT_04_ANDREA_1')	
	self:registerBBT('area_bbt_andrea_2', 'BBT_04_ANDREA_2')
	
	--------------------------------------------------------------------------------
	do 
		local function on_click_maze_path_dialogue(e)
		    if not e.save then
	            self.zoom_andrea:open()
	        end
		end
		self:registerActiveObject('area_click_maze_path_dialogue', on_click_maze_path_dialogue, true, 'CursorDialog')
	end
	--------------------------------------------------------------------------------

	----------------------------------------------------------------------------
	if HasGameState('04_Gazebo_Wrong_Step_Return_From_Maze_Shown', 'false') then
        SetGameState('04_Gazebo_Wrong_Step_Return_From_Maze_Shown', 'true')
            
        if isSceneVisited('05_Forest_path') and not HasGameState('05_Forest_path_Once_Get_Lost_Shown') then
            AddUniqueGameState('05_Forest_path_Once_Get_Lost_Shown', 'true')
        else
            self.timer:add(function()
                    self:showBlackBar('BBT_04_WRONG_STEP_RETURN_FROM_MAZE')
                end, 0)
        end
    else
        if isSceneVisited('05_Forest_path') and not HasGameState('05_Forest_path_Once_Get_Lost_Shown') then
            AddUniqueGameState('05_Forest_path_Once_Get_Lost_Shown', 'true')
        end
    end
    ----------------------------------------------------------------------------

	----------------------------------------------------------------------------
	if HasGameState('05_Forest_path_Once_Get_Lost_Shown') and not self:isComicsShown('Andrea_2', self.name) then
	    self:entityHide('area_bbt_andrea_1')
	    self:entityShow('area_zoom_Andrea')
		
	    self:entityShow('area_click_after_maze')
	    self.fade_object = self:focusOnAndrea()
	    self:setForcedObject(self:getEntityNamed('area_click_after_maze'))

	    local function on_click_after_maze(e)
	        self:entityHide(e.target)

	        self:setForcedObject(nil)
	        self:hideFocus()

            self.zoom_andrea:open()
	    end

	    self:registerActiveObject('area_click_after_maze', on_click_after_maze, false, 'CursorDialog')
	elseif self:isComicsShown('Andrea_2', self.name) then
    	addGameTask('06')
	
	    self:entityHide('area_bbt_andrea_1')
	
	    if not self:isComicsShown('Andrea_3', self.name) then	        
	        self:entityShow('area_zoom_Andrea')
	    else
	        self:addNote('Note_04_Maze_Path')
	    
	        if not isSceneVisited('06_Town') then
	            self:entityShow('area_click_maze_path_dialogue')
            elseif not IsToolFound('06_paper_plane_letter') then
                self:entityShow('area_bbt_andrea_2')
            else
                if not self:isComicsShown('Andrea_4', self.name) then	        
                    self:entityShow('area_zoom_Andrea')
                else
                    self:entityHide('andrea_idle')
                end
            end
	    end
	end
	----------------------------------------------------------------------------
	
	----------------------------------------------------------------------------
	do
		local function on_click_raven(e)
		    self:entityHide(e.target)
		    self:entityShow('area_zoom_Railing')
		    
		    self:getEntityNamed('compositionraven_idle'):stop()
		    self:getEntityNamed('compositionraven_idle'):hide()
		    if not e.save then
		    	self:playSound('04_click_raven')
		        self.mouseBlocker:push()
		        self:getEntityNamed('compositionraven_click'):play()
		        self.timer:add(function()
		                self.mouseBlocker:pop()
		                self:getEntityNamed('compositionraven_click'):hide()
		            end, self:getEntityNamed('compositionraven_click'):getDuration())
		    end
		end
		self:registerActiveObject('area_click_raven', on_click_raven)
	end
	----------------------------------------------------------------------------
	
	self.zoom_tool_box = self:createZoomZone('Tool_box')	
	self.zoom_railing = self:createZoomZone('Railing')
	--------------------------------------------------------------------------------

	--------------------------------------------------------------------------------
	if isSceneVisited('08_Lauras_room') then 
		self:entityHide('04_Gazebo_Anim_Andrea_Bg', 'area_bbt_andrea_1')
	end	
	--------------------------------------------------------------------------------

	--------------------------------------------------------------------------------
	do 	
		if IsToolFound('01_bottle_with_water') and not HasGameState('05_Forest_path_Visited', 'true') then

			local function on_end_cutscene_In_flames()
				self:showBlackBar('BBT_04_IN_FLAMES')
			end 	

			SetGameState('05_Forest_path_Visited', 'true')
			self.in_flames_cut_scene       = createVideo({video = 'In_flames', scale = 1.51, order = 600, x = 512, y = 384, isLooped = false, isAlpha = false})
			self:playSound('In_flames')
			

			self:stopMusicAndrea()	
	        self:startCutScene(self.in_flames_cut_scene , on_end_cutscene_In_flames, nil)
	 	end
	end
	--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
function l_04_Gazebo:requestShowHOTutorial()
    if self.tutorial:isActive() then           
        if ( not self.tutorial:isTipShown( 'HO_ZONE' ) ) then
            self.tutorial:showTip( 'HO_ZONE', 0 )
        end
    end
end
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
function  l_04_Gazebo:playMusicAndrea()
	self.stop_andrea_music = false
	local index = math.random(1, 3)

	self.curent_music_andrea = 'Andlea_play_' .. index
	self:playSound(self.curent_music_andrea)

	 local dTime = 1.0
	-- if index == 2 then
	-- 	dTime = 1.4
	-- end

	local time = self:getSound(self.curent_music_andrea).entity:getDuration() - dTime
	
	if not self.stop_andrea_music then
		self.music_andrea_timer = self.timer:add( function()
							if self.curent_music_andrea then
								self:stopSound(self.curent_music_andrea)
							end
							self:playMusicAndrea()
						end, time)
	end
end
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
function l_04_Gazebo:stopMusicAndrea()	
	if self.curent_music_andrea then
		self:stopSound(self.curent_music_andrea)
	end
	self.stop_andrea_music = true

	if self.music_andrea_timer then
		self.music_andrea_timer:kill()	
	end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function l_04_Gazebo:focusOnAndrea()
	local areaZoomAndrea = self:getEntityNamed( 'area_focus_andrea' )
	areaZoomAndrea:show()

	self:focusOnObject(
		areaZoomAndrea,
		0, 0, Vector2f( 1, 1 ), 0, true )
    
	local name_focus_object = 'fadeObject_'..tostring(fadeObjectCount)
	if self:hasEntityNamed(name_focus_object) then
		self:getEntityNamed(name_focus_object):setColor( Colorf(1, 1, 1, 0.7) )	
	end
end
--------------------------------------------------------------------------------
function l_04_Gazebo:hideFocus()
	local areaZoomAndrea = self:getEntityNamed( 'area_focus_andrea' )
	areaZoomAndrea:hide()
	
	if self.fade_object then
		self.fade_object:destroy()
	end
end
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
--                      GENERATED CONTENT. DO NOT EDIT.                       --
--------------------------------------------------------------------------------

function l_04_Gazebo:CreateLoaderTable()
	local objects =
	{
		{ name = 'bg',  entityType = 'SpriteEntity',  x = 512,  y = 384,  order = 0,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Layers/bg.jpg',  width = 1366,  height = 768,  },
		{ name = '04_Gazebo_Anim_Bg',  entityType = 'CompositionContainer',  parentName = 'bg',  x = -683,  y = -384,  order = 10,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Scripts/Scenes/04_Gazebo/Anim/04_Gazebo_Anim_Bg.lua',  },
		{ name = 'compositionbg_under',  entityType = 'CompositionSequence',  parentName = '04_Gazebo_Anim_Bg',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  isCyclic = true,  speed = 1,  },
		{ name = 'box_closed',  entityType = 'SpriteEntity',  parentName = '04_Gazebo_Anim_Bg',  x = 1009,  y = 542,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Layers/box_closed.png',  width = 184,  height = 98,  },
		{ name = 'box_open',  entityType = 'SpriteEntity',  parentName = '04_Gazebo_Anim_Bg',  x = 1025,  y = 507,  order = 5,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Layers/box_open.png',  width = 100,  height = 60,  },
		{ name = 'compositionraven_idle',  entityType = 'CompositionSequence',  parentName = '04_Gazebo_Anim_Bg',  x = 0,  y = 0,  order = 5,  isVisible = false,  isActive = false,  editingLocked = false,  treeItemIsExpanded = false,  isCyclic = true,  speed = 1,  },
		{ name = 'compositionraven_click',  entityType = 'CompositionSequence',  parentName = '04_Gazebo_Anim_Bg',  x = 0,  y = 0,  order = 10,  isVisible = false,  isActive = false,  editingLocked = false,  treeItemIsExpanded = false,  speed = 1,  },
		{ name = 'compositionbg_over',  entityType = 'CompositionSequence',  parentName = '04_Gazebo_Anim_Bg',  x = 0,  y = 0,  order = 20,  editingLocked = false,  treeItemIsExpanded = false,  isCyclic = true,  speed = 1,  },
		{ name = 'pick',  entityType = 'SpriteEntity',  parentName = 'bg',  x = -357,  y = 139,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Layers/pick.png',  width = 24,  height = 18,  },
		{ name = 'andrea_idle',  entityType = 'SpriteEntity',  x = 340,  y = 398,  order = 10,  isVisible = false,  scale = 1.2,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Layers/andrea.png',  width = 104,  height = 250,  },
		{ name = 'area_click_first_visit',  entityType = 'SpriteEntity',  x = 511,  y = 384,  order = 100,  scaleX = 13.66,  scaleY = 7.68,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_click_after_maze',  entityType = 'SpriteEntity',  x = 511,  y = 384,  order = 100,  scaleX = 13.66,  scaleY = 7.68,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_link_03',  entityType = 'SpriteEntity',  x = 512,  y = 718,  order = 100,  scaleX = 11,  scaleY = 2,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 100,  height = 100,  },
		{ name = 'area_link_05',  entityType = 'SpriteEntity',  x = 845,  y = 265,  order = 100,  scaleX = 1.8,  scaleY = 2,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_bbt_andrea_1',  entityType = 'SpriteEntity',  x = 332,  y = 399,  order = 100,  scaleX = 1.6,  scaleY = 3,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_bbt_andrea_2',  entityType = 'SpriteEntity',  x = 332,  y = 399,  order = 100,  scaleX = 1.6,  scaleY = 3,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_click_raven',  entityType = 'SpriteEntity',  x = 622,  y = 434,  order = 100,  scale = 1.5,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_zoom_Andrea',  entityType = 'SpriteEntity',  x = 384,  y = 385,  order = 100,  scaleX = 1.6,  scaleY = 3,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_zoom_Railing',  entityType = 'SpriteEntity',  x = 622,  y = 434,  order = 100,  scale = 1.5,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 100,  height = 100,  },
		{ name = 'area_zoom_Tool_box',  entityType = 'SpriteEntity',  x = 855,  y = 534,  order = 100,  scale = 1.5,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_link_ho',  entityType = 'SpriteEntity',  x = 147.5,  y = 502,  order = 100,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 188,  height = 181,  },
		{ name = 'area_click_maze_path_dialogue',  entityType = 'SpriteEntity',  x = 332,  y = 399,  order = 100,  scaleX = 1.6,  scaleY = 3,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'bg_ho',  entityType = 'SpriteEntity',  x = 155,  y = 499,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/04_Gazebo/Layers/bg_ho.png',  width = 232,  height = 146,  },
		{ name = '04_Gazebo_Anim_Andrea_Bg',  entityType = 'CompositionContainer',  x = -171,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Scripts/Scenes/04_Gazebo/Anim/04_Gazebo_Anim_Andrea_Bg.lua',  },
		{ name = 'compositionall_anim',  entityType = 'CompositionSequence',  parentName = '04_Gazebo_Anim_Andrea_Bg',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  isCyclic = true,  speed = 1,  },
		{ name = 'compositionanim',  entityType = 'CompositionSequence',  parentName = '04_Gazebo_Anim_Andrea_Bg',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  speed = 1,  },
		{ name = 'compositionanim_idel',  entityType = 'CompositionSequence',  parentName = '04_Gazebo_Anim_Andrea_Bg',  x = 0,  y = 0,  order = 0,  isVisible = false,  editingLocked = false,  treeItemIsExpanded = false,  isCyclic = true,  speed = 1,  },
		{ name = 'area_focus_andrea',  entityType = 'SpriteEntity',  x = 384,  y = 385,  order = 95,  scaleX = 1.6,  scaleY = 3,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 90,  height = 90,  },
	}
	return objects
end
