-- animations -----------------------------------------------------------------
dofile('data/Scripts/scenes/08_street/anim/08_street_anim_bg.lua')
dofile('data/Scripts/scenes/08_street/anim/08_street_anim_z_lock.lua')
dofile('data/Scripts/scenes/08_street/anim/08_street_anim_z_doctor_door.lua')
dofile('data/Scripts/scenes/08_street/anim/08_street_anim_z_shop.lua')
dofile('data/Scripts/scenes/08_street/anim/08_street_anim_leaf.lua')

-- comics ---------------------------------------------------------------------
dofile('data/Scripts/scenes/08_street/comics/08_street_comics_dupin.lua')

class 'l_08_street' (LevelEventHandler)

function l_08_street:__init(name)
	LevelEventHandler.__init(self, name)
	
	-- animations ----------------------------------
	self.anim_bg = AnimationBundle(Loader_08_BG_Animations(Object('bg')))
	self.anim_bg:PlayAnimation('bg')
	
	-- link scenes ---------------------------------
	LinkScene('area_link_06',  'CursorDoorDown',    'l_06_garden')
	LinkScene('area_link_09',  'CursorDoorRightUp', 'l_09_doctor')
	LinkScene('area_link_10',  'CursorDoorLeftUp',  'l_10_hotel')
	LinkScene('area_link_13',  'CursorDoorUp',      'l_13_junk_shop')
	LinkScene('area_link_16',  'CursorDoorUp',      'l_16_weapon_shop')
	LinkScene('area_link_08a', 'CursorDoorLeft',    'l_08a_street_pavilion')
	
	local sound_door_hotel_close  = MakeSoundEntity('08_door_hotel_close')
	local sound_door_hotel_open   = MakeSoundEntity('08_door_hotel_open')
	local sound_door_doctor_close = MakeSoundEntity('08_door_doctor_close')
	local sound_door_doctor_open  = MakeSoundEntity('08_door_doctor_open')
	local sound_door_shop_close   = MakeSoundEntity('08_door_shop_close')
	local sound_door_shop_open    = MakeSoundEntity('08_door_shop_open')
	
	BindDoorObject('area_link_10', Object('layer_door_hotel'),  sound_door_hotel_open,  sound_door_hotel_close)
	BindDoorObject('area_link_09', Object('layer_door_doctor'), sound_door_doctor_open, sound_door_doctor_close)
	BindDoorObject('area_link_13', Object('layer_door_shop'),   sound_door_shop_open,   sound_door_shop_close )
	
	-- main logic ----------------------------------
	ObjectVisible('area_link_16',   false)
	ObjectVisible('area_zoom_gate', false)
	
	ObjectOpacity('layer_dupin_with_scroll', 0)
	ObjectOpacity('layer_gate_open',         0)
	
	do
	    local object = Object('area_click_scroll_comics')
	    object:GetAnimation():SetColor('0x01FFFFFF')
	    object:SetOpacity(1)
	    object:SetVisible(false)
	end
	-------------------------
	
	local function on_click_scroll(e)
	    ObjectVisible(e.target, false)
	    ObjectOpacity('layer_scroll', 0)
	    
	    if e.save then
	        ObjectOpacity('layer_dupin_with_scroll', 1)
	        ObjectVisible('area_click_scroll_comics', true)
	    else
	        self.scroll_video = CreateVideoEntity('data/Video/Scenes/08_street/08_scroll.ogg', '', true)
            self.scroll_video:AttachTo(Object('bg'))
            self.scroll_video:SetZ(49)
            self.scroll_video:SetXY(-200, 0)
            self.scroll_video:SetLoop(false)
            self.scroll_video:SetSoftEdges(false)
            self.scroll_video:SetHideOnStop(false)
            self.scroll_video:PlayVideo()
            
            MakeSoundEntity('08_click_scroll'):PlaySound(false)
            
            local fadeTime = 0.1
            
            self.mouseBlocker:Push()
            self.timer:Add( function()
                                ObjectOpacity('layer_dupin_with_scroll', 1, fadeTime)
                                
                                self.timer:Add( function()
                                                    self.mouseBlocker:Pop()
                                                    
                                                    self.scroll_video:SetHideOnStop(true)
                                                    self.scroll_video:StopVideo()
                                                    
                                                    ObjectVisible('area_click_scroll_comics', true)
                                                end,
                                                fadeTime)
                            end,
                            self.scroll_video:GetDuration() - fadeTime)
	    end
	end
	-------------------------
	
	local function on_click_scroll_comics(e)
	    ObjectVisible(e.target, false)
	    
	    if e.save then
	        ObjectOpacity('layer_dupin_with_scroll', 0)
            NotebookPushNote('note_08_poster')
        else
            ObjectOpacity('layer_dupin_with_scroll', 0, 0.2)
            AddActionCompletedState('shemeFounded')
            
            NotebookPushFlyNote('note_08_poster',
                                e.save,
                                'data/Texture/Notes/Note_08_poster_fly.png',
                                Vector(Object(e.target):GetScrX(), Object(e.target):GetScrY()),
                                Vector(0.2, 0.2),
                                nil,
                                function(e)
                                end)
        end
	end
	-------------------------
	
	local function on_apply_on_dog_shoe(e)
	    ObjectVisible('area_zoom_gate', true)
	    
	    if not e.save then
	        self.dogAnimState = true
	        
	        self.zoom_gate:Open()
	    end
	end
	-------------------------
	
	self:create_cutscene()
	RegisterActiveObject('area_click_scroll',        on_click_scroll)
	RegisterActiveObject('area_click_scroll_comics', on_click_scroll_comics)
	
	RegisterToolApplyOnDogInfo('10_shoe', on_apply_on_dog_shoe, 'area_zoom_gate')
	RegisterWrongApplyDialog('08_acid', 'area_hint_za_lock', 'BBT_08_WRONG_APPLY_ACID_IN_ARMORY')
	
	-- zoom zones ----------------------------------
	
	-- ZOOM GATE
	do
	    CreateSmartZoomZone('gate')
	    ---------------------
	    
	    ObjectOpacity('z_gate_open_left',  0)
        ObjectOpacity('z_gate_open_right', 0)
        ObjectOpacity('z_gate_chain',      0)
	    ---------------------
	    
	    ObjectVisible('area_hint_dog', false)
	    ---------------------
	    
	    self.zoom_gate.on_open = function()
	        if self.dogAnimState then
	            self.video_dog = CreateVideoEntity('data/Video/Scenes/08_street/08_dog.ogg', '', true)
                self.video_dog:AttachTo(Object('z_gate_bg'))
                self.video_dog:SetZ(40)
                self.video_dog:SetXY(40, 48)
                self.video_dog:SetLoop(false)
                self.video_dog:SetHideOnStop(false)
                self.video_dog:PlayVideo()
                
                MakeSoundEntity('08_dog'):PlaySound(false)
	            self:GetPanelLuaObject():SetDogIcoVisible(false)
	            
	            ObjectVisible('area_hint_dog',  true)
	            --ObjectVisible('area_zoom_lock', false)
	            
	            self.mouseBlocker:Push()
	            self.timer:Add( function()
	                                self.mouseBlocker:Pop()
	                            end,
	                            self.video_dog:GetDuration() * 0.5)
	        end
	    end
	    ---------------------
	    
	    self.zoom_gate.on_close = function()
	        if self.dogAnimState then
	            self.dogAnimState = nil
	            self:GetPanelLuaObject():SetDogIcoVisible(true)
	            
	            self.timer:Add( function()
	                                self.video_dog:SetVisible(false)
                                    
                                    ObjectVisible('area_hint_dog',  false)
                                    --ObjectVisible('area_zoom_lock', true)
	                            end,
	                            ZOOM_ZONE_APPEARING_TIME)
	        end
	    end
	    ---------------------
	    
	    LinkScene('area_link_zg_08a', 'CursorDoorUp',    'l_08a_street_pavilion')
	    RegisterMonologObject('area_hint_dog', 'BBT_08_DOG_HNT')
	end
	
	-- ZOOM LOCK
	do
	    CreateSmartZoomZone('lock')
	    ---------------------
	    
	    self.anim_lock = AnimationBundle(Loader_08_Zoom_Lock_Animations(Object('z_lock_bg')))
	    self.anim_lock:GetAnimation('action'):SetVisible(true)
	    ---------------------
	    
	    ObjectVisible('area_link_zg_08a', false)
	    ObjectVisible('area_link_08a',    false)
	    ---------------------
	    
	    local function on_apply_acid(e)
	        ObjectVisible(e.target, false)
	        
	        if e.save then
	            self.anim_lock:GetAnimation('action'):SetVisible(false)
	            self.zoom_lock:CloseAndDisable()
	            self.zoom_gate:Disable()
	            
	            ObjectOpacity('z_gate_lock',  0)
                ObjectOpacity('z_gate_close', 0)
                ObjectOpacity('z_gate_open_left',  1)
                ObjectOpacity('z_gate_open_right', 1)
                ObjectOpacity('z_gate_chain',      1)
                ObjectOpacity('layer_gate_close',  0)
                ObjectOpacity('layer_gate_open',   1)
                
                ObjectVisible('area_link_08a', true)
	        else
	            self.anim_lock:PlayAnimation('action')
	            MakeSoundEntity('08_apply_acid'):PlaySound(false)
	            
	            self.mouseBlocker:Push()
	            self.timer:Add( function()
                                    self.zoom_lock:CloseAndDisable()
                                    
                                    self.timer:Add( function()
                                                        local time = 0.5
                                                        
                                                        ObjectOpacity('z_gate_lock',  0, time)
                                                        ObjectOpacity('z_gate_close', 0, time)
                                                        MakeSoundEntity('08_open_gate'):PlaySound(false)
                                                        
                                                        ObjectOpacity('z_gate_open_left',  1, time)
                                                        ObjectOpacity('z_gate_open_right', 1, time)
                                                        ObjectOpacity('z_gate_chain',      1, time)
                                                        
                                                        ObjectOpacity('layer_gate_close', 0, time)
                                                        ObjectOpacity('layer_gate_open',  1, time)
                                                        
                                                        self.timer:Add( function()
                                                                            self.mouseBlocker:Pop()
                                                                            
                                                                            self.zoom_gate:Disable()
                                                                            ObjectVisible('area_link_08a',    true)
                                                                            ObjectVisible('area_link_zg_08a', true)
                                                                        end,
                                                                        time)
                                                    end,
                                                    ZOOM_ZONE_APPEARING_TIME)
                                end,
                                self.anim_lock:GetAnimation('action'):GetDuration())
	        end
	    end
	    ---------------------
	    
	    RegisterToolApplyInfo('08_acid', 'area_apply_zl_acid', on_apply_acid, 'BBT_08_NEED_APPLY_ACID')
	    ---------------------
	end
	
	-- ZOOM DOCTOR DOOR
	do
	    CreateSmartZoomZone('doctor_door')
	    ---------------------
	    
	    self.anim_doctor_door = AnimationBundle(Loader_08_Zoom_Doctor_Door_Animations(Object('z_doctor_door_bg')))
	    self.anim_doctor_door:GetAnimation('action'):SetVisible(true)
	    self.anim_doctor_door:GetAnimation('action'):SetClippingRect(self.zoom_doctor_door:GetClippingInfo())
	    ---------------------
	    
	    self.anim_leaf = AnimationBundle(Loader_08_Leaf_Animations(Object('z_doctor_door_bg')))
	    self.anim_leaf:PlayAnimation('idle')
	    self.anim_leaf:GetAnimation('action'):SetClippingRect(self.zoom_doctor_door:GetClippingInfo())
	    ---------------------
	    
	    ObjectOpacity('z_doctor_door_snake',  0)
	    ObjectOpacity('z_doctor_door_key',    0)
	    ---------------------
	    
	    ObjectVisible('area_link_09',     false)
	    ObjectVisible('area_link_zdd_09', false)
	    ObjectVisible('area_zoom_ground', false)
	    ---------------------
	    
	    LinkScene('area_link_zdd_09', 'CursorDoorUp', 'l_09_doctor')
	    ---------------------
	    
	    local function on_click_steps(e)
	        ObjectVisible(e.target, false)
	        
	        local compos = self.anim_doctor_door:GetAnimation('action')
	        self.anim_leaf:StopAnimation('idle')
	        
	        if e.save then
	            compos:Rewind(true)
	            ObjectVisible('area_zoom_ground', true)
	        else
	            compos:Play()
	            self.anim_leaf:PlayAnimation('action')
	            
	            MakeSoundEntity('08_click_stone'):PlaySound(false)
	            
	            self.timer:Add( function()
	                                ObjectVisible('area_zoom_ground', true)
	                            end,
	                            compos:GetDuration())
	        end
	    end
	    ---------------------
	    
	    local function on_find_flowerpot(e)
	        ObjectVisible(e.target, false)
	        ObjectOpacity('z_doctor_door_flowerpot', 0)
	        
	        if HasActionCompletedState('doctorDoorOpened') and
	           IsToolFound('08_acid')
	        then
	            self.zoom_doctor_door:CloseAndDisable()
	            ObjectVisible('area_link_09', true)
	        end
	    end
	    ---------------------
	    
	    RegisterActiveObject('area_click_steps', on_click_steps)
	    RegisterToolFindInfo('08_flowerpot', 'area_find_zdd_flowerpot', on_find_flowerpot, false)
	    ---------------------
	end
	
	-- ZOOM DOCTOR HANDLE
	do
	    CreateSmartZoomZone('doctor_handle')
	    ---------------------
	    
	    ObjectOpacity('z_doctor_handle_snake',      0)
	    ObjectOpacity('z_doctor_door_open',         0)
	    ObjectOpacity('z_doctor_handle_key',        0)
	    ObjectOpacity('z_doctor_handle_key_shadow', 0)
	    ---------------------
	    
	    ObjectVisible('area_apply_zdh_doctor_key', false)
	    ObjectVisible('area_click_zdh_handle',     false)
	    ---------------------
	    
	    local function on_apply_snake(e)
	        ObjectVisible(e.target, false)
	        
	        local cover = Object('z_doctor_handle_cover')
	        local angle = cover:GetAngle()
	        local deltaAngle = -97 * M_PI/180
	        
	        if e.save then
	            ObjectOpacity('z_doctor_handle_snake',       1)
	            ObjectOpacity('z_doctor_door_snake',         1)
	            
	            Object('z_doctor_door_keyhole_cover'):SetAngle(math.rad(-70))
	            cover:SetAngle(angle + deltaAngle)
	            ObjectVisible('area_apply_zdh_doctor_key', true)
	        else
	            local time = 0.5
	            ObjectOpacity('z_doctor_handle_snake', 1, time)
	            ObjectOpacity('z_doctor_door_snake',   1, time)
	            
	            MakeSoundEntity('08_apply_snake'):PlaySound(false)
	            
	            self.timer:Add( function()
	                                local rotateTime = 0.5
	                                
	                                local eff = CreateAnimationEffector()
	                                eff:SetDestroysOnEnd(true)
	                                eff:AttachTo(cover)
	                                eff:SetKey(_TRACK_A, 0,          angle)
	                                eff:SetKey(_TRACK_A, time * 0.8, angle + deltaAngle*1.05)
	                                eff:SetKey(_TRACK_A, time,       angle + deltaAngle)
	                                eff:Play()
	                                
	                                Object('z_doctor_door_keyhole_cover'):Rotate(math.rad(-70), rotateTime)
	                                
	                                self.timer:Add( function()
	                                                    ObjectVisible('area_apply_zdh_doctor_key', true)
	                                                end,
	                                                rotateTime) 
	                            end,
	                            time)
	        end
	    end
	    ---------------------
	    
	    local function on_apply_doctor_key(e)
	        ObjectVisible(e.target, false)
	        
	        if e.save then
	            ObjectOpacity('z_doctor_handle_key',        1)
	            ObjectOpacity('z_doctor_handle_key_shadow', 1)
	            ObjectOpacity('z_doctor_door_key',          1)
	            
	            ObjectVisible('area_click_zdh_handle', true)
	        else
	            local time = 0.5
	            ObjectOpacity('z_doctor_handle_key',        1, time)
	            ObjectOpacity('z_doctor_handle_key_shadow', 1, time)
	            ObjectOpacity('z_doctor_door_key',          1, time)
	            
	            self.timer:Add( function()
	                                ObjectVisible('area_click_zdh_handle', true)
	                            end,
	                            time)
	        end
	    end
	    ---------------------
	    
	    local function on_click_handle(e)
	        ObjectVisible(e.target, false)
	        
	        if e.save then
	            self.zoom_doctor_handle:CloseAndDisable()
	            ObjectOpacity('z_doctor_door_open', 1)
	            ObjectOpacity('z_doctor_door_key',  0)
	            ObjectVisible('area_link_zdd_09', true)
	            
	            if IsToolFound('08_flowerpot') and
                   IsToolFound('08_acid')
                then
                    self.zoom_doctor_door:Disable()
                    ObjectVisible('area_link_09', true)
                end
	        else
	            local keyTime = 1
	            Object('z_doctor_handle_key'):Rotate(M_TWO_PI, keyTime)
	            
	            local shadow_effector = CreateAnimationEffector()
	            shadow_effector:AttachTo(Object('z_doctor_handle_key_shadow'))
	            shadow_effector:SetDestroysOnEnd(true)
	            shadow_effector:SetKey(_TRACK_SY, 0,              1)
	            shadow_effector:SetKey(_TRACK_SY, keyTime * 0.5, -1)
	            shadow_effector:SetKey(_TRACK_SY, keyTime,        1)
	            shadow_effector:Play()
	            
	            MakeSoundEntity('08_click_key'):PlaySound(false)
	             
	            self.mouseBlocker:Push()
	            self.timer:Add( function()
                                    local time = 0.5
                                    Object('z_doctor_handle_move'):Rotate(-30 * M_PI/180, time)
                                    MakeSoundEntity('08_open_door'):PlaySound(false)
                                    
                                    AddActionCompletedState('doctorDoorOpened')
                                    
                                    self.timer:Add( function()
                                                        self.zoom_doctor_handle:CloseAndDisable()
                                                        
                                                        self.timer:Add( function()
                                                                            local doorOpenTime = 0.5
                                                                            ObjectOpacity('z_doctor_door_open', 1, doorOpenTime)
                                                                            ObjectOpacity('z_doctor_door_key',  0, doorOpenTime)
                                                                            
                                                                            self.timer:Add( function()
                                                                                                self.mouseBlocker:Pop()
                                                                                                ObjectVisible('area_link_zdd_09', true)
                                                                                                
                                                                                                if IsToolFound('08_flowerpot') and
                                                                                                   IsToolFound('08_acid')
                                                                                                then
                                                                                                    self.zoom_doctor_door:Disable()
                                                                                                    ObjectVisible('area_link_09', true)
                                                                                                end
                                                                                            end,
                                                                                            doorOpenTime)
                                                                        end,
                                                                        ZOOM_ZONE_APPEARING_TIME)
                                                    end,
                                                    time)
                                end,
                                keyTime)
	        end
	    end
	    ---------------------
	    
	    RegisterToolApplyInfo('10_snake',      'area_apply_zdh_snake',      on_apply_snake,      'BBT_08_NEED_APPLY_SNAKE')
	    RegisterToolApplyInfo('08_doctor_key', 'area_apply_zdh_doctor_key', on_apply_doctor_key, 'BBT_08_NEED_APPLY_DOCTOR_KEY')
	    RegisterActiveObject('area_click_zdh_handle', on_click_handle)
	end
	
	-- ZOOM GROUND
	do
	    CreateSmartZoomZone('ground')
	    ---------------------
	    
	    local function on_find_acid(e)
	        ObjectVisible(e.target, false)
	        self.anim_doctor_door:GetAnimation('action'):GetElementByName('Layer_2'):SetOpacity(0)
	        
	        if HasActionCompletedState('doctorDoorOpened') and
	           IsToolFound('08_flowerpot')
	        then
	            ObjectVisible('area_link_09', true)
                self.zoom_doctor_door:CloseAndDisable()
	        end
	    end
	    ---------------------
	    
	    RegisterToolFindInfo('08_acid', 'area_find_zg_acid', on_find_acid)
	    ---------------------
	end
	
	-- ZOOM ARMORY
	do
	    CreateSmartZoomZone('armory')
	    ---------------------
	    
	    RegisterMonologObject('area_hint_za_lock', 'BBT_08_ARMORY_LOCK')
	end
	
	-- ZOOM SHOP
	do
	    CreateSmartZoomZone('shop')
	    ---------------------
	    
	    ObjectOpacity('z_shop_door_open', 0)
	    ObjectOpacity('z_shop_head',      0)
	    ObjectOpacity('z_shop_water',     0)
	    ---------------------
	    
	    ObjectVisible('area_apply_zs_head_of_ringbird', false)
	    ObjectVisible('area_apply_zs_matches',          false)
	    ObjectVisible('area_link_zs_13',                false)
	    ObjectVisible('area_link_13',                   false)
	    ---------------------
	    
	    LinkScene('area_link_zs_13', 'CursorDoorUp', 'l_13_junk_shop')
	    ---------------------
	    
	    self.zoom_shop.on_close = function()
	        if self.sound_whistle then
	            self.sound_whistle:StopSound()
	        end
	        
	        if self.sound_whistle_idle then
	            self.sound_whistle_idle:StopSound()
	        end
	        
	        if self.WhistleSoundAction then
	            self.WhistleSoundAction:Kill()
	            self.WhistleSoundAction = nil
	        end
	        
	        if self.anim_shop then
	            self.timer:Add( function()
	                                self.anim_shop:StopAnimation('action')
	                            end,
	                            ZOOM_ZONE_APPEARING_TIME)
	        end
	    end
	    ---------------------
	    
	    local function on_apply_vase_with_water(e)
	        ObjectVisible(e.target, false)
	        
	        if e.save then
	            ObjectOpacity('z_shop_water', 1)
	            ObjectVisible('area_apply_zs_head_of_ringbird', true)
	        else
	            local time = 3
	            
                self.vase_video = CreateVideoEntity('data/Video/Scenes/08_street/08_z_shop_vase.ogg', '', false)
                self.vase_video:AttachTo(Object('z_shop_bg'))
                self.vase_video:SetZ(20)
                self.vase_video:SetXY(-112, -90)
                self.vase_video:SetLoop(false)
                self.vase_video:SetSoftEdges(true)
                self.vase_video:PlayVideo()
                
                MakeSoundEntity('08_apply_vase_with_water'):PlaySound(false)
	            
	            self.mouseBlocker:Push()
	            self.timer:Add( function()
	                                self.mouseBlocker:Pop()
	                                ObjectOpacity('z_shop_water', 1)
	                                
                                    self.vase_video:SetHideOnStop(true)
                                    self.vase_video:StopVideo()
                                    
                                    ObjectVisible('area_apply_zs_head_of_ringbird', true)
	                            end,
	                            time)
	        end
	    end
	    ---------------------
	    
	    local function on_apply_head_of_ringbird(e)
	        ObjectVisible(e.target, false)
	        
	        if e.save then
	            ObjectOpacity('z_shop_head', 1)
	            ObjectVisible('area_apply_zs_matches', true)
	        else
	            local time = 0.5
	            ObjectOpacity('z_shop_head', 1, time)
	            MakeSoundEntity('08_apply_head_of_ringbird'):PlaySound(false)
	            
	            self.timer:Add( function()
	                                ObjectVisible('area_apply_zs_matches', true)
	                            end,
	                            time)
	        end
	    end
	    ---------------------
	    
	    local function on_apply_matches(e)
	        ObjectVisible(e.target, false)
	        
	        if e.save then
	            ObjectOpacity('z_shop_door_open', 1)
	            ObjectVisible('area_link_13', true)
	            
	            self.zoom_shop:Disable()
	        else
	            local time = 0.5
	            local openDoorDelay = 2
	            
	            self.anim_shop = AnimationBundle(Loader_08_Zoom_Shop_Animations(Object('z_shop_bg')))
	            self.anim_shop:PlayAnimation('action')
	            self.anim_shop:GetAnimation('action'):ChangeOpacity(0, 1, time)
	            self.anim_shop:GetAnimation('action'):SetClippingRect(self.zoom_shop:GetClippingInfo())
	            
	            self.sound_whistle = MakeSoundEntity('08_whistle')
	            self.sound_whistle:PlaySound(false)
	            
	            self.sound_whistle_idle = MakeSoundEntity('08_whistle_idle')
	            
	            self.WhistleSoundAction = self.timer:Add(function()
	                                                        self.WhistleSoundAction = nil
	                                                        --self.sound_whistle:StopSound()
	                                                        self.sound_whistle_idle:PlaySound(true)
	                                                     end,
	                                                     10)
	            
	            self.mouseBlocker:Push()
	            self.timer:Add( function()
	                                local openDoorTime = 0.5
	                                ObjectOpacity('z_shop_door_open', 1, openDoorTime)
	                                MakeSoundEntity('08_open_shop_door'):PlaySound(false)
	                                
	                                self.timer:Add( function()
	                                                    self.mouseBlocker:Pop()
	                                                    
                                                        ObjectVisible('area_link_zs_13', true)
                                                        ObjectVisible('area_link_13',    true)
                                                        
                                                        self.zoom_shop:Disable()
                                                    end,
                                                    openDoorTime)
	                            end,
	                            openDoorDelay)
	        end
	    end
	    ---------------------
	    
	    RegisterToolApplyInfo('10_vase_with_water',  'area_apply_zs_vase_with_water',  on_apply_vase_with_water,  'BBT_08_NEED_APPLY_VASE_WITH_WATER')
	    RegisterToolApplyInfo('12_head_of_ringbird', 'area_apply_zs_head_of_ringbird', on_apply_head_of_ringbird, 'BBT_08_NEED_APPLY_HEAD_OF_RINGBIRD')
	    RegisterToolApplyInfo('11_matches',          'area_apply_zs_matches',          on_apply_matches,          'BBT_08_NEED_APPLY_MATCHES')
	end
