--Usuarios

function info()

--Lo ponemos aqui porque es después de la BiosROM
rutinas={}
if tema==1 then
	for i=1,3 do
		rutinas[i]={x=107+107*i-107,y=245,w=107,h=26,p="",i=nil}
	end
elseif tema==2 then
	for i=1,3 do
		rutinas[i]={x=111+106*i-107,y=242,w=106,h=31,p="",i=nil}
	end
else
	for i=1,3 do
		rutinas[i]={x=114+101*i-100,y=245,w=100,h=27,p="",i=nil}
	end
end


names=nil
passs=nil

velocidad_puntero=tonumber(ini.read("SYSTEM/CONFIG.INI","U"..user,"velocidad",3))
if tonumber(ini.read("SYSTEM/CONFIG.INI","U"..user,"stick",1))==1 then stick=true else stick=false end
if tonumber(ini.read("SYSTEM/CONFIG.INI","U"..user,"captura",1))==1 then captura=true else captura=false end
if tonumber(ini.read("SYSTEM/CONFIG.INI","U"..user,"sonido",1))==1 then estado_sonido=true else estado_sonido=false end
volumen_sonido=tonumber(ini.read("SYSTEM/CONFIG.INI","U"..user,"volumen",100))
fondo_escritorio=tonumber(ini.read("SYSTEM/CONFIG.INI","U"..user,"fondo",1))
home=tonumber(ini.read("SYSTEM/CONFIG.INI","U"..user,"home",1))
img_escritorio[fondo_escritorio]=image.load("FX/imagenes/escritorio/"..fondo_escritorio..".png")
keyboard=tonumber(ini.read("SYSTEM/CONFIG.INI","U"..user,"teclado",1))
if tonumber(ini.read("SYSTEM/CONFIG.INI","U"..user,"avisobat",1))==1 then avisobat=true else avisobat=false end


cursor=tonumber(ini.read("SYSTEM/CONFIG.INI","U"..user,"cursor",1))
p.i=image.load("FX/c"..cursor..".png")

--Ponemos los ajustes
dofile("SYSTEM/panel/funciones.lua")
end

v={}
function re()
	for i=1,4 do
		v[i]=0
	end
end



function usuarios()

names={}
passs={}
for i=1,3 do
	names[i]=ini.read("SYSTEM/CONFIG.INI","U"..i,"name","User"..i)
	passs[i]=ini.read("SYSTEM/CONFIG.INI","U"..i,"pass","0000")
end

actual=1
cajanum=image.create(12,12,blanco)
re()
va=1
posv=1
transn=50
dt=2
pulsado=false

splash3=image.load("FX/imagenes/menu.png")

numbers={}
for i=1,10 do
numbers[i]=image.load("FX/imagenes/"..i..".png")
end

while true do
controls.read()
splash3:blit(0,0)
if dt==2 then transn=transn+1 else transn=transn-1 end
if transn>140 then dt=1 end
if transn<50 then dt=2 end

if controls.press("circle") and pulsado then 
pulsado=false 
re()
end

if not pulsado then
	if controls.press("left") then actual=actual-1 elseif controls.press("right") then actual=actual+1 end
	if actual>3 then actual=1 elseif actual<1 then actual=3 end
else
	if controls.press("right") then va=va+1 elseif controls.press("left") then va=va-1 end
	if va>10 then va=1 elseif va<1 then va=10 end
	if controls.press("cross") then 
		if posv<5 then 
			if va<10 then v[posv]=va else v[posv]=0 end posv=posv+1
		else 
			local contra=tostring(v[1]..v[2]..v[3]..v[4])
			if passs[actual]==os.md5(contra) then 
				user=actual
				username=names[user]
				info() 
				splash3:free()
				splash3=nil
				for i=1,10 do
					numbers[i]:free()
					numbers[i]=nil
				end
				if estado_sonido then sound_encendie:play(1) end
				enter_app() 
			else 
				posv=1
				os.message("Contraseña Incorrecta") 
				re() 
				pulsado=false 
			end
		end
	end

if posv>1 then
	for i=2,posv do
		screen.print(163+20*i,230,"*",0.8,blanco,azul) 
	end
else
	screen.print(240,230,"PASS",0.8,blanco,azul,"center") 
end
	for i=1,10 do
		numbers[i]:blit(114+i*16+i*5,170)
	end
	cajanum:blend(114+va*16+va*5+2,170+2,transn)
end

if controls.press("square") and passtart==1 then
	if posv>1 then 
		v[posv]=0 posv=posv-1
	end
end

if controls.press("cross") then
	if passtart==1 then
		if not pulsado then pulsado=true end
	else
		user=actual
		username=names[user]
		info()
		splash3:free()
		splash3=nil
		if estado_sonido then sound_encendie:play(1) end
		enter_app()
	end
end

for i=1,3 do
	if actual==i then 
		if names[i]:len()<15 then 
			screen.print(120*i,120,names[i],0.8,blanco,verde,"center") 
		else 
			screen.print(120*i,120,names[i]:sub(1,15),0.8,blanco,verde,"center") 
		end
	else 
		if names[i]:len()<15 then 
			screen.print(120*i,120,names[i],0.7,blanco,azul,"center") 
		else 
			screen.print(120*i,120,names[i]:sub(1,15),0.7,blanco,azul,"center") 
		end
	end
end

screen.flip()

end
end