86 lines
2.4 KiB
C#
86 lines
2.4 KiB
C#
using JetBrains.Annotations;
|
|
using Content.Shared.MassMedia.Systems;
|
|
using Content.Shared.MassMedia.Components;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client.MassMedia.Ui;
|
|
|
|
[UsedImplicitly]
|
|
public sealed class NewsWriterBoundUserInterface : BoundUserInterface
|
|
{
|
|
[ViewVariables]
|
|
private NewsWriterMenu? _menu;
|
|
|
|
public NewsWriterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
|
{
|
|
|
|
}
|
|
|
|
protected override void Open()
|
|
{
|
|
base.Open();
|
|
|
|
_menu = this.CreateWindow<NewsWriterMenu>();
|
|
|
|
_menu.ArticleEditorPanel.PublishButtonPressed += OnPublishButtonPressed;
|
|
_menu.DeleteButtonPressed += OnDeleteButtonPressed;
|
|
|
|
_menu.CreateButtonPressed += OnCreateButtonPressed;
|
|
_menu.ArticleEditorPanel.ArticleDraftUpdated += OnArticleDraftUpdated;
|
|
|
|
SendMessage(new NewsWriterArticlesRequestMessage());
|
|
}
|
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
{
|
|
base.UpdateState(state);
|
|
if (state is not NewsWriterBoundUserInterfaceState cast)
|
|
return;
|
|
|
|
_menu?.UpdateUI(cast.Articles, cast.PublishEnabled, cast.NextPublish, cast.DraftTitle, cast.DraftContent);
|
|
}
|
|
|
|
private void OnPublishButtonPressed()
|
|
{
|
|
var title = _menu?.ArticleEditorPanel.TitleField.Text.Trim() ?? "";
|
|
if (_menu == null || title.Length == 0)
|
|
return;
|
|
|
|
var stringContent = Rope.Collapse(_menu.ArticleEditorPanel.ContentField.TextRope).Trim();
|
|
|
|
if (stringContent.Length == 0)
|
|
return;
|
|
|
|
var name = title.Length <= SharedNewsSystem.MaxTitleLength
|
|
? title
|
|
: $"{title[..(SharedNewsSystem.MaxTitleLength - 3)]}...";
|
|
|
|
var content = stringContent.Length <= SharedNewsSystem.MaxContentLength
|
|
? stringContent
|
|
: $"{stringContent[..(SharedNewsSystem.MaxContentLength - 3)]}...";
|
|
|
|
|
|
SendMessage(new NewsWriterPublishMessage(name, content));
|
|
}
|
|
|
|
private void OnDeleteButtonPressed(int articleNum)
|
|
{
|
|
if (_menu == null)
|
|
return;
|
|
|
|
SendMessage(new NewsWriterDeleteMessage(articleNum));
|
|
}
|
|
|
|
private void OnCreateButtonPressed()
|
|
{
|
|
SendMessage(new NewsWriterRequestDraftMessage());
|
|
}
|
|
|
|
private void OnArticleDraftUpdated(string title, string content)
|
|
{
|
|
SendMessage(new NewsWriterSaveDraftMessage(title, content));
|
|
}
|
|
}
|