298 lines
11 KiB
C#
298 lines
11 KiB
C#
using System.Numerics; // DeltaV
|
|
using System.Text;
|
|
using Content.Client.Message;
|
|
using Content.Client.Resources;
|
|
using Content.Client.UserInterface.Controls;
|
|
using Content.Client.Xenoarchaeology.Artifact;
|
|
using Content.Client.Xenoarchaeology.Equipment;
|
|
using Content.Shared.Xenoarchaeology.Artifact.Components;
|
|
using Content.Shared.Xenoarchaeology.Equipment.Components;
|
|
using Robust.Client.Audio;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.ResourceManagement;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client.Xenoarchaeology.Ui;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class AnalysisConsoleMenu : FancyWindow
|
|
{
|
|
private static readonly TimeSpan ExtractInfoDisplayForDuration = TimeSpan.FromSeconds(5);// DeltaV
|
|
|
|
[Dependency] private readonly IEntityManager _ent = default!;
|
|
[Dependency] private readonly IResourceCache _resCache = default!;
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
|
|
private readonly ArtifactAnalyzerSystem _artifactAnalyzer;
|
|
private readonly XenoArtifactSystem _xenoArtifact;
|
|
private readonly AudioSystem _audio;
|
|
private readonly MetaDataSystem _meta = default!;
|
|
|
|
private Entity<AnalysisConsoleComponent> _owner;
|
|
private Entity<XenoArtifactNodeComponent>? _currentNode;
|
|
|
|
private TimeSpan? _hideExtractInfoIn;
|
|
|
|
// Begin DeltaV - Variables for extraction calculation display
|
|
private int _extractionSum;
|
|
private int _glimmerSum;
|
|
private float _multValue;
|
|
private float _ratioValue;
|
|
private bool _pressed;
|
|
// End DeltaV
|
|
public event Action? OnServerSelectionButtonPressed;
|
|
public event Action? OnExtractButtonPressed;
|
|
|
|
public AnalysisConsoleMenu()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
_xenoArtifact = _ent.System<XenoArtifactSystem>();
|
|
_artifactAnalyzer = _ent.System<ArtifactAnalyzerSystem>();
|
|
_audio = _ent.System<AudioSystem>();
|
|
_meta = _ent.System<MetaDataSystem>();
|
|
|
|
if (BackPanel.PanelOverride is StyleBoxTexture tex)
|
|
tex.Texture = _resCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
|
|
|
|
GraphControl.OnNodeSelected += node =>
|
|
{
|
|
_currentNode = node;
|
|
SetSelectedNode(node);
|
|
};
|
|
|
|
ServerButton.OnPressed += _ =>
|
|
{
|
|
OnServerSelectionButtonPressed?.Invoke();
|
|
};
|
|
|
|
// DeltaV
|
|
ExtractButton.OnPressed += _ =>
|
|
{
|
|
_pressed = true;
|
|
OnExtractButtonPressed?.Invoke();
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set entity that corresponds analysis console, for which window is opened.
|
|
/// Closes window if <see cref="AnalysisConsoleComponent"/> is not present on entity.
|
|
/// </summary>
|
|
public void SetOwner(EntityUid owner)
|
|
{
|
|
if (!_ent.TryGetComponent<AnalysisConsoleComponent>(owner, out var comp))
|
|
{
|
|
Close();
|
|
return;
|
|
}
|
|
|
|
_owner = (owner, comp);
|
|
Update(_owner);
|
|
}
|
|
|
|
// DeltaV
|
|
public void UpdateState(float mult, float ratio)
|
|
{
|
|
_multValue = mult;
|
|
_ratioValue = ratio;
|
|
if (_pressed)
|
|
{
|
|
_pressed = false;
|
|
StartExtract();
|
|
return;
|
|
}
|
|
}
|
|
|
|
private void StartExtract() // DeltaV - args changed
|
|
{
|
|
if (!_artifactAnalyzer.TryGetArtifactFromConsole(_owner, out var artifact))
|
|
return;
|
|
|
|
ExtractContainer.Visible = true;
|
|
NodeViewContainer.Visible = false;
|
|
|
|
_extractionSum = 0;// DeltaV
|
|
_glimmerSum = 0;// DeltaV
|
|
var extractionMessage = new FormattedMessage();
|
|
|
|
var nodes = _xenoArtifact.GetAllNodes(artifact.Value);
|
|
|
|
var count = 0;
|
|
foreach (var node in nodes)
|
|
{
|
|
var pointValue = _xenoArtifact.GetResearchValue(node) * _multValue;// DeltaV
|
|
var glimmerValue = (pointValue / _ratioValue / _multValue);// DeltaV
|
|
if (pointValue <= 0)
|
|
continue;
|
|
|
|
count++;
|
|
|
|
var nodeId = _xenoArtifact.GetNodeId(node);
|
|
_extractionSum += (int)pointValue;// DeltaV
|
|
_glimmerSum += (int)(glimmerValue);// DeltaV
|
|
var textPoints = Loc.GetString("analysis-console-extract-value", ("id", nodeId), ("value", (int)(pointValue)));
|
|
var textGlimmer = Loc.GetString("analysis-console-glimmer-value", ("id", nodeId), ("value", (int)(glimmerValue)));// DeltaV
|
|
extractionMessage.AddMarkupOrThrow(textPoints);
|
|
extractionMessage.PushNewline();
|
|
extractionMessage.AddMarkupOrThrow(textGlimmer);// DeltaV
|
|
extractionMessage.PushNewline();
|
|
}
|
|
|
|
if (count == 0)
|
|
extractionMessage.AddMarkupOrThrow(Loc.GetString("analysis-console-extract-none"));
|
|
|
|
_hideExtractInfoIn = _timing.CurTime + ExtractInfoDisplayForDuration;
|
|
|
|
ExtractionResearchLabel.SetMessage(extractionMessage);
|
|
|
|
ExtractionSumLabel.SetMarkup(Loc.GetString("analysis-console-extract-sum", ("value", _extractionSum)));// DeltaV
|
|
GlimmerSumLabel.SetMarkup(Loc.GetString("analysis-console-glimmer-sum", ("value", _glimmerSum)));// DeltaV
|
|
MultLabel.SetMarkup(Loc.GetString("analysis-console-glimmer-mult", ("value", _multValue.ToString("F2"))));// DeltaV
|
|
|
|
_audio.PlayGlobal(_owner.Comp.ScanFinishedSound, _owner, AudioParams.Default.WithVolume(1f));
|
|
|
|
}
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
|
{
|
|
base.FrameUpdate(args);
|
|
|
|
if (_hideExtractInfoIn == null || _timing.CurTime + _meta.GetPauseTime(_owner) < _hideExtractInfoIn)
|
|
return;
|
|
|
|
ExtractContainer.Visible = false;
|
|
NodeViewContainer.Visible = true;
|
|
_hideExtractInfoIn = null;
|
|
}
|
|
|
|
public void Update(Entity<AnalysisConsoleComponent> ent)
|
|
{
|
|
_artifactAnalyzer.TryGetArtifactFromConsole(ent, out var arti);
|
|
ArtifactView.SetEntity(arti);
|
|
GraphControl.SetArtifact(arti);
|
|
|
|
ExtractButton.Disabled = arti == null;
|
|
|
|
if (arti == null)
|
|
NoneSelectedLabel.Visible = false;
|
|
|
|
NoArtiLabel.Visible = true;
|
|
if (!_artifactAnalyzer.TryGetAnalyzer(ent, out _))
|
|
NoArtiLabel.Text = Loc.GetString("analysis-console-info-no-scanner");
|
|
else if (arti == null)
|
|
NoArtiLabel.Text = Loc.GetString("analysis-console-info-no-artifact");
|
|
else
|
|
NoArtiLabel.Visible = false;
|
|
|
|
if (_currentNode == null
|
|
|| arti == null
|
|
|| !_xenoArtifact.TryGetIndex((arti.Value, arti.Value), _currentNode.Value, out _))
|
|
{
|
|
SetSelectedNode(null);
|
|
}
|
|
}
|
|
|
|
public void SetSelectedNode(Entity<XenoArtifactNodeComponent>? node)
|
|
{
|
|
InfoContainer.Visible = node != null;
|
|
if (!_artifactAnalyzer.TryGetArtifactFromConsole(_owner, out var artifact))
|
|
return;
|
|
|
|
NoneSelectedLabel.Visible = node == null;
|
|
|
|
if (node == null)
|
|
return;
|
|
|
|
var nodeId = _xenoArtifact.GetNodeId(node.Value);
|
|
IDValueLabel.SetMarkup(Loc.GetString("analysis-console-info-id-value", ("id", nodeId)));
|
|
|
|
// If active, state is 2. else, it is 0 or 1 based on whether it is unlocked, or not.
|
|
int lockedState;
|
|
if (_xenoArtifact.IsNodeActive(artifact.Value, node.Value))
|
|
lockedState = 2;
|
|
else
|
|
lockedState = node.Value.Comp.Locked ? 0 : 1;
|
|
|
|
LockedValueLabel.SetMarkup(Loc.GetString("analysis-console-info-locked-value", ("state", lockedState)));
|
|
|
|
var percent = (float) node.Value.Comp.Durability / node.Value.Comp.MaxDurability;
|
|
var color = percent switch
|
|
{
|
|
>= 0.75f => Color.Lime,
|
|
>= 0.50f => Color.Yellow,
|
|
_ => Color.Red
|
|
};
|
|
DurabilityValueLabel.SetMarkup(Loc.GetString("analysis-console-info-durability-value",
|
|
("color", color),
|
|
("current", node.Value.Comp.Durability),
|
|
("max", node.Value.Comp.MaxDurability)));
|
|
|
|
var hasInfo = _xenoArtifact.HasUnlockedPredecessor(artifact.Value, node.Value);
|
|
|
|
// DeltaV - start of hide locked node effects
|
|
var specificInfo = node.Value.Comp.EffectTipSpecific ?? "xenoarch-effect-tip-unknown";
|
|
if (!hasInfo || (node.Value.Comp.LockedEffectTipHidden && node.Value.Comp.Locked))
|
|
{
|
|
EffectValueLabel.SetMarkup(Loc.GetString("analysis-console-info-effect-value",
|
|
("state", hasInfo ? XenoArtifactEffectVisibility.Hidden : XenoArtifactEffectVisibility.NoInfo)));
|
|
}
|
|
else if (!node.Value.Comp.LockedEffectTipHidden && node.Value.Comp.LockedEffectTipVague && node.Value.Comp.EffectTipVague != null)
|
|
{
|
|
EffectValueLabel.SetMarkup(Loc.GetString("analysis-console-info-effect-value",
|
|
("state", node.Value.Comp.Locked ? XenoArtifactEffectVisibility.VagueOnly : XenoArtifactEffectVisibility.VagueAndSpecific),
|
|
("specificInfo", Loc.GetString(specificInfo)),
|
|
("vagueInfo", Loc.GetString(node.Value.Comp.EffectTipVague))));
|
|
}
|
|
else
|
|
{
|
|
EffectValueLabel.SetMarkup(Loc.GetString("analysis-console-info-effect-value",
|
|
("state", XenoArtifactEffectVisibility.Simple),
|
|
("specificInfo", Loc.GetString(specificInfo))));
|
|
}
|
|
// DeltaV - end of hide locked node effects
|
|
|
|
var predecessorNodes = _xenoArtifact.GetPredecessorNodes(artifact.Value.Owner, node.Value);
|
|
if (!hasInfo)
|
|
{
|
|
// DeltaV - start of hide locked node effects
|
|
TriggerValueLabel.SetMarkup(Loc.GetString("analysis-console-info-effect-value", ("state", XenoArtifactEffectVisibility.NoInfo)));
|
|
// DeltaV - end of hide locked node effects
|
|
}
|
|
else
|
|
{
|
|
var triggerStr = new StringBuilder();
|
|
triggerStr.Append("- ");
|
|
triggerStr.Append(Loc.GetString(node.Value.Comp.TriggerTip!));
|
|
|
|
foreach (var predecessor in predecessorNodes)
|
|
{
|
|
triggerStr.AppendLine();
|
|
triggerStr.Append("- ");
|
|
triggerStr.Append(Loc.GetString(predecessor.Comp.TriggerTip!));
|
|
}
|
|
TriggerValueLabel.SetMarkup(Loc.GetString("analysis-console-info-triggered-value", ("triggers", triggerStr.ToString())));
|
|
}
|
|
|
|
ClassValueLabel.SetMarkup(Loc.GetString("analysis-console-info-class-value",
|
|
("class", Loc.GetString($"artifact-node-class-{Math.Min(6, predecessorNodes.Count + 1)}"))));
|
|
}
|
|
|
|
// DeltaV - start of hide locked node effects
|
|
public enum XenoArtifactEffectVisibility : sbyte
|
|
{
|
|
NoInfo = 0,
|
|
Hidden = 1,
|
|
Simple = 2,
|
|
VagueOnly = 3,
|
|
VagueAndSpecific = 4,
|
|
}
|
|
// DeltaV - end of hide locked node effects
|
|
}
|
|
|