public void Set(int p_rank, LeaderboardScore p_score)
    {
        m_score = p_score;

        m_rankText.text  = p_rank.ToString();
        m_nameText.text  = p_score.Name;
        m_deathText.text = p_score.Deaths.ToString();
        m_timeText.text  = Game.m_scores.ToDuration(p_score.Time);

        if (m_editable)
        {
            foreach (Image image in m_tutorialImages)
            {
                image.enabled = true;
            }

            m_editing = true;
        }
        else
        {
            foreach (Image image in m_tutorialImages)
            {
                image.enabled = false;
            }
        }
    }
Esempio n. 2
0
    void GameOver()
    {
        // move the shape one row up
        _activeShape.MoveUp();

        StartCoroutine(GameOverRoutine());

        // play the failure sound effect
        PlaySound(_soundManager.gameOverSound, 5f);

        // play "game over" vocal
        PlaySound(_soundManager.gameOverVocalClip, 5f);

        // set the game over condition to true
        _gameOver = true;

        var saveManager      = new SaveManager <LeaderboardScore>();
        var leaderboardScore = new LeaderboardScore
        {
            name  = "Yurii",
            score = _scoreManager.GetCurrentData()
        };

        saveManager.Save(new[] { leaderboardScore }, "leaderbord");
    }
Esempio n. 3
0
        public void TestDeleteAllScoresAfterPlaying()
        {
            playToResults();

            ScoreInfo        score      = null;
            LeaderboardScore scorePanel = null;

            AddStep("get score", () => score = ((ResultsScreen)Game.ScreenStack.CurrentScreen).Score);

            AddAssert("ensure score is databased", () => Game.Realm.Run(r => r.Find <ScoreInfo>(score.ID)?.DeletePending == false));

            AddStep("press back button", () => Game.ChildrenOfType <BackButton>().First().Action());

            AddStep("show local scores",
                    () => Game.ChildrenOfType <BeatmapDetailAreaTabControl>().First().Current.Value = new BeatmapDetailAreaLeaderboardTabItem <BeatmapLeaderboardScope>(BeatmapLeaderboardScope.Local));

            AddUntilStep("wait for score displayed", () => (scorePanel = Game.ChildrenOfType <LeaderboardScore>().FirstOrDefault(s => s.Score.Equals(score))) != null);

            AddStep("open options", () => InputManager.Key(Key.F3));

            AddStep("choose clear all scores", () => InputManager.Key(Key.Number4));

            AddUntilStep("wait for dialog display", () => Game.Dependencies.Get <DialogOverlay>().IsLoaded);
            AddUntilStep("wait for dialog", () => Game.Dependencies.Get <DialogOverlay>().CurrentDialog != null);
            AddStep("confirm deletion", () => InputManager.Key(Key.Number1));
            AddUntilStep("wait for dialog dismissed", () => Game.Dependencies.Get <DialogOverlay>().CurrentDialog == null);

            AddUntilStep("ensure score is pending deletion", () => Game.Realm.Run(r => r.Find <ScoreInfo>(score.ID)?.DeletePending == true));

            AddUntilStep("wait for score panel removal", () => scorePanel.Parent == null);
        }
Esempio n. 4
0
    public void OnSuccess(object obj)
    {
        if ((obj == null) || !(obj is Game))
        {
            this.OnException(null);
            return;
        }

        Game game = (Game)obj;
        IList <Game.Score> scores = game.GetScoreList();

        if (scores == null)
        {
            this.OnException(null);
            return;
        }

        List <LeaderboardScore> scoreList = new List <LeaderboardScore>();

        foreach (var score in scores)
        {
            LeaderboardScore score2 = new LeaderboardScore();

            score2.name  = score.GetUserName();
            score2.score = (int)score.GetValue();
            score2.date  = score.GetCreatedOn();

            scoreList.Add(score2);
        }

        this.updateHUD(scoreList);
    }
