dofile('data/Scripts/scenes/11_corridor/anim/11_corridor_anim_bg.lua')

class 'l_11_corridor' (LevelEventHandler)

function l_11_corridor:__init(name)
	LevelEventHandler.__init(self, name)
	
	-- animations ----------------------------------
	self.anim_bg = AnimationBundle(Loader_11_BG_Animations(Object('bg')))
	self.anim_bg:PlayAnimation('bg')
	
	-- link scenes ---------------------------------
	LinkScene('area_link_10', 'CursorDoorDown',   'l_10_hotel')
	LinkScene('area_link_15', 'CursorDoorLeftUp', 'l_15_headwaiters_room')
	LinkScene('area_link_ho', 'CursorGlass',      'l_11_corridor_ho', nil, nil, true)
	
	if IsToolFound('11_matches') and
	    not IsToolFound('11_binoculars') and
	    IsSceneVisited('l_13_junk_shop')
    then
        ReopenScene('l_11_corridor_ho')
    end
	
	-- main logic ----------------------------------
	
	ObjectOpacity('layer_doot_12_open', 0)
	ObjectOpacity('layer_doot_15_open', 0)
	
	if IsMiniGameCompleted('l_11_Vitraj') then
	    ObjectVisible('area_link_mg', false)
	    LinkScene('area_link_12', 'CursorDoorUp', 'l_12_grannies_room')
	    
	    if not HasActionCompletedState('Door12Opened') then
	        ObjectVisible('area_link_12', false)
	        
	        self.timer:Add( function()
                                local time = 0.5
                                ObjectOpacity('layer_doot_12_open',  1, time)
                                ObjectOpacity('layer_doot_12_close', 0, time)
                                MakeSoundEntity('11_open_door'):PlaySound(false)
                                
                                self.timer:Add( function()
                                                    AddActionCompletedState('Door12Opened')
                                                    ObjectVisible('area_link_12', true)
                                                end,
                                                time)
                            end,
                            0.5)
	    else
	        ObjectOpacity('layer_doot_12_open',  1)
	        ObjectOpacity('layer_doot_12_close', 0)
	    end
	else
	    ObjectVisible('area_link_12', false)
	    LinkScene('area_link_mg', 'CursorGlass',  'l_11_Vitraj')
	end
	
	-- main logic ----------------------------------
	local function on_find_veil(e)
	    ObjectVisible(e.target, false)
	    ObjectOpacity('layer_veil', 0)
	end
	
	RegisterToolFindInfo('11_veil', 'area_find_veil', on_find_veil)
	
	-- zoom zones ----------------------------------
	
	-- ZOOM LOCK
	do
	    CreateSmartZoomZone('lock')
	    ---------------------
	    
	    Helpers.AttachInPlace(Object('z_lock_handle'), Object('z_lock_door'))
	    Helpers.AttachInPlace(Object('z_lock_shadow'), Object('z_lock_door'))
	    Helpers.AttachInPlace(Object('z_lock_key_1'),  Object('z_lock_door'))
	    Helpers.AttachInPlace(Object('z_lock_key_2'),  Object('z_lock_door'))
	    
	    ObjectOpacity('z_lock_key_1',  0)
	    ObjectOpacity('z_lock_key_2',  0)
	    
	    ObjectVisible('area_click_zl_handle', false)
	    ObjectVisible('area_link_15',         false)
	    ---------------------
	    
	    local function on_apply_waiter_key(e)
	        ObjectVisible(e.target, false)
	        
	        if e.save then
	            ObjectOpacity('z_lock_key_1', 1)
	            ObjectVisible('area_click_zl_handle', true)
	        else
	            local time = 0.5
	            ObjectOpacity('z_lock_key_1', 1, time)
	            MakeSoundEntity('11_apply_waiter_key'):PlaySound(false)
	            
	            self.timer:Add( function()
	                                ObjectVisible('area_click_zl_handle', true)
	                            end,
	                            time)
	        end
	    end
	    ---------------------
	    
	    local function on_click_handle(e)
	        ObjectVisible(e.target, false)
	        
	        if e.save then
	            self.zoom_lock:Disable()
	            ObjectVisible('area_link_15', true)
	            ObjectOpacity('layer_doot_15_open',  1)
                ObjectOpacity('layer_doot_15_close', 0)
	        else
	            local keyTime = 0.5
	            ObjectOpacity('z_lock_key_1', 0, keyTime)
	            ObjectOpacity('z_lock_key_2', 1, keyTime)
	            
	            MakeSoundEntity('11_click_handle'):PlaySound(false)
	            
	            self.timer:Add( function()
	                                local handleTime = 0.5
	                                local angle = -20 * M_PI/180
	                                
	                                Object('z_lock_handle'):Rotate(angle, handleTime)
	                                Object('z_lock_shadow'):Rotate(angle, handleTime)
	                                
	                                self.timer:Add( function()
	                                                    local doorTime = 0.5
	                                                    local scale = 0.9
	                                                    
	                                                    Object('z_lock_door'):ChangeScaleX(1, scale, doorTime)
	                                                    
	                                                    self.timer:Add( function()
	                                                                        self.zoom_lock:CloseAndDisable()
                                                                            self.timer:Add( function()
                                                                                                local openDoorTime = 0.5
                                                                                                
                                                                                                ObjectOpacity('layer_doot_15_open',  1, openDoorTime)
                                                                                                ObjectOpacity('layer_doot_15_close', 0, openDoorTime)
                                                                                                
                                                                                                self.timer:Add( function()
                                                                                                                    ObjectVisible('area_link_15', true)
                                                                                                                end,
                                                                                                                openDoorTime)
                                                                                            end,
                                                                                            ZOOM_ZONE_APPEARING_TIME)
	                                                                    end,
	                                                                    doorTime)
	                                                end,
	                                                handleTime)
	                            end,
	                            keyTime)
	        end
	    end
	    ---------------------
	    
	    RegisterToolApplyInfo('10_waiter_key', 'area_apply_zl_waiter_key', on_apply_waiter_key, 'BBT_11_NEED_APPLY_WAITER_KEY')
	    RegisterActiveObject('area_click_zl_handle', on_click_handle)
	end