end

function l_08_street:create_cutscene()
    if HasActionCompletedState('cutsceneShown') then
        self:create_comics_dupin()
    else
        do
            self.cutscene_video = CreateVideoEntity('data/Video/Scenes/08_street/08_cutscene.ogg', '', false)
            self.cutscene_video:AttachTo(Object('bg'))
            self.cutscene_video:SetZ(100)
            self.cutscene_video:SetXY(0, 0)
            self.cutscene_video:SetLoop(false)
            self.cutscene_video:SetOnFirstFrame()
        end
        
        local delay = 0.25
        local time  = self.cutscene_video:GetDuration()
        
        SetCutSceneMode(delay + time)
        
        self.timer:Add( function()
                            self.cutscene_video:PlayVideo()
                            MakeSoundEntity('08_cutscene'):PlaySound(false)
                            
                            local fadeTime = 0.2
                            
                            self.timer:Add( function()
                                                self.cutscene_video:ChangeOpacity(1, 0, fadeTime)
                                                
                                                self.timer:Add( function()
                                                                    AddActionCompletedState('cutsceneShown')
                                                                    
                                                                    self:create_comics_dupin()
                                                                end,
                                                                fadeTime)
                                            end,
                                            time - fadeTime)
                        end,
                        delay)
    end
end

