66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared._DV.CCVars;
|
|
using Content.Shared.Mind;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Player;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Configuration;
|
|
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!;
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
|
|
private SharedMindSystem? _mind;
|
|
|
|
// Maximum length the summary can be in characters.
|
|
private int _maxLengthSummaryLength;
|
|
|
|
public event Action<string>? OnSubmitted;
|
|
|
|
public CustomObjectiveSummaryWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
_cfg.OnValueChanged(DCCVars.MaxObjectiveSummaryLength, len =>
|
|
{
|
|
_maxLengthSummaryLength = len;
|
|
UpdateWordCount();
|
|
},
|
|
invokeImmediately: true);
|
|
|
|
SubmitButton.OnPressed +=
|
|
_ => OnSubmitted?.Invoke(Rope.Collapse(ObjectiveSummaryTextEdit.TextRope));
|
|
ObjectiveSummaryTextEdit.OnTextChanged += _ => UpdateWordCount();
|
|
|
|
_mind ??= _entity.System<SharedMindSystem>();
|
|
|
|
_mind.TryGetMind(_players.LocalSession, out var mindUid, out _);
|
|
|
|
// This is only for if you quit the server then rejoin.
|
|
if (_entity.TryGetComponent<Shared._DV.CustomObjectiveSummary.CustomObjectiveSummaryComponent>(mindUid, out var summary))
|
|
ObjectiveSummaryTextEdit.TextRope = new Rope.Leaf(summary.ObjectiveSummary);
|
|
|
|
UpdateWordCount();
|
|
}
|
|
|
|
private void UpdateWordCount()
|
|
{
|
|
var textLength = ObjectiveSummaryTextEdit.TextLength;
|
|
var overMax = textLength > _maxLengthSummaryLength;
|
|
|
|
// Disable the button if it's over the max length.
|
|
SubmitButton.Disabled = overMax;
|
|
CharacterLimitLabel.Text = textLength + "/" + _maxLengthSummaryLength;
|
|
|
|
CharacterLimitLabel.FontColorOverride = overMax ? Color.Red : null;
|
|
PlaceholderText.Visible = textLength == 0;
|
|
}
|
|
}
|