75 lines
2.2 KiB
C#
75 lines
2.2 KiB
C#
using System.Numerics;
|
|
using Content.Shared.Teleportation.Components;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
namespace Content.Client.Teleportation.Ui;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class TeleportMenu : DefaultWindow
|
|
{
|
|
public string SearchText = "";
|
|
|
|
public HashSet<TeleportPoint> Warps = new();
|
|
|
|
public event Action<NetEntity, string>? TeleportClicked;
|
|
|
|
public TeleportMenu()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
SearchBar.OnTextChanged += OnSearchTextChanged;
|
|
}
|
|
|
|
public void AddTeleportButtons()
|
|
{
|
|
foreach (var points in Warps)
|
|
{
|
|
var name = points.Location;
|
|
var teleportPoint = points.TelePoint;
|
|
|
|
var currentButtonRef = new Button
|
|
{
|
|
Text = name,
|
|
TextAlign = Label.AlignMode.Right,
|
|
HorizontalAlignment = HAlignment.Center,
|
|
VerticalAlignment = VAlignment.Center,
|
|
SizeFlagsStretchRatio = 1,
|
|
MinSize = new Vector2(340, 20),
|
|
ClipText = true,
|
|
};
|
|
|
|
currentButtonRef.OnPressed += _ => TeleportClicked?.Invoke(teleportPoint, name);
|
|
currentButtonRef.Visible = ButtonIsVisible(currentButtonRef);
|
|
|
|
TeleportButtonContainer.AddChild(currentButtonRef);
|
|
}
|
|
}
|
|
|
|
private bool ButtonIsVisible(Button button)
|
|
{
|
|
return string.IsNullOrEmpty(SearchText) || button.Text == null ||
|
|
button.Text.Contains(SearchText, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
private void UpdateVisibleButtons()
|
|
{
|
|
foreach (var child in TeleportButtonContainer.Children)
|
|
{
|
|
if (child is Button button)
|
|
button.Visible = ButtonIsVisible(button);
|
|
}
|
|
}
|
|
|
|
public void OnSearchTextChanged(LineEdit.LineEditEventArgs args)
|
|
{
|
|
SearchText = args.Text;
|
|
UpdateVisibleButtons();
|
|
// Very funny it's called TeleportScroll
|
|
TeleportScroll.SetScrollValue(Vector2.Zero);
|
|
}
|
|
}
|