function l_08_street:create_comics_dupin()
    local comics_name = '08_comics_dupin'
    
    local comics_finish = function(save)
        if save then
        else
        end
    end
    
    if IsComicsShown(comics_name) then
        comics_finish(true)
    else
        local comics = l_08_street_comics_dupin()
		comics:LoadData(play_field)
		
        local c = Comics(comics_name,
                            CreateComicsVideoFrame('Dupin',  'C_08_DUPIN_01', nil, {path='data/Video/Scenes/08_street/C_08_DUPIN_01.ogg', isAlpha=true, x=614}, 'comics_bg')
                            )
        
        Object('comics_bg'):GetAnimation():SetColor('0x01FFFFFF')
        
        c.on_finish = function()
            comics_finish(false)
        end
        
        self.mouseBlocker:Push()
        self.timer:Add( function()
                            self.mouseBlocker:Pop()
                            c:Start()
                        end,
                        0.25)
    end
end

function l_08_street:OnUpdate(dt)
end

function l_08_street:OnAllItemsFound()
end

function l_08_street:OnObjectMouseEnter(object)
end

function l_08_street:OnObjectMouseLeave(object)
end

function l_08_street:OnScreenObjectMouseDown(object, key)
end

function l_08_street:OnObjectMouseDownProcessed(is_wrong_click)
end

