local zoom_aqua;
local zoom_mezzanine;

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/14_Corridor_Room.lua', 'quest', 'data/Scenes/14_Corridor_Main.lua')
    
    play_field:IgnoreOnTestPoint('Fishes_anim');
    play_field:IgnoreOnTestPoint('Bearing_shadow');
    
    play_field:GetObject('Layer_carpet_01'):SetOpacity(0.);
    play_field:GetObject('Layer_carpet_02'):SetOpacity(0.);
    play_field:GetObject('Layer_hammer'   ):SetOpacity(0.);
    play_field:GetObject('Layer_ladder'   ):SetOpacity(0.);
    play_field:GetObject('Wolf_1'         ):SetOpacity(0.);
    play_field:GetObject('Wolf_2'         ):SetOpacity(0.);
    play_field:GetObject('Wolf_3'         ):SetOpacity(0.);
    play_field:GetObject('Wolf_4'         ):SetOpacity(0.);
    play_field:GetObject('Wolf_5'         ):SetOpacity(0.);
    play_field:GetObject('area_open_cache'):SetVisible(false);
    play_field:GetObject('area_mezzanine' ):SetVisible(false);
    
    zoom_aqua = CreateZoomZone( 'area_aquarium',
                                'CloseZoneAqua',
                                'ZOOM_aquarium',    true,
                                'Fishes_anim',      true,
                                'Bearing_shadow',   true,
                                'Bearing',          true,
                                'area_brush_apply', false);
    
    zoom_mezzanine = CreateZoomZone('area_mezzanine',
                                    'CloseZoneMezzanine',
                                    'ZOOM_mezzanine',   true,
                                    'Layer_brush',      true);
    
    RegisterToolApplyInfo('06_scoop_net', 'Bearing', nil, nil,          function(tool_name)
                                                                            zoom_aqua.SetObjectVisible('Bearing_shadow',   false);
                                                                            zoom_aqua.SetObjectVisible('Bearing',          false);
                                                                            zoom_aqua.SetObjectVisible('area_brush_apply', true);
                                                                            zoom_aqua.SetVisible(false);
                                                                            
                                                                            FindTool('14_bearing');
                                                                            AddNoteToNotebook('UPSTAIRS_AQUARIUM');
                                                                        end,
                                                                        function(tool_name)
                                                                            zoom_aqua.SetObjectVisible('Bearing_shadow',   false);
                                                                            zoom_aqua.SetObjectVisible('Bearing',          false);
                                                                            zoom_aqua.SetObjectVisible('area_brush_apply', true);
                                                                        end,
                                                                        function()
                                                                            ShowMonolog('C_14_SCOOP_NET_APPLY_HINT', 'C_14_SCOOP_NET_APPLY_HINT');
                                                                        end);
    
    RegisterToolApplyInfo('16_scalpel', 'area_scalpel_apply', nil, nil, function(tool_name)
                                                                            play_field:GetObject('area_scalpel_apply'):SetVisible(false);
                                                                            play_field:GetObject('area_open_cache'   ):SetVisible(true);
                                                                            
                                                                            play_field:GetObject('Layer_carpet_01'):ChangeOpacity(0., 1., 0.3);
                                                                            
                                                                            PlaySound('14_CutCarpet');
                                                                        end,
                                                                        function(tool_name)
                                                                            play_field:GetObject('area_scalpel_apply'):SetVisible(false);
                                                                            play_field:GetObject('area_open_cache'   ):SetVisible(true);
                                                                            
                                                                            play_field:GetObject('Layer_carpet_01'):SetOpacity(1.);
                                                                        end,
                                                                        function()
                                                                            ShowMonolog('C_14_SCALPEL_APPLY_HINT', 'C_14_SCALPEL_APPLY_HINT');
                                                                        end);
    
    RegisterActiveObject('area_open_cache',                             function(obj_name)
                                                                            play_field:GetObject('area_open_cache'):SetVisible(false);
                                                                            
                                                                            play_field:GetObject('Layer_carpet_02'):ChangeOpacity(0., 1., 0.3);
                                                                            play_field:GetObject('Layer_hammer'   ):ChangeOpacity(0., 1., 0.3);
                                                                            
                                                                            PlaySound('14_OpenCache');
                                                                        end,
                                                                        function(obj_name)
                                                                            play_field:GetObject('area_open_cache'):SetVisible(false);
                                                                            
                                                                            play_field:GetObject('Layer_carpet_02'):SetOpacity(1);
                                                                            play_field:GetObject('Layer_hammer'   ):SetOpacity(1);
                                                                        end);
    
    RegisterToolFindInfo('14_hammer', 'Layer_hammer',                   function(tool_name)
                                                                            local hammer = play_field:GetObject('Layer_hammer');
                                                                            hammer:DestroyChildren();
                                                                            hammer:ChangeOpacity(hammer:GetOpacity(), 0, 0.2);
                                                                        end,
                                                                        function(tool_name)
                                                                            play_field:GetObject('Layer_hammer'):SetOpacity(0);
                                                                        end);
    
    RegisterToolApplyInfo('18_ladder', 'area_ladder_apply', nil, nil,   function(tool_name)
                                                                            play_field:GetObject('area_ladder_apply'):SetVisible(false);
                                                                            play_field:GetObject('area_mezzanine'   ):SetVisible(true);
                                                                            play_field:GetObject('Layer_ladder'     ):ChangeOpacity(0., 1., 0.4);
                                                                            
                                                                            PlaySound('14_PlaceLadder');
                                                                        end,
                                                                        function(tool_name)
                                                                            play_field:GetObject('area_ladder_apply'):SetVisible(false);
                                                                            play_field:GetObject('area_mezzanine'   ):SetVisible(true);
                                                                            play_field:GetObject('Layer_ladder'     ):SetOpacity(1.);
                                                                        end,
                                                                        function()
                                                                            ShowMonolog('C_14_LADDER_APPLY_HIMT', 'C_14_LADDER_APPLY_HIMT')
                                                                        end);
    
    RegisterToolFindInfo('14_brush', 'Layer_brush',                     function(tool_name)
                                                                            zoom_mezzanine.Disable();
                                                                        end,
                                                                        function(tool_name)
                                                                            zoom_mezzanine.Disable();
                                                                        end);
    
    RegisterToolApplyInfo('14_brush', 'area_brush_apply', nil, nil,     function(tool_name)
                                                                            zoom_aqua.SetVisible(false);
                                                                            zoom_aqua.Disable();
                                                                            
                                                                            FindTool('14_brush_wet');
                                                                        end,
                                                                        function(tool_name)
                                                                            zoom_aqua.Disable();
                                                                        end,
                                                                        function()
                                                                            ShowMonolog('C_14_BRUSH_APPLY_HINT', 'C_14_BRUSH_APPLY_HINT')
                                                                        end);
    
    RegisterToolApplyInfo('14_brush_wet', { 'area_pict',
                                            'Wolf_1',
                                            'Wolf_2',
                                            'Wolf_3',
                                            'Wolf_4' }, nil, nil,       function(tool_name, obj_name)
                                                                            local fade_time = 0.2;
                                                                            
                                                                            if obj_name == 'area_pict' then
                                                                                play_field:GetObject('Wolf_1'):ChangeOpacity(0., 1, fade_time);
                                                                                play_field:GetObject('area_pict'):SetVisible(false);
                                                                                
                                                                                PlaySound('14_BrushApply1')
                                                                                
                                                                            elseif obj_name == 'Wolf_1' then
                                                                                local pict = play_field:GetObject('Wolf_1');
                                                                                pict:DestroyChildren();
                                                                                pict:ChangeOpacity(pict:GetOpacity(), 0, fade_time);
                                                                                
                                                                                play_field:GetObject('Wolf_2'):ChangeOpacity(0, 1, fade_time);
                                                                                
                                                                                PlaySound('14_BrushApply2')
                                                                                
                                                                            elseif obj_name == 'Wolf_2' then
                                                                                local pict = play_field:GetObject('Wolf_2');
                                                                                pict:DestroyChildren();
                                                                                pict:ChangeOpacity(pict:GetOpacity(), 0, fade_time);
                                                                                
                                                                                play_field:GetObject('Wolf_3'):ChangeOpacity(0, 1, fade_time);
                                                                                
                                                                                PlaySound('14_BrushApply1')
                                                                                
                                                                            elseif obj_name == 'Wolf_3' then
                                                                                local pict = play_field:GetObject('Wolf_3');
                                                                                pict:DestroyChildren();
                                                                                pict:ChangeOpacity(pict:GetOpacity(), 0, fade_time);
                                                                                
                                                                                play_field:GetObject('Wolf_4'):ChangeOpacity(0, 1, fade_time);
                                                                                
                                                                                PlaySound('14_BrushApply2')
                                                                                
                                                                            elseif obj_name == 'Wolf_4' then
                                                                                local pict = play_field:GetObject('Wolf_4');
                                                                                pict:DestroyChildren();
                                                                                pict:ChangeOpacity(pict:GetOpacity(), 0, fade_time);
                                                                                
                                                                                play_field:GetObject('Wolf_5'):ChangeOpacity(0, 1, fade_time);
                                                                                
                                                                                PlaySound('14_BrushApply1')
                                                                            end
                                                                        end,
                                                                        function(tool_name, obj_name)
                                                                            if obj_name == 'area_pict' then
                                                                                play_field:GetObject('Wolf_1'):SetOpacity(1);
                                                                                play_field:GetObject('area_pict'):SetVisible(false);
                                                                                
                                                                            elseif obj_name == 'Wolf_1' then
                                                                                play_field:GetObject('Wolf_1'):SetOpacity(0);
                                                                                play_field:GetObject('Wolf_2'):SetOpacity(1);
                                                                                
                                                                            elseif obj_name == 'Wolf_2' then
                                                                                play_field:GetObject('Wolf_2'):SetOpacity(0);
                                                                                play_field:GetObject('Wolf_3'):SetOpacity(1);
                                                                                
                                                                            elseif obj_name == 'Wolf_3' then
                                                                                play_field:GetObject('Wolf_3'):SetOpacity(0);
                                                                                play_field:GetObject('Wolf_4'):SetOpacity(1);
                                                                                
                                                                            elseif obj_name == 'Wolf_4' then
                                                                                play_field:GetObject('Wolf_4'):SetOpacity(0);
                                                                                play_field:GetObject('Wolf_5'):SetOpacity(1);
                                                                                
                                                                            elseif obj_name == nil then
                                                                                play_field:GetObject('area_pict'):SetVisible(false);
                                                                                play_field:GetObject('Wolf_5'):SetOpacity(1);
                                                                            end
                                                                            
                                                                        end,
                                                                        function(tool_name, obj_name)
                                                                            if obj_name == 'area_pict' then
                                                                                ShowMonolog('C_14_BRUSH_WET_FIRST_APPLY_HINT', 'C_14_BRUSH_WET_FIRST_APPLY_HINT');
                                                                            else
                                                                                ShowMonolog('C_14_BRUSH_WET_APPLY_HINT', 'C_14_BRUSH_WET_APPLY_HINT');
                                                                            end
                                                                        end);
    
    RegisterToolFindInfo('15_wolf', 'Wolf_5',                           function(tool_name)
                                                                            local pict = play_field:GetObject('Wolf_5');
                                                                            pict:DestroyChildren();
                                                                            pict:ChangeOpacity(pict:GetOpacity(), 0, 0.1);
                                                                        end,
                                                                        function(tool_name)
                                                                            play_field:GetObject('Wolf_5'):SetOpacity(0);
                                                                        end);
    
    RegisterWrongApplyDialog('14_brush', 'area_pict', 'C_14_HINT_NEED_WET_BRUSH');
