local zoom_shelf_top;
local zoom_shelf_bottom;

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/07_Atelier_Main.lua', 'quest')
    
    HideFindedHiddenObjects();
    
    play_field:GetObject('layer_door_open'      ):SetOpacity(0);
    play_field:GetObject('Layer_shelf_top'      ):SetOpacity(0);
    play_field:GetObject('Layer_shelf_bottom'   ):SetOpacity(0);
    play_field:GetObject('area_door_lock'           ):SetVisible(false);
    play_field:GetObject('area_door'                ):SetVisible(false);
    play_field:GetObject('area_shelf_top_open'      ):SetVisible(false);
    play_field:GetObject('area_shelf_bottom_open'   ):SetVisible(false);
    
    play_field:GetObject('Light_1'):SetOpacity(0);
    play_field:GetObject('Light_2'):SetOpacity(0);
    
    play_field:IgnoreOnTestPoint('Light_1');
    play_field:IgnoreOnTestPoint('Light_2');
    
    zoom_shelf_top = CreateZoomZone( 'area_shelf_top_open',
                                     'CloseZoneShelfTop',
                                     'ZOOM_shelf_top',   true,
                                     'Layer_button',     true,
                                     'area_button_find', true);
                                     
    zoom_shelf_bottom = CreateZoomZone( 'area_shelf_bottom_open',
                                        'CloseZoneShelfBottom',
                                        'ZOOM_shelf_bottom', true);
                                     
    play_field:GetObject('area_button_find'):GetAnimation():SetColor('0x01FFFFFF');
    
    local on_enter_comics = CreateComics('07_OnEnter',
                                        CreateComicsFrame('Dupen', 'C_07_START_1_DUPEN', 'body', 'head2'));
    
    if on_enter_comics then
        on_enter_comics.on_finish = function()
            DoAfterEnterComics();
        end
        on_enter_comics.SetVisible( true );
    else
        DoAfterEnterComics();
    end
end

function HideFindedHiddenObjects()
    local ho_table_path = 'data/Scenes/07_Atelier_Table_HO.lua';
    
    if HasGameState('TaskObjectFound', ho_table_path..'(Cup)') then
        play_field:GetObject("BG_Chashka"):SetVisible(false);
    end
    
    if HasGameState('TaskObjectFound', ho_table_path..'(Basket)') then
        play_field:GetObject('BG_Korzinka'):SetVisible(false);
    end
    
    if HasGameState('TaskObjectFound', ho_table_path..'(Iron)') then
        play_field:GetObject('BG_Utyug'):SetVisible(false);
    end
end

