dofile('data/Scenes/15_Workshop_Mechanism.lua')

local zoom_door;

function OnSceneLoad(screen)
    LoadData(screen)
    LoadData_zoomZoneClock(screen)
    DefaultOnSceneLoad('data/Scenes/15_Workshop_Main.lua', 'quest', 'data/Scenes/13_Crimeplace_Main.lua')
    
    RegisterMonologObject('box_open', 'C_15_BOX_EMPTY_HINT');
    
    AddNoteToNotebook('BACK_OF_THE_HOUSE');
    
    play_field:IgnoreOnTestPoint('fly_anim_2');
    play_field:GetObject('box_open' ):SetOpacity(0);
    play_field:GetObject('door_open'):SetOpacity(0);
    play_field:GetObject('Clock_2'  ):SetOpacity(0);
    play_field:GetObject('Clock_3'  ):SetOpacity(0);
    play_field:GetObject('area_door_unlocked'):SetVisible(false);
    
    zoom_door = CreateZoomZone( 'area_door',
                                'ZoomZoneDoor',
                                'ZOOM_door',         true,
                                'layer_burned_wood', false,
                                'area_acid_apply',   true,
                                'area_ps',           false);
    
    play_field:GetObject('area_acid_apply'):GetAnimation():SetColor('0x01FFFFFF');
    play_field:GetObject('area_ps'        ):GetAnimation():SetColor('0x01FFFFFF');
    
    zoom_door.on_open = function()
--                            ShowMonolog('C_16_ACID_DOOR_HINT', 'C_16_ACID_DOOR_HINT')
                        end
    
    zoom_door.on_close = function()
                            if zoom_door.IsDisable() then
                                TimerDoString(  "play_field:GetObject('door_open'):ChangeOpacity(0, 1, OPEN_DOOR_TIME);"..
                                                "PlaySound('15_DoorOpen')"
                                                ,
                                                ZOOM_ZONE_APPEARING_TIME,
                                                play_field:GetTimer());
                                
                                LinkScene(  'area_door_unlocked',
                                            'CursorUp',
                                            'data/Scenes/15_Workshop_Room_HO.lua',
                                            true);
                            end
                         end
    
    zoom_clock = CreateZoomZoneClock()
    
    RegisterToolApplyInfo('15_screwdriver', 'area_4', nil, nil,                     ScrewdriverOnApply,
                                                                                    ScrewdriverOnApplied,
                                                                                    function()
                                                                                        ShowMonolog('C_15_ON_COVER_MECHANISM', 'C_15_ON_COVER_MECHANISM')
                                                                                    end);
                                                                                                                                    
    RegisterToolApplyInfo('15_wrench', {'area_1', 'area_2', 'area_3'}, nil, nil,    WrenchOnApply,
                                                                                    WrenchOnApplied,
                                                                                    function()
                                                                                        ShowMonolog('C_15_ON_COVER_MECHANISM', 'C_15_ON_COVER_MECHANISM')
                                                                                    end);
                                                                                    
    RegisterToolApplyInfo('13_stone', {'area_glass', 'Steklo_2'}, nil, nil,         StoneOnApply,
                                                                                    StoneOnApplied);
    
    RegisterToolFindInfo('15_acid', 'butil',    function()
                                                    zoom_clock.Disable()
                                                    AddNoteToNotebook('ASID_RECEIVED');
                                                end,
                                                function()
                                                    zoom_clock.Disable()
                                                end);
    
    RegisterToolApplyInfo('15_acid', 'area_acid_apply', nil, nil,   function(tool_name)
                                                                        zoom_door.SetObjectVisible('layer_burned_wood', true, 1);
                                                                        zoom_door.SetObjectVisible('area_acid_apply', false);
                                                                        
                                                                        play_field:GetObject('area_door'):SetVisible(false);
                                                                        play_field:GetObject('area_door_unlocked'):SetVisible(true);
                                                                        
                                                                        play_field:GetObject('area_ps'):AddParticleSystem(   'data/ParticleSystem/Acid.psi',
                                                                                                                             'SmokeParticle',
                                                                                                                             true);
                                                                        
                                                                        zoom_door.Disable();
                                                                        
                                                                        PlaySound('15_Acid');
                                                                        
                                                                        TimerDoString("CloseZoomDoor();", 2.5, play_field:GetTimer());
                                                                    end,
                                                                    function(tool_name)
                                                                        zoom_door.SetObjectVisible('layer_burned_wood', true);
                                                                        zoom_door.SetObjectVisible('area_acid_apply', false);
                                                                        
                                                                        play_field:GetObject('area_door'):SetVisible(false);
                                                                        play_field:GetObject('area_door_unlocked'):SetVisible(true);
                                                                        play_field:GetObject('door_open'):SetOpacity(1);
                                                                        
                                                                        zoom_door.Disable();
                                                                        
                                                                        LinkScene(  'area_door_unlocked',
                                                                                    'CursorUp',
                                                                                    'data/Scenes/15_Workshop_Room_HO.lua',
                                                                                    true);
                                                                    end);
    
    RegisterActiveObject('area_box',    function(obj_name)
                                            play_field:GetObject(obj_name):SetVisible(false);
                                            play_field:GetObject('box_open'):ChangeOpacity(0, 1, OPEN_DOOR_TIME);
                                            
                                            PlaySound('15_OpenBox')
                                        end,
                                        function(obj_name)
                                            play_field:GetObject(obj_name):SetVisible(false);
                                            play_field:GetObject('box_open'):SetOpacity(1);
                                        end)
    
    LinkScene(  'area_ho_floor',
                'CursorGlass',
                'data/Scenes/15_Workshop_Floor_HO.lua',
                true);
                
    LinkScene(  'area_cubboard',
                'CursorGlass',
                'data/Scenes/15_Workshop_Cupboard_HO.lua',
                true);
    
    if HasGameState('ToolFound', '15_ball') then
        AddNoteToNotebook('BALL_RECEIVED');
    end
        
    UnRegisterQuestObjects('area_box')
