dofile('data/Scenes/1_Booth_tv_set.lua')
dofile('data/Scenes/1_Booth_Anim_sea.lua')
dofile('data/Scenes/Comics/1_Booth_Use_Active_Zone.lua')
dofile('data/Scenes/Comics/1_Booth_Use_Zoom_Zone.lua')
dofile('data/Scenes/Comics/1_Booth_Use_Hint.lua')
dofile('data/Scenes/1_Booth_Anim_phone_calling.lua')

PATH_MINIGAME_1_CARD            = 'data/Scenes/MiniGames/1_Booth_Cards.lua'

PATH_COMICS_1_END_CARDS         = 'data/Scenes/Comics/HelpersComicsOneReplicHeroes.lua'
PATH_COMICS_1_NO_KEY            = 'data/Scenes/Comics/HelpersComicsOneReplicHeroes.lua'
PATH_COMICS_1_NO_REMOTE_CONTROL = 'data/Scenes/Comics/HelpersComicsOneReplicHeroes.lua'
PATH_COMICS_1_NEWS              = 'data/Scenes/Comics/HelpersComicsOneReplicHeroes.lua'
PATH_COMICS_1_ON_WIN            = 'data/Scenes/Comics/HelpersComicsOneReplicHeroes.lua'
PATH_COMICS_1_KEY_FOUND			= 'data/Scenes/Comics/1_Booth_Click_Inventory.lua'
PATH_COMICS_1_USE_KEY   		= 'data/Scenes/Comics/1_Booth_Use_Key.lua'
PATH_COMICS_1_USE_ACTIVE_ZONE	= 'data/Scenes/Comics/1_Booth_Use_Active_Zone.lua'
PATH_COMICS_1_TASK_LIST			= 'data/Scenes/Comics/1_Booth_Item_List.lua'
PATH_COMICS_1_ZOOM_ZONE			= 'data/Scenes/Comics/1_Booth_Use_Zoom_Zone.lua'
PATH_COMICS_1_HINT				= 'data/Scenes/Comics/1_Booth_Use_Hint.lua'
PATH_COMICS_1_ON_SHOWN          = 'data/Scenes/Comics/HelpersComicsReplic.lua'
PATH_COMICS_1_ON_TV_SET         = 'data/Scenes/Comics/HelpersComicsOneReplicHeroes.lua'

PATH_COMICS_1_TURN_TV_SET       = 'data/Scenes/Comics/HelpersComicsOneSMS.lua'

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad(screen:GetName())
    
    local pf = play_field
    local level = pf:GetLevelScreen()
    local phone = level:GetPhone()
    if not GameStateExists('SetTvSet') then
        AddGameState('SetTvSet', 'false')
    end
    game_state.show_tutorial = false
    
    ---------------------------------------------------------------------------------------------
    NotesFound('Notes_1')
    ---------------------------------------------------------------------------------------------
    level:AddTaskSafe(CreateTask('NEWS', '', 'news'))	
    level:AddTaskSafe(CreateTask('CARDS', '', 'cards'))
    level:AddTaskSafe(CreateTask('FISHING_LINE', '', 'fishing_line'))
    level:AddTaskSafe(CreateTask('CAMERA', '', 'camera'))
    AddRandomTasks(11,
                   CreateTask('CROCODILE', '', 'crocodile'), 
                   CreateTask('CANDY', '', 'candy'),
                   CreateTask('WATCH', '', 'watch'),
                   CreateTask('BALL', '', 'ball'),
                   CreateTask('BAT', '', 'bats'),
                   CreateTask('BUTTON', '', 'button'),
                   CreateTask('DICE', '', 'dice'),
                   CreateTask('FISH', 'FISH', 'fish2'),
                   CreateTask('GLOVES', '', 'gloves'),
                   CreateTask('GUITAR', '', 'guitar'),
                   CreateTask('HAIRBRUSH', '', 'hairbrush'),
                   CreateTask('HIGHLIGHTER', '', 'pen'),
                   CreateTask('PEN', '', 'pen_2'),
                   CreateTask('PENCIL', '', 'pencil'),
                   CreateTask('QUESTION_MARK', '', 'question_mark'),
                   CreateTask('PING_PONG_PADDLES', '', 'racket'),
                   CreateTask('SCISSORS', '', 'scissors'),
                   CreateTask('TELESCOPE', '', 'spy_glass'),
                   CreateTask('THERMOMETER', '', 'thermometer'),                   
				   CreateTask('UMBRELLA', '', 'umbrella'),
				   CreateTask('SPIDER', '', 'spider'),
				   CreateTask('LIGHTER', '', 'zippo'),
				   CreateTask('COIN', '', 'coin'),
				   
				   CreateTask('BUTTERFLY', 'BUTTERFLIES', 'butterfly_2', 'butterfly_3'),
				   CreateTask('DRAGONFLY', '', 'butterfly'),
				   CreateTask('BINOCULARS', 'BINOCULARS', 'pair_of_glasses', 'pair_of_glasses_2'),
				   CreateTask('FEATHER', 'FEATHERS', 'feather', 'feather_2'),
				   CreateTask('PIPE', '', 'pipe'),
				   CreateTask('SKULL', '', 'skull')
                   )
    if IsSkipTutorial() then                   
        pf:IgnoreOnTestPoint('fishing_line')                   
    end
    ---------------------------------------------------------------------------------------------
    zone_bucket = CreateZoomZone('close_zone_bucket',
                                 'pixel_open_bucket',
                                 'bg_bucket',
                                 'key_layer',
                                 'key')
    ---------------------------------------------------------------------------------------------
    zone_box = CreateZoomZone('close_zone_box',
                              '',
                              'bg_box',
                              'cards',
                              'remote_control',
                              'remote_control_layer',
							  'fish2',
							  'zippo',
							  'coin',
							  'spider'
                             )
    zone_box.OnHidden = function()
