class 'l_00_Boat' (PlayField)

function l_00_Boat:__init(game_scene, name, path)
	PlayField.__init(self, game_scene, name, path)
	
	-- links -------------------------------------------------------------------
	self:linkScene('area_link_01',   'CursorUp',    '01_Boat_crash_site')

	-- hide phone --------------------------------------------------------------
	local obj = self:getPanel():getControlsPanel():getEntityNamed('bttn_phone')
	self.timer:add( function() obj:hide() end, 0)
	----------------------------------------------------------------------------	
	self.zoom_comics = self:createZoomZone('Comics', ZOOM_TYPE_VIDEO_CALL)	
	----------------------------------------------------------------------------

	-- interactive help --------------------------------------------------------
    self.tutorial = self:getGameScene():getTutorial() 
   	
   	self.timer:add( function() 
	                    self:askInteractiveHelp() 
	                end, 0 ) 
    ----------------------------------------------------------------------------   

	----------------------------------------------------------------------------
	self:getEntityNamed('bg_idle'):play()	

	self:playSound('02_motor', true)


	local layer_phone_on  = self:getEntityNamed('compositionBG'):getElementByName('Layer_phone_on')
	local layer_phone_off = self:getEntityNamed('compositionBG'):getElementByName('Layer_phone_off')
	local layer_note 	  = self:getEntityNamed('compositionBG'):getElementByName('Layer_note')
	layer_phone_on:setOpacity(0)
	----------------------------------------------------------------------------

	----------------------------------------------------------------------------		
	self:registerBBT('area_bbt_vortex', {'BBT_00_VORTEX_1','BBT_00_VORTEX_2','BBT_00_VORTEX_3'})	
	self:getEntityNamed('area_zoom_Comics'):ChangeOpacity(0, 1, 1)		
	----------------------------------------------------------------------------
	
	-- find note ---------------------------------------------------------------
	local phoneEffector = nil
	do
		local function on_take_note(event)
			local time = 0
			if not event.save then		
				time = 2	
			end	
			self.mouseBlocker:push()	   
		   	self.timer:add( function()
		   			if not self:isObjectClicked('area_click_phone') then
			   			self:entityShow('area_click_phone')	
			   			layer_phone_on:setOpacity(1)	
			   			phoneEffector = self:createPhoneCallEffector()
						self.phoneSound1 = createSoundEntity(self:getMainEntity(), 'PhoneRinging') 
						self.phoneSound1:setRepeated(true)

						phoneEffector:attachTo(layer_phone_on)	

						self.phoneEffector = phoneEffector
						self.phoneEffector:play()
						self.phoneSound1:play()	
					end

					self.mouseBlocker:pop()	
				end, time)
	    end    

	    local function on_find_note(event)
	        self:entityHide('area_click_note')
	        layer_note:setOpacity(0)
	        self:addFlyNote('Note_00_Father', event.save, 'Layer_00_Fly_Father', true, nil, nil, Vector2f(0.5, 0.5), on_take_note)
	        self:addNote('Note_01_Newspaper')
	    end
	    self:registerActiveObject('area_click_note', on_find_note, false)
	end
	----------------------------------------------------------------------------

	-- find phone --------------------------------------------------------------
	do
	  local function on_click_phone(event)
	  		self.timer:add( function()
	  							self:entityHide('area_click_phone')
	  							if self.phoneEffector then
	  								self.phoneEffector:destroy()
	  								self.phoneEffector = nil
	  							end  	

	  							self:getEntityNamed('area_bbt_vortex'):hide()					
	  							
	  							layer_phone_on:setOpacity(0)
	  							layer_phone_off:setOpacity(0)
	  						end, 0)
	  		if (self.phoneSound1) then
	  			self.phoneSound1:stop()	
	  		end

	    	self:setPickPhoneCallback('Father_0_1', function(save)
							self:getEntityNamed('bg_idle'):setActive(false)	 
							self:getEntityNamed('compositionBG'):setActive(false)	  
							if not save then	
								self.zoom_comics:open()
							else		            
								self.timer:add( function()
													-- show phone --------------------------------------------------------------
													local obj = self:getPanel():getControlsPanel():getEntityNamed('bttn_phone')
													obj:show()
													----------------------------------------------------------------------------	
													startLevel('l_01_Boat_crash_site')
												end, 0)
							end
						end, self:getEntityNamed('area_click_phone'))     
	    end
	    self:registerActiveObject('area_click_phone', on_click_phone, false)
	end
	----------------------------------------------------------------------------