end

function l_11_corridor:OnUpdate(dt)
end

function l_11_corridor:OnAllItemsFound()
end

function l_11_corridor:OnObjectMouseEnter(object)
end

function l_11_corridor:OnObjectMouseLeave(object)
end

function l_11_corridor:OnScreenObjectMouseDown(object, key)
end

function l_11_corridor:OnObjectMouseDownProcessed(is_wrong_click)
end

function l_11_corridor:OnMouseMove(previous_pos, current_pos)
end

function l_11_corridor:OnObjectMouseUp(object)
end

function l_11_corridor:OnObjectFound(object)
end

function l_11_corridor:OnToolFound(tool)
end

function l_11_corridor:OnToolApply(tool, object)
end

function l_11_corridor:OnToolAddToInventory(tool)
end

function l_11_corridor:OnObjectReachPanel(object)
end

function l_11_corridor:OnButtonPress(title)
end

function l_11_corridor:OnSetTool(tool)
end

function l_11_corridor:OnLoaded()
end

function l_11_corridor:OnDestroy()
end

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function l_11_corridor:LoadData(screen)
	local anim
	anim = CreateAnimation('data/Texture/Scenes/11_corridor/main/layers/bg.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bg',anim,512,384,50,0,1,1)
	
	anim = CreateAnimation('data/Texture/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_link_10',anim,512,700,100,0,128,17)
	
	anim = CreateAnimation('data/Texture/Common/area_round.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_link_12',anim,138,348,100,0,1.5,4)
	
	anim = CreateAnimation('data/Texture/Common/area_round.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_link_15',anim,362,362,100,0,0.9,3)
	
	anim = CreateAnimation('data/Texture/Common/area_round.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_link_ho',anim,652,426,100,0,1.55,1)
	
	anim = CreateAnimation('data/Texture/Common/area_round.png',0,0,128,128,1,0)
	anim:SetHotSpot(46,35)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_link_mg',anim,103.5,228.97,100,0,1.25,4.07)
	
	anim = CreateAnimation('data/Texture/Common/area_round.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_find_veil',anim,774,520,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/Common/area_round.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_zoom_lock',anim,362,362,100,0,0.9,1)
	
	anim = CreateAnimation('data/Texture/Scenes/11_corridor/main/layers/layer_doot_12_close.png',0,0,100,486,1,0)
	anim:SetHotSpot(50,243)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_doot_12_close',anim,119,362,60,0,1,1)
	
	anim = CreateAnimation('data/Texture/Scenes/11_corridor/main/layers/layer_doot_12_open.png',0,0,217,571,1,0)
	anim:SetHotSpot(108,285)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_doot_12_open',anim,140,409,61,0,1,1)
	
	anim = CreateAnimation('data/Texture/Scenes/11_corridor/main/layers/layer_doot_15_close.png',0,0,46,314,1,0)
	anim:SetHotSpot(23,157)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_doot_15_close',anim,364,371,60,0,1,1)
	
	anim = CreateAnimation('data/Texture/Scenes/11_corridor/main/layers/layer_doot_15_open.png',0,0,224,452,1,0)
	anim:SetHotSpot(112,226)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_doot_15_open',anim,386,443,61,0,1,1)
	
	anim = CreateAnimation('data/Texture/Scenes/11_corridor/main/layers/layer_veil.png',0,0,104,148,1,0)
	anim:SetHotSpot(52,74)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_veil',anim,778,515,60,0,1,1)
	
end
-- CLEAR_ON_SAVE_END
