local zoom_mill;
local zoom_notice;

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/19_Mill_Outside_Main.lua', 'quest')
    
    StopMusic("19_InterNoise", false)
    PlayAmbientMusic("19_InterNoise", true);
    
    game_state.ambient = CreateMillOutsideAmbientComposition();
    game_state.ambient:AttachTo( play_field );
    game_state.ambient:SetZ( 99 );
    
    play_field:GetObject('area_door_open'):SetVisible(false);
    play_field:GetObject('Layer_door_open'):SetOpacity(0);
    
    zoom_mill = CreateZoomZone( 'area_mill',
                                'ZoomZoneMill',
                                'ZOOM_mill',    true,
                                'Layer_button', true);
    
    zoom_notice = CreateZoomZone('Layer_notice_small',
                                 'CloseZoneNotice',
                                 'ZOOM_notice', true);
    
    RegisterActiveObject('area_door_close',                 function(obj_name)
                                                                play_field:GetObject(obj_name):SetVisible(false);
                                                                play_field:GetObject('area_door_open'):SetVisible(true);
                                                                play_field:GetObject('Layer_door_open'):ChangeOpacity(0, 1, OPEN_DOOR_TIME);
                                                                
                                                                PlaySound('19_OpenDoor');
                                                                
                                                                LinkScene('area_door_open',
                                                                          'CursorUpRight',
                                                                          'data/Scenes/20_Mill_Inside_Main.lua',
                                                                          false);
                                                            end,
                                                            function(obj_name)
                                                                play_field:GetObject(obj_name):SetVisible(false);
                                                                play_field:GetObject('area_door_open'):SetVisible(true);
                                                                play_field:GetObject('Layer_door_open'):SetOpacity(1);
                                                                
                                                                LinkScene('area_door_open',
                                                                          'CursorUpRight',
                                                                          'data/Scenes/20_Mill_Inside_Main.lua',
                                                                          false);
                                                            end);
    
    RegisterToolFindInfo('19_button', 'Layer_button',       function(tool_name)
                                                                zoom_mill.Disable();
                                                            end,
                                                            function(tool_name)
                                                                zoom_mill.Disable();
                                                            end);
    
    UnRegisterQuestObjects('Layer_notice_small')
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 == 'ZOOM_notice' then
        ShowMonolog('C_19_NOTICE_HINT', 'C_19_NOTICE_HINT');
    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

