NewsSystem fixes (#23969)
This commit is contained in:
8
Content.Client/MassMedia/NewsSystem.cs
Normal file
8
Content.Client/MassMedia/NewsSystem.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Content.Shared.MassMedia.Systems;
|
||||||
|
|
||||||
|
namespace Content.Client.MassMedia;
|
||||||
|
|
||||||
|
public sealed class NewsSystem : SharedNewsSystem
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
using Robust.Shared.Timing;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.GameObjects;
|
|
||||||
using Content.Shared.MassMedia.Systems;
|
|
||||||
using Content.Shared.MassMedia.Components;
|
using Content.Shared.MassMedia.Components;
|
||||||
using Content.Client.GameTicking.Managers;
|
using Content.Shared.MassMedia.Systems;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Client.MassMedia.Ui
|
namespace Content.Client.MassMedia.Ui
|
||||||
@@ -14,16 +11,11 @@ namespace Content.Client.MassMedia.Ui
|
|||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private NewsWriteMenu? _menu;
|
private NewsWriteMenu? _menu;
|
||||||
|
|
||||||
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;
|
|
||||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
||||||
private ClientGameTicker? _gameTicker;
|
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
private string _windowName = Loc.GetString("news-read-ui-default-title");
|
private string _windowName = Loc.GetString("news-read-ui-default-title");
|
||||||
|
|
||||||
public NewsWriteBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
public NewsWriteBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Open()
|
protected override void Open()
|
||||||
@@ -36,8 +28,6 @@ namespace Content.Client.MassMedia.Ui
|
|||||||
_menu.ShareButtonPressed += OnShareButtonPressed;
|
_menu.ShareButtonPressed += OnShareButtonPressed;
|
||||||
_menu.DeleteButtonPressed += OnDeleteButtonPressed;
|
_menu.DeleteButtonPressed += OnDeleteButtonPressed;
|
||||||
|
|
||||||
_gameTicker = _entitySystem.GetEntitySystem<ClientGameTicker>();
|
|
||||||
|
|
||||||
SendMessage(new NewsWriteArticlesRequestMessage());
|
SendMessage(new NewsWriteArticlesRequestMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,19 +57,21 @@ namespace Content.Client.MassMedia.Ui
|
|||||||
|
|
||||||
var stringContent = Rope.Collapse(_menu.ContentInput.TextRope);
|
var stringContent = Rope.Collapse(_menu.ContentInput.TextRope);
|
||||||
|
|
||||||
if (stringContent == null || stringContent.Length == 0)
|
if (stringContent.Length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var stringName = _menu.NameInput.Text;
|
var stringName = _menu.NameInput.Text.Trim();
|
||||||
var name = (stringName.Length <= 25 ? stringName.Trim() : $"{stringName.Trim().Substring(0, 25)}...");
|
var name = stringName[..(SharedNewsSystem.MaxNameLength)];
|
||||||
|
var content = stringContent[..(SharedNewsSystem.MaxArticleLength)];
|
||||||
_menu.ContentInput.TextRope = new Rope.Leaf(string.Empty);
|
_menu.ContentInput.TextRope = new Rope.Leaf(string.Empty);
|
||||||
_menu.NameInput.Text = string.Empty;
|
_menu.NameInput.Text = string.Empty;
|
||||||
SendMessage(new NewsWriteShareMessage(name, stringContent));
|
SendMessage(new NewsWriteShareMessage(name, content));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDeleteButtonPressed(int articleNum)
|
private void OnDeleteButtonPressed(int articleNum)
|
||||||
{
|
{
|
||||||
if (_menu == null) return;
|
if (_menu == null)
|
||||||
|
return;
|
||||||
|
|
||||||
SendMessage(new NewsWriteDeleteMessage(articleNum));
|
SendMessage(new NewsWriteDeleteMessage(articleNum));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ using Robust.Shared.Timing;
|
|||||||
|
|
||||||
namespace Content.Server.MassMedia.Systems;
|
namespace Content.Server.MassMedia.Systems;
|
||||||
|
|
||||||
public sealed class NewsSystem : EntitySystem
|
public sealed class NewsSystem : SharedNewsSystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _timing = default!;
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||||
@@ -50,6 +50,7 @@ public sealed class NewsSystem : EntitySystem
|
|||||||
[Dependency] private readonly StationRecordsSystem _stationRecords = default!;
|
[Dependency] private readonly StationRecordsSystem _stationRecords = default!;
|
||||||
|
|
||||||
// TODO remove this. Dont store data on systems
|
// 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>();
|
private readonly List<NewsArticle> _articles = new List<NewsArticle>();
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -68,7 +69,7 @@ public sealed class NewsSystem : EntitySystem
|
|||||||
|
|
||||||
private void OnRoundRestart(RoundRestartCleanupEvent ev)
|
private void OnRoundRestart(RoundRestartCleanupEvent ev)
|
||||||
{
|
{
|
||||||
_articles?.Clear();
|
_articles.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ToggleUi(EntityUid user, EntityUid deviceEnt, NewsWriteComponent? component)
|
public void ToggleUi(EntityUid user, EntityUid deviceEnt, NewsWriteComponent? component)
|
||||||
@@ -133,10 +134,12 @@ public sealed class NewsSystem : EntitySystem
|
|||||||
if (!_accessReader.FindAccessItemsInventory(author, out var items))
|
if (!_accessReader.FindAccessItemsInventory(author, out var items))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!_accessReader.FindStationRecordKeys(author, out var stationRecordKeys, items))
|
if (!_accessReader.FindStationRecordKeys(author, out _, items))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string? authorName = null;
|
string? authorName = null;
|
||||||
|
|
||||||
|
// TODO: There is a dedicated helper for this.
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
// ID Card
|
// ID Card
|
||||||
@@ -155,13 +158,15 @@ public sealed class NewsSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NewsArticle article = new NewsArticle
|
var trimmedName = msg.Name.Trim();
|
||||||
|
var trimmedContent = msg.Content.Trim();
|
||||||
|
|
||||||
|
var article = new NewsArticle
|
||||||
{
|
{
|
||||||
Author = authorName,
|
Author = authorName,
|
||||||
Name = (msg.Name.Length <= 25 ? msg.Name.Trim() : $"{msg.Name.Trim().Substring(0, 25)}..."),
|
Name = trimmedName.Length <= MaxNameLength ? trimmedName : $"{trimmedName[..MaxNameLength]}...",
|
||||||
Content = msg.Content,
|
Content = trimmedContent.Length <= MaxArticleLength ? trimmedContent : $"{trimmedContent[..MaxArticleLength]}...",
|
||||||
ShareTime = _ticker.RoundDuration()
|
ShareTime = _ticker.RoundDuration()
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_audio.PlayPvs(component.ConfirmSound, uid);
|
_audio.PlayPvs(component.ConfirmSound, uid);
|
||||||
|
|||||||
@@ -2,6 +2,12 @@ using Robust.Shared.Serialization;
|
|||||||
|
|
||||||
namespace Content.Shared.MassMedia.Systems;
|
namespace Content.Shared.MassMedia.Systems;
|
||||||
|
|
||||||
|
public abstract class SharedNewsSystem : EntitySystem
|
||||||
|
{
|
||||||
|
public const int MaxNameLength = 25;
|
||||||
|
public const int MaxArticleLength = 2048;
|
||||||
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public struct NewsArticle
|
public struct NewsArticle
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user