function DoAfterEnterComics()
    LinkScene(  'area_ho_table',
                'CursorGlass',
                'data/Scenes/07_Atelier_Table_HO.lua',
                true);
                
    LinkScene(  'area_ho_chest',
                'CursorGlass',
                'data/Scenes/07_Atelier_Chest_HO.lua',
                true);

    LinkScene(  'area_door',
                'CursorUpLeft',
                'data/Scenes/13_Crimeplace_Street.lua',
                false);
    
    if not HasGameState('MiniGameCompleted', '07_lock') then
		LinkScene(  'area_lock_mg',
					'CursorGlass',
					'data/Scenes/Minigames/07_lock.lua',
					false);
	else
        play_field:GetObject('area_lock_mg'  ):SetVisible(false);
        play_field:GetObject('area_door_lock'):SetVisible(true);
    end
    
    RegisterActiveObject('area_door_lock',              function(obj_name)
                                                            play_field:GetObject(obj_name):SetVisible(false);
                                                            
                                                            play_field:GetObject('layer_door_open'):ChangeOpacity(0, 1, OPEN_DOOR_TIME);
                                                            play_field:GetObject('Light_2'):ChangeOpacity(0, 0.5, OPEN_DOOR_TIME);
                                                            
                                                            PlaySound('07_OpenDoor')
                                                            
                                                            AddNoteToNotebook('SALON_3');
                                                            
                                                            TimerDoString('CreateLightAnimation();', 0.5,   play_field:GetTimer());
                                                            
                                                            TimerDoString("CreateLeafAnimation();"..
                                                                          "PlaySound('07_Wind');",   1.2,   play_field:GetTimer());
                                                                          
                                                            TimerDoString('CreateFindExitDialog();', 3,     play_field:GetTimer());
                                                            
                                                            --CreateFindExitDialog();
                                                        end,
                                                        function(obj_name)
                                                            play_field:GetObject(obj_name):SetVisible(false);
                                                            play_field:GetObject('area_door'):SetVisible(true);
                                                            
                                                            play_field:GetObject('layer_door_open'):SetOpacity(1);
                                                            
                                                            CreateLightAnimation();
                                                            CreateFindExitDialog();
                                                        end);
                                      
    RegisterActiveObject('area_shelf_top_close',        function(obj_name)
                                                            play_field:GetObject('area_shelf_top_close' ):SetVisible(false);
                                                            play_field:GetObject('area_shelf_top_open'  ):SetVisible(true);
                                                            
                                                            play_field:GetObject('Layer_shelf_top'):ChangeOpacity(0, 1, OPEN_DOOR_TIME);
                                                            
                                                            PlaySound('07_OpenShelf')
                                                        end,
                                                        function(obj_name)
                                                            play_field:GetObject('area_shelf_top_close' ):SetVisible(false);
                                                            play_field:GetObject('area_shelf_top_open'  ):SetVisible(true);
                                                            
                                                            play_field:GetObject('Layer_shelf_top'):SetOpacity(1);
                                                        end);
    --[[
    RegisterActiveObject('area_shelf_bottom_close',     function(obj_name)
                                                            play_field:GetObject('area_shelf_bottom_close' ):SetVisible(false);
                                                            play_field:GetObject('area_shelf_bottom_open'  ):SetVisible(true);
                                                            
                                                            play_field:GetObject('Layer_shelf_bottom'):ChangeOpacity(0, 1, OPEN_DOOR_TIME);
                                                        end,
                                                        function(obj_name)
                                                            play_field:GetObject('area_shelf_bottom_close' ):SetVisible(false);
                                                            play_field:GetObject('area_shelf_bottom_open'  ):SetVisible(true);
                                                            
                                                            play_field:GetObject('Layer_shelf_bottom'):SetOpacity(1);
                                                        end);
    --]]
    RegisterToolFindInfo('07_button', 'area_button_find',
                                                        function(tool_name)
                                                            zoom_shelf_top.SetObjectVisible('Layer_button', false);
                                                            zoom_shelf_top.Disable();
                                                            
                                                            if HasGameState('SceneVisited', 'data/Scenes/Minigames/07_lock.lua') then
                                                                AddNoteToNotebook('SALON_2');
                                                            end
                                                        end,
                                                        function(tool_name)
                                                            zoom_shelf_top.Disable();
                                                        end);
end

function CreateFindExitDialog()
    local comics = CreateComics('07_FindExit',
                                CreateComicsFrame('Dupen', 'C_07_FIND_EXIT_1_DUPEN', 'body', 'head2'));
    
    if comics then
        comics.SetVisible( true );
        comics.on_finish = function()
            play_field:GetObject('area_door'):SetVisible(true);
        end
    else
        play_field:GetObject('area_door'):SetVisible(true);
    end
end

function CreateLightAnimation()
    local eff1 = CreateAnimationEffector();
    eff1:AttachTo( play_field:GetObject('Light_1') )
    eff1:SetMode(_ANIM_FWD + _ANIM_LOOP);

    eff1:SetKey(_TRACK_O, 0, 0);
    eff1:SetKey(_TRACK_O, 2, 1);
    eff1:SetKey(_TRACK_O, 4, 0);

    eff1:Play();
    
    local eff2 = CreateAnimationEffector();
    eff2:AttachTo( play_field:GetObject('Light_2') )
    eff2:SetMode(_ANIM_FWD + _ANIM_LOOP);

    eff2:SetKey(_TRACK_O, 0, 1);
    eff2:SetKey(_TRACK_O, 2, 0);
    eff2:SetKey(_TRACK_O, 4, 1);

    eff2:Play();
end