function l_08_street:OnMouseMove(previous_pos, current_pos)
end

function l_08_street:OnObjectMouseUp(object)
end

function l_08_street:OnObjectFound(object)
end

function l_08_street:OnToolFound(tool)
end

function l_08_street:OnToolApply(tool, object)
end

function l_08_street:OnToolAddToInventory(tool)
end

function l_08_street:OnObjectReachPanel(object)
end

function l_08_street:OnButtonPress(title)
end

function l_08_street:OnSetTool(tool)
end

function l_08_street:OnLoaded()
end

function l_08_street:OnDestroy()
end

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function l_08_street:LoadData(screen)
	local anim
	anim = CreateAnimation('data/Texture/Scenes/08_street/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_06',anim,512,700,100,0,128,17)
	
	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_09',anim,949,482,100,0,13,15)
	
	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,291,469,100,0,13,15)
	
	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_13',anim,595,447,100,0,13,15)
	
	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_16',anim,767,332,100,0,12,15)
	
	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_zoom_armory',anim,722,460,100,0,12,15)
	
	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_zoom_shop',anim,593,447,100,0,13,15)
	
	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_gate',anim,165,473,100,0,0.8,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_link_08a',anim,165,473,100,0,0.8,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_zoom_doctor_door',anim,949,482,100,0,13,15)
	
	anim = CreateAnimation('data/Texture/Scenes/08_street/main/layers/layer_gate_close.png',0,0,50,96,1,0)
	anim:SetHotSpot(25,48)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_gate_close',anim,164,482,52,0,1,1)
	
	anim = CreateAnimation('data/Texture/Scenes/08_street/main/layers/layer_gate_open.png',0,0,58,102,1,0)
	anim:SetHotSpot(29,51)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_gate_open',anim,168,485,53,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_click_scroll_comics',anim,512,384,210,0,128,96)
	
	anim = CreateAnimation('data/Texture/Scenes/08_street/main/layers/layer_dupin_with_scroll.png',0,0,624,768,1,0)
	anim:SetHotSpot(312,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_dupin_with_scroll',anim,312,384,200,0,1,1)
	
	anim = CreateAnimation('data/Texture/Scenes/08_street/main/layers/layer_scroll.png',0,0,74,74,1,0)
	anim:SetHotSpot(37,37)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_scroll',anim,86,41,70,0,1,1)
	
	anim = CreateAnimation('data/Texture/Common/area_round.png',0,0,128,128,1,0)
	anim:SetHotSpot(82,74)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_click_scroll',anim,84.03,43.3,1000,0,4.4,3.43)
	
	anim = CreateAnimation('data/Texture/Scenes/08_street/main/layers/layer_door_doctor.png',0,0,90,124,1,0)
	anim:SetHotSpot(45,62)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_door_doctor',anim,958,500,90,0,1,1)
	
	anim = CreateAnimation('data/Texture/Scenes/08_street/main/layers/layer_door_hotel.png',0,0,27,71,1,0)
	anim:SetHotSpot(13,35)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_door_hotel',anim,279,464,90,0,1,1)
	
	anim = CreateAnimation('data/Texture/Scenes/08_street/main/layers/layer_door_shop.png',0,0,18,35,1,0)
	anim:SetHotSpot(9,17)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_door_shop',anim,606,471,90,0,1,1)
	
end
-- CLEAR_ON_SAVE_END
