dofile('data/Scripts/scenes/13_junk_shop/anim/13_junk_shop_anim_bg.lua')

class 'l_13_junk_shop' (LevelEventHandler)

function l_13_junk_shop:__init(name)
	LevelEventHandler.__init(self, name)
	
	-- animations ----------------------------------
	self.anim_bg = AnimationBundle(Loader_13_BG_Animations(Object('bg')))
	self.anim_bg:PlayAnimation('bg')
	
	-- link scenes ---------------------------------
	LinkScene('area_link_08', 'CursorDoorDown',    'l_08_street')
	LinkScene('area_link_14', 'CursorDoorRightUp', 'l_14_village')
	
	-- zoom zones ----------------------------------
	
	ObjectVisible('area_fade_on_scene', false)
	ObjectOpacity('layer_junkman2', 0)
	
	self:create_cutscene()
end

function l_13_junk_shop:create_cutscene()
    if HasActionCompletedState('cutsceneShown') then
        self.mouseBlocker:Push()
        
        ObjectOpacity('layer_legran',   0)
        ObjectOpacity('layer_junkman',  0)
        ObjectOpacity('layer_junkman2', 1)
        ObjectVisible('area_fade_on_scene', true)
        
        self.timer:Add( function()
                            self.mouseBlocker:Pop()
                            ShowEndOfSurvayDialog()
                        end,
                        0.5)
    else
        do
            self.cutscene_video = CreateVideoEntity('data/Video/Scenes/13_junk_shop/13_cutscene.ogg', '', false)
            self.cutscene_video:AttachTo(Object('bg'))
            self.cutscene_video:SetZ(100)
            self.cutscene_video:SetScale(SCR_W/800)
            self.cutscene_video:SetXY(0, 0)
            self.cutscene_video:SetLoop(false)
            --self.cutscene_video:SetOnFirstFrame()
        end
        
        self.mouseBlocker:Push()
        self.timer:Add( function()
                            self.mouseBlocker:Pop()
                            
                            local delay = 0.25
                            local time  = 15
                            
                            SetCutSceneMode(delay + time)
                            StopAmbientMusic()
                            
                            self.timer:Add( function()
                                                self.cutscene_video:PlayVideo()
                                                MakeSoundEntity('13_cutscene'):PlaySound(false)
                                                
                                                local fadeTime = 0.2
                                                self.timer:Add( function()
                                                                    ObjectOpacity('layer_legran',   0)
                                                                    ObjectOpacity('layer_junkman',  0)
                                                                    ObjectOpacity('layer_junkman2', 1)
                                                                    ObjectVisible('area_fade_on_scene', true)
                                                                    
                                                                    self.cutscene_video:ChangeOpacity(1, 0, fadeTime)
                                                                    
                                                                    self.timer:Add( function()
                                                                                        AddActionCompletedState('cutsceneShown')
                                                                                        
                                                                                        ShowEndOfSurvayDialog()
                                                                                        PlayRandomAmbientMusic()
                                                                                    end,
                                                                                    fadeTime)
                                                                end,
                                                                time - fadeTime)
                                            end,
                                            delay)
                        end,
                        1)
    end
end

function l_13_junk_shop:OnUpdate(dt)
end

function l_13_junk_shop:OnAllItemsFound()
end

function l_13_junk_shop:OnObjectMouseEnter(object)
end

function l_13_junk_shop:OnObjectMouseLeave(object)
end

function l_13_junk_shop:OnScreenObjectMouseDown(object, key)
end

function l_13_junk_shop:OnObjectMouseDownProcessed(is_wrong_click)
end

function l_13_junk_shop:OnMouseMove(previous_pos, current_pos)
end

function l_13_junk_shop:OnObjectMouseUp(object)
end

function l_13_junk_shop:OnObjectFound(object)
end

function l_13_junk_shop:OnToolFound(tool)
end

function l_13_junk_shop:OnToolApply(tool, object)
end

function l_13_junk_shop:OnToolAddToInventory(tool)
end

function l_13_junk_shop:OnObjectReachPanel(object)
end

function l_13_junk_shop:OnButtonPress(title)
end

function l_13_junk_shop:OnSetTool(tool)
end

function l_13_junk_shop:OnLoaded()
end

function l_13_junk_shop:OnDestroy()
end

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function l_13_junk_shop:LoadData(screen)
	local anim
	anim = CreateAnimation('data/Texture/Scenes/13_junk_shop/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_link_08',anim,512,700,100,0,128,17)
	
	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_14',anim,899,307,100,0,10,30)
	
	anim = CreateAnimation('data/Texture/Scenes/13_junk_shop/main/layers/layer_junkman.png',0,0,199,373,1,0)
	anim:SetHotSpot(99,186)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_junkman',anim,309,391,70,0,1,1)
	
	anim = CreateAnimation('data/Texture/Scenes/13_junk_shop/main/layers/layer_legran.png',0,0,141,299,1,0)
	anim:SetHotSpot(70,149)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_legran',anim,514,376,70,0,1,1)
	
	anim = CreateAnimation('data/Texture/Scenes/13_junk_shop/main/layers/layer_junkman2.PNG',0,0,320,344,1,0)
	anim:SetHotSpot(160,172)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_junkman2',anim,279,441,70,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('0xFF000000')
	screen:CreateObject('area_fade_on_scene',anim,512,384,90,0,128,96)
	
end
-- CLEAR_ON_SAVE_END