--[[    
        if phone:HasTool(pf:GetObject('remote_control_tool')) then
            game_state.chain_on_turn_tvset.Play()
        end
]]
    end
    ---------------------------------------------------------------------------------------------
    zone_tvset = CreateZoomZone('close_zone_tvset',
                                'pixel_open_tvset',
                                'bg_tvset',
                                'pixel_action_remote_control_',
                                'news',
                                'crocodile',
                                'pen_2',
                                'candy',
                                'watch'
                               )
    pf:GetObject('pixel_action_remote_control_'):SetMaxOpacity(0.1)
    zone_tvset.RemoveObject('news')
    local text_news_1 = screen:GetObject('text_news_1')
    text_news_1:SetOpacity(0)
    text_news_1:SetXY(text_news_1:GetX() + zone_tvset.offset_x, text_news_1:GetY() + zone_tvset.offset_y)
    zone_tvset.AddObject('text_news_1')
    local text_news_2 = screen:GetObject('text_news_2')
    text_news_2:SetOpacity(0)
    text_news_2:SetXY(text_news_2:GetX() + zone_tvset.offset_x, text_news_2:GetY() + zone_tvset.offset_y)
    zone_tvset.AddObject('text_news_2')
    
    zone_tvset.RemoveObject('text_news_1')
    zone_tvset.RemoveObject('text_news_2')
    pf:GetObject('text_news_1'):GetAnimation():SetColor('0xFFFFFFFF')
    pf:GetObject('text_news_2'):GetAnimation():SetColor('0xFFFFFFFF')
    ---------------------------------------------------------------------------------------------
    local iClippingX        = 485
    local iClippingY        = 380
    local iClippingWidth    = 295
    local iClippingHeight   = 70
    local x_news_1      = text_news_1:GetX()
    local width_news_1  = text_news_1:GetAnimation():GetWidth()
    local x_news_2      = x_news_1 + width_news_1
    local width_news_2  = text_news_2:GetAnimation():GetWidth()
    text_news_1:SetClippingRect(iClippingX, iClippingY, iClippingWidth, iClippingHeight)
    text_news_2:SetClippingRect(iClippingX, iClippingY, iClippingWidth, iClippingHeight)
    text_news_1:SetX( x_news_1 + iClippingWidth )
    text_news_2:SetX( x_news_1 + width_news_1 + iClippingWidth/2 + 129 --[[-6]]) -- magic number для соединения
    text_news_2:SetY( text_news_1:GetY() )
    
    local time_news = 40
    local max_width_news = width_news_1 + width_news_2 + iClippingWidth
    local af_news_1 = CreateAnimationEffector()
    af_news_1:AttachTo( text_news_1 )
    af_news_1:SetKey(_TRACK_X, 0.0,        text_news_1:GetX())
    af_news_1:SetKey(_TRACK_X, time_news,  text_news_1:GetX() - max_width_news)
    af_news_1:SetMode(HGEANIM_FWD + _ANIM_LOOP)
    
    local af_news_2 = CreateAnimationEffector()
    af_news_2:AttachTo( text_news_2 )
    af_news_2:SetKey(_TRACK_X, 0.0,        text_news_2:GetX())
    af_news_2:SetKey(_TRACK_X, time_news,  text_news_2:GetX() - max_width_news)
    af_news_2:SetMode(HGEANIM_FWD + _ANIM_LOOP)

    ---------------------------------------------------------------------------------------------
    local TvSetOn = false
    if HasGameState('SetTvSet', 'true') then
        TvSetOn = true
    end
    local CompositionInclusionsNews = createCompositionnovosti1_BG(TvSetOn)
    CompositionInclusionsNews:SetHotSpot(320, 240)
    CompositionInclusionsNews:AttachTo(pf:GetObject('bg_tvset'))
    CompositionInclusionsNews:SetZ(1)
    CompositionInclusionsNews:SetOpacity(0)
    
    game_state.sound_tv_set = MakeSoundEntity('01_tv_set_work')
    game_state.sound_tv_set:AttachTo(screen)
    
    local DefaultSetVisible = zone_tvset.SetVisible
    zone_tvset.SetVisible = function(is_visible)
        DefaultSetVisible(is_visible)   
        
        if is_visible then
            if HasGameState('SetTvSet', 'true') then
                CompositionInclusionsNews:Resume()
                CompositionInclusionsNews:ChangeOpacity(0, 1, 0.25)
                
                game_state.sound_tv_set:Play(true)
            end
        else
            if HasGameState('SetTvSet', 'true') then
                CompositionInclusionsNews:Pause()
                CompositionInclusionsNews:ChangeOpacity(1, 0, 0.25)
                
                game_state.sound_tv_set:StopSound()
            end
        end
    end -- zone_tvset.SetVisible = function(is_visible)
    local obj_anim_mini_tvset = play_field:GetObject('tvset_mini_loop')
    obj_anim_mini_tvset:SetOpacity(0)
    ---------------------------------------------------------------------------------------------
    local anim_phone_calling = createComposition_phone_calling()
    anim_phone_calling:AttachTo(screen)
    anim_phone_calling:SetZ(185)
    anim_phone_calling:SetCyclic(true)
    game_state.anim_phone_calling = anim_phone_calling
    
    game_state.sound_call_phone = MakeSoundEntity("01_call_phone")
    game_state.sound_call_phone:AttachTo(screen)
    game_state.sound_call_phone:Play(true)
    ---------------------------------------------------------------------------------------------
    local apply_action_key = function(save)
                                RegisterZoomZone(zone_box, 'drawer_layer_pixel')
                                zone_box.SetOffsetHighlight(-70, -40)
                                local drawer = pf:GetObject('drawer_layer')
                                
                                if save then
                                    drawer:SetX(drawer:GetX() - 50)
                                    if pf:HasObject('drawer_layer_pixel') then
                                        local drawer_pixel = pf:GetObject('drawer_layer_pixel') 
                                        drawer_pixel:SetX(drawer_pixel:GetX() - 50)
                                    end
                                else
                                    local af = CreateAnimationEffector()
                                    af:AttachTo(drawer)
                                    af:SetKey(_TRACK_X, 0.0, drawer:GetX()        )
                                    af:SetKey(_TRACK_X, 0.3, drawer:GetX() - 50   )
                                    af:Play()
                                
                                    if pf:HasObject('drawer_layer_pixel') then
                                        local drawer_pixel = pf:GetObject('drawer_layer_pixel')
                                    
                                        local af = CreateAnimationEffector()
                                        af:AttachTo(drawer_pixel)
                                        af:SetKey(_TRACK_X, 0.0, drawer:GetX()        )
                                        af:SetKey(_TRACK_X, 0.3, drawer:GetX() - 50   )
                                        af:Play()
                                    end
                                    
                                    PlaySound("01_move_box")
                                end
                                
                                pf:IgnoreOnTestPoint('pixel_action_key')
                             end
    game_state.apply_action_key = apply_action_key;
    local photo_key = CreatePhotoZone('key', 'KEY', 'key_photo', nil, 'pixel_action_key', apply_action_key)
    level:GetTask('key'):SetUse(true)
    ---------------------------------------------------------------------------------------------
    local photo_action_box = function(save)
                                if not save then
                                    TimerDo(pf:GetTimer(), 0.9, function()
                                                                    game_state.chain_on_turn_tvset.Play()
                                                               end )
                                end
                             end
    local apply_action_box = function(save)
                              SetGameState('SetTvSet', 'true')
                              
                              if save then
                                zone_tvset.AddObject('news')
                                zone_tvset.AddObject('text_news_1')
                                zone_tvset.AddObject('text_news_2')
                                
                                af_news_1:Play()
                                af_news_2:Play()
                              else
                                CompositionInclusionsNews:Play()
                                CompositionInclusionsNews:Show()
                                CompositionInclusionsNews:SetOpacity(1)
                                TimerDo(pf:GetTimer(), 1.16666666666667, function()
                                                                            zone_tvset.AddObject('news')
                                                                            zone_tvset.AddObject('text_news_1')
                                                                            zone_tvset.AddObject('text_news_2')
                                                                            game_state.sound_tv_set:Play(true)
                                                                            
                                                                            if zone_tvset.IsVisible() then
                                                                                pf:GetObject('news'):ChangeOpacity(0, 1, ZOOM_ZONE_APPEARING_TIME)
                                                                                pf:GetObject('text_news_1'):ChangeOpacity(0, 1, ZOOM_ZONE_APPEARING_TIME)
                                                                                pf:GetObject('text_news_2'):ChangeOpacity(0, 1, ZOOM_ZONE_APPEARING_TIME)
                                                                            end
                                                                            TimerDo(pf:GetTimer(), ZOOM_ZONE_APPEARING_TIME, function()
                                                                                                                                af_news_1:Play()
                                                                                                                                af_news_2:Play()
                                                                                                                                game_state.chain_on_tv_set.Play()
                                                                                                                             end )
                                                                          end )
                              end                                                                       
                              obj_anim_mini_tvset:SetOpacity(1)
                              pf:GetObject('pixel_action_remote_control_'):SetOpacity(0)
                             end
    local photo_remote_control = CreatePhotoZoneEx('remote_control', 'remote_control_tool',
                                                   'REMOTE_CONTROL', 
                                                   'remote_control_photo', 
                                                   photo_action_box, 'pixel_action_remote_control_', apply_action_box)
    level:GetTask('remote_control'):SetUse(true)
    ---------------------------------------------------------------------------------------------
    pf:IgnoreOnTestPoint('guitar_layer')
    pf:IgnoreOnTestPoint('table_layer')
    pf:IgnoreOnTestPoint('tvset_mini_loop')
	pf:IgnoreOnTestPoint('scissors_layer')
	pf:IgnoreOnTestPoint('umbrella_stand')
    ---------------------------------------------------------------------------------------------
    pf:GetObject('suitcase_layer'):GetAnimation():SetColor('0xFFFFFFFF')
    pf:GetObject('suitcase_layer'):SetOpacity(0)
    pf:GetObject('fishing_line'):SetOpacity(0)
    local clickOnSuitcase = function(save)
        if save then
            pf:GetObject('suitcase_layer'):SetOpacity(1)
            if  level:IsTaskObject('fishing_line') then
                pf:GetObject('fishing_line'):SetOpacity(1)
            end
        else
            pf:GetObject('suitcase_layer'):ChangeOpacity(0, 1, 0.3)
            pf:GetObject('fishing_line'):ChangeOpacity(0, 1, 0.3)
            
            PlaySound('01_move_bag')
        end            
    end
    RegisterActiveObject('pixel_activate_suitcase', clickOnSuitcase, false, GetCursorArms())
    ---------------------------------------------------------------------------------------------
    local periodically_time_gull_start = 2
    local periodically_time_gull_end = 20
    
    local anim_sea = createCompositionyahta1_good_fon()
    anim_sea:AttachTo(screen)
    anim_sea:SetZ(85)
    anim_sea:SetCyclic(true)
    
    local sea_gull_1 = createComposition_chayka_1()
    sea_gull_1:AttachTo(screen)
    sea_gull_1:SetZ(86.1)
    PlayCompositionPeriodicallyVsRandDelay(sea_gull_1, periodically_time_gull_start, periodically_time_gull_end)
    
    local sea_gull_2 = createComposition_chayka_2()
    sea_gull_2:AttachTo(screen)
    sea_gull_2:SetZ(86.2)
    PlayCompositionPeriodicallyVsRandDelay(sea_gull_2, periodically_time_gull_start, periodically_time_gull_end)
    
    local sea_gull_3 = createComposition_chayka_3()
    sea_gull_3:AttachTo(screen)
    sea_gull_3:SetZ(86.3)
    PlayCompositionPeriodicallyVsRandDelay(sea_gull_3, periodically_time_gull_start, periodically_time_gull_end)
    
    local sea_maska = createComposition_maska()
    sea_maska:AttachTo(screen)
    sea_maska:SetZ(87)
    ---------------------------------------------------------------------------------------------
    if HasGameState(game_state.scene_path, 'input_telefon') then
        game_state.anim_phone_calling:Hide()
        game_state.sound_call_phone:Stop()
    else
        pf:GetLevelScreen():GetPhone():Hide()
    end        
	---------------------------------------------------------------------------------------------
	game_state.chain_key_found = RegisterComicsEx(function()
    												LoadComics(PATH_COMICS_1_KEY_FOUND)
                                                  end )
	---------------------------------------------------------------------------------------------
	game_state.chain_key_use = RegisterComics('COMICS_1_USE_KEY', function()
													LoadComics(PATH_COMICS_1_USE_KEY, 'COMICS_1_USE_KEY')
											   end)
											   
	game_state.chain_use_active_zone = RegisterComicsEx(function()
													        LoadComics(PATH_COMICS_1_USE_ACTIVE_ZONE, 'COMICS_1_USE_ACTIVE_ZONE')
											            end)
    game_state.chain_use_active_zone.OnHidden = function()
        if IsSkipTutorial() then
            OnObjectMouseDown( screen:GetObject('pixel_activate_suitcase') )
            TimerDo(play_field:GetTimer(), 0.3, function()
                                                    game_state.chain_task_list:Play()
                                                end )
        end
    end
											   
	game_state.chain_task_list = RegisterComicsEx(function()
													LoadComics(PATH_COMICS_1_TASK_LIST, 'COMICS_1_TASK_LIST')
											      end)
    game_state.chain_task_list.OnHidden = function()
        phone:UpdateTaskList()
        if IsSkipTutorial() then
            PlayRegisterComics('COMICS_1_ZOOM_ZONE')
        end
    end
											   
	RegisterComics('COMICS_1_ZOOM_ZONE', function()
													LoadComics(PATH_COMICS_1_ZOOM_ZONE, 'COMICS_1_ZOOM_ZONE')
											   end)
	game_state.chain_hint = RegisterComicsEx(function()
	                                            zone_bucket.SetVisible(true)
	
											    LoadComics(PATH_COMICS_1_HINT, 'COMICS_1_HINT')
											 end)
    game_state.chain_hint.OnHidden = function()
        phone:RechargeHint()
    end
    game_state.chain_news = RegisterComicsEx(function()
                                                    LoadComicsWithOneReplicHeroes(PATH_COMICS_1_NEWS, 'COMICS_1_BOOTH_AFTER_NEWS')
                                              end) 
    game_state.chain_news.OnHidden = function()
        OnWin()
    end

    game_state.chain_on_win = RegisterComicsEx(function()
                                                    LoadComicsWithOneReplicHeroes(PATH_COMICS_1_ON_WIN, 'COMICS_1_ON_WIN')
                                               end )
    game_state.chain_on_win.OnHidden = function()
        OnWinLevel()
    end
    
    game_state.chain_input_telefon = RegisterComicsEx(function()
                                                            LoadComics('data/Scenes/Comics/1_Booth_Input_Telefon.lua')
                                                      end )
    
    game_state.chain_on_shown = RegisterComicsEx(function()
                                                            LoadComics(PATH_COMICS_1_ON_SHOWN, 'COMICS_1_BOOTH_START_RING')
                                                            local sms = CreateOneSMS('COMICS_1_BOOTH_START_RING', 1)
                                                      end )
    game_state.chain_on_shown.OnHidden = function()
        ShowTutorial()
    end
    game_state.chain_on_turn_tvset = RegisterComicsEx(function()
                                                            LoadComics(PATH_COMICS_1_TURN_TV_SET, 'COMICS_1_BOOTH_TURN_TV_SET')
                                                            CreateOneSMS('COMICS_1_BOOTH_TURN_TV_SET', 1)
                                                      end )
    game_state.chain_end_cards = RegisterComicsEx(function()
                                                            LoadComicsWithOneReplicHeroes(PATH_COMICS_1_END_CARDS, 'COMICS_1_BOOTH_END_CARDS')
                                                      end )
    game_state.chain_end_cards.OnHidden = function()
        OnWin()
    end
    ---------------------------------------------------------------------------------------------
    game_state.chain_on_tv_set = RegisterComicsEx(function()
                                                           LoadComicsWithOneReplicHeroes(PATH_COMICS_1_ON_TV_SET, 'COMICS_1_ON_TV_SET')
                                                      end )
    game_state.chain_on_tv_set.OnHidden = function()
        NotesFound('Notes_2')
    end
                                                      
    game_state.chain_no_remote_control = RegisterComicsEx(function()
                                                    LoadComicsWithOneReplicHeroes(PATH_COMICS_1_NO_REMOTE_CONTROL, 'COMICS_1_BOOTH_NO_REMOTE_CONTROL')
                                                 end )
    SetHintComicsPhotoZoneEx(photo_remote_control, game_state.chain_no_remote_control)
    
    game_state.chain_no_key = RegisterComicsEx(function()
                                                    LoadComicsWithOneReplicHeroes(PATH_COMICS_1_NO_KEY, 'COMICS_1_BOOTH_NO_KEY')
                                                 end )
    SetHintComicsPhotoZoneEx(photo_key, game_state.chain_no_key)
    ---------------------------------------------------------------------------------------------
    if not GameStateExists('FillingSkip') then
        AddGameState('FillingSkip', '')
        pf:GetLevelScreen():GetPhone():RechargeHint()
    end
    ---------------------------------------------------------------------------------------------
    RegisterMiniGame(PATH_MINIGAME_1_CARD, function()
                                                LoadMiniGames(PATH_MINIGAME_1_CARD)
                                            end )
    ---------------------------------------------------------------------------------------------
