public void Init(int missionNum)
    {
        Data.Instance.events.RalentaTo(0.6f, 0.05f);
        panel.SetActive(true);
        int maxScore     = Data.Instance.GetComponent <Missions>().MissionActive.maxScore;
        int missionScore = Data.Instance.userData.missionScore;
        int quarter      = maxScore / 4;

        string titleText = "";

        int starsQty;

        if (missionScore >= quarter * 4)
        {
            titleText = "EXCELENT";
            starsQty  = 3;
        }
        else if (missionScore >= quarter * 2)
        {
            titleText = "WELL DONE";
            starsQty  = 2;
        }
        else if (missionScore >= quarter)
        {
            titleText = "OK...";
            starsQty  = 1;
        }
        else
        {
            titleText = "POOR...";
            starsQty  = 0;
        }

        stars.Init(starsQty);

        foreach (Text label in fields)
        {
            label.text = titleText;             //"SCORE " + missionScore;
        }
        Data.Instance.events.OnSetStarsToMission(missionNum, starsQty);

        CloseAfter(3);
    }
    public void SetOnSingleResult()
    {
        panel.SetActive(true);
        stars.Init(numStars);

        float lastScore = Data.Instance.levelsData.GetLevelScores(Data.Instance.levels.currentLevel).myScore;
        float score     = 0;

        if (Data.Instance.levels.GetCurrentLevelData().totalTime > 0)
        {
            score = Data.Instance.levelData.laps;

            result            = score + "m";
            hiscoreField.text = "MY BEST " + lastScore + "m";
            //timeField.text = time;
        }
        else
        {
            score = Data.Instance.levelData.time;
            System.TimeSpan lastT    = System.TimeSpan.FromSeconds(lastScore);
            string          lastTime = string.Format("{0:00}:{1:00}.{2:00}", lastT.Minutes, lastT.Seconds, lastT.Milliseconds / 10);
            hiscoreField.text = "MY BEST " + lastTime;

            result = time;

            //   if (Data.Instance.levels.GetCurrentLevelData().Sudden_Death)
            //    result = "";
        }
        resultField.text = result;
        if (lastScore == 0)
        {
            hiscoreField.text = "NEW HISCORE";
        }

        // Events.OnSaveScore(Data.Instance.levels.currentLevel, score);

        Invoke("LoadResults", 1);
    }
    // Use this for initialization
    public void Init(Mission mission, int id)
    {
        this.mission = mission;
        this.id      = id;
        VideogameData data = Data.Instance.videogamesData.GetActualVideogameDataByID(mission.videoGameID);

        if (Data.Instance.playMode == Data.PlayModes.COMPETITION)
        {
            foreach (Text m in missionFields.GetComponentsInChildren <Text>())
            {
                m.text = Data.Instance.videogamesData.GetActualVideogameDataByID(mission.videoGameID).name;
            }
            foreach (Text m in missionNames.GetComponentsInChildren <Text>())
            {
                m.text = "COMPETITION-MODE";
            }
        }
        else
        {
            foreach (Text m in missionFields.GetComponentsInChildren <Text>())
            {
                m.text = data.name + " " + ((int)id + 1).ToString() + "/9";
            }

            foreach (Text m in missionNames.GetComponentsInChildren <Text>())
            {
                m.text = mission.description;
            }

            int starsQty = Data.Instance.userData.GetStars(id);
            stars.Init(starsQty);
            background.transform.localEulerAngles = new Vector3(30, 0, 0);
        }

        logo.sprite        = data.logo;
        floppyCover.sprite = data.floppyCover;
    }
