class 'l_03_Panorama_Z_Radio' (ZoomZone)

function l_03_Panorama_Z_Radio:__init(name, mode, PlayField)
	ZoomZone.__init(self, name, mode, PlayField)
	
	
	self:entityHide('area_click_zr_open_door', 'area_find_zr_glove', 'area_apply_zr_conductor','area_click_handle')
	self:entityHide('zr_door_open','zr_lampa','zr_on','zr_off')
	local apply_wrench_counter = 2	
	local function on_apply_zr_wrench(e)
	    self:entityHide(e.target)
	    local i = string.sub(e.target, -1)
	    
	    if not e.save then
	        self:entityFadeHide('zr_bolt_'..i)
	        self:stopSound('03_apply_zr_wrench')	
	         self:playSound('03_apply_zr_wrench')
	    else
	        self:entityHide('zr_bolt_'..i)
	    end
	    
	    apply_wrench_counter = apply_wrench_counter - 1
	    if apply_wrench_counter<=0 then
	        self:entityShow('area_click_zr_open_door')
	    end
	end
	self:registerToolApplyInfo('01_wrench', {'area_apply_zr_wrench_1', 'area_apply_zr_wrench_2'}, on_apply_zr_wrench, 'BBT_03_NEED_WRENCH')
	
	local function on_click_zr_open_door(e)
	    self:entityHide(e.target)
	    
	    self:entityShow('area_find_zr_glove','area_apply_zr_conductor')
	   
	    	    
	    if not e.save then
	        self.mouseBlocker:push()
	        self:entityFadeShow('zr_off')
	        self:playSound('03_click_zr_open_door')
	        self:entityShow('zr_door_open')
	        self:getEntityNamed('zr_door_closed'):ChangeOpacity(1,0,0.5)
	        self:getEntityNamed('zr_door_open'):ChangeOpacity(0,1,0.5)
			self:getEntityNamed('zt_lamp'):ChangeOpacity(0,1,0.5)	
	        
	        self.playfield:entityShow('door_open')
	        self.playfield:getEntityNamed('door_open'):ChangeOpacity(0,1,0.5)
	        self.timer:add(function()
	                self.mouseBlocker:pop()
	            end, 0.5)
	    else
	        self:entityHide('zr_door_closed')
	        self:entityShow('zr_door_open','zr_off')
			self:entityShow('zt_lamp')	
	        
	        self.playfield:entityShow('door_open')
	    end
	end
	self:registerActiveObject('area_click_zr_open_door', on_click_zr_open_door)

	
	local function on_find_zr_glove(e)
	    self:entityHide(e.target)
	    
	    self:entityHide('zr_glove')
	end
	self:registerToolFindInfo('03_glove', 'area_find_zr_glove', on_find_zr_glove)


	-- apply conductor -----------------------------------------------
	do 
		local function on_apply_zr_conductor(e)
			self:entityShow('area_click_handle')
			self:entityHide(e.target)
			if not e.save then
		        self:playSound('03_apply_zr_conductor')
		        self:entityFadeShow('zr_lampa')
		        self.playfield:entityFadeHide('broken_lamp')
		        self.playfield:entityFadeShow('lamp')
		        self:entityFadeHide('zt_lamp')
		    else
		        self.playfield:entityShow('lamp')
		        self.playfield:entityHide('broken_lamp')
		        self:entityShow('zr_lampa')
				self:entityHide('zt_lamp')
			end
		end
		local info = self:registerToolApplyInfo('01_bulb_lamp', 'area_apply_zr_conductor', on_apply_zr_conductor, 'BBT_03_NEED_BULB_LAMP')

		info.on_target_click = function()
			addGameTask('09')
		end
	end	
	------------------------------------------------------------------

	local function on_click_handle(e)
	    self:entityHide(e.target)	    	    
	    
	    if not e.save then               
	        self:entityFadeHide('zr_off')
	        self:entityFadeShow('zr_on')
	     --   self:entityFadeHide('zr_lampa')
	     --   self.timer:add(function()
		        dofile('Data/Scripts/Scenes/03_Panorama/Animations/03_Panorama_Z_Radio_Animation.lua')
				local sparks = createCompositionbgsparks() 		
			    sparks:attachTo(self:getEntityNamed('zr_bg'))
			    sparks:setXY(-193,  -256)
			    sparks:setOrder(100)
			    self:playSound('03_Panorama_Z_Radio_Animation')
			    self:playSound('03_after_apply_zr_conductor')

			    
		--	end, 0.5)

	       	self.mouseBlocker:push()
	       	local function on_end_cutscene()
    	    	completeGameTask('09')
	   
	       		self.mouseBlocker:pop()
        		self.playfield.paralax_blocked = false	             
                self.playfield:setPickPhoneCallback('Father_3_1', function(save)
                        if not self:isObjectClicked('area_apply_zt_phone', self.playfield.name) then
                            self.playfield.zoom_time_spiral:entityHide('area_bbt_zt_lock')
                            self.playfield.zoom_time_spiral:entityShow('area_apply_zt_phone')
                        end
                        
                        if not save then
                            self.playfield.zoom_comics_father_1:open()
                        end
                    end)
	        end

		    sparks.onFinish:add(function() 
	            self:close()
	            self.playfield.paralax_blocked = true
			    self.playfield:startCutScene(nil, on_end_cutscene, 4)		
		     	
		     	dofile('Data/Scripts/Scenes/03_Panorama/Animations/03_Panorama_Bg_Radio_Animation.lua')
				local radar = createcompositionRadar() 		
			    radar:attachTo(self.playfield:getEntityNamed('anchor_plane_2'))
			    radar:setName('bg_radar_anim')
			    radar:setXY(-171,  0)
			    radar:setOrder(22)
			  
			    dofile('Data/Scripts/Scenes/03_Panorama/Animations/03_Panorama_Bg_Radio_Sky_Animation.lua')
			    local sky = createCompositionSky() 		
			    sky:attachTo(self.playfield:getEntityNamed('anchor_plane_4'))
			    sky:setName('bg_sky_anim')
			    sky:setXY(-171,  0)
			    sky:setOrder(22)

		   	end)
	    else
	    	self:entityHide('zr_off')
	        self:entityShow('zr_on')
	    	--self:entityHide('zr_lampa')
	    	dofile('Data/Scripts/Scenes/03_Panorama/Animations/03_Panorama_Bg_Radio_Animation.lua')
		    local sky = createcompositionRadar() 		
		    sky:attachTo(self.playfield:getEntityNamed('anchor_plane_2'))
		    sky:setXY(-171,  0)
		    sky:setOrder(22)
		    sky:setName('bg_radar_anim')
	    	sky:rewind(true)


	    	dofile('Data/Scripts/Scenes/03_Panorama/Animations/03_Panorama_Bg_Radio_Sky_Animation.lua')
		    local sky = createCompositionSky() 		
		    sky:attachTo(self.playfield:getEntityNamed('anchor_plane_4'))
		    sky:setXY(-171,  0)
		    sky:setOrder(22)
		    sky:setName('bg_sky_anim')
	    	sky:rewind(true)

	    	self.timer:add( function()
					    	    completeGameTask('09')
						    end, 0)
	    	
	        self.playfield:setPickPhoneCallback('Father_3_1', function(save)
                    if not self:isObjectClicked('area_apply_zt_phone', self.playfield.name) then
                        self.timer:add(function()
                                self.playfield.zoom_time_spiral:entityHide('area_bbt_zt_lock')
                                self.playfield.zoom_time_spiral:entityShow('area_apply_zt_phone')
                            end, 0)
                    end
                    
                    if not save then
                        self.playfield.zoom_comics_father_1:open()
                    end
                end)
	    end
	end
	self:registerActiveObject('area_click_handle', on_click_handle)
	
	self:getEntityNamed('area_apply_zr_guitar_wrench').onPress:add(bind(self.shake_string, self))

	local function on_apply_zr_guitar_wrench(e)
	    self:entityHide(e.target)
	    
	    self:entityHide('zr_pins', 'zr_string')
	    
	    self:closeAndDisable()
	    if not HasGameState(TOOL_INFO_SHOWN, '03_string') then
	        self.playfield.paralax_blocked = true
	        self:playSound('03_apply_zr_guitar_wrench')
	        self:findTool('03_string', nil, function()
	                self.playfield.paralax_blocked = false
                end)
        end
	end
	self:registerToolApplyInfo('04_guitar_wrench', 'area_apply_zr_guitar_wrench', on_apply_zr_guitar_wrench, 'BBT_03_NEED_GUITAR_WRENCH')
