News UI overhaul and PDA notifications (#19610)

This commit is contained in:
Julian Giebel
2024-02-27 02:38:00 +01:00
committed by GitHub
parent f284b43ff6
commit 0752acdc2c
54 changed files with 1381 additions and 708 deletions

View File

@@ -199,9 +199,13 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem
return false;
var installedProgram = Spawn(prototype, new EntityCoordinates(loaderUid, 0, 0));
if (!TryComp(installedProgram, out CartridgeComponent? cartridge))
return false;
_containerSystem.Insert(installedProgram, container);
UpdateCartridgeInstallationStatus(installedProgram, deinstallable ? InstallationStatus.Installed : InstallationStatus.Readonly);
UpdateCartridgeInstallationStatus(installedProgram, deinstallable ? InstallationStatus.Installed : InstallationStatus.Readonly, cartridge);
cartridge.LoaderUid = loaderUid;
RaiseLocalEvent(installedProgram, new CartridgeAddedEvent(loaderUid));
UpdateUserInterfaceState(loaderUid, loader);
@@ -223,11 +227,14 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem
if (!GetInstalled(loaderUid).Contains(programUid))
return false;
if (TryComp(programUid, out CartridgeComponent? cartridge))
cartridge.LoaderUid = null;
if (loader.ActiveProgram == programUid)
loader.ActiveProgram = null;
loader.BackgroundPrograms.Remove(programUid);
EntityManager.QueueDeleteEntity(programUid);
QueueDel(programUid);
UpdateUserInterfaceState(loaderUid, loader);
return true;
}
@@ -308,6 +315,18 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem
loader.BackgroundPrograms.Remove(cartridgeUid);
}
public void SendNotification(EntityUid loaderUid, string header, string message, CartridgeLoaderComponent? loader = default!)
{
if (!Resolve(loaderUid, ref loader))
return;
if (!loader.NotificationsEnabled)
return;
var args = new CartridgeLoaderNotificationSentEvent(header, message);
RaiseLocalEvent(loaderUid, ref args);
}
protected override void OnItemInserted(EntityUid uid, CartridgeLoaderComponent loader, EntInsertedIntoContainerMessage args)
{
if (args.Container.ID != InstalledContainerId && args.Container.ID != loader.CartridgeSlot.ID)
@@ -434,13 +453,10 @@ public sealed class CartridgeLoaderSystem : SharedCartridgeLoaderSystem
UpdateUiState(loaderUid, null, loader);
}
private void UpdateCartridgeInstallationStatus(EntityUid cartridgeUid, InstallationStatus installationStatus, CartridgeComponent? cartridgeComponent = default!)
private void UpdateCartridgeInstallationStatus(EntityUid cartridgeUid, InstallationStatus installationStatus, CartridgeComponent cartridgeComponent)
{
if (Resolve(cartridgeUid, ref cartridgeComponent))
{
cartridgeComponent.InstallationStatus = installationStatus;
Dirty(cartridgeUid, cartridgeComponent);
}
cartridgeComponent.InstallationStatus = installationStatus;
Dirty(cartridgeUid, cartridgeComponent);
}
private bool HasProgram(EntityUid loader, EntityUid program, CartridgeLoaderComponent component)

View File

@@ -1,11 +1,11 @@
namespace Content.Server.CartridgeLoader.Cartridges;
[RegisterComponent]
public sealed partial class NewsReadCartridgeComponent : Component
public sealed partial class NewsReaderCartridgeComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
public int ArticleNum;
public int ArticleNumber;
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables(VVAccess.ReadWrite), DataField]
public bool NotificationOn = true;
}

View File

@@ -19,6 +19,7 @@
<ItemGroup>
<ProjectReference Include="..\Content.Packaging\Content.Packaging.csproj" />
<ProjectReference Include="..\Content.Server.Database\Content.Server.Database.csproj" />
<ProjectReference Include="..\Content.Shared.Database\Content.Shared.Database.csproj" />
<ProjectReference Include="..\RobustToolbox\Lidgren.Network\Lidgren.Network.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Shared.Maths\Robust.Shared.Maths.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Shared\Robust.Shared.csproj" />

