
.namespace s04_SearchSite

function OnEnable()
	SearchSite.OnEnable()
	OPLog.Log("OnEnable unit "..self.Name)
	-- if SampleLevel.IsEqual("s03_coffre_open",true) then -- temporaire en attendant le closeup
		-- piano.Enabled = true
	-- end
	if  SampleLevel.IsEqual("s04_search_4","unstarted") then 
		liste_s04_4.Enabled = true
	end
	if  SampleLevel.IsEqual("s04_search_1","unstarted") then 
		liste_s04_1.Enabled = true
		piano.Enabled = true
		piece_secrete.Enabled = false
	end
	
	if SampleLevel.IsEqual("s04_bibli_open","done") then
		piece_secrete.Enabled = true
		bibli_anim.Flags_Visible = true
		bibli_anim.SetFrame(100)
		piano.Enabled = false

	elseif SampleLevel.IsEqual("s04_bibli_open","todo") then
		Open_Bibli()

	elseif SampleLevel.IsEqual("s04_bibli_open","no") then
		bibli_anim.Enabled = true
		bibli_anim.Flags_Visible = true
		bibli_anim.SetFrame(0)
	end

end

function OnEnter()
	if SampleLevel.IsEqual("s04_firstenter",true) then
		InventoryCodeCadenas.Equipped = false
		SequencePlayer.Enabled = true
		SequencePlayer.PlaySequence("GP_400",nil,nil)
		SampleLevel.Set("s04_firstenter",false)
		bibli_anim.Flags_Visible = true
	end		
	if SampleLevel.IsEqual("s04_bibli_open","done") and SampleLevel.IsEqual("s05_firstenter",true) then
	SequencePlayer.Enabled = true
	SequencePlayer.PlaySequence("GP_408",nil,nil)
	end
	if SampleLevel.IsEqual("s03_coffre_open",true) and SampleLevel.IsEqual("s04_bibli_open","no") then
	SequencePlayer.Enabled = true
	SequencePlayer.PlaySequence("GP_409",nil,nil)
	end
end


function UpdateAll()
	
end

function OnPickObject(objname)
	if objname == "obj_jouet_chien" then
		
		SequencePlayer.Enabled = true
		SequencePlayer.PlaySequence("GP_402",nil,nil)
	end
	if objname == "obj_tableau" then
		SequencePlayer.Enabled = true
		SequencePlayer.PlaySequence("GP_407",nil,nil)
		liste_s04_4.Enabled = true
	end
end

function OnSearchEnd(typesearch)

	if typesearch == 4 then
		InventoryManager.AddInInventory("InventoryPlan","msg_ig_inventaire")	
		InventoryPlan.Equipped = true
		-- InventoryManager.AddInInventory("InventoryClefCoffre","msg_ig_inventaire")	
		-- InventoryClefCoffre.Equipped = true
		if SampleLevel.IsEqual("s04_search_1","unstarted")  then
			
		end
	--end
	elseif typesearch == 1 then
		if InventoryLampeTorcheOff.Equipped == true then
			InventoryManager.AddInInventory("InventoryLampeTorcheOn","msg_ig_inventaire")	
			InventoryLampeTorcheOn.Equipped = true
			InventoryLampeTorcheOff.Equipped = false
			InventoryManager.RemoveFromInventory("InventoryLampeTorcheOff")
	
		else
			InventoryManager.AddInInventory("InventoryPile","msg_ig_inventaire")	
			InventoryPile.Equipped = true
		end
						
		if SampleLevel.IsEqual("s04_search_4","unstarted") then
		end
	end
end

function OnTakeList(typesearch)
	if typesearch == 4 then
		if  UserData.IsEqual("displayTutorial", true) then
			NewTutorialManager.OpenPopupTuto("TU_15",nil,188,271,"waitforanyclic")
			popups_tuto.SetFrame(1)
		end
	end
end
function OnPopupLeave(objname)
	if objname == "InventoryPlan" then
		SequencePlayer.Enabled = true
		SequencePlayer.PlaySequence("GP_403",nil,nil)
	end
	if objname == "InventoryLampeTorcheOn" then
		SequencePlayer.Enabled = true
		SequencePlayer.PlaySequence("GP_406",nil,nil)
	end
end

function CondSpecificToFinish()

end

function CanClickOnList(listname)
	if listname == "liste_s04_4" and not SampleLevel.IsEqual("s04_search_1","finished") then
		return false
	end
	return true
end

function Open_Bibli()
		SampleLevel.Set("s04_bibli_open","done")
		piece_secrete.Enabled = true
		bibli_anim.Play()
		piano.Enabled = false
		bibli_anim.Flags_Visible = true
		PlaySoundEffect("gmp_bookcase")
end
