function StartOnEnterComics()
    panel.nootebook_disable = false;
    
    on_enter_comics.on_finish = function()
        OnStartDialogCompleted();
    end
    on_enter_comics.SetVisible(true)
end

function OnStartDialogCompleted()
    AddNoteToNotebook('RESTAURANT');
    
    LinkScene(  'area_kitchen',
                'CursorRight',
                'data/Scenes/12_Restaurant_Kitchen_HO.lua',
                true);

    LinkScene(  'area_glass',
                'CursorGlass',
                'data/Scenes/11_Restaurant_MG.lua',
                false);
                
    LinkScene(  'area_Bar',
                'CursorGlass',
                'data/Scenes/11_Restaurant_Bar_HO.lua',
                true);
                
    RegisterMonologObject('area_piano', 'C_11_PIANO_HINT');
    RegisterMonologObject('area_table', 'C_11_TABLE_HINT');
    
    if HasGameState('MiniGameCompleted', '11_Restaurant_MG') then
        play_field:GetObject('area_glass'):SetVisible(false);
    end
end

function OnGiveRestoratorWine()
    play_field:GetObject('area_restorator'):SetVisible(false);
    play_field:GetObject('C_Golova_1'):ChangeOpacity(1., 0., ZOOM_ZONE_APPEARING_TIME);
    play_field:GetObject('C_Ruka_1'  ):ChangeOpacity(1., 0., ZOOM_ZONE_APPEARING_TIME);
    play_field:GetObject('C_Restorator_telo_2'):ChangeOpacity(1., 0., ZOOM_ZONE_APPEARING_TIME);
    
    local final_dialog = CreateComics('11_FinalDialog',
                                    CreateComicsFrame('Restorator', 'C_11_FINAL_1_RESTORATOR',   'Golova_2', 'C_Restorator_telo', 'Ruka_2'),
                                    CreateComicsFrame('Restorator', 'C_11_FINAL_1_RESTORATOR_A', 'Golova_2', 'C_Restorator_telo', 'Ruka_2'),
                                    CreateComicsFrame('Restorator', 'C_11_FINAL_1_RESTORATOR_B', 'Golova_2', 'C_Restorator_telo', 'Ruka_2'),
                                    CreateComicsFrame('Dupen',      'C_11_FINAL_2_DUPEN',        'body',     'head1'),
                                    CreateComicsFrame('Dupen',      'C_11_FINAL_3_DUPEN',        'body',     'head2'));
    if final_dialog then
        final_dialog.on_finish = function()
            game_state.parent_scene = nil;
            
            AddNoteToNotebook('RESTAURANT_2');
            AddNoteToNotebook('Witness_Restorator');
            
            TimerDoString('Compl()', ZOOM_ZONE_APPEARING_TIME, play_field:GetTimer());
        end
        final_dialog.SetVisible(true);
    else
        game_state.parent_scene = nil;
        
        AddNoteToNotebook('RESTAURANT_2');
        AddNoteToNotebook('Witness_Restorator');
        
        TimerDoString('Compl()', 2, play_field:GetTimer());
    end
end

function Compl()
    CompleteLevel('Restaurant');
end

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/11_Restaurant_Main.lua', 'quest')
    
    play_field:GetObject('area_restorator'):SetVisible(false);
    play_field:GetObject('Golova_2'       ):SetOpacity(0.);
    play_field:GetObject('Ruka_2'         ):SetOpacity(0.);
    play_field:GetObject('C_Restorator_telo_2'):SetOpacity(0.);
    
    on_enter_comics = CreateComics('11_OnEnter',
                                    CreateComicsFrame('Restorator', 'C_11_ENTER_1_RESTORATOR',   'C_Golova_1', 'C_Restorator_telo', 'C_Ruka_1'),
                                    CreateComicsFrame('Dupen',      'C_11_ENTER_2_DUPEN',        'body', 'head1'),
                                    CreateComicsFrame('Restorator', 'C_11_ENTER_3_RESTORATOR',   'C_Golova_1', 'C_Restorator_telo', 'C_Ruka_1'),
                                    CreateComicsFrame('Restorator', 'C_11_ENTER_3_RESTORATOR_A', 'C_Golova_1', 'C_Restorator_telo', 'C_Ruka_1'),
                                    CreateComicsFrame('Restorator', 'C_11_ENTER_3_RESTORATOR_B', 'C_Golova_1', 'C_Restorator_telo', 'C_Ruka_1'),
                                    CreateComicsFrame('Dupen',      'C_11_ENTER_4_DUPEN',        'body', 'head2'));
    
    if on_enter_comics then
        panel.nootebook_disable = true;
        TimerDoString('StartOnEnterComics()', 1.5, play_field:GetTimer())
    else
        OnStartDialogCompleted();
    end
    
    game_state.corkscrew_founded = HasGameState('ToolFound', '12_corkscrew');
    game_state.goblet_founded    = HasGameState('ToolFound', '12_goblet');
    game_state.wine_founded      = HasGameState('ToolFound', '12_wine_bottle');
    game_state.goblet_filled     = HasGameState('ToolFound', '12_wine_glass');
    
    if game_state.corkscrew_founded and game_state.goblet_founded and game_state.wine_founded and not game_state.goblet_filled then
        LinkScene(  'area_bar_mg',
                    'CursorGlass',
                    'data/Scenes/Minigames/11_wine.lua',
                    false);
    else
        play_field:GetObject('area_bar_mg'):SetVisible(false);
    end
    
    if game_state.goblet_filled then
        play_field:GetObject('C_Golova_1'         ):SetOpacity(1.);
        play_field:GetObject('C_Restorator_telo_2'):SetOpacity(1.);
        play_field:GetObject('C_Ruka_1'           ):SetOpacity(1.);
        
        play_field:GetObject('area_restorator'):SetVisible(true);
        
        RegisterToolApplyInfo('12_wine_glass', 'area_restorator',   nil,
                                                                    nil,
                                                                    OnGiveRestoratorWine,
                                                                    OnGiveRestoratorWine);
    end
