78 lines
3.2 KiB
C#
78 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using KernelPanic.Combat;
|
|
using KernelPanic.Core;
|
|
using KernelPanic.Data;
|
|
using KernelPanic.Meta;
|
|
using KernelPanic.Run;
|
|
using UnityEngine;
|
|
using UnityEngine.TextCore.Text;
|
|
using UnityEngine.UIElements;
|
|
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
|
|
namespace KernelPanic.UI
|
|
{
|
|
public sealed partial class MainMenuController
|
|
{
|
|
private void OpenRunHistory()
|
|
{
|
|
if (PersistenceBlocked || _runHistoryOverlay != null) return;
|
|
_runHistoryOverlay = RunHistoryView.Build(_saveData.recentRuns, CloseRunHistory,
|
|
cardDatabase, packageDatabase, LoadArchivedBuildIntoSetup, ArchivedBuildUnavailableReason);
|
|
_root.Add(_runHistoryOverlay);
|
|
TerminalTheme.ConstrainModalFocus(_runHistoryOverlay);
|
|
(_runHistoryOverlay.Q<Button>("CopyRunSeed_0") ?? _runHistoryOverlay.Q<Button>("CloseRunHistory"))?.Focus();
|
|
}
|
|
|
|
private void CloseRunHistory()
|
|
{
|
|
_runHistoryOverlay?.RemoveFromHierarchy();
|
|
_runHistoryOverlay = null;
|
|
_root.Q<Button>("RecentRunsButton")?.Focus();
|
|
}
|
|
|
|
private string ArchivedBuildUnavailableReason(RunHistoryEntry entry)
|
|
{
|
|
return RunHistory.TryResolveBuild(entry, _playerCollection, distroDatabase, cardDatabase,
|
|
packageDatabase, languageDeckDatabase, out _, out string reason) ? null : reason;
|
|
}
|
|
|
|
private void LoadArchivedBuildIntoSetup(RunHistoryEntry entry)
|
|
{
|
|
if (PersistenceBlocked || _runLaunchPending) return;
|
|
if (!RunHistory.TryResolveBuild(entry, _playerCollection, distroDatabase, cardDatabase,
|
|
packageDatabase, languageDeckDatabase, out var build, out string reason))
|
|
{
|
|
var notice = _runHistoryOverlay?.Q<Label>("RunHistoryNotice");
|
|
if (notice != null) notice.text = reason + " Your setup has not been changed.";
|
|
return;
|
|
}
|
|
|
|
// Validation completes before replacing any draft. Loading is not launching: do not
|
|
// change the last-run retry snapshot, hand off a run, or consume a saved repository.
|
|
CaptureSelectedDraftLanguages();
|
|
_cardLoadout.TryLoad(build.Distro.Id, build.CardIds, out _);
|
|
_packageLoadout.Load(build.Distro.Id, build.PackageSlots);
|
|
for (int i = 0; i < _playerCollection.OwnedUnits.Count; i++)
|
|
if (string.Equals(_playerCollection.OwnedUnits[i].Id, build.Distro.Id, StringComparison.OrdinalIgnoreCase))
|
|
_selectedPackageIndex = i;
|
|
_draftLanguagesByDistro[build.Distro.Id] = new List<Language>(build.Languages);
|
|
RestoreSelectedDraftLanguages();
|
|
_runSeedText = build.Seed.ToString(CultureInfo.InvariantCulture);
|
|
SaveCurrentState();
|
|
if (PersistenceBlocked) return;
|
|
CloseRunHistory();
|
|
HandleStartRunClicked();
|
|
_runSetupNotice = build.Notice
|
|
+ (_saveData.activeRun == null ? "" : " Your saved repository run is still available.");
|
|
RenderSelectedPackageDetail();
|
|
}
|
|
|
|
}
|
|
}
|