Skip to content

Commit

Permalink
More bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chromiumboy committed Oct 13, 2024
1 parent 810d328 commit db346bb
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 73 deletions.
3 changes: 1 addition & 2 deletions Content.Client/Holopad/HolopadBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ protected override void UpdateState(BoundUserInterfaceState state)
base.UpdateState(state);

var castState = (HolopadBoundInterfaceState)state;

EntMan.TryGetComponent<TransformComponent>(Owner, out var xform);

_window?.UpdateState(castState.Holopads, castState.CallerId);
_window?.UpdateState(castState.Holopads);
}

public void SendHolopadStartNewCallMessage(NetEntity receiver)
Expand Down
24 changes: 16 additions & 8 deletions Content.Client/Holopad/HolopadWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -47,6 +49,7 @@ public HolopadWindow()
IoCManager.InjectDependencies(this);

_holopadSystem = _entManager.System<SharedHolopadSystem>();
_telephoneSystem = _entManager.System<SharedTelephoneSystem>();
_accessReaderSystem = _entManager.System<AccessReaderSystem>();
_popupSystem = _entManager.System<PopupSystem>();

Expand Down Expand Up @@ -160,16 +163,16 @@ public void SetState(EntityUid owner, HolopadUiKey uiKey)
}
}

public void UpdateState(Dictionary<NetEntity, string> holopads, string? callerId = null)
public void UpdateState(Dictionary<NetEntity, string> holopads)
{
if (_owner == null || !_entManager.TryGetComponent<TelephoneComponent>(_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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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);
}

Expand Down
8 changes: 8 additions & 0 deletions Content.Client/Telephone/TelephoneSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Content.Shared.Telephone;

namespace Content.Client.Telephone;

public sealed class TelephoneSystem : SharedTelephoneSystem
{

}
46 changes: 18 additions & 28 deletions Content.Server/Holopad/HolopadSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,11 @@ private void OnHolopadStationAiRequest(Entity<HolopadComponent> 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;
}
}

Expand Down Expand Up @@ -415,7 +407,6 @@ public override void Update(float frameTime)
var query = AllEntityQuery<HolopadComponent, TelephoneComponent, TransformComponent>();
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 &&
Expand Down Expand Up @@ -460,13 +451,8 @@ public void UpdateUIState(Entity<HolopadComponent> 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<StationAiCoreComponent>(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<HolopadComponent> entity)
Expand Down Expand Up @@ -554,21 +540,25 @@ private void UnlinkHolopadFromUser(Entity<HolopadComponent> entity, Entity<Holop
}
}

private void ShutDownHolopad(Entity<HolopadComponent> holopad)
private void ShutDownHolopad(Entity<HolopadComponent> 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<StationAiCoreComponent>(holopad, out var stationAiCore))
if (entity.Comp.User != null)
UnlinkHolopadFromUser(entity, entity.Comp.User.Value);

if (TryComp<StationAiCoreComponent>(entity, out var stationAiCore))
{
_stationAiSystem.SwitchRemoteMode((holopad.Owner, stationAiCore), true);
_stationAiSystem.SwitchRemoteMode((entity.Owner, stationAiCore), true);

if (TryComp<TelephoneComponent>(holopad, out var stationAiCoreTelphone))
_telephoneSystem.EndTelephoneCalls((holopad, stationAiCoreTelphone));
if (TryComp<TelephoneComponent>(entity, out var stationAiCoreTelphone))
_telephoneSystem.EndTelephoneCalls((entity, stationAiCoreTelphone));
}

Dirty(entity);
}

private void RequestHolopadUserSpriteUpdate(Entity<HolopadUserComponent> user)
Expand Down Expand Up @@ -678,14 +668,14 @@ private void ExecuteBroadcast(Entity<HolopadComponent> 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);
Expand Down
34 changes: 7 additions & 27 deletions Content.Server/Telephone/TelephoneSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private bool TryCallTelephone(Entity<TelephoneComponent> source, Entity<Telephon
source.Comp.LinkedTelephones.Add(receiver);
source.Comp.Muted = options?.MuteSource == true;

receiver.Comp.LastCaller = user;
receiver.Comp.LastCallerId = GetNameAndJobOfCallingEntity(user); // This will be networked when the state changes
receiver.Comp.LinkedTelephones.Add(source);
receiver.Comp.Muted = options?.MuteReceiver == true;

Expand Down Expand Up @@ -367,38 +367,18 @@ private void SetTelephoneMicrophoneState(Entity<TelephoneComponent> 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<TelephoneComponent> source, Entity<TelephoneComponent> receiver)
Expand Down
6 changes: 2 additions & 4 deletions Content.Shared/Holopad/HolopadComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public sealed partial class HolopadComponent : Component
/// The entity that has locked out the controls of this device
/// </summary>
[ViewVariables, AutoNetworkedField]
public EntityUid ControlLockoutInitiator;
public EntityUid? ControlLockoutOwner = null;

/// <summary>
/// The game tick the control lockout was initiated
Expand Down Expand Up @@ -67,12 +67,10 @@ public sealed partial class HolopadComponent : Component
public sealed class HolopadBoundInterfaceState : BoundUserInterfaceState
{
public readonly Dictionary<NetEntity, string> Holopads;
public readonly string? CallerId;

public HolopadBoundInterfaceState(Dictionary<NetEntity, string> holopads, string? callerId = null)
public HolopadBoundInterfaceState(Dictionary<NetEntity, string> holopads)
{
Holopads = holopads;
CallerId = callerId;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Holopad/SharedHolopadSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public bool IsHolopadControlLocked(Entity<HolopadComponent> 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;
Expand Down
28 changes: 28 additions & 0 deletions Content.Shared/Telephone/SharedTelephoneSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,32 @@ public bool IsTelephoneEngaged(Entity<TelephoneComponent> 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;
}
}
6 changes: 3 additions & 3 deletions Content.Shared/Telephone/TelephoneComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ public sealed partial class TelephoneComponent : Component
public bool Muted = false;

/// <summary>
/// The last person to call this telephone
/// The presumed name and/or job of the last person to call this telephone
/// </summary>
[ViewVariables]
public EntityUid? LastCaller;
[ViewVariables, AutoNetworkedField]
public (string?, string?) LastCallerId;
}

#region: Telephone events
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/holopad/holopad.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit db346bb

Please sign in to comment.