end

function OnSceneFree()
    FreeData()
end

function FlyPhone()
    local phone = play_field:GetLevelScreen():GetPhone() 
    phone:Show()
    local time_fly_phone = 0.5
    
    local af = CreateAnimationEffector()
    af:AttachTo( phone )
    af:SetMode(_ANIM_NOLOOP)
    af:SetKey(_TRACK_X, 0, 484)
    af:SetKey(_TRACK_Y, 0, 572)
    af:SetKey(_TRACK_X, time_fly_phone, phone:GetX() )
    af:SetKey(_TRACK_Y, time_fly_phone, phone:GetY() )
    af:SetKey(_TRACK_S, 0, 0.1)
    af:SetKey(_TRACK_S, time_fly_phone, 1)
    af:Play()
    
    game_state.anim_phone_calling:SetOpacity(0)
    game_state.sound_call_phone:Stop()
    play_field:IgnoreOnTestPoint('pixel_phone_calling')
    
    TimerDo(play_field:GetTimer(), time_fly_phone + 0.1, function()
                                                            game_state.chain_on_shown:Play()
                                                            AddGameState(game_state.scene_path, 'input_telefon')
                                                        end )
end

function ShowTutorial()
    if game_state.show_tutorial == false then
        local screen = load_screen('data/Lua/Screens/DialogTutorial.lua')
        screen:SetLayer(50)
        screen:SetXY(120, 0)
        panel:SetAllowInput(false)
                
        play_field:Stop()
        play_field:GetLevelScreen():Stop()
        
        game_state.show_tutorial = true
    end