Exemple #4
0
    public void SetOn()
    {
        panel.SetActive(true);
        panel.GetComponent <Animation>().Play("PopupOn");

        title.text = "LEVEL " + Data.Instance.levels.currentLevel + " COMPLETED!";

        string time = GetTimeFormat(Data.Instance.levelData.time);

        MultiplayerData multiplayerData = Data.Instance.multiplayerData;
        List <MultiplayerData.PlayerData> playersData = multiplayerData.players.OrderBy(x => x.meters).ToList();

        playersData.Reverse();

        int numStars = Data.Instance.levels.GetCurrentLevelStars(Data.Instance.levelData.time, Data.Instance.levelData.laps);

        stars.Init(numStars);

        //  print("STARS: " + numStars);

        float score = 0;

        //si es por tiempo:
        if (Data.Instance.levels.GetCurrentLevelData().totalTime > 0)
        {
            score  = Data.Instance.levelData.laps;
            result = "TIME: " + time;
            puesto1.Init(playersData[0].username, playersData[0].meters.ToString() + "m", playersData[0].color);

            if (playersData.Count > 1)
            {
                puesto2.Init(playersData[1].username, playersData[1].meters.ToString() + "m", playersData[1].color);
            }
            if (playersData.Count > 2)
            {
                puesto3.Init(playersData[2].username, playersData[2].meters.ToString() + "m", playersData[2].color);
            }
            if (playersData.Count > 3)
            {
                puesto4.Init(playersData[3].username, playersData[3].meters.ToString() + "m", playersData[3].color);
            }
        }
        else if (Data.Instance.levels.GetCurrentLevelData().Sudden_Death)
        {
            score = Data.Instance.levelData.time;

            playersData = multiplayerData.players.OrderBy(x => x.time).ToList();
            playersData.Reverse();

            result = "SUDDEN DEATH";

            puesto1.Init(playersData[0].username, GetTimeFormat(playersData[0].time), playersData[0].color);

            if (playersData.Count > 1)
            {
                puesto2.Init(playersData[1].username, GetTimeFormat(playersData[1].time), playersData[1].color);
            }
            if (playersData.Count > 2)
            {
                puesto3.Init(playersData[2].username, GetTimeFormat(playersData[2].time), playersData[2].color);
            }
            if (playersData.Count > 3)
            {
                puesto4.Init(playersData[3].username, GetTimeFormat(playersData[3].time), playersData[3].color);
            }
        }
        else
        {
            score = Data.Instance.levelData.time;
            puesto1.Init(playersData[0].username, time, playersData[0].color);

            result = playersData[0].meters.ToString() + "m";



            if (playersData.Count > 1)
            {
                puesto2.Init(playersData[1].username, "---", playersData[1].color);
            }
            if (playersData.Count > 2)
            {
                puesto3.Init(playersData[2].username, "---", playersData[2].color);
            }
            if (playersData.Count > 3)
            {
                puesto4.Init(playersData[3].username, "---", playersData[3].color);
            }
        }
        timeField.text = result;

        Events.OnSaveScore(Data.Instance.levels.currentLevel, score);
        Events.OnAddMultiplayerScore(Data.Instance.levels.currentLevel, score, playersData[0].playerID, playersData[0].username);


        //if (multiplayerData.players.Count == 1)
        //{
        //    string result = playersData[0].meters.ToString() + " Mts";

        //    if (Data.Instance.levels.GetCurrentLevelData().Sudden_Death)
        //        result = "";

        //    puesto1.Init(playersData[0].username, result, playersData[0].color);
        //    return;
        //}

        //puesto2.gameObject.SetActive(false);
        puesto3.gameObject.SetActive(false);
        puesto4.gameObject.SetActive(false);

        // if (multiplayerData.players.Count > 1)
        //  puesto2.gameObject.SetActive(true);
        if (multiplayerData.players.Count > 2)
        {
            puesto3.gameObject.SetActive(true);
        }
        if (multiplayerData.players.Count > 3)
        {
            puesto4.gameObject.SetActive(true);
        }


        List <int> arr = new List <int>();

        foreach (MultiplayerData.PlayerData data in playersData)
        {
            arr.Add(data.playerID);
        }

        Events.OnTournamentAddScores(Data.Instance.levels.currentLevel, arr);
        if (Data.Instance.tournament.GetTotalMatches() == 8)
        {
            finishButton.SetActive(true);
            shareButton.SetActive(true);
        }
    }
