Improve ExaminedEvent to handle newlines for you with helper methods.
This commit is contained in:
@@ -65,7 +65,7 @@ namespace Content.Client.Construction
|
|||||||
{
|
{
|
||||||
if (component.Prototype == null) return;
|
if (component.Prototype == null) return;
|
||||||
|
|
||||||
args.Message.AddMarkup(Loc.GetString(
|
args.PushMarkup(Loc.GetString(
|
||||||
"construction-ghost-examine-message",
|
"construction-ghost-examine-message",
|
||||||
("name", component.Prototype.Name)));
|
("name", component.Prototype.Name)));
|
||||||
|
|
||||||
|
|||||||
@@ -58,10 +58,9 @@ namespace Content.Server.Construction
|
|||||||
{
|
{
|
||||||
if (component.Target != null)
|
if (component.Target != null)
|
||||||
{
|
{
|
||||||
args.Message.AddMarkup(
|
args.PushMarkup(Loc.GetString(
|
||||||
Loc.GetString(
|
|
||||||
"construction-component-to-create-header",
|
"construction-component-to-create-header",
|
||||||
("targetName", component.Target.Name)) + "\n");
|
("targetName", component.Target.Name)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component.Edge == null && component.TargetNextEdge != null)
|
if (component.Edge == null && component.TargetNextEdge != null)
|
||||||
|
|||||||
@@ -59,10 +59,8 @@ namespace Content.Server.Dice
|
|||||||
private void OnExamined(EntityUid uid, DiceComponent dice, ExaminedEvent args)
|
private void OnExamined(EntityUid uid, DiceComponent dice, ExaminedEvent args)
|
||||||
{
|
{
|
||||||
//No details check, since the sprite updates to show the side.
|
//No details check, since the sprite updates to show the side.
|
||||||
args.Message.PushNewline();
|
args.PushMarkup(Loc.GetString("dice-component-on-examine-message-part-1", ("sidesAmount", dice.Sides)));
|
||||||
args.Message.AddMarkup(Loc.GetString("dice-component-on-examine-message-part-1", ("sidesAmount", dice.Sides)));
|
args.PushMarkup(Loc.GetString("dice-component-on-examine-message-part-2", ("currentSide", dice.CurrentSide)));
|
||||||
args.Message.PushNewline();
|
|
||||||
args.Message.AddMarkup(Loc.GetString("dice-component-on-examine-message-part-2", ("currentSide", dice.CurrentSide)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,15 +169,13 @@ namespace Content.Server.Flash
|
|||||||
{
|
{
|
||||||
if (!comp.HasUses)
|
if (!comp.HasUses)
|
||||||
{
|
{
|
||||||
args.Message.AddText("\n");
|
args.PushText(Loc.GetString("flash-component-examine-empty"));
|
||||||
args.Message.AddText(Loc.GetString("flash-component-examine-empty"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.IsInDetailsRange)
|
if (args.IsInDetailsRange)
|
||||||
{
|
{
|
||||||
args.Message.AddText("\n");
|
args.PushMarkup(
|
||||||
args.Message.AddMarkup(
|
|
||||||
Loc.GetString(
|
Loc.GetString(
|
||||||
"flash-component-examine-detail-count",
|
"flash-component-examine-detail-count",
|
||||||
("count", comp.Uses),
|
("count", comp.Uses),
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace Content.Server.Fluids
|
|||||||
{
|
{
|
||||||
if (ComponentManager.TryGetComponent<SlipperyComponent>(uid, out var slippery) && slippery.Slippery)
|
if (ComponentManager.TryGetComponent<SlipperyComponent>(uid, out var slippery) && slippery.Slippery)
|
||||||
{
|
{
|
||||||
args.Message.AddText(Loc.GetString("puddle-component-examine-is-slipper-text"));
|
args.PushText(Loc.GetString("puddle-component-examine-is-slipper-text"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ namespace Content.Server.Ghost
|
|||||||
? Loc.GetString("comp-ghost-examine-time-minutes", ("minutes", timeSinceDeath.Minutes))
|
? Loc.GetString("comp-ghost-examine-time-minutes", ("minutes", timeSinceDeath.Minutes))
|
||||||
: Loc.GetString("comp-ghost-examine-time-seconds", ("seconds", timeSinceDeath.Seconds));
|
: Loc.GetString("comp-ghost-examine-time-seconds", ("seconds", timeSinceDeath.Seconds));
|
||||||
|
|
||||||
args.Message.AddMarkup(deathTimeInfo);
|
args.PushMarkup(deathTimeInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMindRemovedMessage(EntityUid uid, GhostComponent component, MindRemovedMessage args)
|
private void OnMindRemovedMessage(EntityUid uid, GhostComponent component, MindRemovedMessage args)
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ namespace Content.Server.Hands
|
|||||||
{
|
{
|
||||||
foreach (var inhand in component.GetAllHeldItems())
|
foreach (var inhand in component.GetAllHeldItems())
|
||||||
{
|
{
|
||||||
args.Message.AddText($"\n{Loc.GetString("comp-hands-examine", ("user", component.Owner), ("item", inhand.Owner))}");
|
args.PushText(Loc.GetString("comp-hands-examine", ("user", component.Owner), ("item", inhand.Owner)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,8 +52,7 @@ namespace Content.Server.Lock
|
|||||||
|
|
||||||
private void OnExamined(EntityUid eUI, LockComponent lockComp, ExaminedEvent args)
|
private void OnExamined(EntityUid eUI, LockComponent lockComp, ExaminedEvent args)
|
||||||
{
|
{
|
||||||
args.Message.AddText("\n");
|
args.PushText(Loc.GetString(lockComp.Locked
|
||||||
args.Message.AddText(Loc.GetString(lockComp.Locked
|
|
||||||
? "lock-comp-on-examined-is-locked"
|
? "lock-comp-on-examined-is-locked"
|
||||||
: "lock-comp-on-examined-is-unlocked",
|
: "lock-comp-on-examined-is-unlocked",
|
||||||
("entityName", lockComp.Owner.Name)));
|
("entityName", lockComp.Owner.Name)));
|
||||||
|
|||||||
@@ -108,11 +108,10 @@ namespace Content.Server.Stunnable
|
|||||||
|
|
||||||
private void OnExamined(EntityUid uid, StunbatonComponent comp, ExaminedEvent args)
|
private void OnExamined(EntityUid uid, StunbatonComponent comp, ExaminedEvent args)
|
||||||
{
|
{
|
||||||
args.Message.AddText("\n");
|
|
||||||
var msg = comp.Activated
|
var msg = comp.Activated
|
||||||
? Loc.GetString("comp-stunbaton-examined-on")
|
? Loc.GetString("comp-stunbaton-examined-on")
|
||||||
: Loc.GetString("comp-stunbaton-examined-off");
|
: Loc.GetString("comp-stunbaton-examined-off");
|
||||||
args.Message.AddMarkup(msg);
|
args.PushMarkup(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StunEntity(IEntity entity, StunbatonComponent comp)
|
private void StunEntity(IEntity entity, StunbatonComponent comp)
|
||||||
|
|||||||
@@ -28,16 +28,16 @@ namespace Content.Server.Tools
|
|||||||
{
|
{
|
||||||
if (component.WelderLit)
|
if (component.WelderLit)
|
||||||
{
|
{
|
||||||
args.Message.AddMarkup(Loc.GetString("welder-component-on-examine-welder-lit-message") + "\n");
|
args.PushMarkup(Loc.GetString("welder-component-on-examine-welder-lit-message"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
args.Message.AddText(Loc.GetString("welder-component-on-examine-welder-not-lit-message") + "\n");
|
args.PushMarkup(Loc.GetString("welder-component-on-examine-welder-not-lit-message"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.IsInDetailsRange)
|
if (args.IsInDetailsRange)
|
||||||
{
|
{
|
||||||
args.Message.AddMarkup(Loc.GetString("welder-component-on-examine-detailed-message",
|
args.PushMarkup(Loc.GetString("welder-component-on-examine-detailed-message",
|
||||||
("colorName", component.Fuel < component.FuelCapacity / 4f ? "darkorange" : "orange"),
|
("colorName", component.Fuel < component.FuelCapacity / 4f ? "darkorange" : "orange"),
|
||||||
("fuelLeft", Math.Round(component.Fuel)),
|
("fuelLeft", Math.Round(component.Fuel)),
|
||||||
("fuelCapacity", component.FuelCapacity)));
|
("fuelCapacity", component.FuelCapacity)));
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace Content.Shared.Chemistry.EntitySystems
|
|||||||
|
|
||||||
if (solutionHolder.Contents.Count == 0)
|
if (solutionHolder.Contents.Count == 0)
|
||||||
{
|
{
|
||||||
args.Message.AddText(Loc.GetString("shared-solution-container-component-on-examine-empty-container"));
|
args.PushText(Loc.GetString("shared-solution-container-component-on-examine-empty-container"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ namespace Content.Shared.Chemistry.EntitySystems
|
|||||||
.ToHexNoAlpha(); //TODO: If the chem has a dark color, the examine text becomes black on a black background, which is unreadable.
|
.ToHexNoAlpha(); //TODO: If the chem has a dark color, the examine text becomes black on a black background, which is unreadable.
|
||||||
var messageString = "shared-solution-container-component-on-examine-main-text";
|
var messageString = "shared-solution-container-component-on-examine-main-text";
|
||||||
|
|
||||||
args.Message.AddMarkup(Loc.GetString(messageString,
|
args.PushMarkup(Loc.GetString(messageString,
|
||||||
("color", colorHex),
|
("color", colorHex),
|
||||||
("wordedAmount", Loc.GetString(solutionHolder.Contents.Count == 1
|
("wordedAmount", Loc.GetString(solutionHolder.Contents.Count == 1
|
||||||
? "shared-solution-container-component-on-examine-worded-amount-one-reagent"
|
? "shared-solution-container-component-on-examine-worded-amount-one-reagent"
|
||||||
|
|||||||
@@ -189,13 +189,15 @@ namespace Content.Shared.Examine
|
|||||||
message.PushColor(Color.DarkGray);
|
message.PushColor(Color.DarkGray);
|
||||||
|
|
||||||
// Raise the event and let things that subscribe to it change the message...
|
// Raise the event and let things that subscribe to it change the message...
|
||||||
RaiseLocalEvent(entity.Uid, new ExaminedEvent(message, entity, examiner, IsInDetailsRange(examiner, entity)));
|
var isInDetailsRange = IsInDetailsRange(examiner, entity);
|
||||||
|
var examinedEvent = new ExaminedEvent(message, entity, examiner, isInDetailsRange, doNewline);
|
||||||
|
RaiseLocalEvent(entity.Uid, examinedEvent);
|
||||||
|
|
||||||
//Add component statuses from components that report one
|
//Add component statuses from components that report one
|
||||||
foreach (var examineComponent in entity.GetAllComponents<IExamine>())
|
foreach (var examineComponent in entity.GetAllComponents<IExamine>())
|
||||||
{
|
{
|
||||||
var subMessage = new FormattedMessage();
|
var subMessage = new FormattedMessage();
|
||||||
examineComponent.Examine(subMessage, IsInDetailsRange(examiner, entity));
|
examineComponent.Examine(subMessage, isInDetailsRange);
|
||||||
if (subMessage.Tags.Count == 0)
|
if (subMessage.Tags.Count == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -214,15 +216,17 @@ namespace Content.Shared.Examine
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Raised when an entity is examined.
|
/// Raised when an entity is examined.
|
||||||
/// You have to manually add a newline at the start, and perform cleanup (popping state) at the end.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ExaminedEvent : EntityEventArgs
|
public class ExaminedEvent : EntityEventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The message that will be displayed as the examine text.
|
/// The message that will be displayed as the examine text.
|
||||||
/// Use the methods it exposes to change it, and don't forget to add a newline at the start!
|
/// For most use cases, you probably want to use <see cref="PushMarkup"/> and similar instead to modify this,
|
||||||
/// Input/Output parameter.
|
/// since it handles newlines and such correctly.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <seealso cref="PushMessage"/>
|
||||||
|
/// <seealso cref="PushMarkup"/>
|
||||||
|
/// <seealso cref="PushText"/>
|
||||||
public FormattedMessage Message { get; }
|
public FormattedMessage Message { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -240,12 +244,54 @@ namespace Content.Shared.Examine
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsInDetailsRange { get; }
|
public bool IsInDetailsRange { get; }
|
||||||
|
|
||||||
public ExaminedEvent(FormattedMessage message, IEntity examined, IEntity examiner, bool isInDetailsRange)
|
private bool _doNewLine;
|
||||||
|
|
||||||
|
public ExaminedEvent(FormattedMessage message, IEntity examined, IEntity examiner, bool isInDetailsRange, bool doNewLine)
|
||||||
{
|
{
|
||||||
Message = message;
|
Message = message;
|
||||||
Examined = examined;
|
Examined = examined;
|
||||||
Examiner = examiner;
|
Examiner = examiner;
|
||||||
IsInDetailsRange = isInDetailsRange;
|
IsInDetailsRange = isInDetailsRange;
|
||||||
|
_doNewLine = doNewLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Push another message into this examine result, on its own line.
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="PushMarkup"/>
|
||||||
|
/// <seealso cref="PushText"/>
|
||||||
|
public void PushMessage(FormattedMessage message)
|
||||||
|
{
|
||||||
|
if (message.Tags.Count == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_doNewLine)
|
||||||
|
Message.AddText("\n");
|
||||||
|
|
||||||
|
Message.AddMessage(message);
|
||||||
|
_doNewLine = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Push another message parsed from markup into this examine result, on its own line.
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="PushText"/>
|
||||||
|
/// <seealso cref="PushMessage"/>
|
||||||
|
public void PushMarkup(string markup)
|
||||||
|
{
|
||||||
|
PushMessage(FormattedMessage.FromMarkup(markup));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Push another message containing raw text into this examine result, on its own line.
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="PushMarkup"/>
|
||||||
|
/// <seealso cref="PushMessage"/>
|
||||||
|
public void PushText(string text)
|
||||||
|
{
|
||||||
|
var msg = new FormattedMessage();
|
||||||
|
msg.AddText(text);
|
||||||
|
PushMessage(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,8 +100,7 @@ namespace Content.Shared.Stacks
|
|||||||
if (!args.IsInDetailsRange)
|
if (!args.IsInDetailsRange)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
args.Message.AddText("\n");
|
args.PushMarkup(
|
||||||
args.Message.AddMarkup(
|
|
||||||
Loc.GetString("comp-stack-examine-detail-count",
|
Loc.GetString("comp-stack-examine-detail-count",
|
||||||
("count", component.Count),
|
("count", component.Count),
|
||||||
("markupCountColor", "lightgray")
|
("markupCountColor", "lightgray")
|
||||||
|
|||||||
Reference in New Issue
Block a user