end

function OnScreenShown(fade_out)
    if fade_out then
        local time_start_tutorial = 5
        TimerDo(play_field:GetTimer(), time_start_tutorial, function()
                                                                local phone = play_field:GetLevelScreen():GetPhone()
                                                                if phone:IsHidden() then
                                                                    game_state.chain_input_telefon.Play()                
                                                                end
                                                            end )
        if game_state.chain_on_shown.played and GameStateExists('DialogTutorial') == false and not phone:IsHidden() then
            ShowTutorial()
        end
    end --  if fade_out then
end

function OnHiddenComics(comics)
	if comics == 'COMICS_1_ZOOM_ZONE' and IsSkipTutorial() then
		game_state.chain_hint.Play()
	end
end

function OnWin()
    if play_field:GetLevelScreen():IsCompleteLevel() and
       game_state.chain_news.played and
       game_state.chain_end_cards.played
    then
        game_state.chain_on_win:Play()
    end
end

function OnUpdate(dt)
    DefaultOnUpdate(dt)
    
    if phone:IsHidden() then
        SetCursor(GetCursorArrow())
    end
end

function OnLose()
end

function OnExit()
end

function OnMinigameCompleted()
    DisableZoomZoneRequest(zone_box)
    game_state.chain_end_cards.Play()