end

function l_03_Panorama_Z_Radio:shake_string()
			local effector = nil 
	 	
	    local sx = self:getEntityNamed('zr_string'):getX() -- запоминаем начальную позицыю
	    local sy = self:getEntityNamed('zr_string'):getY()
	    local dx = 1/2
	    local dy = 1
	    effector = CreateAnimationEffector()
	    effector:attachTo(self:getEntityNamed('zr_string'))
	    effector:setDestroysOnEnd(true)				
	--	effector:setMode(_ANIM_LOOP)
		effector:setLifeTime(0, 0.7)
		effector:setKey(_TRACK_X, 0.05, sx + dx) 
		effector:setKey(_TRACK_Y, 0.05, sy + dy) 
		effector:setKey(_TRACK_X, 0.1, sx - dx / 1.3)
		effector:setKey(_TRACK_Y, 0.1, sy - dy / 1.3)
		effector:setKey(_TRACK_X, 0.15, sx + dx / 1.5)
		effector:setKey(_TRACK_Y, 0.15, sy + dy / 1.5)
	 	effector:setKey(_TRACK_X, 0.2, sx - dx / 1.7)
		effector:setKey(_TRACK_Y, 0.2, sy - dy / 1.7)
		effector:setKey(_TRACK_X, 0.25, sx + dx / 1.9)
		effector:setKey(_TRACK_Y, 0.25, sy + dy / 1.9)
		effector:setKey(_TRACK_X, 0.3, sx - dx / 2.1)
		effector:setKey(_TRACK_Y, 0.3, sy - dy / 2.1)
		effector:setKey(_TRACK_X, 0.35, sx + dx / 2.3)
		effector:setKey(_TRACK_Y, 0.35, sy + dy / 2.3)
		effector:setKey(_TRACK_X, 0.4, sx - dx / 2.5)
		effector:setKey(_TRACK_Y, 0.4, sy - dy / 2.5)
		effector:setKey(_TRACK_X, 0.45, sx + dx / 2.7)
		effector:setKey(_TRACK_Y, 0.45, sy + dy / 2.7)
		effector:setKey(_TRACK_X, 0.5, sx - dx / 2.9)
		effector:setKey(_TRACK_Y, 0.5, sy - dy / 2.9)
		effector:setKey(_TRACK_X, 0.55, sx + dx / 3.1)
		effector:setKey(_TRACK_Y, 0.55, sy + dy / 3.1)
	    effector:play()
	    self:stopSound('03_shake_string')
		self:playSound('03_shake_string')
