diff --git a/Content.Client/Holopad/HolopadBoundUserInterface.cs b/Content.Client/Holopad/HolopadBoundUserInterface.cs index f80a6f3dbb2d06..fab39e10deaa6c 100644 --- a/Content.Client/Holopad/HolopadBoundUserInterface.cs +++ b/Content.Client/Holopad/HolopadBoundUserInterface.cs @@ -58,10 +58,9 @@ protected override void UpdateState(BoundUserInterfaceState state) base.UpdateState(state); var castState = (HolopadBoundInterfaceState)state; - EntMan.TryGetComponent(Owner, out var xform); - _window?.UpdateState(castState.Holopads, castState.CallerId); + _window?.UpdateState(castState.Holopads); } public void SendHolopadStartNewCallMessage(NetEntity receiver) diff --git a/Content.Client/Holopad/HolopadWindow.xaml.cs b/Content.Client/Holopad/HolopadWindow.xaml.cs index 4947898c7ba1a2..7db8a79203fa27 100644 --- a/Content.Client/Holopad/HolopadWindow.xaml.cs +++ b/Content.Client/Holopad/HolopadWindow.xaml.cs @@ -22,12 +22,14 @@ public sealed partial class HolopadWindow : FancyWindow [Dependency] private readonly IGameTiming _timing = default!; private readonly SharedHolopadSystem _holopadSystem = default!; + private readonly SharedTelephoneSystem _telephoneSystem = default!; private readonly AccessReaderSystem _accessReaderSystem = default!; private readonly PopupSystem _popupSystem = default!; private EntityUid? _owner = null; private HolopadUiKey _currentUiKey; private TelephoneState _currentState; + private TelephoneState _previousState; private TimeSpan _buttonUnlockTime; private float _updateTimer = 0.25f; @@ -47,6 +49,7 @@ public HolopadWindow() IoCManager.InjectDependencies(this); _holopadSystem = _entManager.System(); + _telephoneSystem = _entManager.System(); _accessReaderSystem = _entManager.System(); _popupSystem = _entManager.System(); @@ -160,16 +163,16 @@ public void SetState(EntityUid owner, HolopadUiKey uiKey) } } - public void UpdateState(Dictionary holopads, string? callerId = null) + public void UpdateState(Dictionary holopads) { if (_owner == null || !_entManager.TryGetComponent(_owner.Value, out var telephone)) return; - // Caller ID - CallerIdText.SetMessage(FormattedMessage.FromMarkupOrThrow(callerId ?? Loc.GetString("chat-telephone-unknown-caller"))); - CallerIdText.Visible = (callerId != null); + // Caller ID text + var callerId = _telephoneSystem.GetFormattedCallerIdForEntity(telephone.LastCallerId.Item1, telephone.LastCallerId.Item2, Color.White, "Default", 11); - LockOutIdText.SetMessage(FormattedMessage.FromMarkupOrThrow(callerId ?? Loc.GetString("chat-telephone-unknown-caller"))); + CallerIdText.SetMessage(FormattedMessage.FromMarkupOrThrow(callerId)); + LockOutIdText.SetMessage(FormattedMessage.FromMarkupOrThrow(callerId)); // Sort holopads alphabetically var holopadArray = holopads.ToArray(); @@ -219,9 +222,10 @@ private void UpdateAppearance() ControlsLockOutContainer.Visible = _holopadSystem.IsHolopadControlLocked((_owner.Value, holopad), localPlayer); ControlsContainer.Visible = !ControlsLockOutContainer.Visible; - // Temporarily disable the interface buttons when the call state changes to prevent any misclicks + // Temporarily disable the interface buttons when the call state changes to prevent any misclicks if (_currentState != telephone.CurrentState) { + _previousState = _currentState; _currentState = telephone.CurrentState; _buttonUnlockTime = _timing.CurTime + _buttonUnlockDelay; } @@ -267,7 +271,11 @@ private void UpdateAppearance() CallStatusText.Text = Loc.GetString("holopad-window-call-in-progress"); break; case TelephoneState.EndingCall: - CallStatusText.Text = Loc.GetString("holopad-window-call-ending"); break; + if (_previousState == TelephoneState.Calling || _previousState == TelephoneState.Idle) + CallStatusText.Text = Loc.GetString("holopad-window-call-rejected"); + else + CallStatusText.Text = Loc.GetString("holopad-window-call-ending"); + break; } // Update control disability @@ -281,7 +289,7 @@ private void UpdateAppearance() FetchingAvailableHolopadsContainer.Visible = (ContactsList.ChildCount == 0); ActiveCallControlsContainer.Visible = (_currentState != TelephoneState.Idle || _currentUiKey == HolopadUiKey.AiRequestWindow); CallPlacementControlsContainer.Visible = !ActiveCallControlsContainer.Visible; - + CallerIdText.Visible = (_currentState == TelephoneState.Ringing); AnswerCallButton.Visible = (_currentState == TelephoneState.Ringing); } diff --git a/Content.Client/Telephone/TelephoneSystem.cs b/Content.Client/Telephone/TelephoneSystem.cs new file mode 100644 index 00000000000000..8fad9f7b85bd27 --- /dev/null +++ b/Content.Client/Telephone/TelephoneSystem.cs @@ -0,0 +1,8 @@ +using Content.Shared.Telephone; + +namespace Content.Client.Telephone; + +public sealed class TelephoneSystem : SharedTelephoneSystem +{ + +} diff --git a/Content.Server/Holopad/HolopadSystem.cs b/Content.Server/Holopad/HolopadSystem.cs index 5087f14eea1e49..daee7025800fcf 100644 --- a/Content.Server/Holopad/HolopadSystem.cs +++ b/Content.Server/Holopad/HolopadSystem.cs @@ -211,19 +211,11 @@ private void OnHolopadStationAiRequest(Entity entity, ref Holo if (!_stationAiSystem.TryGetInsertedAI((receiver, receiverStationAiCore), out var insertedAi)) continue; - LinkHolopadToUser(entity, args.Actor); - if (_userInterfaceSystem.TryOpenUi(receiverUid, HolopadUiKey.AiRequestWindow, insertedAi.Value.Owner)) { - string? callerId = null; - - if (receiverTelephone.CurrentState == TelephoneState.Ringing && receiverTelephone.LastCaller != null) - callerId = _telephoneSystem.GetFormattedCallerIdForEntity(receiverTelephone.LastCaller.Value, Color.White, "Default", 11); - - _userInterfaceSystem.SetUiState(receiverUid, HolopadUiKey.AiRequestWindow, new HolopadBoundInterfaceState(new(), callerId)); + LinkHolopadToUser(entity, args.Actor); + break; } - - break; } } @@ -415,7 +407,6 @@ public override void Update(float frameTime) var query = AllEntityQuery(); while (query.MoveNext(out var uid, out var holopad, out var telephone, out var xform)) { - //if (_userInterfaceSystem.IsUiOpen(ent, HolopadUiKey.Key)) UpdateUIState((uid, holopad), telephone); if (holopad.User != null && @@ -460,13 +451,8 @@ public void UpdateUIState(Entity entity, TelephoneComponent? t holopads.Add(GetNetEntity(receiverUid), name); } - string? callerId = null; - - if (telephone.CurrentState == TelephoneState.Ringing && telephone.LastCaller != null) - callerId = _telephoneSystem.GetFormattedCallerIdForEntity(telephone.LastCaller.Value, Color.White, "Default", 11); - var uiKey = HasComp(entity) ? HolopadUiKey.AiActionWindow : HolopadUiKey.InteractionWindow; - _userInterfaceSystem.SetUiState(entity.Owner, uiKey, new HolopadBoundInterfaceState(holopads, callerId)); + _userInterfaceSystem.SetUiState(entity.Owner, uiKey, new HolopadBoundInterfaceState(holopads)); } private void GenerateHologram(Entity entity) @@ -554,21 +540,25 @@ private void UnlinkHolopadFromUser(Entity entity, Entity holopad) + private void ShutDownHolopad(Entity entity) { - if (holopad.Comp.Hologram != null) - DeleteHologram(holopad.Comp.Hologram.Value, holopad); + entity.Comp.ControlLockoutOwner = null; - if (holopad.Comp.User != null) - UnlinkHolopadFromUser(holopad, holopad.Comp.User.Value); + if (entity.Comp.Hologram != null) + DeleteHologram(entity.Comp.Hologram.Value, entity); - if (TryComp(holopad, out var stationAiCore)) + if (entity.Comp.User != null) + UnlinkHolopadFromUser(entity, entity.Comp.User.Value); + + if (TryComp(entity, out var stationAiCore)) { - _stationAiSystem.SwitchRemoteMode((holopad.Owner, stationAiCore), true); + _stationAiSystem.SwitchRemoteMode((entity.Owner, stationAiCore), true); - if (TryComp(holopad, out var stationAiCoreTelphone)) - _telephoneSystem.EndTelephoneCalls((holopad, stationAiCoreTelphone)); + if (TryComp(entity, out var stationAiCoreTelphone)) + _telephoneSystem.EndTelephoneCalls((entity, stationAiCoreTelphone)); } + + Dirty(entity); } private void RequestHolopadUserSpriteUpdate(Entity user) @@ -678,14 +668,14 @@ private void ExecuteBroadcast(Entity source, EntityUid user) LinkHolopadToUser(source, user); // Lock out the controls of all involved holopads for a set duration - source.Comp.ControlLockoutInitiator = user; + source.Comp.ControlLockoutOwner = user; source.Comp.ControlLockoutStartTime = _timing.CurTime; Dirty(source); foreach (var receiver in GetLinkedHolopads(source)) { - receiver.Comp.ControlLockoutInitiator = user; + receiver.Comp.ControlLockoutOwner = user; receiver.Comp.ControlLockoutStartTime = _timing.CurTime; Dirty(receiver); diff --git a/Content.Server/Telephone/TelephoneSystem.cs b/Content.Server/Telephone/TelephoneSystem.cs index edfce1a33e0d94..b24b77fc17e782 100644 --- a/Content.Server/Telephone/TelephoneSystem.cs +++ b/Content.Server/Telephone/TelephoneSystem.cs @@ -195,7 +195,7 @@ private bool TryCallTelephone(Entity source, Entity entity, bool } } - public string? GetFormattedCallerIdForEntity(EntityUid uid, Color fontColor, string fontType = "Default", int fontSize = 12) + private (string?, string?) GetNameAndJobOfCallingEntity(EntityUid uid) { - var callerId = Loc.GetString("chat-telephone-unknown-caller", - ("color", fontColor), - ("fontType", fontType), - ("fontSize", fontSize)); + string? presumedName = null; + string? presumedJob = null; if (_idCardSystem.TryFindIdCard(uid, out var idCard)) { - var presumedName = string.IsNullOrWhiteSpace(idCard.Comp.FullName) ? null : idCard.Comp.FullName; - var presumedJob = idCard.Comp.JobTitle; - - if (presumedName != null) - { - if (presumedJob != null) - callerId = Loc.GetString("chat-telephone-caller-id-with-job", - ("callerName", presumedName), - ("callerJob", presumedJob), - ("color", fontColor), - ("fontType", fontType), - ("fontSize", fontSize)); - - else - callerId = Loc.GetString("chat-telephone-caller-id-without-job", - ("callerName", presumedName), - ("color", fontColor), - ("fontType", fontType), - ("fontSize", fontSize)); - } + presumedName = string.IsNullOrWhiteSpace(idCard.Comp.FullName) ? null : idCard.Comp.FullName; + presumedJob = idCard.Comp.LocalizedJobTitle; } - return callerId; + return (presumedName, presumedJob); } public bool IsSourceAbleToReachReceiver(Entity source, Entity receiver) diff --git a/Content.Shared/Holopad/HolopadComponent.cs b/Content.Shared/Holopad/HolopadComponent.cs index f0c8a25310d803..98f05b03f93025 100644 --- a/Content.Shared/Holopad/HolopadComponent.cs +++ b/Content.Shared/Holopad/HolopadComponent.cs @@ -37,7 +37,7 @@ public sealed partial class HolopadComponent : Component /// The entity that has locked out the controls of this device /// [ViewVariables, AutoNetworkedField] - public EntityUid ControlLockoutInitiator; + public EntityUid? ControlLockoutOwner = null; /// /// The game tick the control lockout was initiated @@ -67,12 +67,10 @@ public sealed partial class HolopadComponent : Component public sealed class HolopadBoundInterfaceState : BoundUserInterfaceState { public readonly Dictionary Holopads; - public readonly string? CallerId; - public HolopadBoundInterfaceState(Dictionary holopads, string? callerId = null) + public HolopadBoundInterfaceState(Dictionary holopads) { Holopads = holopads; - CallerId = callerId; } } diff --git a/Content.Shared/Holopad/SharedHolopadSystem.cs b/Content.Shared/Holopad/SharedHolopadSystem.cs index b240cea79c2046..ea122828bf120d 100644 --- a/Content.Shared/Holopad/SharedHolopadSystem.cs +++ b/Content.Shared/Holopad/SharedHolopadSystem.cs @@ -14,7 +14,7 @@ public bool IsHolopadControlLocked(Entity entity, EntityUid? u if (entity.Comp.ControlLockoutStartTime + TimeSpan.FromSeconds(entity.Comp.ControlLockoutDuration) < _timing.CurTime) return false; - if (user != null && entity.Comp.ControlLockoutInitiator == user) + if (entity.Comp.ControlLockoutOwner == null || entity.Comp.ControlLockoutOwner == user) return false; return true; diff --git a/Content.Shared/Telephone/SharedTelephoneSystem.cs b/Content.Shared/Telephone/SharedTelephoneSystem.cs index c17cffeccd5a3f..ab423623cb5eaa 100644 --- a/Content.Shared/Telephone/SharedTelephoneSystem.cs +++ b/Content.Shared/Telephone/SharedTelephoneSystem.cs @@ -8,4 +8,32 @@ public bool IsTelephoneEngaged(Entity entity) { return entity.Comp.LinkedTelephones.Any(); } + + public string GetFormattedCallerIdForEntity(string? presumedName, string? presumedJob, Color fontColor, string fontType = "Default", int fontSize = 12) + { + var callerId = Loc.GetString("chat-telephone-unknown-caller", + ("color", fontColor), + ("fontType", fontType), + ("fontSize", fontSize)); + + if (presumedName == null) + return callerId; + + if (presumedJob != null) + callerId = Loc.GetString("chat-telephone-caller-id-with-job", + ("callerName", presumedName), + ("callerJob", presumedJob), + ("color", fontColor), + ("fontType", fontType), + ("fontSize", fontSize)); + + else + callerId = Loc.GetString("chat-telephone-caller-id-without-job", + ("callerName", presumedName), + ("color", fontColor), + ("fontType", fontType), + ("fontSize", fontSize)); + + return callerId; + } } diff --git a/Content.Shared/Telephone/TelephoneComponent.cs b/Content.Shared/Telephone/TelephoneComponent.cs index 30578a7fe3ff17..8577eb8985fe9d 100644 --- a/Content.Shared/Telephone/TelephoneComponent.cs +++ b/Content.Shared/Telephone/TelephoneComponent.cs @@ -103,10 +103,10 @@ public sealed partial class TelephoneComponent : Component public bool Muted = false; /// - /// The last person to call this telephone + /// The presumed name and/or job of the last person to call this telephone /// - [ViewVariables] - public EntityUid? LastCaller; + [ViewVariables, AutoNetworkedField] + public (string?, string?) LastCallerId; } #region: Telephone events diff --git a/Resources/Locale/en-US/holopad/holopad.ftl b/Resources/Locale/en-US/holopad/holopad.ftl index b1eb9eaad922c5..77181c5ee3e729 100644 --- a/Resources/Locale/en-US/holopad/holopad.ftl +++ b/Resources/Locale/en-US/holopad/holopad.ftl @@ -9,6 +9,7 @@ holopad-window-incoming-call = Incoming holo-call from: holopad-window-outgoing-call = Attempting to establish a connection... holopad-window-call-in-progress = Holo-call in progress holopad-window-call-ending = Disconnecting... +holopad-window-call-rejected = Unable to establish a connection holopad-window-ai-request = Your presence is requested by: holopad-window-emergency-broadcast-in-progress = Emergency broadcast in progress holopad-window-controls-locked-out = Control of this device has been locked to: