Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions Content.Client/ADT/Telephone/ADTPhoneBui.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using Content.Shared.ADT.Telephone;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;

namespace Content.Client.ADT.Telephone;

/// <summary>
/// Client-side telephone window: phone list, call, answer, hang up and DND.
/// </summary>
public sealed class ADTPhoneBui : BoundUserInterface
{
private ADTPhoneWindow? _window;
private bool _doNotDisturb;

public ADTPhoneBui(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
base.Open();

// Reuse the window if it was somehow opened twice.
if (_window is { Disposed: false, IsOpen: true })
return;

_window = this.CreateWindow<ADTPhoneWindow>();
if (EntMan.TryGetComponent(Owner, out MetaDataComponent? metaData))
_window.Title = metaData.EntityName;

_window.SearchBar.OnTextChanged += OnSearchChanged;
_window.AnswerButton.OnPressed += _ => SendMessage(new ADTPhoneAnswerMsg());
_window.HangUpButton.OnPressed += _ => SendMessage(new ADTPhoneHangUpMsg());
_window.DoNotDisturbButton.OnPressed += _ => SendMessage(new ADTPhoneDoNotDisturbMsg(!_doNotDisturb));

Refresh();
}

protected override void UpdateState(BoundUserInterfaceState state)
{
Refresh();
}

private void OnSearchChanged(LineEdit.LineEditEventArgs args)
{
ApplySearchFilter(args.Text);
}

private void ApplySearchFilter(string text)
{
if (_window == null)
return;

foreach (var child in _window.PhonesList.Children)
{
if (child is Button button)
button.Visible = string.IsNullOrEmpty(text) ||
button.Text?.Contains(text, StringComparison.OrdinalIgnoreCase) == true;
}
}

private void Refresh()
{
if (_window is not { IsOpen: true } || State is not ADTPhoneBuiState state)
return;

_doNotDisturb = state.DoNotDisturb;

_window.PhonesList.DisposeAllChildren();

if (state.Phones.Count == 0)
{
_window.PhonesList.AddChild(new Label
{
Text = Loc.GetString("adt-phone-no-phones"),
HorizontalAlignment = Control.HAlignment.Center,
Margin = new Thickness(0, 8),
});
}

foreach (var phone in state.Phones)
{
var button = new Button
{
Text = phone.Name,
HorizontalExpand = true,
StyleClasses = { "OpenBoth" },
};
var id = phone.Id;
button.OnPressed += _ => SendMessage(new ADTPhoneCallMsg(id));
_window.PhonesList.AddChild(button);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

ApplySearchFilter(_window.SearchBar.Text);

_window.AnswerButton.Visible = state.Ringing;
_window.HangUpButton.Visible = state.Engaged;
_window.DoNotDisturbButton.Text = Loc.GetString(state.DoNotDisturb ? "adt-phone-do-not-disturb-on" : "adt-phone-do-not-disturb-off");
}
}
38 changes: 38 additions & 0 deletions Content.Client/ADT/Telephone/ADTPhoneWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'adt-phone-window-title'}"
SetSize="320 420"
MinSize="280 320">
<BoxContainer Orientation="Vertical" Margin="4">
<LineEdit Name="SearchBar"
Access="Public"
PlaceHolder="{Loc 'adt-phone-search'}"
HorizontalExpand="True"
MinSize="0 32"/>
<ScrollContainer HScrollEnabled="False"
VerticalExpand="True"
MinSize="0 200"
Margin="0 4">
<BoxContainer Name="PhonesList"
Access="Public"
Orientation="Vertical"
HorizontalExpand="True"/>
</ScrollContainer>
<BoxContainer Orientation="Horizontal">
<Button Name="AnswerButton"
Access="Public"
Text="{Loc 'adt-phone-answer'}"
HorizontalExpand="True"
StyleClasses="OpenRight"/>
<Button Name="HangUpButton"
Access="Public"
Text="{Loc 'adt-phone-hang-up'}"
HorizontalExpand="True"
StyleClasses="OpenBoth"/>
</BoxContainer>
<Button Name="DoNotDisturbButton"
Access="Public"
Text="{Loc 'adt-phone-do-not-disturb-off'}"
HorizontalExpand="True"
Margin="0 4 0 0"/>
</BoxContainer>
</DefaultWindow>
15 changes: 15 additions & 0 deletions Content.Client/ADT/Telephone/ADTPhoneWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.ADT.Telephone;

[GenerateTypedNameReferences]
public sealed partial class ADTPhoneWindow : DefaultWindow
{
public ADTPhoneWindow()
{
RobustXamlLoader.Load(this);
}
}
Loading
Loading