Exemple #5
0
    void LoadSinglePlayerWinners()
    {
        float _myScore = Data.Instance.levelsData.GetMyScoreIfExists(id);

        if (_myScore > 0)
        {
            string _score = Data.Instance.levelsData.GetScoreString(id, _myScore);
            int    _stars = Data.Instance.levels.GetCurrentLevelStarsByScore(id, _myScore);
            stars.Init(_stars);
            myScore.text = _score;
            SetLock(false);

            if (_myScore != PlayerPrefs.GetFloat("Run_Level_" + id))
            {
                Debug.Log("___GRABA LOCAL level: " + id + " score: " + _myScore);
                PlayerPrefs.SetFloat("Run_Level_" + id, _myScore);
            }
        }

        if (Data.Instance.userData.facebookID.Length < 2)
        {
            user1.gameObject.SetActive(false);
            user2.gameObject.SetActive(false);
            user3.gameObject.SetActive(false);
            return;
        }

        if (levelScore.scoreData.Count > 0)
        {
            user1.gameObject.SetActive(true);
            LevelsData.ScoreData scoreData = levelScore.scoreData[0];
            user1.Init(id, scoreData.playerName, scoreData.score.ToString(), scoreData.facebookID);
            user1.SetSinglePlayer();
        }
        else
        {
            user1.gameObject.SetActive(false);
        }
        if (levelScore.scoreData.Count > 1)
        {
            user2.gameObject.SetActive(true);
            LevelsData.ScoreData scoreData = levelScore.scoreData[1];
            user2.Init(id, scoreData.playerName, scoreData.score.ToString(), scoreData.facebookID);
            user2.SetSinglePlayer();
        }
        else
        {
            user2.gameObject.SetActive(false);
        }
        if (levelScore.scoreData.Count > 2)
        {
            user3.gameObject.SetActive(true);
            LevelsData.ScoreData scoreData = levelScore.scoreData[2];
            user3.Init(id, scoreData.playerName, scoreData.score.ToString(), scoreData.facebookID);
            user3.SetSinglePlayer();
        }
        else
        {
            user3.gameObject.SetActive(false);
        }
    }
Exemple #6
0
    public void Open(int levelId)
    {
        panel.transform.localScale = Data.Instance.screenManager.scale;

        if (Data.Instance.userData.mode == UserData.modes.SINGLEPLAYER)
        {
            ranking.LoadSinglePlayerWinners(levelId);

            if (FB.IsLoggedIn)
            {
                Logout.SetActive(false);
            }
            else
            {
                Logout.SetActive(true);
            }

            singlePanel.SetActive(true);
            multiPanel.SetActive(false);
        }
        else
        {
            ranking.LoadMultiplayerWinners(levelId);

            singlePanel.SetActive(false);
            multiPanel.SetActive(true);
            Logout.SetActive(false);
        }

        Events.OnSoundFX("buttonPress");
        this.levelId = levelId;
        isActive     = true;
        panel.SetActive(true);
        panel.GetComponent <Animation>().Play("PopupOn");
        field.text = "LEVEL " + levelId;

        float _myScore = PlayerPrefs.GetFloat("Run_Level_" + levelId);

        starsInLevel = 0;

        if (_myScore == 0)
        {
            stars.Reset();
        }
        else
        {
            starsInLevel = Data.Instance.levels.GetCurrentLevelStarsByScore(levelId, _myScore);
            stars.Init(starsInLevel);
        }

        string _score = Data.Instance.levelsData.GetScoreString(levelId, _myScore);

        if (Data.Instance.userData.mode == UserData.modes.SINGLEPLAYER)
        {
            subTitle.text = "MY BEST: " + _score;
        }
        else
        {
            subTitle.text = "";
        }

        Levels.LevelData levelData = Data.Instance.levels.levels[levelId];

        if (starsInLevel < 1)
        {
            challengesButtonDisable.SetActive(true);
            challengesButton.interactable = false;
        }
        else
        {
            challengesButton.interactable = true;
            challengesButtonDisable.SetActive(false);
        }


        if (levelData.Sudden_Death)
        {
            goalText.text = "SUDDEN DEATH!";
        }
        else if (levelData.totalLaps > 0)
        {
            goalText.text = (levelData.totalLaps * 1000).ToString() + "m";
        }
        else
        {
            goalText.text = (levelData.totalTime).ToString() + " SECONDS";
        }
    }