.namespace	NewTutorialManager
 
g_state = ""
g_message = ""
 
function OnEnable()
end

function OpenPopupTuto(message,utnotify,x,y,poptype)
		--poptype "waitforanyclic" = On clique n'importe ou pour faire disparaitre la popup
		--poptype "waitforaction" = On effectue une action pour faire disparaitre la popup
		--poptype "waitforcliconself" = on clique sur la popup pour la faire disparaitre
		self.poptype = poptype
		g_state = poptype
		g_message = message
		self.active = true
		AssertPopup(type(message) == "string", "prop param openpopup")
		if string.find(GetCurrentManager().Name,"SearchSite") then
			self.oldphase = "SearchSite"
		else
			self.oldphase = "Closeup"
		end
		self.utnotify = utnotify
		self.message=message
		SetVariables("CurrentGamePhase","Tutorial")
		popups_tuto_parent.Enabled = true
		popups_tuto.Position_X = x
		popups_tuto.Position_Y = y
		SpriteFader.Fade(popups_tuto,true,0.4)
		popups_tuto_text.Text = GlobalFunctions.GetText(message)

end

function OnEnable()
	self.active = false
	OPInput.RegisterListener(self, EVENT_MOUSE_LUP)
	OPInput.SetListenerPriority(self,LISTENER_HIGH_PRIORITY)
	self.Flags_AcceptAllInput = true
end

function ClosePopupTuto()
	if self.active then
		self.active = false		
		SpriteFader.Fade(popups_tuto,false,0.4,self)
		SetVariables("CurrentGamePhase",self.oldphase) 
		g_state =""
	end	
end

function OnWbpMouseLUp()

	if self.active and g_state == "waitforanyclic" then
		self.active = false		
		SpriteFader.Fade(popups_tuto,false,0.4,self)
		SetVariables("CurrentGamePhase",self.oldphase)
		g_state =""
		return true
	end
	
	return false
end

function OnFaderEnd()
	--SetVariables("CurrentGamePhase",self.oldphase) 
	
	if GetCurrentManager().OnPopupTutoLeave ~= nil then
		GetCurrentManager().OnPopupTutoLeave(self.message)
	end
	
	if self.utnotify~= nil and self.utnotify.ParentEnabled and self.utnotify.OnPopupTutoLeave ~= nil then
		self.utnotify.OnPopupTutoLeave(self.message)
	end	
end
