* Remove some BUI boilerplate - The disposals overrides got removed due to the helper method handling it. - Replace window creation with CreateWindow helper. - Fixed some stinky code which would cause exceptions. * More * moar * weh * done * More BUIs * More updates * weh * moar * look who it is * weh * merge * weh * fixes
78 lines
2.5 KiB
C#
78 lines
2.5 KiB
C#
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
|
|
{
|
|
private string? _defaultLabel;
|
|
private bool _defaultEnabled;
|
|
private Color _defaultColor;
|
|
|
|
public event Action<string?, bool, Color>? OnApplyButtonPressed;
|
|
|
|
public NavMapBeaconWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
|
VisibleButton.OnPressed += args => UpdateVisibleButton(args.Button.Pressed);
|
|
LabelLineEdit.OnTextChanged += OnTextChanged;
|
|
ColorSelector.OnColorChanged += _ => TryEnableApplyButton();
|
|
|
|
TryEnableApplyButton();
|
|
ApplyButton.OnPressed += OnApplyPressed;
|
|
}
|
|
|
|
public void SetEntity(EntityUid uid, NavMapBeaconComponent navMap)
|
|
{
|
|
_defaultLabel = navMap.Text;
|
|
_defaultEnabled = navMap.Enabled;
|
|
_defaultColor = navMap.Color;
|
|
|
|
UpdateVisibleButton(navMap.Enabled);
|
|
LabelLineEdit.Text = navMap.Text ?? string.Empty;
|
|
ColorSelector.Color = navMap.Color;
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|