2020-08-22 22:29:20 +02:00
|
|
|
using System.Threading.Tasks;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.UserInterface;
|
|
|
|
|
using Content.Shared.Examine;
|
|
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Paper;
|
|
|
|
|
using Content.Shared.Tag;
|
2020-02-11 20:01:05 -03:00
|
|
|
using Robust.Server.GameObjects;
|
2022-03-12 13:26:06 -05:00
|
|
|
|
2020-02-11 20:01:05 -03:00
|
|
|
using Robust.Shared.Utility;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Server.Paper
|
2020-02-11 20:01:05 -03:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning disable 618
|
2022-01-05 02:23:01 +13:00
|
|
|
[ComponentReference(typeof(SharedPaperComponent))]
|
2022-03-12 13:26:06 -05:00
|
|
|
public sealed class PaperComponent : SharedPaperComponent, IExamine, IInteractUsing
|
2021-10-27 18:10:40 +02:00
|
|
|
#pragma warning restore 618
|
2020-02-11 20:01:05 -03:00
|
|
|
{
|
2021-12-08 17:32:32 +01:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
|
|
|
|
2022-03-12 13:26:06 -05:00
|
|
|
public PaperAction Mode;
|
2021-05-15 16:43:19 +01:00
|
|
|
[DataField("content")]
|
2021-11-11 04:29:11 +03:00
|
|
|
public string Content { get; set; } = "";
|
2020-02-11 20:01:05 -03:00
|
|
|
|
2022-01-17 19:24:09 +00:00
|
|
|
[DataField("contentSize")]
|
|
|
|
|
public int ContentSize { get; set; } = 500;
|
|
|
|
|
|
|
|
|
|
|
2020-08-24 20:47:17 +02:00
|
|
|
[ViewVariables] private BoundUserInterface? UserInterface => Owner.GetUIOrNull(PaperUiKey.Key);
|
2020-08-22 22:29:20 +02:00
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void Initialize()
|
2020-02-11 20:01:05 -03:00
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2020-08-22 22:29:20 +02:00
|
|
|
|
|
|
|
|
if (UserInterface != null)
|
|
|
|
|
{
|
|
|
|
|
UserInterface.OnReceiveMessage += OnUiReceiveMessage;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-12 13:26:06 -05:00
|
|
|
Mode = PaperAction.Read;
|
2020-02-11 20:01:05 -03:00
|
|
|
UpdateUserInterface();
|
|
|
|
|
}
|
2021-11-11 02:15:23 +13:00
|
|
|
|
|
|
|
|
public void SetContent(string content)
|
|
|
|
|
{
|
2022-01-17 19:24:09 +00:00
|
|
|
|
2021-11-11 02:15:23 +13:00
|
|
|
Content = content + '\n';
|
|
|
|
|
UpdateUserInterface();
|
|
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
if (!_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance))
|
2021-11-11 02:15:23 +13:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var status = string.IsNullOrWhiteSpace(content)
|
|
|
|
|
? PaperStatus.Blank
|
|
|
|
|
: PaperStatus.Written;
|
|
|
|
|
|
|
|
|
|
appearance.SetData(PaperVisuals.Status, status);
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-12 13:26:06 -05:00
|
|
|
public void UpdateUserInterface()
|
2020-02-11 20:01:05 -03:00
|
|
|
{
|
2022-03-12 13:26:06 -05:00
|
|
|
UserInterface?.SetState(new PaperBoundUserInterfaceState(Content, Mode));
|
2020-02-11 20:01:05 -03:00
|
|
|
}
|
|
|
|
|
|
2021-12-20 12:42:42 +01:00
|
|
|
public void Examine(FormattedMessage message, bool inDetailsRange)
|
2020-02-11 20:01:05 -03:00
|
|
|
{
|
2020-05-31 19:29:06 +01:00
|
|
|
if (!inDetailsRange)
|
|
|
|
|
return;
|
2021-05-15 16:43:19 +01:00
|
|
|
if (Content == "")
|
|
|
|
|
return;
|
2020-05-31 19:29:06 +01:00
|
|
|
|
2021-05-15 16:43:19 +01:00
|
|
|
message.AddMarkup(
|
|
|
|
|
Loc.GetString(
|
|
|
|
|
"paper-component-examine-detail-has-words"
|
|
|
|
|
)
|
|
|
|
|
);
|
2020-02-11 20:01:05 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj)
|
|
|
|
|
{
|
|
|
|
|
var msg = (PaperInputText) obj.Message;
|
|
|
|
|
if (string.IsNullOrEmpty(msg.Text))
|
|
|
|
|
return;
|
|
|
|
|
|
2022-01-17 19:24:09 +00:00
|
|
|
|
|
|
|
|
if (msg.Text.Length + Content.Length <= ContentSize)
|
|
|
|
|
Content += msg.Text + '\n';
|
2020-02-11 20:01:05 -03:00
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
if (_entMan.TryGetComponent(Owner, out AppearanceComponent? appearance))
|
2020-02-11 20:01:05 -03:00
|
|
|
{
|
2021-10-09 14:48:53 +01:00
|
|
|
appearance.SetData(PaperVisuals.Status, PaperStatus.Written);
|
2020-02-11 20:01:05 -03:00
|
|
|
}
|
|
|
|
|
|
2021-12-08 17:32:32 +01:00
|
|
|
_entMan.GetComponent<MetaDataComponent>(Owner).EntityDescription = "";
|
2020-02-11 20:01:05 -03:00
|
|
|
UpdateUserInterface();
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
2020-02-11 20:01:05 -03:00
|
|
|
{
|
2022-02-08 14:08:11 +11:00
|
|
|
if (!EntitySystem.Get<TagSystem>().HasTag(eventArgs.Using, "Write"))
|
2020-02-11 20:01:05 -03:00
|
|
|
return false;
|
2021-12-08 17:32:32 +01:00
|
|
|
if (!_entMan.TryGetComponent(eventArgs.User, out ActorComponent? actor))
|
2020-02-11 20:01:05 -03:00
|
|
|
return false;
|
|
|
|
|
|
2022-03-12 13:26:06 -05:00
|
|
|
Mode = PaperAction.Write;
|
2020-02-11 20:01:05 -03:00
|
|
|
UpdateUserInterface();
|
2021-05-12 13:42:18 +02:00
|
|
|
UserInterface?.Open(actor.PlayerSession);
|
2020-02-11 20:01:05 -03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|