IExamine can now limit certain details behind a 'details' range check. (#1039)

* IExamine can now limit certain details behind a 'details' range check.

* Comic's Review fixes.
- colour -> color. My ancestors are saddened by this.
- Can see wire panel opened/closed at any distance again.
This commit is contained in:
Remie Richards
2020-05-31 19:29:06 +01:00
committed by GitHub
parent a9a43f25ce
commit 2e38c194f7
15 changed files with 73 additions and 35 deletions

View File

@@ -266,7 +266,7 @@ namespace Content.Server.GameObjects.Components.Chemistry
} }
} }
void IExamine.Examine(FormattedMessage message) void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{ {
if (NoExamine) if (NoExamine)
{ {
@@ -281,10 +281,29 @@ namespace Content.Server.GameObjects.Components.Chemistry
foreach (var reagent in ReagentList) foreach (var reagent in ReagentList)
{ {
if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto)) if (_prototypeManager.TryIndex(reagent.ReagentId, out ReagentPrototype proto))
{
if (inDetailsRange)
{ {
message.AddText($"{proto.Name}: {reagent.Quantity}u\n"); message.AddText($"{proto.Name}: {reagent.Quantity}u\n");
} }
else else
{
//This is trash but it shows the general idea
var color = proto.SubstanceColor;
var colorIsh = "Red";
if (color.G > color.R)
{
colorIsh = "Green";
}
if (color.B > color.G && color.B > color.R)
{
colorIsh = "Blue";
}
message.AddText(_loc.GetString("A {0} liquid\n", colorIsh));
}
}
else
{ {
message.AddText(_loc.GetString("Unknown reagent: {0}u\n", reagent.Quantity)); message.AddText(_loc.GetString("Unknown reagent: {0}u\n", reagent.Quantity));
} }

View File

@@ -76,7 +76,7 @@ namespace Content.Server.GameObjects.Components.Interactable
return true; return true;
} }
void IExamine.Examine(FormattedMessage message) void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{ {
var loc = IoCManager.Resolve<ILocalizationManager>(); var loc = IoCManager.Resolve<ILocalizationManager>();

View File

@@ -163,7 +163,7 @@ namespace Content.Server.GameObjects.Components.Interactable
return ToggleWelderStatus(eventArgs.User); return ToggleWelderStatus(eventArgs.User);
} }
public void Examine(FormattedMessage message) public void Examine(FormattedMessage message, bool inDetailsRange)
{ {
if (WelderLit) if (WelderLit)
{ {
@@ -174,9 +174,12 @@ namespace Content.Server.GameObjects.Components.Interactable
message.AddText(Loc.GetString("Not lit\n")); message.AddText(Loc.GetString("Not lit\n"));
} }
if (inDetailsRange)
{
message.AddMarkup(Loc.GetString("Fuel: [color={0}]{1}/{2}[/color].", message.AddMarkup(Loc.GetString("Fuel: [color={0}]{1}/{2}[/color].",
Fuel < FuelCapacity / 4f ? "darkorange" : "orange", Math.Round(Fuel), FuelCapacity)); Fuel < FuelCapacity / 4f ? "darkorange" : "orange", Math.Round(Fuel), FuelCapacity));
} }
}
public void OnUpdate(float frameTime) public void OnUpdate(float frameTime)
{ {

View File

@@ -1,4 +1,4 @@
using Content.Server.GameObjects.Components.Sound; using Content.Server.GameObjects.Components.Sound;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Server.Utility; using Content.Server.Utility;
using Content.Shared.Audio; using Content.Shared.Audio;
@@ -84,8 +84,9 @@ namespace Content.Server.GameObjects.Components.Items
Roll(); Roll();
} }
void IExamine.Examine(FormattedMessage message) void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{ {
//No details check, since the sprite updates to show the side.
var loc = IoCManager.Resolve<ILocalizationManager>(); var loc = IoCManager.Resolve<ILocalizationManager>();
message.AddMarkup(loc.GetString("A dice with [color=lightgray]{0}[/color] sides.\n" + message.AddMarkup(loc.GetString("A dice with [color=lightgray]{0}[/color] sides.\n" +
"It has landed on a [color=white]{1}[/color].", _sides, _currentSide)); "It has landed on a [color=white]{1}[/color].", _sides, _currentSide));

View File

@@ -1,4 +1,4 @@
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
@@ -21,7 +21,7 @@ namespace Content.Server.GameObjects.Components.Markers
serializer.DataField(this, x => x.Location, "location", null); serializer.DataField(this, x => x.Location, "location", null);
} }
public void Examine(FormattedMessage message) public void Examine(FormattedMessage message, bool inDetailsRange)
{ {
var loc = Location == null ? "<null>" : $"'{Location}'"; var loc = Location == null ? "<null>" : $"'{Location}'";
message.AddText(Loc.GetString("This one's location ID is {0}", loc)); message.AddText(Loc.GetString("This one's location ID is {0}", loc));

View File

@@ -114,9 +114,9 @@ namespace Content.Server.GameObjects.Components.Mobs
serializer.DataField(ref _showExamineInfo, "show_examine_info", false); serializer.DataField(ref _showExamineInfo, "show_examine_info", false);
} }
public void Examine(FormattedMessage message) public void Examine(FormattedMessage message, bool inDetailsRange)
{ {
if (!ShowExamineInfo) if (!ShowExamineInfo || !inDetailsRange)
return; return;
var dead = false; var dead = false;

View File

@@ -1,4 +1,4 @@
using System; using System;
using Content.Server.GameObjects.Components.Chemistry; using Content.Server.GameObjects.Components.Chemistry;
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Audio; using Content.Shared.Audio;
@@ -106,9 +106,9 @@ namespace Content.Server.GameObjects.Components.Nutrition
TryUseDrink(eventArgs.Target); TryUseDrink(eventArgs.Target);
} }
public void Examine(FormattedMessage message) public void Examine(FormattedMessage message, bool inDetailsRange)
{ {
if (!Opened) if (!Opened || !inDetailsRange)
{ {
return; return;
} }

View File

@@ -32,8 +32,11 @@ namespace Content.Server.GameObjects.Components.Interactable
_userInterface.SetState(new PaperBoundUserInterfaceState(_content, _mode)); _userInterface.SetState(new PaperBoundUserInterfaceState(_content, _mode));
} }
public void Examine(FormattedMessage message) public void Examine(FormattedMessage message, bool inDetailsRange)
{ {
if (!inDetailsRange)
return;
message.AddMarkup(_content); message.AddMarkup(_content);
} }

View File

@@ -221,11 +221,11 @@ namespace Content.Server.GameObjects.Components.Power
} }
} }
void IExamine.Examine(FormattedMessage message) void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{ {
var loc = IoCManager.Resolve<ILocalizationManager>(); var loc = IoCManager.Resolve<ILocalizationManager>();
if (!Powered) if (!Powered && inDetailsRange)
{ {
message.AddMarkup(loc.GetString("The device is [color=orange]not powered[/color].")); message.AddMarkup(loc.GetString("The device is [color=orange]not powered[/color]."));
} }

View File

@@ -166,7 +166,7 @@ namespace Content.Server.GameObjects.Components.Power
} }
/// <inheritdoc /> /// <inheritdoc />
public void Examine(FormattedMessage message) public void Examine(FormattedMessage message, bool inDetailsRange)
{ {
var loc = IoCManager.Resolve<ILocalizationManager>(); var loc = IoCManager.Resolve<ILocalizationManager>();

View File

@@ -110,7 +110,9 @@ namespace Content.Server.GameObjects.Components.Stack
return false; return false;
} }
void IExamine.Examine(FormattedMessage message) void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{
if (inDetailsRange)
{ {
var loc = IoCManager.Resolve<ILocalizationManager>(); var loc = IoCManager.Resolve<ILocalizationManager>();
message.AddMarkup(loc.GetPluralString( message.AddMarkup(loc.GetPluralString(
@@ -119,3 +121,4 @@ namespace Content.Server.GameObjects.Components.Stack
} }
} }
} }
}

