.namespace LeftInterface

RELOADTIME = 60 --temps pour que l'indice soit à nouveau accessible
HINTINFOTIME = 30
g_needhl = false
g_hlmaxtime = 4
g_hltime =0
g_hlinout= true
g_lasttimeready = 0
g_lasttimeready_count = 0



function OnEnable() 
	if UserData.IsEqual("expertMode", true) then
		self.RELOADTIME = Gameplay.RELOADING_HINT_EXPERT
	else	
		self.RELOADTIME = Gameplay.RELOADING_HINT
	end
	Inventory_bg.Enabled = true
	local lang = DebugOptions.curlanguage
	LeftInterface_locations_title.Image = "media/common/graph/interface/ingame/leftinterface/locations_title_"..lang..".png"
	Inventory_Title.Image = "media/common/graph/interface/ingame/leftinterface/inventory_title_"..lang..".png"
	LeftInterface_hint.Image = "media/common/graph/interface/ingame/leftinterface/hint_active_bg.png|media/common/graph/interface/ingame/leftinterface/hint_inactive_bg.png"
	LeftInterface_hint_text.Image = "media/common/graph/interface/ingame/leftinterface/hint_active_text_"..lang..".png|media/common/graph/interface/ingame/leftinterface/hint_inactive_text_"..lang..".png"
	if SampleLevel.IsEqual("Page_0",true) then
		LeftInterface_book.Flags_Visible=true
	end
end

function OnDisable() 
	Inventory_bg.Enabled = false
end

function OnUpdate(dt)
	if not GameVariables.IsEqual("CurrentGamePhase","SearchSite") and not GameVariables.IsEqual("CurrentGamePhase","Closeup")  and not GameVariables.IsEqual("CurrentGamePhase","Document")   and not GameVariables.IsEqual("CurrentGamePhase","Tutorial")  then
		return
	end
	GameVariables.Set("montreglobalcounter",GameVariables.Get("montreglobalcounter")+dt)	
	GameVariables.Set("montretimecounter",GameVariables.Get("montretimecounter")+dt)	
	if GameVariables.IsEqual("montrestate","showing") --[[and ObjectManager.SearchActivated()]] then	
		-- OPLog.Log(GameVariables.Get("montreglobalcounter"))
		LeftInterface_hint_progress.Position_X=0-(150/3)*GameVariables.Get("montreglobalcounter")
		LeftInterface_hint.SetFrame(1)
		LeftInterface_hint_text.SetFrame(1)
		g_hltime=g_hlmaxtime
		if not ObjectManager.SearchActivated() and LeftInterface_hint_progress.Position_X==-193 then
			Areas_LeftInterface.Reset()
		end

	end
	if GameVariables.IsEqual("montrestate","reloading") then
		LeftInterface_hint.SetFrame(1)
		LeftInterface_hint_text.SetFrame(1)
		local coeff = math.min(1,GameVariables.Get("montreglobalcounter") / self.RELOADTIME)
	
		 -- OPLog.Log(coeff.." "..GameVariables.Get("montreglobalcounter"))
		LeftInterface_hint_progress.Position_X=-(150-(150/self.RELOADTIME)*GameVariables.Get("montreglobalcounter"))
		if GameVariables.Get("montretimecounter") > 1 then
			GameVariables.Set("montretimecounter",0)
			
		end

		if (coeff >= 1 or DebugOptions.QuickIndice == true) then
			g_hltime=0
			SpriteFader.Fade(LeftInterface_hint_hl,true,0.8,LeftInterface)
			g_lasttimeready = OPTime.GetTime()
			g_lasttimeready_count = 0
			GameVariables.Set("montrestate","ready")
			LeftInterface_hint_progress.Position_X=0
			LeftInterface_hint.SetFrame(0)
			LeftInterface_hint_text.SetFrame(0)
			PlaySoundEffect("int_helpload")
		end

	end	
	if GameVariables.IsEqual("montrestate","ready") and  OPTime.GetTime() > g_lasttimeready + HINTINFOTIME and g_lasttimeready_count == 0    then
		if OPTime.GetTime() > ObjectManager.g_lasttimepickedobject + HINTINFOTIME then
			OPLog.Log("on rappelle que l'aide existe")
			g_lasttimeready_count = 1
			g_hltime=0
			SpriteFader.Fade(LeftInterface_hint_hl,true,0.8,LeftInterface)
			PlaySoundEffect("int_helpload")
		end
	end
	
end

function OnFaderEnd()
	if g_hltime < g_hlmaxtime then
		OPLog.Log(g_hltime)
		g_hlinout = not g_hlinout
		g_hltime = g_hltime+1
		SpriteFader.Fade(LeftInterface_hint_hl,g_hlinout,0.8,LeftInterface)
	else
		SpriteFader.Fade(LeftInterface_hint_hl,false,0.8)
		g_hlinout=true
	
	end
end


