Add reckless replay load button (#26212)

* Add reckless replay load button

* A

* More descriptive button
This commit is contained in:
Leon Friedrich
2024-03-18 18:31:36 +11:00
committed by GitHub
parent 7561bef6a7
commit 646f7e07a8
4 changed files with 72 additions and 10 deletions

View File

@@ -70,6 +70,7 @@ namespace Content.Client.Entry
[Dependency] private readonly IResourceManager _resourceManager = default!; [Dependency] private readonly IResourceManager _resourceManager = default!;
[Dependency] private readonly IReplayLoadManager _replayLoad = default!; [Dependency] private readonly IReplayLoadManager _replayLoad = default!;
[Dependency] private readonly ILogManager _logManager = default!; [Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly ContentReplayPlaybackManager _replayMan = default!;
public override void Init() public override void Init()
{ {
@@ -191,6 +192,7 @@ namespace Content.Client.Entry
_resourceManager, _resourceManager,
ReplayConstants.ReplayZipFolder.ToRootedPath()); ReplayConstants.ReplayZipFolder.ToRootedPath());
_replayMan.LastLoad = (null, ReplayConstants.ReplayZipFolder.ToRootedPath());
_replayLoad.LoadAndStartReplay(reader); _replayLoad.LoadAndStartReplay(reader);
} }
else if (_gameController.LaunchState.FromLauncher) else if (_gameController.LaunchState.FromLauncher)

View File