end

function OnObjectMouseEnter(object)
    DefaultOnObjectMouseEnter(object)
end

function OnObjectMouseLeave(object)
    DefaultOnObjectMouseLeave(object)
end

function OnButtonMouseEnter(title)
end

function OnButtonMouseLeave(title)
end

function OnObjectMouseDown(object)
    obj_name = object:GetName()
    local pf = play_field
    local is_wrong_click = true
    local phone = pf:GetLevelScreen():GetPhone()
    
    if phone:IsHidden() then
        if obj_name == 'pixel_phone_calling' then
            FlyPhone()
            is_wrong_click = false
        end
        return is_wrong_click
    end
    
    if GameStateExists('DialogTutorial') == false then
        is_wrong_click = false
        return is_wrong_click
    end
    
    is_wrong_click = DefaultOnObjectMouseDown(object)
    
    return is_wrong_click
end

function OnObjectMouseUp(object)
end

function OnObjectFound(object)
    DefaultOnObjectFound(object)

    if object:GetName() == 'cards' then
        PlayRegisterMiniGame(PATH_MINIGAME_1_CARD)
    end
end

function OnToolFound(tool)
    if tool:GetName() == 'key' then
        if HasGameState('TutorialEnabled', 'true') then
            TimerDo(play_field:GetTimer(), 1.15, function()
                                                    game_state.chain_key_found.Play()
                                                end )
        end
    end
