PDA uplink visibility fix (#7332)
This commit is contained in:
@@ -7,7 +7,6 @@ using Content.Server.Traitor.Uplink.Account;
|
|||||||
using Content.Server.Traitor.Uplink.Components;
|
using Content.Server.Traitor.Uplink.Components;
|
||||||
using Content.Server.PDA.Ringer;
|
using Content.Server.PDA.Ringer;
|
||||||
using Content.Server.UserInterface;
|
using Content.Server.UserInterface;
|
||||||
using Content.Shared.Containers.ItemSlots;
|
|
||||||
using Content.Shared.PDA;
|
using Content.Shared.PDA;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
@@ -21,20 +20,26 @@ namespace Content.Server.PDA
|
|||||||
[Dependency] private readonly UnpoweredFlashlightSystem _unpoweredFlashlight = default!;
|
[Dependency] private readonly UnpoweredFlashlightSystem _unpoweredFlashlight = default!;
|
||||||
[Dependency] private readonly RingerSystem _ringerSystem = default!;
|
[Dependency] private readonly RingerSystem _ringerSystem = default!;
|
||||||
[Dependency] private readonly InstrumentSystem _instrumentSystem = default!;
|
[Dependency] private readonly InstrumentSystem _instrumentSystem = default!;
|
||||||
|
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<PDAComponent, LightToggleEvent>(OnLightToggle);
|
SubscribeLocalEvent<PDAComponent, LightToggleEvent>(OnLightToggle);
|
||||||
|
SubscribeLocalEvent<PDAComponent, AfterActivatableUIOpenEvent>(AfterUIOpen);
|
||||||
|
SubscribeLocalEvent<PDAComponent, UplinkInitEvent>(OnUplinkInit);
|
||||||
|
SubscribeLocalEvent<PDAComponent, UplinkRemovedEvent>(OnUplinkRemoved);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnComponentInit(EntityUid uid, PDAComponent pda, ComponentInit args)
|
protected override void OnComponentInit(EntityUid uid, PDAComponent pda, ComponentInit args)
|
||||||
{
|
{
|
||||||
base.OnComponentInit(uid, pda, args);
|
base.OnComponentInit(uid, pda, args);
|
||||||
|
|
||||||
var ui = pda.Owner.GetUIOrNull(PDAUiKey.Key);
|
if (!TryComp(uid, out ServerUserInterfaceComponent? uiComponent))
|
||||||
if (ui != null)
|
return;
|
||||||
|
|
||||||
|
if (_uiSystem.TryGetUi(uid, PDAUiKey.Key, out var ui, uiComponent))
|
||||||
ui.OnReceiveMessage += (msg) => OnUIMessage(pda, msg);
|
ui.OnReceiveMessage += (msg) => OnUIMessage(pda, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,25 +77,7 @@ namespace Content.Server.PDA
|
|||||||
UpdatePDAUserInterface(pda);
|
UpdatePDAUserInterface(pda);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool OpenUI(PDAComponent pda, EntityUid user)
|
private void UpdatePDAUserInterface(PDAComponent pda)
|
||||||
{
|
|
||||||
if (!EntityManager.TryGetComponent(user, out ActorComponent? actor))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
UpdatePDAUserInterface(pda, user);
|
|
||||||
var ui = pda.Owner.GetUIOrNull(PDAUiKey.Key);
|
|
||||||
ui?.Toggle(actor.PlayerSession);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdatePDAAppearance(PDAComponent pda)
|
|
||||||
{
|
|
||||||
if (EntityManager.TryGetComponent(pda.Owner, out AppearanceComponent? appearance))
|
|
||||||
appearance.SetData(PDAVisuals.IDCardInserted, pda.ContainedID != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdatePDAUserInterface(PDAComponent pda, EntityUid? user = null)
|
|
||||||
{
|
{
|
||||||
var ownerInfo = new PDAIdInfoText
|
var ownerInfo = new PDAIdInfoText
|
||||||
{
|
{
|
||||||
@@ -99,54 +86,40 @@ namespace Content.Server.PDA
|
|||||||
JobTitle = pda.ContainedID?.JobTitle
|
JobTitle = pda.ContainedID?.JobTitle
|
||||||
};
|
};
|
||||||
|
|
||||||
var ui = pda.Owner.GetUIOrNull(PDAUiKey.Key);
|
if (!_uiSystem.TryGetUi(pda.Owner, PDAUiKey.Key, out var ui))
|
||||||
if (ui == null)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ui.SetState(new PDAUpdateState(pda.FlashlightOn, pda.PenSlot.HasItem, ownerInfo,
|
var hasInstrument = HasComp<InstrumentComponent>(pda.Owner);
|
||||||
ShouldShowUplink(pda.Owner, ui, user),
|
var state = new PDAUpdateState(pda.FlashlightOn, pda.PenSlot.HasItem, ownerInfo, false, hasInstrument);
|
||||||
HasComp<InstrumentComponent>(pda.Owner)));
|
|
||||||
}
|
ui.SetState(state);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Check whether the PDA has an uplink, and ensure that the only person that can see the PDA UI has an
|
|
||||||
/// uplink account.
|
|
||||||
/// </summary>
|
|
||||||
public bool ShouldShowUplink(EntityUid uid, BoundUserInterface ui, EntityUid? user = null)
|
|
||||||
{
|
|
||||||
// TODO UPLINK RINGTONES/SECRETS This is just a janky placeholder way of hiding uplinks from non syndicate
|
// TODO UPLINK RINGTONES/SECRETS This is just a janky placeholder way of hiding uplinks from non syndicate
|
||||||
// players. This should really use a sort of key-code entry system that selects an account which is not directly tied to
|
// players. This should really use a sort of key-code entry system that selects an account which is not directly tied to
|
||||||
// a player entity.
|
// a player entity.
|
||||||
|
|
||||||
if (!HasComp<UplinkComponent>(uid))
|
if (!HasComp<UplinkComponent>(pda.Owner))
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
// If a user is trying to open the UI, make sure that they have an uplink account before showing the UI.
|
var uplinkState = new PDAUpdateState(pda.FlashlightOn, pda.PenSlot.HasItem, ownerInfo, true, hasInstrument);
|
||||||
if (user != null && !_uplinkAccounts.HasAccount(user.Value))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// If other users currently have the UI open, check that they too should be allowed to see the button..
|
|
||||||
foreach (var session in ui.SubscribedSessions)
|
foreach (var session in ui.SubscribedSessions)
|
||||||
{
|
{
|
||||||
if (session.AttachedEntity != null && !_uplinkAccounts.HasAccount(session.AttachedEntity.Value))
|
if (session.AttachedEntity is not EntityUid { Valid: true } user)
|
||||||
return false;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
// everyone has an uplink account, show the button.
|
if (_uplinkAccounts.HasAccount(user))
|
||||||
return true;
|
ui.SetState(uplinkState, session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUIMessage(PDAComponent pda, ServerBoundUserInterfaceMessage msg)
|
private void OnUIMessage(PDAComponent pda, ServerBoundUserInterfaceMessage msg)
|
||||||
{
|
{
|
||||||
// cast EntityUid? to EntityUid
|
|
||||||
if (msg.Session.AttachedEntity is not {Valid: true} playerUid)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// todo: move this to entity events
|
// todo: move this to entity events
|
||||||
switch (msg.Message)
|
switch (msg.Message)
|
||||||
{
|
{
|
||||||
case PDARequestUpdateInterfaceMessage _:
|
case PDARequestUpdateInterfaceMessage _:
|
||||||
UpdatePDAUserInterface(pda, playerUid);
|
UpdatePDAUserInterface(pda);
|
||||||
break;
|
break;
|
||||||
case PDAToggleFlashlightMessage _:
|
case PDAToggleFlashlightMessage _:
|
||||||
{
|
{
|
||||||
@@ -175,5 +148,26 @@ namespace Content.Server.PDA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AfterUIOpen(EntityUid uid, PDAComponent pda, AfterActivatableUIOpenEvent args)
|
||||||
|
{
|
||||||
|
// A new user opened the UI --> Check if they are a traitor and should get a user specific UI state override.
|
||||||
|
if (!HasComp<UplinkComponent>(pda.Owner) || !_uplinkAccounts.HasAccount(args.User))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!_uiSystem.TryGetUi(pda.Owner, PDAUiKey.Key, out var ui))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var ownerInfo = new PDAIdInfoText
|
||||||
|
{
|
||||||
|
ActualOwnerName = pda.OwnerName,
|
||||||
|
IdOwner = pda.ContainedID?.FullName,
|
||||||
|
JobTitle = pda.ContainedID?.JobTitle
|
||||||
|
};
|
||||||
|
|
||||||
|
var state = new PDAUpdateState(pda.FlashlightOn, pda.PenSlot.HasItem, ownerInfo, true, HasComp<InstrumentComponent>(pda.Owner));
|
||||||
|
|
||||||
|
ui.SetState(state, args.Session);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ namespace Content.Server.UserInterface
|
|||||||
ui.Toggle(actor.PlayerSession);
|
ui.Toggle(actor.PlayerSession);
|
||||||
|
|
||||||
//Let the component know a user opened it so it can do whatever it needs to do
|
//Let the component know a user opened it so it can do whatever it needs to do
|
||||||
var aae = new AfterActivatableUIOpenEvent(user);
|
var aae = new AfterActivatableUIOpenEvent(user, actor.PlayerSession);
|
||||||
RaiseLocalEvent((aui).Owner, aae, false);
|
RaiseLocalEvent((aui).Owner, aae, false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -186,9 +186,12 @@ namespace Content.Server.UserInterface
|
|||||||
public sealed class AfterActivatableUIOpenEvent : EntityEventArgs
|
public sealed class AfterActivatableUIOpenEvent : EntityEventArgs
|
||||||
{
|
{
|
||||||
public EntityUid User { get; }
|
public EntityUid User { get; }
|
||||||
public AfterActivatableUIOpenEvent(EntityUid who)
|
public readonly IPlayerSession Session;
|
||||||
|
|
||||||
|
public AfterActivatableUIOpenEvent(EntityUid who, IPlayerSession session)
|
||||||
{
|
{
|
||||||
User = who;
|
User = who;
|
||||||
|
Session = session;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user