View File

@@ -139,7 +139,7 @@ namespace Content.Server.GameObjects.Components.VendingMachines
} }
} }
public void Examine(FormattedMessage message) public void Examine(FormattedMessage message, bool inDetailsRange)
{ {
if(_description == null) { return; } if(_description == null) { return; }
message.AddText(_description); message.AddText(_description);

View File

@@ -226,7 +226,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Melee
EntitySystem.Get<AudioSystem>().Play("/Audio/items/weapons/pistol_magout.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f)); EntitySystem.Get<AudioSystem>().Play("/Audio/items/weapons/pistol_magout.ogg", Owner.Transform.GridPosition, AudioHelpers.WithVariation(0.25f));
} }
public void Examine(FormattedMessage message) public void Examine(FormattedMessage message, bool inDetailsRange)
{ {
var loc = IoCManager.Resolve<ILocalizationManager>(); var loc = IoCManager.Resolve<ILocalizationManager>();

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Content.Server.GameObjects.Components.Interactable; using Content.Server.GameObjects.Components.Interactable;
@@ -479,7 +479,7 @@ namespace Content.Server.GameObjects.Components
return true; return true;
} }
void IExamine.Examine(FormattedMessage message) void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{ {
var loc = IoCManager.Resolve<ILocalizationManager>(); var loc = IoCManager.Resolve<ILocalizationManager>();

View File

@@ -1,7 +1,9 @@
using Content.Shared.GameObjects.EntitySystemMessages; using Content.Server.Utility;
using Content.Shared.GameObjects.EntitySystemMessages;
using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems;
using Robust.Server.Interfaces.Player; using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Maths; using Robust.Shared.Maths;
@@ -12,9 +14,10 @@ namespace Content.Server.GameObjects.EntitySystems
public interface IExamine public interface IExamine
{ {
/// <summary> /// <summary>
/// Returns an status examine value for components appended to the end of the description of the entity /// Returns a status examine value for components appended to the end of the description of the entity
/// </summary> /// </summary>
void Examine(FormattedMessage message); /// <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);
} }
public class ExamineSystem : ExamineSystemShared public class ExamineSystem : ExamineSystemShared
@@ -25,6 +28,8 @@ namespace Content.Server.GameObjects.EntitySystems
private static readonly FormattedMessage _entityNotFoundMessage; private static readonly FormattedMessage _entityNotFoundMessage;
private const float ExamineDetailsRange = 3f;
static ExamineSystem() static ExamineSystem()
{ {
_entityNotFoundMessage = new FormattedMessage(); _entityNotFoundMessage = new FormattedMessage();
@@ -40,7 +45,7 @@ namespace Content.Server.GameObjects.EntitySystems
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
} }
private static FormattedMessage GetExamineText(IEntity entity) private static FormattedMessage GetExamineText(IEntity entity, IEntity examiner)
{ {
var message = new FormattedMessage(); var message = new FormattedMessage();
@@ -55,11 +60,15 @@ namespace Content.Server.GameObjects.EntitySystems
message.PushColor(Color.DarkGray); message.PushColor(Color.DarkGray);
var inDetailsRange = Get<SharedInteractionSystem>()
.InRangeUnobstructed(examiner.Transform.MapPosition, entity.Transform.MapPosition,
ExamineDetailsRange, predicate: entity0 => entity0 == examiner || entity0 == entity, insideBlockerValid: true);
//Add component statuses from components that report one //Add component statuses from components that report one
foreach (var examineComponents in entity.GetAllComponents<IExamine>()) foreach (var examineComponent in entity.GetAllComponents<IExamine>())
{ {
var subMessage = new FormattedMessage(); var subMessage = new FormattedMessage();
examineComponents.Examine(subMessage); examineComponent.Examine(subMessage, inDetailsRange);
if (subMessage.Tags.Count == 0) if (subMessage.Tags.Count == 0)
continue; continue;
@@ -91,7 +100,7 @@ namespace Content.Server.GameObjects.EntitySystems
return; return;
} }
var text = GetExamineText(entity); var text = GetExamineText(entity, player.AttachedEntity);
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(request.EntityUid, text), channel); RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(request.EntityUid, text), channel);
} }
} }