Esempio n. 5
0
    private void WriteToJSON(LeaderboardScore p_score, string p_fileName)
    {
        System.IO.StreamWriter Writer = new System.IO.StreamWriter(p_fileName, false);

        Writer.Write(JsonUtility.ToJson(p_score));
        Writer.Close();
    }
Esempio n. 6
0
    /// <summary>
    /// Adds to leaderboard, using a sorted list. The list is sorted by
    /// the following order: Score (0000XX) > User > Date
    /// </summary>
    /// <param name="score">Score integer.</param>
    /// <param name="user">User.</param>
    public static void AddToLeaderboard(float score, string user, string date = null)
    {
        if (leaderboard.Count >= MaxNumRecords)
        {
            leaderboard.RemoveAt(MaxNumRecords - 1);
        }

        var newScore = new LeaderboardScore();

        newScore.name  = user;
        newScore.date  = date ?? System.DateTime.Now.ToString();
        newScore.score = (int)score;

        string key = newScore.ToKey();

        try
        {
            leaderboard.Add(key, newScore);
        }
        catch (System.Exception e)
        {
            Debug.Log("A score already exists with this info\n" + e.Message);
        }

        updated = true;
        SaveData();
    }
    public void AddScore(LeaderboardScore p_score)
    {
        List <LeaderboardScore> online  = GetOnlineScores();
        List <LeaderboardScore> offline = GetLocalScores();
        bool onlineChange = false;

        online.Sort(CompareScores);
        offline.Sort(CompareScores);

        System.IO.StreamWriter Online = new System.IO.StreamWriter(Application.dataPath + "/Data/OnlineLeaderboard.JSON", true);
        System.IO.StreamWriter Local  = new System.IO.StreamWriter(Application.dataPath + "/Data/LocalLeaderboard.JSON", true);

        if (online.Count < m_loadedAmount || online[m_loadedAmount - 1].Score < p_score.Score)        // if we make it in top x
        {
            Online.Write((online.Count > 0 ? "\n" : "") + JsonUtility.ToJson(p_score));
            onlineChange = true;
        }

        if (offline.Count < m_loadedAmount || offline[m_loadedAmount - 1].Score < p_score.Score)        // if we make it in top x
        {
            Local.Write((offline.Count > 0 ? "\n" : "") + JsonUtility.ToJson(p_score));
        }

        Online.Close();
        Local.Close();

        DeletePendingScore();

        if (onlineChange)
        {
            StartCoroutine(Game.m_leaderNetHandler.UploadV2(Game.m_leaderNetHandler.ConvertFileToJSON()));
        }
    }
    public LeaderboardScore GetPendingScore()
    {
        System.IO.StreamReader Reader = new System.IO.StreamReader(Application.dataPath + "/Data/PendingScores.JSON");
        LeaderboardScore       score  = JsonUtility.FromJson <LeaderboardScore>(Reader.ReadLine());

        Reader.Close();
        return(score);
    }
Esempio n. 9
0
        public void OnSuccess(LeaderboardScore score)
        {
            var msg = "get currentplayer leaderboard succeed. \n";

            msg += string.Format("rank:{0}, score:{1}, timespan:{2}, player rank:{3}, scoreTag:{4}, \n",
                                 score.DisplayRank,
                                 score.PlayerRawScore, score.TimeSpan, score.PlayerRank, score.ScoreTag);
            Show(msg);
        }
    public void Load()
    {
        if (m_instantiatedObjects != null && m_instantiatedObjects.Count > 0)
        {
            return;
        }

        m_instantiatedObjects = new List <GameObject>();

        List <LeaderboardScore> scores  = GetLocalScores();
        LeaderboardScore        pending = GetPendingScore();

        if (pending != null)
        {
            scores.Add(pending);
        }

        if (scores.Count > 0)
        {
            scores.Sort(CompareScores);
        }

        for (int i = 1; i <= m_loadedAmount; i++)
        {
            if (scores.Count < i)
            {
                break;
            }

            GameObject       spotObj;
            bool             defaultName = false;
            LeaderboardScore score       = scores[i - 1];

            if (score.Name.Length == 0 && score != pending)
            {
                defaultName = true;
            }

            spotObj = Instantiate(m_spotPrefab, transform.Find("Viewport").Find("Content"));

            m_instantiatedObjects.Add(spotObj);
            LeaderboardSpot spot = spotObj.GetComponent <LeaderboardSpot>();

            if (defaultName)
            {
                score.Name = "AAA";
            }
            if (score == pending)
            {
                spot.m_editable = true;
            }

            spot.m_loader = this;
            spot.Set(i, score);
        }
    }