View File

@@ -1,23 +0,0 @@
using Robust.Shared.Audio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.MassMedia.Components
{
[RegisterComponent]
public sealed partial class NewsWriteComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)]
public bool ShareAvalible = false;
[ViewVariables(VVAccess.ReadWrite), DataField("nextShare", customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextShare;
[ViewVariables(VVAccess.ReadWrite), DataField("shareCooldown")]
public float ShareCooldown = 60f;
[DataField("noAccessSound")]
public SoundSpecifier NoAccessSound = new SoundPathSpecifier("/Audio/Machines/airlock_deny.ogg");
[DataField("confirmSound")]
public SoundSpecifier ConfirmSound = new SoundPathSpecifier("/Audio/Machines/scan_finish.ogg");
}
}

View File

@@ -0,0 +1,25 @@
using Content.Server.MassMedia.Systems;
using Robust.Shared.Audio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.MassMedia.Components;
[RegisterComponent, AutoGenerateComponentPause]
[Access(typeof(NewsSystem))]
public sealed partial class NewsWriterComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField]
public bool PublishEnabled;
[ViewVariables(VVAccess.ReadWrite), DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField]
public TimeSpan NextPublish;
[ViewVariables(VVAccess.ReadWrite), DataField]
public float PublishCooldown = 20f;
[DataField]
public SoundSpecifier NoAccessSound = new SoundPathSpecifier("/Audio/Machines/airlock_deny.ogg");
[DataField]
public SoundSpecifier ConfirmSound = new SoundPathSpecifier("/Audio/Machines/scan_finish.ogg");
}

View File