function CreateMillOutsideAmbientComposition()
    createCompositionMelnica_opacity = function()
    
        local compositionMelnica_opacity = CreateCompositionSequence();
        local compositionDuration = 10.0767434100767;
        compositionMelnica_opacity:SetDuration(compositionDuration);
        compositionMelnica_opacity:SetCyclic(true)
    
    
        -- Layer Layer_2
        local element = createCompositionsky();
        element:SetName("Layer_2");
        compositionMelnica_opacity:AddElement(element);
        element:SetHotSpot(512, 384);
        element:SetParentElement(compositionMelnica_opacity);
        element:SetXY(520, 388);
    
        element:SetScaleX(1.07083333333333);
        element:SetScaleY(1.07083333333333);
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 10.08);
        effector:Play();
    
        compositionMelnica_opacity:Play();
    
        return compositionMelnica_opacity;
    end
    
    createCompositionsky = function()
    
        local compositionsky = CreateCompositionSequence();
        local compositionDuration = 10.08;
        compositionsky:SetDuration(compositionDuration);
    
        -- Layer Layer_1
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/cloud1.png");
        element:SetName("Layer_1");
        compositionsky:AddElement(element);
        element:SetHotSpot(790, 383);
        element:SetParentElement(compositionsky);
        element:SetScaleX(0.57202193746264);
        element:SetScaleY(0.57202193746264);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(5.04, 10.08);
        effector:SetKey(_TRACK_X, 5.04, 226.898170936747);
        effector:SetKey(_TRACK_Y, 5.04, 349);
        effector:SetKey(_TRACK_X, 10.04, 316.590203410257);
        effector:SetKey(_TRACK_Y, 10.04, 349);
        effector:SetKey(_TRACK_X, 15.08, 407);
        effector:SetKey(_TRACK_Y, 15.08, 349);
        effector:SetKey(_TRACK_O, 5.04, 0);
        effector:SetKey(_TRACK_O, 10.04, 1);
        effector:SetKey(_TRACK_O, 15.08, 0);
        effector:Play();
    
    
        -- Layer Layer_2
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/cloud1.png");
        element:SetName("Layer_2");
        compositionsky:AddElement(element);
        element:SetHotSpot(790, 383);
        element:SetParentElement(compositionsky);
        element:SetScaleX(0.57202193746264);
        element:SetScaleY(0.57202193746264);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 5.08);
        effector:SetKey(_TRACK_X, 0, 316.59048206693);
        effector:SetKey(_TRACK_Y, 0, 349);
        effector:SetKey(_TRACK_X, 5.04, 407);
        effector:SetKey(_TRACK_Y, 5.04, 349);
        effector:SetKey(_TRACK_O, 0, 1);
        effector:SetKey(_TRACK_O, 5.04, 0);
        effector:Play();
    
    
        -- Layer Layer_3
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/cloud1.png");
        element:SetName("Layer_3");
        compositionsky:AddElement(element);
        element:SetHotSpot(790, 383);
        element:SetParentElement(compositionsky);
        element:SetScaleX(0.57202193746264);
        element:SetScaleY(0.57202193746264);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 10.08);
        effector:SetKey(_TRACK_X, 0, 226.898170936747);
        effector:SetKey(_TRACK_Y, 0, 349);
        effector:SetKey(_TRACK_X, 10.04, 407);
        effector:SetKey(_TRACK_Y, 10.04, 349);
        effector:SetKey(_TRACK_O, 0, 0);
        effector:SetKey(_TRACK_O, 5, 1);
        effector:SetKey(_TRACK_O, 10.04, 0);
        effector:Play();
    
    
        -- Layer Layer_4
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/cloud2.png");
        element:SetName("Layer_4");
        compositionsky:AddElement(element);
        element:SetHotSpot(1000, 444);
        element:SetParentElement(compositionsky);
        element:SetScaleX(0.32257345571483);
        element:SetScaleY(0.32257345571483);
        element:SetAngle(-0.00280331340704);
    
        effector = element:GetEffector();
        effector:SetLifeTime(5.04, 10.08);
        effector:SetKey(_TRACK_X, 5.04, 465.345000431401);
        effector:SetKey(_TRACK_Y, 5.04, 186.720094598897);
        effector:SetKey(_TRACK_X, 10.04, 489.245725404883);
        effector:SetKey(_TRACK_Y, 10.04, 186.720094598897);
        effector:SetKey(_TRACK_X, 15.08, 513.345000431401);
        effector:SetKey(_TRACK_Y, 15.08, 186.720094598897);
        effector:SetKey(_TRACK_O, 5.04, 0);
        effector:SetKey(_TRACK_O, 10.04, 1);
        effector:SetKey(_TRACK_O, 15.08, 0);
        effector:Play();
    
    
        -- Layer Layer_5
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/cloud2.png");
        element:SetName("Layer_5");
        compositionsky:AddElement(element);
        element:SetHotSpot(1000, 444);
        element:SetParentElement(compositionsky);
        element:SetScaleX(0.32257345571483);
        element:SetScaleY(0.32257345571483);
        element:SetAngle(-0.00280331340704);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 5.08);
        effector:SetKey(_TRACK_X, 0, 489.245725404883);
        effector:SetKey(_TRACK_Y, 0, 186.720094598897);
        effector:SetKey(_TRACK_X, 5.04, 513.345000431401);
        effector:SetKey(_TRACK_Y, 5.04, 186.720094598897);
        effector:SetKey(_TRACK_O, 0, 1);
        effector:SetKey(_TRACK_O, 5.04, 0);
        effector:Play();
    
    
        -- Layer Layer_6
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/cloud2.png");
        element:SetName("Layer_6");
        compositionsky:AddElement(element);
        element:SetHotSpot(1000, 444);
        element:SetParentElement(compositionsky);
        element:SetScaleX(0.32257345571483);
        element:SetScaleY(0.32257345571483);
        element:SetAngle(-0.00280331340704);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 10.08);
        effector:SetKey(_TRACK_X, 0, 465.345000431401);
        effector:SetKey(_TRACK_Y, 0, 186.720094598897);
        effector:SetKey(_TRACK_X, 10.04, 513.345000431401);
        effector:SetKey(_TRACK_Y, 10.04, 186.720094598897);
        effector:SetKey(_TRACK_O, 0, 0);
        effector:SetKey(_TRACK_O, 5, 1);
        effector:SetKey(_TRACK_O, 10.04, 0);
        effector:Play();
    
    
        -- Layer Layer_7
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/cloud2.png");
        element:SetName("Layer_7");
        compositionsky:AddElement(element);
        element:SetHotSpot(1000, 444);
        element:SetParentElement(compositionsky);
        element:SetScaleX(0.458);
        element:SetScaleY(0.458);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(5, 10.08);
        effector:SetKey(_TRACK_X, 5, 378.396598568038);
        effector:SetKey(_TRACK_Y, 5, 159);
        effector:SetKey(_TRACK_X, 10.04, 430.404585540787);
        effector:SetKey(_TRACK_Y, 10.04, 159);
        effector:SetKey(_TRACK_X, 15.04, 482);
        effector:SetKey(_TRACK_Y, 15.04, 159);
        effector:SetKey(_TRACK_O, 5, 0);
        effector:SetKey(_TRACK_O, 10, 1);
        effector:SetKey(_TRACK_O, 15.04, 0);
        effector:Play();
    
    
        -- Layer Layer_8
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/cloud2.png");
        element:SetName("Layer_8");
        compositionsky:AddElement(element);
        element:SetHotSpot(1000, 444);
        element:SetParentElement(compositionsky);
        element:SetScaleX(0.458);
        element:SetScaleY(0.458);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 5.04);
        effector:SetKey(_TRACK_X, 0, 430.404585540787);
        effector:SetKey(_TRACK_Y, 0, 159);
        effector:SetKey(_TRACK_X, 5, 482);
        effector:SetKey(_TRACK_Y, 5, 159);
        effector:SetKey(_TRACK_O, 0, 0.99206349206349);
        effector:SetKey(_TRACK_O, 5, 0);
        effector:Play();
    
    
        -- Layer Layer_9
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/cloud2.png");
        element:SetName("Layer_9");
        compositionsky:AddElement(element);
        element:SetHotSpot(1000, 444);
        element:SetParentElement(compositionsky);
        element:SetScaleX(0.458);
        element:SetScaleY(0.458);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 10.08);
        effector:SetKey(_TRACK_X, 0, 378.396598568038);
        effector:SetKey(_TRACK_Y, 0, 159);
        effector:SetKey(_TRACK_X, 10.04, 482);
        effector:SetKey(_TRACK_Y, 10.04, 159);
        effector:SetKey(_TRACK_O, 0, 0);
        effector:SetKey(_TRACK_O, 5, 1);
        effector:SetKey(_TRACK_O, 10.04, 0);
        effector:Play();
    
    
        -- Layer Layer_10
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/moon.png");
        element:SetName("Layer_10");
        compositionsky:AddElement(element);
        element:SetHotSpot(315, 315);
        element:SetParentElement(compositionsky);
        element:SetXY(624.838882446289, 103.016738891602);
        element:SetScaleX(0.17398608111351);
        element:SetScaleY(0.17398608111351);
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 10.08);
        effector:Play();
    
    
        -- Layer Layer_11
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/back1.jpg");
        element:SetName("Layer_11");
        compositionsky:AddElement(element);
        element:SetHotSpot(654, 412.5);
        element:SetParentElement(compositionsky);
        element:SetScaleX(0.93251968503937);
        element:SetScaleY(0.84251968503937);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 5.2);
        effector:SetKey(_TRACK_X, 0, 480.744327573196);
        effector:SetKey(_TRACK_Y, 0, 326.155789555475);
        effector:SetKey(_TRACK_X, 5.16, 521.851642518532);
        effector:SetKey(_TRACK_Y, 5.16, 326.155789555475);
        effector:SetKey(_TRACK_O, 0, 1);
        effector:SetKey(_TRACK_O, 5.16, 0);
        effector:Play();
    
    
        -- Layer Layer_12
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/back1.jpg");
        element:SetName("Layer_12");
        compositionsky:AddElement(element);
        element:SetHotSpot(654, 412.5);
        element:SetParentElement(compositionsky);
        element:SetScaleX(0.93251968503937);
        element:SetScaleY(0.84251968503937);
        element:SetAngle(0);
    
        effector = element:GetEffector();
        effector:SetLifeTime(5.16, 10.08);
        effector:SetKey(_TRACK_X, 5.16, 441.851642518532);
        effector:SetKey(_TRACK_Y, 5.16, 326.155789555475);
        effector:SetKey(_TRACK_X, 10.04, 480.744327573196);
        effector:SetKey(_TRACK_Y, 10.04, 326.155789555475);
        effector:SetKey(_TRACK_X, 15.2, 521.851642518532);
        effector:SetKey(_TRACK_Y, 15.2, 326.155789555475);
        effector:SetKey(_TRACK_O, 5.16, 0);
        effector:SetKey(_TRACK_O, 10.04, 1);
        effector:SetKey(_TRACK_O, 15.2, 0);
        effector:Play();
    
    
        -- Layer Layer_13
        local element = CreateCompositionElement("data/Texture/Scenes/Common/Ambient/back1.jpg");
        element:SetName("Layer_13");
        compositionsky:AddElement(element);
        element:SetHotSpot(654, 412.5);
        element:SetParentElement(compositionsky);
        element:SetScaleX(0.93251968503937);
        element:SetScaleY(0.84251968503937);
        element:SetAngle(0);
        element:SetOpacity(1);
    
        effector = element:GetEffector();
        effector:SetLifeTime(0, 10.08);
        effector:SetKey(_TRACK_X, 0, 441.851642518532);
        effector:SetKey(_TRACK_Y, 0, 326.155789555475);
        effector:SetKey(_TRACK_X, 10.04, 521.851642518532);
        effector:SetKey(_TRACK_Y, 10.04, 326.155789555475);
        effector:Play();
    
        compositionsky:Play();
    
        return compositionsky;
    end
    
    return createCompositionMelnica_opacity()
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/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('background',anim,512,384,98,0,128,96)
	local anim = CreateAnimation('data/Texture/Scenes/19_Mill_outside/Layers/Ambient/Melnica_opacity.png',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Melnica_opacity',anim,512,384,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/19_Mill_outside/Layers/Layer_door_open.jpg',0,0,87,151,1,0)
	anim:SetHotSpot(43,75)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_door_open',anim,444,467,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_close',anim,450,458,102,0,10,20)
	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_open',anim,450,458,103,0,10,20)
	local anim = CreateAnimation('data/Texture/Scenes/19_Mill_outside/Zoom_mill/ZOOM_mill.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('ZOOM_mill',anim,512,384,150,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/19_Mill_outside/Zoom_mill/Layer_button.png',0,0,88,76,1,0)
	anim:SetHotSpot(44,38)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('Layer_button',anim,675,484,151,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_mill',anim,654,462,101,0,10,10)
	local anim = CreateAnimation('data/Texture/Scenes/19_Mill_outside/Layers/Layer_notice_small.png',0,0,52,42,1,0)
	anim:SetHotSpot(26,21)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_notice_small',anim,152,445,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/19_Mill_outside/Zoom_notice/ZOOM_notice.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('ZOOM_notice',anim,512,384,160,0,1,1)
end
    
function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
