add mass-media system (#18251)
* Add Console, PDA news tab, and ringstone popup * Add English localization * Add mass-media console board to Advanced Entertainment resrarch * Fix misprint * Deleting unused libraries * Fix round restart problem * Fixing restart problem * Just another fix * Сode optimization * Code optimization
This commit is contained in:
9
Content.Server/MassMedia/Components/NewsReadComponent.cs
Normal file
9
Content.Server/MassMedia/Components/NewsReadComponent.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Content.Server.MassMedia.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class NewsReadComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int ArticleNum;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Content.Server.MassMedia.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class NewsWriteComponent : Component
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
163
Content.Server/MassMedia/Systems/NewsSystem.cs
Normal file
163
Content.Server/MassMedia/Systems/NewsSystem.cs
Normal file
@@ -0,0 +1,163 @@
|
||||
using Content.Server.MassMedia.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Content.Shared.MassMedia.Components;
|
||||
using Content.Shared.MassMedia.Systems;
|
||||
using Content.Server.PDA.Ringer;
|
||||
using Content.Shared.GameTicking;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.MassMedia.Systems;
|
||||
|
||||
public sealed class NewsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||
[Dependency] private readonly RingerSystem _ringer = default!;
|
||||
|
||||
public List<NewsArticle> Articles = new List<NewsArticle>();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<NewsWriteComponent, NewsWriteShareMessage>(OnWriteUiMessage);
|
||||
SubscribeLocalEvent<NewsWriteComponent, NewsWriteDeleteMessage>(OnWriteUiMessage);
|
||||
SubscribeLocalEvent<NewsWriteComponent, NewsWriteArticlesRequestMessage>(OnWriteUiMessage);
|
||||
SubscribeLocalEvent<NewsReadComponent, NewsReadNextMessage>(OnReadUiMessage);
|
||||
SubscribeLocalEvent<NewsReadComponent, NewsReadPrevMessage>(OnReadUiMessage);
|
||||
SubscribeLocalEvent<NewsReadComponent, NewsReadArticleRequestMessage>(OnReadUiMessage);
|
||||
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestart);
|
||||
}
|
||||
|
||||
private void OnRoundRestart(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
if (Articles != null) Articles.Clear();
|
||||
}
|
||||
|
||||
public void ToggleUi(EntityUid user, EntityUid deviceEnt, NewsReadComponent? component)
|
||||
{
|
||||
if (!Resolve(deviceEnt, ref component))
|
||||
return;
|
||||
|
||||
if (!TryComp<ActorComponent>(user, out var actor))
|
||||
return;
|
||||
|
||||
_ui.TryToggleUi(deviceEnt, NewsReadUiKey.Key, actor.PlayerSession);
|
||||
}
|
||||
|
||||
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 UpdateWriteUi(EntityUid uid, NewsWriteComponent component)
|
||||
{
|
||||
if (!_ui.TryGetUi(uid, NewsWriteUiKey.Key, out _))
|
||||
return;
|
||||
|
||||
var state = new NewsWriteBoundUserInterfaceState(Articles.ToArray());
|
||||
_ui.TrySetUiState(uid, NewsWriteUiKey.Key, state);
|
||||
}
|
||||
|
||||
public void UpdateReadUi(EntityUid uid, NewsReadComponent component)
|
||||
{
|
||||
if (!_ui.TryGetUi(uid, NewsReadUiKey.Key, out _))
|
||||
return;
|
||||
|
||||
if (component.ArticleNum < 0) NewsReadLeafArticle(component, -1);
|
||||
|
||||
if (Articles.Any())
|
||||
_ui.TrySetUiState(uid, NewsReadUiKey.Key, new NewsReadBoundUserInterfaceState(Articles[component.ArticleNum], component.ArticleNum + 1, Articles.Count));
|
||||
else
|
||||
_ui.TrySetUiState(uid, NewsReadUiKey.Key, new NewsReadEmptyBoundUserInterfaceState());
|
||||
}
|
||||
|
||||
public void OnWriteUiMessage(EntityUid uid, NewsWriteComponent component, NewsWriteShareMessage msg)
|
||||
{
|
||||
Articles.Add(msg.Article);
|
||||
|
||||
UpdateReadDevices();
|
||||
UpdateWriteDevices();
|
||||
TryNotify();
|
||||
}
|
||||
|
||||
public void OnWriteUiMessage(EntityUid uid, NewsWriteComponent component, NewsWriteDeleteMessage msg)
|
||||
{
|
||||
if (msg.ArticleNum < Articles.Count)
|
||||
{
|
||||
Articles.RemoveAt(msg.ArticleNum);
|
||||
}
|
||||
|
||||
UpdateReadDevices();
|
||||
UpdateWriteDevices();
|
||||
}
|
||||
|
||||
public void OnWriteUiMessage(EntityUid uid, NewsWriteComponent component, NewsWriteArticlesRequestMessage msg)
|
||||
{
|
||||
UpdateWriteUi(uid, component);
|
||||
}
|
||||
|
||||
public void OnReadUiMessage(EntityUid uid, NewsReadComponent component, NewsReadNextMessage msg)
|
||||
{
|
||||
NewsReadLeafArticle(component, 1);
|
||||
|
||||
UpdateReadUi(uid, component);
|
||||
}
|
||||
|
||||
public void OnReadUiMessage(EntityUid uid, NewsReadComponent component, NewsReadPrevMessage msg)
|
||||
{
|
||||
NewsReadLeafArticle(component, -1);
|
||||
|
||||
UpdateReadUi(uid, component);
|
||||
}
|
||||
|
||||
public void OnReadUiMessage(EntityUid uid, NewsReadComponent component, NewsReadArticleRequestMessage msg)
|
||||
{
|
||||
UpdateReadUi(uid, component);
|
||||
}
|
||||
|
||||
private void NewsReadLeafArticle(NewsReadComponent 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<NewsReadComponent, RingerComponent>();
|
||||
|
||||
while (query.MoveNext(out var comp, out var ringer))
|
||||
{
|
||||
_ringer.RingerPlayRingtone(comp.Owner, ringer);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateReadDevices()
|
||||
{
|
||||
var query = EntityQueryEnumerator<NewsReadComponent>();
|
||||
|
||||
while (query.MoveNext(out var comp))
|
||||
{
|
||||
UpdateReadUi(comp.Owner, comp);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateWriteDevices()
|
||||
{
|
||||
var query = EntityQueryEnumerator<NewsWriteComponent>();
|
||||
|
||||
while (query.MoveNext(out var comp))
|
||||
{
|
||||
UpdateWriteUi(comp.Owner, comp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Containers;
|
||||
using Content.Shared.Light.Component;
|
||||
using Content.Server.MassMedia.Components;
|
||||
using Content.Server.MassMedia.Systems;
|
||||
|
||||
namespace Content.Server.PDA
|
||||
{
|
||||
@@ -25,6 +27,7 @@ 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 NewsSystem _news = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||
[Dependency] private readonly UnpoweredFlashlightSystem _unpoweredFlashlight = default!;
|
||||
[Dependency] private readonly MindSystem _mindSystem = default!;
|
||||
@@ -42,6 +45,7 @@ namespace Content.Server.PDA
|
||||
SubscribeLocalEvent<PdaComponent, PdaShowMusicMessage>(OnUiMessage);
|
||||
SubscribeLocalEvent<PdaComponent, PdaShowUplinkMessage>(OnUiMessage);
|
||||
SubscribeLocalEvent<PdaComponent, PdaLockUplinkMessage>(OnUiMessage);
|
||||
SubscribeLocalEvent<PdaComponent, PdaOpenNewsMessage>(OnUiMessage);
|
||||
|
||||
SubscribeLocalEvent<StationRenamedEvent>(OnStationRenamed);
|
||||
SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertLevelChanged);
|
||||
@@ -112,6 +116,7 @@ namespace Content.Server.PDA
|
||||
var address = GetDeviceNetAddress(uid);
|
||||
var hasInstrument = HasComp<InstrumentComponent>(uid);
|
||||
var showUplink = HasComp<StoreComponent>(uid) && IsUnlocked(uid);
|
||||
var showNews = HasComp<NewsReadComponent>(uid);
|
||||
|
||||
UpdateStationName(uid, pda);
|
||||
UpdateAlertLevel(uid, pda);
|
||||
@@ -133,6 +138,7 @@ namespace Content.Server.PDA
|
||||
pda.StationName,
|
||||
showUplink,
|
||||
hasInstrument,
|
||||
showNews,
|
||||
address);
|
||||
|
||||
_cartridgeLoader?.UpdateUiState(uid, state);
|
||||
@@ -195,6 +201,18 @@ namespace Content.Server.PDA
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUiMessage(EntityUid uid, PdaComponent pda, PdaOpenNewsMessage msg)
|
||||
{
|
||||
if (!PdaUiKey.Key.Equals(msg.UiKey))
|
||||
return;
|
||||
|
||||
if (TryComp<NewsReadComponent>(uid, out var news))
|
||||
{
|
||||
_news.ToggleUi(msg.Session.AttachedEntity!.Value, uid, news);
|
||||
UpdatePdaUi(uid, pda);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsUnlocked(EntityUid uid)
|
||||
{
|
||||
return !TryComp<RingerUplinkComponent>(uid, out var uplink) || uplink.Unlocked;
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Content.Server.PDA.Ringer
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("range")]
|
||||
public float Range = 3f;
|
||||
public float Range = 0.5f;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("volume")]
|
||||
|
||||
@@ -2,6 +2,7 @@ using Content.Server.Store.Components;
|
||||
using Content.Server.Store.Systems;
|
||||
using Content.Shared.PDA;
|
||||
using Content.Shared.PDA.Ringer;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Store;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
@@ -19,6 +20,7 @@ namespace Content.Server.PDA.Ringer
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||
[Dependency] private readonly AudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -48,6 +50,18 @@ namespace Content.Server.PDA.Ringer
|
||||
private void RingerPlayRingtone(EntityUid uid, RingerComponent ringer, RingerPlayRingtoneMessage args)
|
||||
{
|
||||
EnsureComp<ActiveRingerComponent>(uid);
|
||||
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-ringer-vibration-popup"), uid, Filter.Pvs(uid, 0.05f), false, PopupType.Small);
|
||||
|
||||
UpdateRingerUserInterface(uid, ringer);
|
||||
}
|
||||
|
||||
public void RingerPlayRingtone(EntityUid uid, RingerComponent ringer)
|
||||
{
|
||||
EnsureComp<ActiveRingerComponent>(uid);
|
||||
|
||||
_popupSystem.PopupEntity(Loc.GetString("comp-ringer-vibration-popup"), uid, Filter.Pvs(uid, 0.05f), false, PopupType.Small);
|
||||
|
||||
UpdateRingerUserInterface(uid, ringer);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user