function CreateLeafAnimation()
    createCompositionbackground = function()
        local compositionbackground = CreateCompositionSequence();
        local compositionDuration = 8.1;
        compositionbackground:SetDuration(compositionDuration);
        compositionbackground:AttachTo(play_field);
        compositionbackground:SetZ(104);
    
    
        -- Layer LeafsComp_4
        local element = createCompositionLeafs();
        element:SetName("LeafsComp_4");
        compositionbackground:AddElement(element);
        element:SetHotSpot(512, 384);
        element:SetParentElement(compositionbackground);
        element:SetXY(512, 384);
    
        element:SetScaleX(1);
        element:SetScaleY(1);
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0.35, 50.35);
    
    
        effector:Play();
    
        compositionbackground:Play();
    
        return compositionbackground;
    end
    
    createCompositionLeafs = function()
    
        local compositionLeafs = CreateCompositionSequence();
        local compositionDuration = 8.1;
        compositionLeafs:SetDuration(compositionDuration);
    
    
        -- Layer Leaf_Leyer_1
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/maple3_a.png");
        element:SetName("Leaf_Leyer_1");
        compositionLeafs:AddElement(element);
        element:SetHotSpot(30, 28);
        element:SetParentElement(compositionLeafs);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0.45, 4.49);
    
        effector:SetKey(_TRACK_X, 0.45, 56.0843061536543);
        effector:SetKey(_TRACK_Y, 0.45, 115.741960992611);
        effector:SetKey(_TRACK_X, 0.55572461038828, 146.270722424338);
        effector:SetKey(_TRACK_Y, 0.55572461038828, 167.265536388256);
        effector:SetKey(_TRACK_X, 0.66141308546066, 242.343841700605);
        effector:SetKey(_TRACK_Y, 0.66141308546066, 207.379217785666);
        effector:SetKey(_TRACK_X, 0.76713768839836, 343.995734219481);
        effector:SetKey(_TRACK_Y, 0.76713768839836, 224.56359527352);
        effector:SetKey(_TRACK_X, 0.80518553853035, 364.583337120966);
        effector:SetKey(_TRACK_Y, 0.80518553853035, 197.475129682039);
        effector:SetKey(_TRACK_X, 0.87286232113838, 359.266411809059);
        effector:SetKey(_TRACK_Y, 0.87286232113838, 169.670462586031);
        effector:SetKey(_TRACK_X, 0.97858692407608, 328.19074544158);
        effector:SetKey(_TRACK_Y, 0.97858692407608, 140.51042853138);
        effector:SetKey(_TRACK_X, 1.08427537679672, 285.556085615739);
        effector:SetKey(_TRACK_Y, 1.08427537679672, 148.110468572113);
        effector:SetKey(_TRACK_X, 1.19000000953674, 256.995696516889);
        effector:SetKey(_TRACK_Y, 1.19000000953674, 181.067516051626);
        effector:SetKey(_TRACK_X, 1.29572464227676, 255.871448161725);
        effector:SetKey(_TRACK_Y, 1.29572464227676, 224.574636404855);
        effector:SetKey(_TRACK_X, 1.30840725898743, 257.619035876447);
        effector:SetKey(_TRACK_Y, 1.30840725898743, 229.6211311552);
        effector:SetKey(_TRACK_X, 1.40141309499741, 323.00872509543);
        effector:SetKey(_TRACK_Y, 1.40141309499741, 270.740235792292);
        effector:SetKey(_TRACK_X, 1.50713772773743, 406.868321826512);
        effector:SetKey(_TRACK_Y, 1.50713772773743, 299.5226285278);
        effector:SetKey(_TRACK_X, 1.6128623008728, 493.61889174197);
        effector:SetKey(_TRACK_Y, 1.6128623008728, 298.558302879384);
        effector:SetKey(_TRACK_X, 1.66359276771545, 505.2483086822);
        effector:SetKey(_TRACK_Y, 1.66359276771545, 260.455616744378);
        effector:SetKey(_TRACK_X, 1.71858687400818, 501.592033482662);
        effector:SetKey(_TRACK_Y, 1.71858687400818, 249.995022389141);
        effector:SetKey(_TRACK_X, 1.82427544593811, 484.475702987106);
        effector:SetKey(_TRACK_Y, 1.82427544593811, 239.057052294534);
        effector:SetKey(_TRACK_X, 1.93000001907349, 464.490985682849);
        effector:SetKey(_TRACK_Y, 1.93000001907349, 245.518687778935);
        effector:SetKey(_TRACK_X, 2.03572459220886, 450.048914580892);
        effector:SetKey(_TRACK_Y, 2.03572459220886, 260.956508399318);
        effector:SetKey(_TRACK_X, 2.14141316413879, 448.424288935705);
        effector:SetKey(_TRACK_Y, 2.14141316413879, 281.426671743141);
        effector:SetKey(_TRACK_X, 2.22600002288818, 460.588993358296);
        effector:SetKey(_TRACK_Y, 2.22600002288818, 292.960792094808);
        effector:SetKey(_TRACK_X, 2.24713773727417, 473.453559479892);
        effector:SetKey(_TRACK_Y, 2.24713773727417, 293.504672223997);
        effector:SetKey(_TRACK_X, 2.35286231040955, 538.13763984322);
        effector:SetKey(_TRACK_Y, 2.35286231040955, 288.620153439794);
        effector:SetKey(_TRACK_X, 2.45858688354492, 602.879638373389);
        effector:SetKey(_TRACK_Y, 2.45858688354492, 285.638943236645);
        effector:SetKey(_TRACK_X, 2.56427545547485, 667.663555759612);
        effector:SetKey(_TRACK_Y, 2.56427545547485, 286.791851420278);
        effector:SetKey(_TRACK_X, 2.67000002861023, 732.058489628181);
        effector:SetKey(_TRACK_Y, 2.67000002861023, 294.131319278688);
        effector:SetKey(_TRACK_X, 2.77572460174561, 794.516977688584);
        effector:SetKey(_TRACK_Y, 2.77572460174561, 311.082565523526);
        effector:SetKey(_TRACK_X, 2.80000586509705, 808.21580352238);
        effector:SetKey(_TRACK_Y, 2.80000586509705, 316.900923551471);
        effector:SetKey(_TRACK_X, 2.88141317367554, 837.508035847359);
        effector:SetKey(_TRACK_Y, 2.88141317367554, 330.583967598789);
        effector:SetKey(_TRACK_X, 2.98713774681091, 875.418873923317);
        effector:SetKey(_TRACK_Y, 2.98713774681091, 348.63999979297);
        effector:SetKey(_TRACK_X, 3.09286231994629, 913.163685661118);
        effector:SetKey(_TRACK_Y, 3.09286231994629, 366.991476373962);
        effector:SetKey(_TRACK_X, 3.19858689308167, 950.771225624586);
        effector:SetKey(_TRACK_Y, 3.19858689308167, 385.636316084579);
        effector:SetKey(_TRACK_X, 3.3042754650116, 988.229348772371);
        effector:SetKey(_TRACK_Y, 3.3042754650116, 404.557042873734);
        effector:SetKey(_TRACK_X, 3.41000003814697, 1025.53680373918);
        effector:SetKey(_TRACK_Y, 3.41000003814697, 423.746524909538);
        effector:SetKey(_TRACK_X, 3.51572461128235, 1062.70557562231);
        effector:SetKey(_TRACK_Y, 3.51572461128235, 443.212079944298);
        effector:SetKey(_TRACK_X, 3.62141318321228, 1099.70907807622);
        effector:SetKey(_TRACK_Y, 3.62141318321228, 462.95298474199);
        effector:SetKey(_TRACK_X, 3.72713775634766, 1136.54730179033);
        effector:SetKey(_TRACK_Y, 3.72713775634766, 483.012011184004);
        effector:SetKey(_TRACK_X, 3.79481453895569, 1160.00989891221);
        effector:SetKey(_TRACK_Y, 3.79481453895569, 496.088932506492);
        effector:SetKey(_TRACK_SX, 0.45, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 0.45, 0.46034458705357);
        effector:SetKey(_TRACK_SX, 0.80518553853035, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 0.80518553853035, -0.53706868489584);
        effector:SetKey(_TRACK_SX, 1.30840725898743, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 1.30840725898743, 0.53706868489583);
        effector:SetKey(_TRACK_SX, 1.66359276771545, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 1.66359276771545, -0.53695941354591);
        effector:SetKey(_TRACK_SX, 2.22600002288818, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 2.22600002288818, 0.53699967510657);
        effector:SetKey(_TRACK_SX, 2.58118553161621, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 2.58118553161621, 0.23017229352678);
        effector:SetKey(_TRACK_SX, 2.93640727996826, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 2.93640727996826, 0.49864254984872);
        effector:SetKey(_TRACK_SX, 3.130006980896, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 3.130006980896, 0.155269095431);
        effector:SetKey(_TRACK_SX, 3.49881453514099, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 3.49881453514099, -0.49870663597471);
        effector:SetKey(_TRACK_A, 0.45, 0.2572181453218);
        effector:SetKey(_TRACK_A, 3.130006980896, 0.2572181453218);
    
        effector:Play();
    
        
        -- Layer Leaf_Leyer_2
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/maple3_a.png");
        element:SetName("Leaf_Leyer_2");
        compositionLeafs:AddElement(element);
        element:SetHotSpot(30, 28);
        element:SetParentElement(compositionLeafs);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0.3, 4.34);
    
        effector:SetKey(_TRACK_X, 0.3, 34.5083664903517);
        effector:SetKey(_TRACK_Y, 0.3, 171.243916920064);
        effector:SetKey(_TRACK_X, 0.40572461038828, 127.109869508469);
        effector:SetKey(_TRACK_Y, 0.40572461038828, 218.288893928708);
        effector:SetKey(_TRACK_X, 0.51141308546066, 225.032227497109);
        effector:SetKey(_TRACK_Y, 0.51141308546066, 253.649376045104);
        effector:SetKey(_TRACK_X, 0.61713768839836, 327.403730620321);
        effector:SetKey(_TRACK_Y, 0.61713768839836, 265.834851918153);
        effector:SetKey(_TRACK_X, 0.65518553853035, 346.640004570454);
        effector:SetKey(_TRACK_Y, 0.65518553853035, 237.770637391819);
        effector:SetKey(_TRACK_X, 0.72286232113838, 339.967758548676);
        effector:SetKey(_TRACK_Y, 0.72286232113838, 210.259724772748);
        effector:SetKey(_TRACK_X, 0.82858692407608, 307.501302511432);
        effector:SetKey(_TRACK_Y, 0.82858692407608, 182.656572870749);
        effector:SetKey(_TRACK_X, 0.93427537679672, 265.290003177869);
        effector:SetKey(_TRACK_Y, 0.93427537679672, 192.335477454643);
        effector:SetKey(_TRACK_X, 1.04000000953674, 238.377917570471);
        effector:SetKey(_TRACK_Y, 1.04000000953674, 226.651690671534);
        effector:SetKey(_TRACK_X, 1.14572464227676, 239.385726603012);
        effector:SetKey(_TRACK_Y, 1.14572464227676, 270.161662991877);
        effector:SetKey(_TRACK_X, 1.15840725898743, 241.378363360764);
        effector:SetKey(_TRACK_Y, 1.15840725898743, 275.116516076657);
        effector:SetKey(_TRACK_X, 1.25141309499741, 308.703347930264);
        effector:SetKey(_TRACK_Y, 1.25141309499741, 312.98389802281);
        effector:SetKey(_TRACK_X, 1.35713772773743, 393.871902278181);
        effector:SetKey(_TRACK_Y, 1.35713772773743, 337.624829758974);
        effector:SetKey(_TRACK_X, 1.4628623008728, 480.471149844289);
        effector:SetKey(_TRACK_Y, 1.4628623008728, 332.413154007532);
        effector:SetKey(_TRACK_X, 1.51359276771545, 490.220579550115);
        effector:SetKey(_TRACK_Y, 1.51359276771545, 293.786652781702);
        effector:SetKey(_TRACK_X, 1.56858687400818, 486.056397790616);
        effector:SetKey(_TRACK_Y, 1.56858687400818, 283.517672889783);
        effector:SetKey(_TRACK_X, 1.67427544593811, 468.424931512674);
        effector:SetKey(_TRACK_Y, 1.67427544593811, 273.431079774381);
        effector:SetKey(_TRACK_X, 1.78000001907349, 448.780662255031);
        effector:SetKey(_TRACK_Y, 1.78000001907349, 280.863680998966);
        effector:SetKey(_TRACK_X, 1.88572459220886, 435.111952256642);
        effector:SetKey(_TRACK_Y, 1.88572459220886, 296.990269873804);
        effector:SetKey(_TRACK_X, 1.99141316413879, 434.491776820374);
        effector:SetKey(_TRACK_Y, 1.99141316413879, 317.51543259886);
        effector:SetKey(_TRACK_X, 2.07600002288818, 447.206770997867);
        effector:SetKey(_TRACK_Y, 2.07600002288818, 328.439972861008);
        effector:SetKey(_TRACK_X, 2.09713773727417, 460.082520364151);
        effector:SetKey(_TRACK_Y, 2.09713773727417, 328.353160015738);
        effector:SetKey(_TRACK_X, 2.20286231040955, 524.449771055806);
        effector:SetKey(_TRACK_Y, 2.20286231040955, 320.306678809903);
        effector:SetKey(_TRACK_X, 2.30858688354492, 588.968080653338);
        effector:SetKey(_TRACK_Y, 2.30858688354492, 314.158382070511);
        effector:SetKey(_TRACK_X, 2.41427545547485, 653.730724455006);
        effector:SetKey(_TRACK_Y, 2.41427545547485, 312.137192478228);
        effector:SetKey(_TRACK_X, 2.52000002861023, 718.407829962287);
        effector:SetKey(_TRACK_Y, 2.52000002861023, 316.31418787209);
        effector:SetKey(_TRACK_X, 2.62572460174561, 781.621538667485);
        effector:SetKey(_TRACK_Y, 2.62572460174561, 330.186264452089);
        effector:SetKey(_TRACK_X, 2.65000586509705, 795.588873982955);
        effector:SetKey(_TRACK_Y, 2.65000586509705, 335.326756712794);
        effector:SetKey(_TRACK_X, 2.73141317367554, 825.516067422861);
        effector:SetKey(_TRACK_Y, 2.73141317367554, 347.558829669027);
        effector:SetKey(_TRACK_X, 2.83713774681091, 864.265689383772);
        effector:SetKey(_TRACK_Y, 2.83713774681091, 363.736556955065);
        effector:SetKey(_TRACK_X, 2.94286231994629, 902.863952076015);
        effector:SetKey(_TRACK_Y, 2.94286231994629, 380.217505177274);
        effector:SetKey(_TRACK_X, 3.04858689308166, 941.339472589676);
        effector:SetKey(_TRACK_Y, 3.04858689308166, 396.998189210547);
        effector:SetKey(_TRACK_X, 3.1542754650116, 979.679270173957);
        effector:SetKey(_TRACK_Y, 3.1542754650116, 414.061743974955);
        effector:SetKey(_TRACK_X, 3.26000003814697, 1017.88173877656);
        effector:SetKey(_TRACK_Y, 3.26000003814697, 431.401111658495);
        effector:SetKey(_TRACK_X, 3.36572461128235, 1055.95921310585);
        effector:SetKey(_TRACK_Y, 3.36572461128235, 449.023012380599);
        effector:SetKey(_TRACK_X, 3.47141318321228, 1093.88510161648);
        effector:SetKey(_TRACK_Y, 3.47141318321228, 466.928027464706);
        effector:SetKey(_TRACK_X, 3.57713775634766, 1131.66148815351);
        effector:SetKey(_TRACK_Y, 3.57713775634766, 485.158877057504);
        effector:SetKey(_TRACK_X, 3.64481453895569, 1155.73635854396);
        effector:SetKey(_TRACK_Y, 3.64481453895569, 497.071053485671);
        effector:SetKey(_TRACK_SX, 0.3, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 0.3, 0.46034458705357);
        effector:SetKey(_TRACK_SX, 0.65518553853035, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 0.65518553853035, -0.53706868489584);
        effector:SetKey(_TRACK_SX, 1.15840725898743, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 1.15840725898743, 0.53706868489583);
        effector:SetKey(_TRACK_SX, 1.51359276771545, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 1.51359276771545, -0.53695941354591);
        effector:SetKey(_TRACK_SX, 2.07600002288818, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 2.07600002288818, 0.53699967510657);
        effector:SetKey(_TRACK_SX, 2.43118553161621, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 2.43118553161621, 0.23017229352678);
        effector:SetKey(_TRACK_SX, 2.78640727996826, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 2.78640727996826, 0.49864254984872);
        effector:SetKey(_TRACK_SX, 2.980006980896, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 2.980006980896, 0.155269095431);
        effector:SetKey(_TRACK_SX, 3.34881453514099, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 3.34881453514099, -0.49870663597471);
        effector:SetKey(_TRACK_A, 0.3, 0.20822473718477);
        effector:SetKey(_TRACK_A, 2.980006980896, 0.20822473718477);
    
        effector:Play();
    
    
        -- Layer Leaf_Leyer_3
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/maple3_a.png");
        element:SetName("Leaf_Leyer_3");
        compositionLeafs:AddElement(element);
        element:SetHotSpot(30, 28);
        element:SetParentElement(compositionLeafs);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 4.04);
    
        effector:SetKey(_TRACK_X, 0, -0.15919078762347);
        effector:SetKey(_TRACK_Y, 0, 253.548217773438);
        effector:SetKey(_TRACK_X, 0.10572461038828, 100.167361144993);
        effector:SetKey(_TRACK_Y, 0.10572461038828, 280.434107448426);
        effector:SetKey(_TRACK_X, 0.21141308546066, 203.284378772591);
        effector:SetKey(_TRACK_Y, 0.21141308546066, 294.787950156958);
        effector:SetKey(_TRACK_X, 0.31713768839836, 305.963621085127);
        effector:SetKey(_TRACK_Y, 0.31713768839836, 285.547636465244);
        effector:SetKey(_TRACK_X, 0.35518553853035, 318.982854103989);
        effector:SetKey(_TRACK_Y, 0.35518553853035, 254.113039121598);
        effector:SetKey(_TRACK_X, 0.42286232113838, 306.767585212243);
        effector:SetKey(_TRACK_Y, 0.42286232113838, 228.57568659177);
        effector:SetKey(_TRACK_X, 0.52858692407608, 269.296208800032);
        effector:SetKey(_TRACK_Y, 0.52858692407608, 208.280351104024);
        effector:SetKey(_TRACK_X, 0.63427537679672, 229.997552584947);
        effector:SetKey(_TRACK_Y, 0.63427537679672, 226.47624548287);
        effector:SetKey(_TRACK_X, 0.74000000953674, 210.760742592279);
        effector:SetKey(_TRACK_Y, 0.74000000953674, 265.614563020715);
        effector:SetKey(_TRACK_X, 0.84572464227676, 220.741310456067);
        effector:SetKey(_TRACK_Y, 0.84572464227676, 307.976359311894);
        effector:SetKey(_TRACK_X, 0.85840725898743, 223.715188896621);
        effector:SetKey(_TRACK_Y, 0.85840725898743, 312.412260373746);
        effector:SetKey(_TRACK_X, 0.95141309499741, 297.41398491192);
        effector:SetKey(_TRACK_Y, 0.95141309499741, 335.544040855183);
        effector:SetKey(_TRACK_X, 1.05713772773743, 385.836706606835);
        effector:SetKey(_TRACK_Y, 1.05713772773743, 342.046391992944);
        effector:SetKey(_TRACK_X, 1.1628623008728, 469.487987059387);
        effector:SetKey(_TRACK_Y, 1.1628623008728, 319.045208447315);
        effector:SetKey(_TRACK_X, 1.21359276771545, 471.041825487277);
        effector:SetKey(_TRACK_Y, 1.21359276771545, 279.237625689872);
        effector:SetKey(_TRACK_X, 1.26858687400818, 464.844753755765);
        effector:SetKey(_TRACK_Y, 1.26858687400818, 270.051294095579);
        effector:SetKey(_TRACK_X, 1.37427544593811, 445.509002483711);
        effector:SetKey(_TRACK_Y, 1.37427544593811, 263.827410430517);
        effector:SetKey(_TRACK_X, 1.48000001907349, 427.825552926916);
        effector:SetKey(_TRACK_Y, 1.48000001907349, 275.160392702599);
        effector:SetKey(_TRACK_X, 1.58572459220886, 417.785836753815);
        effector:SetKey(_TRACK_Y, 1.58572459220886, 293.764278281086);
        effector:SetKey(_TRACK_X, 1.69141316413879, 421.422088336862);
        effector:SetKey(_TRACK_Y, 1.69141316413879, 313.974292729616);
        effector:SetKey(_TRACK_X, 1.77600002288818, 436.120769747574);
        effector:SetKey(_TRACK_Y, 1.77600002288818, 322.034361088267);
        effector:SetKey(_TRACK_X, 1.79713773727417, 448.700468245945);
        effector:SetKey(_TRACK_Y, 1.79713773727417, 319.287716012818);
        effector:SetKey(_TRACK_X, 1.90286231040955, 510.013954534606);
        effector:SetKey(_TRACK_Y, 1.90286231040955, 298.108831722982);
        effector:SetKey(_TRACK_X, 2.00858688354492, 571.867637562406);
        effector:SetKey(_TRACK_Y, 2.00858688354492, 278.75590485818);
        effector:SetKey(_TRACK_X, 2.11427545547485, 634.813545550059);
        effector:SetKey(_TRACK_Y, 2.11427545547485, 263.390423660258);
        effector:SetKey(_TRACK_X, 2.22000002861023, 698.957069720652);
        effector:SetKey(_TRACK_Y, 2.22000002861023, 254.106928951826);
        effector:SetKey(_TRACK_X, 2.32572460174561, 763.673010201348);
        effector:SetKey(_TRACK_Y, 2.32572460174561, 254.611613486937);
        effector:SetKey(_TRACK_X, 2.35000586509705, 778.401303031415);
        effector:SetKey(_TRACK_Y, 2.35000586509705, 256.753694451853);
        effector:SetKey(_TRACK_X, 2.43141317367554, 810.210707234765);
        effector:SetKey(_TRACK_Y, 2.43141317367554, 262.534899444641);
        effector:SetKey(_TRACK_X, 2.53713774681091, 851.46762950578);
        effector:SetKey(_TRACK_Y, 2.53713774681091, 270.352728622032);
        effector:SetKey(_TRACK_X, 2.64286231994629, 892.639143209837);
        effector:SetKey(_TRACK_Y, 2.64286231994629, 278.498519382956);
        effector:SetKey(_TRACK_X, 2.74858689308167, 933.752529070802);
        effector:SetKey(_TRACK_Y, 2.74858689308167, 286.962943754707);
        effector:SetKey(_TRACK_X, 2.8542754650116, 974.791601338253);
        effector:SetKey(_TRACK_Y, 2.8542754650116, 295.732186977335);
        effector:SetKey(_TRACK_X, 2.96000003814697, 1015.75332703432);
        effector:SetKey(_TRACK_Y, 2.96000003814697, 304.799671959364);
        effector:SetKey(_TRACK_X, 3.06572461128235, 1056.6511651016);
        effector:SetKey(_TRACK_Y, 3.06572461128235, 314.169430860717);
        effector:SetKey(_TRACK_X, 3.17141318321228, 1097.4592165812);
        effector:SetKey(_TRACK_Y, 3.17141318321228, 323.847520640058);
        effector:SetKey(_TRACK_X, 3.27713775634766, 1138.18835399496);
        effector:SetKey(_TRACK_Y, 3.27713775634766, 333.875314093145);
        effector:SetKey(_TRACK_X, 3.34481453895569, 1164.20571806654);
        effector:SetKey(_TRACK_Y, 3.34481453895569, 340.553344726562);
        effector:SetKey(_TRACK_SX, 0, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 0, 0.46034458705357);
        effector:SetKey(_TRACK_SX, 0.35518553853035, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 0.35518553853035, -0.53706868489584);
        effector:SetKey(_TRACK_SX, 0.85840725898743, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 0.85840725898743, 0.53706868489583);
        effector:SetKey(_TRACK_SX, 1.21359276771545, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 1.21359276771545, -0.53695941354591);
        effector:SetKey(_TRACK_SX, 1.77600002288818, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 1.77600002288818, 0.53699967510657);
        effector:SetKey(_TRACK_SX, 2.13118553161621, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 2.13118553161621, 0.23017229352678);
        effector:SetKey(_TRACK_SX, 2.48640727996826, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 2.48640727996826, 0.49864254984872);
        effector:SetKey(_TRACK_SX, 2.680006980896, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 2.680006980896, 0.155269095431);
        effector:SetKey(_TRACK_SX, 3.04881453514099, -0.46034458705357);
        effector:SetKey(_TRACK_SY, 3.04881453514099, -0.49870663597471);
        effector:SetKey(_TRACK_A, 0, 0);
        effector:SetKey(_TRACK_A, 2.680006980896, 0);
    
        effector:Play();
    
        compositionLeafs:Play();
    
        return compositionLeafs;
    end
    
    return createCompositionbackground();
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

    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/07_Atelier/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/07_Atelier/Zone_main/Layers/layer_door_open.png',0,0,175,298,1,0)
	anim:SetHotSpot(87,149)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_door_open',anim,286,291,101,0,1,1)
	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_ho_table',anim,792,458,105,0,1.6,0.4)
	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_ho_chest',anim,465,400,100,0,15,5)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Layers/BG_Chashka.png',0,0,51,34,1,0)
	anim:SetHotSpot(25,17)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_Chashka',anim,583,440,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Layers/BG_chashka-korzinka.png',0,0,141,46,1,0)
	anim:SetHotSpot(70,23)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_chashka-korzinka',anim,637,444,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Layers/BG_Korzinka.png',0,0,95,73,1,0)
	anim:SetHotSpot(47,36)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_Korzinka',anim,685,418,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Layers/BG_Kuvshin.png',0,0,91,72,1,0)
	anim:SetHotSpot(45,36)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_Kuvshin',anim,721,452,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Layers/BG_Shkatulka.png',0,0,89,73,1,0)
	anim:SetHotSpot(44,36)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_Shkatulka',anim,763,451,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Layers/BG_Utyug.png',0,0,79,60,1,0)
	anim:SetHotSpot(39,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('BG_Utyug',anim,903,443,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_door_lock',anim,244,292,111,0,7,30)
	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_door',anim,244,292,102,0,7,30)
	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,375,508,120,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('0x00FFFFFF')
	screen:CreateObject('head2',anim,407,200,121,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Layers/Layer_shelf_bottom.png',0,0,180,84,1,0)
	anim:SetHotSpot(90,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_shelf_bottom',anim,88,583,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Layers/Layer_shelf_top.png',0,0,175,113,1,0)
	anim:SetHotSpot(87,56)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_shelf_top',anim,87,437,110,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_shelf_top_close',anim,82,427,111,0,20,5)
	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_shelf_top_open',anim,82,427,112,0,20,5)
	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_shelf_bottom_close',anim,81,573,111,-12,20,6)
	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_shelf_bottom_open',anim,96,582,112,-12,20,6)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Zoom_shelf/ZOOM_shelf.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('ZOOM_shelf_top',anim,512,384,150,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Zoom_shelf/ZOOM_shelf.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('ZOOM_shelf_bottom',anim,512,384,160,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Zoom_shelf/Layer_button.png',0,0,67,58,1,0)
	anim:SetHotSpot(33,29)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_button',anim,334,329,151,0,1,1)
	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_button_find',anim,335,327,152,0,0.8,0.8)
	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_lock_mg',anim,215,323,112,0,0.7,0.7)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Layers/Light_1.png',0,0,400,442,1,0)
	anim:SetHotSpot(200,221)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Light_1',anim,392,343,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Layers/Light_2.png',0,0,400,442,1,0)
	anim:SetHotSpot(200,221)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Light_2',anim,392,343,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/07_Atelier/Zone_main/Layers/mask.jpg',0,0,218,768,1,0)
	anim:SetHotSpot(109,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('mask',anim,109,384,109,0,1,1)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