Esempio n. 11
0
    public void LoadLeaderboardScore(LeaderboardScore score)
    {
        var scorePrefabView = GameObject
                              .Instantiate(_leaderboardScorePrefab, _leaderboardLayout.transform, false)
                              .GetComponent <LeaderboardScoreView>();

        string name = score.playerName != null ? score.playerName : score.playerId;

        scorePrefabView
        .SetupLeaderboardScoreView(score.positionOnBoard, score.value, name);
    }
Esempio n. 12
0
    private void AddScore(float score)
    {
        LeaderboardScore lbScore = new LeaderboardScore(playerName, score, timeElapsedInSeconds);
        LeaderboardData  lbData  = SaveManager.GetLeaderboardData();

        lbData.allScores.Add(lbScore);
        lbData.allScores.Sort(
            delegate(LeaderboardScore x, LeaderboardScore y) {
            return(x.playerScore.CompareTo(y.playerScore));
        }
            );

        SaveManager.SaveLeaderboardData(lbData);
    }
    public void Set(int p_rank, LeaderboardScore p_score)
    {
        m_score          = p_score;
        m_rankText.text  = p_rank.ToString();
        m_nameText.text  = p_score.Name;
        m_scoreText.text = p_score.Score.ToString();

        if (m_editable)
        {
            InputField field = m_nameText.GetComponent <InputField>();
            field.Select();
            field.ActivateInputField();
        }
    }
 public static int CompareScores(LeaderboardScore first, LeaderboardScore second)
 {
     try {
         return(second.Time - first.Time > 0 ? -1 : 1);
     } catch (NullReferenceException) {
         if (first == null)
         {
             return(-1);
         }
         else
         {
             return(1);
         }
     }
 }
Esempio n. 15
0
        private void Deserialize(JSONObject json)
        {
            JSONObject data1        = json["data"];
            JSONObject leaderboard1 = data1["leaderboard"];
            JSONObject data2        = leaderboard1["data"];

            MetaData = new LeaderboardMetaData(data2);

            var myScoreData = json["data"]["myScore"]["data"];

            if (myScoreData != null && !myScoreData.IsNull)
            {
                CurrentScore = new LeaderboardScore(myScoreData);
            }
        }
    public void Load()
    {
        if (m_instantiatedObjects != null && m_instantiatedObjects.Count > 0)
        {
            return;
        }

        m_instantiatedObjects = new List <GameObject>();

        List <LeaderboardScore> scores  = m_local ? GetLocalScores() : GetOnlineScores();
        LeaderboardScore        pending = GetPendingScore();

        if (pending != null)
        {
            scores.Add(pending);
        }

        if (scores.Count > 0)
        {
            scores.Sort(CompareScores);
        }

        for (int i = 1; i <= m_loadedAmount; i++)
        {
            if (scores.Count < i)
            {
                break;
            }

            GameObject spotObj;

            if (scores[i - 1].Name.Length == 0)
            {
                spotObj = Instantiate(m_editableSpotPrefab, transform);
            }
            else
            {
                spotObj = Instantiate(m_spotPrefab, transform);
            }

            m_instantiatedObjects.Add(spotObj);
            LeaderboardSpot spot = spotObj.GetComponent <LeaderboardSpot>();

            spot.m_local  = m_local;
            spot.m_loader = this;
            spot.Set(i, scores[i - 1]);
        }
    }