end

function OnToolApply(tool, object)
    local tool_applied = DefaultOnToolApply(tool, object)
end

function OnObjectReachPanel(object)
    DefaultOnObjectReachPanel(object)
    
    if object:GetName() == 'news' then
        game_state.chain_news.Play()
    end
end

function OnPhotographing()
    DefaultOnPhotographing()
end

function OnButtonPress(title)
    DefaultOnButtonPress(title)
end

function OnMouseMove(previous_pos, current_pos)
end

function OnSetTool(tool)
end

-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData(screen)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/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,70,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/button.png',0,0,24,35,1,0)
	anim:SetHotSpot(12,17)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('button',anim,572,58,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/camera.png',0,0,64,67,1,0)
	anim:SetHotSpot(32,33)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('camera',anim,690,560,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/dice.png',0,0,51,23,1,0)
	anim:SetHotSpot(25,11)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('dice',anim,509,515,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/gloves.png',0,0,65,48,1,0)
	anim:SetHotSpot(32,24)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('gloves',anim,245,419,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/hairbrush.png',0,0,119,45,1,0)
	anim:SetHotSpot(59,22)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('hairbrush',anim,398,572,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/pen.png',0,0,74,31,1,0)
	anim:SetHotSpot(37,15)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('pen',anim,329,581,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/pencil.png',0,0,53,21,1,0)
	anim:SetHotSpot(26,10)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('pencil',anim,504,551,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/question_mark.png',0,0,21,39,1,0)
	anim:SetHotSpot(10,19)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('question_mark',anim,981,362,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/racket.png',0,0,153,97,1,0)
	anim:SetHotSpot(76,48)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('racket',anim,457,737,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/ring.png',0,0,29,25,1,0)
	anim:SetHotSpot(14,12)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('ring',anim,953,443,222,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/scissors.png',0,0,84,71,1,0)
	anim:SetHotSpot(42,35)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('scissors',anim,900,756,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/spy_glass.png',0,0,111,42,1,0)
	anim:SetHotSpot(55,21)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('spy_glass',anim,343,538,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/thermometer.png',0,0,18,59,1,0)
	anim:SetHotSpot(9,29)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('thermometer',anim,739,217,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/umbrella.png',0,0,71,210,1,0)
	anim:SetHotSpot(35,105)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('umbrella',anim,966,683,205,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/umbrella_stand.png',0,0,90,161,1,0)
	anim:SetHotSpot(45,80)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('umbrella_stand',anim,973,692,290,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('pixel_open_bucket',anim,670,707,100,0,12,15)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomBucket/bg_bucket.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('bg_bucket',anim,512,384,500,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomBucket/key.png',0,0,94,48,1,0)
	anim:SetHotSpot(47,24)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('key',anim,546,470,505,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('pixel_action_key',anim,937,529,205,0,9,10)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Layers/guitar_layer.png',0,0,54,120,1,0)
	anim:SetHotSpot(27,60)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('guitar_layer',anim,382,442,120,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('pixel_open_box',anim,818,518,200,0,7,9)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomBox/bg_box.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('bg_box',anim,512,384,800,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Layers/spy_glass_layer.png',0,0,72,28,1,0)
	anim:SetHotSpot(36,14)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('spy_glass_layer',anim,308,547,120,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Layers/table_layer.png',0,0,122,164,1,0)
	anim:SetHotSpot(61,82)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('table_layer',anim,964,519,200,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Layers/drawer_layer.png',0,0,144,155,1,0)
	anim:SetHotSpot(72,77)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('drawer_layer',anim,987,521,150,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Layers/drawer_layer.png',0,0,144,155,1,0)
	anim:SetHotSpot(72,77)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('drawer_layer_pixel',anim,987,521,155,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('pixel_open_tvset',anim,515,212,152,0,12,8)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomTvset/bg_tvset.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bg_tvset',anim,512,384,500,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/bats.png',0,0,37,132,1,0)
	anim:SetHotSpot(18,66)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bats',anim,739,444,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomBucket/key_layer.png',0,0,71,34,1,0)
	anim:SetHotSpot(35,17)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('key_layer',anim,519,485,530,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('pixel_action_remote_control_',anim,509,320,518,0,44,25)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomTvset/news.png',0,0,115,35,1,0)
	anim:SetHotSpot(57,17)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('news',anim,632,235,520,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Animation/tvset_mini_loop.png',0,0,71,42,238,15)
	anim:SetHotSpot(36,21)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('tvset_mini_loop',anim,518,212,150,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomBox/remote_control.png',0,0,153,143,1,0)
	anim:SetHotSpot(76,71)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('remote_control',anim,595,508,820,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomBox/remote_control_layer.png',0,0,124,90,1,0)
	anim:SetHotSpot(62,45)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('remote_control_layer',anim,591,522,830,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomBox/cards.png',0,0,136,79,1,0)
	anim:SetHotSpot(68,39)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('cards',anim,689,516,830,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Photo/key_photo.jpg',0,0,177,298,1,0)
	anim:SetHotSpot(88,149)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('key_photo',anim,101,160,10,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Photo/remote_control_photo.jpg',0,0,177,298,1,0)
	anim:SetHotSpot(88,149)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('remote_control_photo',anim,98,157,10,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomBox/remote_control_tool.png',0,0,121,129,1,0)
	anim:SetHotSpot(60,64)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('remote_control_tool',anim,99,644,10,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomTvset/Items/crocodile.png',0,0,72,27,1,0)
	anim:SetHotSpot(36,13)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('crocodile',anim,304,474,550,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomTvset/Items/candy.png',0,0,54,22,1,0)
	anim:SetHotSpot(27,11)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('candy',anim,771,501,550,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomTvset/Items/pen.png',0,0,91,19,1,0)
	anim:SetHotSpot(45,9)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('pen_2',anim,546,191,550,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomTvset/Items/watch.png',0,0,57,35,1,0)
	anim:SetHotSpot(28,17)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('watch',anim,615,604,550,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomTvset/text_news_1.png',0,0,1640,26,1,0)
	anim:SetHotSpot(833,13)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('text_news_1',anim,1207,406,850,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomTvset/text_news_2.png',0,0,1640,26,1,0)
	anim:SetHotSpot(820,13)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('text_news_2',anim,1250,427,850,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomBox/coin.png',0,0,38,33,1,0)
	anim:SetHotSpot(19,16)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('coin',anim,419,174,810,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomBox/fish2.png',0,0,58,80,1,0)
	anim:SetHotSpot(29,40)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('fish2',anim,547,205,810,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomBox/spider.png',0,0,44,44,1,0)
	anim:SetHotSpot(22,22)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('spider',anim,519,596,810,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/ZoomBox/zippo.png',0,0,64,68,1,0)
	anim:SetHotSpot(32,34)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('zippo',anim,795,588,810,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Layers/suitcase_layer.png',0,0,149,85,1,0)
	anim:SetHotSpot(74,42)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('suitcase_layer',anim,637,484,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('pixel_activate_suitcase',anim,621,484,110,0,8,7)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/fishing_line.png',0,0,39,26,1,0)
	anim:SetHotSpot(19,13)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fishing_line',anim,602,500,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/pixel.jpg',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('pixel_phone_calling',anim,489,569,1900,0,10,5)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/guitar.png',0,0,91,210,1,0)
	anim:SetHotSpot(45,105)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('guitar',anim,382,411,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/butterfly.png',0,0,50,58,1,0)
	anim:SetHotSpot(25,29)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('butterfly',anim,481,378,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/butterfly_2.png',0,0,63,54,1,0)
	anim:SetHotSpot(31,27)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('butterfly_2',anim,587,378,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/butterfly_3.png',0,0,62,40,1,0)
	anim:SetHotSpot(31,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('butterfly_3',anim,436,530,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/feather.png',0,0,76,23,1,0)
	anim:SetHotSpot(38,11)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('feather',anim,518,166,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/feather_2.png',0,0,39,106,1,0)
	anim:SetHotSpot(19,53)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('feather_2',anim,863,353,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/pair_of_glasses.png',0,0,52,52,1,0)
	anim:SetHotSpot(26,26)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('pair_of_glasses',anim,609,587,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/pair_of_glasses_2.png',0,0,65,58,1,0)
	anim:SetHotSpot(32,29)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('pair_of_glasses_2',anim,873,269,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/pipe.png',0,0,138,27,1,0)
	anim:SetHotSpot(69,13)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('pipe',anim,463,642,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/1_booth_/Items/skull.png',0,0,47,61,1,0)
	anim:SetHotSpot(23,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('skull',anim,585,699,100,0,1,1)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
