dofile('data/Scripts/scenes/03_yard/anim/03_yard_anim_bg.lua')
--dofile('data/Scripts/scenes/03_yard/anim/03_yard_anim_z_barrel.lua')
dofile('data/Scripts/scenes/03_yard/anim/03_yard_anim_z_dovecote.lua')

class 'l_03_yard' (LevelEventHandler)

function l_03_yard:__init(name)
	LevelEventHandler.__init(self, name)
	
	ObjectVisible('area_link_04', false)
	
	-- animations ----------------------------------
	self.anim_bg = AnimationBundle(Loader_03_BG_Animations(Object('bg')))
	self.anim_bg:GetAnimation('door'):SetVisible(true)
	self.anim_bg:PlayAnimation('bg')
	
	-- link scenes ---------------------------------
	LinkScene('area_link_02', 'CursorDoorDown', 'l_02_legran_gate')
	LinkScene('area_link_04', 'CursorDoorUp',   'l_04_guest_room')
	
	-- zoom zones ----------------------------------
	
	-- zoom barrel
	do
	    CreateSmartZoomZone('barrel')
	    ---------------------
	    
	    --self.anim_barrel = AnimationBundle(Loader_03_Zoom_Barrel_Animations(Object('z_barrel_bg')))
	    --self.anim_barrel:GetAnimation('action'):SetVisible(true)
	    ---------------------
	    
	    ObjectVisible('area_find_zb_opener', false)
	    ---------------------
	    
	    local leafOffset = Vector(-70, -10)
	    
	    local function on_click_leaf(e)
	        ObjectVisible(e.target, false)
	        
	        --local compos = self.anim_barrel:GetAnimation('action')
	        
	        if e.save then
	            --compos:Rewind(true)
	            Object('z_barrel_leaf'):Move(leafOffset.x, leafOffset.y, 0)
	            ObjectVisible('area_find_zb_opener', true)
	        else
	            local time = 0.5
	            --compos:Play()
	            Object('z_barrel_leaf'):Move(leafOffset.x, leafOffset.y, time)
	            MakeSoundEntity('03_click_leaf'):PlaySound(false)
	            
	            self.timer:Add( function()
	                                ObjectVisible('area_find_zb_opener', true)
	                            end,
	                            time) --compos:GetDuration())
	        end
	    end
	    ---------------------
	    
	    local function on_find_opener(e)
	    end
	    ---------------------
	    
	    RegisterActiveObject('area_click_zb_leaf', on_click_leaf)
	    RegisterToolFindInfo('03_opener', 'area_find_zb_opener', on_find_opener)
	end
	
	-- zoom doghouse
	do
	    CreateSmartZoomZone('doghouse')
	    ---------------------
	    
	    ObjectOpacity('z_doghouse_after', 0)
	    ObjectVisible('area_find_zdh_mg_03_01_item_02', false)
	    ---------------------
	    
	    self.zoom_doghouse.on_open = function()
	        if not HasActionCompletedState('dog_clicked') then
	            if not self.dog_idle_video then
                    self.dog_idle_video = CreateVideoEntity('data/Video/Scenes/03_yard/03_dog_idle.ogg', '', false)
                    self.dog_idle_video:AttachTo(Object('z_doghouse_bg'))
                    self.dog_idle_video:SetZ(5)
                    self.dog_idle_video:SetXY(-2, 92)
                    self.dog_idle_video:SetLoop(true)
                end
                
                self.dog_idle_video:PlayVideo()
	        end
	    end
	    ---------------------
	    
	    self.zoom_doghouse.on_close = function()
	        self.timer:Add( function()
	                            if not HasActionCompletedState('dog_clicked') then
	                                self.dog_idle_video:StopVideo()
	                            end
	                        end,
	                        ZOOM_ZONE_APPEARING_TIME)
	    end
	    ---------------------
	    
	    local function on_click_dog(e)
	        ObjectVisible(e.target, false)
	        
	        ObjectOpacity('z_doghouse_after',  1)
	        ObjectOpacity('z_doghouse_before', 0)
	        
	        if e.save then
	            ObjectVisible('area_find_zdh_mg_03_01_item_02', true)
	        else
	            AddActionCompletedState('dog_clicked')
	            
	            do
                    self.dog_drinking_video = CreateVideoEntity('data/Video/Scenes/03_yard/03_dog_drinking.ogg', '', false)
                    self.dog_drinking_video:AttachTo(Object('z_doghouse_bg'))
                    self.dog_drinking_video:SetZ(5)
                    self.dog_drinking_video:SetXY(-69, 64)
                    self.dog_drinking_video:SetLoop(false)
                    self.dog_drinking_video:SetHideOnStop(false)
                end
                
                self.dog_drinking_video:PlayVideo()
                self.dog_idle_video:StopVideo()
                
                MakeSoundEntity('03_click_dog'):PlaySound(false)
                
                self.mouseBlocker:Push()
                self.timer:Add( function()
                                    self.mouseBlocker:Pop()
                                    self.dog_drinking_video:SetHideOnStop(true)
                                    self.dog_drinking_video:StopVideo()
                                    
                                    ObjectVisible('area_find_zdh_mg_03_01_item_02', true)
                                end,
                                self.dog_drinking_video:GetDuration())
	        end
	    end
	    ---------------------
	    
	    local function on_find_zdh_mg_03_01_item_02(e)
	    end
	    ---------------------
	    
	    RegisterActiveObject('area_click_zdh_dog', on_click_dog)
	    RegisterToolFindInfo('MG_03_01_item_02', 'area_find_zdh_mg_03_01_item_02', on_find_zdh_mg_03_01_item_02)
	end
	
	-- zoom dovecote
	do
	    CreateSmartZoomZone('dovecote')
	    ---------------------
	    
	    self.anim_dovecote = AnimationBundle(Loader_03_Zoom_Dovecote_Animations(Object('z_dovecote_bg')))
	    self.anim_dovecote:GetAnimation('action'):SetClippingRect(self.zoom_dovecote:GetClippingInfo())
	    ---------------------
	    
	    if not IsToolFound('MG_03_01_item_03') then
	        self.dove_idle_sound = MakeSoundEntity('03_dove_idle')
	    end
	    ---------------------
	    
	    ObjectVisible('area_find_zdv_mg_03_01_item_03', false)
	    ---------------------
	    
	    self.zoom_dovecote.on_open = function()
	        if self.dove_idle_sound then
	            self.dove_idle_sound:PlaySound(true)
	        end
	        
	        if not IsToolApplied('01_bag_of_millet') then
	            if not self.dove_idle_video then
                    self.dove_idle_video = CreateVideoEntity('data/Video/Scenes/03_yard/03_dove_idle.ogg', '', true)
                    self.dove_idle_video:AttachTo(Object('z_dovecote_bg'))
                    self.dove_idle_video:SetZ(100)
                    self.dove_idle_video:SetXY(80, 0)
                    self.dove_idle_video:SetLoop(true)
                    self.dove_idle_video:PlayVideo()
                end
            else
                if not self.dove_idle2_video then
                    self.dove_idle2_video = CreateVideoEntity('data/Video/Scenes/03_yard/03_dove_idle2.ogg', '', true)
                    self.dove_idle2_video:AttachTo(Object('z_dovecote_bg'))
                    self.dove_idle2_video:SetZ(100)
                    self.dove_idle2_video:SetXY(-73, 15)
                    self.dove_idle2_video:SetLoop(true)
                    self.dove_idle2_video:PlayVideo()
                end
	        end
	    end
	    ---------------------
	    
	    self.zoom_dovecote.on_close = function()
	        if self.dove_idle_sound then
	            self.dove_idle_sound:StopSound()
	        end
	    end
	    ---------------------
	    
	    local function on_apply_bag_of_millet(e)
	        ObjectVisible(e.target, false)
	        
	        if e.save then
	            self.anim_dovecote:GetAnimation('action'):SetVisible(true)
	            self.anim_dovecote:GetAnimation('action'):Rewind(true)
	            
	            ObjectVisible('area_find_zdv_mg_03_01_item_03', true)
	        else
	            self.anim_dovecote:PlayAnimation('action')
	            self.mouseBlocker:Push()
	            
	            MakeSoundEntity('03_apply_bag_of_millet'):PlaySound(false)
	            
	            self.timer:Add( function()
                                    self.dove_move_video = CreateVideoEntity('data/Video/Scenes/03_yard/03_dove_move.ogg', '', true)
                                    self.dove_move_video:AttachTo(Object('z_dovecote_bg'))
                                    self.dove_move_video:SetZ(100)
                                    self.dove_move_video:SetXY(-8, -17)
                                    self.dove_move_video:SetLoop(false)
                                    
                                    self.dove_idle2_video = CreateVideoEntity('data/Video/Scenes/03_yard/03_dove_idle2.ogg', '', true)
                                    self.dove_idle2_video:AttachTo(Object('z_dovecote_bg'))
                                    self.dove_idle2_video:SetZ(100)
                                    self.dove_idle2_video:SetXY(-73, 15)
                                    self.dove_idle2_video:SetLoop(true)
                                    
                                    self.dove_move_video:PlayVideo()
                                    self.dove_idle_video:StopVideo()
                                    
                                    local fade_time = 1
                                    self.timer:Add( function()
                                                        self.dove_idle2_video:PlayVideo()
                                                        self.dove_idle2_video:ChangeOpacity(0, 1, fade_time)
                                                        
                                                        self.timer:Add( function()
                                                                            self.mouseBlocker:Pop()
                                                                            ObjectVisible('area_find_zdv_mg_03_01_item_03', true)
                                                                        end,
                                                                        fade_time)
                                                    end,
                                                    self.dove_move_video:GetDuration() - fade_time)
                                end,
                                self.anim_dovecote:GetAnimation('action'):GetDuration())
	        end
	    end
	    ---------------------
	    
	    local function on_find_zdv_mg_03_01_item_03(e)
	    end
	    ---------------------
	    
	    RegisterToolApplyInfo('01_bag_of_millet', 'area_apply_zdv_bag_of_millet', on_apply_bag_of_millet, 'BBT_03_NEED_APPLY_BAG_OF_MILLET')
	    RegisterToolFindInfo('MG_03_01_item_03', 'area_find_zdv_mg_03_01_item_03', on_find_zdv_mg_03_01_item_03)
	end
	
	-- zoom door
	do
	    self.zoom, self.zoneObj = CreateSmartZoomZone( 'door' )
    end