Esempio n. 17
0
    private static void SaveData()
    {
        LeaderboardScore[] scores = new LeaderboardScore[leaderboard.Count];

        for (int i = 0; i < leaderboard.Count; i++)
        {
            LeaderboardScore lScore = (LeaderboardScore)leaderboard.GetByIndex(i);
            scores[i] = lScore;
        }

        string scoresToJson = ToJson <LeaderboardScore>(scores);

        Debug.Log(scoresToJson);
        PlayerPrefs.SetString(SavedLeaderboardName, scoresToJson);
        PlayerPrefs.SetString(SavedLastUserName, lastUser);
        PlayerPrefs.Save();
    }
Esempio n. 18
0
    private static void LoadData()
    {
        string scoresJson = PlayerPrefs.GetString(SavedLeaderboardName);

        lastUser = PlayerPrefs.GetString(SavedLastUserName);

        if (!string.IsNullOrEmpty(scoresJson))
        {
            LeaderboardScore[] scores = FromJson <LeaderboardScore>(scoresJson);

            for (int i = 0; i < scores.Length; i++)
            {
                LeaderboardScore lScore = scores[i];
                AddToLeaderboard(lScore);
            }
        }
    }
    public void AddScore(LeaderboardScore p_score)
    {
        List <LeaderboardScore> offline = GetLocalScores();

        offline.Sort(CompareScores);

        System.IO.StreamWriter Local = new System.IO.StreamWriter(Application.dataPath + "/Data/LocalLeaderboard.JSON", true);

        if (offline.Count < m_loadedAmount || offline[m_loadedAmount - 1].Time < p_score.Time) // if we make it in top x
        {
            Local.Write((offline.Count > 0 ? "\n" : "") + JsonUtility.ToJson(p_score));
        }

        Local.Close();

        DeletePendingScore();
    }
Esempio n. 20
0
        public void TestDeleteScoreAfterPlaying()
        {
            playToResults();

            ScoreInfo        score      = null;
            LeaderboardScore scorePanel = null;

            AddStep("get score", () => score = ((ResultsScreen)Game.ScreenStack.CurrentScreen).Score);

            AddAssert("ensure score is databased", () => Game.Realm.Run(r => r.Find <ScoreInfo>(score.ID)?.DeletePending == false));

            AddStep("press back button", () => Game.ChildrenOfType <BackButton>().First().Action());

            AddStep("show local scores",
                    () => Game.ChildrenOfType <BeatmapDetailAreaTabControl>().First().Current.Value = new BeatmapDetailAreaLeaderboardTabItem <BeatmapLeaderboardScope>(BeatmapLeaderboardScope.Local));

            AddUntilStep("wait for score displayed", () => (scorePanel = Game.ChildrenOfType <LeaderboardScore>().FirstOrDefault(s => s.Score.Equals(score))) != null);

            AddStep("right click panel", () =>
            {
                InputManager.MoveMouseTo(scorePanel);
                InputManager.Click(MouseButton.Right);
            });

            AddStep("click delete", () =>
            {
                var dropdownItem = Game
                                   .ChildrenOfType <PlayBeatmapDetailArea>().First()
                                   .ChildrenOfType <OsuContextMenu>().First()
                                   .ChildrenOfType <DrawableOsuMenuItem>().First(i => i.Item.Text.ToString() == "Delete");

                InputManager.MoveMouseTo(dropdownItem);
                InputManager.Click(MouseButton.Left);
            });

            AddUntilStep("wait for dialog display", () => Game.Dependencies.Get <DialogOverlay>().IsLoaded);
            AddUntilStep("wait for dialog", () => Game.Dependencies.Get <DialogOverlay>().CurrentDialog != null);
            AddStep("confirm deletion", () => InputManager.Key(Key.Number1));
            AddUntilStep("wait for dialog dismissed", () => Game.Dependencies.Get <DialogOverlay>().CurrentDialog == null);

            AddUntilStep("ensure score is pending deletion", () => Game.Realm.Run(r => r.Find <ScoreInfo>(score.ID)?.DeletePending == true));

            AddUntilStep("wait for score panel removal", () => scorePanel.Parent == null);
        }
        private void requestScoresCallback(bool succeeded, XML.WebResponse response)
        {
            if (succeeded)
            {
                var scores = new LeaderboardScore[response.Scores.Count];
                for (int i = 0; i != response.Scores.Count; ++i)
                {
                    var score = response.Scores[i];
                    scores[i] = new LeaderboardScore(score.Username, score.Score);
                }

                if (RequestScores_callback != null)
                {
                    RequestScores_callback(scores, true, null);
                }
            }
            else
            {
                if (RequestScores_callback != null)
                {
                    RequestScores_callback(null, false, response != null ? response.ErrorMessage : "Unkown");
                }
            }
        }