end
--------------------------------------------------------------------------------
--                      GENERATED CONTENT. DO NOT EDIT.                       --
--------------------------------------------------------------------------------

function l_03_Panorama_Z_Radio:CreateLoaderTable()
	local objects =
	{
		{ name = 'zr_bg',  entityType = 'SpriteEntity',  x = 512,  y = 384,  order = 0,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zr_bg.jpg',  width = 384,  height = 512,  },
		{ name = 'zt_lamp',  entityType = 'SpriteEntity',  x = 563,  y = 258,  order = 1,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zt_lamp.png',  width = 46,  height = 90,  },
		{ name = 'area_apply_zr_guitar_wrench',  entityType = 'SpriteEntity',  x = 487,  y = 531,  order = 120,  scaleX = 1.7,  scaleY = 1.2,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_apply_zr_wrench_1',  entityType = 'SpriteEntity',  x = 638,  y = 183,  order = 110,  scale = 0.75,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_apply_zr_wrench_2',  entityType = 'SpriteEntity',  x = 620,  y = 512,  order = 110,  scale = 0.75,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_click_zr_open_door',  entityType = 'SpriteEntity',  x = 542,  y = 360,  order = 110,  angle = 2,  scaleX = 2.5,  scaleY = 4.5,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_find_zr_glove',  entityType = 'SpriteEntity',  x = 592,  y = 432,  order = 140,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'area_apply_zr_conductor',  entityType = 'SpriteEntity',  x = 546,  y = 277,  order = 110,  scale = 2,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 100,  height = 100,  },
		{ name = 'zr_glove',  entityType = 'SpriteEntity',  x = 572,  y = 433,  order = 9,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zr_glove.png',  width = 148,  height = 54,  },
		{ name = 'zr_door_open',  entityType = 'SpriteEntity',  x = 512,  y = 384,  order = 10,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zr_door_open.png',  width = 384,  height = 512,  },
		{ name = 'zr_door_closed',  entityType = 'SpriteEntity',  x = 512,  y = 384,  order = 15,  scaleX = 1,  scaleY = 0.96,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zr_door_closed.png',  width = 384,  height = 512,  },
		{ name = 'zr_bolt_1',  entityType = 'SpriteEntity',  parentName = 'zr_door_closed',  x = 126,  y = -198,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zr_bolt_1.png',  width = 52,  height = 46,  },
		{ name = 'zr_bolt_2',  entityType = 'SpriteEntity',  parentName = 'zr_door_closed',  x = 112,  y = 133,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zr_bolt_2.png',  width = 52,  height = 48,  },
		{ name = 'zr_guitar',  entityType = 'SpriteEntity',  x = 535,  y = 511,  order = 20,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zr_guitar.png',  width = 348,  height = 296,  },
		{ name = 'zr_string',  entityType = 'SpriteEntity',  parentName = 'zr_guitar',  x = 40,  y = 53,  order = 25,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zr_string.png',  width = 268,  height = 180,  },
		{ name = 'zr_pins',  entityType = 'SpriteEntity',  parentName = 'zr_guitar',  x = -63,  y = 28,  order = 30,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zr_pins.png',  width = 128,  height = 90,  },
		{ name = 'area_click_handle',  entityType = 'SpriteEntity',  x = 477,  y = 286,  order = 110,  scale = 2,  color = {r = 1, g = 1, b = 1, a = 0.00392157},  editingLocked = false,  treeItemIsExpanded = true,  width = 30,  height = 100,  },
		{ name = 'zr_lampa',  entityType = 'SpriteEntity',  x = 563,  y = 260,  order = 0,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zr_lampa.png',  width = 46,  height = 90,  },
		{ name = 'zr_off',  entityType = 'SpriteEntity',  x = 466,  y = 220,  order = 11,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zr_on.png',  width = 62,  height = 72,  },
		{ name = 'zr_on',  entityType = 'SpriteEntity',  x = 465,  y = 310,  order = 11,  editingLocked = false,  treeItemIsExpanded = false,  texturePath = 'Data/Textures/Scenes/03_Panorama/Z_Radio/zr_off.png',  width = 64,  height = 72,  },
	}
	return objects
end
