Everything: Rich text redux (#5625)

* lord save me

* UI/ChatBox: Use the new `defStyle` param for `RenderMarkup`

The previous iteration didn't work because `AddMessage` can't inherit
its color from the PushColor (since we're not doing actual tag stacks
anymore).

* rebase touchup
This commit is contained in:
E F R
2021-12-13 02:25:42 +00:00
committed by GitHub
parent 7c31964613
commit b2da936848
61 changed files with 305 additions and 214 deletions

View File

@@ -36,13 +36,13 @@ namespace Content.Shared.Actions.Prototypes
/// Name to show in UI. Accepts formatting.
/// </summary>
[DataField("name")]
public FormattedMessage Name { get; private set; } = new();
public FormattedMessage Name { get; private set; } = FormattedMessage.Empty;
/// <summary>
/// Description to show in UI. Accepts formatting.
/// </summary>
[DataField("description")]
public FormattedMessage Description { get; } = new();
public FormattedMessage Description { get; } = FormattedMessage.Empty;
/// <summary>
/// Requirements message to show in UI. Accepts formatting, but generally should be avoided
@@ -101,8 +101,10 @@ namespace Content.Shared.Actions.Prototypes
public virtual void AfterDeserialization()
{
Name = new FormattedMessage();
Name.AddText(ID);
Name = new FormattedMessage(new []
{
new Section {Content=ID}
});
if (BehaviorType == BehaviorType.None)
{

View File

@@ -39,13 +39,13 @@ namespace Content.Shared.Alert
/// Name to show in tooltip window. Accepts formatting.
/// </summary>
[DataField("name")]
public FormattedMessage Name { get; private set; } = new();
public FormattedMessage Name { get; private set; } = FormattedMessage.Empty;
/// <summary>
/// Description to show in tooltip window. Accepts formatting.
/// </summary>
[DataField("description")]
public FormattedMessage Description { get; private set; } = new();
public FormattedMessage Description { get; private set; } = FormattedMessage.Empty;
/// <summary>
/// Category the alert belongs to. Only one alert of a given category

View File

@@ -2,6 +2,7 @@
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility;
using Robust.Shared.Utility.Markup;
namespace Content.Shared.Construction.Steps
{
@@ -16,7 +17,7 @@ namespace Content.Shared.Construction.Steps
if (string.IsNullOrEmpty(Name))
return;
examinedEvent.Message.AddMarkup(Loc.GetString("construction-insert-arbitrary-entity", ("stepName", Name)));
examinedEvent.Message.AddMessage(Basic.RenderMarkup(Loc.GetString("construction-insert-arbitrary-entity", ("stepName", Name))));
}
public override ConstructionGuideEntry GenerateGuideEntry()

View File

@@ -2,6 +2,7 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility.Markup;
namespace Content.Shared.Construction.Steps
{
@@ -23,13 +24,15 @@ namespace Content.Shared.Construction.Steps
public override void DoExamine(ExaminedEvent examinedEvent)
{
examinedEvent.Message.AddMarkup(string.IsNullOrEmpty(Name)
? Loc.GetString(
"construction-insert-entity-with-component",
("componentName", Component))// Terrible.
: Loc.GetString(
"construction-insert-exact-entity",
("entityName", Name)));
examinedEvent.Message.AddMessage(
Basic.RenderMarkup(string.IsNullOrEmpty(Name)
? Loc.GetString(
"construction-insert-entity-with-component",
("componentName", Component))// Terrible.
: Loc.GetString(
"construction-insert-exact-entity",
("entityName", Name))
));
}
}
}

View File

@@ -7,6 +7,7 @@ using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Utility.Markup;
namespace Content.Shared.Construction.Steps
{
@@ -24,7 +25,7 @@ namespace Content.Shared.Construction.Steps
{
var material = IoCManager.Resolve<IPrototypeManager>().Index<StackPrototype>(MaterialPrototypeId);
examinedEvent.Message.AddMarkup(Loc.GetString("construction-insert-material-entity", ("amount", Amount), ("materialName", material.Name)));
examinedEvent.Message.AddMessage(Basic.RenderMarkup(Loc.GetString("construction-insert-material-entity", ("amount", Amount), ("materialName", material.Name))));
}
public override bool EntityValid(EntityUid uid, IEntityManager entityManager)

View File

@@ -2,6 +2,7 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Utility.Markup;
namespace Content.Shared.Construction.Steps
{
@@ -17,7 +18,8 @@ namespace Content.Shared.Construction.Steps
public override void DoExamine(ExaminedEvent examinedEvent)
{
examinedEvent.Message.AddMarkup(string.IsNullOrEmpty(Name)
var nb = new Basic();
nb.AddMarkup(string.IsNullOrEmpty(Name)
? Loc.GetString(
"construction-insert-prototype-no-name",
("prototypeName", Prototype) // Terrible.
@@ -26,6 +28,8 @@ namespace Content.Shared.Construction.Steps
"construction-insert-prototype",
("entityName", Name)
));
examinedEvent.Message.AddMessage(nb.Render());
}
}
}

View File

@@ -13,6 +13,7 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Utility;
using Robust.Shared.Utility.Markup;
using static Content.Shared.Interaction.SharedInteractionSystem;
namespace Content.Shared.Examine
@@ -25,7 +26,7 @@ namespace Content.Shared.Examine
/// </summary>
/// <param name="message">The message to append to which will be displayed.</param>
/// <param name="inDetailsRange">Whether the examiner is within the 'Details' range, allowing you to show information logically only availabe when close to the examined entity.</param>
void Examine(FormattedMessage message, bool inDetailsRange);
void Examine(FormattedMessage.Builder message, bool inDetailsRange);
}
public abstract class ExamineSystemShared : EntitySystem
@@ -212,11 +213,11 @@ namespace Content.Shared.Examine
public FormattedMessage GetExamineText(EntityUid entity, EntityUid? examiner)
{
var message = new FormattedMessage();
var message = new FormattedMessage.Builder();
if (examiner == null)
{
return message;
return new(new Section[] {});
}
var doNewline = false;
@@ -238,21 +239,15 @@ namespace Content.Shared.Examine
//Add component statuses from components that report one
foreach (var examineComponent in EntityManager.GetComponents<IExamine>(entity))
{
var subMessage = new FormattedMessage();
examineComponent.Examine(subMessage, isInDetailsRange);
if (subMessage.Tags.Count == 0)
continue;
examineComponent.Examine(message, isInDetailsRange);
if (doNewline)
message.AddText("\n");
message.AddMessage(subMessage);
doNewline = true;
}
message.Pop();
return message;
return message.Build();
}
}
@@ -269,7 +264,7 @@ namespace Content.Shared.Examine
/// <seealso cref="PushMessage"/>
/// <seealso cref="PushMarkup"/>
/// <seealso cref="PushText"/>
public FormattedMessage Message { get; }
public FormattedMessage.Builder Message { get; }
/// <summary>
/// The entity performing the examining.
@@ -288,7 +283,7 @@ namespace Content.Shared.Examine
private bool _doNewLine;
public ExaminedEvent(FormattedMessage message, EntityUid examined, EntityUid examiner, bool isInDetailsRange, bool doNewLine)
public ExaminedEvent(FormattedMessage.Builder message, EntityUid examined, EntityUid examiner, bool isInDetailsRange, bool doNewLine)
{
Message = message;
Examined = examined;
@@ -304,9 +299,6 @@ namespace Content.Shared.Examine
/// <seealso cref="PushText"/>
public void PushMessage(FormattedMessage message)
{
if (message.Tags.Count == 0)
return;
if (_doNewLine)
Message.AddText("\n");
@@ -321,7 +313,7 @@ namespace Content.Shared.Examine
/// <seealso cref="PushMessage"/>
public void PushMarkup(string markup)
{
PushMessage(FormattedMessage.FromMarkup(markup));
PushMessage(Basic.RenderMarkup(markup));
}
/// <summary>
@@ -329,11 +321,6 @@ namespace Content.Shared.Examine
/// </summary>
/// <seealso cref="PushMarkup"/>
/// <seealso cref="PushMessage"/>
public void PushText(string text)
{
var msg = new FormattedMessage();
msg.AddText(text);
PushMessage(msg);
}
public void PushText(string text) => Message.AddText(text);
}
}