
.namespace VideoPlayer


g_curvideo = nil
g_nextdestination = nil
g_vid = nil
g_videoskipped = false

function OnEnable()
	if DebugOptions.interfaceVersion == 2 then
		LeftInterface.Enabled = false
	else
		SearchInterface.Enabled = false
	end
	OPInput.RegisterListener(self , EVENT_MOUSE_LDOWN)
	self.Flags_AcceptAllInput = true
	Search_ShowObject.Flags_Visible = false
	g_videoskipped = false
	
	SetVariables("VideoMode",true)
	
	Closeup_SkipButton_Indication.Enabled = true
end

function FinishVideo()
	if IsEqualVariables("CurrentGamePhase","Video") then
		OnVideoEnd()
		g_videoskipped  = true
		return true
	end
end

function PlayVideo(videoname,nextdestination)


	g_curvideo = videoname
	g_nextdestination = nextdestination
	NavigationManager.SwitchTo(nil,"VideoPlayer")
	AssertPopup(type(videoname) == "string" , "prob param" )
end

function OnEnter_Gen()
	OPLog.Log("onenter "..self.Name)
	--on fait un switch sur le video player
	-- if not OPCore.EditorMode() then
		-- GlobalFunctions.SetGraphicMode(1024,768,true)		
	-- end
	
	-- g_vid = OPUnitFactory.CreateUnit("Bink")
	-- g_vid.UnitNotify = self
	-- g_vid.Loop = false
	-- g_vid.Enabled = true
	-- g_vid.File = "media/video/"..g_curvideo..".bik"
	-- SetCenter(g_vid,Vector:new(WIDTH_SCREEN/2,HEIGHT_SCREEN/2))
	-- g_vid.Play()

	
	g_vid = OPUnitFactory.CreateUnit("Theora")
	g_vid.UnitNotify = self
	g_vid.Loop = false
	g_vid.File = "media/video/"..g_curvideo..".ogv"
	g_vid.Enabled = true
	g_vid.Layer = LayerMiddleground
	
	g_vid.Scale_X = 1280 / g_vid.Dimension_Width
	g_vid.Scale_Y = 800 / g_vid.Dimension_Height
	SetCenter(g_vid,Vector:new(WIDTH_SCREEN/2,HEIGHT_SCREEN/2))
	g_vid.Play()
	
	--on joue le soustitre
	VideoSubtitleManager.Enabled = true
	VideoSubtitleManager.loadSubtitleForVideo(g_curvideo)
 end

function OnVideoEnd()
	if g_videoskipped then
		return
	end

	OPLog.Log(" onvideoend "..self.Name)
	SetVariables("CurrentGamePhase","SearchSite")
	NavigationManager.SwitchTo(nil,g_nextdestination)
end

function OnBinkEnd()
	if g_videoskipped then
		return
	end
	
	OPLog.Log(" onbinkend "..self.Name)
	SetVariables("CurrentGamePhase","SearchSite")
	NavigationManager.SwitchTo(nil,g_nextdestination)
end

function OnDisable()
	if g_vid ~= nil then
		OPUnitFactory.CloseUnit(g_vid)
		g_vid = nil

	end
	
	SetVariables("VideoMode",false)
	VideoSubtitleManager.Enabled = false
	VideoText.Enabled = false
	
	Closeup_SkipButton_Indication.Enabled = false
	-- if not OPCore.EditorMode() then
		-- GlobalFunctions.SetGraphicMode(GlobalFunctions.cur_width,GlobalFunctions.cur_height)	
	-- end
end



