using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;

public class rankingInput : MonoBehaviour {
    public GameObject ifield;

    public void onNameEnter(string name) {
        if (string.IsNullOrEmpty(name))
            return;

        int oldScore = PlayerPrefs.GetInt("score", 0);
        if(GameLogig.clientes > oldScore)
        {
            PlayerPrefs.SetString("rangName", name);
            PlayerPrefs.SetInt("score", GameLogig.clientes);

        }
        SceneManager.LoadScene("gameover");
    }

    class NameScore
    {
        public string name;
        public int score;

        public NameScore(string _name, int _score)
        {
            name = _name;
            score = _score;
        }
    }


    public void onNameEnter2(string name)
    {
        bool alreadyEntered = false;
        List<NameScore> l = new List<NameScore>();
        for(int i = 0; i < 5; i++)
        {
            int scoretmp = PlayerPrefs.GetInt("score" + i, 0);

            if (GameLogig.clientes >= scoretmp && alreadyEntered == false)
            {
                l.Add(new NameScore(name, GameLogig.clientes));
                alreadyEntered = true;
            }

            l.Add(new NameScore(PlayerPrefs.GetString("rangName" + i, ""), scoretmp));
        }

        for(int i = 0; i < 5; ++ i)
        {
            PlayerPrefs.SetInt("score"+i, l[i].score);
            PlayerPrefs.SetString("rangName" + i, l[i].name);
        }
        //SceneManager.LoadScene("gameover");
        ifield.SetActive(false);
    }

}
