Paper and pen (#582)
* A very basic paper and pen implementation * Removes SharedWriteComponent * Update ContentNetIDs.cs
This commit is contained in:
@@ -129,7 +129,9 @@ namespace Content.Client
|
|||||||
"ShuttleController",
|
"ShuttleController",
|
||||||
"HumanInventoryController",
|
"HumanInventoryController",
|
||||||
"UseDelay",
|
"UseDelay",
|
||||||
"Pourable"
|
"Pourable",
|
||||||
|
"Paper",
|
||||||
|
"Write"
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var ignoreName in registerIgnore)
|
foreach (var ignoreName in registerIgnore)
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
Content.Client/GameObjects/Components/Paper/PaperWindow.cs
Normal file
36
Content.Client/GameObjects/Components/Paper/PaperWindow.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<ServerUserInterfaceComponent>()
|
||||||
|
.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<WriteComponent>())
|
||||||
|
return false;
|
||||||
|
if (!eventArgs.User.TryGetComponent(out IActorComponent actor))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_mode = PaperAction.Write;
|
||||||
|
UpdateUserInterface();
|
||||||
|
_userInterface.Open(actor.playerSession);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,5 +39,6 @@
|
|||||||
public const uint WELDER = 1034;
|
public const uint WELDER = 1034;
|
||||||
public const uint STACK = 1035;
|
public const uint STACK = 1035;
|
||||||
public const uint HANDHELD_LIGHT = 1036;
|
public const uint HANDHELD_LIGHT = 1036;
|
||||||
|
public const uint PAPER = 1037;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
37
Resources/Prototypes/Entities/items/paper.yml
Normal file
37
Resources/Prototypes/Entities/items/paper.yml
Normal file
@@ -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
|
||||||
BIN
Resources/Textures/Objects/Misc/bureaucracy.dmi
Normal file
BIN
Resources/Textures/Objects/Misc/bureaucracy.dmi
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
Reference in New Issue
Block a user