uplink locking/unlocking, minor pda refactor (#15842)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
@@ -3,6 +3,8 @@ using Content.Server.Store.Systems;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.PDA;
|
||||
using Content.Shared.PDA.Ringer;
|
||||
using Content.Shared.Store;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Player;
|
||||
@@ -14,8 +16,10 @@ namespace Content.Server.PDA.Ringer
|
||||
{
|
||||
public sealed class RingerSystem : SharedRingerSystem
|
||||
{
|
||||
[Dependency] private readonly PDASystem _pda = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly StoreSystem _store = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -26,7 +30,7 @@ namespace Content.Server.PDA.Ringer
|
||||
SubscribeLocalEvent<RingerUplinkComponent, ComponentInit>(RandomizeUplinkCode);
|
||||
// RingerBoundUserInterface Subscriptions
|
||||
SubscribeLocalEvent<RingerComponent, RingerSetRingtoneMessage>(OnSetRingtone);
|
||||
SubscribeLocalEvent<RingerUplinkComponent, RingerSetRingtoneMessage>(OnSetUplinkRingtone);
|
||||
SubscribeLocalEvent<RingerUplinkComponent, BeforeRingtoneSetEvent>(OnSetUplinkRingtone);
|
||||
SubscribeLocalEvent<RingerComponent, RingerPlayRingtoneMessage>(RingerPlayRingtone);
|
||||
SubscribeLocalEvent<RingerComponent, RingerRequestUpdateInterfaceMessage>(UpdateRingerUserInterfaceDriver);
|
||||
|
||||
@@ -50,17 +54,28 @@ namespace Content.Server.PDA.Ringer
|
||||
// Client sent us an updated ringtone so set it to that.
|
||||
if (args.Ringtone.Length != RingtoneLength) return;
|
||||
|
||||
var ev = new BeforeRingtoneSetEvent(args.Ringtone);
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
if (ev.Handled)
|
||||
return;
|
||||
|
||||
UpdateRingerRingtone(ringer, args.Ringtone);
|
||||
}
|
||||
|
||||
private void OnSetUplinkRingtone(EntityUid uid, RingerUplinkComponent uplink, RingerSetRingtoneMessage args)
|
||||
private void OnSetUplinkRingtone(EntityUid uid, RingerUplinkComponent uplink, ref BeforeRingtoneSetEvent args)
|
||||
{
|
||||
if (uplink.Code.SequenceEqual(args.Ringtone) &&
|
||||
args.Session.AttachedEntity != null &&
|
||||
TryComp<StoreComponent>(uid, out var store))
|
||||
if (uplink.Code.SequenceEqual(args.Ringtone) && TryComp<StoreComponent>(uid, out var store))
|
||||
{
|
||||
var user = args.Session.AttachedEntity.Value;
|
||||
_store.ToggleUi(args.Session.AttachedEntity.Value, uid, store);
|
||||
uplink.Unlocked = !uplink.Unlocked;
|
||||
if (TryComp<PDAComponent>(uid, out var pda))
|
||||
_pda.UpdatePdaUi(uid, pda);
|
||||
|
||||
// can't keep store open after locking it
|
||||
if (!uplink.Unlocked)
|
||||
_ui.TryCloseAll(uid, StoreUiKey.Key);
|
||||
|
||||
// no saving the code to prevent meta click set on sus guys pda -> wewlad
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,3 +176,6 @@ namespace Content.Server.PDA.Ringer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public record struct BeforeRingtoneSetEvent(Note[] Ringtone, bool Handled = false);
|
||||
|
||||
Reference in New Issue
Block a user