@@ -1,8 +1,10 @@
using System.IO.Compression;
using Content.Client.Administration.Managers; using Content.Client.Administration.Managers;
using Content.Client.Launcher; using Content.Client.Launcher;
using Content.Client.MainMenu; using Content.Client.MainMenu;
using Content.Client.Replay.Spectator; using Content.Client.Replay.Spectator;
using Content.Client.Replay.UI.Loading; using Content.Client.Replay.UI.Loading;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Systems.Chat; using Content.Client.UserInterface.Systems.Chat;
using Content.Shared.Chat; using Content.Shared.Chat;
using Content.Shared.Effects; using Content.Shared.Effects;
@@ -24,7 +26,13 @@ using Robust.Client.Replays.Playback;
using Robust.Client.State; using Robust.Client.State;
using Robust.Client.Timing; using Robust.Client.Timing;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.ContentPack;
using Robust.Shared.Serialization.Markdown.Mapping; using Robust.Shared.Serialization.Markdown.Mapping;
using Robust.Shared.Utility;
namespace Content.Client.Replay; namespace Content.Client.Replay;
@@ -41,6 +49,8 @@ public sealed class ContentReplayPlaybackManager
[Dependency] private readonly IClientAdminManager _adminMan = default!; [Dependency] private readonly IClientAdminManager _adminMan = default!;
[Dependency] private readonly IPlayerManager _player = default!; [Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IBaseClient _client = default!; [Dependency] private readonly IBaseClient _client = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IResourceManager _resMan = default!;
/// <summary> /// <summary>
/// UI state to return to when stopping a replay or loading fails. /// UI state to return to when stopping a replay or loading fails.
@@ -51,6 +61,13 @@ public sealed class ContentReplayPlaybackManager
private bool _initialized; private bool _initialized;
/// <summary>
/// Most recently loaded file, for re-attempting the load with error tolerance.
/// Required because the zip reader auto-disposes and I'm too lazy to change it so that
/// <see cref="ReplayFileReaderZip"/> can re-open it.
/// </summary>
public (ResPath? Zip, ResPath Folder)? LastLoad;
public void Initialize() public void Initialize()
{ {
if (_initialized) if (_initialized)
@@ -73,11 +90,50 @@ public sealed class ContentReplayPlaybackManager
private void OnFinishedLoading(Exception? exception) private void OnFinishedLoading(Exception? exception)
{ {
if (exception != null) if (exception == null)
{ {
ReturnToDefaultState(); LastLoad = null;
_uiMan.Popup(Loc.GetString("replay-loading-failed", ("reason", exception))); return;
} }
ReturnToDefaultState();
// Show a popup window with the error message
var text = Loc.GetString("replay-loading-failed", ("reason", exception));
var box = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Vertical,
Children = {new Label {Text = text}}
};
var popup = new DefaultWindow { Title = "Error!" };
popup.Contents.AddChild(box);
// Add button for attempting to re-load the replay while ignoring some errors.
if (!_cfg.GetCVar(CVars.ReplayIgnoreErrors) && LastLoad is {} last)
{
var button = new Button
{
Text = Loc.GetString("replay-loading-retry"),
StyleClasses = { StyleBase.ButtonCaution }
};
button.OnPressed += _ =>
{
_cfg.SetCVar(CVars.ReplayIgnoreErrors, true);
popup.Dispose();
IReplayFileReader reader = last.Zip == null
? new ReplayFileReaderResources(_resMan, last.Folder)
: new ReplayFileReaderZip(new(_resMan.UserData.OpenRead(last.Zip.Value)), last.Folder);
_loadMan.LoadAndStartReplay(reader);
};
box.AddChild(button);
}
popup.OpenCentered();
} }
public void ReturnToDefaultState() public void ReturnToDefaultState()

View File

@@ -1,6 +1,7 @@
using System.IO.Compression; using System.IO.Compression;
using System.Linq; using System.Linq;
using Content.Client.Message; using Content.Client.Message;
using Content.Client.Replay;
using Content.Client.UserInterface.Systems.EscapeMenu; using Content.Client.UserInterface.Systems.EscapeMenu;
using Robust.Client; using Robust.Client;
using Robust.Client.Replays.Loading; using Robust.Client.Replays.Loading;
@@ -31,6 +32,7 @@ public sealed class ReplayMainScreen : State
[Dependency] private readonly IGameController _controllerProxy = default!; [Dependency] private readonly IGameController _controllerProxy = default!;
[Dependency] private readonly IClientRobustSerializer _serializer = default!; [Dependency] private readonly IClientRobustSerializer _serializer = default!;
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!; [Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly ContentReplayPlaybackManager _replayMan = default!;
private ReplayMainMenuControl _mainMenuControl = default!; private ReplayMainMenuControl _mainMenuControl = default!;
private SelectReplayWindow? _selectWindow; private SelectReplayWindow? _selectWindow;
@@ -207,13 +209,14 @@ public sealed class ReplayMainScreen : State
private void OnLoadPressed(BaseButton.ButtonEventArgs obj) private void OnLoadPressed(BaseButton.ButtonEventArgs obj)
{ {
if (_selected.HasValue) if (!_selected.HasValue)
{ return;
_replayMan.LastLoad = (_selected.Value, ReplayZipFolder);
var fileReader = new ReplayFileReaderZip( var fileReader = new ReplayFileReaderZip(
new ZipArchive(_resMan.UserData.OpenRead(_selected.Value)), ReplayZipFolder); new ZipArchive(_resMan.UserData.OpenRead(_selected.Value)), ReplayZipFolder);
_loadMan.LoadAndStartReplay(fileReader); _loadMan.LoadAndStartReplay(fileReader);
} }
}
private void RefreshReplays() private void RefreshReplays()
{ {

View File

@@ -6,8 +6,9 @@ replay-loading-processing = Processing Files
replay-loading-spawning = Spawning Entities replay-loading-spawning = Spawning Entities
replay-loading-initializing = Initializing Entities replay-loading-initializing = Initializing Entities
replay-loading-starting= Starting Entities replay-loading-starting= Starting Entities
replay-loading-failed = Failed to load replay: replay-loading-failed = Failed to load replay. Error:
{$reason} {$reason}
replay-loading-retry = Try load with more exception tolerance - MAY CAUSE BUGS!
# Main Menu # Main Menu
replay-menu-subtext = Replay Client replay-menu-subtext = Replay Client