end

function CloseZoomDoor()
    zoom_door.SetVisible(false);
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_door'
    or obj_name == 'area_acid_apply'
    then
        ShowMonolog('C_16_ACID_DOOR_HINT', 'C_16_ACID_DOOR_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

--------------------------------------------------------------------------------
-- 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/15_Workshop/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_ho_floor',anim,375,496,101,0,15,10)
	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_cubboard',anim,425,248,101,0,12,20)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_main/Layers/door_open.jpg',0,0,119,234,1,0)
	anim:SetHotSpot(59,117)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('door_open',anim,605,313,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_main/Layers/box_open.jpg',0,0,54,84,1,0)
	anim:SetHotSpot(27,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('box_open',anim,254,327,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',anim,607,289,102,0,13,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_unlocked',anim,607,289,102,0,13,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_box',anim,250,326,102,0,10,10)
	local anim = CreateAnimation('data/Texture/Scenes/05_Gendarmery/Zone_wart/Animations/fly_anim.png',0,0,217,217,8,12)
	anim:SetHotSpot(108,108)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fly_anim_2',anim,672,315,101,0,0.9,0.9)
	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('candle_flame2',anim,510,230,102,0,0.6,0.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_clock',anim,125,30,104,0,10,10)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_main/Layers/Clock_1.png',0,0,63,48,1,0)
	anim:SetHotSpot(31,24)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Clock_1',anim,124,31,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_main/Layers/Clock_2.png',0,0,63,48,1,0)
	anim:SetHotSpot(31,24)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Clock_2',anim,124,31,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_main/Layers/Clock_3.png',0,0,63,48,1,0)
	anim:SetHotSpot(31,24)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Clock_3',anim,124,31,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_main/Zoom_door/ZOOM_door.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('ZOOM_door',anim,512,384,170,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/15_Workshop/Zone_main/Zoom_door/layer_burned_wood.jpg',0,0,314,480,1,0)
	anim:SetHotSpot(157,240)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_burned_wood',anim,675,384,171,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('0xFFFFFFFF')
	screen:CreateObject('area_acid_apply',anim,667,397,172,0,2,2.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('0xFFFFFFFF')
	screen:CreateObject('area_ps',anim,660,426,173,0,20,10)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
