
.namespace s10_c01

function OnEnable()
	Closeup.OnEnable("MiniGame")
	Reset()
	gamestart=false
	page=4
	if DebugOptions.DebugMode == true then
		InventoryManager.AddInInventory("InventoryParchemin")
	end
end

function Reset()
	Draggedpaper.texte=" "
	Draggedpaper.Enabled=false
	gamestart=true
	valid=0
	right=0
	u=1
	h=1
	chgpg=0
	tabmot={GlobalFunctions.GetText('dic_43'),GlobalFunctions.GetText('dic_59'),GlobalFunctions.GetText('dic_37'),GlobalFunctions.GetText('dic_18'),GlobalFunctions.GetText('dic_52')}
	tabdicot1={"AwasiJi :","Akwimda :","Alo :","Apchokozid :","AwanBiju :","Boji :","Bakka :","Both :","Bosasakhigon :","Bokwaloskw :"}
	tabdicot2={"Cheskwadakas :","Chigual :","Cheglaskw :","Chimelililhasis :","Chonnapsak :","Gosp :","Gawhowona :","Gdekinna :","Gawadiali :","Gwanigadok :"}
	tabdicot3={"Kazi :","Kwaskoai :","Kajogigilhasis :","Kaska :","Kchio :","Lobbial :","Lawiskad :","Lessahakigan :","Lakazôgôgan :","Lasoba :"}
	tabdicot4={"Magôlibo :","Mawia :","Mamlawiwi :","Maji :","Molsomnoki :","Noki :","N'namtonana :","Nahama :","Nkazawi :","Namas :"}
	tabdicot5={"O'kawôgano :","O'mwaimlasas :","Oja :","Odano :","O'dolibiôgaan :","Patai :","Pabômiki :","Pasbhigan :","Pazewadoit :","Poli :"}
	tabdicot6={"Sasagiwi :","Sobagw :","Sipkiwi :","Senojiwi :","Soghebat :","Tagasiwi :","Tagwôgo :","Telaps :","Tôni :","Tôbi :"}
	tabdicot7={"Wigawôwiji :","Wskobi :","Wiwnowi :","Wemi :","Wôôbaksiomigw :","","","","",""}
	
	tabdicof1={"0","0","0","0","r","0","0e","0r","0e","0he"}
	tabdicof2={"0r","0e","0n","0e","0t","0e","0r","0r","0t","0e"}
	tabdicof3={"0s","0z","0e","0n","0","0e","0e","0e","0e","0e"}
	tabdicof4={"0u","0x","0p","0s","0p","0x","0s","0e","0r","0n"}
	tabdicof5={"0e","0l","0s","0e","0e","0s","0n","0l","0e","0u"}
	tabdicof6={"0t","0r","0d","0ge","0te","0t","0e","0e","0ù","0c"}
	tabdicof7={"0t","0e","0r","0z","0e","","","","",""}
	
	for h=1,10 do
		tabd2=10+h
		tabd3=20+h
		tabd4=30+h
		tabd5=40+h
		tabd6=50+h
		tabd7=60+h
		tabdicof1[h]=GlobalFunctions.GetText('dic_'..tostring(h))
		tabdicof2[h]=GlobalFunctions.GetText('dic_'..tostring(tabd2))
		tabdicof3[h]=GlobalFunctions.GetText('dic_'..tostring(tabd3))
		tabdicof4[h]=GlobalFunctions.GetText('dic_'..tostring(tabd4))
		tabdicof5[h]=GlobalFunctions.GetText('dic_'..tostring(tabd5))
		tabdicof6[h]=GlobalFunctions.GetText('dic_'..tostring(tabd6))
		tabdicof7[h]=GlobalFunctions.GetText('dic_'..tostring(tabd7))
		textedico = OPUnitFactory.GetUnit("texte"..tostring(h))
		textedico.texte=tabdicof4[h]
		textedico.Children[0].Text=tostring(textedico.texte)
		textedico.Children[0].Font = "media/common/graph/fonts/daniel.ttf"
		texteabetab = OPUnitFactory.GetUnit("texteabe"..tostring(h))
		texteabetab.Text=tabdicot4[h]
		texteabetab.Font = "media/common/graph/fonts/danielbd.ttf"
	end
	
	for k=1,5  do 
		blatte = OPUnitFactory.GetUnit("cible"..tostring(k))
		blatte.texte=" "
		blatte.Children[0].Text=tostring(blatte.texte)
		blatte.Color.r = 255
		blatte.Color.g = 255
		blatte.Color.b = 255
	end
