50 lines
1.6 KiB
C#
50 lines
1.6 KiB
C#
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared.Mind;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Player;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client._DV.CustomObjectiveSummary;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class CustomObjectiveSummaryWindow : FancyWindow
|
|
{
|
|
[Dependency] private readonly IPlayerManager _players = default!;
|
|
[Dependency] private readonly IEntityManager _entity = default!;
|
|
|
|
private SharedMindSystem? _mind;
|
|
|
|
private readonly int _maxLength = 256;
|
|
|
|
public event Action<string>? OnSubmitted;
|
|
|
|
public CustomObjectiveSummaryWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
SubmitButton.OnPressed +=
|
|
_ => OnSubmitted?.Invoke(Rope.Collapse(ObjectiveSummaryTextEdit.TextRope));
|
|
ObjectiveSummaryTextEdit.OnTextChanged += _ => UpdateWordCount();
|
|
|
|
_mind ??= _entity.System<SharedMindSystem>();
|
|
|
|
_mind.TryGetMind(_players.LocalSession, out var mindUid, out _);
|
|
|
|
UpdateWordCount();
|
|
|
|
if (_entity.TryGetComponent<Shared._DV.CustomObjectiveSummary.CustomObjectiveSummaryComponent>(mindUid, out var summary))
|
|
ObjectiveSummaryTextEdit.TextRope = new Rope.Leaf(summary.ObjectiveSummary);
|
|
|
|
UpdateWordCount();
|
|
}
|
|
|
|
private void UpdateWordCount()
|
|
{
|
|
// Disable the button if its over the max length.sa
|
|
SubmitButton.Disabled = ObjectiveSummaryTextEdit.TextLength > _maxLength;
|
|
CharacterLimitLabel.Text = ObjectiveSummaryTextEdit.TextLength + "/" + _maxLength;
|
|
}
|
|
}
|