@@ -3,285 +3,321 @@ using Content.Server.Administration.Logs;
using Content.Server.CartridgeLoader;
using Content.Server.CartridgeLoader.Cartridges;
using Content.Server.GameTicking;
using Content.Server.MassMedia.Components;
using Content.Server.PDA.Ringer;
using System.Diagnostics.CodeAnalysis;
using Content.Server.Access.Systems;
using Content.Server.Popups;
using Content.Server.StationRecords.Systems;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.CartridgeLoader;
using Content.Shared.CartridgeLoader.Cartridges;
using Content.Shared.Database;
using Content.Shared.GameTicking;
using Content.Shared.MassMedia.Components;
using Content.Shared.MassMedia.Systems;
using Content.Shared.PDA;
using Robust.Server.GameObjects;
using Content.Server.MassMedia.Components;
using Robust.Shared.Timing;
using Content.Server.Station.Systems;
using Content.Shared.Popups;
using Content.Shared.StationRecords;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Containers;
using Robust.Shared.Player;
namespace Content.Server.MassMedia.Systems;
public sealed class NewsSystem : SharedNewsSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly RingerSystem _ringer = default!;
[Dependency] private readonly CartridgeLoaderSystem _cartridgeLoaderSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly AccessReaderSystem _accessReader = default!;
[Dependency] private readonly StationRecordsSystem _stationRecords = default!;
// TODO remove this. Dont store data on systems
// Honestly NewsSystem just needs someone to rewrite it entirely.
private readonly List<NewsArticle> _articles = new List<NewsArticle>();
[Dependency] private readonly IdCardSystem _idCardSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<NewsWriteComponent, NewsWriteShareMessage>(OnWriteUiShareMessage);
SubscribeLocalEvent<NewsWriteComponent, NewsWriteDeleteMessage>(OnWriteUiDeleteMessage);
SubscribeLocalEvent<NewsWriteComponent, NewsWriteArticlesRequestMessage>(OnRequestWriteUiMessage);
// News writer
SubscribeLocalEvent<NewsWriterComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<NewsReadCartridgeComponent, CartridgeUiReadyEvent>(OnReadUiReady);
SubscribeLocalEvent<NewsReadCartridgeComponent, CartridgeMessageEvent>(OnReadUiMessage);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
}
private void OnRoundRestart(RoundRestartCleanupEvent ev)
{
_articles.Clear();
}
public void ToggleUi(EntityUid user, EntityUid deviceEnt, NewsWriteComponent? component)
{
if (!Resolve(deviceEnt, ref component))
return;
if (!TryComp<ActorComponent>(user, out var actor))
return;
_ui.TryToggleUi(deviceEnt, NewsWriteUiKey.Key, actor.PlayerSession);
}
public void OnReadUiReady(EntityUid uid, NewsReadCartridgeComponent component, CartridgeUiReadyEvent args)
{
UpdateReadUi(uid, args.Loader, component);
}
public void UpdateWriteUi(EntityUid uid, NewsWriteComponent component)
{
if (!_ui.TryGetUi(uid, NewsWriteUiKey.Key, out _))
return;
var state = new NewsWriteBoundUserInterfaceState(_articles.ToArray(), component.ShareAvalible);
_ui.TrySetUiState(uid, NewsWriteUiKey.Key, state);
}
public void UpdateReadUi(EntityUid uid, EntityUid loaderUid, NewsReadCartridgeComponent? component)
{
if (!Resolve(uid, ref component))
return;
NewsReadLeafArticle(component, 0);
if (_articles.Any())
_cartridgeLoaderSystem?.UpdateCartridgeUiState(loaderUid, new NewsReadBoundUserInterfaceState(_articles[component.ArticleNum], component.ArticleNum + 1, _articles.Count, component.NotificationOn));
else
_cartridgeLoaderSystem?.UpdateCartridgeUiState(loaderUid, new NewsReadEmptyBoundUserInterfaceState(component.NotificationOn));
}
private void OnReadUiMessage(EntityUid uid, NewsReadCartridgeComponent component, CartridgeMessageEvent args)
{
if (args is not NewsReadUiMessageEvent message)
return;
if (message.Action == NewsReadUiAction.Next)
NewsReadLeafArticle(component, 1);
if (message.Action == NewsReadUiAction.Prev)
NewsReadLeafArticle(component, -1);
if (message.Action == NewsReadUiAction.NotificationSwith)
component.NotificationOn = !component.NotificationOn;
UpdateReadUi(uid, GetEntity(args.LoaderUid), component);
}
public void OnWriteUiShareMessage(EntityUid uid, NewsWriteComponent component, NewsWriteShareMessage msg)
{
// dont blindly trust input from clients.
if (msg.Session.AttachedEntity is not {} author)
return;
if (!_accessReader.FindAccessItemsInventory(author, out var items))
return;
if (!_accessReader.FindStationRecordKeys(author, out _, items))
return;
string? authorName = null;
// TODO: There is a dedicated helper for this.
foreach (var item in items)
// New writer bui messages
Subs.BuiEvents<NewsWriterComponent>(NewsWriterUiKey.Key, subs =>
{
// ID Card
if (TryComp(item, out IdCardComponent? id))
{
authorName = id.FullName;
break;
}
subs.Event<NewsWriterDeleteMessage>(OnWriteUiDeleteMessage);
subs.Event<NewsWriterArticlesRequestMessage>(OnRequestArticlesUiMessage);
subs.Event<NewsWriterPublishMessage>(OnWriteUiPublishMessage);
});
if (TryComp(item, out PdaComponent? pda)
&& pda.ContainedId != null
&& TryComp(pda.ContainedId, out id))
{
authorName = id.FullName;
break;
}
}
var trimmedName = msg.Name.Trim();
var trimmedContent = msg.Content.Trim();
var article = new NewsArticle
{
Author = authorName,
Name = trimmedName.Length <= MaxNameLength ? trimmedName : $"{trimmedName[..MaxNameLength]}...",
Content = trimmedContent.Length <= MaxArticleLength ? trimmedContent : $"{trimmedContent[..MaxArticleLength]}...",
ShareTime = _ticker.RoundDuration()
};
_audio.PlayPvs(component.ConfirmSound, uid);
_adminLogger.Add(LogType.Chat, LogImpact.Medium, $"{ToPrettyString(author):actor} created news article {article.Name} by {article.Author}: {article.Content}");
_articles.Add(article);
component.ShareAvalible = false;
component.NextShare = _timing.CurTime + TimeSpan.FromSeconds(component.ShareCooldown);
UpdateReadDevices();
UpdateWriteDevices();
TryNotify();
}
public void OnWriteUiDeleteMessage(EntityUid uid, NewsWriteComponent component, NewsWriteDeleteMessage msg)
{
if (msg.ArticleNum > _articles.Count)
return;
var articleDeleter = msg.Session.AttachedEntity;
if (CheckDeleteAccess(_articles[msg.ArticleNum], uid, articleDeleter))
{
if (articleDeleter != null)
_adminLogger.Add(LogType.Chat, LogImpact.Medium, $"{ToPrettyString(articleDeleter.Value):actor} deleted news article {_articles[msg.ArticleNum].Name} by {_articles[msg.ArticleNum].Author}: {_articles[msg.ArticleNum].Content}");
else
_adminLogger.Add(LogType.Chat, LogImpact.Medium, $"{msg.Session.Name:actor} created news article {_articles[msg.ArticleNum].Name}: {_articles[msg.ArticleNum].Content}");
_articles.RemoveAt(msg.ArticleNum);
_audio.PlayPvs(component.ConfirmSound, uid);
}
else
{
_popup.PopupEntity(Loc.GetString("news-write-no-access-popup"), uid);
_audio.PlayPvs(component.NoAccessSound, uid);
}
UpdateReadDevices();
UpdateWriteDevices();
}
public void OnRequestWriteUiMessage(EntityUid uid, NewsWriteComponent component, NewsWriteArticlesRequestMessage msg)
{
UpdateWriteUi(uid, component);
}
private void NewsReadLeafArticle(NewsReadCartridgeComponent component, int leafDir)
{
component.ArticleNum += leafDir;
if (component.ArticleNum >= _articles.Count) component.ArticleNum = 0;
if (component.ArticleNum < 0) component.ArticleNum = _articles.Count - 1;
}
private void TryNotify()
{
var query = EntityQueryEnumerator<CartridgeLoaderComponent, RingerComponent, ContainerManagerComponent>();
while (query.MoveNext(out var uid, out var comp, out var ringer, out var cont))
{
if (!_cartridgeLoaderSystem.TryGetProgram<NewsReadCartridgeComponent>(uid, out _, out var newsReadCartridgeComponent, false, comp, cont)
|| !newsReadCartridgeComponent.NotificationOn)
continue;
_ringer.RingerPlayRingtone(uid, ringer);
}
}
private void UpdateReadDevices()
{
var query = EntityQueryEnumerator<CartridgeLoaderComponent>();
while (query.MoveNext(out var owner, out var comp))
{
if (EntityManager.TryGetComponent<NewsReadCartridgeComponent>(comp.ActiveProgram, out var cartridge))
UpdateReadUi(comp.ActiveProgram.Value, owner, cartridge);
}
}
private void UpdateWriteDevices()
{
var query = EntityQueryEnumerator<NewsWriteComponent>();
while (query.MoveNext(out var owner, out var comp))
{
UpdateWriteUi(owner, comp);
}
}
private bool CheckDeleteAccess(NewsArticle articleToDelete, EntityUid device, EntityUid? user)
{
if (EntityManager.TryGetComponent<AccessReaderComponent>(device, out var accessReader) &&
user.HasValue &&
_accessReader.IsAllowed(user.Value, device, accessReader))
{
return true;
}
if (articleToDelete.AuthorStationRecordKeyIds == null ||
!articleToDelete.AuthorStationRecordKeyIds.Any())
{
return true;
}
var conv = _stationRecords.Convert(articleToDelete.AuthorStationRecordKeyIds);
if (user.HasValue
&& _accessReader.FindStationRecordKeys(user.Value, out var recordKeys)
&& recordKeys.Intersect(conv).Any())
{
return true;
}
return false;
// News reader
SubscribeLocalEvent<NewsReaderCartridgeComponent, NewsArticlePublishedEvent>(OnArticlePublished);
SubscribeLocalEvent<NewsReaderCartridgeComponent, NewsArticleDeletedEvent>(OnArticleDeleted);
SubscribeLocalEvent<NewsReaderCartridgeComponent, CartridgeMessageEvent>(OnReaderUiMessage);
SubscribeLocalEvent<NewsReaderCartridgeComponent, CartridgeUiReadyEvent>(OnReaderUiReady);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<NewsWriteComponent>();
var query = EntityQueryEnumerator<NewsWriterComponent>();
while (query.MoveNext(out var uid, out var comp))
{
if (comp.ShareAvalible || _timing.CurTime < comp.NextShare)
if (comp.PublishEnabled || _timing.CurTime < comp.NextPublish)
continue;
comp.ShareAvalible = true;
UpdateWriteUi(uid, comp);
comp.PublishEnabled = true;
UpdateWriterUi((uid, comp));
}
}
}
#region Writer Event Handlers
private void OnMapInit(Entity<NewsWriterComponent> ent, ref MapInitEvent args)
{
var station = _station.GetOwningStation(ent);
if (!station.HasValue)
return;
EnsureComp<StationNewsComponent>(station.Value);
}
private void OnWriteUiDeleteMessage(Entity<NewsWriterComponent> ent, ref NewsWriterDeleteMessage msg)
{
if (!TryGetArticles(ent, out var articles))
return;
if (msg.ArticleNum >= articles.Count)
return;
if (msg.Session.AttachedEntity is not { } actor)
return;
var article = articles[msg.ArticleNum];
if (CheckDeleteAccess(article, ent, actor))
{
_adminLogger.Add(
LogType.Chat, LogImpact.Medium,
$"{ToPrettyString(actor):actor} deleted news article {article.Title} by {article.Author}: {article.Content}"
);
articles.RemoveAt(msg.ArticleNum);
_audio.PlayPvs(ent.Comp.ConfirmSound, ent);
}
else
{
_popup.PopupEntity(Loc.GetString("news-write-no-access-popup"), ent, PopupType.SmallCaution);
_audio.PlayPvs(ent.Comp.NoAccessSound, ent);
}
var args = new NewsArticleDeletedEvent();
var query = EntityQueryEnumerator<NewsReaderCartridgeComponent>();
while (query.MoveNext(out var readerUid, out _))
{
RaiseLocalEvent(readerUid, ref args);
}
UpdateWriterDevices();
}
private void OnRequestArticlesUiMessage(Entity<NewsWriterComponent> ent, ref NewsWriterArticlesRequestMessage msg)
{
UpdateWriterUi(ent);
}
private void OnWriteUiPublishMessage(Entity<NewsWriterComponent> ent, ref NewsWriterPublishMessage msg)
{
if (!ent.Comp.PublishEnabled)
return;
ent.Comp.PublishEnabled = false;
ent.Comp.NextPublish = _timing.CurTime + TimeSpan.FromSeconds(ent.Comp.PublishCooldown);
if (!TryGetArticles(ent, out var articles))
return;
if (msg.Session.AttachedEntity is not { } author)
return;
if (!_accessReader.FindStationRecordKeys(author, out _))
return;
string? authorName = null;
if (_idCardSystem.TryFindIdCard(author, out var idCard))
authorName = idCard.Comp.FullName;
var title = msg.Title.Trim();
var content = msg.Content.Trim();
var article = new NewsArticle
{
Title = title.Length <= MaxTitleLength ? title : $"{title[..MaxTitleLength]}...",
Content = content.Length <= MaxContentLength ? content : $"{content[..MaxContentLength]}...",
Author = authorName,
ShareTime = _ticker.RoundDuration()
};
_audio.PlayPvs(ent.Comp.ConfirmSound, ent);
_adminLogger.Add(
LogType.Chat,
LogImpact.Medium,
$"{ToPrettyString(author):actor} created news article {article.Title} by {article.Author}: {article.Content}"
);
articles.Add(article);
var args = new NewsArticlePublishedEvent(article);
var query = EntityQueryEnumerator<NewsReaderCartridgeComponent>();
while (query.MoveNext(out var readerUid, out _))
{
RaiseLocalEvent(readerUid, ref args);
}
UpdateWriterDevices();
}
#endregion
#region Reader Event Handlers
private void OnArticlePublished(Entity<NewsReaderCartridgeComponent> ent, ref NewsArticlePublishedEvent args)
{
if (Comp<CartridgeComponent>(ent).LoaderUid is not { } loaderUid)
return;
UpdateReaderUi(ent, loaderUid);
if (!ent.Comp.NotificationOn)
return;
_cartridgeLoaderSystem.SendNotification(
loaderUid,
Loc.GetString("news-pda-notification-header"),
args.Article.Title);
}
private void OnArticleDeleted(Entity<NewsReaderCartridgeComponent> ent, ref NewsArticleDeletedEvent args)
{
if (Comp<CartridgeComponent>(ent).LoaderUid is not { } loaderUid)
return;
UpdateReaderUi(ent, loaderUid);
}
private void OnReaderUiMessage(Entity<NewsReaderCartridgeComponent> ent, ref CartridgeMessageEvent args)
{
if (args is not NewsReaderUiMessageEvent message)
return;
switch (message.Action)
{
case NewsReaderUiAction.Next:
NewsReaderLeafArticle(ent, 1);
break;
case NewsReaderUiAction.Prev:
NewsReaderLeafArticle(ent, -1);
break;
case NewsReaderUiAction.NotificationSwitch:
ent.Comp.NotificationOn = !ent.Comp.NotificationOn;
break;
}
UpdateReaderUi(ent, GetEntity(args.LoaderUid));
}
private void OnReaderUiReady(Entity<NewsReaderCartridgeComponent> ent, ref CartridgeUiReadyEvent args)
{
UpdateReaderUi(ent, args.Loader);
}
#endregion
private bool TryGetArticles(EntityUid uid, [NotNullWhen(true)] out List<NewsArticle>? articles)
{
if (_station.GetOwningStation(uid) is not { } station ||
!TryComp<StationNewsComponent>(station, out var stationNews))
{
articles = null;
return false;
}
articles = stationNews.Articles;
return true;
}
private void UpdateWriterUi(Entity<NewsWriterComponent> ent)
{
if (!_ui.TryGetUi(ent, NewsWriterUiKey.Key, out var ui))
return;
if (!TryGetArticles(ent, out var articles))
return;
var state = new NewsWriterBoundUserInterfaceState(articles.ToArray(), ent.Comp.PublishEnabled, ent.Comp.NextPublish);
_ui.SetUiState(ui, state);
}
private void UpdateReaderUi(Entity<NewsReaderCartridgeComponent> ent, EntityUid loaderUid)
{
if (!TryGetArticles(ent, out var articles))
return;
NewsReaderLeafArticle(ent, 0);
if (articles.Count == 0)
{
_cartridgeLoaderSystem.UpdateCartridgeUiState(loaderUid, new NewsReaderEmptyBoundUserInterfaceState(ent.Comp.NotificationOn));
return;
}
var state = new NewsReaderBoundUserInterfaceState(
articles[ent.Comp.ArticleNumber],
ent.Comp.ArticleNumber + 1,
articles.Count,
ent.Comp.NotificationOn);
_cartridgeLoaderSystem.UpdateCartridgeUiState(loaderUid, state);
}
private void NewsReaderLeafArticle(Entity<NewsReaderCartridgeComponent> ent, int leafDir)
{
if (!TryGetArticles(ent, out var articles))
return;
ent.Comp.ArticleNumber += leafDir;
if (ent.Comp.ArticleNumber >= articles.Count)
ent.Comp.ArticleNumber = 0;
if (ent.Comp.ArticleNumber < 0)
ent.Comp.ArticleNumber = articles.Count - 1;
}
private void UpdateWriterDevices()
{
var query = EntityQueryEnumerator<NewsWriterComponent>();
while (query.MoveNext(out var owner, out var comp))
{
UpdateWriterUi((owner, comp));
}
}
private bool CheckDeleteAccess(NewsArticle articleToDelete, EntityUid device, EntityUid user)
{
if (TryComp<AccessReaderComponent>(device, out var accessReader) &&
_accessReader.IsAllowed(user, device, accessReader))
return true;
if (articleToDelete.AuthorStationRecordKeyIds == null || articleToDelete.AuthorStationRecordKeyIds.Count == 0)
return true;
return _accessReader.FindStationRecordKeys(user, out var recordKeys)
&& StationRecordsToNetEntities(recordKeys).Intersect(articleToDelete.AuthorStationRecordKeyIds).Any();
}
private ICollection<(NetEntity, uint)> StationRecordsToNetEntities(IEnumerable<StationRecordKey> records)
{
return records.Select(record => (GetNetEntity(record.OriginStation), record.Id)).ToList();
}
}

