/// <summary> /// Checks if there are new scoreboard users. /// </summary> private void CheckIfNewScoreboardUsers() { if (Screen.IsPlayTesting || StopCheckingForScoreboardUsers) { return; } var mapScores = MapManager.Selected.Value.Scores.Value; if (mapScores == null || mapScores.Count <= 0 || (ScoreboardLeft.Users?.Count < 1 && ScoreboardRight != null && ScoreboardRight.Users.Count < 1)) { return; } for (var i = 0; i < (OnlineManager.CurrentGame == null ? 4 : mapScores.Count) && i < mapScores.Count; i++) { ScoreboardUser user; // For online scores we want to just give them their score in the processor, // since we don't have access to their judgement breakdown. if (mapScores[i].IsOnline) { user = new ScoreboardUser(Screen, ScoreboardUserType.Other, $"{mapScores[i].Name}", new List <Judgement>(), UserInterface.UnknownAvatar, (ModIdentifier)mapScores[i].Mods, mapScores[i]) { Parent = Container, Alignment = Alignment.MidLeft }; if (OnlineManager.CurrentGame != null && OnlineManager.CurrentGame.Ruleset == MultiplayerGameRuleset.Team && OnlineManager.GetTeam(user.LocalScore.PlayerId) == MultiplayerTeam.Blue) { user.Scoreboard = ScoreboardRight; user.X = WindowManager.Width; } else { user.Scoreboard = ScoreboardLeft; } user.SetImage(); var processor = user.Processor as ScoreProcessorKeys; processor.Accuracy = (float)mapScores[i].Accuracy; processor.MaxCombo = mapScores[i].MaxCombo; processor.Score = mapScores[i].TotalScore; user.Score.Text = $"{user.RatingProcessor.CalculateRating(processor.Accuracy):0.00} / {StringHelper.AccuracyToString(processor.Accuracy)}"; user.Combo.Text = $"{processor.MaxCombo}x"; } // Allow the user to play against their own local scores. else { // Decompress score var breakdownHits = GzipHelper.Decompress(mapScores[i].JudgementBreakdown); var judgements = new List <Judgement>(); // Get all of the hit stats for the score. foreach (var hit in breakdownHits) { judgements.Add((Judgement)int.Parse(hit.ToString())); } user = new ScoreboardUser(Screen, ScoreboardUserType.Other, $"{mapScores[i].Name}", judgements, UserInterface.UnknownAvatar, (ModIdentifier)mapScores[i].Mods, mapScores[i]) { Parent = Container, Alignment = Alignment.MidLeft }; if (OnlineManager.CurrentGame != null && OnlineManager.CurrentGame.Ruleset == MultiplayerGameRuleset.Team && OnlineManager.GetTeam(user.LocalScore.PlayerId) == MultiplayerTeam.Blue) { user.Scoreboard = ScoreboardRight; } else { user.Scoreboard = ScoreboardLeft; } user.SetImage(); // Make sure the user's score is updated with the current user. for (var j = 0; j < Screen.Ruleset.ScoreProcessor.TotalJudgementCount && i < judgements.Count; j++) { var processor = user.Processor as ScoreProcessorKeys; processor?.CalculateScore(judgements[i]); } } if (OnlineManager.CurrentGame != null && OnlineManager.CurrentGame.Ruleset == MultiplayerGameRuleset.Team && OnlineManager.GetTeam(user.LocalScore.PlayerId) == MultiplayerTeam.Blue) { ScoreboardRight.Users.Add(user); } else { ScoreboardLeft.Users.Add(user); } } ScoreboardLeft.SetTargetYPositions(); ScoreboardRight?.SetTargetYPositions(); // Re-change the transitioner and pause screen's parent so that they appear on top of the scoreboard // again. if (ProgressBar != null) { ProgressBar.Parent = Container; } Transitioner.Parent = Container; PauseScreen.Parent = Container; StopCheckingForScoreboardUsers = true; Screen.SetRichPresence(); }
/// <summary> /// Updates the scoreboard for all the current users. /// </summary> public void UpdateScoreboardUsers() { ScoreboardLeft?.CalculateScores(); ScoreboardRight?.CalculateScores(); }