end
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
function l_00_Boat:createPhoneCallEffector()
	local effector = CreateAnimationEffector()
	effector:setDestroysOnEnd( true )
	effector:setMode( _ANIM_FWD + _ANIM_LOOP )

	effector:setKey( _TRACK_O, 0,   0)
	effector:setKey( _TRACK_O, 0.5, 1)
	effector:setKey( _TRACK_O, 0.8, 0)
	effector:setKey( _TRACK_O, 1.1, 1)
	effector:setKey( _TRACK_O, 1.4, 0)

	return effector
end
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
function l_00_Boat:showCutscene()
    local function on_cutscene_end()
        self:getGameScene():volumeRestoreMusic()
        -- show phone --------------------------------------------------------------
		local obj = self:getPanel():getControlsPanel():getEntityNamed('bttn_phone')
		obj:show()
		----------------------------------------------------------------------------	

        startLevel('l_01_Boat_crash_site')        
    end
    
    self:getPanel():setMode(EPanelMode.CLEAN)   

    self:getGameScene():volumeTurnDownMusic()
    self:getEntityNamed('cutscene').onFinish:add(on_cutscene_end)
    self:getEntityNamed('cutscene'):setVisible(true)    
    self:getEntityNamed('cutscene'):setActive(true)
    self:playSound('cutscene')
end
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
function l_00_Boat:askInteractiveHelp()
    local function callback( agreed, save )
        if self.tutorial:isActive() then           
            if ( not self.tutorial:isTipShown( 'FLYNOTE_CLICK' ) ) then
                self.tutorial:showTip( 'FLYNOTE_CLICK', 0 )          
            end           
        end
    end

    self.tutorial:showRequestDialog( callback )
end
--------------------------------------------------------------------------------

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

function l_00_Boat:CreateLoaderTable()
	local objects =
	{
		{ name = 'area_zoom_Comics',  entityType = 'SpriteEntity',  x = 512,  y = 384,  order = 0,  isVisible = false,  isRespondable = false,  isActive = false,  scale = 2,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_link_01',  entityType = 'SpriteEntity',  x = 512,  y = 384,  order = 0,  isVisible = false,  isRespondable = false,  isActive = false,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'cutscene',  entityType = 'VideoEntity',  x = 512,  y = 384,  order = 100,  isVisible = false,  isRespondable = false,  isActive = false,  scale = 1.5,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Video/Scenes/00_Boat/cutscene.webm',  hasAlpha = false,  isLooped = false,  fps = 24,  },
		{ name = 'area_click_note',  entityType = 'SpriteEntity',  x = 228.5,  y = 575,  order = 10,  scaleX = 2,  scaleY = 1.5,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 102.5,  height = 100,  },
		{ name = 'area_click_phone',  entityType = 'SpriteEntity',  x = 318,  y = 581,  order = 10,  isVisible = false,  isRespondable = false,  scaleX = 1.4,  scaleY = 1.5,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  width = 100,  height = 100,  },
		{ name = '00_Boat_anim_bg',  entityType = 'CompositionContainer',  x = -171,  y = 0,  order = 8,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Scripts/Scenes/00_Boat/Animations/00_Boat_anim_bg.lua',  },
		{ name = 'compositionBG',  entityType = 'CompositionSequence',  parentName = '00_Boat_anim_bg',  x = 0,  y = 0,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  isCyclic = true,  speed = 1,  },
		{ name = 'bg_idle',  entityType = 'VideoEntity',  x = 512,  y = 276,  order = 4,  scale = 1.5,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Video/Menu/menu_idle.webm',  hasAlpha = false,  isLooped = true,  fps = 24,  },
		{ name = 'area_bbt_vortex',  entityType = 'SpriteEntity',  x = 517,  y = 103,  order = 20,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = false,  hotSpot = {x = 324, y = 95},  width = 648,  height = 190,  },
	}
	return objects
end
