Station beacons (#23136)

* Station beacons

* crate

* remove navmap from warp points

* ack

* oh damn

* okay emisser
This commit is contained in:
Nemanja
2023-12-28 19:02:21 -05:00
committed by GitHub
parent aa8861ab00
commit 99d78c4b97
18 changed files with 899 additions and 103 deletions

View File

@@ -0,0 +1,35 @@
using Content.Shared.Pinpointer;
using JetBrains.Annotations;
namespace Content.Client.Pinpointer.UI;
[UsedImplicitly]
public sealed class NavMapBeaconBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private NavMapBeaconWindow? _window;
public NavMapBeaconBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_window = new NavMapBeaconWindow(Owner);
_window.OpenCentered();
_window.OnClose += Close;
_window.OnApplyButtonPressed += (label, enabled, color) =>
{
SendMessage(new NavMapBeaconConfigureBuiMessage(label, enabled, color));
};
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_window?.Dispose();
}
}

View File

@@ -0,0 +1,17 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'nav-beacon-window-title'}"
MinSize="250 230"
SetSize="320 230">
<BoxContainer Orientation="Vertical" Margin="5">
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'nav-beacon-text-label'}" Margin="0 0 5 0"/>
<LineEdit Name="LabelLineEdit" HorizontalExpand="True"/>
<Button Name="VisibleButton" ToggleMode="True" Text="{Loc 'nav-beacon-toggle-visible'}" Margin="10 0 0 0" MinWidth="100"/>
</BoxContainer>
<ColorSelectorSliders Name="ColorSelector" Margin="0 5 0 10"/>
<BoxContainer HorizontalAlignment="Right" VerticalAlignment="Bottom" VerticalExpand="True">
<Button Name="ApplyButton" Text="{Loc 'nav-beacon-button-apply'}" HorizontalAlignment="Right"/>
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>

View 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();
}
}