Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Assets/Script/Gameplay/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,7 @@ private bool EndSong()
IsHighScore = player.Score > player.LastHighScore,
Player = player.Player,
Stats = player.BaseStats,
AverageMultiplier = player.BaseEngine.BaseNoteScore == 0 ?
0 :
// PendingScore should be 0 at this point, so no reason to add it
(float) player.BaseStats.CommittedScore / player.BaseEngine.BaseNoteScore,
IsReplay = player.Player.IsReplay
}).ToArray(),
BandScore = BandScore,
BandStars = (int) BandStars,
Expand Down
8 changes: 6 additions & 2 deletions Assets/Script/Menu/History/HistoryMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ protected override void OnEnable()
() => CurrentSelection?.ViewClick()),
new NavigationScheme.Entry(MenuAction.Red, "Menu.Common.Back",
Back, hide: true),
new NavigationScheme.Entry(MenuAction.Yellow, "Menu.History.Analyze",
() => CurrentSelection?.Shortcut1()),
new NavigationScheme.Entry(MenuAction.Yellow, "Menu.History.ViewScoreCard",
() => CurrentSelection?.ViewScoreCardClick()),
#if UNITY_EDITOR || YARG_TEST_BUILD // This is the replay analyze, which isn't really useful if you are not a dev
new NavigationScheme.Entry(MenuAction.Blue, "Menu.History.Analyze",
() => CurrentSelection?.AnalyzeReplayClick()),
#endif
new NavigationScheme.Entry(MenuAction.Orange, "Menu.History.PlayWithReplay",
() => CurrentSelection?.PlayWithReplayClick())
}, false));
Expand Down
107 changes: 102 additions & 5 deletions Assets/Script/Menu/History/ViewTypes/ReplayViewType.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
using YARG.Core.Logging;
using YARG.Core.Replays;
using YARG.Core.Replays.Analyzer;
using YARG.Core.Song;
using YARG.Helpers;
using YARG.Localization;
using YARG.Menu.Persistent;
using YARG.Menu.ScoreScreen;
using YARG.Player;
using YARG.Replays;
using YARG.Scores;
using YARG.Settings;
Expand All @@ -18,6 +22,8 @@ namespace YARG.Menu.History
public class ReplayViewType : ViewType
{
public override BackgroundType Background => BackgroundType.Normal;
private const string BASE_LOCALIZATION_KEY = "Menu.Dialog.ReplayMenu";


public override bool UseFullContainer => true;

Expand Down Expand Up @@ -83,7 +89,9 @@ public override async void ViewClick()
{
if (_songEntry == null)
{
DialogManager.Instance.ShowMessage("Unavailable Song", "A song compatible with the selected play is not present in your library! Most likely deleted!");
var title = Localize.Key(BASE_LOCALIZATION_KEY, "UnavailableSong.Title");
var desc = Localize.Key(BASE_LOCALIZATION_KEY, "UnavailableSong.Description");
DialogManager.Instance.ShowMessage(title, desc);
return;
}

Expand All @@ -97,7 +105,7 @@ public override async void ViewClick()
if (SettingsManager.Settings.ShowEngineInconsistencyDialog)
{
var dialog = DialogManager.Instance.ShowOneTimeMessage(
"Menu.Dialog.EngineInconsistency",
"Menu.Dialog.ReplayMenu.EngineInconsistency",
() =>
{
SettingsManager.Settings.ShowEngineInconsistencyDialog = false;
Expand All @@ -111,11 +119,13 @@ public override async void ViewClick()
}

// Analyze Replay Button
public override void Shortcut1()
public override void AnalyzeReplayClick()
{
if (_songEntry == null)
{
DialogManager.Instance.ShowMessage("Unavailable Song", "A song compatible with the selected play is not present in your library! Most likely deleted!");
var title = Localize.Key(BASE_LOCALIZATION_KEY, "UnavailableSong.Title");
var desc = Localize.Key(BASE_LOCALIZATION_KEY, "UnavailableSong.Description");
DialogManager.Instance.ShowMessage(title, desc);
return;
}

Expand Down Expand Up @@ -158,6 +168,93 @@ public override void Shortcut1()
}
}

public override void ViewScoreCardClick()
{
_entry ??= LoadReplay("Cannot load replay.");
if (_entry == null)
{
return;
}

if (_songEntry == null)
{
var title = Localize.Key(BASE_LOCALIZATION_KEY, "UnavailableSong.Title");
var desc = Localize.Key(BASE_LOCALIZATION_KEY, "UnavailableSong.Description");
DialogManager.Instance.ShowMessage(title, desc);
return;
}

GlobalVariables.State.CurrentSong = _songEntry;
GlobalVariables.State.CurrentReplay = _entry;
var chart = _songEntry.LoadChart();
if (chart == null)
{
YargLogger.LogError("Failed to load chart");
return;
}

var replayOptions = new ReplayReadOptions
{
KeepFrameTimes = GlobalVariables.VerboseReplays
};
var (result, data) = ReplayIO.TryLoadData(_entry, replayOptions);
if (result != ReplayReadResult.Valid)
{
YargLogger.LogFormatError("Failed to load replay data: {0}", result);
DialogManager.Instance.ShowMessage(Localize.Key(BASE_LOCALIZATION_KEY, "ReplayLoadFail.Title"), Localize.Key(BASE_LOCALIZATION_KEY, "ReplayLoadFail.Description"));
return;
}

var results = ReplayAnalyzer.AnalyzeReplay(chart, _entry, data);
bool replayConsistent = results.All(r => r.Passed);
if (!replayConsistent)
{
YargLogger.LogInfo("Replay did not pass verification!");
}

var playerScoreCards = new PlayerScoreCard[results.Length];
for (int i = 0; i < _entry.Stats.Length; i++)
{
var playerResult = results[i];
var playerEntry = _entry.Stats[i];
bool isHighScore;
if (_gameInfo.PlayerScoreRecords == null)
{
// Imported replays do not have PlayerScoreRecords
isHighScore = false;
}
else
{
var playerScoreRecord = _gameInfo.PlayerScoreRecords[i];
var currentHighScore = ScoreContainer.GetHighScore(_entry.SongChecksum, playerScoreRecord.PlayerId,
playerResult.Frame.Profile.CurrentInstrument, false);
isHighScore = currentHighScore != null &&
playerScoreRecord.GameRecordId == currentHighScore.GameRecordId;
}

playerScoreCards[i] = new PlayerScoreCard
{
// If it's null, technically it is a high score but who knows what the hell happened so don't show that
// This compares ids, so imported replays should never be the high score.
IsHighScore = isHighScore,
Player = new YargPlayer(playerResult.Frame, data),
Stats = playerResult.ResultStats,
IsReplay = playerEntry.IsReplayPlayer
};
}

GlobalVariables.State.ScoreScreenStats = new ScoreScreenStats
{
PlayerScores = playerScoreCards,
BandScore = _entry.BandScore,
BandStars = (int) _entry.BandStars,
ReplayInfo = _entry,
ReplayWasConsistent = results.All(r => r.Passed),
};
// Go to the score screen
GlobalVariables.Instance.LoadScene(SceneIndex.Score);
}

public void ExportReplay()
{
_entry ??= LoadReplay("Cannot Export Replay");
Expand Down Expand Up @@ -191,7 +288,7 @@ public override void PlayWithReplayClick()
{
return _gameInfo;
}

//TODO: This method needs to be localized
private ReplayInfo? LoadReplay(string messageBoxTitle)
{
if (_record == null)
Expand Down
7 changes: 6 additions & 1 deletion Assets/Script/Menu/History/ViewTypes/ViewType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public virtual void PlayWithReplayClick()

}

public virtual void Shortcut1()
public virtual void ViewScoreCardClick()
{

}

public virtual void AnalyzeReplayClick()
{

}
Expand Down
21 changes: 13 additions & 8 deletions Assets/Script/Menu/ScoreScreen/ScoreCards/ScoreCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ public abstract class ScoreCard<T> : MonoBehaviour, IScoreCard<T> where T : Base
private TextMeshProUGUI _offsetHistogramRightAxisLabel;
private readonly List<RectTransform> _offsetHistogramBarPool = new();

protected bool IsHighScore;
protected T Stats;
protected float AverageMultiplier;
protected bool IsHighScore;
protected T Stats;
protected bool IsReplay;

public YargPlayer Player { get; private set; }

Expand All @@ -125,12 +125,12 @@ private void Awake()
_colorizer = GetComponent<ScoreCardColorizer>();
}

public void Initialize(bool isHighScore, YargPlayer player, T stats, float averageMultiplier)
public void Initialize(bool isHighScore, YargPlayer player, T stats, bool isReplay)
{
IsHighScore = isHighScore;
Player = player;
Stats = stats;
AverageMultiplier = averageMultiplier;
IsReplay = isReplay;
}

public virtual void SetCardContents()
Expand Down Expand Up @@ -164,7 +164,7 @@ public virtual void SetCardContents()
_colorizer.SetCardColor(ScoreCardColorizer.ScoreCardColor.Gray);
ShowTag("Bot");
}
else if (Player.IsReplay)
else if (IsReplay)
{
if (Stats.IsFullCombo)
{
Expand All @@ -187,11 +187,16 @@ public virtual void SetCardContents()
_colorizer.SetCardColor(ScoreCardColorizer.ScoreCardColor.Blue);
ShowTag("High Score");
}
else
else if (!GlobalVariables.State.IsReplay)
{
_colorizer.SetCardColor(ScoreCardColorizer.ScoreCardColor.Blue);
ShowTag(SettingsManager.Settings.NoFail.Value != NoFailMode.Off ? "Completed" : "Cleared");
}
else
{
_colorizer.SetCardColor(ScoreCardColorizer.ScoreCardColor.Blue);
_tagGameObject.SetActive(false);
}

_score.text = Stats.TotalScore.ToString("N0");
_starView.SetStars((int) Stats.Stars);
Expand All @@ -202,7 +207,7 @@ public virtual void SetCardContents()
_notesMissedContainer.gameObject.SetActive(Stats.NotesMissed != 0);
_starpowerPhrases.text = $"{ColorizePrimary(Stats.StarPowerPhrasesHit)} / " +
$"{ColorizeSecondary(Stats.TotalStarPowerPhrases)}";
_averageMultiplier.text = ColorizePrimary(AverageMultiplier.ToString("0.00"));
_averageMultiplier.text = ColorizePrimary(Stats.AverageMultiplier.ToString("0.00"));
_bandBonusScore.text = ColorizePrimary(Stats.BandBonusScore.ToString("N0"));
_averageOffset.text = $"{ColorizePrimary(Math.Round(Stats.GetAverageOffset() * 1000, MidpointRounding.AwayFromZero))} {ColorizeSecondary("ms")}";
_starPowerActivations.text = ColorizePrimary(Stats.StarPowerActivationCount);
Expand Down
3 changes: 2 additions & 1 deletion Assets/Script/Menu/ScoreScreen/ScoreScreenContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace YARG.Menu.ScoreScreen
public struct PlayerScoreCard
{
public bool IsHighScore;
public float AverageMultiplier;
public bool IsReplay;

public YargPlayer Player;
public BaseStats Stats;
Expand All @@ -23,6 +23,7 @@ public struct ScoreScreenStats

#nullable enable
public ReplayInfo? ReplayInfo;
public bool? ReplayWasConsistent;
#nullable disable
}
}
Loading