end

function OnSceneFree(screen)
    DefaultOnSceneFree()
    FreeData(screen)
end

function OnUpdate(dt)
    DefaultOnUpdate(dt)
end

function OnAllItemsFound()
    DefaultOnAllItemsFound()
end

function OnLose()
    DefaultOnLose()
end

function OnExit()
    DefaultOnExit()
end

function OnClose()
    DefaultOnClose()
end

function OnObjectMouseEnter(object)
    DefaultOnObjectMouseEnter(object)
end

function OnObjectMouseLeave(object)
    DefaultOnObjectMouseLeave(object)
end

function OnObjectMouseDown(object)
    local is_wrong_click = not DefaultOnObjectMouseDown(object)
    local obj_name = object:GetName()
    local pf = play_field
    
    if obj_name == 'area_restorator' then
        ShowMonolog('C_11_NEED_GIVE_GOBLET', 'C_11_NEED_GIVE_GOBLET');
    end
    
    DefaultOnObjectMouseDownProcessed(is_wrong_click);
end

function OnObjectMouseUp(object)
    DefaultOnObjectMouseUp(object)
end

function OnObjectFound(object)
    DefaultOnObjectFound(object)
end

function OnToolFound(tool)
    DefaultOnToolFound(tool)
end

function OnToolApply(tool, object)
    DefaultOnToolApply(tool, object)
end

function OnObjectReachPanel(object)
    DefaultOnObjectReachPanel(object)
end

function OnButtonPress(title)
    DefaultOnButtonPress(title)
end

function OnMouseMove(previous_pos, current_pos)
    DefaultOnMouseMove(previous_pos, current_pos)
end

function OnSetTool(tool)
    DefaultOnSetTool(tool)
end

function LevelLoaded(level)
end

function OnSceneDestroy(playfield)
    DefaultOnSceneDestroy(playfield)
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/11_Restaurant/Zone_main/Layers/background.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('background',anim,512,384,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_kitchen',anim,880,404,101,0,6,6)
	local anim = CreateAnimation('data/Texture/Scenes/Common/Animations/candle.png',0,0,20,40,25,16)
	anim:SetHotSpot(10,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('candle',anim,288,429,102,0,0.7,0.7)
	local anim = CreateAnimation('data/Texture/Scenes/Common/Animations/candle.png',0,0,20,40,25,17)
	anim:SetHotSpot(10,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('candle2',anim,698,446,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/Animations/candle.png',0,0,20,40,25,16)
	anim:SetHotSpot(10,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('candle3',anim,819,452,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/Animations/candle.png',0,0,20,40,25,18)
	anim:SetHotSpot(10,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('candle4',anim,462,-2,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/Animations/candle.png',0,0,20,40,25,16)
	anim:SetHotSpot(10,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('candle5',anim,509,-2,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/Animations/candle.png',0,0,20,40,25,18)
	anim:SetHotSpot(10,20)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('candle6',anim,647,22,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_glass',anim,354,324,101,0,47,23)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_Bar',anim,667,348,103,0,15,15)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_bar_mg',anim,619,462,104,0,20,10)
	local anim = CreateAnimation('data/Texture/Characters/Restorator/Golova_1.png',0,0,140,207,1,0)
	anim:SetHotSpot(70,103)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('C_Golova_1',anim,335,172,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Characters/Restorator/Restorator_telo.png',0,0,354,556,1,0)
	anim:SetHotSpot(177,278)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('C_Restorator_telo',anim,308,490,111,0,1,1)
	local anim = CreateAnimation('data/Texture/Characters/Restorator/Restorator_telo.png',0,0,354,556,1,0)
	anim:SetHotSpot(177,278)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('C_Restorator_telo_2',anim,308,490,111,0,1,1)
	local anim = CreateAnimation('data/Texture/Characters/Restorator/Ruka_1.png',0,0,69,203,1,0)
	anim:SetHotSpot(34,101)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('C_Ruka_1',anim,456,457,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Characters/Dupen/body.png',0,0,376,520,1,0)
	anim:SetHotSpot(188,260)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('body',anim,790,509,111,0,-1,1)
	local anim = CreateAnimation('data/Texture/Characters/Dupen/head1.png',0,0,185,244,1,0)
	anim:SetHotSpot(92,122)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('head1',anim,757,201,112,0,-1,1)
	local anim = CreateAnimation('data/Texture/Characters/Dupen/head2.png',0,0,214,252,1,0)
	anim:SetHotSpot(107,126)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('head2',anim,761,200,113,0,-1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_restorator',anim,326,330,115,0,40,60)
	local anim = CreateAnimation('data/Texture/Characters/Restorator/Golova_2.png',0,0,136,206,1,0)
	anim:SetHotSpot(68,103)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Golova_2',anim,325,174,112,0,1,1)
	local anim = CreateAnimation('data/Texture/Characters/Restorator/Ruka_2.png',0,0,167,226,1,0)
	anim:SetHotSpot(83,113)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Ruka_2',anim,495,417,112,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_piano',anim,80,463,101,0,12,23)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area_circle.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_table',anim,755,601,101,5,3,0.8)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
