Station beacons (#23136)
* Station beacons * crate * remove navmap from warp points * ack * oh damn * okay emisser
This commit is contained in:
78
Content.Client/Pinpointer/UI/NavMapBeaconWindow.xaml.cs
Normal file
78
Content.Client/Pinpointer/UI/NavMapBeaconWindow.xaml.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Shared.Pinpointer;
|
||||
using Content.Shared.Preferences;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Pinpointer.UI;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class NavMapBeaconWindow : FancyWindow
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
private string? _defaultLabel;
|
||||
private bool _defaultEnabled;
|
||||
private Color _defaultColor;
|
||||
|
||||
public event Action<string?, bool, Color>? OnApplyButtonPressed;
|
||||
|
||||
public NavMapBeaconWindow(EntityUid beaconEntity)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
if (!_entityManager.TryGetComponent<NavMapBeaconComponent>(beaconEntity, out var navMap))
|
||||
return;
|
||||
_defaultLabel = navMap.Text;
|
||||
_defaultEnabled = navMap.Enabled;
|
||||
_defaultColor = navMap.Color;
|
||||
|
||||
UpdateVisibleButton(navMap.Enabled);
|
||||
VisibleButton.OnPressed += args => UpdateVisibleButton(args.Button.Pressed);
|
||||
|
||||
LabelLineEdit.Text = navMap.Text ?? string.Empty;
|
||||
LabelLineEdit.OnTextChanged += OnTextChanged;
|
||||
|
||||
ColorSelector.Color = navMap.Color;
|
||||
ColorSelector.OnColorChanged += _ => TryEnableApplyButton();
|
||||
|
||||
TryEnableApplyButton();
|
||||
ApplyButton.OnPressed += OnApplyPressed;
|
||||
}
|
||||
|
||||
private void UpdateVisibleButton(bool value)
|
||||
{
|
||||
VisibleButton.Pressed = value;
|
||||
VisibleButton.Text = Loc.GetString(value
|
||||
? "nav-beacon-toggle-visible"
|
||||
: "nav-beacon-toggle-invisible");
|
||||
|
||||
TryEnableApplyButton();
|
||||
}
|
||||
|
||||
private void OnTextChanged(LineEdit.LineEditEventArgs obj)
|
||||
{
|
||||
if (obj.Text.Length > HumanoidCharacterProfile.MaxNameLength)
|
||||
obj.Control.Text = obj.Text.Substring(0, HumanoidCharacterProfile.MaxNameLength);
|
||||
|
||||
TryEnableApplyButton();
|
||||
}
|
||||
|
||||
private void TryEnableApplyButton()
|
||||
{
|
||||
ApplyButton.Disabled = LabelLineEdit.Text == (_defaultLabel ?? string.Empty) &&
|
||||
VisibleButton.Pressed == _defaultEnabled &&
|
||||
ColorSelector.Color == _defaultColor;
|
||||
}
|
||||
|
||||
private void OnApplyPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
_defaultLabel = LabelLineEdit.Text == string.Empty ? null : LabelLineEdit.Text;
|
||||
_defaultEnabled = VisibleButton.Pressed;
|
||||
_defaultColor = ColorSelector.Color;
|
||||
OnApplyButtonPressed?.Invoke(_defaultLabel, _defaultEnabled, _defaultColor);
|
||||
TryEnableApplyButton();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user