diff --git a/Content.Client/EntryPoint.cs b/Content.Client/EntryPoint.cs index 85ba2ba59c..7ed60563b9 100644 --- a/Content.Client/EntryPoint.cs +++ b/Content.Client/EntryPoint.cs @@ -129,7 +129,9 @@ namespace Content.Client "ShuttleController", "HumanInventoryController", "UseDelay", - "Pourable" + "Pourable", + "Paper", + "Write" }; foreach (var ignoreName in registerIgnore) diff --git a/Content.Client/GameObjects/Components/Paper/PaperBoundUserInterface.cs b/Content.Client/GameObjects/Components/Paper/PaperBoundUserInterface.cs new file mode 100644 index 0000000000..b064d7519c --- /dev/null +++ b/Content.Client/GameObjects/Components/Paper/PaperBoundUserInterface.cs @@ -0,0 +1,44 @@ +using Content.Shared.GameObjects.Components; +using Robust.Client.GameObjects.Components.UserInterface; +using Robust.Client.UserInterface.Controls; +using Robust.Shared.GameObjects.Components.UserInterface; + +namespace Content.Client.GameObjects.Components +{ + public class PaperBoundUserInterface : BoundUserInterface + { + private PaperWindow _window; + + public PaperBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey) + { + } + + protected override void Open() + { + base.Open(); + _window = new PaperWindow + { + Title = Owner.Owner.Name, + }; + _window.OnClose += Close; + _window.Input.OnTextEntered += Input_OnTextEntered; + _window.OpenCentered(); + + } + + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + _window.Populate((SharedPaperComponent.PaperBoundUserInterfaceState)state); + } + + private void Input_OnTextEntered(LineEdit.LineEditEventArgs obj) + { + if(!string.IsNullOrEmpty(obj.Text)) + { + SendMessage(new SharedPaperComponent.PaperInputText(obj.Text)); + _window.Input.Text = string.Empty; + } + } + } +} diff --git a/Content.Client/GameObjects/Components/Paper/PaperWindow.cs b/Content.Client/GameObjects/Components/Paper/PaperWindow.cs new file mode 100644 index 0000000000..2762625832 --- /dev/null +++ b/Content.Client/GameObjects/Components/Paper/PaperWindow.cs @@ -0,0 +1,36 @@ +using Content.Shared.GameObjects.Components; +using Robust.Client.UserInterface.Controls; +using Robust.Client.UserInterface.CustomControls; +using Robust.Shared.Maths; +using Robust.Shared.Utility; + +namespace Content.Client.GameObjects.Components +{ + public class PaperWindow : SS14Window + { + private readonly RichTextLabel _label; + public readonly LineEdit Input; + protected override Vector2? CustomSize => (300, 300); + + public PaperWindow() + { + var container = new VBoxContainer(); + _label = new RichTextLabel(); + Input = new LineEdit {Visible = false}; + container.AddChild(_label); + container.AddChild(Input); + Contents.AddChild(container); + } + + public void Populate(SharedPaperComponent.PaperBoundUserInterfaceState state) + { + if (state.Mode == SharedPaperComponent.PaperAction.Write) + { + Input.Visible = true; + } + var msg = new FormattedMessage(); + msg.AddMarkup(state.Text); + _label.SetMessage(msg); + } + } +} diff --git a/Content.Server/GameObjects/Components/Paper/PaperComponent.cs b/Content.Server/GameObjects/Components/Paper/PaperComponent.cs new file mode 100644 index 0000000000..9c29df3cde --- /dev/null +++ b/Content.Server/GameObjects/Components/Paper/PaperComponent.cs @@ -0,0 +1,78 @@ +using Content.Server.GameObjects.EntitySystems; +using Content.Shared.GameObjects.Components; +using Robust.Server.GameObjects; +using Robust.Server.GameObjects.Components.UserInterface; +using Robust.Server.Interfaces.GameObjects; +using Robust.Shared.GameObjects; +using Robust.Shared.Utility; + +namespace Content.Server.GameObjects.Components.Interactable +{ + [RegisterComponent] + public class PaperComponent : SharedPaperComponent, IExamine, IAttackBy, IUse + { + + private BoundUserInterface _userInterface; + private string _content; + private PaperAction _mode; + + public override void Initialize() + { + base.Initialize(); + _userInterface = Owner.GetComponent() + .GetBoundUserInterface(PaperUiKey.Key); + _userInterface.OnReceiveMessage += OnUiReceiveMessage; + _content = ""; + _mode = PaperAction.Read; + UpdateUserInterface(); + } + private void UpdateUserInterface() + { + _userInterface.SetState(new PaperBoundUserInterfaceState(_content, _mode)); + } + + public void Examine(FormattedMessage message) + { + message.AddMarkup(_content); + } + + public bool UseEntity(UseEntityEventArgs eventArgs) + { + if (!eventArgs.User.TryGetComponent(out IActorComponent actor)) + return false; + _mode = PaperAction.Read; + UpdateUserInterface(); + _userInterface.Open(actor.playerSession); + return true; + } + + private void OnUiReceiveMessage(ServerBoundUserInterfaceMessage obj) + { + var msg = (PaperInputText) obj.Message; + if (string.IsNullOrEmpty(msg.Text)) + return; + + _content += msg.Text + '\n'; + + if (Owner.TryGetComponent(out SpriteComponent sprite)) + { + sprite.LayerSetState(0, "paper_words"); + } + + UpdateUserInterface(); + } + + public bool AttackBy(AttackByEventArgs eventArgs) + { + if (!eventArgs.AttackWith.HasComponent()) + return false; + if (!eventArgs.User.TryGetComponent(out IActorComponent actor)) + return false; + + _mode = PaperAction.Write; + UpdateUserInterface(); + _userInterface.Open(actor.playerSession); + return true; + } + } +} diff --git a/Content.Server/GameObjects/Components/Paper/WriteComponent.cs b/Content.Server/GameObjects/Components/Paper/WriteComponent.cs new file mode 100644 index 0000000000..d154a388fc --- /dev/null +++ b/Content.Server/GameObjects/Components/Paper/WriteComponent.cs @@ -0,0 +1,11 @@ +using Content.Shared.GameObjects.Components; +using Robust.Shared.GameObjects; + +namespace Content.Server.GameObjects.Components.Interactable +{ + [RegisterComponent] + public class WriteComponent : Component + { + public override string Name => "Write"; + } +} diff --git a/Content.Shared/GameObjects/Components/SharedPaperComponent.cs b/Content.Shared/GameObjects/Components/SharedPaperComponent.cs new file mode 100644 index 0000000000..71b4317d9c --- /dev/null +++ b/Content.Shared/GameObjects/Components/SharedPaperComponent.cs @@ -0,0 +1,63 @@ +using System; +using System.Net.Mime; +using Robust.Shared.GameObjects; +using Robust.Shared.GameObjects.Components.UserInterface; +using Robust.Shared.Serialization; + +namespace Content.Shared.GameObjects.Components +{ + public class SharedPaperComponent : Component + { + public override string Name => "Paper"; + + [Serializable, NetSerializable] + public class PaperBoundUserInterfaceState : BoundUserInterfaceState + { + public readonly string Text; + public readonly PaperAction Mode; + + public PaperBoundUserInterfaceState(string text, PaperAction mode = PaperAction.Read) + { + Text = text; + Mode = mode; + } + } + + [Serializable, NetSerializable] + public class PaperActionMessage : BoundUserInterfaceMessage + { + public readonly PaperAction Action; + public PaperActionMessage(PaperAction action) + { + Action = action; + } + } + + [Serializable, NetSerializable] + public class PaperInputText : BoundUserInterfaceMessage + { + public readonly string Text; + + public PaperInputText(string text) + { + Text = text; + } + } + + [Serializable, NetSerializable] + public enum PaperUiKey + { + Key + } + + [Serializable, NetSerializable] + public enum PaperAction + { + Read, + Write, + CrossOut, + Stamp + } + + } +} diff --git a/Content.Shared/GameObjects/ContentNetIDs.cs b/Content.Shared/GameObjects/ContentNetIDs.cs index f47007a8b1..bb3f1c6400 100644 --- a/Content.Shared/GameObjects/ContentNetIDs.cs +++ b/Content.Shared/GameObjects/ContentNetIDs.cs @@ -39,5 +39,6 @@ public const uint WELDER = 1034; public const uint STACK = 1035; public const uint HANDHELD_LIGHT = 1036; + public const uint PAPER = 1037; } } diff --git a/Resources/Prototypes/Entities/items/paper.yml b/Resources/Prototypes/Entities/items/paper.yml new file mode 100644 index 0000000000..48cef161f0 --- /dev/null +++ b/Resources/Prototypes/Entities/items/paper.yml @@ -0,0 +1,37 @@ +- type: entity + name: Paper + parent: BaseItem + id: Paper + description: '' + components: + - type: Sprite + sprite: Objects/Misc/bureaucracy.rsi + state: paper + - type: Icon + sprite: Objects/Misc/bureaucracy.rsi + state: paper + - type: Item + sprite: Objects/Misc/bureaucracy.rsi + state: paper + - type: Paper + - type: UserInterface + interfaces: + - key: enum.PaperUiKey.Key + type: PaperBoundUserInterface + +- type: entity + name: Pen + parent: BaseItem + id: Pen + description: 'A dark ink pen' + components: + - type: Sprite + sprite: Objects/Misc/bureaucracy.rsi + state: pen + - type: Icon + sprite: Objects/Misc/bureaucracy.rsi + state: pen + - type: Item + sprite: Objects/Misc/bureaucracy.rsi + state: pen + - type: Write diff --git a/Resources/Textures/Objects/Misc/bureaucracy.dmi b/Resources/Textures/Objects/Misc/bureaucracy.dmi new file mode 100644 index 0000000000..41e890e983 Binary files /dev/null and b/Resources/Textures/Objects/Misc/bureaucracy.dmi differ