View File

@@ -1,5 +1,6 @@
using Content.Server.AlertLevel;
using Content.Server.CartridgeLoader;
using Content.Server.Chat.Managers;
using Content.Server.DeviceNetwork.Components;
using Content.Server.Instruments;
using Content.Server.Light.EntitySystems;
@@ -10,10 +11,14 @@ using Content.Server.Store.Components;
using Content.Server.Store.Systems;
using Content.Shared.Access.Components;
using Content.Shared.CartridgeLoader;
using Content.Shared.Chat;
using Content.Shared.Light.Components;
using Content.Shared.PDA;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Containers;
using Robust.Shared.Player;
using Robust.Shared.Utility;
namespace Content.Server.PDA
{
@@ -24,8 +29,10 @@ namespace Content.Server.PDA
[Dependency] private readonly RingerSystem _ringer = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly StoreSystem _store = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly UnpoweredFlashlightSystem _unpoweredFlashlight = default!;
[Dependency] private readonly ContainerSystem _containerSystem = default!;
public override void Initialize()
{
@@ -41,6 +48,8 @@ namespace Content.Server.PDA
SubscribeLocalEvent<PdaComponent, PdaShowUplinkMessage>(OnUiMessage);
SubscribeLocalEvent<PdaComponent, PdaLockUplinkMessage>(OnUiMessage);
SubscribeLocalEvent<PdaComponent, CartridgeLoaderNotificationSentEvent>(OnNotification);
SubscribeLocalEvent<StationRenamedEvent>(OnStationRenamed);
SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertLevelChanged);
}
@@ -106,6 +115,28 @@ namespace Content.Server.PDA
}
}
private void OnNotification(Entity<PdaComponent> ent, ref CartridgeLoaderNotificationSentEvent args)
{
_ringer.RingerPlayRingtone(ent.Owner);
if (!_containerSystem.TryGetContainingContainer(ent, out var container)
|| !TryComp<ActorComponent>(container.Owner, out var actor))
return;
var message = FormattedMessage.EscapeText(args.Message);
var wrappedMessage = Loc.GetString("pda-notification-message",
("header", args.Header),
("message", message));
_chatManager.ChatMessageToOne(
ChatChannel.Notifications,
message,
wrappedMessage,
EntityUid.Invalid,
false,
actor.PlayerSession.Channel);
}
/// <summary>
/// Send new UI state to clients, call if you modify something like uplink.
/// </summary>

View File

@@ -63,13 +63,16 @@ namespace Content.Server.PDA.Ringer
UpdateRingerUserInterface(uid, ringer, true);
}
public void RingerPlayRingtone(EntityUid uid, RingerComponent ringer)
public void RingerPlayRingtone(Entity<RingerComponent?> ent)
{
EnsureComp<ActiveRingerComponent>(uid);
if (!Resolve(ent, ref ent.Comp))
return;
_popupSystem.PopupEntity(Loc.GetString("comp-ringer-vibration-popup"), uid, Filter.Pvs(uid, 0.05f), false, PopupType.Small);
EnsureComp<ActiveRingerComponent>(ent);
UpdateRingerUserInterface(uid, ringer, true);
_popupSystem.PopupEntity(Loc.GetString("comp-ringer-vibration-popup"), ent, Filter.Pvs(ent, 0.05f), false, PopupType.Medium);
UpdateRingerUserInterface(ent, ent.Comp, true);
}
private void UpdateRingerUserInterfaceDriver(EntityUid uid, RingerComponent ringer, RingerRequestUpdateInterfaceMessage args)