end

function CloseZoomAqua()
    if zoom_aqua.IsVisible() then
        zoom_aqua.SetVisible(false);
    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 == 'ZOOM_aquarium' then
        ShowMonolog('C_14_AQUARIUM_HINT', 'C_14_AQUARIUM_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/14_Corridor/Zone_room/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/14_Corridor/Zone_room/Animations/fishes_small.png',0,0,127,61,56,12)
	anim:SetHotSpot(63,30)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('fishes_small',anim,859,388,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Animations/driftweed_small.png',0,0,26,84,25,12)
	anim:SetHotSpot(13,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('driftweed_small',anim,841,385,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Animations/driftweed2_small.png',0,0,40,63,25,12)
	anim:SetHotSpot(20,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('driftweed2_small',anim,877,394,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Layers/aquarium.png',0,0,132,93,1,0)
	anim:SetHotSpot(66,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('aquarium',anim,861,379,104,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_aquarium',anim,862,374,106,0,1.2,0.87)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Zoom_aquarium/ZOOM_aquarium.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('ZOOM_aquarium',anim,512,384,150,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Zoom_aquarium/Fishes_anim.png',0,0,303,325,25,8)
	anim:SetHotSpot(151,162)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('Fishes_anim',anim,527,370,153,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Zoom_aquarium/Bearing_shadow.png',0,0,125,116,1,0)
	anim:SetHotSpot(62,58)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('Bearing_shadow',anim,476,363,151,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Zoom_aquarium/Bearing.png',0,0,78,83,1,0)
	anim:SetHotSpot(39,41)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('Bearing',anim,484,379,152,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Layers/Layer_carpet_01.png',0,0,214,65,1,0)
	anim:SetHotSpot(107,32)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_carpet_01',anim,487,582,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Layers/Layer_carpet_02.png',0,0,168,110,1,0)
	anim:SetHotSpot(84,55)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_carpet_02',anim,576,573,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Layers/Layer_hammer.png',0,0,77,32,1,0)
	anim:SetHotSpot(38,16)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_hammer',anim,539,592,103,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_scalpel_apply',anim,520,573,104,0,2.05,0.87)
	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_open_cache',anim,533,584,105,0,0.94,0.56)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Layers/Layer_ladder.png',0,0,347,394,1,0)
	anim:SetHotSpot(173,197)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Layer_ladder',anim,173,443,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_ladder_apply',anim,288,392,102,-7,0.93,2.31)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Zoom_mezzanine/ZOOM_mezzanine.jpg',0,0,640,480,1,0)
	anim:SetHotSpot(320,240)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('ZOOM_mezzanine',anim,512,384,160,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Zoom_mezzanine/Layer_brush.png',0,0,592,183,1,0)
	anim:SetHotSpot(296,91)
	anim:SetBlendMode(2)
	anim:SetColor('0x00FFFFFF')
	screen:CreateObject('Layer_brush',anim,512,384,161,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_mezzanine',anim,242,204,103,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('0x00FFFFFF')
	screen:CreateObject('area_brush_apply',anim,526,382,155,0,3.09,3.09)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Layers/Wolf_1.jpg',0,0,99,100,1,0)
	anim:SetHotSpot(49,50)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Wolf_1',anim,518,296,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Layers/Wolf_2.jpg',0,0,99,100,1,0)
	anim:SetHotSpot(49,50)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Wolf_2',anim,518,296,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Layers/Wolf_3.jpg',0,0,99,100,1,0)
	anim:SetHotSpot(49,50)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Wolf_3',anim,518,296,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Layers/Wolf_4.jpg',0,0,99,100,1,0)
	anim:SetHotSpot(49,50)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Wolf_4',anim,518,296,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/14_Corridor/Zone_room/Layers/Wolf_5.jpg',0,0,99,100,1,0)
	anim:SetHotSpot(49,50)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Wolf_5',anim,518,296,105,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_pict',anim,517,298,106,0,14,14)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