Esempio n. 22
0
    public void SaveScoreToJSON()
    {
        LeaderboardScore score = new LeaderboardScore("", Game.m_scores.GetTotalAdjustedTime(), Game.m_scores.GetTotalDeaths());

        WriteToJSON(score, Application.dataPath + "/Data/PendingScores.JSON");
    }
		private void guiRequestScoresCallback(LeaderboardScore[] scores, bool succeeded, string errorMessage)
		{
			if (succeeded)
			{
				guiScores = scores;
				guiMode = ReignScores_ClassicGuiModes.ShowingScores;
			}
			else
			{
				guiMode = ReignScores_ClassicGuiModes.None;
				if (guiShowNativeViewDoneCallback != null) guiShowNativeViewDoneCallback(false, errorMessage);
			}
		}
		private void requestScoresCallback(bool succeeded, XML.WebResponse response)
		{
			if (succeeded)
			{
				var scores = new LeaderboardScore[response.Scores.Count];
				for (int i = 0; i != response.Scores.Count; ++i)
				{
					var score = response.Scores[i];
					scores[i] = new LeaderboardScore(score.Username, score.Score);
				}

				if (RequestScores_callback != null) RequestScores_callback(scores, true, null);
			}
			else
			{
				if (RequestScores_callback != null) RequestScores_callback(null, false, response != null ? response.ErrorMessage : "Unkown");
			}
		}
Esempio n. 25
0
    public void SaveScoreToJSON()
    {
        LeaderboardScore score = new LeaderboardScore("", m_score.Value);

        WriteToJSON(score, Application.dataPath + "/Data/PendingScores.JSON");
    }
Esempio n. 26
0
 public static void AddToLeaderboard(LeaderboardScore score)
 {
     AddToLeaderboard(score.score, score.name, score.date);
 }
		private void requestScoresCallback(LeaderboardScore[] scores, bool succeeded, string errorMessage)
		{
			if (succeeded)
			{
				mode = ReignScores_UnityUIModes.ShowingScores;

				// clear values
				foreach (var username in Scores_Usernames) username.text = "";
				foreach (var value in Scores_ScoreValues) value.text = "";

				// set new values
				for (int i = 0; i != TopScoresToListPerPage; ++i)
				{
					if (i >= Scores_Usernames.Length || i >= Scores_ScoreValues.Length || i >= scores.Length) break;

					var score = scores[i];
					Scores_Usernames[i].text = score.Username;

					string scoreValue;
					if (ScoreFormatCallback != null) ScoreFormatCallback(score.Score, out scoreValue);
					else scoreValue = score.Score.ToString();
					Scores_ScoreValues[i].text = scoreValue;
				}
			}
			else
			{
				mode = ReignScores_UnityUIModes.None;
				if (showNativeViewDoneCallback != null) showNativeViewDoneCallback(false, errorMessage);
			}
		}
Esempio n. 28
0
 private static string ToKey(this LeaderboardScore score)
 {
     return(score + "0-" + score.name + score.date);
 }