end

function l_03_yard:OnUpdate(dt)
end

function l_03_yard:OnAllItemsFound()
end

function l_03_yard:OnObjectMouseEnter(object)
end

function l_03_yard:OnObjectMouseLeave(object)
end

function l_03_yard:OnScreenObjectMouseDown(object, key)
end

function l_03_yard:OnObjectMouseDownProcessed(is_wrong_click)
end

function l_03_yard:OnMouseMove(previous_pos, current_pos)
end

function l_03_yard:OnObjectMouseUp(object)
end

function l_03_yard:OnObjectFound(object)
end

function l_03_yard:OnToolFound(tool)
end

function l_03_yard:OnToolApply(tool, object)
end

function l_03_yard:OnToolAddToInventory(tool)
end

function l_03_yard:OnObjectReachPanel(object)
end

function l_03_yard:OnButtonPress(title)
end

function l_03_yard:OnSetTool(tool)
end

function l_03_yard:OnLoaded()
end

function l_03_yard:OnDestroy()
end

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function l_03_yard:LoadData(screen)
	local anim
	anim = CreateAnimation('data/Texture/Scenes/03_Yard/main/layers/bg.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bg',anim,512,384,50,0,1,1)
	
	anim = CreateAnimation('data/Texture/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_zoom_door',anim,840,292,100,0,20,20)
	
	anim = CreateAnimation('data/Texture/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_link_02',anim,512,700,100,0,128,17)
	
	anim = CreateAnimation('data/Texture/Common/area_round.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_zoom_barrel',anim,443,470,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/Common/area_round.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,83)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_zoom_doghouse',anim,197,488.08,100,0,1.27,1.32)
	
	anim = CreateAnimation('data/Texture/Common/area_round.png',0,0,128,128,1,0)
	anim:SetHotSpot(64,64)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_zoom_dovecote',anim,105,303,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_link_04',anim,838,288,110,0,12,20)
	
	anim = CreateAnimation('data/Texture/Scenes/03_yard/main/layers/layer_dog.png',0,0,108,62,1,0)
	anim:SetHotSpot(54,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_dog',anim,232,514,51,0,1,1)
	
end
-- CLEAR_ON_SAVE_END