end

function OnUpdate()
		-- OPLog.Log("valid "..valid)
		-- OPLog.Log("right "..right)
		-- OPLog.Log("h "..h)
		-- OPLog.Log("page "..page)
		-- OPLog.Log("u "..u)
		-- OPLog.Log("chgpg "..chgpg)
		if Draggedpaper.Enabled==true then
			cursorpos = GetCenter(Cursor)
			Draggedpaper.Position_X=cursorpos.x-100
			Draggedpaper.Position_Y=cursorpos.y-55
			TextDragged.Text=Draggedpaper.texte
		end
		
		--le change page
		if chgpg==1 then
			if page==1 then
				dicofr=tabdicof1
				dicoab=tabdicot1
			elseif page==2 then 
				dicofr=tabdicof2
				dicoab=tabdicot2
			elseif page==3 then
				dicofr=tabdicof3
				dicoab=tabdicot3
			elseif page==4 then
				dicofr=tabdicof4
				dicoab=tabdicot4
			elseif page==5 then
				dicofr=tabdicof5
				dicoab=tabdicot5
			elseif page==6 then
				dicofr=tabdicof6
				dicoab=tabdicot6
				texte6.Enabled=true
				texte7.Enabled=true
				texte8.Enabled=true
				texte9.Enabled=true
				texte10.Enabled=true
				texteabe6.Enabled=true
				texteabe7.Enabled=true
				texteabe8.Enabled=true
				texteabe9.Enabled=true
				texteabe10.Enabled=true
			elseif page==7 then
				dicofr=tabdicof7
				dicoab=tabdicot7
				texte6.Enabled=false
				texte7.Enabled=false
				texte8.Enabled=false
				texte9.Enabled=false
				texte10.Enabled=false
				texteabe6.Enabled=false
				texteabe7.Enabled=false
				texteabe8.Enabled=false
				texteabe9.Enabled=false
				texteabe10.Enabled=false
			end
			
			if u<11 then 
				cockroach = OPUnitFactory.GetUnit("texte"..tostring(u))
				texteabenaquis = OPUnitFactory.GetUnit("texteabe"..tostring(u))
				cockroach.texte=dicofr[u]
				cockroach.Children[0].Text=tostring(cockroach.texte)
				texteabenaquis.Text=dicoab[u]
				u=u+1
			end
			
			if u==11 then
				chgpg=0
				u=1
			end
			
		end
		
		if valid==1 then
			cafard = OPUnitFactory.GetUnit("cible"..tostring(h))
			if cafard.texte==tabmot[h] then
				right=right+1
				cafard.Color.r = 0
				cafard.Color.g = 255
				cafard.Color.b = 0
			else
				cafard.Color.r = 255
				cafard.Color.g = 0
				cafard.Color.b = 0
			end
			h=h+1
			if h==6 then
				valid=0
				if right~=5 then
					PlaySoundEffect("int_closeupfail")
					SequencePlayer.PlaySequence("GP_1012",self,nil)
					right=0
					h=1
				end
			end
		end
		
		if right==5 then
			Itsawin()
			
			right=0
		end
end

function Itsawin()
	--SequencePlayer.Enabled = true
	-- SequencePlayer.PlaySequence("GP_1011",self,nil)
	PlaySoundEffect("int_closeupwin")
	InventoryManager.AddInInventory("InventoryParcheminTraduit")
	NavigationManager.SwitchTo(nil,"s10_SearchSite")
	SampleLevel.Set("s10_dico",true)
	s10_c01.Enabled = false
end

function OnDocumentUse(docname)
	if docname == "InventoryParchemin" then
		SequencePlayer.Enabled = true
		SequencePlayer.PlaySequence("GP_1010",self,nil)
		bandelette.Enabled = true
		SpriteFader.Fade(bandelette,true,1)
		InventoryManager.RemoveFromInventory("InventoryParchemin")
		gamestart=true
		return true
	end
	return false
end

function OnEnter()
	
	SequencePlayer.Enabled = true
	SequencePlayer.PlaySequence("GP_1013",self,nil)
end

function OnSequenceEnd(dialogue)
	--if dialogue == "GP_1011" then
		
		
	--end
	
	if dialogue == "GP_1010" then
		SequencePlayer.PlaySequence("AI_"..GetCurrentManager().Name,self,nil,"help")
		return true
	end
end

function OnSubtitlesEnd()
end
