
.namespace Areas_LeftInterface --  Menu_Principal

SPEEDLOUPE = 20
SPEEDBACKGROUND = 30

FADEDISAPPEARLENGTH = 3
FADEAPPEARLENGTH = 2

OFFSETLOUPE = {x=75,y=75}

BLINKNB = 4
BLINKTIME = 0.2

SHIFTANGLEDISPLAY = math.rad(-30) --angle de décalage sur le display

ZOOMLOUPE = 0.5 --de combien on zoom
ZOOMLENGTH = 1.6
-- Ce script gère les boutons du menu principal

function OnEnable()
	newpos = 100
end
function OnPopupYNLeave(popupansw, message)
		OPLog.Log("hello word2")
		if message == "msg_ig_menu_minijeu" and popupansw then
			NavigationManager.SwitchTo(nil,"Menu_Start")
		end
end
function OnWbpMouseLUp()
	if not self.CanClickOn() then
		return
	end
	PlaySoundEffect("int_click")
	-- if self.Name == "Inventory_hotspot" then
		
	-- end	
	if self.Name == "LeftInterface_menu_hotspot" then
	    if IsEqualVariables("CurrentGamePhase","Closeup") then
			PopupManager.OpenPopupYN("msg_ig_menu_minijeu",LeftInterface_book_hotspot)
		else	
			NavigationManager.SwitchTo(nil,"Menu_Start")
		end	
	end
	
	-- Bouton livre
--	if self.Name == "LeftInterface_book_hotspot" and SampleLevel.IsEqual("Page_0",true) then
--		SetVariables("CurrentGamePhase","Document")
--		-- Active le livre
--		PlaySoundEffect("int_bookopen")
--		Book.Enabled = true
--		-- Book_parent.Enabled = true
--		end
	if self.Name == "LeftInterface_hint_hotspot" then

		if GameVariables.IsEqual("montrestate","ready") then
			if NewTutorialManager.g_message == "TU_05" then
				NewTutorialManager.ClosePopupTuto()
			end		
			local obj = ObjectManager.GetNextObject()
			if obj ~= nil then
				Search_ShowObject.Flags_Visible = true
				Search_ShowObject.Scale_X = 1
				Search_ShowObject.Scale_Y = 1
				Search_ShowObject.Layer = LayerMenu

				GameVariables.Set("montrestate","showing")
				GameVariables.Set("montreglobalcounter",0)
				SpriteFader.Fade(Search_ShowObject,true,FADEAPPEARLENGTH)
				
							
				Search_ShowObject.Parent = obj.Parent
				Search_ShowObject.Position_X = self.Position_X - obj.Parent.Position_X
				Search_ShowObject.Position_Y = self.Position_Y - obj.Parent.Position_Y
				
				x,y = obj.GetRefPositionWithoutParent()
				
				SpriteMover.Move(Search_ShowObject,Vector:new(x,y) - Vector:new(OFFSETLOUPE.x,OFFSETLOUPE.y),SPEEDLOUPE,self)
				
				
				-- LeftInterface_hint_progress.Position_X=-150
				
				-- if IsEqualVariables("CurrentGamePhase","Tutorial") then
					-- TutorialManager.OnLaunchIndice()
				-- end
				
				-- le jouer a utilisé plus besoin de lancer le tuto
				-- UserData.Set("indicetutorialdone",true)
				
				-- Pas terrible... (TODO : à modifier)
				-- if FX_montre ~= nil then
					-- TutorialManager.OnLaunchIndice()
				-- end
				
				PlaySoundEffect("int_helpon")
			else
				local listnumb = 0
				local finishedlist = 0
				local needhotspothint = false
				if string.find(GetCurrentManager().Name,"_SearchSite") then
					scenename = string.gsub(GetCurrentManager().Name, "_SearchSite", "")	
				else
					scenename = GetCurrentManager().Name
				end
				for i=1,6  do
					if SampleLevel.IsRegistered(scenename.."_search_"..tostring(i))  then
						listnumb = listnumb+1
						if SampleLevel.IsEqual(scenename.."_search_"..tostring(i),"finished") then 
							finishedlist = finishedlist+1
						end
					end
				end
				OPLog.Log("Areas LI: "..finishedlist.."/"..listnumb)
				if listnumb == finishedlist then
					PlaySoundEffect("int_helpon")
					Search_HintLayer.Enabled = true
					Search_HintLayer.Layer = LayerMenu
					GameVariables.Set("montrestate","showing")
					GameVariables.Set("montreglobalcounter",0)
				else
					SequencePlayer.PlayRandomSequence({"IN_0","IN_1"},nil,nil)
				end
			end
		end

		return true
	end		
end


function OnMouseOn()
	if not self.CanClickOn() then
		return
	end
		OPLog.Log("onmouseon")
	if self.Name == "LeftInterface_book_hotspot" then
		LeftInterface_book.SetFrame(1)
	end
	if self.Name == "Inventory_hotspot" then
		Inventory_arrow.Flags_Visible = true
	end	
	if self.Name == "LeftInterface_menu_hotspot" then
		LeftInterface_menuhl.Flags_Visible = true
	end		
end

function OnMouseOff()
	if self.Name == "LeftInterface_book_hotspot" and not IsEqualVariables("CurrentGamePhase","Document")  then
		LeftInterface_book.SetFrame(0)
	end
	if self.Name == "Inventory_hotspot" then
		Inventory_arrow.Flags_Visible = false
	end	
	if self.Name == "LeftInterface_menu_hotspot" then
		LeftInterface_menuhl.Flags_Visible = false
	end		
end

function CanClickOn()
	return IsEqualVariables("CurrentGamePhase","SearchSite") 
	or IsEqualVariables("CurrentGamePhase","Closeup") 
	or (IsEqualVariables("CurrentGamePhase","Tutorial") and NewTutorialManager.g_state == "waitforaction" and NewTutorialManager.g_message == "TU_05")
	
end

function OnMoveEnd()
	--Reset()	
	--on fait disparaitre la loupe lentement
	SpriteFader.Fade(Search_ShowObject,false,FADEDISAPPEARLENGTH,self)
	
	--et on zoom aussi
	SpriteZoom.Zoom(Search_ShowObject,ZOOMLOUPE,ZOOMLENGTH,nil,Vector:new(Search_ShowObject))
	
end

function OnFaderEnd()
	Reset()
	-- Search_ShowObject.Parent = SearchInterface 
end

function Reset()
	GameVariables.Set("montrestate","reloading") -- 3 phases, chargement, "ready"" pret à cliquer et "showing" la loupe se dirige vers l'objet
	
	--self.counter = 0
	GameVariables.Set("montreglobalcounter",0)
	Search_ShowObject.Color.a = 0
--	Search_Montre_Highlight.Flags_Visible = false
	Search_HintLayer.Enabled = false
end
