Make examine use tooltips. (#189)

FANCY.
This commit is contained in:
Pieter-Jan Briers
2019-04-09 17:33:53 +02:00
committed by GitHub
parent e4676395c0
commit c283634efb
12 changed files with 283 additions and 48 deletions

View File

@@ -7,6 +7,7 @@ using SS14.Server.GameObjects.Components.Container;
using SS14.Shared.Enums;
using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Utility;
using SS14.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Interactable
@@ -53,11 +54,12 @@ namespace Content.Server.GameObjects.Components.Interactable
return _cellContainer.Insert(eventArgs.AttackWith);
}
string IExamine.Examine()
void IExamine.Examine(FormattedMessage message)
{
if (Activated) return "The light is currently on.";
return null;
if (Activated)
{
message.AddText("The light is currently on.");
}
}
bool IUse.UseEntity(UseEntityEventArgs eventArgs)

View File

@@ -1,9 +1,11 @@
using System;
using System.Text;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Utility;
using YamlDotNet.RepresentationModel;
using SS14.Server.GameObjects;
using Content.Server.GameObjects.EntitySystems;
using SS14.Shared.Maths;
using SS14.Shared.Serialization;
using SS14.Shared.ViewVariables;
@@ -145,13 +147,22 @@ namespace Content.Server.GameObjects.Components.Interactable.Tools
}
}
string IExamine.Examine()
void IExamine.Examine(FormattedMessage message)
{
if (Activated)
{
return "The welding tool is currently lit";
message.PushColor(Color.Orange);
message.AddText("Lit\n");
message.Pop();
}
return null;
else
{
message.AddText("Not lit\n");
}
message.AddText("Fuel: ");
message.PushColor(Fuel < FuelCapacity / 4f ? Color.DarkOrange : Color.Orange);
message.AddText($"{Math.Round(Fuel)}/{FuelCapacity}");
message.Pop();
}
}
}

View File

@@ -181,13 +181,12 @@ namespace Content.Server.GameObjects.Components.Power
serializer.DataField(ref _priority, "priority", Powernet.Priority.Medium);
}
string IExamine.Examine()
void IExamine.Examine(FormattedMessage message)
{
if (!Powered)
{
return "The device is not powered";
message.AddText("The device is not powered");
}
return null;
}
private void UpdateLoad(float value)

View File

@@ -4,6 +4,7 @@ using SS14.Shared.GameObjects;
using SS14.Shared.Interfaces.Reflection;
using SS14.Shared.IoC;
using SS14.Shared.Serialization;
using SS14.Shared.Utility;
using SS14.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Stack
@@ -113,9 +114,9 @@ namespace Content.Server.GameObjects.Components.Stack
return false;
}
public string Examine()
void IExamine.Examine(FormattedMessage message)
{
return $"There are {Count} things in the stack.";
message.AddText($"There are {Count} things in the stack.");
}
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Text;
using Content.Shared.GameObjects.EntitySystemMessages;
using Content.Shared.Input;
using SS14.Server.GameObjects.EntitySystems;
using SS14.Server.Interfaces.Chat;
@@ -7,11 +8,15 @@ using SS14.Server.Interfaces.Player;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.Systems;
using SS14.Shared.Input;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.GameObjects.Components;
using SS14.Shared.Interfaces.Network;
using SS14.Shared.IoC;
using SS14.Shared.Log;
using SS14.Shared.Map;
using SS14.Shared.Maths;
using SS14.Shared.Players;
using SS14.Shared.Utility;
namespace Content.Server.GameObjects.EntitySystems
{
@@ -20,63 +25,89 @@ namespace Content.Server.GameObjects.EntitySystems
/// <summary>
/// Returns an status examine value for components appended to the end of the description of the entity
/// </summary>
/// <returns></returns>
string Examine();
void Examine(FormattedMessage message);
}
public class ExamineSystem : EntitySystem
{
/// <inheritdoc />
public override void Initialize()
#pragma warning disable 649
[Dependency] private IEntityManager _entityManager;
#pragma warning restore 649
private static readonly FormattedMessage _entityNotFoundMessage;
static ExamineSystem()
{
var inputSys = EntitySystemManager.GetEntitySystem<InputSystem>();
inputSys.BindMap.BindFunction(ContentKeyFunctions.ExamineEntity, new PointerInputCmdHandler(HandleExamine));
_entityNotFoundMessage = new FormattedMessage();
_entityNotFoundMessage.AddText("That entity doesn't exist");
}
private void HandleExamine(ICommonSession session, GridCoordinates coords, EntityUid uid)
public override void Initialize()
{
if (!(session is IPlayerSession svSession))
return;
base.Initialize();
var playerEnt = svSession.AttachedEntity;
if (!EntityManager.TryGetEntity(uid, out var examined))
return;
IoCManager.InjectDependencies(this);
}
//Verify player has a transform component
if (!playerEnt.TryGetComponent<ITransformComponent>(out var playerTransform))
{
return;
}
public override void RegisterMessageTypes()
{
base.RegisterMessageTypes();
//Verify player is on the same map as the entity he clicked on
if (coords.MapID != playerTransform.MapID)
{
Logger.WarningS("sys.examine", $"Player named {session.Name} clicked on a map he isn't located on");
return;
}
RegisterMessageType<ExamineSystemMessages.RequestExamineInfoMessage>();
}
//Start a StringBuilder since we have no idea how many times this could be appended to
var fullExamineText = new StringBuilder("This is " + examined.Name);
private FormattedMessage GetExamineText(IEntity entity)
{
var message = new FormattedMessage();
var doNewline = false;
//Add an entity description if one is declared
if (!string.IsNullOrEmpty(examined.Description))
if (!string.IsNullOrEmpty(entity.Description))
{
fullExamineText.Append(Environment.NewLine + examined.Description);
message.AddText(entity.Description);
doNewline = true;
}
message.PushColor(Color.DarkGray);
var subMessage = new FormattedMessage();
//Add component statuses from components that report one
foreach (var examineComponents in examined.GetAllComponents<IExamine>())
foreach (var examineComponents in entity.GetAllComponents<IExamine>())
{
var componentDescription = examineComponents.Examine();
if (string.IsNullOrEmpty(componentDescription))
examineComponents.Examine(subMessage);
if (subMessage.Tags.Count == 0)
continue;
fullExamineText.Append(Environment.NewLine);
fullExamineText.Append(componentDescription);
if (doNewline)
{
message.AddText("\n");
doNewline = false;
}
message.AddMessage(subMessage);
}
//Send to client chat channel
IoCManager.Resolve<IChatManager>().DispatchMessage(svSession.ConnectedClient, SS14.Shared.Console.ChatChannel.Visual, fullExamineText.ToString(), session.SessionId);
message.Pop();
return message;
}
public override void HandleNetMessage(INetChannel channel, EntitySystemMessage message)
{
base.HandleNetMessage(channel, message);
if (message is ExamineSystemMessages.RequestExamineInfoMessage request)
{
if (!_entityManager.TryGetEntity(request.EntityUid, out var entity))
{
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(
request.EntityUid, _entityNotFoundMessage));
return;
}
var text = GetExamineText(entity);
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(request.EntityUid, text));
}
}
}
}