Files
Delta-v/Content.Client/Nyanotrasen/ReverseEngineering/ReverseEngineeringMachineMenu.xaml.cs
T
708e17a3d3 reverse engineering refactor and missing recipe test (#1230)
* make jugg not atmos hardsuit reable lmao

* re machine yaml refactor

* use the enum name to localize re results

* move a lot of code to shared and refactor

* clientside rework

* add test for missing recipes

* untroll

* make exped board recipe yml consistent with upstream

* fix unearthed sneaky bugs + generic does nothing so remove

* add mass media console board, remove roundstart boards from dynamic recipes

* remove roundstart stuff, add rcd ammo to protolathe

* dont dupe because of access electronics prototypes

* fix final fails

* final untroll

* final untroll 2

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Co-authored-by: Null <56081759+NullWanderer@users.noreply.github.com>
2024-06-01 21:31:06 +00:00

88 lines
3.0 KiB
C#

using Content.Client.UserInterface.Controls;
using Content.Shared.ReverseEngineering;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.State;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Timing;
namespace Content.Client.Nyanotrasen.ReverseEngineering;
[GenerateTypedNameReferences]
public sealed partial class ReverseEngineeringMachineMenu : FancyWindow
{
private readonly IEntityManager _entMan;
private readonly IGameTiming _timing;
private readonly SharedReverseEngineeringSystem _revEng;
private readonly Entity<ReverseEngineeringMachineComponent> _owner;
public event Action? OnScanButtonPressed;
public event Action? OnSafetyButtonToggled;
public event Action? OnAutoScanButtonToggled;
public event Action? OnStopButtonPressed;
public event Action? OnEjectButtonPressed;
public ReverseEngineeringMachineMenu(EntityUid owner, IEntityManager entMan, IGameTiming timing)
{
RobustXamlLoader.Load(this);
_entMan = entMan;
_timing = timing;
_revEng = entMan.System<SharedReverseEngineeringSystem>();
_owner = (owner, entMan.GetComponent<ReverseEngineeringMachineComponent>(owner));
ScanButton.OnPressed += _ => OnScanButtonPressed?.Invoke();
SafetyButton.OnToggled += _ => OnSafetyButtonToggled?.Invoke();
AutoScanButton.OnToggled += _ => OnAutoScanButtonToggled?.Invoke();
StopButton.OnPressed += _ => OnStopButtonPressed?.Invoke();
EjectButton.OnPressed += _ => OnEjectButtonPressed?.Invoke();
}
private void UpdateArtifactIcon(EntityUid? uid)
{
if (uid == null)
{
ItemDisplay.Visible = false;
return;
}
ItemDisplay.Visible = true;
ItemDisplay.SetEntity(uid);
}
public void UpdateState(ReverseEngineeringMachineState state)
{
Information.SetMessage(state.ScanMessage);
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
var scanning = _revEng.IsActive(_owner);
var item = _revEng.GetItem(_owner);
ScanButton.Disabled = scanning || item == null;
StopButton.Disabled = !scanning;
SafetyButton.Pressed = _owner.Comp.SafetyOn;
AutoScanButton.Pressed = _owner.Comp.AutoScan;
EjectButton.Disabled = ScanButton.Disabled;
UpdateArtifactIcon(item);
ProgressBox.Visible = scanning;
if (!_entMan.TryGetComponent<ActiveReverseEngineeringMachineComponent>(_owner, out var active)
|| !_entMan.TryGetComponent<ReverseEngineeringComponent>(item, out var rev))
return;
TotalProgressBar.Value = (float) rev.Progress;
var remaining = Math.Max(active.NextProbe.TotalSeconds - _timing.CurTime.TotalSeconds, 0.0);
ProgressLabel.Text = Loc.GetString("analysis-console-progress-text", ("seconds", (int) remaining));
ProgressBar.Value = 1f - (float) (remaining / _owner.Comp.AnalysisDuration.TotalSeconds);
}
}